[Insight-users] Problem with conversion dicom -> .vtk file
agata
agatakrason at gmail.com
Fri Feb 18 14:52:34 EST 2011
Hello All ITK-Users ;)
I 'm writing my first program with ITK ..
I'm fresh user of ITK . I ' m beging my adventure with itk . ..
I need to convert dcm series to .vtk file (as surface vtkPolyData)
I wrote code , it compiles good but when I open a file I receive wrog data
. I think that it's a problem with mesh ? could You look at my code please
???
--------------------------------------------------------
# vtk DataFile Version 2.0
File written by itkVTKPolyDataWriter
ASCII
DATASET POLYDATA
POINTS 0 float
---------------------------------------------------------
If it 's possible Could You help me please ?
#include <iostream>
#include <cstdlib>
#include "itkImage.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkMesh.h"
#include "itkImage.h"
#include "itkCovariantVector.h"
#include "itkImageFileReader.h"
#include "itkVTKImageIO.h"
#include "itkBinaryMask3DMeshSource.h"
#include "itkVTKPolyDataWriter.h"
#include <vector>
#include <itksys/SystemTools.hxx>
int main()
{
typedef signed short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image<PixelType, Dimension> ImageType;
typedef itk::ImageSeriesReader<ImageType> ReaderType;
typedef itk::GDCMImageIO ImageIOType;
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
ImageIOType::Pointer gdcmIO = ImageIOType::New();
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
std::string folderWE;
std::cout<<" path to directory : "<<std::endl;
std::cin>>folderWE;
namesGenerator->SetInputDirectory(folderWE);
const ReaderType::FileNamesContainer &filenames =
namesGenerator->GetInputFileNames();
unsigned int numberOfFilenames = filenames.size();
std::cout<<numberOfFilenames <<std::endl;
for(unsigned int fni = 0; fni < numberOfFilenames; fni++)
{
std::cout<<"filename # "<<fni << " = ";
std::cout<<filenames[fni] <<std::endl;
}
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(gdcmIO);
reader->SetFileNames(filenames);
// read dicom series
try
{
reader->Update();
}
catch(itk::ExceptionObject &excp)
{
std::cerr<<" Exception .."<<std::endl;
std::cerr<<excp<<std::endl;
}
// create mesh ..
/// I don't know here ????
typedef float MeshPixelType;
typedef itk::Mesh<MeshPixelType,Dimension> MeshType;
typedef itk::BinaryMask3DMeshSource<ImageType, MeshType> MeshSourceType; //
???
MeshSourceType::Pointer meshSource = MeshSourceType::New();
const PixelType objectValue = static_cast<PixelType>(1250);
meshSource->SetObjectValue(objectValue);
meshSource->SetInput(reader->GetOutput());
// write *.vtk
meshSource->Update();
MeshType::Pointer mesh = meshSource->GetOutput();
typedef itk::VTKPolyDataWriter<MeshType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(mesh);
std::string fileVTK;
std::cout<<"save as *.vtk: "<<std::endl;
std::cin>>fileVTK;
writer->SetFileName(fileVTK);
//writer->SetInput(reader->GetOutput());
try
{
writer->Update();
}
catch(itk::ExceptionObject &excp)
{
std::cerr<<"Exception Object !"<<std::endl;
std::cerr<<excp<<std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
I would appreciate for any help .
Best,
Agata
--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Problem-with-conversion-dicom-vtk-file-tp6041275p6041275.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list