<html><body><span class="xfm_80429276">I think it is CT/MRT. Thank you for your answer. Do vtk has something better than marching cubes if you say it's not good enough?<br/><br/><div style="font-size:14px;font-style:italic;">
31 July 2015, 18:45:38, by "Bill Lorensen" <<a href="mailto:bill.lorensen@gmail.com" target="_self">bill.lorensen@gmail.com</a>>:<br/></div>
<br/><blockquote style="border-left:1px solid rgb(204, 204, 204);margin:0px 0px 0px 0.8ex;padding-left:1ex;">
<span>
  <div dir="ltr">stl and ply store triangles and, for ply, polygons. Your example is rendering a volume directly. You would need to extract polygonal surfaces from your volume. This means you will need to perform some sort of segmentation to identify the structures to model with polygons. Marching Cubes is one technique that extracts surfaces based on a threshold. But most medical segmentation requires more sophisticated techniques.<div><br/></div><div>What is the modality of the dicom files/ CT, MRI, PET, ...?</div><div><br/></div></div>
  <div class="xfmc1"><br/><div class="xfmc2">On Fri, Jul 31, 2015 at 11:16 AM, Ievgen Petrashchuk <span dir="ltr"><<a href="mailto:vaper@ukr.net" target="_blank">vaper@ukr.net</a>></span> wrote:<br/><blockquote class="xfmc2" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><span>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><u></u>#include <vtkPLYWriter.h></span></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();<u></u><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->SetSiz
 e(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<vtkVolumeProper
 ty> 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->R
 ender();</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></div>
</div><br/>_______________________________________________<br/>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br/><br/>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br/><br/>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br/><br/>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" target="_blank">http://markmail.org/search/?q=vtkusers</a><br/><br/>
Follow this link to subscribe/unsubscribe:<br/><a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br/><br/></blockquote></div><br/><br clear="all"/><div><br/></div>-- <br/><div class="xfmc3">Unpaid intern in BillsBasement at noware dot com<br/></div>
</div>
</span>
</blockquote>

</span><img src="https://mail.ukr.net/api/public/message_read?a=gqeivMpnKHmsk7uvZLEpXiDsDNMyH8jpU1xKfL_DJhOldEcMnZOb_uZ1hYiWY3C-xWJvr8PR6L20boZ55IwL6ysfWQ==" alt="" width="1" height="1" style="visibility: hidden; width: 1px; height: 1px;"/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       </body></html>