Exemplo n.º 1
0
 //multislicing boilerplate code
 public void multislice(string configname, bool getOnlyToolpaths, string arguments, string stlfile_arg)
 {
     doActionForFile(configname, stlfile_arg, (string stlfile) => {
         if (arguments.Length == 0)
         {
             throw new ApplicationException("Arguments must be provided!!!");
         }
         using (SI.ExternalSlicerManager external = createExternalSlicerManager(stlfile)) {
             try {
                 using (SI.MultiSlicerHandler handler = new SI.MultiSlicerHandler(dll, arguments)) {
                     bool alsoContours = !getOnlyToolpaths && (handler.alsoContours);
                     modifyAutoCADDocument((Transaction tr, BlockTableRecord btr) => {
                         if (handler.usingScheduler)
                         {
                             multislice_3dscheduler(external, handler, alsoContours, tr, btr);
                         }
                         else
                         {
                             multislice_2dsimple(external, handler, alsoContours, tr, btr);
                         }
                     });
                 }
             } catch {
                 external.terminate();
                 throw;
             }
         }
     });
 }
Exemplo n.º 2
0
        //2d simple multislicing
        private unsafe void multislice_2dsimple(SI.ExternalSlicerManager external, SI.MultiSlicerHandler handler, bool alsoContours, Transaction tr, BlockTableRecord btr)
        {
            double zstep = handler.z_uniform_step;

            double[] zs = handler.use_z_base ? external.prepareSTLSimple(zstep, handler.z_base) :
                          external.prepareSTLSimple(zstep);
            int numslices = zs.Length;

            for (int i = 0; i < numslices; ++i)
            {
                SI.IntPoint[][] rawslice = external.readSlice();
                if (rawslice.Length == 0)
                {
                    continue;
                }
                if (alsoContours)
                {
                    showExternalSlice(rawslice, external.scalingFactor, zs[i], tr, btr);
                }
                void *slice = handler.feedRawSliceIntoDll(rawslice);
                rawslice = null;
                void *result = handler.computeSlice2D(slice); //the slice is freed in computeSlice2D()
                if (result == null)
                {
                    throw new ApplicationException("Error in compute2D: " + dll.err);
                }
                try {
                    const bool mode2D = true;
                    int        ntools = handler.numProcesses;
                    for (int j = 0; j < ntools; ++j)
                    {
                        readOutputSlices(result, mode2D, alsoContours, zs[i], j, tr, btr);
                    }
                } finally {
                    if (result != null)
                    {
                        dll.freeResult(result);
                    }
                }
            }
        }
Exemplo n.º 3
0
        //multislicing with 3d scheduling
        private unsafe void multislice_3dscheduler(SI.ExternalSlicerManager external, SI.MultiSlicerHandler handler, bool alsoContours, Transaction tr, BlockTableRecord btr)
        {
            double minx, maxx, miny, maxy, minz, maxz;

            external.getBoundingBox(out minx, out maxx, out miny, out maxy, out minz, out maxz);
            double[] zs = handler.getSlicesZs(minz, maxz);
            external.sendZs(zs);

            for (int i = 0; i < zs.Length; ++i)
            {
                SI.IntPoint[][] rawslice = external.readSlice();
                if ((rawslice.Length > 0) && (alsoContours))
                {
                    showExternalSlice(rawslice, external.scalingFactor, zs[i], tr, btr);
                }
                //here, it may be the moment to use dll.receiveAdditionalAdditiveContours() if we were using online feedback...
                void *slice = handler.feedRawSliceIntoDll(rawslice);
                rawslice = null;
                handler.feedSliceToScheduler(slice); //the slice is freed in feedSliceToScheduler()
                while (true)
                {
                    void *result = handler.getResultFromScheduler();
                    if (result == null)
                    {
                        break;
                    }
                    try {
                        const bool   mode2D          = false;
                        const double z_not_used      = 0.0; //for !mode2D, z is not used
                        const int    single_sliceIdx = 0;   //for !mode2D, there is a single result, not one for each tool
                        readOutputSlices(result, mode2D, alsoContours, z_not_used, single_sliceIdx, tr, btr);
                    } finally {
                        dll.freeResult(result);
                    }
                }
            }
        }