[vtkusers] vtkVolume vtkActor
andon
antoniod987 at gmail.com
Wed Jun 27 04:43:08 EDT 2012
Hi,
sorry for the late. Ok if you have the itk compiled on your pc you could try
to compile something like this:
#include "itkVersion.h"
#include "itkImage.h"
#include "itkMinimumMaximumImageFilter.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkNumericSeriesFileNames.h"
#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"
#include "itkResampleImageFilter.h"
#include "itkShiftScaleImageFilter.h"
#include "itkIdentityTransform.h"
#include "itkLinearInterpolateImageFunction.h"
#include <itksys/SystemTools.hxx>
#include "itkNeighborhoodConnectedImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "itkImageFileReader.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkImageToVTKImageFilter.h"
#include <vtkSmartPointer.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVolumeProperty.h>
#include <vtkMatrix4x4.h>
#include <vtkAxesActor.h>
#include <vtkDICOMImageReader.h>
#include <vtkImageData.h>
#include <vtkImageDataGeometryFilter.h>
int main( int argc, char* argv[] ){
const unsigned int InputDimension = 3;
const unsigned int OutputDimension = 3;
typedef signed short PixelType;
typedef itk::Image< PixelType, InputDimension >
InputImageType;
typedef itk::Image< PixelType, 2 >
InputImageType2;
typedef itk::Image< PixelType, OutputDimension >
OutputImageType;
typedef itk::ImageSeriesReader< InputImageType >
ReaderType;
typedef itk::ImageFileReader< InputImageType2 >
ReaderType2;
typedef itk::GDCMImageIO
ImageIOType;
typedef itk::GDCMSeriesFileNames
InputNamesGeneratorType;
////////////////////////////////////////////////
// 1) Read the input series
ImageIOType::Pointer gdcmIO = ImageIOType::New();
InputNamesGeneratorType::Pointer inputNames =
InputNamesGeneratorType::New();
inputNames->SetInputDirectory("../data/input");
std::cout<<"Stiamo leggendo"<<std::endl;
const ReaderType::FileNamesContainer & filenames =
inputNames->GetInputFileNames();
ReaderType::Pointer reader = ReaderType::New();
//ReaderType2::Pointer reader2 = ReaderType2::New();
reader->SetImageIO( gdcmIO );
reader->SetFileNames( filenames );
typedef itk::BinaryThresholdImageFilter <InputImageType, InputImageType>
BinaryThresholdImageFilterType;
/*
BinaryThresholdImageFilterType::Pointer thresholdFilter
= BinaryThresholdImageFilterType::New();
thresholdFilter->SetInput(reader->GetOutput());
thresholdFilter->SetLowerThreshold(-1000);
thresholdFilter->SetUpperThreshold(-600);
thresholdFilter->SetInsideValue(255);
thresholdFilter->SetOutsideValue(0);
*/
try
{
reader->Update();
}
catch (itk::ExceptionObject &excp)
{
std::cerr << "Exception thrown while reading the series" << std::endl;
std::cerr << excp << std::endl;
//return EXIT_FAILURE;
}
std::cout<<"Letto!!!"<<std::endl;
std::cout<<"Renderizzo"<<std::endl;
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
ren1->SetBackground(0.5f,0.5f,1.0f);
renWin->AddRenderer(ren1);
renWin->SetSize(1280,1024);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
renWin->Render(); // make sure we have an OpenGL context.*/
typedef itk::ImageToVTKImageFilter<OutputImageType> itkVtkConverter;
itkVtkConverter::Pointer conv=itkVtkConverter::New();
conv->SetInput(reader->GetOutput());
vtkSmartPointer<vtkGPUVolumeRayCastMapper> volumeMapper =
vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
volumeMapper->SetInput(conv->GetOutput());
//vtkImageData* imData = conv->GetOutput();
vtkSmartPointer<vtkVolumeProperty> volumeProperty =
vtkSmartPointer<vtkVolumeProperty>::New();
vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =
vtkSmartPointer<vtkPiecewiseFunction>::New();
compositeOpacity->AddPoint(0.0,0.0);
compositeOpacity->AddPoint(80.0,1.0);
compositeOpacity->AddPoint(80.1,0.0);
compositeOpacity->AddPoint(255.0,0.0);
volumeProperty->SetScalarOpacity(compositeOpacity);
vtkSmartPointer<vtkColorTransferFunction> color =
vtkSmartPointer<vtkColorTransferFunction>::New();
color->AddRGBPoint(0.0 ,0.0,0.0,0.0);
color->AddRGBPoint(40.0 ,0.5,0.5,0.5);
color->AddRGBPoint(255.0,1.0,1.0,1.0);
volumeProperty->SetColor(color);
vtkSmartPointer<vtkVolume> volume =
vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
//Here we take care of position and orientation
//so that volume is in DICOM patient physical space
OutputImageType::DirectionType d=reader->GetOutput()->GetDirection();
vtkMatrix4x4 *mat=vtkMatrix4x4::New(); //start with identity matrix
for (int i=0; i<3; i++)
for (int k=0; k<3; k++)
mat->SetElement(i,k, d(i,k));
//counteract the built-in translation by origin
OutputImageType::PointType origin= reader->GetOutput()->GetOrigin();
volume->SetPosition(-origin[0], -origin[1], -origin[2]);
// volume->SetPosition(0,0,0);
//add translation to the user matrix
for (int i=0; i<3; i++)
mat->SetElement(i,3, origin[i]);
volume->SetUserMatrix(mat);
vtkImageData* imageData = conv->GetOutput();
vtkSmartPointer<vtkImageDataGeometryFilter> filter =
vtkSmartPointer<vtkImageDataGeometryFilter>::New();
filter->SetInput(imageData);
vtkSmartPointer<vtkPolyDataMapper> polyDataMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
polyDataMapper->SetInputConnection(filter->GetOutputPort());
vtkSmartPointer<vtkActor> polyActor = vtkSmartPointer<vtkActor>::New();
polyActor->SetMapper(polyDataMapper);
ren1->AddActor(polyActor);
ren1->ResetCamera();
renWin->Render();
iren->Start();
}
I have nothing on the screen....Off course i don't need to visualize the
actor (it's possible simply using AddVolume() ), but i need the actor for
others reasons......could you help me? as input you could use a dicom
directory with some dcm files...you could download something from the web,
maybe like this one here:
http://www.microdicom.com/component/docman/doc_download/3-bu001015-v01.html
P.S. maybe some includes are unusefull
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkVolume-vtkActor-tp5714227p5714261.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list