Ejemplo n.º 1
0
        public Mesh GenerateSurface()
        {
            d  = bmp.depth;
            h  = bmp.height;
            w  = bmp.width;
            wh = w * h;
            Int16Triple[] temp = new Int16Triple[8];
            Mesh          m    = new Mesh();

            OriginalTriangle[]     tempTriangles = new OriginalTriangle[6];
            MCTriangleNetHashTable hash          = new MCTriangleNetHashTable(0, 0, w, h);

            for (int k = 0; k <= d - 1; k++)
            {
                for (int j = 0; j <= h - 1; j++)
                {
                    for (int i = 0; i <= w - 1; i++)
                    {
                        byte value = GetConfig(temp, bmp, i, j, k);
                        if (value == 0 || value == 255)
                        {
                            continue;
                        }
                        int tcount = ExtractTriangles(temp, value, i, j, k, tempTriangles);
                        for (int tindex = 0; tindex < tcount; tindex++)
                        {
                            MergeTriangleIntoMesh(m, hash, tempTriangles[tindex]);
                        }
                    }
                }
                hash.IncreaseIndex();
            }
            return(m);
        }
Ejemplo n.º 2
0
        private void MergeTriangleIntoMesh(Mesh mesh, MCTriangleNetHashTable hashMap, OriginalTriangle ot)
        {
            int e0i = CubeEdgeMapTable[ot.E0].D;
            int p0x = ot.CellCoord.X + CubeEdgeMapTable[ot.E0].A;
            int p0y = ot.CellCoord.Y + CubeEdgeMapTable[ot.E0].B;
            int p0z = ot.CellCoord.Z + CubeEdgeMapTable[ot.E0].C;


            int e1i = CubeEdgeMapTable[ot.E1].D;
            int p1x = ot.CellCoord.X + CubeEdgeMapTable[ot.E1].A;
            int p1y = ot.CellCoord.Y + CubeEdgeMapTable[ot.E1].B;
            int p1z = ot.CellCoord.Z + CubeEdgeMapTable[ot.E1].C;


            int e2i = CubeEdgeMapTable[ot.E2].D;
            int p2x = ot.CellCoord.X + CubeEdgeMapTable[ot.E2].A;
            int p2y = ot.CellCoord.Y + CubeEdgeMapTable[ot.E2].B;
            int p2z = ot.CellCoord.Z + CubeEdgeMapTable[ot.E2].C;


            int p0i;
            int p1i;
            int p2i;
            int index = 0;

            index = hashMap.GetHashValue(p0x, p0y, p0z, e0i);
            if (index == -1)
            {
                Point3d interp = GetIntersetedPoint(ot.CellCoord.X, ot.CellCoord.Y, ot.CellCoord.Z, ot.E0);
                p0i = mesh.AddVertex(interp);
                hashMap.SetHashValue(p0x, p0y, p0z, e0i, p0i);
            }
            else
            {
                p0i = index;
            }

            index = hashMap.GetHashValue(p1x, p1y, p1z, e1i);
            if (index == -1)
            {
                Point3d interp = GetIntersetedPoint(ot.CellCoord.X, ot.CellCoord.Y, ot.CellCoord.Z, ot.E1);
                p1i = mesh.AddVertex(interp);
                hashMap.SetHashValue(p1x, p1y, p1z, e1i, p1i);
            }
            else
            {
                p1i = index;
            }

            index = hashMap.GetHashValue(p2x, p2y, p2z, e2i);
            if (index == -1)
            {
                Point3d interp = GetIntersetedPoint(ot.CellCoord.X, ot.CellCoord.Y, ot.CellCoord.Z, ot.E2);
                p2i = mesh.AddVertex(interp);
                hashMap.SetHashValue(p2x, p2y, p2z, e2i, p2i);
            }
            else
            {
                p2i = index;
            }

            Triangle t = new Triangle(p0i, p1i, p2i);

            mesh.AddFace(t);
        }