Skip to content

Commit

Permalink
Added installer, fixed release mode float issues
Browse files Browse the repository at this point in the history
Apparently floats behave different depending on release/debug, and
depending on whether it's run under the VS context.  Anyway, the slicing
code is more robust now.

Also added a Wix installer project.  Just build Release in VS and run
"run.bat" in the install folder.  Need to remember to keep the *.xml
file updated whenever a new assembly is added - possible future task,
automate.
  • Loading branch information
xenovacivus committed Jan 6, 2014
1 parent daa080a commit ee6eee1
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Wix installer generated files
*.wixobj
*.wixpdb

# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
Expand Down
8 changes: 7 additions & 1 deletion GUI/GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GUI</RootNamespace>
<AssemblyName>GUI</AssemblyName>
<AssemblyName>PathCAM</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
Expand Down Expand Up @@ -48,6 +48,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -176,6 +179,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
30 changes: 21 additions & 9 deletions GUI/TriangleMeshGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public void Draw()

// Draw the slice at the mouse point
//GL.Disable(EnableCap.Lighting);
//GL.Color3(Color.White);
//Slice s = new Slice(this, new Plane(Vector3.UnitZ, mousePoint));
//GL.Color3(Color.Black);
//Slice s = new Slice(this, new Plane(Vector3.UnitZ, mouseHoverPoint));
//foreach (var line in s.GetLines(Slice.LineType.All))
//{
// GL.Begin(PrimitiveType.LineLoop);
Expand All @@ -134,6 +134,18 @@ public void Draw()
// }
// GL.End();
//}
//GL.Translate(0, 0, .25f);
//GL.Color3(Color.DarkBlue);
//GL.Begin(PrimitiveType.Triangles);
//foreach (var tri in s.Triangles())
//{
// foreach (var point in tri.Vertices)
// {
// GL.Vertex3(point);
// }
//}
//GL.End();
//GL.Translate(0, 0, -.25f);
//GL.Enable(EnableCap.Lighting);

// Draw the triangles & edges
Expand All @@ -148,16 +160,16 @@ public void Draw()
}
lastNumTriangles = TriangleCount;
}

if (triangleDisplayList >= 0)
{
GL.Color3(triangleColor);
GL.CallList(triangleDisplayList);

GL.Disable(EnableCap.Lighting);
GL.Color3(lineColor);
GL.CallList(lineDisplayList);

GL.Color3(badLineColor);
GL.CallList(badLineDisplayList);
GL.Enable(EnableCap.Lighting);
Expand All @@ -170,7 +182,7 @@ public void Draw()
lineDisplayList = GL.GenLists(1);
badLineDisplayList = GL.GenLists(1);
}

// Triangles
GL.Color3(triangleColor);
if (useDisplayLists)
Expand All @@ -191,7 +203,7 @@ public void Draw()
{
GL.EndList();
}

// Outside Edges
List<LineSegment> edges = new List<LineSegment>();
List<LineSegment> badEdges = new List<LineSegment>();
Expand All @@ -211,7 +223,7 @@ public void Draw()
badEdges.Add(edge.LineSegment);
}
}

GL.Disable(EnableCap.Lighting);
GL.Color3(lineColor);
if (useDisplayLists)
Expand All @@ -229,7 +241,7 @@ public void Draw()
{
GL.EndList();
}

