Exemplo n.º 1
0
 private void DrawSelectedEdges(TetMesh mesh)
 {
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
     GL.LineWidth(GlobalSetting.DisplaySetting.SelectionLineWidth);
     GL.Enable(EnableCap.LineSmooth);
     GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);
     GL.Begin(BeginMode.Lines);
     foreach (var edge in mesh.Edges)
     {
         if (edge.Flag != 0)
         {
             Color4 color = edge.Color;
             if (color != Color4.Black)
             {
                 OpenTK.Graphics.Color4 colorTwo = new OpenTK.Graphics.Color4((float)color.R, (float)color.G, (float)color.B, 0.0f);
                 OpenGLManager.Instance.SetColorMesh(colorTwo);
             }
             else
             {
                 OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.SelectedEdgeColor);
             }
             foreach (var v in edge.Vertices)
             {
                 GL.Normal3(v.Normal.ToArray());
                 GL.Vertex3(v.Pos.ToArray());
             }
         }
     }
     GL.End();
 }
Exemplo n.º 2
0
        public void DrawTransparent(TetMesh mesh)
        {
            GlobalSetting.SettingLight.DoubleSideLight = true;
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.ColorMaterial);

            float alpha = GlobalSetting.MaterialSetting.MaterialDiffuse.A / 256f;
            float f = 1 - alpha;

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Front);
            GL.DepthFunc(DepthFunction.Always);
            this.DrawTransparentMesh(mesh, f * alpha);
            GL.DepthFunc(DepthFunction.Lequal);
            this.DrawTransparentMesh(mesh, (alpha - f * alpha) / (1f - f * alpha));

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.DepthFunc(DepthFunction.Always);
            this.DrawTransparentMesh(mesh, f * alpha);
            GL.DepthFunc(DepthFunction.Lequal);
            this.DrawTransparentMesh(mesh, (alpha - f * alpha) / (1f - f * alpha));

            GL.Disable(EnableCap.Blend);
            GL.DepthMask(true);
            GL.Disable(EnableCap.DepthTest);
        }
Exemplo n.º 3
0
 private void View_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left)
     {
         this.onPatch = true;
         TetMesh      mesh        = GlobalData.Instance.TetMesh;
         DataGridView dgv         = (DataGridView)sender;
         int          columnIndex = 0;
         foreach (DataGridViewColumn column in dgv.Columns)
         {
             if (column.Name.EndsWith("Flag"))
             {
                 columnIndex = column.Index;
             }
         }
         foreach (DataGridViewRow row in dgv.Rows)
         {
             if (row.Selected)
             {
                 DataGridViewCell cell = row.Cells[columnIndex];
                 if (e.KeyCode == Keys.Right)
                 {
                     cell.Value = (int)cell.Value + 1;
                 }
                 else if (e.KeyCode == Keys.Left)
                 {
                     cell.Value = (int)cell.Value > 0 ? (int)cell.Value - 1 : 0;
                 }
             }
         }
         this.onPatch = false;
         mesh.ComputeSelectedNormal();
         GlobalData.Instance.OnChanged(new EventArgs());
     }
 }
Exemplo n.º 4
0
        public TetMeshInfo()
        {
            InitializeComponent();
            TetMesh tet = GlobalData.Instance.TetMesh;

            this.propertyGrid1.SelectedObject = new TetMeshSettings();
        }
Exemplo n.º 5
0
 private void DrawSelectedEdges(TetMesh mesh)
 {
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
     GL.LineWidth(GlobalSetting.DisplaySetting.SelectionLineWidth);
     GL.Enable(EnableCap.LineSmooth);
     GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);
     GL.Begin(BeginMode.Lines);
     foreach (var edge in mesh.Edges)
     {
         if (edge.Flag != 0)
         {
             Color4 color = edge.Color;
             if (color != Color4.Black)
             {
                 OpenTK.Graphics.Color4 colorTwo = new OpenTK.Graphics.Color4((float)color.R, (float)color.G, (float)color.B, 0.0f);
                 OpenGLManager.Instance.SetColorMesh(colorTwo);
             }
             else
             {
                 OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.SelectedEdgeColor);
             }
             foreach (var v in edge.Vertices)
             {
                 GL.Normal3(v.Normal.ToArray());
                 GL.Vertex3(v.Pos.ToArray());
             }
         }
     }
     GL.End();
 }
