[vtkusers] vtkmarchingcube

medamine miladimedamine at yahoo.fr
Sun Apr 8 15:27:54 EDT 2007


Hi;
I m using vtkmarchingcube to do the 3D isosurface reconstruction  from a
series slices segmented images.
but some methode as setvalue is not clear to me.
i  would like to give you my code bellow and i want that let me your
comments because i have some problem in excuting him.
Olso i need to knew how to get multi surface and what the way to separate
them.
thanks.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// marchingcube.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkProperty.h" 
#include <vtkGenericCell.h>
#include <vtkMarchingCubes.h>
#include <vtkVolume16Reader.h>
#include "vtkCell.h"
#include "vtkPLYReader.h"
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>

int main(int argc, char** argv)
{


//first convert series slices of image into volume data
  
    vtkVolume16Reader *m_reader=vtkVolume16Reader::New();
    m_reader->SetDataDimensions(64,64);
    m_reader->SetImageRange(1,93);
    m_reader->SetDataByteOrderToLittleEndian();
    m_reader->SetFilePrefix("C:\\test\\EffortEndocarde");//exemple of file
"C:\\test\\EffortEndocarde10"
    m_reader->SetDataSpacing (3.2, 3.2, 1.5);
    m_reader->Update();

//second execute the vtkmarching cube

    vtkMarchingCubes *m_cube=vtkMarchingCubes::New();
    vtkPolyData  *m_polydata=vtkPolyData::New();//define an object frm the
filter
    m_cube->SetValue(0,500); // set value corresponding  to which the
isosurface will be created
    m_cube->ComputeNormalsOff(); // turn Normals Creation off (u can do it
later...and only if u  have light settings)
    m_cube->ComputeGradientsOff(); // gradients off
    m_cube->SetInput(m_reader->GetOutput()); // set input for the volume
from which u'll extract iso surface
    m_polydata= m_cube->GetOutput(); // get o/p (it's of polydata type)
    m_polydata->Update();

    vtkPolyDataMapper *m_polydataMapper = vtkPolyDataMapper::New();
    m_polydataMapper->SetInput(m_polydata);
    m_polydataMapper->SetScalarRange(0,7);
    m_polydataMapper->Update();

   vtkActor *m_Actor = vtkActor::New();
   m_Actor->SetMapper(m_polydataMapper);

   vtkRenderer *m_renderer = vtkRenderer::New();
   vtkRenderWindow *m_renWin = vtkRenderWindow::New();
   m_renWin->AddRenderer(m_renderer);

   vtkRenderWindowInteractor *m_iren = vtkRenderWindowInteractor::New();
   m_iren->SetRenderWindow(m_renWin);

   vtkInteractorStyleTrackballCamera *m_style =
vtkInteractorStyleTrackballCamera::New();
   m_iren->SetInteractorStyle(m_style);

   m_renderer->AddActor(m_Actor);
   m_renderer->SetBackground(0.1, 0.2, 0.4);
  
   m_renWin->SetSize(300,300);
   m_renWin->Render();
   m_iren->Start();

   m_cube->Delete();
   m_polydata->Delete();
   m_polydataMapper->Delete();
   m_Actor->Delete();
   m_renderer->Delete();
   m_renWin->Delete();
   m_iren->Delete();

    return 0;
}

-- 
View this message in context: http://www.nabble.com/vtkmarchingcube-tf3544529.html#a9894928
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list