[vtkusers] read .vtk file
shirani kannangara
mangalika673 at gmail.com
Wed Oct 3 01:15:31 EDT 2012
Dear Alex
I want to read an image data file (.vtk format) and visualize it.I tried
with ImageReader2.Cxx. I am using VTK version 5.10 and CMake2.8.9. Though
it made .exe file does not dispaly any.My codes are below.I am highly
appreciated if you could help me.
Shirani
#include <vtkSmartPointer.h>
#include <vtkImageReader2.h>
#include <vtkImageData.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkImageActor.h>
int main(int argc, char *argv[])
{
// Verify command line arguments
/*if(argc < 2)
{
std::cout << "Usage: " << argv[0]
<< " InputFilename" << std::endl;
return EXIT_FAILURE;
}*/
// Parse command line arguments
std::string inputFilename =("D:\\To_SMK\\rgbabdomen\\Debug\\output.vtk");
// Read file
vtkSmartPointer<vtkImageReader2> reader =
vtkSmartPointer<vtkImageReader2>::New();
reader->SetFileName(("D:\\To_SMK\\rgbabdomen\\Debug\\output.vtk"));
reader->SetDataScalarTypeToUnsignedChar();
reader->Update();
// Create an actor
vtkSmartPointer<vtkImageActor> actor =
vtkSmartPointer<vtkImageActor>::New();
actor->SetInput(reader->GetOutput());
// Setup renderer
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->ResetCamera();
// Setup render window
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// Setup render window interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleImage> style =
vtkSmartPointer<vtkInteractorStyleImage>::New();
renderWindowInteractor->SetInteractorStyle(style);
// Render and start interaction
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121003/87d34e2e/attachment.htm>
More information about the vtkusers
mailing list