Exemplo n.º 6
0
 public void DrawSelectedFaces(TetMesh mesh)
 {
     GL.ShadeModel(ShadingModel.Smooth);
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
     GL.Enable(EnableCap.Normalize);
     GL.Begin(BeginMode.Triangles);
     foreach (var face in mesh.Faces)
     {
         if (face.Flag != 0)
         {
             Color4 color = face.Color;
             if (color != Color4.Black)
             {
                 OpenTK.Graphics.Color4 colorTwo = new OpenTK.Graphics.Color4((float)color.R, (float)color.G, (float)color.B, 0.0f);
                 OpenGLManager.Instance.SetColorMesh(colorTwo);
             }
             else
             {
                 OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.SelectedFaceColor);
             }
             foreach (var v in face.Vertices)
             {
                 GL.Normal3(v.Normal.ToArray());
                 GL.Vertex3(v.Pos.ToArray());
             }
         }
     }
     GL.End();
 }
Exemplo n.º 7
0
 public void DrawSelectedFaces(TetMesh mesh)
 {
     GL.ShadeModel(ShadingModel.Smooth);
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
     GL.Enable(EnableCap.Normalize);
     GL.Begin(BeginMode.Triangles);
     foreach (var face in mesh.Faces)
     {
         if (face.Flag != 0)
         {
             Color4 color = face.Color;
             if (color != Color4.Black)
             {
                 OpenTK.Graphics.Color4 colorTwo = new OpenTK.Graphics.Color4((float)color.R, (float)color.G, (float)color.B, 0.0f);
                 OpenGLManager.Instance.SetColorMesh(colorTwo);
             }
             else
             {
                 OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.SelectedFaceColor);
             }
             foreach (var v in face.Vertices)
             {
                 GL.Normal3(v.Normal.ToArray());
                 GL.Vertex3(v.Pos.ToArray());
             }
         }
     }
     GL.End();
 }
Exemplo n.º 8
0
        public void DrawTransparent(TetMesh mesh)
        {
            GlobalSetting.SettingLight.DoubleSideLight = true;
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.ColorMaterial);

            float alpha = GlobalSetting.MaterialSetting.MaterialDiffuse.A / 256f;
            float f     = 1 - alpha;

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Front);
            GL.DepthFunc(DepthFunction.Always);
            this.DrawTransparentMesh(mesh, f * alpha);
            GL.DepthFunc(DepthFunction.Lequal);
            this.DrawTransparentMesh(mesh, (alpha - f * alpha) / (1f - f * alpha));

            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.DepthFunc(DepthFunction.Always);
            this.DrawTransparentMesh(mesh, f * alpha);
            GL.DepthFunc(DepthFunction.Lequal);
            this.DrawTransparentMesh(mesh, (alpha - f * alpha) / (1f - f * alpha));

            GL.Disable(EnableCap.Blend);
            GL.DepthMask(true);
            GL.Disable(EnableCap.DepthTest);
        }
Exemplo n.º 9
0
 public void DrawWireFrame(TetMesh mesh)
 {
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
     GL.LineWidth(GlobalSetting.DisplaySetting.LineWidth);
     //GL.Enable(EnableCap.CullFace);
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.WifeFrameColor);
     DrawTriangles(mesh);
 }
Exemplo n.º 10
0
 public void DrawWireFrame(TetMesh mesh)
 {
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
     GL.LineWidth(GlobalSetting.DisplaySetting.LineWidth);
     //GL.Enable(EnableCap.CullFace);
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.WifeFrameColor);
     DrawTriangles(mesh);
 }
