[vtkusers] Question ? Save two actors in vtk or stl file

agatte agatakrason at gmail.com
Sun Jan 12 07:13:01 EST 2014


Hi,


I load two actors, display in the same renderer, after move them (change
position).
I want to save actors (mesh) in vtk or stl file with position ect ..
Now, I obtain save two mesh but I can't save new position. It was
overlapped.

I used vtkPolyDataAppend.

I don't know, what I have to add or change.
Could someone help me please ?

Here  my simple code :

int main(int, char *[])
{
  vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
 
  vtkSmartPointer<vtkSTLReader> readerLower =
vtkSmartPointer<vtkSTLReader>::New();
  readerLower->SetFileName("5EZXH6__lower.stl");
  readerLower->Update();

  vtkSmartPointer<vtkPolyData> lowerPolyData = readerLower->GetOutput();


  vtkSmartPointer<vtkPolyDataMapper> lowerMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
  lowerMapper->SetInput(lowerPolyData);
  vtkSmartPointer<vtkActor> lowerActor =  vtkSmartPointer<vtkActor>::New();
  lowerActor->SetMapper(lowerMapper);
 
  vtkSmartPointer<vtkSTLReader> readerUpper =
vtkSmartPointer<vtkSTLReader>::New();
  readerUpper->SetFileName("5EZXH6__upper.stl");
  readerUpper->Update();

  vtkSmartPointer<vtkPolyData> upperPolyData = readerUpper->GetOutput();
 
  vtkSmartPointer<vtkPolyDataMapper> upperMapper = 
vtkSmartPointer<vtkPolyDataMapper>::New();
  upperMapper->SetInput(upperPolyData);
  vtkSmartPointer<vtkActor> upperActor =  vtkSmartPointer<vtkActor>::New();
  upperActor->SetMapper(upperMapper);
  renderer->AddActor(upperActor);
 
  vtkSmartPointer<vtkActorCollection> actorCollection =
vtkSmartPointer<vtkActorCollection>::New();
  actorCollection->AddItem(lowerActor);
  actorCollection->InitTraversal();
 
  vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
  transform->PostMultiply(); //this is the key line
  transform->RotateZ(180.0);
  transform->RotateX(180.0);
  transform->Translate(0,0,35);

   for(vtkIdType i = 0; i < actorCollection->GetNumberOfItems(); i++)
    {
    vtkActor* actor = actorCollection->GetNextActor();
    actor->SetUserTransform(transform);
    renderer->AddActor(actor);
    }
 
  // Create a renderer, render window, and interactor
  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->AddInputConnection(readerLower->GetOutputPort());
  appender->AddInputConnection(readerUpper->GetOutputPort());
  appender->Update();

  // Save as stl file
  vtkSmartPointer<vtkSTLWriter> writer =
vtkSmartPointer<vtkSTLWriter>::New();
  writer->SetFileName("Actors2.stl");
  writer->SetInput(appender->GetOutput());
  writer->Write();

 // Save as vtk file
  vtkSmartPointer<vtkPolyDataWriter> writerVTK =
vtkSmartPointer<vtkPolyDataWriter>::New();
  writerVTK->SetFileName("ActorsVTK.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-tp5725333.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list