private void plate()
        {
            //vertex thickness value
            List <double> thickness = new List <double>();

            foreach (Vertex vertex in iSpringMesh.Vertices)
            {
                thickness.Add(0.5);
            }

            List <List <LineCurve> > dualVertices = new List <List <LineCurve> >();

            for (int i = 0; i < iSpringMesh.Vertices.Count; i++)
            {
                dualVertices.Add(new List <LineCurve>());
            }

            foreach (Edge edge in iSpringMesh.Edges)
            {
                if (edge.SecondTriangleIndex >= 0)
                {
                    int firstVertexIndex    = edge.FirstVertexIndex;
                    int secondVertexIndex   = edge.SecondVertexIndex;
                    int firstTriangleIndex  = edge.FirstTriangleIndex;
                    int secondTriangleIndex = edge.SecondTriangleIndex;

                    //Point3d firstTPI = iSpringMesh.ComputeDoubleLayerTPI(firstTriangleIndex, thickness);
                    //Point3d secondTPI = iSpringMesh.ComputeDoubleLayerTPI(secondTriangleIndex, thickness);

                    Point3d firstTPI  = iSpringMesh.ComputeTPI(firstTriangleIndex);
                    Point3d secondTPI = iSpringMesh.ComputeTPI(secondTriangleIndex);

                    Point3d firstCenterPt  = iSpringMesh.ComputeTriangleCentroid(firstTriangleIndex);
                    Point3d secondCenterPt = iSpringMesh.ComputeTriangleCentroid(secondTriangleIndex);

                    if (ICD.Utils.Distance(firstTPI, firstCenterPt) < iMaxThickness &&
                        ICD.Utils.Distance(secondTPI, secondCenterPt) < iMaxThickness)
                    {
                        dualVertices[firstVertexIndex].Add(new LineCurve(firstTPI, secondTPI));
                        dualVertices[secondVertexIndex].Add(new LineCurve(firstTPI, secondTPI));
                    }
                }
                else
                {
                }
            }


            for (int i = 0; i < iSpringMesh.Vertices.Count; i++)
            {
                if (dualVertices[i].Count == iSpringMesh.Vertices[i].NeighborVertexIndices.Count)
                {
                    Curve dualcurve = Curve.JoinCurves(dualVertices[i])[0];
                    oDebugCurves1.Add(dualcurve);
                }
            }
        }
        private List <double> checkCoplanarity(SpringMesh sMesh, double thickness, List <Line> linesUp, List <Line> linesDown)
        {
            List <double> coplanarity = new List <double>();

            foreach (Edge edge in sMesh.Edges)
            {
                if (edge.SecondTriangleIndex >= 0)
                {
                    int triLeft  = edge.FirstTriangleIndex;
                    int triRight = edge.SecondTriangleIndex;

                    Point3d centreLeftO  = sMesh.ComputeTriangleCentroid(triLeft);
                    Point3d centreRightO = sMesh.ComputeTriangleCentroid(triRight);

                    Point3d centreLeft  = sMesh.ComputeTPI(triLeft);
                    Point3d centreRight = sMesh.ComputeTPI(triRight);

                    if (ICD.Utils.Distance(centreLeftO, centreLeft) < iMaxThickness && ICD.Utils.Distance(centreRightO, centreRight) < iMaxThickness)
                    {
                        Vector3d normalLeft  = sMesh.ComputeTriangleNormal(triLeft);
                        Vector3d normalRight = sMesh.ComputeTriangleNormal(triRight);

                        Point3d centreLeftUp  = centreLeft + normalLeft * thickness;
                        Point3d centreRightUp = centreRight + normalRight * thickness;

                        Point3d centreLeftDown  = centreLeft - normalLeft * thickness;
                        Point3d centreRightDown = centreRight - normalRight * thickness;

                        linesUp.Add(new Line(centreLeftUp, centreRightUp));
                        linesDown.Add(new Line(centreLeftDown, centreRightDown));

                        Line planarCheckLine01 = new Line(centreLeftUp, centreRightDown);
                        Line planarCheckLine02 = new Line(centreRightUp, centreLeftDown);

                        double dist = planarCheckLine01.MinimumDistanceTo(planarCheckLine02);
                        coplanarity.Add(dist);
                    }
                }
            }
            return(coplanarity);
        }