Exemplo n.º 11
0
 public void DrawSmoothShaded(TetMesh mesh)
 {
     GL.ShadeModel(ShadingModel.Smooth);
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
     GL.Enable(EnableCap.Normalize);
     Color c = GlobalSetting.DisplaySetting.MeshColor;
     OpenGLManager.Instance.SetColorMesh(c);
     DrawTriangles(mesh);
 }
Exemplo n.º 12
0
 void DrawTransparentMesh(TetMesh mesh, float alpha)
 {
     OpenTK.Graphics.Color4 front = GlobalSetting.MaterialSetting.MaterialDiffuse;
     front.A = alpha;
     OpenTK.Graphics.Color4 back = GlobalSetting.MaterialSetting.BackMaterialDiffuse;
     back.A = alpha;
     GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, front);
     GL.Material(MaterialFace.Back, MaterialParameter.Diffuse, back);
 }
Exemplo n.º 13
0
 void DrawTransparentMesh(TetMesh mesh, float alpha)
 {
     OpenTK.Graphics.Color4 front = GlobalSetting.MaterialSetting.MaterialDiffuse;
     front.A = alpha;
     OpenTK.Graphics.Color4 back = GlobalSetting.MaterialSetting.BackMaterialDiffuse;
     back.A = alpha;
     GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, front);
     GL.Material(MaterialFace.Back, MaterialParameter.Diffuse, back);
 }
Exemplo n.º 14
0
 public static double ComputeEdgeAvgLength(TetMesh mesh)
 {
     double sum = 0;
     foreach (var edge in mesh.Edges)
     {
         sum += Vector3D.Distance(edge.Vertices[0].Pos, edge.Vertices[1].Pos);
     }
     return sum / mesh.Edges.Count;
 }
Exemplo n.º 15
0
        public void DrawSmoothShaded(TetMesh mesh)
        {
            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.Normalize);
            Color c = GlobalSetting.DisplaySetting.MeshColor;

            OpenGLManager.Instance.SetColorMesh(c);
            DrawTriangles(mesh);
        }
Exemplo n.º 16
0
        public static double ComputeEdgeAvgLength(TetMesh mesh)
        {
            double sum = 0;

            foreach (var edge in mesh.Edges)
            {
                sum += Vector3D.Distance(edge.Vertices[0].Pos, edge.Vertices[1].Pos);
            }
            return(sum / mesh.Edges.Count);
        }
Exemplo n.º 17
0
 public void BeginTransparent(TetMesh mesh)
 {
     //GL.Enable(EnableCap.CullFace);
     //GL.CullFace(CullFaceMode.Back);
     GL.DepthMask(false);
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(GlobalSetting.BlendSetting.BlendingFactorSrc, GlobalSetting.BlendSetting.BlendingFactorDest);
     GL.BlendEquation(GlobalSetting.BlendSetting.BlendEquationMode);
     GL.BlendColor(GlobalSetting.BlendSetting.BlendColor);
 }
Exemplo n.º 18
0
 public void BeginTransparent(TetMesh mesh)
 {
     //GL.Enable(EnableCap.CullFace);
     //GL.CullFace(CullFaceMode.Back);
     GL.DepthMask(false);
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(GlobalSetting.BlendSetting.BlendingFactorSrc, GlobalSetting.BlendSetting.BlendingFactorDest);
     GL.BlendEquation(GlobalSetting.BlendSetting.BlendEquationMode);
     GL.BlendColor(GlobalSetting.BlendSetting.BlendColor);
 }
