[vtkusers] Soild *.stl format needed.

#YAN RI AN# yanrian at pmail.ntu.edu.sg
Mon Feb 24 02:05:53 EST 2003


Dear All vtk users:
I need Solid *.stl format model for the rapid prototyping technology.
the MarchingCubes Algorithm only got isosurface *.stl format only.
I do not know how to solve the proplem.
Could any experts help me?
Here is my program:

 //main program:
    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(3.2,3.2,1.5);
    v16->Update();//put the image into memory
	
    vtkMarchingCubes *iso=vtkMarchingCubes::New();
    iso->SetInput(v16->GetOutput());
    iso->SetValue(0,1150);
    iso->ComputeGradientsOn();
    iso->ComputeScalarsOff();
 
    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
   vtkTriangleFilter *triangles=vtkTriangleFilter::New();
   triangles->SetInput(iso->GetOutput());
   
  vtkDecimatePro *decimate=vtkDecimatePro::New();
  decimate->SetInput(triangles->GetOutput());
  decimate-> SetTargetReduction(0.9);
  decimate-> PreserveTopologyOn();  

   vtkSTLWriter *stl=vtkSTLWriter::New();
   stl->SetInput(decimate->GetOutput());
   stl->SetFileName("head.stl");
   stl->Write();
   //   
  renWin->Render();
  iren->Start();
  
  v16->Delete();
  iso->Delete();
  isoMapper->Delete();
  isoActor->Delete();

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

  triangles->Delete();
  decimate->Delete();
  stl->Delete();

  return 0;
}

*************************************** 
* Best Regards
* Yan Rian (Research Student) 
* Email : yanrian at pmail.ntu.edu.sg
* Lab : AMRC Research Centre 
* Nanyang Technological University 
* Singapore 
***************************************





More information about the vtkusers mailing list