Beispiel #1
0
        private void Render()
        {
            RenderingOptions options = new RenderingOptions()
            {
                ViewPolygons = viewPolygonsToolStripMenuItem.Checked
            };

            if (treeView1.SelectedNode != null)
            {
                if (treeView1.SelectedNode.Tag != null)
                {
                    ScObject data = (ScObject)treeView1.SelectedNode.Tag;
                    pictureBox1.Image = data.Render(options);
                    pictureBox1.Refresh();
                    label1.Text = data.GetInfo();
                }
            }   
        }
Beispiel #2
0
 public override Bitmap Render(RenderingOptions options)
 {
     return(GetBitmap());
 }
Beispiel #3
0
 public override Bitmap Render(RenderingOptions options)
 {
     return GetBitmap();
 }
Beispiel #4
0
        public override Bitmap Render(RenderingOptions options)
        {
            /*
             * Log("XY:");
             * foreach(ShapeChunk chunk in m_vChunks)
             * {
             *  foreach(var p in chunk.GetPointsXY())
             *  {
             *      Log("x: " + p.X + ", y: " + p.Y);
             *  }
             *  Log("");
             * }
             *
             * foreach (ShapeChunk chunk in m_vChunks)
             * {
             *  foreach (var p in chunk.GetPointsUV())
             *  {
             *      Log("u: " + p.X + ", u: " + p.Y);
             *  }
             *  Log("");
             * }
             */

            Log("Rendering image of " + m_vChunks.Count.ToString() + " polygons");

            //Calculate et initialize the final shape size
            List <PointF> pointsXY = m_vChunks.SelectMany(chunk => ((ShapeChunk)chunk).GetPointsXY()).ToList();
            GraphicsPath  pathXY   = new GraphicsPath();

            pathXY.AddPolygon(pointsXY.ToArray());
            int width = Rectangle.Round(pathXY.GetBounds()).Width;

            width = width > 0 ? width : 1;
            int height = Rectangle.Round(pathXY.GetBounds()).Height;

            height = height > 0 ? height : 1;
            int x          = Rectangle.Round(pathXY.GetBounds()).X;
            int y          = Rectangle.Round(pathXY.GetBounds()).Y;
            var finalShape = new Bitmap(width, height);

            //Assemble shape chunks
            foreach (ShapeChunk chunk in m_vChunks)
            {
                var    texture = (Texture)m_vStorageObject.GetTextures()[chunk.GetTextureId()];
                Bitmap bitmap  = texture.GetBitmap();

                var polygonUV = chunk.GetPointsUV();
                var polygonXY = chunk.GetPointsXY();

                GraphicsPath gpuv = new GraphicsPath();
                gpuv.AddPolygon(polygonUV.ToArray());

                GraphicsPath gpxy = new GraphicsPath();
                gpxy.AddPolygon(polygonXY.ToArray());

                int gpuvWidth = Rectangle.Round(gpuv.GetBounds()).Width;
                gpuvWidth = gpuvWidth > 0 ? gpuvWidth : 1;
                int gpuvHeight = Rectangle.Round(gpuv.GetBounds()).Height;
                gpuvHeight = gpuvHeight > 0 ? gpuvHeight : 1;
                var shapeChunk = new Bitmap(gpuvWidth, gpuvHeight);

                int chunkX = Rectangle.Round(gpuv.GetBounds()).X;
                int chunkY = Rectangle.Round(gpuv.GetBounds()).Y;


                //bufferizing shape
                using (Graphics g = Graphics.FromImage(shapeChunk))
                {
                    //On conserve la qualité de l'image intacte
                    gpuv.Transform(new Matrix(1, 0, 0, 1, -chunkX, -chunkY));
                    g.SetClip(gpuv);
                    g.DrawImage(bitmap, -chunkX, -chunkY);
                }

                GraphicsPath gp = new GraphicsPath();
                gp.AddPolygon(new Point[] { new Point(0, 0), new Point(gpuvWidth, 0), new Point(0, gpuvHeight) });

                //Calculate transformation Matrix of UV
                //double[,] matrixArrayUV = { { polygonUV[0].X, polygonUV[1].X, polygonUV[2].X }, { polygonUV[0].Y, polygonUV[1].Y, polygonUV[2].Y }, { 1, 1, 1 } };
                double[,] matrixArrayUV = { { gpuv.PathPoints[0].X, gpuv.PathPoints[1].X, gpuv.PathPoints[2].X }, { gpuv.PathPoints[0].Y, gpuv.PathPoints[1].Y, gpuv.PathPoints[2].Y }, { 1, 1, 1 } };
                double[,] matrixArrayXY = { { polygonXY[0].X, polygonXY[1].X, polygonXY[2].X }, { polygonXY[0].Y, polygonXY[1].Y, polygonXY[2].Y }, { 1, 1, 1 } };
                var matrixUV = Matrix <double> .Build.DenseOfArray(matrixArrayUV);

                var matrixXY = Matrix <double> .Build.DenseOfArray(matrixArrayXY);

                var inverseMatrixUV = matrixUV.Inverse();
                var transformMatrix = matrixXY * inverseMatrixUV;
                var m = new Matrix((float)transformMatrix[0, 0], (float)transformMatrix[1, 0], (float)transformMatrix[0, 1], (float)transformMatrix[1, 1], (float)transformMatrix[0, 2], (float)transformMatrix[1, 2]);
                //var m = new Matrix((float)transformMatrix[0, 0], (float)transformMatrix[1, 0], (float)transformMatrix[0, 1], (float)transformMatrix[1, 1], (float)Math.Round(transformMatrix[0, 2]), (float)Math.Round(transformMatrix[1, 2]));

                //Perform transformations
                gp.Transform(m);

                using (Graphics g = Graphics.FromImage(finalShape))
                {
                    //g.InterpolationMode = InterpolationMode.NearestNeighbor;
                    //g.PixelOffsetMode = PixelOffsetMode.None;

                    //Set origin
                    Matrix originTransform = new Matrix();
                    originTransform.Translate(-x, -y);
                    g.Transform = originTransform;

                    g.DrawImage(shapeChunk, gp.PathPoints, gpuv.GetBounds(), System.Drawing.GraphicsUnit.Pixel);

                    if (options.ViewPolygons)
                    {
                        gpuv.Transform(m);
                        g.DrawPath(new Pen(Color.DarkGray, 1), gpuv);
                    }
                }
            }
            return(finalShape);
        }