Exemplo n.º 19
0
        public void DrawSelectedTetrahedron(TetMesh mesh)
        {
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.LineWidth(GlobalSetting.DisplaySetting.LineWidth);
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.WifeFrameColor);
            GL.Begin(BeginMode.Triangles);
            foreach (var tet in mesh.Tetras)
            {
                if (tet.Flag != 0)
                {
                    foreach (var face in tet.Faces)
                    {
                        if (TetMeshFlag.CheckBoundary(face) != null)
                        {
                            foreach (var v in face.Vertices)
                            {
                                GL.Normal3(v.SelectedNormal.ToArray());
                                GL.Vertex3(v.Pos.ToArray());
                            }
                        }
                    }
                }
            }
            GL.End();

            GL.LightModel(LightModelParameter.LightModelTwoSide, 1f);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.Normalize);
            //Color c = GlobalSetting.MeshDisplaySetting.TetrahedronColor;
            //OpenGLManager.Instance.SetMeshColor(c);
            GL.Disable(EnableCap.ColorMaterial);
            OpenGLManager.Instance.SetMaterialInfo();

            GL.Begin(BeginMode.Triangles);
            foreach (var tet in mesh.Tetras)
            {
                if (tet.Flag != 0)
                {
                    foreach (var face in tet.Faces)
                    {
                        if (TetMeshFlag.CheckBoundary(face) != null)
                        {
                            foreach (var v in face.Vertices)
                            {
                                GL.Normal3(v.SelectedNormal.ToArray());
                                GL.Vertex3(v.Pos.ToArray());
                            }
                        }
                    }
                }
            }
            GL.End();
            GL.Enable(EnableCap.ColorMaterial);
        }
Exemplo n.º 20
0
        public void DrawPoints(TetMesh m)
        {
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.CullFace);

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
            GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
            GL.Enable(EnableCap.PointSmooth);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.MeshColor);
            DrawVertices(m);
        }
Exemplo n.º 21
0
        public void DrawPoints(TetMesh m)
        {
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.CullFace);

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
            GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
            GL.Enable(EnableCap.PointSmooth);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.MeshColor);
            DrawVertices(m);
        }
Exemplo n.º 22
0
 public void DrawVertices(TetMesh mesh)
 {
     GL.Begin(BeginMode.Points);
     foreach (var v in mesh.Vertices)
     {
         if ((GlobalTetSetting.TetDisplayFlag & TetDisplayFlag.HasInner) == TetDisplayFlag.HasInner || v.OnBoundary)
         {
             GL.Normal3(v.Normal.ToArray());
             GL.Vertex3(v.Pos.ToArray());
         }
     }
     GL.End();
 }
Exemplo n.º 23
0
 public void DrawVertices(TetMesh mesh)
 {
     GL.Begin(BeginMode.Points);
     foreach (var v in mesh.Vertices)
     {
         if ((GlobalTetSetting.TetDisplayFlag & TetDisplayFlag.HasInner) == TetDisplayFlag.HasInner || v.OnBoundary)
         {
             GL.Normal3(v.Normal.ToArray());
             GL.Vertex3(v.Pos.ToArray());
         }
     }
     GL.End();
 }
Exemplo n.º 24
0
 public void DrawFlag(TetMesh mesh)
 {
     TetDisplayFlag mode = GlobalTetSetting.TetDisplayFlag;
     GL.Enable(EnableCap.DepthTest);
     GL.Enable(EnableCap.PolygonOffsetFill);
     foreach (var item in methods)
     {
         if ((mode & item.Flag) == item.Flag)
         {
             item.Action(mesh);
         }
     }
     GL.Disable(EnableCap.PolygonOffsetFill);
 }
Exemplo n.º 25
0
        public void DrawFlag(TetMesh mesh)
        {
            TetDisplayFlag mode = GlobalTetSetting.TetDisplayFlag;

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.PolygonOffsetFill);
            foreach (var item in methods)
            {
                if ((mode & item.Flag) == item.Flag)
                {
                    item.Action(mesh);
                }
            }
            GL.Disable(EnableCap.PolygonOffsetFill);
        }
