/// <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
                    {
                        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
                        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);
            }
        }
Exemple #2
0
        /// <summary>
        /// This function will immediately return a bitmap slice at the specified Z-Level
        /// If lstPoly is not null, a list of vector polylines representing the slice is returned
        /// </summary>
        /// <param name="zlev"></param>
        /// <param name="lstPoly"></param>
        /// <returns></returns>
        //public Bitmap SliceImmediate(float curz, List<PolyLine3d> lstPoly = null)
        public Bitmap SliceImmediate(float curz, List <PolyLine3d> allIntersections, bool outline = true, bool bottomLayers = false)
        {
            outline = true;
            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
                using (Graphics graph = Graphics.FromImage(bmp))
                {
                    graph.Clear(UVDLPApp.Instance().m_appconfig.m_backgroundcolor);
                    graph.DrawRectangle(new Pen(new SolidBrush(UVDLPApp.Instance().m_appconfig.m_foregroundcolor), (float)m_sf.m_config.m_wall_thickness), new Rectangle(0, 0, m_sf.m_config.xres, m_sf.m_config.yres));
                    //graph.DrawString("omid", new Font(new FontFamily("Tahoma"), 10 ,FontStyle.Bold), new SolidBrush(Color.Red), new PointF(2, 299));
                    //clear the image for rendering
                    if (bottomLayers)
                    {
                        graph.Clear(UVDLPApp.Instance().m_appconfig.m_backgroundcolor);
                    }
                }
                //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
                    {
                        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
                        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, outline);
                        if (allIntersections != null)
                        {
                            allIntersections.AddRange(lstintersections);
                        }

                        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().LogError(ex);
                return(null);
            }
        }