// Draw the file helix private void Helix(int length, float[][] points) { if (finished) { int choice; if (DisplacementCB.SelectedIndex != -1) { choice = (int)DisplacementCB.SelectedIndex; } else { choice = 0; } // Get the array of displacements of choice float[] displacementType = ArrayManipulation.GetColumn(tensions.ToArray(), choice); TransformDisplacement(displacementType); OpenGL gl = GLControl.OpenGL; gl.Begin(BeginMode.LineStrip); float[] color = new float[] { 0.0f, 0.0f, 0.0f }; float[] displacement = displacementTransformed.ToArray(); for (int i = 0; i < length; i++) { // Colors switch (displacement[i]) { case var n when n >= -1 && n < -0.6: color = new float[] { 0.0f, 0.0f, 1.0f }; // Blue break; case var n when n >= -0.6 && n < -0.3: color = new float[] { 0.0f, 1.0f, 1.0f }; // Cyan break; case var n when n >= -0.3 && n < 0: color = new float[] { 0.0f, 1.0f, 0.0f }; // Green break; case var n when n >= 0 && n < 0.3: color = new float[] { 1.0f, 1.0f, 0.0f }; // Yellow break; case var n when n >= 0.3 && n < 0.6: color = new float[] { 1.0f, 0.5f, 0.0f }; // Orange break; case var n when n >= 0.6: color = new float[] { 1.0f, 0.0f, 0.0f }; // Red break; default: break; } gl.Color(color); gl.Vertex(new SharpGL.SceneGraph.Vertex(points[i][0], points[i][1], points[i][2])); } gl.End(); // Done Rendering gl.Flush(); } }
// Open file dialog and events private void OpenFileClick(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog { DefaultExt = ".txt", // Required file extension Filter = "Text documents (.txt)|*.txt" // Optional file extensions }; bool?result = dlg.ShowDialog(); if (result == true) { using (Stream s = dlg.OpenFile()) { // Get the path of the file string path = dlg.FileName; tb.Text = path; // Get the number of points registered in the file, discount the first line int length = File.ReadAllLines(path).Length - 1; // Begin reading float[,] points = new float[length, 7]; int count = -1; foreach (string line in File.ReadLines(path)) { // Get the numbers in a line string[] numbers = line.Split(); // Exclude the first line if (line[0] != char.Parse("I")) { for (int i = 0; i < 7; i++) { // Form the matrix containing all numbers points[count, i] = float.Parse(numbers[i], CultureInfo.InvariantCulture); } } count++; } // Put the wanted data in different arrays float[,] pointsCartesian = new float[length, 3]; float[,] displacement = new float[length, 3]; for (int i = 0; i < length; i++) { pointsCartesian[i, 0] = points[i, 1] * (float)Math.Cos(points[i, 2]) / 10; pointsCartesian[i, 1] = points[i, 1] * (float)Math.Sin(points[i, 2]) / 10; pointsCartesian[i, 2] = points[i, 3] / 10; displacement[i, 0] = points[i, 4]; displacement[i, 1] = points[i, 5]; displacement[i, 2] = points[i, 6]; } // Add the data in external lists for further use for (int i = 0; i < length; i++) { vertexes.Add(ArrayManipulation.GetRow(pointsCartesian, i)); tensions.Add(ArrayManipulation.GetRow(displacement, i)); } if (path != "") { btnOpenFile.IsEnabled = false; } openFileOk = true; } } }