Exemplo n.º 26
0
        private void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TetGenParser parser = new TetGenParser(IOHuiZhao.Instance.GetPath() + "/" + "tettmp.1");

            TetGenParser parser = new TetGenParser("tettmp.1");
            TetMesh      mesh   = parser.ReadAll();

            mesh.BuildAdj();
            mesh.ComputeTraits();
            mesh.ComputeNormal();
            //mesh.Check();

            GlobalData.Instance.TetMesh = mesh;
            GlobalData.Instance.TriMesh = null;
            this.OnChanged(new EventArgs());
        }
Exemplo n.º 27
0
 public void DrawFaceNormal(TetMesh mesh)
 {
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor);
     double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength;
     GL.Begin(BeginMode.Lines);
     foreach (var face in mesh.Faces)
     {
         if (face.Normal != Vector3D.Zero)
         {
             Vector3D mid = TetMeshUtil.GetMidPoint(face);
             Vector3D normal = face.Normal * l;
             GL.Vertex3(mid.ToArray());
             GL.Vertex3((mid + normal).ToArray());
         }
     }
     GL.End();
 }
Exemplo n.º 28
0
        public void DrawSelectedVertexNormal(TetMesh mesh)
        {
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor);
            double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength;

            GL.Begin(BeginMode.Lines);
            foreach (var v in mesh.Vertices)
            {
                if (v.SelectedNormal != Vector3D.Zero)
                {
                    Vector3D normal = v.SelectedNormal * l;
                    GL.Vertex3(v.Pos.ToArray());
                    GL.Vertex3((v.Pos + normal).ToArray());
                }
            }
            GL.End();
        }
Exemplo n.º 29
0
        public void DrawSelectedFaceNormal(TetMesh mesh)
        {
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor);
            double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength;

            GL.Begin(BeginMode.Lines);
            foreach (var face in mesh.Faces)
            {
                if (face.SelectedNormal != Vector3D.Zero)
                {
                    Vector3D mid    = TetMeshUtil.GetMidPoint(face);
                    Vector3D normal = face.SelectedNormal * l;
                    GL.Vertex3(mid.ToArray());
                    GL.Vertex3((mid + normal).ToArray());
                }
            }
            GL.End();
        }
Exemplo n.º 30
0
        public TetGenParser(string fileWithoutExt)
        {
            nodeFile = fileWithoutExt + ".node";
            edgeFile = fileWithoutExt + ".edge";
            faceFile = fileWithoutExt + ".face";
            eleFile = fileWithoutExt + ".ele";
            //neighFile = fileWithoutExt + ".neigh";

            if (!File.Exists(nodeFile) ||
                !File.Exists(edgeFile) ||
                !File.Exists(faceFile) ||
                !File.Exists(eleFile) )
                //!File.Exists(neighFile))
            {
                throw new FileNotFoundException("tetgen文件不全");
            }

            mesh = new TetMesh();
        }
Exemplo n.º 31
0
        public TetGenParser(string fileWithoutExt)
        {
            nodeFile = fileWithoutExt + ".node";
            edgeFile = fileWithoutExt + ".edge";
            faceFile = fileWithoutExt + ".face";
            eleFile  = fileWithoutExt + ".ele";
            //neighFile = fileWithoutExt + ".neigh";

            if (!File.Exists(nodeFile) ||
                !File.Exists(edgeFile) ||
                !File.Exists(faceFile) ||
                !File.Exists(eleFile))
            //!File.Exists(neighFile))
            {
                throw new FileNotFoundException("tetgen文件不全");
            }

            mesh = new TetMesh();
        }
