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);
        }
        private void storePlatesTPI()
        {
            // initial
            // 3 for polygon id, 3 for 3 tri side id. use the number to compare if polygon is clockwise.
            int[] triIndex = new int[6] {
                -1, -1, -1, -1, -1, -1
            };

            // construct center pt
            for (int i = 0; i < iSpringMesh.Triangles.Count; i++)
            {
                topCenterPts.Add(iSpringMesh.ComputeTriangleCentroid(i));
                bottomCenterPts.Add(iSpringMesh.ComputeTriangleCentroid(i));
                topCenterPolygonOccupied.Add(false);    // to see if triangle be occupied by polygon

                int[] copy = (int[])triIndex.Clone();   // have to copy array otherwise it's reference type it will change all
                indexSortPolygon.Add(copy);
            }


            // compare center pt with TPI
            // get discontinuity points
            for (int i = 0; i < iPolyLine.Count; i++)
            {
                Curve  c = iPolyLine[i];
                double t;
                double start   = c.Domain.Min;
                int    counter = 0;
                while (c.GetNextDiscontinuity(Continuity.C1_locus_continuous, start, c.Domain.Max, out t))
                {
                    //oInfo += "outsider i = " + i.ToString() + "\n";
                    start = t;
                    Point3d pt = c.PointAt(t);
                    if (i < iPolyLine.Count / 2)
                    {
                        Point3d closestPt = Point3dList.ClosestPointInList(topCenterPts, pt);
                        int     index     = topCenterPts.IndexOf(closestPt);
                        topCenterPts[index]             = pt;
                        topCenterPolygonOccupied[index] = true; // set occupied status

                        // sort triangle id ///////////////////////////////////////
                        //oInfo += "index = " + index.ToString() + "\n";
                        for (int j = 0; j < 3; j++)
                        {
                            //oInfo += "in for loop \n";
                            if (indexSortPolygon[index][j] == -1)
                            {
                                //oInfo += "indexP " + indexSortPolygon[index][j] + "\n";
                                //oInfo += "indexP " + indexSortPolygon[index][j + 3] + "\n";

                                //oInfo += "j = " + j.ToString() + "\n";
                                //oInfo += "i = " + i.ToString() + "\n";

                                indexSortPolygon[index][j]     = i;
                                indexSortPolygon[index][j + 3] = counter;

                                //oInfo += "indexP " + indexSortPolygon[index][j] + "\n";
                                //oInfo += "indexP " + indexSortPolygon[index][j + 3] + "\n";

                                break;
                            }
                        }
                        counter++;
                        //oInfo += "counter = " + counter.ToString() + "\n";
                        //oInfo += "================= \n";
                        /////////////////////////////////////////////////////////////
                    }
                    else
                    {
                        Point3d closestPt = Point3dList.ClosestPointInList(bottomCenterPts, pt);
                        int     index     = bottomCenterPts.IndexOf(closestPt);
                        bottomCenterPts[index] = pt;
                    }
                }
            }
            foreach (Point3d p in topCenterPts)
            {
                oDebugList.Add(p);
            }
            foreach (Point3d p in bottomCenterPts)
            {
                oDebugList.Add(p);
            }

            // debug

            /*
             * foreach (int[] ip in indexSortPolygon)
             *  oInfo += ip[0].ToString() + ", " +
             *           ip[1].ToString() + ", " +
             *           ip[2].ToString() + ", " +
             *           ip[3].ToString() + ", " +
             *           ip[4].ToString() + ", " +
             *           ip[5].ToString() + "\n";*/
        }
Ejemplo n.º 4
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;
                        }
                    }
                }
            }
        }