Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public static IPolygon Union(List <IPolygon> polygons)
        {
            if (polygons.Count == 0)
            {
                return(null);
            }
            if (polygons.Count == 1)
            {
                return(polygons[0]);
            }

            /*
             * if (polygons.Count > 100)
             * {
             *  return polygons[0];
             * }
             */

            Clip_polygon union_polygon = new Clip_polygon();
            Clip_polygon polygon1      = ClipWrapper.PolygonTo_Clip_polygon(polygons[0]);

            try
            {
                for (int i = 1; i < polygons.Count; i++)
                {
                    union_polygon = new Clip_polygon();
                    Clip_polygon polygon2 = ClipWrapper.PolygonTo_Clip_polygon(polygons[i]);

                    ClipPolygon(ref polygon1, ref polygon2, ClipOperation.Union, ref union_polygon);
                    if (i == 1)
                    {
                        ClipWrapper.Free_Clip_polygon(polygon1);
                    }
                    else
                    {
                        ClipWrapper.FreePolygon(ref polygon1);
                    }
                    ClipWrapper.Free_Clip_polygon(polygon2);

                    polygon1 = union_polygon;
                }
                IPolygon polygon = ClipWrapper.Clip_polygon_ToPolygon(union_polygon);

                return(polygon);
            }
            finally
            {
                ClipWrapper.FreePolygon(ref union_polygon);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 6
0
        public static GeomTristrip PolygonToTristip(IPolygon polygon)
        {
            Clip_tristrip clip_strip = new Clip_tristrip();
            Clip_polygon  clip_pol   = ClipWrapper.PolygonTo_Clip_polygon(polygon);

            try
            {
                Polygon2Tristrip(ref clip_pol, ref clip_strip);
                GeomTristrip tristrip = ClipWrapper.Clip_strip_ToTristrip(clip_strip);

                return(tristrip);
            }
            finally
            {
                ClipWrapper.Free_Clip_polygon(clip_pol);
                ClipWrapper.FreeTristrip(ref clip_strip);
            }
        }
Ejemplo n.º 7
0
        public static GeomTristrip GeomPolygonToTristrip(GeomPolygon polygon)
        {
            Clip_tristrip Clip_strip = new Clip_tristrip();
            Clip_polygon  Clip_pol   = ClipWrapper.GeomPolygonTo_Clip_polygon(polygon);

            try
            {
                Polygon2Tristrip(ref Clip_pol, ref Clip_strip);
                GeomTristrip tristrip = ClipWrapper.Clip_strip_ToTristrip(Clip_strip);

                return(tristrip);
            }
            finally
            {
                ClipWrapper.Free_Clip_polygon(Clip_pol);
                ClipWrapper.FreeTristrip(ref Clip_strip);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public static IPolygon Clip(ClipOperation operation, IPolygon subject_polygon, IPolygon clip_polygon)
        {
            Clip_polygon Clip_polygon         = new Clip_polygon();
            Clip_polygon Clip_subject_polygon = ClipWrapper.PolygonTo_Clip_polygon(subject_polygon);
            Clip_polygon Clip_clip_polygon    = ClipWrapper.PolygonTo_Clip_polygon(clip_polygon);

            try
            {
                ClipPolygon(ref Clip_subject_polygon, ref Clip_clip_polygon, operation, ref Clip_polygon);
                IPolygon polygon = ClipWrapper.Clip_polygon_ToPolygon(Clip_polygon);

                return(polygon);
            }
            finally
            {
                ClipWrapper.Free_Clip_polygon(Clip_subject_polygon);
                ClipWrapper.Free_Clip_polygon(Clip_clip_polygon);
                ClipWrapper.FreePolygon(ref Clip_polygon);
            }
        }
Ejemplo n.º 10
0
        public static GeomTristrip ClipToTristrip(ClipOperation operation, GeomPolygon subject_polygon, GeomPolygon clip_polygon)
        {
            Clip_tristrip Clip_strip           = new Clip_tristrip();
            Clip_polygon  Clip_subject_polygon = ClipWrapper.GeomPolygonTo_Clip_polygon(subject_polygon);
            Clip_polygon  Clip_clip_polygon    = ClipWrapper.GeomPolygonTo_Clip_polygon(clip_polygon);

            try
            {
                ClipTristrip(ref Clip_subject_polygon, ref Clip_clip_polygon, operation, ref Clip_strip);
                GeomTristrip tristrip = ClipWrapper.Clip_strip_ToTristrip(Clip_strip);

                return(tristrip);
            }
            finally
            {
                ClipWrapper.Free_Clip_polygon(Clip_subject_polygon);
                ClipWrapper.Free_Clip_polygon(Clip_clip_polygon);
                ClipWrapper.FreeTristrip(ref Clip_strip);
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
Ejemplo n.º 13
0
 private static extern void FreePolygon([In] ref Clip_polygon polygon);
Ejemplo n.º 14
0
 private static extern void ClipTristrip([In]     ref Clip_polygon subject_polygon,
                                         [In]     ref Clip_polygon clip_polygon,
                                         [In]     ClipOperation set_operation,
                                         [In, Out] ref Clip_tristrip result_tristrip);
Ejemplo n.º 15
0
 private static extern void ClipPolygon([In]     ref Clip_polygon subject_polygon,
                                        [In]     ref Clip_polygon clip_polygon,
                                        [In]     ClipOperation set_operation,
                                        [In, Out] ref Clip_polygon result_polygon);
Ejemplo n.º 16
0
 private static extern void Polygon2Tristrip([In]     ref Clip_polygon polygon,
                                             [In, Out] ref Clip_tristrip tristrip);