Exemplo n.º 32
0
        void RefreshEdge()
        {
            TetMesh mesh = GlobalData.Instance.TetMesh;

            this.onLoad = true;
            this.edgeView.Rows.Clear();
            this.edgeView.Rows.Add(mesh.Edges.Count);
            for (int i = 0; i < mesh.Edges.Count; i++)
            {
                TetEdge         e   = mesh.Edges[i];
                DataGridViewRow row = this.edgeView.Rows[i];
                row.Cells["EIndex"].Value    = e.Index;
                row.Cells["EFlag"].Value     = e.Flag;
                row.Cells["EBoundary"].Value = e.OnBoundary;

                row.Cells["EV0"].Value = e.Vertices[0].Index;
                row.Cells["EV1"].Value = e.Vertices[1].Index;
            }
            this.onLoad = false;
        }
Exemplo n.º 33
0
        void ChangePlane()
        {
            TetMesh mesh = GlobalData.Instance.TetMesh;

            foreach (var tet in mesh.Tetras)
            {
                PlaneIntersectionType intersect = TetMeshUtil.Intersect(this.plane, tet);
                if (intersect == PlaneIntersectionType.Front ||
                    (intersecting && intersect == PlaneIntersectionType.Intersecting))
                {
                    tet.Flag = 1;
                }
                else
                {
                    tet.Flag = 0;
                }
            }
            mesh.ComputeSelectedNormal();
            GlobalData.Instance.OnChanged(EventArgs.Empty);
        }
Exemplo n.º 34
0
        public void DrawVertexNormal(TetMesh mesh)
        {
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor);
            double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength;

            GL.Begin(BeginMode.Lines);
            foreach (var v in mesh.Vertices)
            {
                if (v.OnBoundary)
                {
                    Vector3D normal = v.Normal * l;
                    double   x      = v.Pos.x;
                    double   y      = v.Pos.y;
                    double   z      = v.Pos.z;
                    GL.Vertex3(x, y, z);
                    GL.Vertex3(x + normal.x, y + normal.y, z + normal.z);
                }
            }
            GL.End();
        }
Exemplo n.º 35
0
 public void DrawVertexNormal(TetMesh mesh)
 {
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor);
     double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength;
     GL.Begin(BeginMode.Lines);
     foreach (var v in mesh.Vertices)
     {
         if (v.OnBoundary)
         {
             Vector3D normal = v.Normal * l;
             double x = v.Pos.x;
             double y = v.Pos.y;
             double z = v.Pos.z;
             GL.Vertex3(x, y, z);
             GL.Vertex3(x + normal.x, y + normal.y, z + normal.z);
             
         }
     }
     GL.End();
 }
Exemplo n.º 36
0
        public static Vector3D[] ComputeNormalUniformWeight(TetMesh mesh)
        {
            Vector3D[] vn = new Vector3D[mesh.Vertices.Count];
            foreach (var face in mesh.Faces)
            {
                Vector3D fn = ComputeNormal(face);
                if (fn != Vector3D.Zero)
                {
                    foreach (var v in face.Vertices)
                    {
                        vn[v.Index] += fn;
                    }
                }
            }

            for (int i = 0; i < vn.Length; i++)
            {
                vn[i] = vn[i].Normalize();
            }
            return vn;
        }
Exemplo n.º 37
0
        void RefreshFace()
        {
            TetMesh mesh = GlobalData.Instance.TetMesh;

            this.onLoad = true;
            this.faceView.Rows.Clear();
            this.faceView.Rows.Add(mesh.Faces.Count);
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                TetFace         f   = mesh.Faces[i];
                DataGridViewRow row = this.faceView.Rows[i];
                row.Cells["FIndex"].Value    = f.Index;
                row.Cells["FFlag"].Value     = f.Flag;
                row.Cells["FBoundary"].Value = f.OnBoundary;

                row.Cells["FV0"].Value = f.Vertices[0].Index;
                row.Cells["FV1"].Value = f.Vertices[1].Index;
                row.Cells["FV2"].Value = f.Vertices[2].Index;
            }
            this.onLoad = false;
        }
