[vtkusers] From .vtp and PolyData to ImageData

Lonni Besançon lonni.besancon at gmail.com
Wed Jul 6 08:38:28 EDT 2016


Hello everyone,

I have a working code that can read and display .vtk and .vti file with the
following code (just an extract of the code, because it's too long).

/vtkSmartPointer<vtkImageData>  loadTypedDataSet(const std::string&
fileName){

vtkNew<T> reader;

	LOGI("Loading file: %s...", fileName.c_str());
	reader->SetFileName(fileName.c_str());

	vtkNew<VTKErrorObserver> errorObserver;
	reader->AddObserver(vtkCommand::ErrorEvent, errorObserver.GetPointer());

	reader->Update();

	if (errorObserver->hasError()) {
		// TODO? Throw a different type of error to let Java code
		// display a helpful message to the user
		throw std::runtime_error("Error loading data: " +
errorObserver->getErrorMessage());
	}

	vtkSmartPointer<vtkImageData> data = vtkSmartPointer<vtkImageData>::New();
	data->DeepCopy(reader->GetOutputDataObject(0));

	return data;
}



const std::string ext = fileName.substr(fileName.find_last_of(".") + 1);
if (ext == "vtk")
	data = loadTypedDataSet<vtkDataSetReader>(fileName);
else if (ext == "vti")
	data = loadTypedDataSet<vtkXMLImageDataReader>(fileName);
else
        throw std::runtime_error("Error loading data: unknown extension: \""
+ ext + "\"");
/

Except that now I would like to adapt it to render .vtp files (such as
bunny.vtp or teapot.vtp).

I was wondering if you could point me in the right direction there.

For the remaining part of my code I really need to be able to manipulate
vtkImageData, so I would like to be able to obtain an image data from the
input file if possible.

Have a good day and thanks in advance for the help,





--
View this message in context: http://vtk.1045678.n5.nabble.com/From-vtp-and-PolyData-to-ImageData-tp5739138.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list