[vtkusers] How to Change Variable Array in VTK Plot?

Shahid Rauf srauf106326 at gmail.com
Wed Feb 10 00:33:17 EST 2010


I am new to VTK and would greatly appreciate help with the following
question.

I have an XML Unstructured Grid data file (.vtu) which has multiple scalar
DataArrays within the PointData block:

            <PointData Scalars="var_1">
        <DataArray type="Float32" Name="var_1" format="ascii">
          ...
        </DataArray>
        <DataArray type="Float32" Name="var_2" format="ascii">
          ...
        </DataArray>
        <DataArray type="Float32" Name="var_3" format="ascii">
          ...
        </DataArray>
      </PointData>

I can visualize the data in this file using Paraview and look at the
different variables easily.  I am now trying to visualize using a C++ VTK
program, but the program is only displaying the first variable ("var_1").
 So far I have not been able to figure out how to make VTK plot the other
variables ("var_2", "var_3").  Can somebody let me know which class and
function to use to change the scalar variable that is plotted.  I am
including portions of my C++ code to help explain what I am doing.

  vtkRenderer *renderer = vtkRenderer::New();
 vtkRenderWindow *renWin = vtkRenderWindow::New();
 renWin->AddRenderer(renderer);
 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
 iren->SetRenderWindow(renWin);

 vtkXMLUnstructuredGridReader *reader = vtkXMLUnstructuredGridReader::New();
 char *cfname = "vtk.vtu";
 reader->SetFileName( cfname );
 delete[] cfname;
 reader->Update();

 vtkExtractUnstructuredGrid *usplane=vtkExtractUnstructuredGrid::New();
 usplane->SetInput(reader->GetOutput());
 usplane->SetExtent(-10,10,-10,10,-10,10);

 vtkPlane *planefunction=vtkPlane::New();
 planefunction->SetOrigin(0.0,0.0,0.05);
 planefunction->SetNormal(0,0,1);

 vtkCutter *cutter=vtkCutter::New();
 cutter->SetInput(usplane->GetOutput());
 cutter->SetCutFunction(planefunction);

 vtkPolyDataMapper *planeMapper=vtkPolyDataMapper::New();
 planeMapper->SetInputConnection(cutter->GetOutputPort());
 planeMapper->SetScalarModeToUsePointData();
 planeMapper->SetScalarRange(0.0,100.0);
 vtkActor *planeActor=vtkActor::New();
 planeActor->SetMapper(planeMapper);

 renderer->AddActor(planeActor);

 renWin->Render();
 iren->Start();

Thanks a lot for your help,

Shahid Rauf.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100209/be70a3ae/attachment.htm>


More information about the vtkusers mailing list