Exemplo n.º 38
0
        public static Vector3D[] ComputeNormalUniformWeight(TetMesh mesh)
        {
            Vector3D[] vn = new Vector3D[mesh.Vertices.Count];
            foreach (var face in mesh.Faces)
            {
                Vector3D fn = ComputeNormal(face);
                if (fn != Vector3D.Zero)
                {
                    foreach (var v in face.Vertices)
                    {
                        vn[v.Index] += fn;
                    }
                }
            }

            for (int i = 0; i < vn.Length; i++)
            {
                vn[i] = vn[i].Normalize();
            }
            return(vn);
        }
Exemplo n.º 39
0
        void RefreshVertex()
        {
            TetMesh mesh = GlobalData.Instance.TetMesh;

            this.onLoad = true;
            this.vertexView.Rows.Clear();
            this.vertexView.Rows.Add(mesh.Vertices.Count);
            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                TetVertex       v   = mesh.Vertices[i];
                DataGridViewRow row = this.vertexView.Rows[i];
                row.Cells["VIndex"].Value    = v.Index;
                row.Cells["VFlag"].Value     = v.Flag;
                row.Cells["VBoundary"].Value = v.OnBoundary;

                row.Cells["VX"].Value = v.Pos.x;
                row.Cells["VY"].Value = v.Pos.y;
                row.Cells["VZ"].Value = v.Pos.z;
            }
            this.onLoad = false;
        }
Exemplo n.º 40
0
        void RefreshTetrahedron()
        {
            TetMesh mesh = GlobalData.Instance.TetMesh;

            this.onLoad = true;
            this.tetrahedronView.Rows.Clear();
            this.tetrahedronView.Rows.Add(mesh.Tetras.Count);
            for (int i = 0; i < mesh.Tetras.Count; i++)
            {
                Tetrahedron     tet = mesh.Tetras[i];
                DataGridViewRow row = this.tetrahedronView.Rows[i];
                row.Cells["TIndex"].Value    = tet.Index;
                row.Cells["TFlag"].Value     = tet.Flag;
                row.Cells["TBoundary"].Value = tet.OnBoundary;

                row.Cells["TV0"].Value = tet.Vertices[0].Index;
                row.Cells["TV1"].Value = tet.Vertices[1].Index;
                row.Cells["TV2"].Value = tet.Vertices[2].Index;
                row.Cells["TV3"].Value = tet.Vertices[3].Index;
            }
            this.onLoad = false;
        }
Exemplo n.º 41
0
        private void CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (!this.onLoad)
            {
                TetMesh            mesh   = GlobalData.Instance.TetMesh;
                DataGridView       dgv    = (DataGridView)sender;
                DataGridViewColumn column = dgv.Columns[e.ColumnIndex];
                DataGridViewRow    row    = dgv.Rows[e.RowIndex];
                int index = (int)row.Cells[0].Value;
                switch (column.Name)
                {
                case "VFlag":
                    mesh.Vertices[index].Flag = Convert.ToInt32(row.Cells[e.ColumnIndex].Value);
                    break;

                case "EFlag":
                    mesh.Edges[index].Flag = Convert.ToInt32(row.Cells[e.ColumnIndex].Value);
                    break;

                case "FFlag":
                    mesh.Faces[index].Flag = Convert.ToInt32(row.Cells[e.ColumnIndex].Value);
                    break;

                case "TFlag":
                    mesh.Tetras[index].Flag = Convert.ToInt32(row.Cells[e.ColumnIndex].Value);
                    break;

                default:
                    break;
                }
                if (!this.onPatch)
                {
                    mesh.ComputeSelectedNormal();
                    GlobalData.Instance.OnChanged(new EventArgs());
                }
            }
        }
