Example #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[4];
            SMCTriangleNetHashTable hash          = new SMCTriangleNetHashTable(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);
        }
Example #2
0
        private int ExtractTriangles(Int16Triple[] temp, byte value, int indexInWidth, int indexInHeight, int indexInDepth, OriginalTriangle[] result)
        {
            int tcount = 0;

            if (SMCTable.TableFat[value, 0] != -1)
            {
                int index = 0;
                while (SMCTable.TableFat[value, index] != -1)
                {
                    Int16Triple t0 = temp[SMCTable.TableFat[value, index]];
                    Int16Triple t1 = temp[SMCTable.TableFat[value, index + 1]];
                    Int16Triple t2 = temp[SMCTable.TableFat[value, index + 2]];
                    result[tcount] = new OriginalTriangle(t0.X, t0.Y, t0.Z, t1.X, t1.Y, t1.Z, t2.X, t2.Y, t2.Z);
                    tcount++;
                    index += 3;
                }
            }
            return(tcount);
        }
Example #3
0
        private int ExtractTriangles(Int16Triple[] temp, byte value, int indexInWidth, int indexInHeight, int indexInDepth, OriginalTriangle[] result)
        {
            int tcount = 0;

            if (MCTable.TriTable[value, 0] != -1)
            {
                int index = 0;
                while (MCTable.TriTable[value, index] != -1)
                {
                    int e0index = MCTable.TriTable[value, index];
                    int e1index = MCTable.TriTable[value, index + 1];
                    int e2index = MCTable.TriTable[value, index + 2];
                    result[tcount] = new OriginalTriangle(indexInWidth, indexInHeight, indexInDepth, e0index, e1index, e2index);
                    tcount++;
                    index += 3;
                }
            }
            return(tcount);
        }
Example #4
0
        private void MergeTriangleIntoMesh(Mesh mesh, SMCTriangleNetHashTable hashMap, OriginalTriangle ot)
        {
            int p0x = ot.P0.X;
            int p0y = ot.P0.Y;
            int p0z = ot.P0.Z;
            int p1x = ot.P1.X;
            int p1y = ot.P1.Y;
            int p1z = ot.P1.Z;
            int p2x = ot.P2.X;
            int p2y = ot.P2.Y;
            int p2z = ot.P2.Z;
            int p0i;
            int p1i;
            int p2i;
            int index = 0;

            index = hashMap.GetHashValue(p0x, p0y, p0z);
            if (index == -1)
            {
                p0i = mesh.AddVertex(new Point3d(p0x, p0y, p0z));
                hashMap.SetHashValue(p0x, p0y, p0z, p0i);
            }
            else
            {
                p0i = index;
            }

            index = hashMap.GetHashValue(p1x, p1y, p1z);
            if (index == -1)
            {
                p1i = mesh.AddVertex(new Point3d(p1x, p1y, p1z));
                hashMap.SetHashValue(p1x, p1y, p1z, p1i);
            }
            else
            {
                p1i = index;
            }

            index = hashMap.GetHashValue(p2x, p2y, p2z);
            if (index == -1)
            {
                p2i = mesh.AddVertex(new Point3d(p2x, p2y, p2z));
                hashMap.SetHashValue(p2x, p2y, p2z, p2i);
            }
            else
            {
                p2i = index;
            }

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

            mesh.AddFace(t);
        }
Example #5
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);
        }