Beispiel #5
0
 public virtual Bitmap Render(RenderingOptions options)
 {
     return(null);
 }
Beispiel #6
0
 public virtual Bitmap Render(RenderingOptions options)
 {
     return null;
 }
Beispiel #7
0
        public override Bitmap Render(RenderingOptions options)
        {
            Debug.WriteLine("Rendering chunk from shape " + m_vShapeId);
            Bitmap result = null;
            var texture = (Texture)m_vStorageObject.GetTextures()[m_vTextureId];
            if (texture != null)
            {
                Bitmap bitmap = texture.GetBitmap();

                Debug.WriteLine("Rendering polygon image of " + GetPointsUV().Count.ToString() + " points");
                foreach(PointF uv in GetPointsUV())
                {
                    Debug.WriteLine("u: " + uv.X + ", v: " + uv.Y);
                }
          
                GraphicsPath gpuv = new GraphicsPath();
                gpuv.AddPolygon(GetPointsUV().ToArray());

                int gpuvWidth = Rectangle.Round(gpuv.GetBounds()).Width;
                gpuvWidth = gpuvWidth > 0 ? gpuvWidth : 1;
                Debug.WriteLine("gpuvWidth: " + gpuvWidth);
                int gpuvHeight = Rectangle.Round(gpuv.GetBounds()).Height;
                gpuvHeight = gpuvHeight > 0 ? gpuvHeight : 1;
                Debug.WriteLine("gpuvHeight: " + gpuvHeight);
                var shapeChunk = new Bitmap(gpuvWidth, gpuvHeight);

                int chunkX = Rectangle.Round(gpuv.GetBounds()).X;
                int chunkY = Rectangle.Round(gpuv.GetBounds()).Y;
 
                //bufferizing shape
                using (Graphics g = Graphics.FromImage(shapeChunk))
                {
                    //On conserve la qualité de l'image intacte
                    gpuv.Transform(new Matrix(1, 0, 0, 1, -chunkX, -chunkY));
                    g.SetClip(gpuv);
                    g.DrawImage(bitmap, -chunkX, -chunkY);
                    if (options.ViewPolygons)
                        g.DrawPath(new Pen(Color.DarkGray, 2), gpuv); 
                }

                result = shapeChunk;
            }
            return result;
        }
