public void CreateQuadTessellation(OutputMesh builder, int internalsIndex, int facesIndex,
                                           CPNPolygon polygon)
        {
            /*---- SPECIAL CASES  ----*/
            if (DealWithSpecialCases(builder, facesIndex, polygon))
            {
                return;
            }

            CPNSideEdge[] polylines             = polygon.sideEdges;
            int           trPosition            = facesIndex;
            int           innerVerticesPosition = internalsIndex;

            //Internal Quads -- Pretty Straightforward
            for (int i = 0; i < MV - 2; i++)
            {
                int rowPosition1 = innerVerticesPosition + (i) * (MH - 1);
                int rowPosition2 = innerVerticesPosition + (i + 1) * (MH - 1);

                for (int j = 0; j < MH - 2; j++)
                {
                    trPosition = builder.WriteQuad(trPosition, rowPosition1 + j, rowPosition1 + j + 1,
                                                   rowPosition2 + j + 1, rowPosition2 + j);
                }
            }

            UpdateSides(builder, polygon, trPosition, innerVerticesPosition);
        }
        private bool DealWithSpecialCases(OutputMesh builder, int facesIndex,
                                          CPNPolygon polygon)
        {
            CPNSideEdge[] polylines = polygon.sideEdges;
            /*---- SPECIAL CASES  ----*/
            if (MV == 1 && MH != 1)
            {
                NetPolylineIndicesArray array1 = new NetPolylineIndicesArray(polylines[0], builder);
                NetPolylineIndicesArray array2 = new NetPolylineIndicesArray(polylines[2], builder, true);
                MeshStructures.CreateSideTriangles(builder, array2, array1, facesIndex);
                return(true);
            }

            if (MV != 1 && MH == 1)
            {
                NetPolylineIndicesArray array1 = new NetPolylineIndicesArray(polylines[1], builder);
                NetPolylineIndicesArray array2 = new NetPolylineIndicesArray(polylines[3], builder, true);
                MeshStructures.CreateSideTriangles(builder, array2, array1, facesIndex);
                return(true);
            }

            if (MV == 1 && MH == 1)
            {
                builder.WriteQuad(facesIndex, polylines[0].GetFirstVertex(), polylines[1].GetFirstVertex(),
                                  polylines[2].GetFirstVertex(), polylines[3].GetFirstVertex());
                return(true);
            }
            return(false);
        }
        public int UpdateSides(OutputMesh builder, CPNPolygon polygon, int trPosition,
                               int innerVerticesPosition)
        {
            CPNSideEdge[] polylines = polygon.sideEdges;

            first[0] = innerVerticesPosition;
            first[1] = innerVerticesPosition + (MH - 2);
            first[2] = innerVerticesPosition + (MV - 1) * (MH - 1) - 1;
            first[3] = innerVerticesPosition + (MV - 2) * (MH - 1);

            move[0] = 1;
            move[1] = (MH - 1);
            move[2] = -1;
            move[3] = -(MH - 1);

            count[0] = MH - 1;
            count[1] = MV - 1;
            count[2] = MH - 1;
            count[3] = MV - 1;

            for (int i = 0; i < 4; i++)
            {
                if (polylines[i].GetN() > 1)
                {
                    LinearMeshIndicesArray          lmi = new LinearMeshIndicesArray(first[i], move[i], count[i], builder);
                    NetPolylineInternalIndicesArray npi = new NetPolylineInternalIndicesArray(polylines[i], builder);
                    trPosition = MeshStructures.CreateSideTriangles(builder, lmi, npi, trPosition);
                }
                else
                {
                    LinearMeshIndicesArray  lmi = new LinearMeshIndicesArray(first[i], move[i], count[i], builder);
                    NetPolylineIndicesArray npi = new NetPolylineIndicesArray(polylines[i], builder);
                    trPosition = MeshStructures.CreateSideTriangles(builder, lmi, npi, trPosition);
                }

                int prev = i == 0 ? 3 : i - 1;
                if (polylines[i].GetN() > 1 && polylines[prev].GetN() > 1)
                {
                    trPosition = builder.WriteQuad(trPosition, polylines[i].GetIndex(0), polylines[i].GetIndex(1), first[i],
                                                   polylines[prev].GetBackIndex(1));
                }
                else if (polylines[i].GetN() > 1)
                {
                    trPosition = builder.WriteTriangle(trPosition, polylines[i].GetIndex(0), polylines[i].GetIndex(1),
                                                       first[i]);
                }
                else if (polylines[prev].GetN() > 1)
                {
                    trPosition = builder.WriteTriangle(trPosition, polylines[i].GetIndex(0), first[i],
                                                       polylines[prev].GetBackIndex(1));
                }

                // System.err.println("trPosition on sides " + trPosition);
            }

            return(trPosition);
        }
