示例#1
0
        private static IPolygon Clip_polygon_ToPolygon(Clip_polygon Clip_polygon)
        {
            Polygon polygon = new Polygon();

            if (Clip_polygon.num_contours == 0)
            {
                return(new Polygon());
            }

            short[] holeShort = new short[Clip_polygon.num_contours];
            Marshal.Copy(Clip_polygon.hole, holeShort, 0, Clip_polygon.num_contours);

            IntPtr ptr = Clip_polygon.contour;

            for (int i = 0; i < Clip_polygon.num_contours; i++)
            {
                Clip_vertex_list Clip_vtx_lst = (Clip_vertex_list)Marshal.PtrToStructure(ptr, typeof(Clip_vertex_list));
                IRing            ring         = ((holeShort[i] == 0) ? new Ring() : new Hole());

                IntPtr ptr2 = Clip_vtx_lst.vertex;
                for (int j = 0; j < Clip_vtx_lst.num_vertices; j++)
                {
                    Clip_vertex Clip_vtx = (Clip_vertex)Marshal.PtrToStructure(ptr2, typeof(Clip_vertex));
                    ring.AddPoint(new gView.Framework.Geometry.Point(
                                      Clip_vtx.x, Clip_vtx.y));

                    ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx)); //(IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx));
                }
                polygon.AddRing(ring);
                ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_lst)); //(IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_lst));
            }
            return(polygon);
        }
示例#2
0
        private static GeomTristrip Clip_strip_ToTristrip(Clip_tristrip Clip_strip)
        {
            GeomTristrip tristrip = new GeomTristrip();

            tristrip.NofStrips = Clip_strip.num_strips;
            tristrip.Strip     = new GeomVertexList[tristrip.NofStrips];
            IntPtr ptr = Clip_strip.strip;

            for (int i = 0; i < tristrip.NofStrips; i++)
            {
                tristrip.Strip[i] = new GeomVertexList();
                Clip_vertex_list Clip_vtx_list = (Clip_vertex_list)Marshal.PtrToStructure(ptr, typeof(Clip_vertex_list));
                tristrip.Strip[i].NofVertices = Clip_vtx_list.num_vertices;
                tristrip.Strip[i].Vertex      = new GeomVertex[tristrip.Strip[i].NofVertices];

                IntPtr ptr2 = Clip_vtx_list.vertex;
                for (int j = 0; j < tristrip.Strip[i].NofVertices; j++)
                {
                    Clip_vertex Clip_vtx = (Clip_vertex)Marshal.PtrToStructure(ptr2, typeof(Clip_vertex));
                    tristrip.Strip[i].Vertex[j].X = Clip_vtx.x;
                    tristrip.Strip[i].Vertex[j].Y = Clip_vtx.y;

                    ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx)); // (IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx));
                }
                ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_list));  // (IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_list));
            }

            return(tristrip);
        }
示例#3
0
        private static Clip_polygon PolygonTo_Clip_polygon(IPolygon polygon)
        {
            if (polygon == null || polygon.RingCount == 0)
            {
                return(new Clip_polygon());
            }

            int          RingCount = polygon.RingCount;
            Clip_polygon Clip_pol  = new Clip_polygon();

            Clip_pol.num_contours = RingCount;

            int[] hole = new int[RingCount];
            for (int i = 0; i < RingCount; i++)
            {
                hole[i] = ((polygon[i] is IHole) ? 1 : 0);
            }
            Clip_pol.hole = Marshal.AllocCoTaskMem(RingCount * Marshal.SizeOf(hole[0]));
            Marshal.Copy(hole, 0, Clip_pol.hole, hole.Length);

            Clip_pol.contour = Marshal.AllocCoTaskMem(RingCount * Marshal.SizeOf(new Clip_vertex_list()));
            IntPtr ptr = Clip_pol.contour;

            for (int i = 0; i < RingCount; i++)
            {
                Clip_vertex_list Clip_vtx_lst = new Clip_vertex_list();

                IRing ring       = polygon[i];
                int   PointCount = ring.PointCount;

                if (ring[0].X != ring[PointCount - 1].X ||
                    ring[0].Y != ring[PointCount - 1].Y)
                {
                    PointCount += 1;
                }

                Clip_vtx_lst.num_vertices = PointCount;
                Clip_vtx_lst.vertex       = Marshal.AllocCoTaskMem(PointCount * Marshal.SizeOf(new Clip_vertex()));
                IntPtr ptr2 = Clip_vtx_lst.vertex;
                for (int j = 0; j < PointCount; j++)
                {
                    IPoint      point    = ((j < ring.PointCount) ? ring[j] : ring[0]);
                    Clip_vertex Clip_vtx = new Clip_vertex();
                    Clip_vtx.x = point.X;
                    Clip_vtx.y = point.Y;
                    Marshal.StructureToPtr(Clip_vtx, ptr2, false);
                    ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx));// (IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx));
                }

                Marshal.StructureToPtr(Clip_vtx_lst, ptr, false);
                ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_lst)); //(IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_lst));
            }

            return(Clip_pol);
        }
