[vtkusers] Function to read a file

David Doria daviddoria+vtk at gmail.com
Mon Jul 6 10:17:23 EDT 2009


On Mon, Jul 6, 2009 at 9:10 AM, ClaudeG <claude.gangolf at gmail.com> wrote:

>
> The problem is that i have a file which is like this :
>
> 0 2
> 1.5 1.5 1.5 1.5 1.5 1.5
> 2.5 2.4 2.6 2.4  2.5 2.7
>
> where in the first line 0 stands for the time (here the first time step) 2
> stand for two vectors and then comes the coordinates from the vectors, the
> second line has the coordinates from the first vector an so on, the first
> three values are the x,y,z coordinate from the starting point and the last
> three values are teh x,y,z values from the ending point.
>
> And i want now read the file and stor the value in x1, y1, z1, x2, y2, z2,
> so that i can use the values later in an other function.
>

I'm still not clear on what the problem is?

Is a real file like this?
0 2
1.5 1.5 1.5 1.5 1.5 1.5
2.5 2.4 2.6 2.4  2.5 2.7
1 3
1.5 1.5 1.5 1.5 1.5 1.5
2.5 2.4 2.6 2.4  2.5 2.7
2.5 2.4 2.6 2.4  2.5 2.7

Are you trying to make each time step into a polydata? What do you want in
each polydata? a unit vector from the starting point in the direction (end -
start)? a vector between start and end? Do you want them to be lines or
arrows? Are you trying to display this from c++ or do you want to write it
to a file? From what you said you just want to store the values... so you
could do something like the below (just an outline, clearly) - but this
isn't a VTK question so it is better posed on a c++ mailing list:

struct Vec
{

	double x1,y1,z1,x2,y2,z2;
Vec(const double X1, const double Y1, const double Z1, const double
X2, const double Y2, const double Z2) : x1(X1), y1(Y1), z1(Z1),
x2(X2), y2(Y2), z2(Z2){}

};
//the outer std::vector is the time steps, the inner std::vector is the
std::vector<std::vector<Vec> > Vectors;

	while(getline(fin, line))
	{
//... figure out when a new time step starts ...

std::vector<Vec> CurrentTimeVectors;
		double x1,y1,z1,x2,y2,z2;
		std::stringstream linestream;
		linestream << line;
		linestream >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;

Vec v(x1,y1,z1,x2,y2,z1);
CurrentTimeVectors.push_back(v);

// ... when the current time step ends...
Vectors.push_back(CurrentTimeVectors);
	}



Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090706/16126a55/attachment.htm>


More information about the vtkusers mailing list