Beispiel #8
0
        public override Bitmap Render(RenderingOptions options)
        {
            /*
            Debug.WriteLine("XY:");
            foreach(ShapeChunk chunk in m_vChunks)
            {
                foreach(var p in chunk.GetPointsXY())
                {
                    Debug.WriteLine("x: " + p.X + ", y: " + p.Y);
                }
                Debug.WriteLine("");
            }

            foreach (ShapeChunk chunk in m_vChunks)
            {
                foreach (var p in chunk.GetPointsUV())
                {
                    Debug.WriteLine("u: " + p.X + ", u: " + p.Y);
                }
                Debug.WriteLine("");
            }
            */

            Debug.WriteLine("Rendering image of " + m_vChunks.Count.ToString() + " polygons");

            //Calculate et initialize the final shape size
            List<PointF> pointsXY = m_vChunks.SelectMany(chunk => ((ShapeChunk)chunk).GetPointsXY()).ToList();
            GraphicsPath pathXY = new GraphicsPath();
            pathXY.AddPolygon(pointsXY.ToArray());
            int width = Rectangle.Round(pathXY.GetBounds()).Width;
            width = width > 0 ? width : 1;
            int height = Rectangle.Round(pathXY.GetBounds()).Height;
            height = height > 0 ? height : 1;
            int x = Rectangle.Round(pathXY.GetBounds()).X;
            int y = Rectangle.Round(pathXY.GetBounds()).Y;
            var finalShape = new Bitmap(width, height);

            //Assemble shape chunks
            foreach (ShapeChunk chunk in m_vChunks)
            {
                var texture = (Texture)m_vStorageObject.GetTextures()[chunk.GetTextureId()];
                Bitmap bitmap = texture.GetBitmap();

                var polygonUV = chunk.GetPointsUV();
                var polygonXY = chunk.GetPointsXY();
          
                GraphicsPath gpuv = new GraphicsPath();
                gpuv.AddPolygon(polygonUV.ToArray());

                GraphicsPath gpxy = new GraphicsPath();
                gpxy.AddPolygon(polygonXY.ToArray());

                int gpuvWidth = Rectangle.Round(gpuv.GetBounds()).Width;
                gpuvWidth = gpuvWidth > 0 ? gpuvWidth : 1;
                int gpuvHeight = Rectangle.Round(gpuv.GetBounds()).Height;
                gpuvHeight = gpuvHeight > 0 ? gpuvHeight : 1;
                var shapeChunk = new Bitmap(gpuvWidth, gpuvHeight);

                int chunkX = Rectangle.Round(gpuv.GetBounds()).X;
                int chunkY = Rectangle.Round(gpuv.GetBounds()).Y;

                    
                //bufferizing shape
                using (Graphics g = Graphics.FromImage(shapeChunk))
                {
                    //On conserve la qualité de l'image intacte
                    gpuv.Transform(new Matrix(1, 0, 0, 1, -chunkX, -chunkY));
                    g.SetClip(gpuv);
                    g.DrawImage(bitmap, -chunkX, -chunkY);
                }
  
                GraphicsPath gp = new GraphicsPath();
                gp.AddPolygon(new Point[] { new Point(0, 0), new Point(gpuvWidth, 0), new Point(0, gpuvHeight) });

                //Calculate transformation Matrix of UV
                //double[,] matrixArrayUV = { { polygonUV[0].X, polygonUV[1].X, polygonUV[2].X }, { polygonUV[0].Y, polygonUV[1].Y, polygonUV[2].Y }, { 1, 1, 1 } };
                double[,] matrixArrayUV = { { gpuv.PathPoints[0].X, gpuv.PathPoints[1].X, gpuv.PathPoints[2].X }, { gpuv.PathPoints[0].Y, gpuv.PathPoints[1].Y, gpuv.PathPoints[2].Y }, { 1, 1, 1 } };
                double[,] matrixArrayXY = { { polygonXY[0].X, polygonXY[1].X, polygonXY[2].X }, { polygonXY[0].Y, polygonXY[1].Y, polygonXY[2].Y }, { 1, 1, 1 } };
                var matrixUV = Matrix<double>.Build.DenseOfArray(matrixArrayUV);
                var matrixXY = Matrix<double>.Build.DenseOfArray(matrixArrayXY);
                var inverseMatrixUV = matrixUV.Inverse();
                var transformMatrix = matrixXY * inverseMatrixUV;
                var m = new Matrix((float)transformMatrix[0, 0], (float)transformMatrix[1, 0], (float)transformMatrix[0, 1], (float)transformMatrix[1, 1], (float)transformMatrix[0, 2], (float)transformMatrix[1, 2]);
                //var m = new Matrix((float)transformMatrix[0, 0], (float)transformMatrix[1, 0], (float)transformMatrix[0, 1], (float)transformMatrix[1, 1], (float)Math.Round(transformMatrix[0, 2]), (float)Math.Round(transformMatrix[1, 2]));

                //Perform transformations
                gp.Transform(m);

                using (Graphics g = Graphics.FromImage(finalShape))
                {
                    //g.InterpolationMode = InterpolationMode.NearestNeighbor;
                    //g.PixelOffsetMode = PixelOffsetMode.None;

                    //Set origin
                    Matrix originTransform = new Matrix();
                    originTransform.Translate(-x, -y);
                    g.Transform = originTransform;

                    g.DrawImage(shapeChunk, gp.PathPoints, gpuv.GetBounds(), System.Drawing.GraphicsUnit.Pixel);
                    
                    if (options.ViewPolygons)
                    {
                        gpuv.Transform(m);
                        g.DrawPath(new Pen(Color.DarkGray, 1), gpuv);  
                    }          
                }
            }
            return finalShape;
        }