This looks like my misunderstanding of <div>the vtkPolyData GetPoints function. It </div><div>apparently returns physical coordinates, </div><div>not indices. When I convert the physical</div><div>coordinates to the image indices, I get the </div>
<div>result I was expecting. </div><div><br></div><div>Thank you,</div><div>Cagatay</div><div><br><div class="gmail_quote">On Mon, May 7, 2012 at 1:54 PM, Cagatay Bilgin <span dir="ltr"><<a href="mailto:bilgincc@gmail.com" target="_blank">bilgincc@gmail.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>Hi Bill, </div><div><br></div><div>#include "itkImageToVTKImageFilter.h"</div><div>#include "itkVTKImageToImageFilter.h"</div>
<div><br></div><div>#include <vtkDiscreteMarchingCubes.h></div>
<div>#include <vtkSmartPointer.h></div><div><br></div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImageFileReader.h"</div><div><br></div><div><br></div><div>#include "vtkPolyDataMapper.h"</div>
<div>#include "vtkActor.h"</div><div>#include "vtkRenderer.h"</div><div>#include "vtkRenderWindow.h"</div><div>#include "vtkRenderWindowInteractor.h"</div><div><br></div><div>int main(int argc, char*argv[]){</div>
<div><br></div><div> if(argc!=2){</div><div> std::cout << argv[0] << " inputFileName.mhd" << std::endl;</div><div> return -1;</div><div> }</div><div><br></div><div> typedef itk::Image<unsigned int,3> ImageType;</div>
<div> typedef itk::ImageFileReader<ImageType> ReaderType; </div><div> ReaderType::Pointer reader = ReaderType::New();</div><div> reader->SetFileName(argv[1]);</div><div> reader->Update();</div><div> ImageType::Pointer input = reader->GetOutput();</div>
<div><br></div><div> typedef itk::ImageToVTKImageFilter<ImageType> ITK2VTKType;</div><div> ITK2VTKType::Pointer itk2vtk = ITK2VTKType::New();</div><div> itk2vtk->SetInput(input);</div><div> itk2vtk->Update();</div>
<div><br></div><div> //extent and origin seems correct</div><div> double* origin = itk2vtk->GetOutput()->GetOrigin();</div><div> int* extent = itk2vtk->GetOutput()->GetExtent(); </div><div> std::cout << input->GetLargestPossibleRegion().GetIndex() << std::endl;</div>
<div> std::cout << extent[0] << " " << extent[1] << " " </div><div> << extent[2] << " " << extent[3] << " "</div><div> << extent[4] << " " << extent[5] << std::endl;</div>
<div> </div><div> vtkSmartPointer<vtkDiscreteMarchingCubes> discreteCubes =</div><div> vtkSmartPointer<vtkDiscreteMarchingCubes>::New();</div><div> discreteCubes->SetInput(itk2vtk->GetOutput());</div>
<div> discreteCubes->GenerateValues(1, 1, 1); //TODO Fixed numbers</div><div> discreteCubes->Update();</div><div><br></div><div> //The object starts around the 10th slice, there is a problem here.</div><div> vtkSmartPointer<vtkPolyData> cubes = discreteCubes->GetOutput();</div>
<div> for(unsigned int i = 0; i < cubes->GetNumberOfPoints(); i++)</div><div> {</div><div> double p[3];</div><div> cubes->GetPoint(i, p);</div><div> std::cout << p[0] << " " << p[1] << " " << p[2] << std::endl;</div>
<div> }</div><div><br></div><div><br></div><div> // Create a mapper and actor</div><div> vtkSmartPointer<vtkPolyDataMapper> surfaceMapper = </div><div> vtkSmartPointer<vtkPolyDataMapper>::New();</div><div>
surfaceMapper->SetInputConnection(discreteCubes->GetOutputPort());</div><div> vtkSmartPointer<vtkActor> surfaceActor = vtkSmartPointer<vtkActor>::New();</div><div> surfaceActor->SetMapper(surfaceMapper);</div>
<div><br></div><div> // Create a renderer, render window, and interactor</div><div> vtkSmartPointer<vtkRenderer> renderer = </div><div> vtkSmartPointer<vtkRenderer>::New();</div><div> vtkSmartPointer<vtkRenderWindow> renderWindow = </div>
<div> vtkSmartPointer<vtkRenderWindow>::New();</div><div> renderWindow->AddRenderer(renderer);</div><div> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = </div><div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div>
<div> renderWindowInteractor->SetRenderWindow(renderWindow);</div><div> </div><div> // Add the actor to the scene</div><div> renderer->AddActor(surfaceActor);</div><div> renderer->SetBackground(.1, .2, .3); // Background color blue</div>
<div> renderWindow->Render();</div><div> renderWindowInteractor->Start();</div><div><br></div><div>}</div></div><div><br></div><div>I have also uploaded the data I am using here:</div><div><a href="http://vision.lbl.gov/People/bilgin/input.tar.gz" target="_blank">http://vision.lbl.gov/People/bilgin/input.tar.gz</a></div>
<div><br></div><div>All I am trying to do is obtain the indices of points on the </div><div>surface. </div><div><br></div><div>Thank you, </div><span><font color="#888888">Cagatay</font></span><div>
<div><div><br><div class="gmail_quote">On Mon, May 7, 2012 at 12:46 PM, Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Please post a small compilable example that illustrates the problem.<br>
<div><div><br>
On Mon, May 7, 2012 at 2:18 PM, Cagatay Bilgin <<a href="mailto:bilgincc@gmail.com" target="_blank">bilgincc@gmail.com</a>> wrote:<br>
> Hello vtk-users<br>
><br>
> I am having problems understanding the<br>
> output of vtkDiscreteMarchingCubes.<br>
><br>
> when I print the output polydata points, they<br>
> do not match the input positions. It looks like<br>
> the filter is doing a bounding box for the<br>
> object. The extent and the origin seems<br>
> to change. My sphere is located around 100,100,100<br>
> with a radius of 10 in the input image, after the<br>
> marching cubes it is around 10,10,10 with a<br>
> radius of 10. How can make the filter give me<br>
> the correct indices ?<br>
><br>
> Thanks,<br>
> Cagatay<br>
><br>
</div></div>> _______________________________________________<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>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
<span><font color="#888888"><br>
<br>
<br>
--<br>
Unpaid intern in BillsBasement at noware dot com<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>