GL.Color3(badLineColor);
if (useDisplayLists)
{
Expand Down
53 changes: 52 additions & 1 deletion Geometry/Intersect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class TrianglePlaneIntersect
private Vector3 pointA;
private Vector3 pointB;
private bool intersects = false;
public bool all_intersect = false;
public TrianglePlaneIntersect(Triangle triangle, Plane plane)
{
// Find the intersections between edges on the triangle and the plane.
Expand All @@ -129,14 +130,64 @@ public TrianglePlaneIntersect(Triangle triangle, Plane plane)
{
float d1 = distances[i];
float d2 = distances[(i + 1) % 3];
float d3 = distances[(i + 2) % 3];
Vector3 v1 = vertices[i];
Vector3 v2 = vertices[(i + 1) % 3];
Vector3 v3 = vertices[(i + 2) % 3];

if (d1 * d2 < 0)
{
// Edge of the triangle crosses the plane, interpolate to get the intersection point
// One point on the edge from D1 to D2
Vector3 intersect = new Vector3(v2 * d1 - v1 * d2) / (d1 - d2);
onPlane.Add(intersect);
if (d3 == 0)
{
// Other point is on D3
onPlane.Add(v3);
break;
}
else
{
if (d1 * d3 < 0)
{
// Intersect with v1 to v3
onPlane.Add(new Vector3(v3 * d1 - v1 * d3) / (d1 - d3));
break;
}
else if (d2 * d3 < 0)
{
// Intersect with v2 to v3
onPlane.Add(new Vector3(v3 * d2 - v2 * d3) / (d2 - d3));
break;
}
else
{
// how the heck would we get here?
}
}
}
if (d1 == 0 && d2 == 0)
{
if (d3 == 0)
{
// Triangle intersects perfectly with the plane - need to return all 3 edges here?
all_intersect = true;
break;
}
else
{
onPlane.Add(v1);
onPlane.Add(v2);
break;
}
}

//if (d1 * d2 < 0)
//{
// // Edge of the triangle crosses the plane, interpolate to get the intersection point
// Vector3 intersect = new Vector3(v2 * d1 - v1 * d2) / (d1 - d2);
// onPlane.Add(intersect);
//}
}

if (onPlane.Count == 2)
Expand Down
4 changes: 4 additions & 0 deletions Geometry/Loaders/DAE_Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public Source FindSourceById(Source[] sources, string id)

public float[] PositionFloats()
{
if (vertices == null)
{
return new float[] { };
}
Input i = FindInputBySemantic(vertices.input, "POSITION");
Source s = FindSourceById(sources, i.source);
IEnumerable<float> floats = s.float_array.Split(new char[] { ' ' }).Select(float_str => float.Parse(float_str));
Expand Down
38 changes: 30 additions & 8 deletions Geometry/Slice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,50 @@ public Slice(TriangleMesh mesh, Plane plane)
//GL.LineWidth(2);
//GL.Begin(PrimitiveType.Lines);
//float height = 0;
LineHandler lineHandler = new LineHandler();

// Slice at 3 levels and combine all segments - this obviates floating point comparison handling.

// Slice at 3 levels and combine all segments - this obviates dealing with triangles that are exactly on the plane.
for (int i = -1; i <= 1; i++)
{
Vector3 offset = plane.Normal * 0.0001f * (float)i;
LineHandler lineHandler = new LineHandler(0.0f);
Plane testPlane = new Plane(plane.Normal, plane.Point + offset);
foreach (Triangle t in mesh.Triangles)
{
var intersect = new TrianglePlaneIntersect(t, testPlane);
if (intersect.Intersects)
{
lineHandler.AddSegment(intersect.PointA - offset, intersect.PointB - offset);
lineHandler.AddSegment(intersect.PointA, intersect.PointB);
//GL.Color3(Color.Blue);
//GL.Vertex3(intersect.PointA + new Vector3(0, 0, height + .01f));
//GL.Color3(Color.Red);
//GL.Vertex3(intersect.PointB + new Vector3(0, 0, height + .01f));
}
else if (intersect.all_intersect && Vector3.Dot(t.Plane.Normal, testPlane.Normal) > 0.5f)
{
// Entire triangle intersects
// Add all the triangle edges (TODO: clean this up...)
List<Vector3> vertices = new List<Vector3>(t.Vertices);
for (int a = 0; a < 3; a++)
{
Vector3 v1 = vertices[a];
Vector3 v2 = vertices[(a + 1) % 3];
lineHandler.AddSegment(v1, v2);
}
}
}
if (this.polyTree == null)
{
Init(lineHandler.GetOuterLoops(), plane);
}
else
{
Slice s = new Slice(lineHandler.GetOuterLoops(), plane);
this.Add(s);
}
}
//GL.End();
//GL.Enable(EnableCap.Lighting);
//GL.LineWidth(1);
Init(lineHandler.GetOuterLoops(), plane);
}

public Slice(Slice fromSlice)
Expand Down Expand Up @@ -541,12 +561,13 @@ public override string ToString()
// All units are in thousandths of an inch
// Floats have a precision of about 7 digits.
// An epsilion value of 0.001f will be valid for about +-100 inches
private const float epsilon = 0.01f;
private float epsilon = 0.001f;
private List<VectorWrapper> vectors = new List<VectorWrapper>();
private List<Segment> segments = new List<Segment>();

public LineHandler()
public LineHandler(float epsilon = 0.01f)
{
this.epsilon = epsilon;
}

public void AddSegment (Vector3 a, Vector3 b)
Expand All @@ -561,7 +582,8 @@ public void AddSegment (Vector3 a, Vector3 b)

private VectorWrapper FindVectorWrapper(Vector3 v)
{
int index = vectors.FindIndex(vectorwrapper => (vectorwrapper.vector - v).Length < epsilon);
//int index = vectors.FindIndex(vectorwrapper => (vectorwrapper.vector - v).Length <= epsilon);
int index = vectors.FindIndex(vectorwrapper => vectorwrapper.vector == v);
if (index < 0)
{
vectors.Add(new VectorWrapper(v));
Expand Down
Binary file added Installer/PathCAM.msi
Binary file not shown.
94 changes: 94 additions & 0 deletions Installer/PathCAM.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>

<Product Name='PathCAM' Id='8454EA61-B731-447D-80DF-488DC83D3986' UpgradeCode='1419EB08-9DC9-4986-B9F7-6B66377D4776'
Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='Subvertlab'>

<Package Id='*' Keywords='Installer' Description="PathCAM Installer"
Comments='PathCAM - Toolpath generation software for CNC robots' Manufacturer='Subvertlab'
InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />

<Media Id='1' Cabinet='PathCAM.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1' />
<Property Id='DiskPrompt' Value="Installation Source[1]" />

<Directory Id='TARGETDIR' Name='SourceDir'>


<Directory Id='ProgramFilesFolder' Name='PFiles'>
<!--Directory Id='Subvertlab' Name='Subvertlab'-->
<Directory Id='INSTALLDIR' Name='PathCAM'>

<Component Id='MainExecutable' Guid='25FD7BF3-A7E8-4EC1-A8A0-7150B675AE5D'>

<File Id='PathCAMEexe' Name='PathCAM.exe' DiskId='1' Source='..\GUI\bin\Release\PathCAM.exe' KeyPath='yes'>
<Shortcut Id="startmenuPathCAM" Directory="ProgramMenuDir" Name="PathCAM"
WorkingDirectory='INSTALLDIR' Icon="icon.ico" IconIndex="0" Advertise="yes" />
<Shortcut Id="desktopPathCAM" Directory="DesktopFolder" Name="PathCAM"
WorkingDirectory='INSTALLDIR' Icon="icon.ico" IconIndex="0" Advertise="yes" />
</File>

<File Id='clipper_libraryDLL' Name='clipper_library.dll' DiskId='1' Source='..\GUI\Bin\Release\clipper_library.dll' />
<File Id='CommandsDLL' Name='Commands.dll' DiskId='1' Source='..\GUI\Bin\Release\Commands.dll' />
<File Id='GCodeDLL' Name='GCode.dll' DiskId='1' Source='..\GUI\Bin\Release\GCode.dll' />
<File Id='GeometryDLL' Name='Geometry.dll' DiskId='1' Source='..\GUI\Bin\Release\Geometry.dll' />
<File Id='OpenTKDLL' Name='OpenTK.dll' DiskId='1' Source='..\GUI\Bin\Release\OpenTK.dll' />
<File Id='OpenTK_GLControlDLL' Name='OpenTK.GLControl.dll' DiskId='1' Source='..\GUI\Bin\Release\OpenTK.GLControl.dll' />
<File Id='QuantumConcepts_CommonDLL' Name='QuantumConcepts.Common.dll' DiskId='1' Source='..\GUI\Bin\Release\QuantumConcepts.Common.dll' />
<File Id='QuantumConcepts_Formats_STLDLL' Name='QuantumConcepts.Formats.STL.dll' DiskId='1' Source='..\GUI\Bin\Release\QuantumConcepts.Formats.STL.dll' />
<File Id='RobotDLL' Name='Robot.dll' DiskId='1' Source='..\GUI\Bin\Release\Robot.dll' />
<File Id='SerialDLL' Name='Serial.dll' DiskId='1' Source='..\GUI\Bin\Release\Serial.dll' />
<File Id='TriangleDLL' Name='Triangle.dll' DiskId='1' Source='..\GUI\Bin\Release\Triangle.dll' />

</Component>


</Directory>
<!--/Directory-->
</Directory>

<Directory Id="ProgramMenuFolder" Name="Programs">
<Directory Id="ProgramMenuDir" Name="PathCAM">
<Component Id="ProgramMenuDir" Guid="2A3E1F52-6D25-4D6C-A610-292FAADF4ABC">
<RemoveFolder Id='ProgramMenuDir' On='uninstall' />
<RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
</Component>
</Directory>
</Directory>

<Directory Id="DesktopFolder" Name="Desktop" />
</Directory>

<Feature Id='Complete' Level='1' Title='PathCAM' Description='The PathCAM Software' Display='expand' ConfigurableDirectory='INSTALLDIR'>
<ComponentRef Id='MainExecutable' />
<ComponentRef Id='ProgramMenuDir' />
</Feature>

<PropertyRef Id="NETFRAMEWORK45"/>
<Condition Message="This application requires .NET Framework 4.5. Please install the .NET Framework then run this installer again.">
<![CDATA[Installed OR NETFRAMEWORK45]]>
</Condition>

<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
<UI>
<UIRef Id="WixUI_InstallDir" />

<Publish Dialog="WelcomeDlg"
Control="Next"
Event="NewDialog"
Value="InstallDirDlg"
Order="2">1</Publish>
<Publish Dialog="InstallDirDlg"
Control="Back"
Event="NewDialog"
Value="WelcomeDlg"
Order="2">1</Publish>
</UI>
<UIRef Id="WixUI_ErrorProgressText" />

<WixVariable Id="WixUIBannerBmp" Value="banner.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="dialog.bmp" />

<Icon Id="icon.ico" SourceFile="..\GUI\icon.ico" />

</Product>
</Wix>
Binary file added Installer/banner.bmp
Binary file not shown.
Binary file added Installer/dialog.bmp
Binary file not shown.
10 changes: 10 additions & 0 deletions Installer/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
You'll need Wix to build the installer:

http://wixtoolset.org/

Make sure the <installdir>\bin directory is in the PATH
environment variable. That allows candle.exe and light.exe
to be executed from scripts without providing the full path
all the time.

Then just build the VS solution in release mode and double click run.bat
Loading

0 comments on commit ee6eee1

Please sign in to comment.