[vtkusers] Marching Cubes Problem
Vinícius da Silva
dsilva.vinicius at gmail.com
Thu Jul 22 15:05:07 EDT 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100722/a90711a3/attachment.htm>
More information about the vtkusers
mailing list