[vtkusers] vtkDiscreteMarchingCubes extend
Cagatay Bilgin
bilgincc at gmail.com
Mon May 7 16:54:09 EDT 2012
Hi Bill,
#include "itkImageToVTKImageFilter.h"
#include "itkVTKImageToImageFilter.h"
#include <vtkDiscreteMarchingCubes.h>
#include <vtkSmartPointer.h>
#include "itkImageFileWriter.h"
#include "itkImageFileReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
int main(int argc, char*argv[]){
if(argc!=2){
std::cout << argv[0] << " inputFileName.mhd" << std::endl;
return -1;
}
typedef itk::Image<unsigned int,3> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
ImageType::Pointer input = reader->GetOutput();
typedef itk::ImageToVTKImageFilter<ImageType> ITK2VTKType;
ITK2VTKType::Pointer itk2vtk = ITK2VTKType::New();
itk2vtk->SetInput(input);
itk2vtk->Update();
//extent and origin seems correct
double* origin = itk2vtk->GetOutput()->GetOrigin();
int* extent = itk2vtk->GetOutput()->GetExtent();
std::cout << input->GetLargestPossibleRegion().GetIndex() << std::endl;
std::cout << extent[0] << " " << extent[1] << " "
<< extent[2] << " " << extent[3] << " "
<< extent[4] << " " << extent[5] << std::endl;
vtkSmartPointer<vtkDiscreteMarchingCubes> discreteCubes =
vtkSmartPointer<vtkDiscreteMarchingCubes>::New();
discreteCubes->SetInput(itk2vtk->GetOutput());
discreteCubes->GenerateValues(1, 1, 1); //TODO Fixed numbers
discreteCubes->Update();
//The object starts around the 10th slice, there is a problem here.
vtkSmartPointer<vtkPolyData> cubes = discreteCubes->GetOutput();
for(unsigned int i = 0; i < cubes->GetNumberOfPoints(); i++)
{
double p[3];
cubes->GetPoint(i, p);
std::cout << p[0] << " " << p[1] << " " << p[2] << std::endl;
}
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> surfaceMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
surfaceMapper->SetInputConnection(discreteCubes->GetOutputPort());
vtkSmartPointer<vtkActor> surfaceActor = vtkSmartPointer<vtkActor>::New();
surfaceActor->SetMapper(surfaceMapper);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actor to the scene
renderer->AddActor(surfaceActor);
renderer->SetBackground(.1, .2, .3); // Background color blue
renderWindow->Render();
renderWindowInteractor->Start();
}
I have also uploaded the data I am using here:
http://vision.lbl.gov/People/bilgin/input.tar.gz
All I am trying to do is obtain the indices of points on the
surface.
Thank you,
Cagatay
On Mon, May 7, 2012 at 12:46 PM, Bill Lorensen <bill.lorensen at gmail.com>wrote:
> Please post a small compilable example that illustrates the problem.
>
> On Mon, May 7, 2012 at 2:18 PM, Cagatay Bilgin <bilgincc at gmail.com> wrote:
> > Hello vtk-users
> >
> > I am having problems understanding the
> > output of vtkDiscreteMarchingCubes.
> >
> > when I print the output polydata points, they
> > do not match the input positions. It looks like
> > the filter is doing a bounding box for the
> > object. The extent and the origin seems
> > to change. My sphere is located around 100,100,100
> > with a radius of 10 in the input image, after the
> > marching cubes it is around 10,10,10 with a
> > radius of 10. How can make the filter give me
> > the correct indices ?
> >
> > Thanks,
> > Cagatay
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120507/0de0faf8/attachment.htm>
More information about the vtkusers
mailing list