[vtkusers] [Collision detection ] How to prevent overlapping actors ?
agatte
agatakrason at gmail.com
Wed Jan 22 16:57:16 EST 2014
Hi,
I want to prevent overlapping/collision of two actors in the render scene.
I have already tried vtkIntersectionFilter, bu tit doesn't work in my case.
Could You advice me something different ?
int main(int, char *[])
{
// Lower - first model
vtkSmartPointer<vtkSTLReader> readerLower =
vtkSmartPointer<vtkSTLReader>::New();
readerLower->SetFileName("lower.stl");
readerLower->Update();
// Upper - second model
vtkSmartPointer<vtkSTLReader> readerUpper =
vtkSmartPointer<vtkSTLReader>::New();
readerUpper->SetFileName("upper.stl");
readerUpper->Update();
// Create polydata
vtkSmartPointer<vtkPolyData> lowerPolyData = readerLower->GetOutput();
vtkSmartPointer<vtkPolyData> pointsUpperPolyData =
readerUpper->GetOutput();
pointsUpperPolyData->GetPoints();
// Set input transform to avoid overlap actors (models)
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(pointsUpperPolyData); // upperPolyData
transformFilter->SetTransform(transform);
transformFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> lowerMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
lowerMapper->SetInput(lowerPolyData);
vtkSmartPointer<vtkPolyDataMapper> upperMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
upperMapper->SetInput(pointsUpperPolyData);
vtkSmartPointer<vtkActor> upperActor = vtkSmartPointer<vtkActor>::New();
upperActor->SetMapper(upperMapper);
vtkSmartPointer<vtkActor> lowerActor = vtkSmartPointer<vtkActor>::New();
lowerActor->SetMapper(lowerMapper);
lowerActor->SetUserTransform(transform);
vtkSmartPointer<vtkIntersectionPolyDataFilter> intersectionPolyDataFilter
=
vtkSmartPointer<vtkIntersectionPolyDataFilter>::New();
intersectionPolyDataFilter->SetInput( 0, lowerPolyData );
intersectionPolyDataFilter->SetInput( 1, pointsUpperPolyData );
intersectionPolyDataFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> intersectionMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
intersectionMapper->SetInputConnection(
intersectionPolyDataFilter->GetOutputPort() );
intersectionMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> intersectionActor =
vtkSmartPointer<vtkActor>::New();
intersectionActor->SetMapper( intersectionMapper );
//vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
//renderer->AddViewProp(sphere1Actor);
//renderer->AddViewProp(sphere2Actor);
//renderer->AddViewProp(intersectionActor);
// Visualization
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(lowerActor);
renderer->AddActor(upperActor);
//renderer->AddActor(booleanOperationActor);
renderer->AddActor(intersectionActor);
// Render Window
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// Interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Move actors
vtkSmartPointer<vtkInteractorStyleTrackballActor> styleActor =
vtkSmartPointer<vtkInteractorStyleTrackballActor>::New();
renderWindowInteractor->SetInteractorStyle( styleActor );
renderWindowInteractor->SetRenderWindow(renderWindow);
// 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/Collision-detection-How-to-prevent-overlapping-actors-tp5725551.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list