Esempio n. 1
0
        // no cuts
        private void Generate_polygon_cuts_()
        {
            com.epl.geometry.AttributeStreamOfInt32 cutHandles = new com.epl.geometry.AttributeStreamOfInt32(0);
            com.epl.geometry.EditShape shape = new com.epl.geometry.EditShape();
            int sideIndex    = shape.CreateGeometryUserIndex();
            int cutteeHandle = shape.AddGeometry(m_cuttee);
            int cutterHandle = shape.AddGeometry(m_cutter);

            com.epl.geometry.TopologicalOperations topoOp = new com.epl.geometry.TopologicalOperations();
            try
            {
                topoOp.SetEditShapeCrackAndCluster(shape, m_tolerance, m_progressTracker);
                topoOp.Cut(sideIndex, cutteeHandle, cutterHandle, cutHandles);
                com.epl.geometry.Polygon   cutteeRemainder = (com.epl.geometry.Polygon)shape.GetGeometry(cutteeHandle);
                com.epl.geometry.MultiPath left            = new com.epl.geometry.Polygon();
                com.epl.geometry.MultiPath right           = new com.epl.geometry.Polygon();
                m_cuts.Clear();
                m_cuts.Add(left);
                m_cuts.Add(right);
                for (int icutIndex = 0; icutIndex < cutHandles.Size(); icutIndex++)
                {
                    com.epl.geometry.Geometry cutGeometry;
                    {
                        // intersection
                        com.epl.geometry.EditShape shapeIntersect = new com.epl.geometry.EditShape();
                        int geometryA = shapeIntersect.AddGeometry(cutteeRemainder);
                        int geometryB = shapeIntersect.AddGeometry(shape.GetGeometry(cutHandles.Get(icutIndex)));
                        topoOp.SetEditShape(shapeIntersect, m_progressTracker);
                        int intersectHandle = topoOp.Intersection(geometryA, geometryB);
                        cutGeometry = shapeIntersect.GetGeometry(intersectHandle);
                        if (cutGeometry.IsEmpty())
                        {
                            continue;
                        }
                        int side = shape.GetGeometryUserIndex(cutHandles.Get(icutIndex), sideIndex);
                        if (side == 2)
                        {
                            left.Add((com.epl.geometry.MultiPath)cutGeometry, false);
                        }
                        else
                        {
                            if (side == 1)
                            {
                                right.Add((com.epl.geometry.MultiPath)cutGeometry, false);
                            }
                            else
                            {
                                m_cuts.Add((com.epl.geometry.MultiPath)cutGeometry);
                            }
                        }
                    }
                    {
                        // Undefined
                        // difference
                        com.epl.geometry.EditShape shapeDifference = new com.epl.geometry.EditShape();
                        int geometryA = shapeDifference.AddGeometry(cutteeRemainder);
                        int geometryB = shapeDifference.AddGeometry(shape.GetGeometry(cutHandles.Get(icutIndex)));
                        topoOp.SetEditShape(shapeDifference, m_progressTracker);
                        cutteeRemainder = (com.epl.geometry.Polygon)shapeDifference.GetGeometry(topoOp.Difference(geometryA, geometryB));
                    }
                }
                if (!cutteeRemainder.IsEmpty() && cutHandles.Size() > 0)
                {
                    m_cuts.Add((com.epl.geometry.MultiPath)cutteeRemainder);
                }
                if (left.IsEmpty() && right.IsEmpty())
                {
                    m_cuts.Clear();
                }
            }
            finally
            {
                // no cuts
                topoOp.RemoveShape();
            }
        }