[vtkusers] Question ? Save two actors in vtk or stl file
agatte
agatakrason at gmail.com
Wed Jan 15 02:58:47 EST 2014
Hi,
Thanks for reply.
I apply vtkTransform and vtkTransformPolyDataFilter, but It save two models
with fixed transformation.
When I change position of actors (mesh), It doesn't save modified transform
?
I want to change position of actors(mesh) and save it in new position.
I need to compute new transform after changed postion of actors.
int main(int, char *[])
{
// Lower - first model
vtkSmartPointer<vtkSTLReader> readerLower =
vtkSmartPointer<vtkSTLReader>::New();
readerLower->SetFileName("5EZXH6__lower.stl");
readerLower->Update();
// Upper - second model
vtkSmartPointer<vtkSTLReader> readerUpper =
vtkSmartPointer<vtkSTLReader>::New();
readerUpper->SetFileName("5EZXH6__upper.stl");
readerUpper->Update();
// Create polydata
vtkSmartPointer<vtkPolyData> lowerPolyData = readerLower->GetOutput();
vtkSmartPointer<vtkPolyData> upperPolyData = readerUpper->GetOutput();
// Set transform
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->PostMultiply();
transform->RotateZ(180.0);
transform->RotateX(180.0);
transform->Translate(0,0,35);
// Set polydata filter
vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transformFilter->SetInput(upperPolyData);
// transformFilter->AddInput(upperPolyData);
//transformFilter->AddInput(lowerPolyData);
transformFilter->SetTransform(transform);
transformFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> lowerMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
lowerMapper->SetInput(lowerPolyData);
vtkSmartPointer<vtkPolyDataMapper> upperMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
upperMapper->SetInput(upperPolyData);
vtkSmartPointer<vtkActor> upperActor = vtkSmartPointer<vtkActor>::New();
upperActor->SetMapper(upperMapper);
vtkSmartPointer<vtkActor> lowerActor = vtkSmartPointer<vtkActor>::New();
lowerActor->SetMapper(lowerMapper);
lowerActor->SetUserTransform(transform);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(lowerActor);
renderer->AddActor(upperActor);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
vtkSmartPointer<vtkInteractorStyleTrackballActor> styleActor =
vtkSmartPointer<vtkInteractorStyleTrackballActor>::New();
renderWindowInteractor->SetInteractorStyle( styleActor );
renderWindowInteractor->SetRenderWindow(renderWindow);
// Join two actors
vtkSmartPointer<vtkAppendPolyData> appender =
vtkSmartPointer<vtkAppendPolyData>::New();
appender->AddInput(upperPolyData);
//appender->AddInput(lowerPolyData);
appender->AddInput(transformFilter->GetOutput());
appender->Update();
//// Add the actor to the scene
//vtkSmartPointer<vtkSTLWriter> writer =
vtkSmartPointer<vtkSTLWriter>::New();
//writer->SetFileName("Actors2.stl");
//writer->SetInput(appender->GetOutput());
//writer->Write();
vtkSmartPointer<vtkPolyDataWriter> writerVTK =
vtkSmartPointer<vtkPolyDataWriter>::New();
writerVTK->SetFileName("ActorsVTK3.vtk");
writerVTK->SetInput(appender->GetOutput());
writerVTK->Write();
// Render and interact
renderer->SetBackground(.2, .3, .4);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
I would appreciate for any help please :)
--
View this message in context: http://vtk.1045678.n5.nabble.com/Question-Save-two-actors-in-vtk-or-stl-file-tp5725333p5725393.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list