<div dir="ltr"><div>Since your volume has discrete labels generated by the confidence connected filter, I suggest you use vtkDiscreteMarchingCubes instead of vtkContourFilter.<br><br></div>Set the isovalue to your segmentation lable (255).<br>
<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 20, 2013 at 12:31 PM, Zohreh Tavakoli <span dir="ltr"><<a href="mailto:tavakoli.0991@yahoo.com" target="_blank">tavakoli.0991@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:14pt;font-family:times new roman,new york,times,serif"><div>Hi every one</div><div style="font-family:times new roman,new york,times,serif;font-size:14pt">
<div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div><div><div><div style="font-size:14pt;font-family:times new roman,new york,times,serif"><div><br>I want to make 3D mesh of abdomen during insufflation on
ITK,VTK. I tried to make a mesh via marching cubes , but i could not
got the desire one.<br>could you please help me for modification of codes and changing that to be match on my Image???<br>I have attached the codes and image.</div><div style="font-style:normal;font-size:18.66px;background-color:transparent;font-family:times new roman,new york,times,serif">
The image is something like a half of the moon, Imagin Abdomen from side view.<br>Thanks<br>zoya</div><div style="font-style:normal;font-size:18.66px;background-color:transparent;font-family:times new roman,new york,times,serif">
</div><div style="font-style:normal;font-size:18.66px;background-color:transparent;font-family:times new roman,new york,times,serif"> </div><div style="font-style:normal;font-size:18.66px;background-color:transparent;font-family:times new roman,new york,times,serif">
codes:<br></div><div style="font-style:normal;font-size:18.66px;background-color:transparent;font-family:times new roman,new york,times,serif">#include "itkCommand.h"<br>#include "itkImage.h"<br>#include "itkVTKImageExport.h"<br>
#include "itkVTKImageImport.h"<br>#include "itkConfidenceConnectedImageFilter.h"<br>#include "itkCastImageFilter.h"<br>#include "itkRGBPixel.h"<br>#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>#include "itkOrientImageFilter.h"<br><br><var></var>#include "vtkImageImport.h"<br>#include "vtkImageExport.h"<br>#include "vtkRenderer.h"<br>
#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkActor.h"<br>#include "vtkPolyData.h"<br>#include
"vtkPolyDataMapper.h"<br>#include "vtkContourFilter.h"<br>#include "vtkImageData.h"<br>#include "vtkDataSet.h"<br>#include "vtkProperty.h"<br>#include "vtkImagePlaneWidget.h"<br>
#include "vtkCellPicker.h"<br>#include "vtkPolyDataWriter.h"<br>#include <iostream><br><br><br>/**<br> * This function will connect the given itk::VTKImageExport filter to<br> * the given vtkImageImport filter.<br>
*/<br>template <typename ITK_Exporter, typename VTK_Importer><br>void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)<br>{<br> importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());<br>
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());<br> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());<br> importer->SetSpacingCallback(exporter->GetSpacingCallback());<br>
importer->SetOriginCallback(exporter->GetOriginCallback());<br> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());<br> importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());<br>
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());<br> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());<br> importer->SetDataExtentCallback(exporter->GetDataExtentCallback());<br>
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());<br> importer->SetCallbackUserData(exporter->GetCallbackUserData());<br>}<br><br>/**<br> * This function will connect the given vtkImageExport filter to<br>
* the given itk::VTKImageImport filter.<br> */<br>template <typename VTK_Exporter, typename ITK_Importer><br>void ConnectPipelines(VTK_Exporter* exporter,
ITK_Importer importer)<br>{<br> importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());<br> importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());<br> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());<br>
importer->SetSpacingCallback(exporter->GetSpacingCallback());<br> importer->SetOriginCallback(exporter->GetOriginCallback());<br> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());<br>
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());<br> importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());<br> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());<br>
importer->SetDataExtentCallback(exporter->GetDataExtentCallback());<br>
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());<br> importer->SetCallbackUserData(exporter->GetCallbackUserData());<br>}<br><br><br>/**<br> * This program implements an example connection between ITK and VTK<br>
* pipelines. The combined pipeline flows as follows:<br> *<br> * itkImageFileReader ==> itkVTKImageExport ==><br> * vtkImageImport ==> vtkImagePlaneWidget<br> *<br> * The resulting vtkImagePlaneWidget is displayed in a vtkRenderWindow.<br>
* Whenever the VTK pipeline executes, information is propagated<br> * through the ITK pipeline. If the ITK pipeline is out of date, it<br> * will re-execute and cause the VTK pipeline to update properly as<br> * well.<br>
*/<br>int main(int argc, char * argv [] )<br>{ <br><br> // Load a color image using ITK and display it with VTK<br><br> if( argc
< 2 )<br> {<br> std::cerr << "Missing parameters" << std::endl;<br> std::cerr << "Usage: " << argv[0] << " inputImageFilename ";<br> std::cerr << "[seedX seedY seedZ] [output.vtk] [surface=0 wireframe=1]" << std::endl;<br>
return 1;<br> }<br> <br> try<br> {<br> typedef unsigned char PixelType;<br> const unsigned int Dimension = 3;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br> <br> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
<br> ReaderType::Pointer reader = ReaderType::New();<br> reader->SetFileName( argv[1] );<br> <br> reader->Update();<br><br>
typedef itk::ConfidenceConnectedImageFilter<ImageType,ImageType> SegmentationFilterType;<br><br> SegmentationFilterType::Pointer filter = SegmentationFilterType::New();<br><br> filter->SetInput( reader->GetOutput() );<br>
<br> filter->SetNumberOfIterations(200);<br> filter->SetReplaceValue(255);<br> filter->SetMultiplier(5.5);<br><br><br> // Obtain center index of the image<br> // <br> ImageType::Pointer inputImage = reader->GetOutput();<br>
ImageType::SizeType size = inputImage->GetBufferedRegion().GetSize();<br> ImageType::IndexType start = inputImage->GetBufferedRegion().GetIndex();<br><br><br> // set a seed by default in the center of the image.<br>
ImageType::IndexType seed;<br>
seed[0] = start[0 + size[0] / 2;<br> seed[1] = start[1] + size[1] / 2;<br> seed[2] = start[2] + size[2] / 2;<br><br> if( argc > 4 )<br> {<br> seed[0] = atoi( argv[1] );<br> seed[1] = atoi( argv[3] );<br>
seed[2] = atoi( argv[4] );<br> }<br><br> filter->SetSeed( seed );<br> <br> <br> typedef itk::VTKImageExport< ImageType > ExportFilterType;<br> ExportFilterType::Pointer itkExporter1 = ExportFilterType::New();<br>
ExportFilterType::Pointer itkExporter2 = ExportFilterType::New();<br><br> itkExporter1->SetInput( reader->GetOutput() );<br> itkExporter2->SetInput(
filter->GetOutput() );<br><br> // Create the vtkImageImport and connect it to the<br> // itk::VTKImageExport instance.<br> vtkImageImport* vtkImporter1 = vtkImageImport::New(); <br> ConnectPipelines(itkExporter1, vtkImporter1);<br>
<br> vtkImageImport* vtkImporter2 = vtkImageImport::New(); <br> ConnectPipelines(itkExporter2, vtkImporter2);<br> <br><br> vtkImporter1->Update();<br> <br> //------------------------------------------------------------------------<br>
// VTK pipeline.<br> //------------------------------------------------------------------------<br><br> // Create a renderer, render window, and render window interactor to<br> // display the
results.<br> vtkRenderer* renderer = vtkRenderer::New();<br> vtkRenderWindow* renWin = vtkRenderWindow::New();<br> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();<br><br> renWin->SetSize(700, 700);<br>
renWin->AddRenderer(renderer);<br> iren->SetRenderWindow(renWin);<br> <br><br> // use cell picker for interacting with the image orthogonal views.<br> //<br> vtkCellPicker * picker = vtkCellPicker::New();<br>
picker->SetTolerance(0.004);<br><br><br> //assign default props to the ipw's texture plane actor<br> vtkProperty * ipwProp = vtkProperty::New();<br> <br><br> // Create 3 orthogonal view using the ImagePlaneWidget<br>
//<br> vtkImagePlaneWidget * xImagePlaneWidget = vtkImagePlaneWidget::New();<br> vtkImagePlaneWidget * yImagePlaneWidget = vtkImagePlaneWidget::New();<br> vtkImagePlaneWidget * zImagePlaneWidget = vtkImagePlaneWidget::New();<br>
<br> // The 3 image plane widgets are used to probe the dataset.<br> //<br> xImagePlaneWidget->DisplayTextOn();<br> //xImagePlaneWidget->SetInput(vtkImporter1->GetOutput());<br> xImagePlaneWidget->SetInputConnection(vtkImporter1->GetOutputPort()) ;<br>
xImagePlaneWidget->SetPlaneOrientationToXAxes();<br> xImagePlaneWidget->SetSliceIndex(size[0]/2);<br> xImagePlaneWidget->SetPicker(picker);<br> xImagePlaneWidget->RestrictPlaneToVolumeOn();<br>
xImagePlaneWidget->SetKeyPressActivationValue('x');<br> xImagePlaneWidget->GetPlaneProperty()->SetColor(1, 0, 0);<br> xImagePlaneWidget->SetTexturePlaneProperty(ipwProp);<br> xImagePlaneWidget->SetResliceInterpolateToNearestNeighbour();<br>
<br> yImagePlaneWidget->DisplayTextOn();<br> // yImagePlaneWidget->SetInput(vtkImporter1->GetOutput());<br> yImagePlaneWidget->SetInputConnection(vtkImporter1->GetOutputPort());<br> yImagePlaneWidget->SetPlaneOrientationToYAxes();<br>
yImagePlaneWidget->SetSliceIndex(size[1]/2);<br> yImagePlaneWidget->SetPicker(picker);<br> yImagePlaneWidget->RestrictPlaneToVolumeOn();<br> yImagePlaneWidget->SetKeyPressActivationValue('y');<br>
yImagePlaneWidget->GetPlaneProperty()->SetColor(1, 1, 0);<br> yImagePlaneWidget->SetTexturePlaneProperty(ipwProp);<br> yImagePlaneWidget->SetLookupTable(xImagePlaneWidget->GetLookupTable());<br><br>
zImagePlaneWidget->DisplayTextOn();<br> //zImagePlaneWidget->SetInput(vtkImporter1->GetOutput());<br> zImagePlaneWidget->SetInputConnection(vtkImporter1->GetOutputPort());<br> zImagePlaneWidget->SetPlaneOrientationToZAxes();<br>
zImagePlaneWidget->SetSliceIndex(size[2]/2);<br> zImagePlaneWidget->SetPicker(picker);<br> zImagePlaneWidget->SetKeyPressActivationValue('z');<br> zImagePlaneWidget->GetPlaneProperty()->SetColor(0, 0, 1);<br>
zImagePlaneWidget->SetTexturePlaneProperty(ipwProp);<br>
zImagePlaneWidget->SetLookupTable(xImagePlaneWidget->GetLookupTable());<br><br> xImagePlaneWidget->SetInteractor( iren );<br> xImagePlaneWidget->On();<br> <br> yImagePlaneWidget->SetInteractor( iren );<br>
yImagePlaneWidget->On();<br> <br> zImagePlaneWidget->SetInteractor( iren );<br> zImagePlaneWidget->On();<br><br><br> // Set the background to something grayish<br> renderer->SetBackground(0.4392, 0.5020, 0.5647);<br>
<br><br> // Draw contours around the segmented regions<br> vtkContourFilter * contour = vtkContourFilter::New();<br> contour->SetInputConnection( vtkImporter2->GetOutputPort() );<br> contour->SetValue(0, 128); // edges of a binary image with
values 0,255<br><br><br> vtkPolyDataMapper * polyMapper = vtkPolyDataMapper::New();<br> vtkActor * polyActor = vtkActor::New();<br><br> polyActor->SetMapper( polyMapper );<br> polyMapper->SetInputConnection( contour->GetOutputPort() );<br>
polyMapper->ScalarVisibilityOff();<br><br> vtkProperty * property = vtkProperty::New();<br> property->SetAmbient(0.1);<br> property->SetDiffuse(0.1);<br> property->SetSpecular(0.5);<br> property->SetColor(1.0,0.0,0.0);<br>
property->SetLineWidth(2.0);<br> property->SetRepresentationToSurface();<br><br> polyActor->SetProperty( property );<br> <br> renderer->AddActor(
polyActor );<br> <br> if( argc > 5 )<br> {<br> vtkPolyDataWriter * writer = vtkPolyDataWriter::New();<br> writer->SetFileName(argv[5]);<br> writer->SetInputConnection( contour->GetOutputPort() );<br>
writer->Write();<br> }<br> <br> if( argc > 6 )<br> {<br> int representation = atoi( argv[6] );<br> switch(representation)<br> {<br> case 0:<br> property->SetRepresentationToSurface();<br>
break;<br> case 1:<br> property->SetRepresentationToWireframe();<br> break;<br> }<br> }<br><br> // Bring up the render window and begin interaction.<br> renderer->ResetCamera();<br>
renWin->Render();<br> iren->Start();<br><br> // Release all VTK components<br> polyActor->Delete();<br> picker->Delete();<br> ipwProp->Delete();<br> vtkImporter1->Delete();<br> vtkImporter2->Delete();<br>
xImagePlaneWidget->Delete();<br> yImagePlaneWidget->Delete();<br>
zImagePlaneWidget->Delete();<br> contour->Delete();<br> property->Delete();<br> polyMapper->Delete();<br> renWin->Delete();<br> renderer->Delete();<br> iren->Delete();<br><br><br> }<br>
catch( itk::ExceptionObject & e )<br> {<br> std::cerr << "Exception catched !! " << e << std::endl;<br> }<br><br><br> <br> return 0;<br>}</div></div></div></div><br><br></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<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Unpaid intern in BillsBasement at noware dot com<br>
</div>