示例#4
0
        private static void Free_Clip_polygon(Clip_polygon Clip_pol)
        {
            Marshal.FreeCoTaskMem(Clip_pol.hole);
            IntPtr ptr = Clip_pol.contour;

            for (int i = 0; i < Clip_pol.num_contours; i++)
            {
                Clip_vertex_list Clip_vtx_list = (Clip_vertex_list)Marshal.PtrToStructure(ptr, typeof(Clip_vertex_list));
                Marshal.FreeCoTaskMem(Clip_vtx_list.vertex);
                ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_list)); //(IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_list));
            }
            Marshal.FreeCoTaskMem(Clip_pol.contour);
        }
示例#5
0
        public static IPolygon BufferPath(IPath path, double distance)
        {
            Clip_vertex_list vtx_lst        = PathTo_Clip_vertex_list(path);
            Clip_polygon     buffer_polygon = new Clip_polygon();

            try
            {
                BufferVertextList(ref vtx_lst, distance, BufferOperation.Buffer_LINES, ref buffer_polygon);
                IPolygon polygon = ClipWrapper.Clip_polygon_ToPolygon(buffer_polygon);

                return(polygon);
            }
            finally
            {
                ClipWrapper.Free_Clip_polygon(buffer_polygon);
                ClipWrapper.Free_Clip_vertex_list(vtx_lst);
            }
        }
示例#6
0
        private static GeomPolygon Clip_polygon_ToGeomPolygon(Clip_polygon Clip_polygon)
        {
            GeomPolygon polygon = new GeomPolygon();

            polygon.NofContours = Clip_polygon.num_contours;
            if (polygon.NofContours == 0)
            {
                return(new GeomPolygon());
            }

            polygon.ContourIsHole = new bool[polygon.NofContours];
            polygon.Contour       = new GeomVertexList[polygon.NofContours];
            short[] holeShort = new short[polygon.NofContours];
            IntPtr  ptr       = Clip_polygon.hole;

            Marshal.Copy(Clip_polygon.hole, holeShort, 0, polygon.NofContours);

            for (int i = 0; i < polygon.NofContours; i++)
            {
                polygon.ContourIsHole[i] = (holeShort[i] != 0);
            }

            ptr = Clip_polygon.contour;
            for (int i = 0; i < polygon.NofContours; i++)
            {
                Clip_vertex_list Clip_vtx_list = (Clip_vertex_list)Marshal.PtrToStructure(ptr, typeof(Clip_vertex_list));
                polygon.Contour[i]             = new GeomVertexList();
                polygon.Contour[i].NofVertices = Clip_vtx_list.num_vertices;
                polygon.Contour[i].Vertex      = new GeomVertex[polygon.Contour[i].NofVertices];
                IntPtr ptr2 = Clip_vtx_list.vertex;
                for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                {
                    Clip_vertex Clip_vtx = (Clip_vertex)Marshal.PtrToStructure(ptr2, typeof(Clip_vertex));
                    polygon.Contour[i].Vertex[j].X = Clip_vtx.x;
                    polygon.Contour[i].Vertex[j].Y = Clip_vtx.y;

                    ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx)); //(IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx));
                }
                ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_list));  //(IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_list));
            }

            return(polygon);
        }
