Esempio n. 1
0
        private void slicefunc()
        {
            try
            {

               // m_slices = new ArrayList();
                //iterate
                //determine the number of slices
                m_obj.FindMinMax();
                int numslices = (int)((m_obj.m_max.z - m_obj.m_min.z) / m_sf.m_config.ZThick);

                double curz = (double)m_obj.m_min.z;
                RaiseSliceEvent(eSliceEvent.eSliceStarted, 0, numslices);
                DebugLogger.Instance().LogRecord("Slicing started");
                int c = 0;
                for (c = 0; c < numslices; c++)
                {
                    if (m_cancel)
                    {
                        isslicing = false;
                        m_cancel = false;
                        RaiseSliceEvent(eSliceEvent.eSliceCancelled, c, numslices);
                        return;
                    }
                    //get a list of polygons at this slice z height that intersect
                    ArrayList lstply = GetZPolys(m_obj, curz);
                    //iterate through all the polygons and generat 2d line segments at this z level
                    ArrayList lstintersections = GetZIntersections(lstply, curz);
                    curz += m_sf.m_config.ZThick;
                    Slice sl = new Slice();
                    sl.m_segments = lstintersections;
                    m_sf.m_slices.Add(sl);
                    RaiseSliceEvent(eSliceEvent.eLayerSliced, c, numslices);
                }
                RaiseSliceEvent(eSliceEvent.eSliceCompleted, c, numslices);
                DebugLogger.Instance().LogRecord("Slicing Completed");
                isslicing = false;

            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogRecord(ex.Message);
            }
        }
