[vtkusers] VTK xml Rectinlinear writer multiple Scalars (Vectors) and timesteps
Mohamad M. Nasr-Azadani
mmnasr at gmail.com
Thu Jan 31 16:18:14 EST 2008
Hi David,
Thanks for the help.
But, since I am new to VTK, I am not sure how to specify the data for
such situations, i.e. multiple scalars or vectors.
I think I can pass several scalars to "vtkXMLWriterC_SetPointData()"
but I am not sure if it is the write way (also I don't know how to
specify different names for different scalars, this way).
Is there any other command (C version) which should be used to set the
non-active scalar data? I went through "vtkXMLWriterC.h" and could not
locate any other function for setting
For example, I want to write two scalars, "Sname1" and "Sname2" which
are already in arrays data1[] and data2[]?
Could you please give me a hint how to do so?
Thanks, again.
-Mohamad
On Jan 31, 2008 5:21 AM, David E DeMarle <dave.demarle at kitware.com> wrote:
> Howdy,
>
> You can have as many arrays as you want in the data and in the file,
> however only one of them at any given time will be marked as the
> SCALARS. Think of the designation SCALARS as meaning, the "ACTIVE"
> scalar array, as opposed to meaning, and array that has a single
> component. Similarly VECTORS means Active vectors and not an array
> with three components, etc. What these designations do is to tell
> downstream filters what array to process if you haven't explicitly
> told them which array by name of position.
>
> cheers,
> Dave
>
>
> On 1/31/08, Mohamad M. Nasr-Azadani <mmnasr at gmail.com> wrote:
> > Hi,
> >
> > I have just started using VTK. I tried to write xml rectilinear vtk
> > files. My code (see below) works fine only for ONE vector field and
> > ONE Scalar and also only one time step.
> > I am trying to write several scalars (or vectors) to file. It turns
> > out after each "vtkXMLWriterC_SetPointData()", the previous data
> > (Vector or Scalar) is replaced by the last one. So, I could only have
> > one Scalar and One Vector field.
> > Also, if I try to write several time steps in one xml file, I do not
> > get the right output.
> >
> > I think someone had that problem before. I did not see any replies to
> > the problem in C.
> > Can someone help me with these two problems?
> >
> > In advance, thanks.
> >
> > -Mohamad
> >
> > PS: Hope this seudo code helps the ones like me who could not find
> > good examples to start with xml writers in vtk.
> >
> > **************************
> >
> > .
> > .
> > .
> >
> > vtkXMLWriterC* writer = vtkXMLWriterC_New();
> > int extent[6] = {0, Nx-1, 0, Ny-1, 0, Nz-1};
> > int Nt = Nx*Ny*Nz;
> > .
> > .
> > .
> > vtkXMLWriterC_SetDataObjectType(writer, VTK_RECTILINEAR_GRID);
> > vtkXMLWriterC_SetExtent(writer, extent);
> >
> > /* xc, yc, zc: arrays of the grid positions */
> > /****************************/
> > axis = 0;
> > dataType = VTK_FLOAT;
> > numCoordinates = Nx;
> >
> > vtkXMLWriterC_SetCoordinates(writer, axis, VTK_FLOAT, xc, Nx);
> >
> > /****************************/
> > axis = 1;
> > dataType = VTK_FLOAT;
> > numCoordinates = Ny;
> >
> > vtkXMLWriterC_SetCoordinates(writer, axis, VTK_FLOAT, yc, Ny);
> > /****************************/
> > axis = 2;
> > dataType = VTK_FLOAT;
> > numCoordinates = Nz;
> >
> > vtkXMLWriterC_SetCoordinates(writer, axis, VTK_FLOAT, zc, Nz);
> >
> > vtkXMLWriterC_SetFileName(writer, "data.vtr");
> > vtkXMLWriterC_SetNumberOfTimeSteps(writer, NTIMESTEPS);
> > vtkXMLWriterC_Start(writer);
> >
> > /* for all timesteps: */
> > for(m=0; m<NTIMESTEPS; m++)
> > {
> >
> > for (k=0; k<Nz; k++) {
> >
> > for (j=0; j<Ny; j++) {
> >
> > for (i=0; i<Nx; i++) {
> >
> > index = k*(Nx*Ny) + j*Nx + i;
> > data1[index] = sin(xc[i])*sin(yc[j]);
> > }
> > }
> > }
> >
> > vtkXMLWriterC_SetPointData(writer, "S1", VTK_FLOAT, data1, Nt, 1,
> > "SCALARS");
> > for (k=0; k<Nz; k++) {
> >
> > for (j=0; j<Ny; j++) {
> >
> > for (i=0; i<Nx; i++) {
> >
> > index = k*(Nx*Ny) + j*Nx + i;
> > data2[index] = cos(xc[i])*cos(yc[j]);
> > }
> > }
> > }
> >
> > vtkXMLWriterC_SetPointData(writer, "S2", VTK_FLOAT, data2, Nt, 1,
> > "SCALARS");
> >
> > vtkXMLWriterC_WriteNextTimeStep(writer, m);
> > }
> >
> > vtkXMLWriterC_Stop(writer);
> > vtkXMLWriterC_Delete(writer);
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
More information about the vtkusers
mailing list