[vtkusers] Marching Cubes Problem
David Doria
daviddoria+vtk at gmail.com
Thu Jul 22 15:17:21 EDT 2010
2010/7/22 Vinícius da Silva <dsilva.vinicius at gmail.com>:
> Hello, everybody.
>
> I'm testing VTK marching cubes to know if this algorithm suits my needs. I'm
> trying to make a simple example, using the vtkMarchingCubes in a
> vtkImageData volumetric array, but the resulting vtkPolyData doesn't make
> much sense for me. Am I doing something wrong? The code is below.
>
> Thanks.
>
> void calcIsoSurface(vtkPolyData *pPolyData){
> //create an image data
> vtkSmartPointer<vtkImageData> pImageData =
> vtkSmartPointer<vtkImageData>::New();
>
> //specify the size of the image data
> pImageData->SetDimensions(I_XDIM , I_YDIM , I_ZDIM);
> pImageData->SetNumberOfScalarComponents(1);
> pImageData->SetScalarTypeToDouble();
>
> int* piDims = pImageData->GetDimensions();
>
> cout << "Dims: " << " x: " << piDims[0] << " y: " << piDims[1] << " z: "
> << piDims[2] << endl;
> cout << "Number of points: " << pImageData->GetNumberOfPoints() << endl;
> cout << "Number of cells: " << pImageData->GetNumberOfCells() << endl;
>
> for (int iZ = 0; iZ < piDims[2]; iZ++){
> for (int iY = 0; iY < piDims[1]; iY++){
> for (int iX = 0; iX < piDims[0]; iX++){
> double* pdPixel =
> static_cast<double*>(pImageData->GetScalarPointer(iX , iY , iZ));
> if(iX < 1 || iY < 1 || iZ < 1 || iX > piDims[0] - 2 || iY >
> piDims[1] - 2 || iZ > piDims[2] - 2){
> pdPixel[0] = 10.0;
> }else if(iX < 2 || iY < 2 || iZ < 2 || iX > piDims[0] - 3 ||
> iY > piDims[1] - 3 || iZ > piDims[2] - 3){
> pdPixel[0] = 0.0;
> }
> else{
> pdPixel[0] = -10.0;
> }
> }
> }
> }
>
> pImageData->Update();
> vtkMarchingCubes *pIso = vtkMarchingCubes::New();
> pIso->SetInput(pImageData);
> pIso->SetNumberOfContours(1);
> pIso->SetValue(0, 0.0);
> pIso->Update();
>
> vtkIndent indent;
> pIso->PrintSelf(cout , indent);
> g_pPolyData = vtkPolyData::New();
> g_pPolyData = pIso->GetOutput();
> g_pPolyData->Update();
>
> //writing the status of PolyData
> cout << endl << "isoSurface: lines: " << g_pPolyData->GetNumberOfLines()
> << " vertices: " << g_pPolyData->GetNumberOfVerts() << endl;
> }
>
> Best Regards,
>
> Vinícius da Silva,
> M. Sc. Student
> Systems Engineering and Computation Program
> PESC/COPPE/UFRJ
> Rio de Janeiro - Brazil
>
Have you seen the wiki examples? http://www.vtk.org/Wiki/VTK/Examples
There is an example of marching cubes there:
http://www.vtk.org/Wiki/VTK/Examples/Medical/GenerateModelsFromLabels
Let us know if you still have any problems.
Thanks,
David
More information about the vtkusers
mailing list