[vtkusers] extractwire

blldw blldw at 163.com
Wed Apr 13 03:46:36 EDT 2011


hello all,
I am looking for help to resolve my problem in VTK for delaunay torus. I first use implicit bool operation to create torus and then extract the torus with vtkExtractGeometry, but the result is not as good as I expected since the result's zigzag. The code and results is as follows.
 
 // create a boolean torus
 vtkSmartPointer<vtkQuadric> circle1 = vtkQuadric::New();
 circle1->SetCoefficients(1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);
 
 vtkSmartPointer<vtkQuadric> circle2 = vtkQuadric::New();
 circle2->SetCoefficients(1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.25);
 
 vtkSmartPointer<vtkImplicitBoolean> subtract = vtkImplicitBoolean::New();
 subtract->SetOperationTypeToDifference();
 subtract->AddFunction(circle1);
 subtract->AddFunction(circle2);
 
 vtkSmartPointer<vtkSampleFunction> sample = vtkSampleFunction::New();
 sample->SetImplicitFunction(subtract);
 sample->SetSampleDimensions(30, 30, 30);
 sample->ComputeNormalsOff();
 
 vtkSmartPointer<vtkExtractGeometry> extract = vtkExtractGeometry::New();
 extract->SetInputConnection(sample->GetOutputPort());
 extract->SetImplicitFunction(subtract);
 extract->ExtractInsideOn();
 
 vtkSmartPointer<vtkDelaunay2D> del2D = vtkDelaunay2D::New();
 del2D->SetInputConnection(extract->GetOutputPort());
 del2D->SetAlpha(0.1);
 
 vtkSmartPointer<vtkDataSetMapper> mapper = vtkDataSetMapper::New();
 mapper->SetInputConnection(del2D->GetOutputPort());
 
 vtkSmartPointer<vtkActor> actor = vtkActor::New();
 actor->SetMapper(mapper);
 actor->GetProperty()->SetColor(1.0, 1.0, 1.0);
 
 vtkSmartPointer<vtkRenderer> renderer = vtkRenderer::New();
 vtkSmartPointer<vtkRenderWindow> renWin = vtkRenderWindow::New();
 vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkRenderWindowInteractor::New();
 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkInteractorStyleTrackballCamera::New();
 renderer->AddActor(actor);
 renderer->SetBackground(0.0, 0.0, 0.0);
 renderer->ResetCamera();
 renWin->AddRenderer(renderer);
 renWin->SetSize(500, 500);
 renWin->Render();
 iren->SetInteractorStyle(style);
 iren->SetRenderWindow(renWin);
 iren->Initialize();
 iren->Start();
I would like to make the edge smooth so I add a vtkContourFilter before vtkExtractGeometryFilter, and before the vtkExtractGeometryFilter and vtkDelaunay2D is applied on the output of vtkContourFilter, the result looks good.
the result is achieved by adding a vtkContourFilter without vtkExtractGeometry and vtkDelaunay2D applied:
// The code here is the same as above
vtkSmartPointer<vtkSampleFunction> sample = vtkSampleFunction::New();
 sample->SetImplicitFunction(subtract);
 sample->SetSampleDimensions(30, 30, 30);
 sample->ComputeNormalsOff();
 
vtkSmartPointer<vtkContourFilter> contour = vtkContourFilter::New();
 contour->SetInputConnection(sample->GetOutputPort());
 contour->SetValue(0, 0.0);
 
vtkSmartPointer<vtkDataSetMapper> mapper = vtkDataSetMapper::New();
 mapper->SetInputConnection(contour->GetOutputPort());
// the following code is the same as above
 
NOW I add vtkExtractGeometry and vtkDelaunay2D after vtkContourFilter:
 
// contour filter has been added
vtkSmartPointer<vtkExtractGeometry> extract = vtkExtractGeometry::New();
 extract->SetInputConnection(contour->GetOutputPort());
 extract->SetImplicitFunction(subtract);
 extract->ExtractInsideOn();
 
 vtkSmartPointer<vtkDelaunay2D> del2D = vtkDelaunay2D::New();
 del2D->SetInputConnection(extract->GetOutputPort());
 del2D->SetAlpha(0.1);
 
vtkSmartPointer<vtkDataSetMapper> mapper = vtkDataSetMapper::New();
 mapper->SetInputConnection(del2D->GetOutputPort());
// The following code doesn't change
 
What I got is:
What should I do in order to get delaunayed smooth torus, OR anyone could give me other methods to get the torus inside of which is delaunayed?
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110413/f4665fdb/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extractwire.png
Type: image/png
Size: 11570 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110413/f4665fdb/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: torus.png
Type: image/png
Size: 5069 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110413/f4665fdb/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: torusdel.png
Type: image/png
Size: 4291 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110413/f4665fdb/attachment-0002.png>


More information about the vtkusers mailing list