示例#1
0
        public override bool Execute()
        {
            Ensure.AreEqual(Dependency[0].Integer % 3, 1);
            while (Dependency[0].Integer != Dependency.Count - 1)
            {
                AddDependency(InterpreterNames.Point3D);
            }
            var pointList = new Point3D[4];
            var items     = Dependency[0].Integer;

            var compoundShape = new TopoDSCompound();
            var shapeBuilder  = new BRepBuilder();

            shapeBuilder.MakeCompound(compoundShape);
            var startIndex = 0;

            while (startIndex < items - 1)
            {
                pointList[0] = Dependency[startIndex + 1].TransformedPoint3D;
                pointList[1] = Dependency[startIndex + 2].TransformedPoint3D;
                pointList[2] = Dependency[startIndex + 3].TransformedPoint3D;
                pointList[3] = Dependency[startIndex + 4].TransformedPoint3D;

                var shape = SplineUtils.BuildSplineWire(pointList);
                shapeBuilder.Add(compoundShape, shape);
                startIndex += 3;
            }

            Shape = compoundShape;

            return(true);
        }
        public static TriangleMesh Process(TopoDSShape shapeFused)
        {
            var result  = new TriangleMesh();
            var builder = new BRepBuilder();
            var comp    = new TopoDSCompound();

            builder.MakeCompound(comp);
            BRepMesh.Mesh(shapeFused, 1);
            var ex = new TopExpExplorer(shapeFused,
                                        TopAbsShapeEnum.TopAbs_FACE,
                                        TopAbsShapeEnum.TopAbs_SHAPE);

            while (ex.More)
            {
                var shapeResult = new TriangleMesh();
                var face        = TopoDS.Face(ex.Current);
                var location    = new TopLocLocation();
                var facing      = BRepTool.Triangulation(face, location);
                var tab         = new TColgpArray1OfPnt(1, facing.NbNodes);
                //  facing.Nodes(tab);
                var tri = new PolyArray1OfTriangle(1, facing.NbTriangles);
                //  facing.Triangles(tri);
                var triCount   = facing.NbTriangles;
                var listPoints = new List <Point3D>();
                for (var i = 1; i <= triCount; i++)
                {
                    var trian = tri.Value(i);
                    int index1 = 0, index2 = 0, index3 = 0;
                    trian.Get(ref index1, ref index2, ref index3);

                    var firstPoint  = new Point3D(tab.Value(index1));
                    var secondPoint = new Point3D(tab.Value(index2));
                    var thirdPoint  = new Point3D(tab.Value(index3));
                    listPoints.Add(firstPoint);
                    listPoints.Add(secondPoint);
                    listPoints.Add(thirdPoint);
                }
                shapeResult.Points.Clear();
                foreach (var point in listPoints)
                {
                    shapeResult.Points.Add(point);
                }
                shapeResult.Points = GeomUtils.SortAndCompactListPoints(shapeResult.Points);
                var triangleIndex = 0;
                var triangleArray = new int[3];
                foreach (var point in listPoints)
                {
                    triangleArray[triangleIndex] = shapeResult.ComputePointId(point);
                    triangleIndex = (triangleIndex + 1) % 3;
                    if (triangleIndex == 0)
                    {
                        shapeResult.AddTriangle(triangleArray);
                    }
                }
                ex.Next();
                result = result.Combine(shapeResult);
            }
            return(result);
        }