Exemplo n.º 42
0
 public void DrawSelectedVertices(TetMesh mesh)
 {
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
     GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
     GL.Enable(EnableCap.PointSmooth);
     GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.SelectedVertexColor);
     GL.Begin(BeginMode.Points);
     foreach (var v in mesh.Vertices)
     {
         if (v.Flag != 0)
         {
             Color4 color = v.Color;
             if (color != Color4.Black)
             {
                 OpenTK.Graphics.Color4 colorTwo = new OpenTK.Graphics.Color4((float)color.R, (float)color.G, (float)color.B, 0.0f);
                 OpenGLManager.Instance.SetColorMesh(colorTwo);
             }
             GL.Normal3(v.Normal.ToArray());
             GL.Vertex3(v.Pos.ToArray());
         }
     }
     GL.End();
 }
Exemplo n.º 43
0
 public void DrawSelectedVertices(TetMesh mesh)
 {
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Point);
     GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
     GL.Enable(EnableCap.PointSmooth);
     GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.SelectedVertexColor);
     GL.Begin(BeginMode.Points);
     foreach (var v in mesh.Vertices)
     {
         if (v.Flag != 0)
         {
             Color4 color = v.Color;
             if (color != Color4.Black)
             {
                 OpenTK.Graphics.Color4 colorTwo = new OpenTK.Graphics.Color4((float)color.R, (float)color.G, (float)color.B, 0.0f);
                 OpenGLManager.Instance.SetColorMesh(colorTwo);
             }
             GL.Normal3(v.Normal.ToArray());
             GL.Vertex3(v.Pos.ToArray());
         }
     }
     GL.End();
 }
Exemplo n.º 44
0
 public void EndTransparent(TetMesh mesh)
 {
     GL.Disable(EnableCap.Blend);
     GL.DepthMask(true);
 }
Exemplo n.º 45
0
        public void DrawSelectedTetrahedron(TetMesh mesh)
        {
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.LineWidth(GlobalSetting.DisplaySetting.LineWidth);
            OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.WifeFrameColor);
            GL.Begin(BeginMode.Triangles);
            foreach (var tet in mesh.Tetras)
            {
                if (tet.Flag != 0)
                {
                    foreach (var face in tet.Faces)
                    {
                        if (TetMeshFlag.CheckBoundary(face) != null)
                        {
                            foreach (var v in face.Vertices)
                            {
                                GL.Normal3(v.SelectedNormal.ToArray());
                                GL.Vertex3(v.Pos.ToArray());
                            }
                        }
                    }
                }
            }
            GL.End();

            GL.LightModel(LightModelParameter.LightModelTwoSide, 1f);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.Normalize);
            //Color c = GlobalSetting.MeshDisplaySetting.TetrahedronColor;
            //OpenGLManager.Instance.SetMeshColor(c);
            GL.Disable(EnableCap.ColorMaterial);
            OpenGLManager.Instance.SetMaterialInfo();

            GL.Begin(BeginMode.Triangles);
            foreach (var tet in mesh.Tetras)
            {
                if (tet.Flag != 0)
                {
                    foreach (var face in tet.Faces)
                    {
                        if (TetMeshFlag.CheckBoundary(face) != null)
                        {
                            foreach (var v in face.Vertices)
                            {
                                GL.Normal3(v.SelectedNormal.ToArray());
                                GL.Vertex3(v.Pos.ToArray());
                            }
                        }
                    }
                }
            }
            GL.End();
            GL.Enable(EnableCap.ColorMaterial);
        }
Exemplo n.º 46
0
 public void DrawSelectedVertexNormal(TetMesh mesh)
 {
     OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor);
     double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength;
     GL.Begin(BeginMode.Lines);
     foreach (var v in mesh.Vertices)
     {
         if (v.SelectedNormal != Vector3D.Zero)
         {
             Vector3D normal = v.SelectedNormal * l;
             GL.Vertex3(v.Pos.ToArray());
             GL.Vertex3((v.Pos + normal).ToArray());
         }
     }
     GL.End();
 }
Exemplo n.º 47
0
 public void EndTransparent(TetMesh mesh)
 {
     GL.Disable(EnableCap.Blend);
     GL.DepthMask(true);
 }