adityatan's picture

Suggestions for plotting lines

Hi there:

I'm trying to plot lines in a specified order. The problem is that the lines are numerous and has unknown numbers (could varies all the time depends on the data).

Any suggestions on how should I store these coordinates and plot it?

THank you.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sgsrules's picture

You can create a List, Dictionary, or even a sorted dictionary to store vectors for the coordinates. All of these collections can have elements added or removed.

hannesh's picture

Could you clarify?
From what I understand you want an ordered array of elements.

Will elements get randomly added or removed (then i'd suggest some kind of tree)?
Or is it a fixed size with only the data changing? If so, does it need to be resorted?

adityatan's picture

Thanks for the response. I tried to create a List; but it couldn't take an int inputs. It's strange. Let me do one other thing, and I'll get back to you guys on Monday evening.

Sorry for being unclear. Thanks for the help.


hannesh's picture

Do you know how to use lists?

List myList = new List();
int value = 42;

the Fiddler's picture

Or, more specifically:

using System;
using System.Collection.Generics;
List<int> myList = new List<int>();
foreach (int i in myList)
    // Do something with i
adityatan's picture

I'm sorry for being unclear.

So, here's the summary of what I'm trying to do:

1. Get the element numbers using "a.Mesh.ElementConnectivityList.ElementAt(k)[0] = Convert.ToInt32(fields[0]);"
2. Store the element numbers using "index0.Add(a.Mesh.ElementConnectivityList.ElementAt(k)[0] - 1);"
3. Get the coordinates for the corresponding element numbers using "a.Nodes.ElementAt(i).Coordinate[0] = Convert.ToDouble(fields[0]);"
4. Assigning each element numbers to their corresponding coordinates AND storing them using "x_temp0.Add(a.Nodes.ElementAt(index).Coordinate[0]);"
5. And finally plot them in OnRenderFrame.

And below is the detailed piece of code. Do not worry about my camera and OpenTK set-up, they are correct.

        protected override void OnLoad(EventArgs e)
            List<int> index0_temp = new List<int>();
            using (TextReader rdr3 = File.OpenText(@"c:\Input Files\SampleS05.PLT"))
                string line3;
                while ((line3 = rdr3.ReadLine()) != null)
                    string[] fields = line3.Split(new char[] { ' ' });
                    if (fields.Count() < 5)
                        k = k + 1;
                        a.Mesh.ElementConnectivityList.ElementAt(k)[0] = Convert.ToInt32(fields[0]);
                        index0.Add(a.Mesh.ElementConnectivityList.ElementAt(k)[0] - 1);                        
            //Assigning the values from the text file to the nodes
            using (TextReader rdr2 = File.OpenText(@"c:\Input Files\SampleS05.PLT"))
                string line2;
                while ((line2 = rdr2.ReadLine()) != null)
                    string[] fields = line2.Split(new char[] { ' ' });
                    if (fields.Count() > 5)
                        i = i + 1;
                        a.Nodes.ElementAt(i).Coordinate[0] = Convert.ToDouble(fields[0]); // x coordinate
                        a.Nodes.ElementAt(i).Coordinate[1] = Convert.ToDouble(fields[1]); // y coordinate
                        a.Nodes.ElementAt(i).Coordinate[2] = Convert.ToDouble(fields[2]); // z coordinate
                        // Storing the elements
                        foreach (var index in index0)
        protected override void OnRenderFrame(FrameEventArgs e)
            // Plotting the element nodes
            foreach (var vertex in coordinates)

Thank you for your help!

Aditya Tan

P.S. @Fiddler: Welcome back!