示例#1
0
        public void CalculateSurface()
        {
            float[]    cube_cell     = new float[8];
            Vertex3D[] cube_vertex3d = new Vertex3D[8];
            Vertex3D[] list_vertex3d = new Vertex3D[12];
            Vertex3D   normal        = new Vertex3D();

            for (int counter = 0; counter <= 7; counter++)
            {
                cube_vertex3d[counter] = new Vertex3D();
            }
            for (int counter = 0; counter <= 11; counter++)
            {
                list_vertex3d[counter] = new Vertex3D();
            }



            int temp1;

            Gl.glNewList(ID_List, Gl.GL_COMPILE);

            for (int i = 0; i < Xsize - 1; i++)
            {
                for (int j = 0; j < Ysize - 1; j++)
                {
                    for (int k = 0; k < Zsize - 1; k++)
                    {
                        cube_cell[0] = Data[i, j, k];
                        cube_cell[1] = Data[i + 1, j, k];
                        cube_cell[2] = Data[i + 1, j + 1, k];
                        cube_cell[3] = Data[i, j + 1, k];
                        cube_cell[4] = Data[i, j, k + 1];
                        cube_cell[5] = Data[i + 1, j, k + 1];
                        cube_cell[6] = Data[i + 1, j + 1, k + 1];
                        cube_cell[7] = Data[i, j + 1, k + 1];



                        cube_vertex3d[0].Set(this.getVertexValueX(i), this.getVertexValueY(j), this.getVertexValueZ(k));
                        cube_vertex3d[1].Set(this.getVertexValueX(i + 1), this.getVertexValueY(j), this.getVertexValueZ(k));
                        cube_vertex3d[2].Set(this.getVertexValueX(i + 1), this.getVertexValueY(j + 1), this.getVertexValueZ(k));
                        cube_vertex3d[3].Set(this.getVertexValueX(i), this.getVertexValueY(j + 1), this.getVertexValueZ(k));
                        cube_vertex3d[4].Set(this.getVertexValueZ(i), this.getVertexValueY(j), this.getVertexValueZ(k + 1));
                        cube_vertex3d[5].Set(this.getVertexValueX(i + 1), this.getVertexValueY(j), this.getVertexValueZ(k + 1));
                        cube_vertex3d[6].Set(this.getVertexValueX(i + 1), this.getVertexValueY(j + 1), this.getVertexValueZ(k + 1));
                        cube_vertex3d[7].Set(this.getVertexValueX(i), this.getVertexValueY(j + 1), this.getVertexValueZ(k + 1));

                        int cube_index = 0;
                        if (cube_cell[0] < isoline)
                        {
                            cube_index |= 1;
                        }
                        if (cube_cell[1] < isoline)
                        {
                            cube_index |= 2;
                        }
                        if (cube_cell[2] < isoline)
                        {
                            cube_index |= 4;
                        }
                        if (cube_cell[3] < isoline)
                        {
                            cube_index |= 8;
                        }
                        if (cube_cell[4] < isoline)
                        {
                            cube_index |= 16;
                        }
                        if (cube_cell[5] < isoline)
                        {
                            cube_index |= 32;
                        }
                        if (cube_cell[6] < isoline)
                        {
                            cube_index |= 64;
                        }
                        if (cube_cell[7] < isoline)
                        {
                            cube_index |= 128;
                        }

                        if (TabEdg.Table[cube_index] != 0)
                        {
                            //Finding intersections 1-cube & surface

                            if ((TabEdg.Table[cube_index] & 1) != 0)
                            {
                                list_vertex3d [0].TransVertex(isoline, cube_vertex3d[0], cube_vertex3d[1], cube_cell[0], cube_cell[1]);
                            }
                            if ((TabEdg.Table[cube_index] & 2) != 0)
                            {
                                list_vertex3d [1].TransVertex(isoline, cube_vertex3d[1], cube_vertex3d[2], cube_cell[1], cube_cell[2]);
                            }
                            if ((TabEdg.Table[cube_index] & 4) != 0)
                            {
                                list_vertex3d [2].TransVertex(isoline, cube_vertex3d[2], cube_vertex3d[3], cube_cell[2], cube_cell[3]);
                            }
                            if ((TabEdg.Table[cube_index] & 8) != 0)
                            {
                                list_vertex3d [3].TransVertex(isoline, cube_vertex3d[3], cube_vertex3d[0], cube_cell[3], cube_cell[0]);
                            }
                            if ((TabEdg.Table[cube_index] & 16) != 0)
                            {
                                list_vertex3d [4].TransVertex(isoline, cube_vertex3d[4], cube_vertex3d[5], cube_cell[4], cube_cell[5]);
                            }
                            if ((TabEdg.Table[cube_index] & 32) != 0)
                            {
                                list_vertex3d [5].TransVertex(isoline, cube_vertex3d[5], cube_vertex3d[6], cube_cell[5], cube_cell[6]);
                            }
                            if ((TabEdg.Table[cube_index] & 64) != 0)
                            {
                                list_vertex3d [6].TransVertex(isoline, cube_vertex3d[6], cube_vertex3d[7], cube_cell[6], cube_cell[7]);
                            }
                            if ((TabEdg.Table[cube_index] & 128) != 0)
                            {
                                list_vertex3d [7].TransVertex(isoline, cube_vertex3d[7], cube_vertex3d[4], cube_cell[7], cube_cell[4]);
                            }
                            if ((TabEdg.Table[cube_index] & 256) != 0)
                            {
                                list_vertex3d [8].TransVertex(isoline, cube_vertex3d[0], cube_vertex3d[4], cube_cell[0], cube_cell[4]);
                            }
                            if ((TabEdg.Table[cube_index] & 512) != 0)
                            {
                                list_vertex3d [9].TransVertex(isoline, cube_vertex3d[1], cube_vertex3d[5], cube_cell[1], cube_cell[5]);
                            }
                            if ((TabEdg.Table[cube_index] & 1024) != 0)
                            {
                                list_vertex3d [10].TransVertex(isoline, cube_vertex3d[2], cube_vertex3d[6], cube_cell[2], cube_cell[6]);
                            }
                            if ((TabEdg.Table[cube_index] & 2048) != 0)
                            {
                                list_vertex3d [11].TransVertex(isoline, cube_vertex3d[3], cube_vertex3d[7], cube_cell[3], cube_cell[7]);
                            }

                            temp1 = 0;
                            Gl.glColor3f(1, 1, 0);
                            for (int q = 0; TabPos.Matrix[cube_index, q] != -1; q += 3)
                            {
                                float mult = 1.0f;
                                normal.NormalCount(list_vertex3d[TabPos.Matrix[cube_index, q]], list_vertex3d[TabPos.Matrix[cube_index, q + 1]], list_vertex3d[TabPos.Matrix[cube_index, q + 2]]);
                                float x, y, z;
                                float x1, y1, z1;
                                float x2, y2, z2;
                                float x3, y3, z3;
                                float nx, ny, nz;

                                x = normal.x * mult;
                                y = normal.y * mult;
                                z = normal.z * mult;

                                nx = x; ny = y; nz = z;

                                x  = list_vertex3d[TabPos.Matrix[cube_index, q]].x;
                                y  = list_vertex3d[TabPos.Matrix[cube_index, q]].y;
                                z  = list_vertex3d[TabPos.Matrix[cube_index, q]].z;
                                x1 = x; y1 = y; z1 = z;

                                x  = list_vertex3d[TabPos.Matrix[cube_index, q + 1]].x;
                                y  = list_vertex3d[TabPos.Matrix[cube_index, q + 1]].y;
                                z  = list_vertex3d[TabPos.Matrix[cube_index, q + 1]].z;
                                x2 = x; y2 = y; z2 = z;

                                x  = list_vertex3d[TabPos.Matrix[cube_index, q + 2]].x;
                                y  = list_vertex3d[TabPos.Matrix[cube_index, q + 2]].y;
                                z  = list_vertex3d[TabPos.Matrix[cube_index, q + 2]].z;
                                x3 = x; y3 = y; z3 = z;

                                Gl.glBegin(Gl.GL_TRIANGLES);

                                Gl.glNormal3f(nx, ny, nz);
                                Gl.glVertex3f(x1, y1, z1);
                                Gl.glVertex3f(x2, y2, z2);
                                Gl.glVertex3f(x3, y3, z3);

                                Gl.glEnd();

                                temp1++;
                            }
                        }
                    }
                }
            }


            Gl.glEndList();
        }