+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Main authors : XX XX XX
-
- Authors belongs to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
- - BSD http://www.opensource.org/licenses/bsd-license.php
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-
- =========================================================================*/
-
-#include "clitkDicomRT_ROI.h"
-#include <vtkSmartPointer.h>
-#include <vtkAppendPolyData.h>
-
-//--------------------------------------------------------------------
-clitk::DicomRT_ROI::DicomRT_ROI() {
- mName = "NoName";
- mNumber = -1;
- mColor.resize(3);
- mColor[0] = mColor[1] = mColor[2] = 0;
- mMeshIsUpToDate = false;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-clitk::DicomRT_ROI::~DicomRT_ROI() {
-
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-int clitk::DicomRT_ROI::GetROINumber() const {
- return mNumber;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-const std::string & clitk::DicomRT_ROI::GetName() const {
- return mName;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-const std::vector<double> & clitk::DicomRT_ROI::GetDisplayColor() const {
- return mColor;
-}
-//--------------------------------------------------------------------
-
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI::Print(std::ostream & os) const {
- os << "ROI " << mNumber << "\t" << mName
- << "\t(" << mColor[0] << " " << mColor[1] << " " << mColor[2] << ")"
- << "\t Contours = " << mListOfContours.size() << std::endl;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI::Read(std::map<int, std::string> & rois, gdcm::SQItem * item) {
-
- // ROI number [Referenced ROI Number]
- mNumber = atoi(item->GetEntryValue(0x3006,0x0084).c_str());
-
- // Retrieve ROI Name
- mName = rois[mNumber];
-
- // ROI Color [ROI Display Color]
- mColor = clitk::parse_string<double>(item->GetEntryValue(0x3006,0x002a),'\\');
-
- // Read contours [Contour Sequence]
- gdcm::SeqEntry * contours=item->GetSeqEntry(0x3006,0x0040);
- for(gdcm::SQItem* j=contours->GetFirstSQItem();j!=0;j=contours->GetNextSQItem()) {
- DicomRT_Contour * c = new DicomRT_Contour;
- bool b = c->Read(j);
- if (b) mListOfContours.push_back(c);
- }
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-vtkPolyData * clitk::DicomRT_ROI::GetMesh() {
- if (!mMeshIsUpToDate) {
- ComputeMesh();
- }
- return mMesh;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI::ComputeMesh() {
- vtkAppendPolyData * append = vtkAppendPolyData::New();
- for(unsigned int i=0; i<mListOfContours.size(); i++) {
- append->AddInput(mListOfContours[i]->GetMesh());
- }
- append->Update();
- mMesh = append->GetOutput();
- mMeshIsUpToDate = true;
-}
-//--------------------------------------------------------------------
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Main authors : XX XX XX
-
- Authors belongs to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
- - BSD http://www.opensource.org/licenses/bsd-license.php
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-
- =========================================================================*/
-
-#ifndef CLITKDICOMRT_ROI_H
-#define CLITKDICOMRT_ROI_H
-
-#include "clitkDicomRT_Contour.h"
-
-namespace clitk {
-
- //--------------------------------------------------------------------
- class DicomRT_ROI {
-
- public:
- DicomRT_ROI();
- ~DicomRT_ROI();
-
- void Print(std::ostream & os = std::cout) const;
- void Read(std::map<int, std::string> & rois, gdcm::SQItem * item);
-
- int GetROINumber() const;
- const std::string & GetName() const;
- const std::vector<double> & GetDisplayColor() const;
- vtkPolyData * GetMesh();
-
- protected:
- void ComputeMesh();
- std::string mName;
- int mNumber;
- std::vector<double> mColor;
- std::vector<DicomRT_Contour*> mListOfContours;
- vtkPolyData * mMesh;
- bool mMeshIsUpToDate;
- };
- //--------------------------------------------------------------------
-
-} // end namespace clitk
-#endif // CLITKDICOMRT_ROI_H
-
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Main authors : XX XX XX
-
- Authors belongs to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
- - BSD http://www.opensource.org/licenses/bsd-license.php
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-
- =========================================================================*/
-
-#include "clitkDicomRT_ROI_ConvertToImageFilter.h"
-#include <vtkPolyDataToImageStencil.h>
-#include <vtkSmartPointer.h>
-#include <vtkImageStencil.h>
-#include <vtkLinearExtrusionFilter.h>
-#include <itkVTKImageToImageFilter.h>
-#include "clitkImageCommon.h"
-
-//--------------------------------------------------------------------
-clitk::DicomRT_ROI_ConvertToImageFilter::DicomRT_ROI_ConvertToImageFilter() {
- mROI = NULL;
- mImageInfoIsSet = false;
- mWriteOutput = false;
- mCropMask = true;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-clitk::DicomRT_ROI_ConvertToImageFilter::~DicomRT_ROI_ConvertToImageFilter() {
-
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI_ConvertToImageFilter::SetROI(clitk::DicomRT_ROI * roi) {
- mROI = roi;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI_ConvertToImageFilter::SetCropMaskEnabled(bool b) {
- mCropMask = b;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI_ConvertToImageFilter::SetOutputImageFilename(std::string s) {
- mOutputFilename = s;
- mWriteOutput = true;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI_ConvertToImageFilter::SetImageFilename(std::string f) {
- itk::ImageIOBase::Pointer header = clitk::readImageHeader(f);
- if (header->GetNumberOfDimensions() < 3) {
- std::cerr << "Error. Please provide a 3D image instead of " << f << std::endl;
- exit(0);
- }
- if (header->GetNumberOfDimensions() > 3) {
- std::cerr << "Warning dimension > 3 are ignored" << std::endl;
- }
- mSpacing.resize(3);
- mOrigin.resize(3);
- mSize.resize(3);
- for(unsigned int i=0; i<3; i++) {
- mSpacing[i] = header->GetSpacing(i);
- mOrigin[i] = header->GetOrigin(i);
- mSize[i] = header->GetDimensions(i);
- }
- mImageInfoIsSet = true;
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-void clitk::DicomRT_ROI_ConvertToImageFilter::Update() {
- if (!mROI) {
- std::cerr << "Error. No ROI set, please use SetROI." << std::endl;
- exit(0);
- }
- if (!mImageInfoIsSet) {
- std::cerr << "Error. Please provide image info (spacing/origin) with SetImageFilename" << std::endl;
- exit(0);
- }
- // DD("Update");
-
- // Get Mesh
- vtkPolyData * mesh = mROI->GetMesh();
- // DD(mesh->GetNumberOfCells());
-
- // Get bounds
- double *bounds=mesh->GetBounds();
- // for(int i=0; i<6; i++){
-// DD(bounds[i]);
-// }
-
- // Compute origin
- std::vector<double> origin;
- origin.resize(3);
- origin[0] = floor((bounds[0]-mOrigin[0])/mSpacing[0]-2)*mSpacing[0]+mOrigin[0];
- origin[1] = floor((bounds[2]-mOrigin[1])/mSpacing[1]-2)*mSpacing[1]+mOrigin[1];
- origin[2] = floor((bounds[4]-mOrigin[2])/mSpacing[2]-2)*mSpacing[2]+mOrigin[2];
-
- // Compute extend
- std::vector<double> extend;
- extend.resize(3);
- extend[0] = ceil((bounds[1]-origin[0])/mSpacing[0]+4);
- extend[1] = ceil((bounds[3]-origin[1])/mSpacing[1]+4);
- extend[2] = ceil((bounds[5]-origin[2])/mSpacing[2]+4);
-
- // If no crop, set initial image size/origin
- if (!mCropMask) {
- for(int i=0; i<3; i++) {
- origin[i] = mOrigin[i];
- extend[i] = mSize[i]-1;
- }
- }
-
- // Create new output image
- mBinaryImage = vtkImageData::New();
- mBinaryImage->SetScalarTypeToUnsignedChar();
- mBinaryImage->SetOrigin(&origin[0]);
- mBinaryImage->SetSpacing(&mSpacing[0]);
- mBinaryImage->SetExtent(0, extend[0],
- 0, extend[1],
- 0, extend[2]);
- mBinaryImage->AllocateScalars();
-
- // for(int i=0; i<3; i++){
- // DD(origin[i]);
- // DD(extend[i]);
- // DD(mBinaryImage->GetDimensions()[i]);
- // }
- memset(mBinaryImage->GetScalarPointer(), 0,
- mBinaryImage->GetDimensions()[0]*mBinaryImage->GetDimensions()[1]*mBinaryImage->GetDimensions()[2]*sizeof(unsigned char));
-
- // Extrude
- vtkSmartPointer<vtkLinearExtrusionFilter> extrude=vtkSmartPointer<vtkLinearExtrusionFilter>::New();
- extrude->SetInput(mesh);
- ///We extrude in the -slice_spacing direction to respect the FOCAL convention // ?????????????
- extrude->SetVector(0, 0, -mSpacing[2]);
-
- // Binarization
- vtkSmartPointer<vtkPolyDataToImageStencil> sts=vtkSmartPointer<vtkPolyDataToImageStencil>::New();
- //The following line is extremely important
- //http://www.nabble.com/Bug-in-vtkPolyDataToImageStencil--td23368312.html#a23370933
- sts->SetTolerance(0);
- sts->SetInformationInput(mBinaryImage);
- sts->SetInput(extrude->GetOutput());
- //sts->SetInput(mesh);
-
- vtkSmartPointer<vtkImageStencil> stencil=vtkSmartPointer<vtkImageStencil>::New();
- stencil->SetStencil(sts->GetOutput());
- stencil->SetInput(mBinaryImage);
- stencil->ReverseStencilOn();
- stencil->Update();
- mBinaryImage->ShallowCopy(stencil->GetOutput());
-
- if (mWriteOutput) {
- typedef itk::Image<unsigned char, 3> ImageType;
- typedef itk::VTKImageToImageFilter<ImageType> ConnectorType;
- ConnectorType::Pointer connector = ConnectorType::New();
- connector->SetInput(GetOutput());
- connector->Update();
- clitk::writeImage<ImageType>(connector->GetOutput(), mOutputFilename);
- }
-}
-//--------------------------------------------------------------------
-
-
-
-//--------------------------------------------------------------------
-vtkImageData * clitk::DicomRT_ROI_ConvertToImageFilter::GetOutput() {
- return mBinaryImage;
-}
-//--------------------------------------------------------------------
+++ /dev/null
-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Main authors : XX XX XX
-
- Authors belongs to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
- - BSD http://www.opensource.org/licenses/bsd-license.php
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-
- =========================================================================*/
-
-#ifndef CLITKDICOMRT_ROI_CONVERTTOIMAGEFILTER_H
-#define CLITKDICOMRT_ROI_CONVERTTOIMAGEFILTER_H
-
-#include "clitkDicomRT_ROI.h"
-#include "clitkImageCommon.h"
-#include <vtkImageData.h>
-
-namespace clitk {
-
- //--------------------------------------------------------------------
- class DicomRT_ROI_ConvertToImageFilter {
-
- public:
- DicomRT_ROI_ConvertToImageFilter();
- ~DicomRT_ROI_ConvertToImageFilter();
-
- void SetROI(clitk::DicomRT_ROI * roi);
- void SetImageFilename(std::string s);
- void SetOutputImageFilename(std::string s);
- void Update();
- vtkImageData * GetOutput();
- void SetCropMaskEnabled(bool b);
-
- protected:
- bool mImageInfoIsSet;
- bool mWriteOutput;
- bool mCropMask;
- std::string mOutputFilename;
- std::vector<double> mSpacing;
- std::vector<double> mOrigin;
- std::vector<int> mSize;
- clitk::DicomRT_ROI * mROI;
- vtkImageData * mBinaryImage;
- };
- //--------------------------------------------------------------------
-
-} // end namespace clitk
-#endif // CLITKDICOMRT_ROI_CONVERTTOIMAGEFILTER_H
-