@@ -66,6 +66,9 @@ public static void WriteSlicesToCliFile( PolySliceStack oSlices,
6666 string strDate = "" ,
6767 float fUnitsInMM = 0.0f )
6868 {
69+ if ( ( oSlices . nCount ( ) < 1 ) || oSlices . oBBox ( ) . bIsEmpty ( ) )
70+ throw new Exception ( "No valid slices detected (empty)" ) ;
71+
6972 if ( fUnitsInMM <= 0.0f )
7073 fUnitsInMM = 1.0f ;
7174
@@ -83,12 +86,15 @@ public static void WriteSlicesToCliFile( PolySliceStack oSlices,
8386 oTextWriter . WriteLine ( "$$LABEL/1,default" ) ;
8487 oTextWriter . WriteLine ( "$$DATE/" + strDate ) ;
8588
89+ // Use X/Y dimenstions of the bounding box
90+ // use 0 as first Z coordinate and last layer's Z coordinate as Z height
91+
8692 string strDim = oSlices . oBBox ( ) . vecMin . X . ToString ( "00000000.00000" ) + "," +
8793 oSlices . oBBox ( ) . vecMin . Y . ToString ( "00000000.00000" ) + "," +
88- oSlices . oBBox ( ) . vecMin . Z . ToString ( "00000000.00000" ) + "," +
94+ "00000000.00000" + "," +
8995 oSlices . oBBox ( ) . vecMax . X . ToString ( "00000000.00000" ) + "," +
9096 oSlices . oBBox ( ) . vecMax . Y . ToString ( "00000000.00000" ) + "," +
91- oSlices . oBBox ( ) . vecMax . Z . ToString ( "00000000.00000" ) ;
97+ oSlices . oSliceAt ( oSlices . nCount ( ) - 1 ) . fZPos ( ) . ToString ( "00000000.00000" ) ;
9298
9399 oTextWriter . WriteLine ( "$$DIMENSION/{0}" , strDim ) ;
94100 oTextWriter . WriteLine ( "$$LAYERS/{0}" , ( oSlices . nCount ( ) + 1 ) . ToString ( "00000" ) ) ;
@@ -680,9 +686,8 @@ private static bool bExtractParameter( ref string strLine,
680686
681687 public partial class Voxels
682688 {
683- public void SaveToCliFile ( string strFileName ,
684- float fLayerHeight = 0f ,
685- bool bUseAbsXYOrigin = false )
689+ public PolySliceStack oVectorize ( float fLayerHeight = 0f ,
690+ bool bUseAbsXYOrigin = false )
686691 {
687692 if ( fLayerHeight == 0f )
688693 fLayerHeight = Library . fVoxelSizeMM ;
@@ -733,6 +738,9 @@ public void SaveToCliFile( string strFileName,
733738 continue ;
734739 }
735740
741+ Console . WriteLine ( $ "Slice has { oSlice . nCountours ( ) } contours") ;
742+
743+ oSlice . Close ( ) ;
736744 oSlices . Add ( oSlice ) ;
737745
738746 fLayerZ += fLayerHeight ;
@@ -741,6 +749,14 @@ public void SaveToCliFile( string strFileName,
741749 PolySliceStack oStack = new ( ) ;
742750 oStack . AddSlices ( oSlices ) ;
743751
752+ return oStack ;
753+ }
754+
755+ public void SaveToCliFile ( string strFileName ,
756+ float fLayerHeight = 0f ,
757+ bool bUseAbsXYOrigin = false )
758+ {
759+ PolySliceStack oStack = oVectorize ( fLayerHeight , bUseAbsXYOrigin ) ;
744760 CliIo . WriteSlicesToCliFile ( oStack , strFileName ) ;
745761 }
746762 }
0 commit comments