示例#3
0
        public void DualTPI(bool flip)
        {
            List <List <LineCurve> > dualVertices = new List <List <LineCurve> >();

            for (int i = 0; i < oSpringMesh.Vertices.Count; i++)
            {
                dualVertices.Add(new List <LineCurve>());
            }

            ////// this is to create planar plate
            foreach (Edge edge in oSpringMesh.Edges)
            {
                if (edge.SecondTriangleIndex >= 0)
                {
                    int firstVertexIndex    = edge.FirstVertexIndex;
                    int secondVertexIndex   = edge.SecondVertexIndex;
                    int firstTriangleIndex  = edge.FirstTriangleIndex;
                    int secondTriangleIndex = edge.SecondTriangleIndex;

                    Point3d firstTPI  = oSpringMesh.ComputeDoubleLayerTPI(firstTriangleIndex, othickness, flip, iPlatesOffset);
                    Point3d secondTPI = oSpringMesh.ComputeDoubleLayerTPI(secondTriangleIndex, othickness, flip, iPlatesOffset);

                    Point3d firstTPIO       = oSpringMesh.ComputeTPI(firstTriangleIndex);
                    Point3d secondTPIO      = oSpringMesh.ComputeTPI(secondTriangleIndex);
                    Point3d firstCenterPtO  = oSpringMesh.ComputeTriangleCentroid(firstTriangleIndex);
                    Point3d secondCenterPtO = oSpringMesh.ComputeTriangleCentroid(secondTriangleIndex);

                    Point3d firstCenterPt;
                    Point3d secondCenterPt;

                    if (!flip)
                    {
                        firstCenterPt = oSpringMesh.ComputeTriangleCentroid(firstTriangleIndex) +
                                        oSpringMesh.ComputeTriangleNormal(firstTriangleIndex);
                        secondCenterPt = oSpringMesh.ComputeTriangleCentroid(secondTriangleIndex) +
                                         oSpringMesh.ComputeTriangleNormal(secondTriangleIndex);
                    }
                    else
                    {
                        firstCenterPt = oSpringMesh.ComputeTriangleCentroid(firstTriangleIndex) -
                                        oSpringMesh.ComputeTriangleNormal(firstTriangleIndex);
                        secondCenterPt = oSpringMesh.ComputeTriangleCentroid(secondTriangleIndex) -
                                         oSpringMesh.ComputeTriangleNormal(secondTriangleIndex);
                    }

                    // ===========================================================================
                    // Added 14/06/2015 to make some tolerance for plates

                    Circle firstCircle  = oSpringMesh.ComputeDoubleLayerIncircle(firstTriangleIndex, iPlatesThreadsP, othickness, flip, iPlatesOffset);
                    Circle secondCircle = oSpringMesh.ComputeDoubleLayerIncircle(secondTriangleIndex, iPlatesThreadsP, othickness, flip, iPlatesOffset);

                    //Circle firstCircle = oSpringMesh.ComputeDoubleLayerCircumscribedCircle(firstTriangleIndex, iPlatesThreadsP, othickness, flip, iPlatesOffset);
                    //Circle secondCircle = oSpringMesh.ComputeDoubleLayerCircumscribedCircle(secondTriangleIndex, iPlatesThreadsP, othickness, flip, iPlatesOffset);

                    Circle firstCircleO  = oSpringMesh.ComputeIncircle(firstTriangleIndex, iPlatesThreadsP); // iPlatesThreads = 0.0-1.0
                    Circle secondCircleO = oSpringMesh.ComputeIncircle(secondTriangleIndex, iPlatesThreadsP);

                    Plane firstPO  = oSpringMesh.ComputePlane(firstTriangleIndex);
                    Plane secondPO = oSpringMesh.ComputePlane(secondTriangleIndex);

                    Point3d projectFirstTPIO  = firstPO.ClosestPoint(firstTPIO);
                    Point3d projectSecondTPIO = secondPO.ClosestPoint(secondTPIO);


                    Point3d newFirstTPI  = firstCircle.ClosestPoint(firstTPI);
                    Point3d newSecondTPI = secondCircle.ClosestPoint(secondTPI);

                    // manuel selected plates
                    foreach (int id in iID)
                    {
                        if (id == firstVertexIndex)
                        {
                            dualVertices[firstVertexIndex].Add(new LineCurve(newFirstTPI, newSecondTPI));
                        }
                        if (id == secondVertexIndex)
                        {
                            dualVertices[secondVertexIndex].Add(new LineCurve(newFirstTPI, newSecondTPI));
                        }
                    }
                    // auto generated plates
                    if (ICD.Utils.Distance(projectFirstTPIO, firstCenterPtO) < iPlatesThreads &&
                        ICD.Utils.Distance(projectSecondTPIO, secondCenterPtO) < iPlatesThreads &&
                        iAutoGenPlates && !iID.Contains(firstVertexIndex) && !iID.Contains(secondVertexIndex))
                    {
                        dualVertices[firstVertexIndex].Add(new LineCurve(newFirstTPI, newSecondTPI));
                        dualVertices[secondVertexIndex].Add(new LineCurve(newFirstTPI, newSecondTPI));
                    }
                }
                else
                {
                }
            }

            int counter = -1;

            for (int i = 0; i < oSpringMesh.Vertices.Count; i++)
            {
                // if is close and all right
                if (dualVertices[i].Count == oSpringMesh.Vertices[i].NeighborVertexIndices.Count &&
                    !iID.Contains(i))
                {
                    Curve dualcurve = Curve.JoinCurves(dualVertices[i])[0];

                    oInfo += dualcurve.IsClosed.ToString() + "\n";

                    if (dualcurve.IsClosed)
                    {
                        oPolyLine.Add(dualcurve);
                        counter++;
                        // change the vertex staus to be occupied
                        oVertexStatus[i] = true;
                        oPolyLineID[i]   = counter;
                    }
                }
                // manuel selected plate
                foreach (int id in iID)
                {
                    if (id == i)
                    {
                        Curve dualcurve = Curve.JoinCurves(dualVertices[i])[0];
                        if (dualcurve.IsClosed)
                        {
                            oPolyLine.Add(dualcurve);
                            counter++;
                            // change the vertex staus to be occupied
                            oVertexStatus[i] = true;
                            oPolyLineID[i]   = counter;
                        }
                    }
                }
            }
        }