Skip to content

Commit 8155d96

Browse files
Added functionality to abstract the reading of text/binary STLs (see STLDocument.Read) (fixes #2); commented the codebase (fixes #3); binary STLs now write the AttributeByteCount value for facets (fixes #4); added functionality to convert an STL document between text and binary format (see STLDocument.CopyAsText and STLDocument.CopyAsBinary) (fixes #5).
1 parent bf5ba14 commit 8155d96

8 files changed

Lines changed: 328 additions & 41 deletions

File tree

Source/STL/Facet.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,29 @@
88

99
namespace QuantumConcepts.Formats.StereoLithography
1010
{
11-
public class Facet : IEquatable<Facet>
11+
/// <summary>A representation of a facet which is defined by its location (<see cref="Vertices"/>) and directionality (<see cref="Normal"/>).</summary>
12+
public class Facet : IEquatable<Facet>, IEnumerable<Vertex>
1213
{
14+
/// <summary>Indicates the directionality of the <see cref="Facet"/>.</summary>
1315
public Normal Normal { get; set; }
14-
public List<Vertex> Vertices { get; set; }
16+
17+
/// <summary>Indicates the location of the <see cref="Facet"/>.</summary>
18+
public IList<Vertex> Vertices { get; set; }
19+
20+
/// <summary>Additional data attached to the facet.</summary>
21+
/// <remarks>Depending on the source of the STL, this could be used to indicate such things as the color of the <see cref="Facet"/>. This functionality only exists in binary STLs.</remarks>
1522
public int AttributeByteCount { get; set; }
1623

24+
/// <summary>Creates a new, empty <see cref="Facet"/>.</summary>
1725
public Facet()
1826
{
1927
this.Vertices = new List<Vertex>();
2028
}
2129

30+
/// <summary>Creates a new <see cref="Facet"/> using the provided parameters.</summary>
31+
/// <param name="normal">The directionality of the <see cref="Facet"/>.</param>
32+
/// <param name="vertices">The location of the <see cref="Facet"/>.</param>
33+
/// <param name="attributeByteCount">Additional data to attach to the <see cref="Facet"/>.</param>
2234
public Facet(Normal normal, IEnumerable<Vertex> vertices, int attributeByteCount)
2335
: this()
2436
{
@@ -27,6 +39,8 @@ public Facet(Normal normal, IEnumerable<Vertex> vertices, int attributeByteCount
2739
this.AttributeByteCount = attributeByteCount;
2840
}
2941

42+
/// <summary>Reads a single <see cref="Facet"/> from the <paramref name="reader"/>.</summary>
43+
/// <param name="reader">The reader which contains a <see cref="Facet"/> to be read at the current position</param>
3044
public static Facet Read(StreamReader reader)
3145
{
3246
if (reader == null)
@@ -52,6 +66,8 @@ public static Facet Read(StreamReader reader)
5266
return facet;
5367
}
5468

69+
/// <summary>Reads a single <see cref="Facet"/> from the <paramref name="reader"/>.</summary>
70+
/// <param name="reader">The reader which contains a <see cref="Facet"/> to be read at the current position</param>
5571
public static Facet Read(BinaryReader reader)
5672
{
5773
if (reader == null)
@@ -72,6 +88,8 @@ public static Facet Read(BinaryReader reader)
7288
return facet;
7389
}
7490

91+
/// <summary>Writes the <see cref="Facet"/> as text to the <paramref name="writer"/>.</summary>
92+
/// <param name="writer">The writer to which the <see cref="Facet"/> will be written at the current position.</param>
7593
public void Write(StreamWriter writer)
7694
{
7795
writer.Write("\t");
@@ -84,26 +102,46 @@ public void Write(StreamWriter writer)
84102
writer.WriteLine("\t\tendloop");
85103
writer.WriteLine("\tendfacet");
86104
}
87-
105+
106+
/// <summary>Writes the <see cref="Facet"/> as binary to the <paramref name="writer"/>.</summary>
107+
/// <param name="writer">The writer to which the <see cref="Facet"/> will be written at the current position.</param>
88108
public void Write(BinaryWriter writer)
89109
{
90110
//Write the normal.
91111
this.Normal.Write(writer);
92112

93113
//Write each vertex.
94114
this.Vertices.ForEach(o => o.Write(writer));
115+
116+
//Write the attribute byte count.
117+
writer.Write(this.AttributeByteCount);
95118
}
96119

120+
/// <summary>Returns the string representation of this <see cref="Facet"/>.</summary>
97121
public override string ToString()
98122
{
99123
return "facet {0}".FormatString(this.Normal);
100124
}
101125

126+
/// <summary>Determines whether or not this instance is the same as the <paramref name="other"/> instance.</summary>
127+
/// <param name="other">The <see cref="Facet"/> to which to compare.</param>
102128
public bool Equals(Facet other)
103129
{
104130
return (this.Normal.Equals(other.Normal)
105131
&& this.Vertices.Count == other.Vertices.Count
106132
&& this.Vertices.All((i, o) => o.Equals(other.Vertices[i])));
107133
}
134+
135+
/// <summary>Iterates through the <see cref="Vertices"/> collection.</summary>
136+
public IEnumerator<Vertex> GetEnumerator()
137+
{
138+
return this.Vertices.GetEnumerator();
139+
}
140+
141+
/// <summary>Iterates through the <see cref="Vertices"/> collection.</summary>
142+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
143+
{
144+
return GetEnumerator();
145+
}
108146
}
109147
}

Source/STL/Normal.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,33 @@
77

88
namespace QuantumConcepts.Formats.StereoLithography
99
{
10+
/// <summary>A simple XYZ representation of a normal (<see cref="Vertex"/>).</summary>
1011
public class Normal : Vertex
1112
{
12-
public Normal() { }
13+
/// <summary>Creates a new, empty <see cref="Normal"/>.</summary>
14+
public Normal() : base() { }
1315

14-
public Normal(decimal x, decimal y, decimal z)
15-
: this()
16-
{
17-
this.X = x;
18-
this.Y = y;
19-
this.Z = z;
20-
}
16+
/// <summary>Creates a new <see cref="Normal"/> using the provided coordinates.</summary>
17+
public Normal(decimal x, decimal y, decimal z) : base(x, y, z) { }
2118

19+
/// <summary>Reads a single <see cref="Normal"/> from the <paramref name="reader"/>.</summary>
20+
/// <param name="reader">The reader which contains a <see cref="Normal"/> to be read at the current position</param>
2221
public static Normal Read(StreamReader reader)
2322
{
2423
return Normal.FromVertex(Vertex.Read(reader));
2524
}
2625

26+
/// <summary>Reads a single <see cref="Normal"/> from the <paramref name="reader"/>.</summary>
27+
/// <param name="reader">The reader which contains a <see cref="Normal"/> to be read at the current position</param>
2728
public static Normal Read(BinaryReader reader)
2829
{
2930
return Normal.FromVertex(Vertex.Read(reader));
3031
}
3132

33+
/// <summary>Converts the <paramref name="vertex"/> to a normal.</summary>
34+
/// <remarks>This does nothing more than copy the X, Y and Z coordinates of the <paramref name="vertex"/> into a new <see cref="Normal"/> instance.</remarks>
35+
/// <param name="vertex">The <see cref="Vertex"/> to be converted into a <see cref="Normal"/>.</param>
36+
/// <returns>A <see cref="Normal"/> or null if the <paramref name="vertex"/> is null.</returns>
3237
public static Normal FromVertex(Vertex vertex)
3338
{
3439
if (vertex == null)
@@ -42,6 +47,7 @@ public static Normal FromVertex(Vertex vertex)
4247
};
4348
}
4449

50+
/// <summary>Returns the string representation of this <see cref="Normal"/>.</summary>
4551
public override string ToString()
4652
{
4753
return "normal {0} {1} {2}".FormatString(this.X, this.Y, this.Z);

Source/STL/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
[assembly: AssemblyProduct("STL Format Reader and Writer")]
99
[assembly: AssemblyCopyright("Copyright © Quantum Concepts Corporation")]
1010
[assembly: AssemblyTrademark("Copyright © Quantum Concepts Corporation")]
11-
[assembly: AssemblyVersion("1.0.0.0")]
12-
[assembly: AssemblyFileVersion("1.0.0.0")]
11+
[assembly: AssemblyVersion("1.1.0.0")]
12+
[assembly: AssemblyFileVersion("1.1.0.0")]

Source/STL/QuantumConcepts.Formats.STL.dll.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>QuantumConcepts.Formats.STL</id>
5-
<version>1.0.0.1</version>
5+
<version>1.1.0.0</version>
66
<title>Quantum Concepts STLdotNET</title>
77
<authors>Quantum Concepts</authors>
88
<owners>Quantum Concepts</owners>
@@ -11,8 +11,8 @@
1111
<iconUrl>http://quantumconceptscorp.com/Resources/Images/QCLogoButton-32.png</iconUrl>
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>This library facilitates the reading and writing of Stereo Lithograph (STL) files.</description>
14-
<releaseNotes>This is the initial release which includes all basic features required to read/write STL files.</releaseNotes>
15-
<copyright>Copyright 2013 Quantum Concepts Corporation, released under the GNU Affero General Public License./</copyright>
14+
<releaseNotes>Added functionality to abstract the reading of text/binary STLs (see STLDocument.Read); commented the codebase; binary STLs now write the AttributeByteCount value for facets; added functionality to convert an STL document between text and binary format (see STLDocument.CopyAsText and STLDocument.CopyAsBinary).</releaseNotes>
15+
<copyright>Copyright 2014 Quantum Concepts Corporation, released under the GNU Affero General Public License./</copyright>
1616
<tags>3d reprap stl</tags>
1717
<dependencies>
1818
<dependency id="QuantumConcepts.Common" version="1.0" />

0 commit comments

Comments
 (0)