Esempio n. 2
0
        private void slicefunc()
        {
            try
            {
                //first take care of scaling up the output bitmap paramters size, so we can re-sample later
                double scaler = 1.5; // specify the scale factor
                m_saved.CopyFrom(m_sf.m_config); // save the original
                if (m_sf.m_config.antialiasing == true)
                {
                    scaler = m_sf.m_config.aaval;
                    //  scale them up.
                    m_sf.m_config.dpmmX *= scaler;
                    m_sf.m_config.dpmmY *= scaler;
                    m_sf.m_config.xres = (int)(m_sf.m_config.xres * scaler);
                    m_sf.m_config.yres = (int)(m_sf.m_config.yres * scaler);

                }
                else
                {
                    scaler = 1.0; // no scaling
                }

                //determine the number of slices
                //UVDLPApp.Instance().Scene.FindMinMax();

                MinMax mm = UVDLPApp.Instance().Engine3D.CalcSceneExtents();
                int numslices = (int)((mm.m_max - mm.m_min) / m_sf.m_config.ZThick);
                //int numslices = (int)((UVDLPApp.Instance().Scene.m_max.z) / m_sf.m_config.ZThick);
                // I should start slicing at Wz 0, not Oz 0
                float curz = 0; // start at Wz0

                // an alternative here is to slice the scene from wZ 0, therefore, all object geometry beneath the ground plane won't be slice;
                //double curz = (double)0.0;// start at the ground

                int c = 0;
                string scenename = "";
                // a little housework here...
                foreach (Object3d obj in UVDLPApp.Instance().Engine3D.m_objects)
                {
                    obj.CalcMinMaxes();
                    if (c == 0)
                    {
                        //get the first objects' name
                        scenename = obj.m_fullname;
                        m_sf.modelname = obj.m_fullname;
                    }
                    c++;
                }
                m_sf.NumSlices = numslices;
                SliceStarted(scenename, numslices);
                DebugLogger.Instance().LogRecord("Slicing started");

                if (m_sf.m_config.export == false)
                {
                    // if we're not actually exporting slices right now, then
                    // raise the completed event and exit
                    SliceCompleted(scenename, 0, numslices);
                    m_sf.m_config.CopyFrom(m_saved);
                    isslicing = false;
                    return; // exit slicing, nothing more to do...
                }
                for (c = 0; c < numslices; c++)
                {
                    Bitmap bmp = new Bitmap(m_sf.m_config.xres,m_sf.m_config.yres); // create a new bitmap on a per-slice basis
                    //clear the image for rendering
                    Graphics graph = Graphics.FromImage(bmp);
                    graph.Clear(UVDLPApp.Instance().m_appconfig.m_backgroundcolor);

                    //convert all to 2d lines
                    Bitmap savebm = null;
                    // check for cancelation
                    if (m_cancel)
                    {
                        isslicing = false;
                        m_cancel = false;
                        //restore the original sizes
                        m_sf.m_config.CopyFrom(m_saved);
                        RaiseSliceEvent(eSliceEvent.eSliceCancelled, c, numslices);
                        return;
                    }

                    foreach (Object3d obj in UVDLPApp.Instance().Engine3D.m_objects)
                    {
                        savebm = bmp; // need to set this here in case it's not rendered
                        if (curz >=obj.m_min.z &&  curz <= obj.m_max.z) // only slice from the bottom to the top of the objects
                        {
                            //obj.ClearCached();
                            ArrayList lstply = GetZPolys(obj, curz);//get a list of polygons at this slice z height that potentially intersect
                            ArrayList lstintersections = GetZIntersections(lstply, curz);//iterate through all the polygons and generate x/y line segments at this 3d z level

                            Slice sl = new Slice();//create a new slice
                            sl.m_segments = lstintersections;// Set the list of intersections
                           // m_sf.m_slices.Add(sl);// add the slice to slicefile
                            // now render the slice into the scaled, pre-allocated bitmap
                            sl.RenderSlice(m_sf.m_config, ref bmp);
                            savebm = bmp;
                        }
                    }

                    if (m_sf.m_config.antialiasing == true) // we're using anti-aliasing here, so resize the image
                    {
                        savebm = ResizeImage(bmp, new Size(m_saved.xres,m_saved.yres));
                    }
                    if (m_sf.m_config.m_flipX == true)
                    {
                        savebm = ReflectX(savebm);
                    }
                    if (m_sf.m_config.m_flipY == true)
                    {
                        savebm = ReflectY(savebm);
                    }
                    curz += (float)m_sf.m_config.ZThick;// move the slice for the next layer
                    //raise an event to say we've finished a slice
                    LayerSliced(scenename, c,numslices,savebm);
                }
                // restore the original
                m_sf.m_config.CopyFrom(m_saved);
                SliceCompleted(scenename, c, numslices);
                DebugLogger.Instance().LogRecord("Slicing Completed");
                isslicing = false;

            }
            catch (Exception ex)
            {
                string s = ex.StackTrace;
                DebugLogger.Instance().LogRecord(ex.Message);
                //RaiseSliceEvent(eSliceEvent.eSliceCancelled,0,0);
                m_cancel = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This function will immediately return a bitmap slice at the specified Z-Level
        /// </summary>
        /// <param name="zlev"></param>
        /// <returns></returns>
        public Bitmap SliceImmediate(float curz)
        {
            try
            {
                //first take care of scaling up the output bitmap paramters size, so we can re-sample later
                double scaler = 1.5; // specify the scale factor
                m_saved.CopyFrom(m_sf.m_config);// save the orginal
                if (m_sf.m_config.antialiasing == true)
                {
                    scaler = m_sf.m_config.aaval;
                    m_sf.m_config.dpmmX *= scaler;
                    m_sf.m_config.dpmmY *= scaler;
                    m_sf.m_config.xres = (int)(scaler * m_sf.m_config.xres);
                    m_sf.m_config.yres = (int)(scaler * m_sf.m_config.yres);
                }
                SliceBuildConfig sbf = new SliceBuildConfig(m_sf.m_config); // save it

                Bitmap bmp = new Bitmap(m_sf.m_config.xres, m_sf.m_config.yres); // create a new bitmap on a per-slice basis
                Graphics graph = Graphics.FromImage(bmp);
                graph.Clear(UVDLPApp.Instance().m_appconfig.m_backgroundcolor);//clear the image for rendering

                //convert all to 2d lines
                Bitmap savebm = null;
                // check for cancelation

                foreach (Object3d obj in UVDLPApp.Instance().Engine3D.m_objects)
                {
                    savebm = bmp; // need to set this here in case it's not rendered
                    if (curz >= obj.m_min.z && curz <= obj.m_max.z) // only slice from the bottom to the top of the objects
                    {
                        ArrayList lstply = GetZPolys(obj, curz);//get a list of polygons at this slice z height that potentially intersect
                        ArrayList lstintersections = GetZIntersections(lstply, curz);//iterate through all the polygons and generate x/y line segments at this 3d z level
                        Slice sl = new Slice();//create a new slice
                        sl.m_segments = lstintersections;// Set the list of intersections
                        sl.RenderSlice(m_sf.m_config, ref bmp);
                        savebm = bmp;
                    }
                }

                if (m_sf.m_config.antialiasing == true) // we're using anti-aliasing here, so resize the image
                {
                    savebm = ResizeImage(bmp,new Size(m_saved.xres,m_saved.yres));
                }
                if (m_sf.m_config.m_flipX == true)
                {
                    savebm = ReflectX(savebm);
                }
                if (m_sf.m_config.m_flipY == true)
                {
                    savebm = ReflectY(savebm);
                }
                //restore the original size
                m_sf.m_config.CopyFrom(m_saved);
                return savebm;
            }
            catch (Exception ex)
            {
                string s = ex.StackTrace;
                DebugLogger.Instance().LogRecord(ex.Message);
                return null;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This get slice immediate is currently for previewing only
        /// </summary>
        /// <param name="curz"></param>
        /// <returns></returns>
        public Slice GetSliceImmediate(float curz)
        {
            try
            {
                SliceBuildConfig sbf = new SliceBuildConfig(m_sf.m_config); // save it
                Slice sl = new Slice();//create a new slice
                sl.m_segments = new List<PolyLine3d>();
                foreach (Object3d obj in UVDLPApp.Instance().Engine3D.m_objects)
                {
                    if (curz >= obj.m_min.z && curz <= obj.m_max.z) // only slice from the bottom to the top of the objects
                    {
                        List<Polygon> lstply = GetZPolys(obj, curz);//get a list of polygons at this slice z height that potentially intersect
                        List<PolyLine3d> lstintersections = GetZIntersections(lstply, curz);//iterate through all the polygons and generate x/y line segments at this 3d z level
                        sl.m_segments.AddRange(lstintersections);// Set the list of intersections
                    }
                }

                return sl;
            }
            catch (Exception ex)
            {
                string s = ex.StackTrace;
                DebugLogger.Instance().LogRecord(ex.Message);
                return null;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This will be called when we're exporting 
        /// </summary>
        /// <param name="scenename"></param>
        /// <param name="layer"></param>
        /// <param name="numslices"></param>
        /// <param name="bmp"></param>
        /// <param name="lstPoly"></param>
        private void LayerSliced(string scenename, int layer, int numslices, Bitmap bmp, List<PolyLine3d> lstintersections)
        {
            string path;
            try
            {
                // if (m_buildparms.exportimages)
                {
                    // get the model name
                    String modelname = scenename;
                    // strip off the file extension
                    path = SliceFile.GetSliceFilePath(modelname);
                    String imname = Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}", layer) + ".png";
                    String imagename = path + UVDLPApp.m_pathsep + imname;
                    //if (m_sf.m_config.m_exportopt.ToUpper().Contains("ZIP"))
                    {
                        // create a memory stream for this to save into
                        MemoryStream ms = new MemoryStream();
                        bmp.Save(ms, ImageFormat.Png);
                        ms.Seek(0, SeekOrigin.Begin); // seek back to beginning
                        if (!m_cancel) // if we're not in the process of cancelling
                        {
                            SceneFile.Instance().AddSlice(UVDLPApp.Instance().SceneFileName,ms, imname);
                        }
                    }
                    if (m_sf.m_config.exportpng)
                    {
                        //imagename
                        bmp.Save(imagename);
                    }
                    if (lstintersections != null)
                    {
                        StreamWriter sw;
                        imname = Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}", layer) + ".svg";
                        imagename = path + UVDLPApp.m_pathsep + imname;
                        if (m_sf.m_config.exportsvg < 3)
                        {
                            Path2D vectorPath = new Path2D(lstintersections);
                            sw = vectorPath.GenerateSVG(UVDLPApp.Instance().m_printerinfo.m_PlatXSize,
                                UVDLPApp.Instance().m_printerinfo.m_PlatYSize, m_sf.m_config.exportsvg == 2);
                        }
                        else
                        {
                            Slice sl = new Slice();
                            sl.m_segments = lstintersections;
                            sl.Optimize();
                            sw = GenerateSVG(sl.m_opsegs, m_sf.m_config.exportsvg == 4);
                        }
                        if (!m_cancel)
                        {
                            SceneFile.Instance().AddVectorSlice(UVDLPApp.Instance().SceneFileName,(MemoryStream)sw.BaseStream, imname);
                        }
                    }

                    RaiseSliceEvent(eSliceEvent.eLayerSliced, layer, numslices);
                }
            }
            catch (Exception ex)
            {
                string s = ex.StackTrace;
                DebugLogger.Instance().LogError(ex.Message);
            }
        }
Esempio n. 6
0
        private void slicefunc()
        {
            try
            {

                //determine the number of slices
                m_obj.FindMinMax();
                // I think I should calculate the number of slices from the world 0 position, not just the bottom of the object
                int numslices = (int)((m_obj.m_max.z - m_obj.m_min.z) / m_sf.m_config.ZThick);
                // I should start slicing at Wz 0, not Oz 0
                double curz = (double)m_obj.m_min.z;
                RaiseSliceEvent(eSliceEvent.eSliceStarted, 0, numslices);
                DebugLogger.Instance().LogRecord("Slicing started");
                int c = 0;
                m_obj.CalcMinMaxes();
                m_obj.ClearCached();
                for (c = 0; c < numslices; c++)
                {
                    // check for cancelation
                    if (m_cancel)
                    {
                        isslicing = false;
                        m_cancel = false;
                        RaiseSliceEvent(eSliceEvent.eSliceCancelled, c, numslices);
                        return;
                    }
                    //get a list of polygons at this slice z height that potentially intersect
                    ArrayList lstply = GetZPolys(m_obj, curz);
                    //iterate through all the polygons and generate x/y line segments at this 3d z level
                    ArrayList lstintersections = GetZIntersections(lstply, curz);
                    // move the slice for the next layer
                    curz += m_sf.m_config.ZThick;
                    //create a new slice
                    Slice sl = new Slice();
                   // Set the list of intersections
                    sl.m_segments = lstintersections;
                    // add the slice to slicefile
                    m_sf.m_slices.Add(sl);
                    //raise an event to say we've finished a slice
                    RaiseSliceEvent(eSliceEvent.eLayerSliced, c, numslices);
                }
                RaiseSliceEvent(eSliceEvent.eSliceCompleted, c, numslices);
                DebugLogger.Instance().LogRecord("Slicing Completed");
                isslicing = false;

            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogRecord(ex.Message);
                //RaiseSliceEvent(eSliceEvent.eSliceCancelled,0,0);
                m_cancel = true;
            }
        }