[vtkusers] Marching Cubes Problem
Bill Lorensen
bill.lorensen at gmail.com
Thu Jul 22 15:36:47 EDT 2010
The wiki example is for a volume that has been labeled (segmented)
into discrete labels. For grayscale data, look at the examples in the
vtk source distribution:
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Medical/Cxx/Medical1.cxx;h=c920c7bcc50f40ffe9befac17c5e757f0df9349e;hb=HEAD
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Medical/Cxx/Medical2.cxx;h=74e980bc326a1c6724324ee714b36df94fea80ac;hb=HEAD
http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Medical/Cxx/Medical3.cxx;h=321f2b224fa02dfc01b00443959b3e1f90e46640;hb=HEAD
Bill
2010/7/22 David Doria <daviddoria+vtk at gmail.com>:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list