int main(int argc, char *argv[])
{
using InternalPixelType = float;
constexpr unsigned int Dimension = 3;
using InternalImageType = itk::Image<InternalPixelType, Dimension>;
using OutputPixelType = float;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;
using CastingFilterType =
itk::CastImageFilter<InternalImageType, OutputImageType>;
CastingFilterType::Pointer caster = CastingFilterType::New(a);using ReaderType = itk::ImageSeriesReader<InternalImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;
using ImageIOType = itk::GDCMImageIO;
using NamesGeneratorType = itk::GDCMSeriesFileNames;
ReaderType::Pointer reader = ReaderType::New(a); WriterType::Pointer writer = WriterType::New(a); ImageIOType::Pointer dicomIO = ImageIOType::New(a); reader->SetImageIO(dicomIO);
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New(a); nameGenerator->SetUseSeriesDetails(true);
nameGenerator->SetDirectory("D:\\software\\30dicom\\222\\14");
writer->SetFileName("D:\\software\\30dicom\\cttt.mha");
using SeriesIdContainer = std::vector<std::string>;
const SeriesIdContainer &seriesUID = nameGenerator->GetSeriesUIDs(a);auto seriesItr = seriesUID.begin(a);auto seriesEnd = seriesUID.end(a);using FileNamesContainer = std::vector<std::string>;
FileNamesContainer fileNames;
std::string seriesIdentifier;
while(seriesItr ! = seriesEnd) { seriesIdentifier = seriesItr->c_str(a); fileNames = nameGenerator->GetFileNames(seriesIdentifier);
++seriesItr;
}
reader->SetFileNames(fileNames);
try
{
reader->Update(a); }catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
InternalImageType::SizeType imgSize = reader->GetOutput() - >GetLargestPossibleRegion().GetSize(a); cout <<"Read the done! Original size: " << imgSize << endl;
// Area growth segmentation ///
using CurvatureFlowImageFilterType =
itk::CurvatureFlowImageFilter<InternalImageType, InternalImageType>;
CurvatureFlowImageFilterType::Pointer smoothing =
CurvatureFlowImageFilterType::New(a);using ConnectedFilterType =
itk::ConnectedThresholdImageFilter<InternalImageType, InternalImageType>;
ConnectedFilterType::Pointer connectedThreshold =
ConnectedFilterType::New(a);//smoothing->SetInput(reader->GetOutput());
// smoothing->SetNumberOfIterations(5);
/ / smoothing - > SetTimeStep (0.125);
connectedThreshold->SetInput(reader->GetOutput());
const InternalPixelType lowerThreshold = std::stod("3600");
const InternalPixelType upperThreshold = std::stod("4000");
connectedThreshold->SetLower(lowerThreshold);
connectedThreshold->SetUpper(upperThreshold);
connectedThreshold->SetReplaceValue(255);
InternalImageType::IndexType index1;
index1[0] = std::stoi("295");
index1[1] = std::stoi("98");
index1[2] = std::stoi("159");
connectedThreshold->AddSeed(index1);
// InternalImageType::IndexType index2;
// index2[0] = std::stoi("149");
// index2[1] = std::stoi("172");
// index2[2] = std::stoi("159");
// connectedThreshold->AddSeed(index2);
connectedThreshold->Update(a);//caster->SetInput(connectedThreshold->GetOutput());
// writer->SetInput(connectedThreshold->GetOutput());
// try
/ / {
// writer->Update();
// }
// catch (const itk::ExceptionObject &excep)
/ / {
// std::cerr << "Exception caught !" << std::endl;
// //std::cerr << excep << std::endl;
// }
cout << "Saved." << imgSize << endl;
/
//itk to vtk
typedef itk::ImageToVTKImageFilter<InternalImageType> itkTovtkFilterType;
itkTovtkFilterType::Pointer itkTovtkImageFilter = itkTovtkFilterType::New(a); itkTovtkImageFilter->SetInput(connectedThreshold->GetOutput());
itkTovtkImageFilter->Update(a); vtkSmartPointer<vtkGPUVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New(a); volumeMapper->SetInputData(itkTovtkImageFilter->GetOutput());
volumeMapper->SetSampleDistance(volumeMapper->GetSampleDistance(a) /2); // Set the ray sampling distance
vtkSmartPointer<vtkVolumeProperty> volumeProperty =
vtkSmartPointer<vtkVolumeProperty>::New(a); volumeProperty->SetInterpolationTypeToLinear(a); volumeProperty->ShadeOn(a);// Turn the shadow test on or off
volumeProperty->SetAmbient(0.1);
volumeProperty->SetDiffuse(0.9); / / diffuse
volumeProperty->SetSpecular(0.2); // Mirror reflection
volumeProperty->SetSpecularPower(10.0);
// Set the opacity
vtkSmartPointer<vtkPiecewiseFunction> opacityFun =
vtkSmartPointer<vtkPiecewiseFunction>::New(a); opacityFun->AddPoint(- 3024..0);
opacityFun->AddPoint(129.54.0);
opacityFun->AddPoint(145.24.0.17);
opacityFun->AddPoint(169.92.0.63);
opacityFun->AddPoint(395.58.0.81);
opacityFun->AddPoint(1578.73.0.81);
opacityFun->AddPoint(3071.0.81);
volumeProperty->SetScalarOpacity(opacityFun); // Set the opacity transfer function
// Set the color properties
vtkSmartPointer<vtkColorTransferFunction> colorFun =
vtkSmartPointer<vtkColorTransferFunction>::New(a); colorFun->AddRGBPoint(- 3024..0.0.0);
colorFun->AddRGBPoint(129.54.0.55.0.25.0.15);
colorFun->AddRGBPoint(157.02.1.1.1);
colorFun->AddRGBPoint(169.92.0.99.0.87.0.39);
colorFun->AddRGBPoint(395.58.1.0.88.0.66);
colorFun->AddRGBPoint(1578.73.1.0.95.0.96);
colorFun->AddRGBPoint(3071.0.83.0.66.1);
volumeProperty->SetColor(colorFun);
vtkSmartPointer<vtkVolume> volume =
vtkSmartPointer<vtkVolume>::New(a); volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
vtkSmartPointer<vtkCamera>camera = vtkSmartPointer<vtkCamera>::New(a); camera->SetViewUp(0.0.- 1);
camera->SetPosition(0.1.0);
camera->SetFocalPoint(0.0.0);
camera->ComputeViewPlaneNormal(a); camera->Azimuth(10.0);
camera->Elevation(10.0);
// A renderer and render window
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(a); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(a); renderWindow->AddRenderer(renderer);
renderWindow->SetSize(1000.1000);
renderer->SetActiveCamera(camera);
renderer->SetBackground(0.0.0);
renderer->AddVolume(volume);
// An interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New(a); renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->ResetCamera(a); renderWindow->Render(a); vtkSmartPointer<vtkInteractorStyleTrackballCamera>style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New(a); renderWindowInteractor->SetInteractorStyle(style);
// renderWindowInteractor->Initialize();
// renderWindowInteractor->Start();
renderWindowInteractor->Initialize(a); renderWindow->Render(a); renderWindowInteractor->Start(a);return EXIT_SUCCESS;
}
Copy the code
Reconstructed implants