[vtkusers] Question ? Save two actors in vtk or stl file
alethea
alethea at anatomage.com
Wed Jan 15 12:58:36 EST 2014
For display, you can transform an object by changing the data (mesh points),
or the actor (user transform). vtkTransformPolyDataFilter works on the
first, and I assume this is what you mean by "fixed transformation"? I don't
know of any way to use vtkPolyDataWriter to store actor transformation
information. However, you could always save this information in a separate
file, that you reload, and use to recreate the actor transform you were
using in your first version.
For more information on how vtkPolyDataWriter is writing your data, see
http://www.vtk.org/VTK/img/file-formats.pdf
You'll notice that it does not include any mapper or actor information.
Hope this helps
agatte wrote
> 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-tp5725333p5725418.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list