read and view .vtk file

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

read and view .vtk file

Zou Jing

Dear all 

T want to read and view .vtk file ,but there is an error at    actor->SetMapper(Mapper)    

said that There is no proper conversion function from vtkSmartPointer<vtkPolyDataMapper> to<vtkImageMapper3D> .

here is my code:

vtkSmartPointer<vtkPolyDataReader> vtkReader = vtkSmartPointer<vtkPolyDataReader>::New();
vtkReader->SetFileName("C:\\Users\\Administrator\\Desktop\\jing\\t.vtk");

//vtkSmartPointer<vtkPolyData> polydata = vtkReader->GetOutput();

vtkSmartPointer<vtkPolyDataMapper> Mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
Mapper->SetInputConnection(vtkReader->GetOutputPort());

vtkSmartPointer<vtkImageActor> actor =
vtkSmartPointer<vtkImageActor>::New();
actor->SetMapper(Mapper);//->SetInputConnection(vtkreader->GetOutputPort());

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow); 
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
 


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: read and view .vtk file

Polly Lina
This post has NOT been accepted by the mailing list yet.
Hi, I am also just started to learn on VTK. This is how i do my code to read my .vtk files.
Hope this help.

#include "vtkPolyDataReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkPolyData.h"
#include "vtkRenderWindowInteractor.h"
#include <stdio.h>
#include <iostream>
#include <string>

std::string strg;

int main (int argc, char *argv[])
{

 vtkPolyDataReader *face = vtkPolyDataReader::New();
 //face->SetFileName("370.vtk");
 face->SetFileName(argv[1]); //type the file name .vtk when load in cmd Face.exe xxx.vtk
 strg = argv[1];


 vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
 mapper->SetInputConnection(face->GetOutputPort());
 
 vtkActor *faceActor = vtkActor::New();
 faceActor->SetMapper(mapper);
 
 vtkRenderer *ren=vtkRenderer::New();
 ren->AddActor(faceActor);
 ren->SetBackground(.1, .1, .1);
 ren->GetSize();

 vtkRenderWindow *renWindow=vtkRenderWindow::New();
 renWindow->AddRenderer(ren);
 renWindow->SetSize(500, 500);

 vtkRenderWindowInteractor *renderWindowInteractor = vtkRenderWindowInteractor::New();
 renderWindowInteractor->SetRenderWindow(renWindow);

 renWindow->Render();
 renderWindowInteractor->Start();
 
 return EXIT_SUCCESS;
}