private int DeleteNoisyPoints(Common.Vbo handle) { List <Vector3> v = new List <Vector3>(); List <Vector3> n = new List <Vector3>(); float threashold = SPUR_DISTANCE_THREASHOLD * SPUR_DISTANCE_THREASHOLD; for (int i = 0; i < handle.verticesStats.numVertices; i++) { if ((handle.verticesData.vertices[i] - handle.verticesStats.Mean).LengthSquared < threashold) { v.Add(handle.verticesData.vertices[i]); if (handle.validNormals) { n.Add(handle.verticesData.normals[i]); } } } int dels = handle.verticesStats.numVertices - v.Count; //handle.verticesData.vertices = v.ToArray(); //if (handle.validNormals) // handle.verticesData.normals = n.ToArray(); LoadVertices_Normals(ref handle, v.ToArray(), n.ToArray()); InitVerticesStats(ref handle); return(dels); }
public string ComputeNormals(ref Common.Vbo handle, int k, bool flipNormals) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = Directory.GetCurrentDirectory() + @"\MeshLabServer"; string inputMeshFile = GenerateTempMeshName("xyz"); string outputMeshFile = GenerateTempMeshName("ply"); WriteXYZFile(inputMeshFile, handle.verticesData.vertices, null); startInfo.FileName = @"MeshLabServer\meshlabserver.exe"; startInfo.Arguments = "-i " + @inputMeshFile + " -o " + outputMeshFile; startInfo.Arguments += " -s NormalEstimation.mlx";//BallPivoting.mlx"; startInfo.Arguments += " -om vn"; startInfo.RedirectStandardOutput = false; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = false; try { EditMLXFile_NormalK(startInfo.WorkingDirectory + @"\NormalEstimation.mlx", k, flipNormals); } catch (Exception e) { Common.Logger.Log("MainForm", "Triangulation.cs", "ComputeNormals", e.Message, true); return(e.Message); } try { using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit(); //exeProcess.Kill(); exeProcess.Close(); } File.Delete(inputMeshFile); if (File.Exists(outputMeshFile)) { Common.Logger.Log("MainForm", "Triangulatoin", "ComputeNormals", "Point cloud normal calculated", false); return(outputMeshFile); } else { Common.Logger.Log("MainForm", "Triangulatoin", "ComputeNormals", "Error in Point cloud normal calculation", true); return("error");; } } catch (Exception e) { Common.Logger.Log("MainForm", "Triangulatoin", "ComputeNormals", e.Message, true); return("error"); } }
private void TranslateRotate(Common.Vbo handle, float[,] rotationMat, float[] transformation) { Vector4[] rotv = new Vector4[4]; for (int i = 0; i < 3; i++) { rotv[i] = new Vector4(rotationMat[i, 0], rotationMat[i, 1], rotationMat[i, 2], 0); } rotv[3] = new Vector4(0, 0, 0, 0); Matrix4 rotm = new Matrix4(rotv[0], rotv[1], rotv[2], rotv[3]); Vector3 transv = new Vector3(transformation[0], transformation[1], transformation[2]); Vector3[] newPoints = new Vector3[handle.verticesData.vertices.Length]; Vector3[] newNormals = new Vector3[handle.verticesData.normals.Length]; for (int i = 0; i < newPoints.Length; i++) { Matrix4 t = new Matrix4(new Vector4(handle.verticesData.vertices[i]), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0)); t = Matrix4.Mult(t, rotm); newPoints[i] = t.Row0.Xyz + transv; t = new Matrix4(new Vector4(handle.verticesData.normals[i]), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0)); t = Matrix4.Mult(t, rotm); newNormals[i] = t.Row0.Xyz; } handle.verticesData.vertices = newPoints; handle.verticesData.normals = newNormals; ReLoadBuffer(BufferTarget.ArrayBuffer, handle.VboVertices, handle.verticesData.vertices); ReLoadBuffer(BufferTarget.ArrayBuffer, handle.VboNormals, handle.verticesData.normals); }
private void Reset(ref Common.Vbo handle) { Application.Idle -= Application_Idle; Thread.Sleep(100); //UnBindOpenGL(); DeleteVBO(ref handle); ClearArrays(ref handle.verticesData); handle.selectedVertices.Clear(); if (!vbo1.validVertices && !vbo2.validVertices) { InitOpenGL(); } Application.Idle += Application_Idle; InitVerticesStats(ref handle); //InitTeethBoxes(); if (handle.vboName == "vbo1") { config.lastLoadedMeshFileAddress1 = "empty"; config.lastLoadedMeshName1 = "No Mesh loaded"; config.lastLoadedMeshType1 = "empty"; } else if (handle.vboName == "vbo2") { config.lastLoadedMeshFileAddress2 = "empty"; config.lastLoadedMeshName2 = "No Mesh loaded"; config.lastLoadedMeshType2 = "empty"; } ClearSelection(handle); UpdateUI(); }
private void InitVBO(ref Common.Vbo handle, string name) { handle = new Vbo() { vboName = name }; }
void DiscriminateSelectedVertex(ref Common.Vbo handle, uint vertexNumber) { if (!VertexColorChange(ref handle, vertexNumber, DISCRIMINATECOLOR)) { return; } }
void IndiscriminateSelectedVertex(Common.Vbo handle, uint vertexNumber) { Vector3 color; if (handle == null) { return; } if (handle.selectedVertices.Contains(vertexNumber)) { int index = handle.selectedVertices.FindIndex(x => x == vertexNumber); if (index <= 12) { color = Common.Common.ColorRGB2Float(Common.Common.SelectColor[index]); } else { color = SELECTCOLOR; } } else { float d = (float)randColor.NextDouble() / 20; color = new Vector3(d, d, d); color = color + handle.color; } if (!VertexColorChange(ref handle, vertexNumber, color)) { return; } }
void DeleteVBO(ref Common.Vbo handle) { GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.BindTexture(TextureTarget.Texture2D, 0); if (handle.validVertices) { GL.DeleteBuffers(1, ref handle.VboVertices); GL.DeleteBuffers(1, ref handle.VboNormals); GL.DeleteBuffers(1, ref handle.VboColor); handle.VboColor = 0; handle.VboNormals = 0; handle.VboVertices = 0; handle.validVertices = false; handle.validNormals = false; handle.validColor = false; handle.NumTriElements = 0; handle.NumWireElements = 0; } if (handle.validMesh) { GL.DeleteBuffers(1, ref handle.TriEID); GL.DeleteBuffers(1, ref handle.WireframeEID); handle.TriEID = 0; handle.WireframeEID = 0; handle.validMesh = false; handle.validWireframe = false; } }
private Vector3[] ProjectToothOnAxisPlane(Common.Vbo handle, Common.Plane axisP, Common.Plane occlusalP) { const float dist2CenterTh = 5; const float dist2PlaneTh = 0.2f; List <Vector3> projectedPoints = new List <Vector3>(); double distanceToLowest = occlusalP.Distance2Point(axisP.lowestPoint); double distanceToHighest = occlusalP.Distance2Point(axisP.highestPoint); //int sideLowest = occlusalP.PointSide for (int i = 0; i < handle.verticesData.vertices.Length; i++) { if (axisP.Distance2Point(handle.verticesData.vertices[i]) < dist2PlaneTh && (handle.verticesData.vertices[i] - axisP.center).Length <dist2CenterTh && //occlusalP.Distance2Point(handle.verticesData.vertices[i]) < distanceToLowest && //occlusalP.Distance2Point(handle.verticesData.vertices[i]) > distanceToHighest handle.verticesData.vertices[i].Z> axisP.lowestPoint.Z && // ASSUMING CAST IS FACED UPWARD = Z handle.verticesData.vertices[i].Z < axisP.highestPoint.Z //ASSUMING CAST IS FACED UPWARD = Z ) { projectedPoints.Add(axisP.ProjectPointOnPlane(handle.verticesData.vertices[i])); } } return(projectedPoints.ToArray());//projectedPointsOnAxisPlane[selectedToothIndex].ToArray(); ; }
private void WriteSelectionFile(string fileAddress, Common.Vbo handle) { TextWriter tw = new StreamWriter(File.Create(fileAddress)); tw.WriteLine("OrthoAid - TXT Selection File"); tw.Write("X,Y,Z,index\n"); for (int i = 0; i < handle.selectedVertices.Count; i++) { //modified for convenience Vector3 p = handle.verticesData.vertices[handle.selectedVertices[i]]; tw.WriteLine(p.X.ToString() + ',' + p.Y.ToString() + ',' + p.Z.ToString() + "," + handle.selectedVertices[i].ToString()); //new one for better excel import //Vector3 p = handle.verticesData.vertices[handle.selectedVertices[i]]; //tw.Write(p.X.ToString() + ',' + p.Y.ToString() + ',' + p.Z.ToString() + // ","); } //new one for better excel import //tw.WriteLine(); //for (int i = 0; i < handle.selectedVertices.Count; i++) //{ // tw.Write(handle.selectedVertices[i].ToString()+','); //} tw.Close(); }
private bool DefineSagitalPlane(Common.Vbo handle, ref Common.Plane plane, int selectedIndex, Common.Plane occlusalPlane) { if (occlusalPlane == null || !occlusalPlane.valid) { MessageBox.Show("Occlusal Plane should be defined prior to defining Sagital Plane.", "No Occlusal Plane"); return(false); } List <uint> sel; Vector3[] verts; sel = handle.selectedVertices; verts = handle.verticesData.vertices; if (sel.Count != 2) { MessageBox.Show("To define a Sagital Plane, first define the Occlusal Plane, then Select 2 points on the midline.", "Wrong number of selected points"); return(false); } plane = new Common.Plane(verts[sel[0]], verts[sel[1]], occlusalPlane.GetNormal()) { valid = true }; return(true); }
private void TranslateRotate(Common.Vbo handle, float rx, float ry, float rz, float tx, float ty, float tz) { Matrix4 rotMatx = Matrix4.CreateRotationX(rx); Matrix4 rotMaty = Matrix4.CreateRotationY(ry); Matrix4 rotMatz = Matrix4.CreateRotationZ(rz); Vector3 transMat = new Vector3(tx, ty, tz); Vector3[] newPoints = new Vector3[handle.verticesData.vertices.Length]; Vector3[] newNormals = new Vector3[handle.verticesData.normals.Length]; for (int i = 0; i < newPoints.Length; i++) { Matrix4 t = new Matrix4(new Vector4(handle.verticesData.vertices[i]), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0)); t = Matrix4.Mult(t, rotMatx); t = Matrix4.Mult(t, rotMaty); t = Matrix4.Mult(t, rotMatz); newPoints[i] = t.Row0.Xyz + transMat; t = new Matrix4(new Vector4(handle.verticesData.normals[i]), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0)); t = Matrix4.Mult(t, rotMatx); t = Matrix4.Mult(t, rotMaty); t = Matrix4.Mult(t, rotMatz); //t = Matrix4.Mult(t, transMat); newNormals[i] = t.Row0.Xyz; } handle.verticesData.vertices = newPoints; handle.verticesData.normals = newNormals; ReLoadBuffer(BufferTarget.ArrayBuffer, handle.VboVertices, handle.verticesData.vertices); ReLoadBuffer(BufferTarget.ArrayBuffer, handle.VboNormals, handle.verticesData.normals); }
void LoadVertices_Normals(ref Common.Vbo handle, Vector3[] vertices, Vector3[] normals) { try { if (LoadBuffer <Vector3>(BufferTarget.ArrayBuffer, ref handle.VboVertices, vertices)) { handle.validVertices = true; } else { throw new ApplicationException("Vertex data not uploaded correctly"); } flags.verticesSelectionType = Common.VerticesSelectionType.vertices; if (normals != null && normals.Length > 0) { if (LoadBuffer <Vector3>(BufferTarget.ArrayBuffer, ref handle.VboNormals, normals)) { handle.validNormals = true; } } else { GL.GenBuffers(1, out handle.VboNormals); } SetColor(ref handle); if (flags.RandomColorEnable) { Vector3[] colors = new Vector3[vertices.Length]; for (int i = 0; i < colors.Length; i++) { float d = (float)randColor.NextDouble() / 20; colors[i] = new Vector3(d, d, d) + handle.color; } if (LoadBuffer <Vector3>(BufferTarget.ArrayBuffer, ref handle.VboColor, colors)) { handle.validColor = true; } } handle.verticesData.vertices = vertices; handle.verticesData.normals = normals; Common.Logger.Log("MainForm", "Load", "LoadVertices_Normals", "Vertices and Normals loaded", false); } catch (Exception e) { Common.Logger.Log("MainForm", "Load", "LoadVertices_Normals", e.Message, true); } config.viewMode = Common.ViewMode.Points; UpdateUI(); }
private bool DefineTeethPlaneAndTangentLine(Common.Vbo handle, ref Common.Plane toothAxisPlane, int selectedToothIndex, Common.Plane[] Planes) { try { List <uint> sel; Vector3[] verts; sel = handle.selectedVertices; verts = handle.verticesData.vertices; if (sel.Count != 3) { MessageBox.Show("Exactly 3 points must be selected to define the tooth axis", "Wrong number of points"); return(false); } if (Planes[OCCLUSALPLANE_INDEX] == null || !Planes[OCCLUSALPLANE_INDEX].valid) { MessageBox.Show("Occlusal Plane should be defined prior to calculatin tooth Inclination.", "No Occlusal Plane"); return(false); } Vector3 point1 = verts[sel[0]]; Vector3 point2 = verts[sel[1]]; Vector3 point3 = verts[sel[2]]; //making sure points are in correct order--> lowest:point1, middle: point2, top: point3 //cause occulsal plane sometimes goes lower than the upper and even middle point, //couldn't find a solution at the moment and decided to go with this: //the operator should Select the points in the correct order: lowest=first, highest=last //Sort3PointsBasedOnDistanceToOcclusalPlane(ref point1, ref point2, ref point3, Planes[OCCLUSALPLANE_INDEX]); toothAxisPlane = DefineAxisPlane(point1, point2, point3, Planes[OCCLUSALPLANE_INDEX]); Vector3[] projectedPoints = ProjectToothOnAxisPlane(handle, toothAxisPlane, Planes[OCCLUSALPLANE_INDEX]); Vector3[] projectedPointsOnBuccal = FindAndSortPointsOnBuccalSide(projectedPoints, toothAxisPlane, Planes[OCCLUSALPLANE_INDEX]); Vector3 BBPUser = point2; Vector3 projectedBBPUser = toothAxisPlane.ProjectPointOnPlane(point2); toothAxisPlane.projectedPointsOnAxisPlane = projectedPointsOnBuccal; toothAxisPlane.tangentPoints = CalculateTangentLine(projectedPointsOnBuccal, toothAxisPlane, projectedBBPUser); Vector3 tangentVector = toothAxisPlane.tangentPoints[1] - toothAxisPlane.tangentPoints[0]; toothAxisPlane.Inclination = Planes[OCCLUSALPLANE_INDEX].Angle2Vector(tangentVector); //radian toothAxisPlane.Inclination = (toothAxisPlane.Inclination / (float)Math.PI) * 180; toothAxisPlane.Inclination = CorrectInclination_BiggerORSmallerThan90(toothAxisPlane, point1, Planes[OCCLUSALPLANE_INDEX]); toothAxisPlane.validInclination = true; return(true); } catch (Exception e) { Common.Logger.Log("MainForm", "TeethComputations", "DefineTeethPlaneAndTangentLine", e.Message, true); return(false); } }
private void ClearSelection(Common.Vbo handle) { for (int i = 0; i < handle.selectedVertices.Count; ++i) { UnmarkSelectedVertex(ref handle, handle.selectedVertices[i]); } handle.selectedVertices.Clear(); UpdateUI(); }
private void Select(ref Common.Vbo handle) { //GL.GetInteger(GetPName.Viewport, viewport); int heightDiff = 0;// this.Height - glControlCast.Height - 38; double[] modelview = new double[16]; double[] projection = new double[16]; //viewport[2] = 711; //viewport[3] = 600; GL.GetDouble(GetPName.ModelviewMatrix, modelview); GL.GetDouble(GetPName.ProjectionMatrix, projection); // obtain the Z position (not world coordinates but in range 0 - 1) float z_cursor = 0; GL.ReadPixels(MouseX, viewport[3] - MouseY - heightDiff, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent , PixelType.Float, ref z_cursor); // obtain the world coordinates double[] x, y, z; x = new double[1]; y = new double[1]; z = new double[1]; #pragma warning disable CS0618 // 'Glu' is obsolete: 'Use OpenTK math functions instead.' OpenTK.Graphics.Glu.UnProject((double)MouseX, viewport[3] - (double)MouseY - heightDiff, (double)z_cursor, #pragma warning restore CS0618 // 'Glu' is obsolete: 'Use OpenTK math functions instead.' modelview, projection, viewport, x, y, z); //this.Text = x[0].ToString().Substring(0,5) + " : " + y[0].ToString().Substring(0,5) + " : " + z[0].ToString().Substring(0,5); //this.Text = MouseX + " : " + MouseY; uint vertexNumber = FindNearestVertex(ref handle, x[0], y[0], z[0]); //uint trueVertexNumber = FindNearestTrueVertex(x[0], y[0], z[0]); if (vertexNumber != NO_VERTEX_INDEX) { if (pointedVertexNumber != vertexNumber) { if (pointedVertexNumber != NO_VERTEX_INDEX) { IndiscriminateSelectedVertex(handle, pointedVertexNumber); } DiscriminateSelectedVertex(ref handle, vertexNumber); pointedVertexNumber = vertexNumber; } } else { if (pointedVertexNumber != NO_VERTEX_INDEX) { IndiscriminateSelectedVertex(handle, pointedVertexNumber); } pointedVertexNumber = vertexNumber; } }
public ComputeNormalsForm(MainForm f, Common.Vbo vbo) { InitializeComponent(); this.f = f; this.vbo = vbo; foreach (Control control in this.Controls) { control.KeyDown += ComputeNormalsForm_KeyDown; } }
void UnmarkSelectedVertex(ref Common.Vbo handle, uint vertexNumber) { Vector3 color; float d = (float)randColor.NextDouble() / 20; color = new Vector3(d, d, d) + handle.color; if (!VertexColorChange(ref handle, vertexNumber, color)) { return; } }
private void LoadPointCloud(string FileName, Common.Vbo handle) { Reset(ref handle); Vector3[] vertices; Vector3[] normals; //ReadXYZNInputFile(FileName, out vertices, out normals); ReadPointCloudInputFile(FileName, out vertices, out normals); LoadVertices_Normals(ref handle, vertices, normals); UpdateFileRelatedConfiguration(ref handle, FileName, "point cloud"); handle.show = true; InitVerticesStats(ref handle); CentralizeCast(GetSelectedVBO()); }
private float Ruler_ComputeDistance(Common.Vbo handle) { if (Ruler_PointAIndex != NO_VERTEX_INDEX && Ruler_PointBIndex != NO_VERTEX_INDEX) { Ruler_PointA = handle.verticesData.vertices[Ruler_PointAIndex]; Ruler_PointB = handle.verticesData.vertices[Ruler_PointBIndex]; float f = (Ruler_PointA - Ruler_PointB).Length; return(f); } else { return(0); } }
private void CalculateDistanceToPlane(Common.Vbo handle, int selectedIndex) { if ((handle.selectedVertices.Count != 1)) { if ((selectedIndex == 1 && (Planes[0][OCCLUSALPLANE_INDEX] == null || Planes[0][SAGITALPLANE_INDEX] == null)) || (selectedIndex == 2 && (Planes[1][OCCLUSALPLANE_INDEX] == null || Planes[1][SAGITALPLANE_INDEX] == null))) { MessageBox.Show("After defining the Occlusal/Sagital Plane, Select a tooth and a cusp tip to calculate the distance from the cusp tip to the defined plane.", "Wrong number of points"); return; } } List <uint> sel; Vector3[] verts; sel = handle.selectedVertices; verts = handle.verticesData.vertices; if (GetSelectedVbOIndex() == 1) { if (Planes[0][OCCLUSALPLANE_INDEX] != null && Planes[0][OCCLUSALPLANE_INDEX].valid) { Distance2OcclusalPlane1[selectedIndex].length = (float)Planes[0][OCCLUSALPLANE_INDEX].Distance2Point(verts[sel[0]]); Distance2OcclusalPlane1[selectedIndex].valid = true; } if (Planes[0][SAGITALPLANE_INDEX] != null && Planes[0][SAGITALPLANE_INDEX].valid) { Distance2SagitalPlane1[selectedIndex].length = (float)Planes[0][SAGITALPLANE_INDEX].Distance2Point(verts[sel[0]]); Distance2SagitalPlane1[selectedIndex].valid = true; } } else if (GetSelectedVbOIndex() == 2) { if (Planes[1][OCCLUSALPLANE_INDEX] != null && Planes[1][OCCLUSALPLANE_INDEX].valid) { Distance2OcclusalPlane2[selectedIndex].length = (float)Planes[1][OCCLUSALPLANE_INDEX].Distance2Point(verts[sel[0]]); Distance2OcclusalPlane2[selectedIndex].valid = true; } if (Planes[1][SAGITALPLANE_INDEX] != null && Planes[1][SAGITALPLANE_INDEX].valid) { Distance2SagitalPlane2[selectedIndex].length = (float)Planes[1][SAGITALPLANE_INDEX].Distance2Point(verts[sel[0]]); Distance2SagitalPlane2[selectedIndex].valid = true; } } }
private void ReadSelectionFile(string fileAddress, Common.Vbo handle) { StreamReader sr = new StreamReader(fileAddress); try { string[] header1 = sr.ReadLine().Split(','); if (header1[0] != "OrthoAid - TXT Selection File" && header1[0] != "AHA OrthoAid - TXT Selection File") { throw new Exception("Selection calculation file was not in the correct format"); } string header2 = sr.ReadLine(); if (header2 != "X,Y,Z,index") { throw new Exception("Selection calculation file was not in the correct format"); } handle.selectedVertices.Clear(); //while (!sr.EndOfStream) //{ // string[] tokens = sr.ReadLine().Split(','); // handle.selectedVertices.Add(uint.Parse(tokens[3])); //} //sr.ReadLine(); //SKIPPING XYZ DATA //string[] tokens = sr.ReadLine().Split(','); //for (int i = 0; i < tokens.Length - 1; ++i) //-1 for the last comma // handle.selectedVertices.Add(uint.Parse(tokens[i])); while (sr.Peek() != -1) { string[] tokens = sr.ReadLine().Split(','); handle.selectedVertices.Add(uint.Parse(tokens[3])); } UpdateUI(); } catch (Exception err) { Common.Logger.Log("MainForm", "ReadWriteFile", "ReadSelectionFile", err.ToString(), true); } sr.Close(); }
private void LoadMesh(string FileName, Common.Vbo handle) { Reset(ref handle); Vector3[] vertices; Vector3[] normals; UInt32[] indices; ReadMeshInputFile(FileName, out vertices, out normals, out indices); //@"tri\inputBigMeshLabGUIBallPivoting_1.tri"); LoadVertices_Normals(ref handle, vertices, normals); LoadIndices(ref handle, indices); UpdateFileRelatedConfiguration(ref handle, FileName, "mesh"); handle.show = true; InitVerticesStats(ref handle); CentralizeCast(GetSelectedVBO()); }
private bool VertexColorChange(ref Common.Vbo handle, uint vertexNumber, Vector3 color) { try { //Vector3 color = new Vector3(0.7f, 0, 0f); GL.BindBuffer(BufferTarget.ArrayBuffer, handle.VboColor); GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)((vertexNumber) * 12), (IntPtr)(BlittableValueType.StrideOf(color)), ref color); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); return(true); } catch (Exception e) { Common.Logger.Log("MainForm", "Selection", "VertexColorChange", e.Message, true); return(false); } }
void LoadIndices(ref Common.Vbo handle, UInt32[] indices) { try { //Index of Triangulation if (LoadBuffer <uint>(BufferTarget.ElementArrayBuffer, ref handle.TriEID, indices)) { handle.validMesh = true; handle.NumTriElements = indices.Length; } //Index of WireFrame uint[] wire = new uint[indices.Length * 2]; int count = 0; for (int i = 0; i < indices.Length; i += 3) { wire[count++] = indices[i]; wire[count++] = indices[i + 1]; wire[count++] = indices[i + 1]; wire[count++] = indices[i + 2]; wire[count++] = indices[i + 2]; wire[count++] = indices[i]; } if (LoadBuffer <uint>(BufferTarget.ElementArrayBuffer, ref handle.WireframeEID, wire)) { handle.validWireframe = true; handle.NumWireElements = wire.Length; } handle.verticesData.indices = indices; Common.Logger.Log("MainForm", "Load", "LoadIndices", "indices loaded.", false); } catch (Exception e) { Common.Logger.Log("MainForm", "Load", "LoadIndices", e.Message, true); } config.viewMode = Common.ViewMode.Mesh; UpdateUI(); }
void MarkInsertedVertices(Common.Vbo handle) { for (int i = 0; i < handle.selectedVertices.Count; i++) { Vector3 color; if (i <= 12) { color = Common.Common.ColorRGB2Float(Common.Common.SelectColor[i]); } else { color = SELECTCOLOR; } if (!VertexColorChange(ref handle, handle.selectedVertices[i], color)) { return; } } }
private uint FindNearestVertex(ref Common.Vbo handle, double x, double y, double z) { double minDist = double.MaxValue; uint minIndex = NO_VERTEX_INDEX; Vector3 v = new Vector3((float)x, (float)y, (float)z); for (uint i = 0; i < handle.verticesData.vertices.Length; ++i) { float mag = (handle.verticesData.vertices[i] - v).Length; if (mag < minDist && mag < (handle.verticesStats.MaxX - handle.verticesStats.MinX) / 3) { minDist = mag; minIndex = i; } } return(minIndex); }
bool DefineOcclusalPlane(Common.Vbo handle, ref Common.Plane plane, int planeNumber) { List <uint> sel; Vector3[] verts; sel = handle.selectedVertices; verts = handle.verticesData.vertices; if (sel.Count != 3) { MessageBox.Show("Exactly 3 points must be selected to define the Occlusal Plane", "Wrong number of points"); return(false); } plane = new Common.Plane(verts[sel[0]], verts[sel[1]], verts[sel[2]], "occlusal " + planeNumber.ToString(), PLANE_DRAW_RADIUS_OTHER) { valid = true }; return(true); }
void MarkAndInsertSelectedVertex(Common.Vbo handle, uint vertexNumber) { //this.Text += "+ " + vertexNumber.ToString(); if (!handle.show) { return; } if (controlKeyDown || lockSelection) { if (!handle.selectedVertices.Contains(vertexNumber)) { if (vertexNumber != NO_VERTEX_INDEX) { handle.selectedVertices.Add(vertexNumber); } } else { handle.selectedVertices.Remove(vertexNumber); UnmarkSelectedVertex(ref handle, vertexNumber); } } else { for (int i = 0; i < handle.selectedVertices.Count; ++i) { UnmarkSelectedVertex(ref handle, handle.selectedVertices[i]); } handle.selectedVertices.Clear(); if (vertexNumber != NO_VERTEX_INDEX) { handle.selectedVertices.Add(vertexNumber); } } }
private void DrawAll() { if (!openGLInitiated) { return; } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); //DrawBackground(); SetCamera(); DrawCoords(); //GL.Enable(EnableCap.Blend); if (vbo1.validVertices && vbo1.show) { Render(vbo1); MarkInsertedVertices(vbo1); } if (vbo2.validVertices && vbo2.show) { Render(vbo2); MarkInsertedVertices(vbo2); } if (reduceDensityVbo.validVertices && reduceDensityVbo.show) { Render(reduceDensityVbo); } //GL.Disable(EnableCap.Blend); Common.Vbo vbo = GetSelectedVBO(); if (vbo != null && vbo.validMesh && vbo.show) { if (config.editMode == Common.EditMode.Select || config.editMode == Common.EditMode.Ruler) { Select(ref vbo); } } if (vbo1.validVertices && vbo1.show) { for (int i = 1; i < OCCLUSALPLANE_INDEX; ++i) { if (tcb[i].Checked && Planes[0][i] != null && Planes[0][i].valid) { //DrawPlane(Planes[0][i], Color.Pink); //DrawProjectedPoints(Planes[0][i].projectedPointsOnAxisPlane, Color.Yellow); DrawTangentLine(Planes[0][i].tangentPoints, Color.BlueViolet); } } for (int i = OCCLUSALPLANE_INDEX; i <= CURVEPLANE_INDEX; ++i) { if (tcb[Plane_CB1[i]].Checked && Planes[0][i] != null && Planes[0][i].valid) { DrawPlane(Planes[0][i], Color.Blue); } } } if (vbo2.validVertices && vbo2.show) { for (int i = 1; i < OCCLUSALPLANE_INDEX; ++i) { if (tcb[i].Checked && Planes[1][i] != null && Planes[1][i].valid) { //DrawPlane(Planes[1][i], Color.Pink); //DrawProjectedPoints(Planes[1][i].projectedPointsOnAxisPlane, Color.Yellow); DrawTangentLine(Planes[1][i].tangentPoints, Color.YellowGreen); } } for (int i = OCCLUSALPLANE_INDEX; i <= CURVEPLANE_INDEX; ++i) { if (tcb[Plane_CB2[i]].Checked && Planes[1][i] != null && Planes[1][i].valid) { DrawPlane(Planes[1][i], Color.Yellow); } } } if (config.editMode == Common.EditMode.Ruler) { DrawRulerLine(Color.BlueViolet); } glControlCast.SwapBuffers(); }