[vtkusers] [vtkImplicitBoolean] polygonal 3D reconstruction from silhouettes
Cedric
cedric.lm at gmail.com
Thu Aug 9 03:55:08 EDT 2007
Hi all,
I’m working on 3D reconstruction from silhouettes.
What I need is a library for CSG (Constructive Solid Geometry)
computing. And I am looking toward that with VTK.
In fact, what I need to do is to make a boolean intersection between 2
complex polyhedron.
These polyhedron are made like a cone with a polygonal base (which
represente silhouette).
I had a look to the vtkImplicitBoolean class, it seems that it is what I
want to do. But, I don't know how to get a result from that class.
I use the vtkSampleFunction to get it but it doesn't give me any result.
And the only code example I have, for that class is a icecream made with
simple dataset (cone, plane, sphere...).
I give below the code i am using and you can find enclosed the input
data (in a VRML file).
Does anyone know if what I want is possible with VTK (boolean
intersection of complex polyhedron) ?
Does anyone see an error in my approach of the problem ?
Tanks a lot for any help !
Regards,
Cedric.
vtkVRMLImporter* vi = vtkVRMLImporter::New();
vi->SetFileName("cones.wrl");
vi->Read();
vtkRenderer *renderer;
renderer = vi->GetRenderer();
int cones_nb = renderer->GetActors()->GetNumberOfItems();
if (cones_nb > 1) {
vtkImplicitBoolean* coneIntersect = vtkImplicitBoolean::New();
coneIntersect->SetOperationTypeToIntersection();
vtkCollectionIterator* a_it = renderer->GetActors()->NewIterator();
vtkActor** coneActors = new vtkActor*[cones_nb];
vtkActor** coneRemakeActors = new vtkActor*[cones_nb];
a_it->GoToFirstItem();
for (int i_cone=0; i_cone<cones_nb; i_cone++)
{
vtkActor* coneActor = (vtkActor*)a_it->GetCurrentObject();
coneActors[i_cone] = coneActor;
vtkPolyData *conePolyData;
conePolyData = (vtkPolyData *)
coneActor->GetMapper()->GetInput();
vtkImplicitDataSet* coneData = vtkImplicitDataSet::New();
coneData->SetDataSet(conePolyData);
coneIntersect->AddFunction(coneData);
vtkPolyDataMapper* Mapper = vtkPolyDataMapper::New();
Mapper->SetInput(conePolyData);
vtkActor* Actor = vtkActor::New();
Actor->SetMapper(Mapper);
coneRemakeActors[i_cone] = Actor;
a_it->GoToNextItem();
}
vtkSampleFunction* theSample = vtkSampleFunction::New();
theSample->SetImplicitFunction(coneIntersect);
theSample->SetModelBounds(-200, 200, 0, 600, -200, 200);
theSample->SetSampleDimensions(60, 60, 60);
theSample->ComputeNormalsOff();
vtkContourFilter* theSurface = vtkContourFilter::New();
theSurface->SetInputConnection(theSample->GetOutputPort());
theSurface->SetValue(0, 0.0);
vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInputConnection(theSurface->GetOutputPort());
coneMapper->ScalarVisibilityOff();
vtkActor* Actor = vtkActor::New();
Actor->SetMapper(coneMapper);
Actor->GetProperty()->SetColor(1, 0.6, 0.6);
renderer->AddActor(Actor);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( renderer );
renWin->SetSize( 300, 300 );
renWin->Render();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
// VRML export
vtkVRMLExporter* ve = vtkVRMLExporter::New();
ve->SetFileName("out.wrl");
ve->SetInput(renWin);
ve->Write();
ve->Delete();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cones.wrl
Type: model/vrml
Size: 4362 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070809/4587f607/attachment.wrl>
More information about the vtkusers
mailing list