<html><body><span class="xfm_80024569">Hello, I've been playing with VTK examples and got the tool that renders 3D mesh, based on DICOM files. <br/>How can I export the mesh to .ply or .stl file?<br/><br/>My code:<br/><div>#include <vtkVersion.h></div><div>#include <vtkSmartPointer.h></div><div>#include <vtkSphere.h></div><div>#include <vtkSampleFunction.h></div><div>#include <vtkSmartVolumeMapper.h></div><div>#include <vtkColorTransferFunction.h></div><div>#include <vtkPiecewiseFunction.h></div><div>#include <vtkRenderer.h></div><div>#include <vtkRenderWindow.h></div><div>#include <vtkRenderWindowInteractor.h></div><div>#include <vtkVolumeProperty.h></div><div>#include <vtkCamera.h></div><div>#include <vtkImageShiftScale.h></div><div>#include <vtkImageData.h></div><div>#include <vtkPointData.h></div><div>#include <vtkDataArray.h></div><div>#include <vtkXMLImageDataReader.h></div><div>#include <vtkPLYWriter.h></div><div>#include <vtkDICOMImageReader.h></div><div>#include <vtkVolumeOutlineSource.h></div><div><br/></div><div>int main(int argc, char* argv[])</div><div>{</div><div> // Verify input arguments</div><div> if ( argc != 3 )</div><div> {</div><div> std::cout << "Usage: " << argv[0]</div><div> << " FolderName" << "Export.ply" << std::endl;</div><div> return EXIT_FAILURE;</div><div> }</div><div><br/></div><div> std::string folder = argv[1];</div><div> std::string output = argv[2];</div><div><br/></div><div> // Read all the DICOM files in the specified directory.</div><div> vtkSmartPointer<vtkDICOMImageReader> reader =</div><div> vtkSmartPointer<vtkDICOMImageReader>::New();</div><div> reader->SetDirectoryName(folder.c_str());</div><div> reader->Update();</div><div><br/></div><div> //Create vtkImageData</div><div> vtkSmartPointer<vtkImageData> imageData =</div><div> vtkSmartPointer<vtkImageData>::New();</div><div><br/></div><div> imageData->ShallowCopy(reader->GetOutput());</div><div><br/></div><div> //renderer</div><div> vtkSmartPointer<vtkRenderWindow> renWin =</div><div> vtkSmartPointer<vtkRenderWindow>::New();</div><div> vtkSmartPointer<vtkRenderer> ren1 =</div><div> vtkSmartPointer<vtkRenderer>::New();</div><div> ren1->SetBackground(0,0,0);</div><div><br/></div><div> renWin->AddRenderer(ren1);</div><div><br/></div><div> renWin->SetSize(301,300); // intentional odd and NPOT width/height</div><div><br/></div><div> vtkSmartPointer<vtkRenderWindowInteractor> iren =</div><div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div> iren->SetRenderWindow(renWin);</div><div><br/></div><div> renWin->Render(); // make sure we have an OpenGL context.</div><div><br/></div><div> vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper =</div><div> vtkSmartPointer<vtkSmartVolumeMapper>::New();</div><div> volumeMapper->SetBlendModeToComposite(); // composite first</div><div>#if VTK_MAJOR_VERSION <= 5</div><div> volumeMapper->SetInputConnection(imageData->GetProducerPort());</div><div>#else</div><div> volumeMapper->SetInputData(imageData);</div><div>#endif</div><div> vtkSmartPointer<vtkVolumeProperty> volumeProperty =</div><div> vtkSmartPointer<vtkVolumeProperty>::New();</div><div> volumeProperty->ShadeOff();</div><div> volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);</div><div><br/></div><div> vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =</div><div> vtkSmartPointer<vtkPiecewiseFunction>::New();</div><div> compositeOpacity->AddPoint(-1000.0,0.0);</div><div> compositeOpacity->AddPoint(0.0,0.0);</div><div> compositeOpacity->AddPoint(1000.0,0.89);</div><div> volumeProperty->SetScalarOpacity(compositeOpacity); // composite first.</div><div><br/></div><div> vtkSmartPointer<vtkColorTransferFunction> color =</div><div> vtkSmartPointer<vtkColorTransferFunction>::New();</div><div><br/></div><div> color->AddRGBPoint(0, 0.0, 0.0, 0.0);</div><div> color->AddRGBPoint(1000, 1.0, 1, 1);</div><div> color->AddRGBPoint(-1000, 0.0, 0.0, 0.0);</div><div> volumeProperty->SetColor(color);</div><div><br/></div><div> volumeProperty->SetInterpolationTypeToLinear();</div><div> volumeProperty->ShadeOff();</div><div><br/></div><div> vtkSmartPointer<vtkVolume> volume =</div><div> vtkSmartPointer<vtkVolume>::New();</div><div> volume->SetMapper(volumeMapper);</div><div> volume->SetProperty(volumeProperty);</div><div><br/></div><div><br/></div><div> ren1->AddViewProp(volume);</div><div> ren1->ResetCamera();</div><div><br/></div><div> // Render composite. In default mode. For coverage.</div><div> renWin->Render();</div><div><br/></div><div> // 3D texture mode. For coverage.</div><div> volumeMapper->SetRequestedRenderModeToDefault();</div><div> renWin->Render();</div><div><br/></div><div> // Software mode, for coverage. It also makes sure we will get the same</div><div> // regression image on all platforms.</div><div> volumeMapper->SetRequestedRenderModeToRayCast();</div><div> renWin->Render();</div><div><br/></div><div> iren->Start();</div><div><br/></div><div> return EXIT_SUCCESS;</div><div>}</div></span><img src="https://mail.ukr.net/api/public/message_read?a=gqeivMpnKHmsk7uvZLEpXiDsCdY_EMjkU1dKcr_DLx6reUcMnZOb_uZ1hYiWY3C-xWJvpm8NJwAEWykfMCPXAZqNcA==" alt="" width="1" height="1" style="visibility: hidden; width: 1px; height: 1px;"/> </body></html>