[vtkusers] How Can get the Volume *.stl Format from the Image Slice Data?

#YAN RI AN# PS7278514B at ntu.edu.sg
Mon Sep 30 08:43:28 EDT 2002


Dear VTK- Users:
I want to export the Volume *.stl Format file.
But I can only get the Surface *.stl Format file now.
I have the concept about how to get the Volume *.stl Format file from image slice.
vtkImageData -> vtkPolyData -> vtkTriangleFilter -> .........

I used vtkMarchCubes class to convert vtkImageData to vtkPolyData. It got the Surface *.stl Format only.
Could I use the vtkPolyData Class to convert it, & how to convert?

Here is my Code that got the Surface *.stl Format:

    vtkVolume16Reader *v16=vtkVolume16Reader::New();
    v16->SetDataDimensions(64,64);
    v16->GetOutput()->SetOrigin(0,0,0);
    v16->SetDataByteOrderToLittleEndian();
    v16->SetFilePrefix("c:/Vtkdata/Data/headsq/quarter");
    v16->SetImageRange(1,93);
    v16->SetDataSpacing(1,1,0.5);
    v16->Update();//put the image into memory
	
    vtkMarchingCubes *iso=vtkMarchingCubes::New();
    iso->SetInput(v16->GetOutput());
    iso->SetValue(0,1150);
    iso->ComputeGradientsOff();
    iso->ComputeScalarsOff();
	iso->ComputeNormalsOff();
 
    vtkPolyDataMapper *isoMapper=vtkPolyDataMapper::New();
    isoMapper->SetInput(iso->GetOutput());
    isoMapper->ScalarVisibilityOn();
    isoMapper->ImmediateModeRenderingOn();


    vtkActor *isoActor=vtkActor::New();
    isoActor->SetMapper(isoMapper);
    isoActor->GetProperty()->SetColor(1,1,1);

// Add the actors to the renderer, set the background and size
     vtkRenderer *ren1 = vtkRenderer::New();
     ren1->AddActor(isoActor);
     ren1->SetBackground(0,0,1);
 
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);
    renWin->SetSize(600,600);
  
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);	
  
 
  //
  //STL OutPut
 /*  vtkPolyData *data = vtkPolyData::New();

   data->GetPointData()->SetScalars(int);*/



   vtkTriangleFilter *triangles=vtkTriangleFilter::New();
   triangles->SetInput(iso->GetOutput());
   
  vtkDecimatePro *decimate=vtkDecimatePro::New();
  decimate->SetInput(triangles->GetOutput());
  decimate-> SetTargetReduction(0.6);
  decimate-> PreserveTopologyOn();

   vtkSTLWriter *stl=vtkSTLWriter::New();
   stl->SetInput(decimate->GetOutput());
   stl->SetFileName("head.stl");
   stl->Write();


   //   
  renWin->Render();
  iren->Start();





/*  ren1->Delete();
  renWin->Delete();
  iren->Delete();*/

  return 0;
}
*************************************** 
* Best Regards
* Yan Rian (Research Student) 
* Email : ps7278514b at ntu.edu.sg
* Lab : AMRC Research Centre 
* Nanyang Technological University 
* Singapore 
***************************************





More information about the vtkusers mailing list