Skip to content

Commit

Permalink
Merge branch 'release/v0.9.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Spatz committed Nov 19, 2014
2 parents ab4950a + ea7204f commit 75dd8d3
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 57 deletions.
10 changes: 4 additions & 6 deletions GenericStl/AsciiStlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AsciiStlReader(Func<TVertex, TVertex, TVertex, TNormal, TTriangle> create

public AsciiStlReader(IDataStructureCreator<TTriangle, TVertex, TNormal> structureCreator)
: base(structureCreator)
{
{
}

public IEnumerable<TTriangle> Read(IEnumerable<string> fileContent)
Expand Down Expand Up @@ -55,12 +55,10 @@ public override IEnumerable<TTriangle> ReadFromStream(Stream s)

private static IEnumerable<string> ReadLines(Stream s)
{
using (var r = new StreamReader(s, Encoding.UTF8, true, DefaultBufferSize, true))
var r = new StreamReader(s, Encoding.UTF8, true, DefaultBufferSize); // do not dispose this reader as it would dispose the stream
while (!r.EndOfStream)
{
while (!r.EndOfStream)
{
yield return r.ReadLine();
}
yield return r.ReadLine();
}
}

Expand Down
10 changes: 4 additions & 6 deletions GenericStl/AsciiStlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ namespace GenericStl
[SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes")]
public class AsciiStlWriter<TTriangle, TVertex, TNormal> : StlWriterBase<TTriangle, TVertex, TNormal>
{
public AsciiStlWriter(Func<TTriangle, Tuple<TVertex, TVertex, TVertex, TNormal>> extractTriangle, Func<TVertex, Tuple<float, float, float>> extractVertex, Func<TNormal, Tuple<float, float, float>> extractNormal)
public AsciiStlWriter(Func<TTriangle, Tuple<TVertex, TVertex, TVertex, TNormal>> extractTriangle, Func<TVertex, Tuple<float, float, float>> extractVertex, Func<TNormal, Tuple<float, float, float>> extractNormal)
: base(extractTriangle, extractVertex, extractNormal)
{
}

public AsciiStlWriter(IDataStructureExtractor<TTriangle, TVertex, TNormal> extractor)
: base(extractor)
{

}

public override void WriteToFile(string fileName, IEnumerable<TTriangle> triangles)
Expand Down Expand Up @@ -47,10 +46,9 @@ public override void WriteToStream(Stream s, IEnumerable<TTriangle> triangles)
throw new ArgumentNullException("triangles");
}

using (var w = new StreamWriter(s, new UTF8Encoding(false, true), 1024, true))
{
WriteTo(w, triangles);
}
var w = new StreamWriter(s, new UTF8Encoding(false, true), 1024); // do not dispose this reader as it would dispose the stream
WriteTo(w, triangles);
w.Flush();
}

public string Write(IEnumerable<TTriangle> triangles)
Expand Down
26 changes: 12 additions & 14 deletions GenericStl/BinaryStlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ namespace GenericStl
{
public class BinaryStlReader<TTriangle, TVertex, TNormal> : StlReaderBase<TTriangle, TVertex, TNormal>
{
public BinaryStlReader(Func<TVertex, TVertex, TVertex, TNormal, TTriangle> createTriangle, Func<float, float, float, TVertex> createVertex, Func<float, float, float, TNormal> createNormal)
public BinaryStlReader(Func<TVertex, TVertex, TVertex, TNormal, TTriangle> createTriangle, Func<float, float, float, TVertex> createVertex, Func<float, float, float, TNormal> createNormal)
: base(createTriangle, createVertex, createNormal)
{

}

public BinaryStlReader(IDataStructureCreator<TTriangle, TVertex, TNormal> structureCreator)
: base(structureCreator)
{
{
}

public override IEnumerable<TTriangle> ReadFromFile(string fileName)
Expand All @@ -34,19 +33,18 @@ public override IEnumerable<TTriangle> ReadFromStream(Stream s)
throw new ArgumentNullException("s");
}

using (var reader = new BinaryReader(s, Encoding.UTF8, true))
{
reader.ReadBytes(80); //header
var reader = new BinaryReader(s, Encoding.UTF8); // do not dispose this reader as it would dispose the stream

var numTriangles = reader.ReadInt32();
reader.ReadBytes(80); //header

for (var i = 0; i < numTriangles; ++i)
{
yield return ReadTriangle(reader);
}
var numTriangles = reader.ReadInt32();

Debug.Assert(s.Position == s.Length);
for (var i = 0; i < numTriangles; ++i)
{
yield return ReadTriangle(reader);
}

Debug.Assert(s.Position == s.Length);
}


Expand Down Expand Up @@ -78,7 +76,7 @@ public IEnumerable<TTriangle> Read(byte[] data)
using (var s = new MemoryStream(data, false))
{
foreach (var triangle in ReadFromStream(s)) yield return triangle;
}
}
}
}
}
}
27 changes: 13 additions & 14 deletions GenericStl/BinaryStlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,22 @@ public void WriteToStream(Stream s, IEnumerable<TTriangle> triangles, byte[] hea

var hdr = PrepareHeader(header);

using (var w = new BinaryWriter(s, new UTF8Encoding(false, true), true))
{
WriteHeader(w, hdr);
WriteLength(w, 0);

var length = 0;
var w = new BinaryWriter(s, new UTF8Encoding(false, true)); // do not dispose this reader as it would dispose the stream
WriteHeader(w, hdr);
WriteLength(w, 0);

foreach (var triangle in triangles)
{
length++;
var length = 0;

WriteTriangle(w, triangle);
}
foreach (var triangle in triangles)
{
length++;

s.Seek(HeaderLengthInByte, SeekOrigin.Begin);
WriteLength(w, length);
WriteTriangle(w, triangle);
}

s.Seek(HeaderLengthInByte, SeekOrigin.Begin);
WriteLength(w, length);
w.Flush();
}

private static byte[] PrepareHeader(byte[] header)
Expand All @@ -97,7 +96,7 @@ private static byte[] PrepareHeader(byte[] header)

if (header.Length < HeaderLengthInByte)
{
Array.Copy(header, newHdr, header.Length);
Array.Copy(header, newHdr, header.Length);
}
else if (header.Length > HeaderLengthInByte)
{
Expand Down
10 changes: 9 additions & 1 deletion GenericStl/GenericStl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GenericStl</RootNamespace>
<AssemblyName>GenericStl</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<BuildPackage>true</BuildPackage>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -32,6 +33,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="MoreLinq">
<HintPath>..\packages\morelinq.1.1.0\lib\net35\MoreLinq.dll</HintPath>
Expand All @@ -58,6 +65,7 @@
</ItemGroup>
<ItemGroup>
<None Include="GenericStl.nuspec" />
<None Include="key.snk" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions GenericStl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("0.9.2.0")]
[assembly: AssemblyFileVersion("0.9.2.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyFileVersion("0.0.0.0")]
25 changes: 12 additions & 13 deletions GenericStl/StlFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ public static bool IsBinary(Stream stream)
{
try
{
using(var r = new BinaryReader(stream, Encoding.UTF8, true))
{
var firstChars = new string(r.ReadChars(5));
var r = new BinaryReader(stream, Encoding.UTF8); // do not dispose this reader as it would dispose the stream

if (!string.Equals(firstChars, "solid", StringComparison.OrdinalIgnoreCase))
{
return true;
}
var firstChars = new string(r.ReadChars(5));

var numberOfCharsToReadAtEnd = "endsolid".Length + 300;
numberOfCharsToReadAtEnd = numberOfCharsToReadAtEnd > stream.Length ? (int)stream.Length : numberOfCharsToReadAtEnd;
if (!string.Equals(firstChars, "solid", StringComparison.OrdinalIgnoreCase))
{
return true;
}

stream.Seek(-numberOfCharsToReadAtEnd , SeekOrigin.End);
var numberOfCharsToReadAtEnd = "endsolid".Length + 300;
numberOfCharsToReadAtEnd = numberOfCharsToReadAtEnd > stream.Length ? (int) stream.Length : numberOfCharsToReadAtEnd;

var lastChars = new string(r.ReadChars(numberOfCharsToReadAtEnd));
stream.Seek(-numberOfCharsToReadAtEnd, SeekOrigin.End);

return !lastChars.Contains("endsolid");
}
var lastChars = new string(r.ReadChars(numberOfCharsToReadAtEnd));

return !lastChars.Contains("endsolid");
}
finally
{
Expand Down
Binary file added GenericStl/key.snk
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GenericStl
GenericStl [![Build status](https://ci.appveyor.com/api/projects/status/36i67p5mqduq1qry/branch/master?svg=true)](https://ci.appveyor.com/project/Musashi178/genericstl/branch/master)
==========

GenericSTL is a library for reading and writing ascii and binary STL files. It is designed to support your own data structures.
Expand Down
74 changes: 74 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Notes:
# - Minimal appveyor.yml file is an empty file. All sections are optional.
# - Indent each level of configuration with 2 spaces. Do not use tabs!
# - All section names are case-sensitive.
# - Section names should be unique on each level.

#---------------------------------#
# general configuration #
#---------------------------------#

# version format
version: 0.9.4.{build}

# branches to build
#branches:
# whitelist
# only:
# - master
# - production

# Do not build on tags (GitHub only)
skip_tags: true

#---------------------------------#
# environment configuration #
#---------------------------------#

# scripts that are called at very beginning, before repo cloning
init:
- git config --global core.autocrlf true

# enable patching of AssemblyInfo.* files
assembly_info:
patch: true
file: AssemblyInfo.*
assembly_version: "{version}"
assembly_file_version: "{version}"
assembly_informational_version: "{version}"

#---------------------------------#
# build configuration #
#---------------------------------#

# build platform, i.e. x86, x64, Any CPU. This setting is optional.
platform: Any CPU

# to add several platforms to build matrix:
#platform:
# - x86
# - Any CPU

# build Configuration, i.e. Debug, Release, etc.
configuration: Release

# to add several configurations to build matrix:
#configuration:
# - Debug
# - Release

build:
project: GenericStl.sln # path to Visual Studio solution or project
publish_nuget: true # package projects with .nuspec files and push to artifacts
publish_nuget_symbols: true # generate and publish NuGet symbol packages

# MSBuild verbosity level
verbosity: minimal

#---------------------------------#
# tests configuration #
#---------------------------------#

test:
assemblies:
- '**\*.Tests.dll'

0 comments on commit 75dd8d3

Please sign in to comment.