示例#7
0
        /*
         *      public static void SavePolygon( string filename, bool writeHoleFlags, GeomPolygon polygon )
         *      {
         *              Clip_polygon Clip_polygon = ClipWrapper.PolygonTo_Clip_polygon( polygon );
         *
         *              IntPtr fp = fopen( filename, "wb" );
         *              Clip_write_polygon( fp, writeHoleFlags?((int)1):((int)0), ref Clip_polygon );
         *              fclose( fp );
         *
         *              ClipWrapper.Free_Clip_polygon( Clip_polygon );
         *      }
         *
         *      public static GeomPolygon ReadPolygon( string filename, bool readHoleFlags )
         *      {
         *              Clip_polygon Clip_polygon = new Clip_polygon();
         *
         *              IntPtr fp = fopen( filename, "rb" );
         *              Clip_read_polygon( fp, readHoleFlags?((int)1):((int)0), ref Clip_polygon );
         *              GeomPolygon polygon = Clip_polygon_ToPolygon( Clip_polygon );
         *              FreePolygon( ref Clip_polygon );
         *              fclose( fp );
         *
         *              return polygon;
         *      }
         * */

        private static Clip_polygon GeomPolygonTo_Clip_polygon(GeomPolygon polygon)
        {
            Clip_polygon Clip_pol = new Clip_polygon();

            Clip_pol.num_contours = polygon.NofContours;

            int[] hole = new int[polygon.NofContours];
            for (int i = 0; i < polygon.NofContours; i++)
            {
                hole[i] = (polygon.ContourIsHole[i] ? 1 : 0);
            }
            Clip_pol.hole = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(hole[0]));
            Marshal.Copy(hole, 0, Clip_pol.hole, polygon.NofContours);

            Clip_pol.contour = Marshal.AllocCoTaskMem(polygon.NofContours * Marshal.SizeOf(new Clip_vertex_list()));
            IntPtr ptr = Clip_pol.contour;

            for (int i = 0; i < polygon.NofContours; i++)
            {
                Clip_vertex_list Clip_vtx_list = new Clip_vertex_list();
                Clip_vtx_list.num_vertices = polygon.Contour[i].NofVertices;
                Clip_vtx_list.vertex       = Marshal.AllocCoTaskMem(polygon.Contour[i].NofVertices * Marshal.SizeOf(new Clip_vertex()));
                IntPtr ptr2 = Clip_vtx_list.vertex;
                for (int j = 0; j < polygon.Contour[i].NofVertices; j++)
                {
                    Clip_vertex Clip_vtx = new Clip_vertex();
                    Clip_vtx.x = polygon.Contour[i].Vertex[j].X;
                    Clip_vtx.y = polygon.Contour[i].Vertex[j].Y;
                    Marshal.StructureToPtr(Clip_vtx, ptr2, false);
                    ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx)); // (IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx));
                }
                Marshal.StructureToPtr(Clip_vtx_list, ptr, false);
                ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_list)); //(IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_list));
            }

            return(Clip_pol);
        }
示例#8
0
        private static Clip_vertex_list PathTo_Clip_vertex_list(IPath path)
        {
            if (path == null)
            {
                return(new Clip_vertex_list());
            }

            Clip_vertex_list Clip_vtx_lst = new Clip_vertex_list();
            int PointCount = path.PointCount;

            if (path is IRing)
            {
                if (path[0].X != path[PointCount - 1].X ||
                    path[0].Y != path[PointCount - 1].Y)
                {
                    PointCount += 1;
                }
            }

            Clip_vtx_lst.num_vertices = PointCount;
            Clip_vtx_lst.vertex       = Marshal.AllocCoTaskMem(PointCount * Marshal.SizeOf(new Clip_vertex()));

            IntPtr ptr2 = Clip_vtx_lst.vertex;

            for (int j = 0; j < PointCount; j++)
            {
                IPoint      point    = ((j < path.PointCount) ? path[j] : path[0]);
                Clip_vertex Clip_vtx = new Clip_vertex();
                Clip_vtx.x = point.X;
                Clip_vtx.y = point.Y;
                Marshal.StructureToPtr(Clip_vtx, ptr2, false);
                ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx)); //(IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx));
            }

            return(Clip_vtx_lst);
        }
示例#9
0
 private static extern void BufferVertextList([In]   ref Clip_vertex_list vtx_list,
                                              [In]   double distance,
                                              [In]   BufferOperation buffer_op,
                                              [In, Out] ref Clip_polygon result_polygon);
示例#10
0
 private static void Free_Clip_vertex_list(Clip_vertex_list Clip_vtx_list)
 {
     Marshal.FreeCoTaskMem(Clip_vtx_list.vertex);
 }