[vtkusers] Read data from a .vtk file

madz madaramh at gmail.com
Wed Jan 28 01:51:14 EST 2015


I'm trying to read array data from a .vtk file (see attachment). The code
I've used is,

#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkStructuredGridReader.h>
#include <vtkStructuredGridGeometryFilter.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkStructuredGridOutlineFilter.h>
#include <vtkShrinkFilter.h>
#include <vtkCellData.h>
#include <vtkXMLStructuredGridWriter.h>
#include <vtkXMLStructuredGridReader.h>
#include <vtkPlane.h>
#include <vtkCutter.h>
#include <vtkDataSetReader.h>

int main(int argc, char* argv[])
{
	std::string inputFilename = "Zone2.vtk";

	// Read the file
	vtkSmartPointer<vtkDataSetReader> reader
=vtkSmartPointer<vtkDataSetReader>::New();
	reader->SetFileName(inputFilename.c_str());
	reader->Update();

	vtkSmartPointer<vtkGeometryFilter> geometryFilter =
vtkSmartPointer<vtkGeometryFilter>::New();
	geometryFilter->SetInputConnection(reader->GetOutputPort());
	geometryFilter->Update(); 

	vtkSmartPointer<vtkPolyData> polydata = geometryFilter->GetOutput();
	vtkSmartPointer<vtkDataArray> arr1 =
polydata->GetFieldData()->GetArray("EnergyStagnationDensity");
	vtkSmartPointer<vtkDataArray> arr2 =
polydata->GetCellData()->GetArray("EnergyStagnationDensity");
	vtkSmartPointer<vtkDataArray> arr3 =
polydata->GetPointData()->GetArray("EnergyStagnationDensity");

	// Visualize
	vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInput(polydata);

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);

	actor->GetProperty()->SetRepresentationToSurface();
	//actor->GetProperty()->SetRepresentationToPoints();
	//actor->GetProperty()->SetRepresentationToWireframe();

	vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
	renderer->AddActor(actor);


	vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
	renderWindow->AddRenderer(renderer);

	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
	renderWindowInteractor->SetRenderWindow(renderWindow);

	renderer->Render();
	renderer->SetBackground(1,1,1);

	renderWindow->Render();
	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}

When I view the file from paraView it displays 3 dataArrays. "Density",
"EnergyStagnationDensity" and "Momentum". I can access both "Momentum" and
"Density" how ever I cannot access "EnergyStagnationDensity". I tried this
with vtkDataSetReader and got the same result. Is there a way to access all
3 dataArrays? If anyone can point out how paraView has accomplished this
I'll be most grateful.

<http://vtk.1045678.n5.nabble.com/file/n5730244/zone2.png> 



file -  Zone2.vtk <http://vtk.1045678.n5.nabble.com/file/n5730244/Zone2.vtk>   



--
View this message in context: http://vtk.1045678.n5.nabble.com/Read-data-from-a-vtk-file-tp5730244.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list