예제 #4
0
        int WritePolygons(OutputMesh mesh, int position)
        {
            int geometriesCount = this.curvedPolygonsNet.GetGeometriesCount();

            CPNPolygon[][] polygons                = tessellationOutput.GetPolygons();
            int[][]        polygonsProfile         = tessellationOutput.GetPolygonsProfile();
            int[][]        polygonsVerticesProfile = tessellationOutput.GetPolygonsVerticesProfile();

            for (int k = 0; k < geometriesCount; k++)
            {
                mesh.SetGeometry(k);
                CPNGeometry geometry = this.curvedPolygonsNet.GetGeometries()[k];

                int geomPolygonsCount = subSet == null?geometry.GetPolygonsCount() : subSet.polygons[k].Length;

                for (int i = 0; i < geomPolygonsCount; i++)
                {
                    int        index = subSet == null ? i : subSet.polygons[k][i];
                    int        countEffectiveSize = polygons[k][index].sideEdges.Length;
                    CPNPolygon polygonData        = polygons[k][index];

                    if (countEffectiveSize > 2 && countEffectiveSize < TESSELLATION_PROCESS_NET_INTERPOLATORS &&
                        !polygonData.skip)
                    {
                        polygonData.computeSideEdgesSizes();
                        ICPNetInterpolator netInterpolator = manager.GetSchema(polygonData.schemaIndex).
                                                             interpolators[countEffectiveSize];

                        netInterpolator.UdpdateContent(mesh, polygonData, polygonsVerticesProfile[k][index],
                                                       polygonsProfile[k][index]);
                    }
                }
                position += polygonsVerticesProfile[k][geometry.GetPolygonsCount()];

                int     triangleIndex  = polygonsProfile[k][geometry.GetPolygonsCount()];
                int     trianglesCount = geometry.GetTrianglesCount();
                short[] triangles      = geometry.GetTriangles();
                for (int i = 0; i < trianglesCount; i++)
                {
                    mesh.WriteTriangle(triangleIndex, triangles[3 * i], triangles[3 * i + 1], triangles[3 * i + 2]);
                    triangleIndex++;
                }
                int     quadsCount = geometry.GetQuadsCount();
                short[] quads      = geometry.GetQuads();
                for (int i = 0; i < quadsCount; i++)
                {
                    mesh.WriteQuad(triangleIndex, quads[3 * i], quads[3 * i + 1], quads[3 * i + 2], quads[3 * i + 3]);
                    triangleIndex += 2;
                }
            }

            return(position);
        }
        public void CreateTriangleTessellation(OutputMesh mesh, int internalsIndex, int facesIndex,
                                               CPNPolygon polygon)
        {
            // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
            // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
            // internalsIndex:%d facesIndex:%d", internalsIndex, facesIndex);
            // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

            CPNSideEdge[] polylines = polygon.sideEdges;
            RetrieveInfos(polygon);

            int trPosition = facesIndex;

            if (M == 1)
            {
                trPosition = mesh.WriteTriangle(trPosition, polylines[0].GetIndex(0), polylines[1].GetIndex(0),
                                                polylines[2].GetIndex(0));
                return;
            }
            else if (M == 2)
            {
                // int[] MS=new int[3];
                MS[0] = polylines[0].GetN();
                MS[1] = polylines[1].GetN();
                MS[2] = polylines[2].GetN();
                for (int i = 0; i < 3; i++)
                {
                    int prev = i == 0 ? 2 : i - 1;
                    if (MS[prev] == 2)
                    {
                        // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                        // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                        // M == 2 i:%d trPosition:%d writing CASE 1",i,trPosition);
                        // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                        trPosition = mesh.WriteTriangle(trPosition,
                                                        polylines[i].GetIndex(0), polylines[i].GetIndex(1),
                                                        polylines[prev].GetBackIndex(1));
                    }
                    else if (MS[i] == 2)
                    {
                        int other = (i == 2 ? 0 : i + 1);
                        if (MS[other] == 2)
                        {
                            // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                            // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                            // M == 2 i:%d trPosition:%d writing CASE 2", i,
                            // trPosition);
                            // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                            trPosition = mesh.WriteTriangle(trPosition, polylines[i].GetIndex(0), polylines[i].GetIndex(1),
                                                            polylines[other].GetIndex(1));
                        }
                        else
                        {
                            // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                            // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                            // M == 2 i:%d trPosition:%d writing CASE 3", i,
                            // trPosition);
                            // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                            trPosition = mesh.WriteTriangle(trPosition, polylines[i].GetIndex(0), polylines[i].GetIndex(1),
                                                            polylines[other].GetIndex(1));
                        }
                    }
                }
                if (MS[0] == 2 && MS[1] == 2 && MS[2] == 2)
                {
                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // M == 2 writing CASE 4");
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    trPosition = mesh.WriteTriangle(trPosition, polylines[0].GetIndex(1), polylines[1].GetIndex(1),
                                                    polylines[2].GetIndex(1));
                }

                // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                // if(facesIndex+trianglesN!=trPosition)
                // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                // ERROR on trianglesN facesIndex:%d trianglesN:%d trPosition:%d",
                // facesIndex, trianglesN, trPosition);
                // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

                return;
            }

            int innerVerticesPosition = internalsIndex;
            int rowPosition1          = innerVerticesPosition;
            int rowPosition2          = innerVerticesPosition + M - 2;

            // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
            // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
            // writing Internals innerVerticesPosition:%d rowPosition1:%d
            // rowPosition2:%d", innerVerticesPosition, rowPosition1, rowPosition2);
            // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

            for (int i = 0; i < M - 3; i++)
            {
                for (int j_ = 0; j_ < M - 4 - i; j_++)
                {
                    trPosition = mesh.WriteTriangle(trPosition, rowPosition1 + j_, rowPosition1 + j_ + 1, rowPosition2 + j_);
                    trPosition = mesh.WriteTriangle(trPosition, rowPosition2 + j_, rowPosition1 + j_ + 1,
                                                    rowPosition2 + j_ + 1);
                }

                int j = M - 4 - i;

                trPosition = mesh.WriteTriangle(trPosition, rowPosition1 + j, rowPosition1 + j + 1, rowPosition2 + j);

                rowPosition1 = rowPosition2;
                rowPosition2 = rowPosition2 + (M - 3 - i);
                // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                // writing Internals rowPosition1:%d rowPosition2:%d", rowPosition1,
                // rowPosition2);
                // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
            }

            first[0] = innerVerticesPosition;
            first[1] = innerVerticesPosition + M - 3;
            first[2] = innerVerticesPosition + (((M - 1) * (M - 2)) >> 1) - 1;

            move[0] = 1;
            move[1] = M - 2;
            move[2] = -1;

            deltaMove[0] = 0;
            deltaMove[1] = -1;
            deltaMove[2] = -1;

            int count = M - 2;

            // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
            // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
            // preparing Sides count:%d first:[%d,%d,%d] move:[%d,%d,%d]
            // deltaMove:[%d,%d,%d]",
            // count, first[0], first[1], first[2], move[0], move[1], move[2],
            // deltaMove[0], deltaMove[1], deltaMove[2]);
            // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

            for (int i = 0; i < 3; i++)
            {
                int N = polylines[i].GetN();
                if (N >= 2)
                {
                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // side Triangle case A trPosition:%d", trPosition);
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    meshIndicesArray.Setup(first[i], move[i], deltaMove[i], count, mesh,
                                           TriangleMeshStructure.DEFAULT_VERTICES_LAYER);

                    NetPolylineInternalIndicesArray npi = new NetPolylineInternalIndicesArray(polylines[i], mesh);
                    trPosition = MeshStructures.CreateSideTriangles(mesh, meshIndicesArray, npi, trPosition);
                }
                else if (N == 1)
                {
                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // side Triangle case B trPosition:%d (Begin)", trPosition);
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    meshIndicesArray.Setup(first[i], move[i], deltaMove[i], count, mesh, DEFAULT_VERTICES_LAYER);

                    NetPolylineIndicesArray npi = new NetPolylineIndicesArray(polylines[i], mesh);
                    trPosition = MeshStructures.CreateSideTriangles(mesh, meshIndicesArray, npi, trPosition);

                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // side Triangle case B trPosition:%d (End)", trPosition);
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                }

                int prev  = i == 0 ? 2 : i - 1;
                int prevN = polylines[prev].GetN();
                if (N > 1 && prevN > 1)
                {
                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // writing corner Index as Quad a:%d b:%d c:%d d:%d",
                    // polylines[i].getIndex(1),first[i],
                    // polylines[prev].getBackIndex(1), polylines[i].getIndex(0));
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

                    if (prevN + N < 1.5f * M)
                    {
                        trPosition = mesh.WriteQuad(trPosition, polylines[i].GetIndex(0), polylines[i].GetIndex(1),
                                                    first[i], polylines[prev].GetBackIndex(1));
                    }
                    else
                    {
                        trPosition = mesh.WriteQuad(trPosition, polylines[i].GetIndex(1), first[i],
                                                    polylines[prev].GetBackIndex(1), polylines[i].GetIndex(0));
                    }
                }
                else if (polylines[i].GetN() > 1)
                {
                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // writing corner Index as Triangle a:%d b:%d c:%d ",
                    // polylines[i].getIndex(0), polylines[i].getIndex(1),
                    // first[i]);
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

                    trPosition = mesh.WriteTriangle(trPosition, polylines[i].GetIndex(0), polylines[i].GetIndex(1),
                                                    first[i]);
                }
                else if (polylines[prev].GetN() > 1)
                {
                    // #ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
                    // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
                    // writing corner Index as Triangle a:%d b:%d c:%d ",
                    // polylines[i].getIndex(0),
                    // first[i],polylines[i].getBackIndex(1));
                    // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR

                    trPosition = mesh.WriteTriangle(trPosition, polylines[i].GetIndex(0), first[i],
                                                    polylines[prev].GetBackIndex(1));
                }
            }

            // #
            // ifdef SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
            // if(facesIndex+trianglesN!=trPosition)
            //
            // printf("\nSFCPNTrianglesMeshStructure.createTriangleTessellation
            // ERROR on trianglesN facesIndex:%d trianglesN:%d trPosition:%d",
            // facesIndex, trianglesN, trPosition);
            // #endif //SF_RAW_DEBUG_TRIANGLE_TESSELLATOR
        }