示例#3
0
        /// <summary>
        ///   Cuts through all childs of the node with the TopoDS_Shape passed as parameter.
        ///   It returns a compund made from the affected shapes
        /// </summary>
        /// <param name = "nodes"></param>
        /// <param name = "cutPrismShape"></param>
        private static TopoDSShape CutThroughAll(IEnumerable <SceneSelectedEntity> nodes, TopoDSShape cutPrismShape)
        {
            var compoundShape = new TopoDSCompound();
            var shapeBuilder  = new BRepBuilder();

            shapeBuilder.MakeCompound(compoundShape);
            var resShape = (TopoDSShape)compoundShape;

            foreach (var cutShape in nodes)
            {
                var childNode = cutShape.Node;
                // Try to Cut through the object
                var topoShape = childNode.Get <NamedShapeInterpreter>().Shape;
                if (topoShape == null)
                {
                    continue;
                }
                var cut = new BRepAlgoAPICut(topoShape, cutPrismShape);
                // Check if the shape was altered by the Cut
                if ((cut.HasGenerated == false) && (cut.HasModified == false))
                {
                    continue;
                }

                TopoDSShape shapeCut = null;
                try
                {
                    shapeCut = cut.Shape;
                }
                catch (Exception)
                {
                    Log.Info("Exception on create cut shape");
                }

                if ((shapeCut != null) && (!shapeCut.IsNull))
                {
                    // Show the new shape as a new Node
                    shapeBuilder.Add(resShape, shapeCut);
                }
            }

            return(resShape);
        }
        public override bool Execute()
        {
            if (Dependency.Count < 2)
            {
                return(false);
            }
            var compoundShape = new TopoDSCompound();
            var shapeBuilder  = new BRepBuilder();

            shapeBuilder.MakeCompound(compoundShape);
            var resShape     = (TopoDSShape)compoundShape;
            var isFirstPoint = true;
            var second       = new Point3D();

            foreach (var childNode in Dependency.Children)
            {
                var point3D = childNode.TransformedPoint3D;
                if (isFirstPoint)
                {
                    second       = point3D;
                    isFirstPoint = false;
                    continue;
                }
                var first = second;
                second = point3D;
                var shapeCut = CreateLine(first, second);
                if (shapeCut != null)
                {
                    shapeBuilder.Add(resShape, shapeCut);
                }
            }

            Shape = resShape;

            return(true);
        }
示例#5
0
 public static void Update(TopoDSCompound C)
 {
     BRepTools_UpdateF7963FEC(C.Instance);
 }
示例#6
0
        /// <summary>
        ///   Cuts through all childs of the node with the TopoDS_Shape passed as parameter.
        ///   It returns a compund made from the affected shapes
        /// </summary>
        /// <param name = "root"></param>
        /// <param name = "cutPrismShape"></param>
        /// <param name = "affectedNodes"></param>
        /// <param name = "shapeList"></param>
        private static TopoDSShape CutThroughAll(Node root, TopoDSShape cutPrismShape,
                                                 ICollection <SceneSelectedEntity> affectedNodes,
                                                 IEnumerable <int> shapeList)
        {
            var compoundShape = new TopoDSCompound();
            var shapeBuilder  = new BRepBuilder();

            shapeBuilder.MakeCompound(compoundShape);
            var resShape = (TopoDSShape)compoundShape;

            foreach (var childNodeIndex in shapeList)
            {
                var childNode = new NodeBuilder(root[childNodeIndex]);

                var topoShape = childNode.Shape;
                if (topoShape == null)
                {
                    continue;
                }
                BRepAlgoAPICut cut;
                var            filler = new BOPToolsDSFiller();
                try
                {
                    filler.SetShapes(topoShape, cutPrismShape);
                    if (!filler.IsDone)
                    {
                        continue;
                    }
                    filler.Perform();
                    cut = new BRepAlgoAPICut(topoShape, cutPrismShape, filler, true);
                    if (!cut.IsDone)
                    {
                        continue;
                    }
                    // Check if the shape was altered by the Cut
                    //if ((cut.HasGenerated == false) && (cut.HasModified == false))
                    //    continue;
                }
                catch (Exception)
                {
                    continue;
                }

                TopoDSShape shapeCut = null;
                try
                {
                    shapeCut = cut.Shape;
                }
                catch (Exception)
                {
                    Log.Info("Exception on create cut shape");
                }

                if ((shapeCut == null) || (shapeCut.IsNull))
                {
                    continue;
                }
                // If Cut succeeded hide the original shape
                NodeUtils.Hide(childNode.Node);
                // Show the new shape as a new Node
                shapeBuilder.Add(resShape, shapeCut);
                // Add the affceted node into the affectedNodes list
                affectedNodes.Add(new SceneSelectedEntity(childNode.Node));
            }

            return(resShape);
        }