[vtkusers] Integrate VTK in Matlab
32sthide
32sthide at gmail.com
Mon Aug 13 06:28:36 EDT 2012
hi all,
I've created a cxx file with my code. It is a imageplanewidget essentialy,
which has a bmpreader that reads some bmp slices from a ct.
I would like to call my code from matlab so i can see the slices there in
the plane.
I've visited http://www.vtk.org/Wiki/VTK/VTKMatlab and tried to understand
how to do it, but i couldn't figure it out.
Can anyone help me?
I'll post here my code:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkBMPReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkImageData.h"
#include "vtkOutlineFilter.h"
#include "vtkPolyDataReader.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkImagePlaneWidget.h"
#include "vtkCellPicker.h"
#include "vtkCubeAxesActor2D.h"
#include "vtkPolyDataNormals.h"
int main()
{
// Using vtkBMPReader to read all the 128 bmp slices
vtkBMPReader *bmp= vtkBMPReader::New();
bmp->SetDataByteOrderToLittleEndian();
bmp->SetFilePrefix ("/home/matt/Desktop/ouBMP/exemplo");
bmp->SetFilePattern("%s%d.bmp");
bmp->SetFileNameSliceSpacing(1);
bmp->SetNumberOfScalarComponents(3);
bmp->SetDataOrigin(0,0,0);
bmp->SetDataSpacing(0.011741683,0.005865103,0.047244094);
bmp->SetDataExtent(0,511,0,1023,1,128);
bmp->Update();
// An outline
vtkOutlineFilter *outline= vtkOutlineFilter::New();
outline->SetInputConnection(bmp->GetOutputPort());
vtkPolyDataMapper *outlineMapper= vtkPolyDataMapper::New();
outlineMapper->SetInput(outline->GetOutput());
vtkActor *outlineActor= vtkActor::New();
outlineActor->SetMapper(outlineMapper);
outlineActor->GetProperty()->SetColor(1,1,1);
// Create renderer
vtkRenderer *ren= vtkRenderer::New();
ren->AddActor(outlineActor);
ren->SetBackground(0,0,0);
// Create a window for the renderer
vtkRenderWindow *renWin= vtkRenderWindow::New();
renWin->AddRenderer(ren);
renWin->SetSize(500, 500);
// Set an user interface interactor for the render window
vtkRenderWindowInteractor *iren= vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
// ImagePlanes picker
vtkCellPicker *picker= vtkCellPicker::New();
picker->SetTolerance(0.05);
// Create a Xplane
vtkImagePlaneWidget *planeX= vtkImagePlaneWidget::New();
planeX->SetInteractor(iren);
planeX->SetPicker(picker);
planeX->RestrictPlaneToVolumeOn();
planeX->GetPlaneProperty()->SetColor(1, 0, 0);
planeX->SetInput(bmp->GetOutput());
planeX->SetPlaneOrientationToXAxes();
planeX->SetSliceIndex(256);
planeX->DisplayTextOn();
planeX->On();
//Create a Yplane
vtkImagePlaneWidget *planeY= vtkImagePlaneWidget::New();
planeY->SetInteractor(iren);
planeY->SetPicker(picker);
planeY->RestrictPlaneToVolumeOn();
planeY->GetPlaneProperty()->SetColor(0, 1, 0);
planeY->SetInput(bmp->GetOutput());
planeY->SetPlaneOrientationToYAxes();
planeY->SetSliceIndex(512);
planeY->DisplayTextOn();
planeY->SetLookupTable(planeX->GetLookupTable());
planeY->On();
//Create a Zplane
vtkImagePlaneWidget *planeZ= vtkImagePlaneWidget::New();
planeZ->SetInteractor(iren);
planeZ->SetPicker(picker);
planeZ->RestrictPlaneToVolumeOn();
planeZ->GetPlaneProperty()->SetColor(0, 0, 1);
planeZ->SetInput(bmp->GetOutput());
planeZ->SetPlaneOrientationToZAxes();
planeZ->SetSliceIndex(64);
planeZ->DisplayTextOn();
planeZ->SetLookupTable(planeX->GetLookupTable());
planeZ->On();
// Drawing some X,Y,Z axes
/*vtkCubeAxesActor2D *axes= vtkCubeAxesActor2D::New();
axes->SetViewProp(outlineActor);
axes->SetCamera(ren->GetActiveCamera());
axes->GetScaling();
axes->GetFlyMode();
axes->SetBounds(1.0,2.0,1.0,2.0,1.0,2.0);
axes->SetCornerOffset(0.0);
axes->UseRangesOn();
axes->SetRanges(0.0,6.0,0.0,2.0,0.0,6.0);
axes->SetLabelFormat("%6.4g");
axes->SetNumberOfLabels(12);
axes->SetFontFactor(1);
ren->AddViewProp(axes);*/
// Start the initialization and rendering
iren->Initialize();
renWin->Render();
iren->Start();
// Delete objects
picker->Delete();
planeX->Delete();
planeY->Delete();
planeZ->Delete();
//axes->Delete();
style->Delete();
bmp->Delete();
outline->Delete();
outlineMapper->Delete();
outlineActor->Delete();
ren->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/Integrate-VTK-in-Matlab-tp5715217.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list