<div>Here's the code of my experiment. You can easily change it to switch between vtkContourFilter and vtkMarchingCubes. As I said, vtkContourFilter displays holes on the voxelized sphere and vtkMarchingCubes doesn't display anything.</div>
<div><br></div><div><div>#include "vtkActor.h"</div><div>#include "vtkPolyDataMapper.h"</div><div>#include "vtkPolyData.h"</div><div>#include "vtkRenderWindowInteractor.h"</div><div>
#include "vtkRenderWindow.h"</div><div>#include "vtkRenderer.h"</div><div><br></div><div>#include "vtkImageData.h"</div><div>#include "vtkVoxelModeller.h"</div><div>#include "vtkMarchingCubes.h"</div>
<div>#include "vtkContourFilter.h"</div><div>#include "vtkSphereSource.h"</div><div><br></div><div>int main(int argc, char *argv[]) {</div><div><br></div><div> vtkRenderer* ren1 = vtkRenderer::New();</div>
<div> ren1->SetBackground(1, 1, 1); // Background color white</div><div><br></div><div> vtkRenderWindow* renWin = vtkRenderWindow::New();</div><div> renWin->AddRenderer(ren1);</div><div> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();</div>
<div> iren->SetRenderWindow(renWin);</div><div><br></div><div> vtkSphereSource* sphereModel = vtkSphereSource::New();</div><div> sphereModel->SetThetaResolution(10);</div><div> sphereModel->SetPhiResolution(10);</div>
<div><br></div><div> vtkVoxelModeller* voxeller = vtkVoxelModeller::New();</div><div> voxeller->SetSampleDimensions(17, 17, 17);</div><div> voxeller->SetModelBounds(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5);</div><div>
voxeller->SetInputConnection(sphereModel->GetOutputPort());</div><div><br></div><div> vtkContourFilter* surface = vtkContourFilter::New();</div><div> //vtkMarchingCubes* surface = vtkMarchingCubes::New();</div>
<div><br></div><div> surface->SetInputConnection(voxeller->GetOutputPort());</div><div> surface->SetNumberOfContours(1);</div><div> surface->ComputeScalarsOn();</div><div> surface->ComputeGradientsOn();</div>
<div> surface->ComputeNormalsOn();</div><div> surface->SetValue(0, 0.5);</div><div><br></div><div> vtkPolyDataMapper* voxelMapper = vtkPolyDataMapper::New();</div><div> voxelMapper->SetInputConnection(surface->GetOutputPort());</div>
<div><br></div><div> vtkActor* voxelActor = vtkActor::New();</div><div> voxelActor->SetMapper(voxelMapper);</div><div><br></div><div> vtkPolyDataMapper* sphereMapper = vtkPolyDataMapper::New();</div><div> sphereMapper->SetInputConnection(sphereModel->GetOutputPort());</div>
<div><br></div><div> vtkActor* sphereActor = vtkActor::New();</div><div> sphereActor->SetMapper(sphereMapper);</div><div><br></div><div> //ren1->AddActor(sphereActor);</div><div> ren1->AddActor(voxelActor);</div>
<div><br></div><div> renWin->Render();</div><div> iren->Start();</div><div>}</div><div><br></div><br><div class="gmail_quote">2010/3/10 David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="im">On Wed, Mar 10, 2010 at 6:12 PM, Daniel Soares <span dir="ltr"><<a href="http://adaptchart.info" target="_blank">adaptchart.info</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I suppose you are saying that I use the following pipeline:<div><br></div><div>vtkSphereSource -> vtkVoxelModeller -> vtkDelaunay3D</div><div><br></div><div>The problem is that the input of vtkDelaunay3D is a vtkPointSet and the output of vtkVoxelModeller is a vtkImageData. How could I convert a vtkImageData to a vtkPointSet?</div>
<div><br></div><div>Anyway, it looks like the solution involves vtkMarchingCubes, as it's input is a vtkImageData. The problem is that vtkMarchingCubes is not displaying any result when used in my source code.</div><div>
<br></div><div>Any ideas?</div><div><br></div><div>Daniel Soares<br></div><div><br></div></blockquote><div class="gmail_quote"><br></div></div>To convert an ImageData to a PointSet, I don't think there is a better way than to do:</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">vtkPolyData* pd = vtkPolyData::New();</div><div class="gmail_quote">for(unsigned int i = 0; i < image->GetNumberOfPoints(); i++</div><div class="gmail_quote">
{</div><div class="gmail_quote"> double p[3];</div><div class="gmail_quote"> image->GetPoint(i, p);</div><div class="gmail_quote"> pd->InsertNextPoint(p);</div><div class="gmail_quote">}</div><div class="gmail_quote">
<br></div><div class="gmail_quote">As for why marching cubes doesn't display anything - maybe you can make the simplest example that will compile - make a sphere source, convert it to an ImageData, then run MarchingCubes. Post this compilable code to the list and we'll check it out.</div>
<div class="gmail_quote"><br clear="all">Thanks,<br><font color="#888888"><br>David</font></div>
</blockquote></div><br></div>