diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index e17c4dc3..c2d5c8f5 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -72,6 +72,25 @@ endif() #========================================================= target_link_libraries(clitkCommon ${VTK_LIBRARIES} ${ITK_LIBRARIES}) +# I have some linking problems on linux if VTK 7.1.1 (at least) is built statically - It asks for Qt5::X11Extras - I do not know why +# First workaround - link clitkCommon with Qt5::X11Extras - Qt5::X11Extras is not necessary if VTK is built dynamically +# Second workaround - oblige the user to recompile VTK as a dynamic library (better solution) +if(UNIX AND NOT APPLE) + if(vv_QT_VERSION VERSION_EQUAL "5") #5 + if(VTK_VERSION VERSION_EQUAL "7.1.1") #7.1.1 + #message(${VTK_DIR}) + list(GET VTK_LIBRARIES 0 FIRST_VTK_ELEMENT) + #message(${FIRST_VTK_ELEMENT}) + file(GLOB FIRST_VTK_LIB ${VTK_DIR}/../../*${FIRST_VTK_ELEMENT}*.a) + #message(${FIRST_VTK_LIB}) + if(EXISTS ${FIRST_VTK_LIB}) + message(FATAL_ERROR "VTK is built as a statically library - you need to recompile VTK and/or ITK as dynamic libraries") + #find_package(Qt5X11Extras REQUIRED) + #target_link_libraries(clitkCommon Qt5::X11Extras) + endif() + endif() + endif() +endif() add_library(clitkDicomRTStruct STATIC clitkDicomRT_Contour.cxx diff --git a/common/clitkCommon.h b/common/clitkCommon.h index 37295846..7e9985db 100644 --- a/common/clitkCommon.h +++ b/common/clitkCommon.h @@ -76,7 +76,7 @@ namespace clitk { //-------------------------------------------------------------------- // when everything goes wrong #define WHEREAMI "[ " << __FILE__ << " ] line " << __LINE__ -#define FATAL(a) { std::cerr << "ERROR in " << WHEREAMI << ": " << a; exit(0); } +#define FATAL(a) { std::cerr << "ERROR in " << WHEREAMI << ": " << a << std::endl; exit(0); } //-------------------------------------------------------------------- // GGO with modified struct name diff --git a/common/clitkDicomRTStruct2ImageFilter.cxx b/common/clitkDicomRTStruct2ImageFilter.cxx index 2e11fdc4..65ef9034 100644 --- a/common/clitkDicomRTStruct2ImageFilter.cxx +++ b/common/clitkDicomRTStruct2ImageFilter.cxx @@ -23,6 +23,7 @@ // clitk #include "clitkDicomRTStruct2ImageFilter.h" #include "clitkImageCommon.h" +#include "vvImageWriter.h" // vtk #include @@ -32,6 +33,7 @@ #include #include #include +#include //-------------------------------------------------------------------- @@ -107,13 +109,19 @@ void clitk::DicomRTStruct2ImageFilter::SetImage(vvImage::Pointer image) { if (image->GetNumberOfDimensions() != 3) { std::cerr << "Error. Please provide a 3D image." << std::endl; - exit(0); + exit(EXIT_FAILURE); } mSpacing.resize(3); mOrigin.resize(3); mSize.resize(3); mDirection.resize(3); - mTransformMatrix = image->GetTransform()[0]->GetMatrix(); + //mTransformMatrix = image->GetTransform()[0]->GetMatrix(); + mTransformMatrix = vtkSmartPointer::New(); + for(unsigned int i=0;i<4;i++) { + for(unsigned int j=0;j<4;j++) { + mTransformMatrix->SetElement(i,j,image->GetTransform()[0]->GetMatrix()->GetElement(i,j)); + } + } for(unsigned int i=0; i<3; i++) { mSpacing[i] = image->GetSpacing()[i]; mOrigin[i] = image->GetOrigin()[i]; @@ -132,7 +140,7 @@ void clitk::DicomRTStruct2ImageFilter::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); + exit(EXIT_FAILURE); } if (header->GetNumberOfDimensions() > 3) { std::cerr << "Warning dimension > 3 are ignored" << std::endl; @@ -149,6 +157,18 @@ void clitk::DicomRTStruct2ImageFilter::SetImageFilename(std::string f) for(unsigned int j=0; j<3; j++) mDirection[i][j] = header->GetDirection(i)[j]; } + //cf. AddItkImage function in vvImage.txx + mTransformMatrix = vtkSmartPointer::New(); + mTransformMatrix->Identity(); + for(unsigned int i=0; i<3; i++) { + double tmp = 0; + for(unsigned int j=0; j<3; j++) { + mTransformMatrix->SetElement(i,j,mDirection[i][j]); + tmp -= mDirection[i][j] * mOrigin[j]; + } + tmp += mOrigin[i]; + mTransformMatrix->SetElement(i,3,tmp); + } } //-------------------------------------------------------------------- @@ -182,11 +202,11 @@ void clitk::DicomRTStruct2ImageFilter::Update() { if (!mROI) { std::cerr << "Error. No ROI set, please use SetROI." << std::endl; - exit(0); + exit(EXIT_FAILURE); } if (!ImageInfoIsSet()) { std::cerr << "Error. Please provide image info (spacing/origin) with SetImageFilename" << std::endl; - exit(0); + exit(EXIT_FAILURE); } // Get Mesh @@ -206,7 +226,7 @@ void clitk::DicomRTStruct2ImageFilter::Update() // Get bounds double *bounds=mesh->GetBounds(); - + /* //Change mOrigin, mSize and mSpacing with respect to the directions // Spacing is influenced by input direction std::vector tempSpacing; @@ -238,7 +258,7 @@ void clitk::DicomRTStruct2ImageFilter::Update() } mSize[i] = lrint(tempSize[i]); } - + */ // Compute origin std::vector origin; origin.resize(3); @@ -259,7 +279,18 @@ void clitk::DicomRTStruct2ImageFilter::Update() extend[i] = mSize[i]-1; } } - + //Apply the transform to the mesh + vtkSmartPointer outputLabelmapGeometryTransform = vtkSmartPointer::New(); + outputLabelmapGeometryTransform->SetMatrix(mTransformMatrix); + // Apparently the inverse is wrong... + //outputLabelmapGeometryTransform->Inverse(); + vtkSmartPointer transformPolyDataFilter = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 + transformPolyDataFilter->SetInput(mesh); +#else + transformPolyDataFilter->SetInputData(mesh); +#endif + transformPolyDataFilter->SetTransform(outputLabelmapGeometryTransform); // Create new output image mBinaryImage = vtkSmartPointer::New(); #if VTK_MAJOR_VERSION <= 5 @@ -281,11 +312,7 @@ void clitk::DicomRTStruct2ImageFilter::Update() // Extrude vtkSmartPointer extrude=vtkSmartPointer::New(); -#if VTK_MAJOR_VERSION <= 5 - extrude->SetInput(mesh); -#else - extrude->SetInputData(mesh); -#endif + extrude->SetInputConnection(transformPolyDataFilter->GetOutputPort()); ///We extrude in the -slice_spacing direction to respect the FOCAL convention (NEEDED !) extrude->SetVector(0, 0, -mSpacing[2]); @@ -295,11 +322,7 @@ void clitk::DicomRTStruct2ImageFilter::Update() //http://www.nabble.com/Bug-in-vtkPolyDataToImageStencil--td23368312.html#a23370933 sts->SetTolerance(0); sts->SetInformationInput(mBinaryImage); -#if VTK_MAJOR_VERSION <= 5 - sts->SetInput(extrude->GetOutput()); -#else sts->SetInputConnection(extrude->GetOutputPort(0)); -#endif //sts->SetInput(mesh); vtkSmartPointer stencil=vtkSmartPointer::New(); @@ -316,22 +339,26 @@ void clitk::DicomRTStruct2ImageFilter::Update() stencil->ReverseStencilOn(); stencil->Update(); - /* - vtkSmartPointer w = vtkSmartPointer::New(); - w->SetInput(stencil->GetOutput()); - w->SetFileName("binary2.mhd"); - w->Write(); - */ - mBinaryImage->ShallowCopy(stencil->GetOutput()); + vvImage::Pointer vvBinaryImage = vvImage::New(); + vtkSmartPointer vvBinaryImageT = vtkSmartPointer::New(); + vvBinaryImageT->SetMatrix(mTransformMatrix); + vvBinaryImage->AddVtkImage(mBinaryImage, vvBinaryImageT); + if (mWriteOutput) { - typedef itk::Image ImageType; - typedef itk::VTKImageToImageFilter ConnectorType; - ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(GetOutput()); - connector->Update(); - clitk::writeImage(connector->GetOutput(), mOutputFilename); + //typedef itk::Image ImageType; + //typedef itk::VTKImageToImageFilter ConnectorType; + //ConnectorType::Pointer connector = ConnectorType::New(); + //connector->SetInput(GetOutput()); + //connector->Update(); + //clitk::writeImage(connector->GetOutput(), mOutputFilename); + vvImageWriter::Pointer writer = vvImageWriter::New(); + writer->SetInput(vvBinaryImage); + if (!vvBinaryImage->GetTransform().empty()) + writer->SetSaveTransform(true); + writer->SetOutputFileName(mOutputFilename); + writer->Update(); } } //-------------------------------------------------------------------- @@ -341,7 +368,10 @@ void clitk::DicomRTStruct2ImageFilter::Update() //-------------------------------------------------------------------- vtkImageData * clitk::DicomRTStruct2ImageFilter::GetOutput() { - assert(mBinaryImage); + //assert(mBinaryImage); + if (mBinaryImage == NULL) { + FATAL("The binary RTStruct image is NULL"); + } return mBinaryImage; } //-------------------------------------------------------------------- diff --git a/common/clitkDicomRTStruct2ImageFilter.h b/common/clitkDicomRTStruct2ImageFilter.h index f93cbb29..9ba08453 100644 --- a/common/clitkDicomRTStruct2ImageFilter.h +++ b/common/clitkDicomRTStruct2ImageFilter.h @@ -72,17 +72,17 @@ namespace clitk { //-------------------------------------------------------------------- -template -typename itk::Image::ConstPointer clitk::DicomRTStruct2ImageFilter::GetITKOutput() -{ - assert(mBinaryImage); - typedef itk::Image ConnectorImageType; - typedef itk::VTKImageToImageFilter ConnectorType; - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(mBinaryImage); - connector->Update(); - return connector->GetOutput(); -} +//template +//typename itk::Image::ConstPointer clitk::DicomRTStruct2ImageFilter::GetITKOutput() +//{ +// assert(mBinaryImage); +// typedef itk::Image ConnectorImageType; +// typedef itk::VTKImageToImageFilter ConnectorType; +// typename ConnectorType::Pointer connector = ConnectorType::New(); +// connector->SetInput(mBinaryImage); +// connector->Update(); +// return connector->GetOutput(); +//} //-------------------------------------------------------------------- #endif // CLITKDICOMRT_TRUCT2IMAGEFILTER_H diff --git a/common/clitkDicomRT_Contour.cxx b/common/clitkDicomRT_Contour.cxx index 9a5042be..89ff7755 100644 --- a/common/clitkDicomRT_Contour.cxx +++ b/common/clitkDicomRT_Contour.cxx @@ -82,11 +82,7 @@ void clitk::DicomRT_Contour::UpdateDicomItem() double * p = mData->GetPoint(i); points[i*3] = p[0]; points[i*3+1] = p[1]; -#if VTK_MAJOR_VERSION <= 5 - points[i*3+1] = p[2]; -#else points[i*3+1] = p[2]-0.5; -#endif } // Get attribute @@ -96,7 +92,7 @@ void clitk::DicomRT_Contour::UpdateDicomItem() at.SetFromDataElement( contourdata ); // Set attribute - at.SetValues(&points[0], points.size(), false); + at.SetValues(&points[0], points.size()); DD(at.GetValues()[0]); DD("replace"); @@ -151,7 +147,10 @@ bool clitk::DicomRT_Contour::Read(gdcm::Item * item) at.SetFromDataElement( contourdata ); const double* points = at.GetValues(); // unsigned int npts = at.GetNumberOfValues() / 3; - assert(at.GetNumberOfValues() == static_cast(mNbOfPoints)*3); + //assert(at.GetNumberOfValues() == static_cast(mNbOfPoints)*3); + if (at.GetNumberOfValues() != static_cast(mNbOfPoints)*3) { + FATAL("The number of contour points is inconsistent with the number of triplets defining the contour"); + } // Organize values mData = vtkSmartPointer::New(); @@ -161,19 +160,16 @@ bool clitk::DicomRT_Contour::Read(gdcm::Item * item) double p[3]; p[0] = points[i*3]; p[1] = points[i*3+1]; -#if VTK_MAJOR_VERSION <= 5 - p[2] = points[i*3+2]; -#else p[2] = points[i*3+2]+0.5; -#endif mData->SetPoint(i, p); if (mZ == -1) mZ = p[2]; - if (p[2] != mZ) { + if (std::fabs(p[2] - mZ) > mTolerance) { DD(i); DD(p[2]); DD(mZ); - std::cout << "ERROR ! contour not in the same slice" << std::endl; - assert(p[2] == mZ); + //std::cout << "ERROR ! contour not in the same slice" << std::endl; + //assert(p[2] == mZ); + FATAL("ERROR ! contour not in the same slice"); } } @@ -202,7 +198,10 @@ bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) // Read values [Contour Data] std::vector points = parse_string(item->GetEntryValue(0x3006,0x0050),'\\'); - assert(points.size() == static_cast(mNbOfPoints)*3); + //assert(points.size() == static_cast(mNbOfPoints)*3); + if (points.size() != static_cast(mNbOfPoints)*3) { + FATAL("The number of contour points is inconsistent with the number of triplets defining the contour"); + } // Organize values mData = vtkSmartPointer::New(); @@ -212,19 +211,16 @@ bool clitk::DicomRT_Contour::Read(gdcm::SQItem * item) double p[3]; p[0] = points[i*3]; p[1] = points[i*3+1]; -#if VTK_MAJOR_VERSION <= 5 - p[2] = points[i*3+2]; -#else p[2] = points[i*3+2]+0.5; -#endif mData->SetPoint(i, p); if (mZ == -1) mZ = p[2]; - if (p[2] != mZ) { + if (std::fabs(p[2] - mZ) > mTolerance) { DD(i); DD(p[2]); DD(mZ); - std::cout << "ERROR ! contour not in the same slice" << std::endl; - assert(p[2] == mZ); + //std::cout << "ERROR ! contour not in the same slice" << std::endl; + //assert(p[2] == mZ); + FATAL("ERROR ! contour not in the same slice"); } } @@ -259,8 +255,17 @@ void clitk::DicomRT_Contour::SetTransformMatrix(vtkMatrix4x4* matrix) mTransformMatrix = matrix; } //-------------------------------------------------------------------- - - +//-------------------------------------------------------------------- +double clitk::DicomRT_Contour::GetTolerance() +{ + return mTolerance; +} +//-------------------------------------------------------------------- +void clitk::DicomRT_Contour::SetTolerance(double tol) +{ + mTolerance = tol; +} +//-------------------------------------------------------------------- //-------------------------------------------------------------------- void clitk::DicomRT_Contour::ComputeMeshFromDataPoints() { @@ -271,10 +276,10 @@ void clitk::DicomRT_Contour::ComputeMeshFromDataPoints() mMesh->SetPoints(mPoints); vtkIdType ids[2]; for (unsigned int idx=0 ; idxGetPoint(idx)[j]; - pointIn[3] = 1.0; + //double pointIn[4]; + //for (unsigned int j=0 ; j<3; ++j) + // pointIn[j] = mData->GetPoint(idx)[j]; + //pointIn[3] = 1.0; /*double pointOut[4]; mTransformMatrix->MultiplyPoint(pointIn, pointOut); std::cout << pointOut[0] << " " << pointOut[1] << " " << pointOut[2] << " " << pointOut[3] << std::endl; diff --git a/common/clitkDicomRT_Contour.h b/common/clitkDicomRT_Contour.h index ab6db0d2..389bbdd8 100644 --- a/common/clitkDicomRT_Contour.h +++ b/common/clitkDicomRT_Contour.h @@ -56,6 +56,8 @@ class DicomRT_Contour : public itk::LightObject{ vtkPoints * GetPoints() {return mData;} double GetZ() const {return mZ;} void SetTransformMatrix(vtkMatrix4x4* matrix); + double GetTolerance(); + void SetTolerance(double tol); protected: @@ -70,6 +72,7 @@ class DicomRT_Contour : public itk::LightObject{ bool mMeshIsUpToDate; ///Z location of the contour double mZ; + double mTolerance; #if GDCM_MAJOR_VERSION >= 2 gdcm::Item * mItem; diff --git a/common/clitkDicomRT_ROI.cxx b/common/clitkDicomRT_ROI.cxx index af8bee67..bc2a1c54 100644 --- a/common/clitkDicomRT_ROI.cxx +++ b/common/clitkDicomRT_ROI.cxx @@ -149,7 +149,7 @@ double clitk::DicomRT_ROI::GetForegroundValueLabelImage() const //-------------------------------------------------------------------- #if GDCM_MAJOR_VERSION >= 2 -bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) +bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour, double tol) { //FATAL("Error : compile vv with itk4 + external gdcm"); // Keep dicom item @@ -186,7 +186,10 @@ bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) // ROI Color [ROI Display Color] gdcm::Attribute<0x3006,0x002a> color = {}; color.SetFromDataSet( nestedds ); - assert( color.GetNumberOfValues() == 3 ); + //assert( color.GetNumberOfValues() == 3 ); + if (color.GetNumberOfValues() != 3) { + FATAL("The RGB triplet color representation for ROI is not a triplet"); + } mColor[0] = color.GetValue(0); mColor[1] = color.GetValue(1); mColor[2] = color.GetValue(2); @@ -212,6 +215,7 @@ bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) { gdcm::Item & j = sqi2->GetItem(i+1); // Item start at #1 DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + c->SetTolerance(tol); c->SetTransformMatrix(mTransformMatrix); bool b = c->Read(&j); if (b) { @@ -222,7 +226,7 @@ bool clitk::DicomRT_ROI::Read(gdcm::Item * itemInfo, gdcm::Item * itemContour) return true; } #else -void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::SQItem * item) +void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::SQItem * item, double tol) { // ROI number [Referenced ROI Number] mNumber = atoi(item->GetEntryValue(0x3006,0x0084).c_str()); @@ -239,6 +243,7 @@ void clitk::DicomRT_ROI::Read(std::map & rois, gdcm::SQItem * int i=0; for(gdcm::SQItem* j=contours->GetFirstSQItem(); j!=0; j=contours->GetNextSQItem()) { DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + c->SetTolerance(tol); c->SetTransformMatrix(mTransformMatrix); bool b = c->Read(j); if (b) { @@ -506,7 +511,7 @@ void clitk::DicomRT_ROI::ComputeContoursFromImage() //-------------------------------------------------------------------- #if CLITK_USE_SYSTEM_GDCM == 1 -void clitk::DicomRT_ROI::Read(vtkSmartPointer & reader, int roiindex) +void clitk::DicomRT_ROI::Read(vtkSmartPointer & reader, int roiindex, double tol) { vtkRTStructSetProperties * p = reader->GetRTStructSetProperties(); @@ -529,6 +534,7 @@ void clitk::DicomRT_ROI::Read(vtkSmartPointer & reader, i // Get the contour mMesh = reader->GetOutput(roiindex); DicomRT_Contour::Pointer c = DicomRT_Contour::New(); + c->SetTolerance(tol); c->SetTransformMatrix(mTransformMatrix); c->SetMesh(mMesh); // FIXME no GetZ, not GetPoints mMeshIsUpToDate = true; diff --git a/common/clitkDicomRT_ROI.h b/common/clitkDicomRT_ROI.h index b4179332..d7c5a981 100644 --- a/common/clitkDicomRT_ROI.h +++ b/common/clitkDicomRT_ROI.h @@ -80,14 +80,14 @@ class DicomRT_ROI : public itk::LightObject // Read from DICOM RT STRUCT #if GDCM_MAJOR_VERSION >= 2 - bool Read(gdcm::Item * itemInfo, gdcm::Item * itemContour); + bool Read(gdcm::Item * itemInfo, gdcm::Item * itemContour, double tol); void UpdateDicomItem(); #else - void Read(std::map & rois, gdcm::SQItem * item); + void Read(std::map & rois, gdcm::SQItem * item, double tol); #endif #if CLITK_USE_SYSTEM_GDCM == 1 - void Read(vtkSmartPointer & reader, int roiindex); + void Read(vtkSmartPointer & reader, int roiindex, double tol); #endif protected: diff --git a/common/clitkDicomRT_StructureSet.cxx b/common/clitkDicomRT_StructureSet.cxx index a845ef55..68a5c216 100644 --- a/common/clitkDicomRT_StructureSet.cxx +++ b/common/clitkDicomRT_StructureSet.cxx @@ -317,7 +317,7 @@ void clitk::DicomRT_StructureSet::Write(const std::string & filename) //-------------------------------------------------------------------- -void clitk::DicomRT_StructureSet::Read(const std::string & filename) +void clitk::DicomRT_StructureSet::Read(const std::string & filename, double tol) { //Try to avoid to use extern GDCM library @@ -397,7 +397,10 @@ void clitk::DicomRT_StructureSet::Read(const std::string & filename) //const gdcm::DataElement &ssroisq = ds.GetDataElement( tssroisq ); mROIInfoSequenceOfItems = ssroisq.GetValueAsSQ(); gdcm::SmartPointer & roi_seq = mROIInfoSequenceOfItems; - assert(roi_seq); // TODO error message + //assert(roi_seq); // TODO error message + if (roi_seq == NULL) { + FATAL("The Structure Set ROI Sequence tag does not contain any value"); + } for(unsigned int ridx = 0; ridx < roi_seq->GetNumberOfItems(); ++ridx) { gdcm::Item & item = roi_seq->GetItem( ridx + 1); // Item starts at 1 @@ -429,7 +432,10 @@ void clitk::DicomRT_StructureSet::Read(const std::string & filename) //const gdcm::DataElement &roicsq = ds.GetDataElement( troicsq ); gdcm::SmartPointer roi_contour_seq = roicsq.GetValueAsSQ(); mROIContoursSequenceOfItems = roi_contour_seq; - assert(roi_contour_seq); // TODO error message + //assert(roi_contour_seq); // TODO error message + if (roi_contour_seq == NULL) { + FATAL("The ROI Contour Sequence tag does not contain any value"); + } for(unsigned int ridx = 0; ridx < roi_contour_seq->GetNumberOfItems(); ++ridx) { gdcm::Item & item = roi_contour_seq->GetItem( ridx + 1); // Item starts at 1 // ROI number [Referenced ROI Number] @@ -448,7 +454,7 @@ void clitk::DicomRT_StructureSet::Read(const std::string & filename) // Create the roi mROIs[nb] = DicomRT_ROI::New(); mROIs[nb]->SetTransformMatrix(mTransformMatrix); - mROIs[nb]->Read(mMapOfROIInfo[nb], mMapOfROIContours[nb]); + mROIs[nb]->Read(mMapOfROIInfo[nb], mMapOfROIContours[nb], tol); } return; @@ -534,5 +540,60 @@ int clitk::DicomRT_StructureSet::AddBinaryImageAsNewROI(vvImage * im, std::strin return max; } //-------------------------------------------------------------------- - - +void clitk::DicomRT_StructureSet::Anon(const std::string & filename, const std::string & outputfilename, const std::string newPID) +{ + bool isDRTStruct = this->IsDicomRTStruct(filename); + if(isDRTStruct == false) { + std::cerr << "Your file is not a proper RTStruct" << std::endl; + return; + } +#if GDCM_MAJOR_VERSION >= 2 + gdcm::DataSet & ds = mFile->GetDataSet(); + //Patient name = 0010,0010 + gdcm::Attribute<0x0010,0x0010> patientNameA; + patientNameA.SetFromDataSet(ds); + std::string patientName = patientNameA.GetValue(); + std::cout<<"Patient name="<< patientName < +bool HaveSameOrigin(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B); + +template +bool HaveSameOrigin(typename ImageType1::Pointer A, + typename ImageType2::Pointer B); +//-------------------------------------------------------------------- +template bool HaveSameSpacing(typename ImageType1::ConstPointer A, typename ImageType2::ConstPointer B); diff --git a/common/clitkImageCommon.txx b/common/clitkImageCommon.txx index a07c66f0..56e1ed81 100644 --- a/common/clitkImageCommon.txx +++ b/common/clitkImageCommon.txx @@ -308,6 +308,28 @@ void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +bool HaveSameOrigin(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B) +{ + if (A->GetImageDimension() != B->GetImageDimension()) return false; + for(unsigned int i=0; iGetImageDimension(); i++) { + if (A->GetOrigin()[i] != B->GetOrigin()[i]) return false; + } + return true; +} +template +bool HaveSameOrigin(typename ImageType1::Pointer A, + typename ImageType2::Pointer B) +{ + if (A->GetImageDimension() != B->GetImageDimension()) return false; + for(unsigned int i=0; iGetImageDimension(); i++) { + if (A->GetOrigin()[i] != B->GetOrigin()[i]) return false; + } + return true; +} +//-------------------------------------------------------------------- //-------------------------------------------------------------------- template diff --git a/common/clitkTransformUtilities.cxx b/common/clitkTransformUtilities.cxx index 832d5983..433111bc 100644 --- a/common/clitkTransformUtilities.cxx +++ b/common/clitkTransformUtilities.cxx @@ -37,6 +37,23 @@ GetForwardAffineMatrix<3>(itk::Array transformParameters) return GetForwardAffineMatrix3D(transformParameters); } +//-------------------------------------------------------------------- +template < > +itk::Matrix +GetForwardAffineMatrix<4>(itk::Array transformParameters) +{ + itk::Matrix matrix; + matrix.SetIdentity(); + itk::Matrix tmp = GetForwardAffineMatrix3D(transformParameters); + for (unsigned int i = 0; i < 3; ++i) + for (unsigned int j = 0; j < 3; ++j) + matrix[i][j] = tmp[i][j]; + for (unsigned int i = 0; i < 3; ++i) + matrix[i][4] = tmp[i][3]; + // + return matrix; +} + //-------------------------------------------------------------------- template < > itk::Matrix diff --git a/common/vvImage.cxx b/common/vvImage.cxx index f75d3212..3fe5df2d 100644 --- a/common/vvImage.cxx +++ b/common/vvImage.cxx @@ -70,7 +70,7 @@ void vvImage::Reset() //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void vvImage::AddVtkImage(vtkImageData* input) +void vvImage::AddVtkImage(vtkImageData* input, vtkSmartPointer transform) { // RP: 20/12/2011 // Note that we're simply adding a new image to the vector. @@ -90,6 +90,7 @@ void vvImage::AddVtkImage(vtkImageData* input) mImageDimension = 1; mVtkImages.push_back(input); + mTransform.push_back(transform); } //-------------------------------------------------------------------- diff --git a/common/vvImage.h b/common/vvImage.h index cbb0284c..81c2219b 100644 --- a/common/vvImage.h +++ b/common/vvImage.h @@ -47,7 +47,7 @@ public : void Init(); void Reset(); template void AddItkImage(TItkImageType *input); - void AddVtkImage(vtkImageData* input); + void AddVtkImage(vtkImageData* input, vtkSmartPointer transform); const std::vector& GetVTKImages(); vtkImageData* GetFirstVTKImageData(); int GetNumberOfDimensions() const; diff --git a/common/vvImageReader.txx b/common/vvImageReader.txx index 2eba11c8..20fe59b8 100644 --- a/common/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -200,10 +200,10 @@ void vvImageReader::UpdateWithDimAndInputPixelType() } } -/* if (VImageDimension == 4) - mType == VECTORPIXELIMAGEWITHTIME; + if (VImageDimension == 4) + mType = VECTORPIXELIMAGEWITHTIME; else - mType == VECTORPIXELIMAGE;*/ + mType = VECTORPIXELIMAGE; try { mImage = vvImageFromITK(output, mType == VECTORPIXELIMAGEWITHTIME); @@ -316,4 +316,3 @@ void vvImageReader::UpdateWithDimAndInputVectorPixelType() //---------------------------------------------------------------------------- #endif /* end #define vvImageReader_TXX */ - diff --git a/itk/clitkCropLikeImageFilter.txx b/itk/clitkCropLikeImageFilter.txx index e7e342fc..184e669a 100644 --- a/itk/clitkCropLikeImageFilter.txx +++ b/itk/clitkCropLikeImageFilter.txx @@ -101,11 +101,11 @@ GenerateOutputInformation() { // Get input info typename ImageType::SizeType likeSize; typename ImageType::IndexType likeStart; - typename ImageType::PointType likeOrigin; - typename ImageType::SpacingType likeSpacing; + typename ImageType::PointType likeOrigin; + typename ImageType::SpacingType likeSpacing; typename ImageType::DirectionType likeDirection; typename ImageType::DirectionType like_invDirection; - if (m_LikeImage) { + if (m_LikeImage) { likeSize = m_LikeImage->GetLargestPossibleRegion().GetSize(); likeStart = m_LikeImage->GetLargestPossibleRegion().GetIndex(); likeOrigin = m_LikeImage->GetOrigin(); @@ -126,10 +126,10 @@ GenerateOutputInformation() { likeSpacing[i] = header->GetSpacing(i); for(unsigned int j=0; jGetDirection(i)[j]; - } + } //I don't know really why I need the inverse... like_invDirection = likeDirection.GetInverse(); - } + } else { clitkExceptionMacro("You should provide SetCropLikeFilename or SetCropLike to CropLikeImageFilter"); } @@ -159,7 +159,7 @@ GenerateOutputInformation() { output->SetRegions(m_OutputRegion); output->SetRequestedRegion(m_OutputRegion); output->SetBufferedRegion(m_OutputRegion); - output->SetSpacing(likeSpacing); + output->SetSpacing(likeSpacing); output->SetOrigin(likeOrigin); output->SetDirection(like_invDirection); output->Allocate(); // Needed ? diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index 75e5ef35..432b9c32 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -1430,8 +1430,9 @@ namespace clitk { typename InfoFilterType::Pointer indexChangeFilter = InfoFilterType::New(); indexChangeFilter->ChangeRegionOn(); // The next line is commented because not exist in itk 3 - // typename InfoFilterType::OutputImageOffsetValueType indexShift[3]; - long indexShift[3]; + typename InfoFilterType::OutputImageOffsetValueType indexShift[3]; + // does not compile on windows - uncomment the previous line + // long indexShift[3]; typename ImageType::IndexType index = input->GetLargestPossibleRegion().GetIndex(); for(uint i=0;i namespace clitk { diff --git a/registration/clitkOptNormalizedCorrelationImageToImageMetric.h b/registration/clitkOptNormalizedCorrelationImageToImageMetric.h index ea065716..7da08a81 100644 --- a/registration/clitkOptNormalizedCorrelationImageToImageMetric.h +++ b/registration/clitkOptNormalizedCorrelationImageToImageMetric.h @@ -128,14 +128,14 @@ class ITK_EXPORT NormalizedCorrelationImageToImageMetric : MeasureType ComputeSums( const ParametersType & parameters ) const; - inline bool GetValueThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + inline bool GetValueThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue ) const ITK_OVERRIDE; - inline bool GetValueAndDerivativeThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + inline bool GetValueAndDerivativeThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue, const ImageDerivativesType & diff --git a/registration/clitkOptNormalizedCorrelationImageToImageMetric.txx b/registration/clitkOptNormalizedCorrelationImageToImageMetric.txx index fbb52ca4..061ed011 100644 --- a/registration/clitkOptNormalizedCorrelationImageToImageMetric.txx +++ b/registration/clitkOptNormalizedCorrelationImageToImageMetric.txx @@ -211,8 +211,8 @@ template < class TFixedImage, class TMovingImage > inline bool NormalizedCorrelationImageToImageMetric ::GetValueThreadProcessSample( - unsigned int threadID, - unsigned long fixedImageSample, + itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue) const { @@ -416,8 +416,8 @@ template < class TFixedImage, class TMovingImage > inline bool NormalizedCorrelationImageToImageMetric ::GetValueAndDerivativeThreadProcessSample( - unsigned int threadID, - unsigned long fixedImageSample, + itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue, const ImageDerivativesType & diff --git a/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.h b/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.h index 3afd1b6b..559dd778 100644 --- a/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.h +++ b/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.h @@ -128,14 +128,14 @@ class ITK_EXPORT NormalizedCorrelationImageToImageMetricFor3DBLUTFFD : MeasureType ComputeSums( const ParametersType & parameters ) const; - inline bool GetValueThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + inline bool GetValueThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue ) const ITK_OVERRIDE; - inline bool GetValueAndDerivativeThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + inline bool GetValueAndDerivativeThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue, const ImageDerivativesType & diff --git a/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.txx b/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.txx index 494c61a5..632ce5fc 100644 --- a/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.txx +++ b/registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.txx @@ -211,8 +211,8 @@ template < class TFixedImage, class TMovingImage > inline bool NormalizedCorrelationImageToImageMetricFor3DBLUTFFD ::GetValueThreadProcessSample( - unsigned int threadID, - unsigned long fixedImageSample, + itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue) const { @@ -416,8 +416,8 @@ template < class TFixedImage, class TMovingImage > inline bool NormalizedCorrelationImageToImageMetricFor3DBLUTFFD ::GetValueAndDerivativeThreadProcessSample( - unsigned int threadID, - unsigned long fixedImageSample, + itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue, const ImageDerivativesType & diff --git a/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.h b/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.h index 79bd1c17..3ba1d252 100644 --- a/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.h +++ b/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.h @@ -333,8 +333,8 @@ class ITK_EXPORT MattesMutualInformationImageToImageMetricFor3DBLUTFFD : virtual inline void GetValueThreadPreProcess( unsigned int threadID, bool withinSampleThread ) const ITK_OVERRIDE; - virtual inline bool GetValueThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + virtual inline bool GetValueThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue ) const ITK_OVERRIDE; virtual inline void GetValueThreadPostProcess( unsigned int threadID, @@ -343,8 +343,8 @@ class ITK_EXPORT MattesMutualInformationImageToImageMetricFor3DBLUTFFD : virtual inline void GetValueAndDerivativeThreadPreProcess( unsigned int threadID, bool withinSampleThread ) const ITK_OVERRIDE; - virtual inline bool GetValueAndDerivativeThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + virtual inline bool GetValueAndDerivativeThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue, const ImageDerivativesType & diff --git a/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx b/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx index 9f717668..4bce2829 100644 --- a/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx +++ b/registration/itkOptMattesMutualInformationImageToImageMetricFor3DBLUTFFD.txx @@ -559,8 +559,8 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD template < class TFixedImage, class TMovingImage > inline bool MattesMutualInformationImageToImageMetricFor3DBLUTFFD -::GetValueThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, +::GetValueThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue) const { @@ -822,8 +822,8 @@ MattesMutualInformationImageToImageMetricFor3DBLUTFFD template < class TFixedImage, class TMovingImage > inline bool MattesMutualInformationImageToImageMetricFor3DBLUTFFD -::GetValueAndDerivativeThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, +::GetValueAndDerivativeThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue, const ImageDerivativesType & diff --git a/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.h b/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.h index d23a9cd6..8bdc0276 100644 --- a/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.h +++ b/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.h @@ -127,13 +127,13 @@ class ITK_EXPORT MeanSquaresImageToImageMetricFor3DBLUTFFD : //purposely not implemented void operator=(const Self &); - inline bool GetValueThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + inline bool GetValueThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue ) const ITK_OVERRIDE; - inline bool GetValueAndDerivativeThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, + inline bool GetValueAndDerivativeThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & mappedPoint, double movingImageValue, const ImageDerivativesType & diff --git a/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.txx b/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.txx index 02427a39..ed9c41b0 100644 --- a/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.txx +++ b/registration/itkOptMeanSquaresImageToImageMetricFor3DBLUTFFD.txx @@ -136,8 +136,8 @@ MeanSquaresImageToImageMetricFor3DBLUTFFD template < class TFixedImage, class TMovingImage > inline bool MeanSquaresImageToImageMetricFor3DBLUTFFD -::GetValueThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, +::GetValueThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue) const { @@ -202,8 +202,8 @@ MeanSquaresImageToImageMetricFor3DBLUTFFD template < class TFixedImage, class TMovingImage > inline bool MeanSquaresImageToImageMetricFor3DBLUTFFD -::GetValueAndDerivativeThreadProcessSample( unsigned int threadID, - unsigned long fixedImageSample, +::GetValueAndDerivativeThreadProcessSample( itk::ThreadIdType threadID, + itk::SizeValueType fixedImageSample, const MovingImagePointType & itkNotUsed(mappedPoint), double movingImageValue, const ImageDerivativesType & diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index c1fe88a4..ce202d32 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -53,11 +53,13 @@ namespace clitk ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components); // Call UpdateWithDim - if(Dimension==2) UpdateWithDim<2>(PixelType, Components); - else - if(Dimension==3) UpdateWithDim<3>(PixelType, Components); - else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); - else { + if (Dimension==2) + UpdateWithDim<2>(PixelType, Components); + else if (Dimension==3) + UpdateWithDim<3>(PixelType, Components); + else if (Dimension==4) + UpdateWithDim<4>(PixelType, Components); + else { std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"< matrix; - if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given) - { - if (m_ArgsInfo.matrix_given) - { + if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given) { + if (m_ArgsInfo.matrix_given) { std::cerr << "You must use either rotate/translate or matrix options" << std::endl; return; - } + } itk::Array transformParameters(2 * Dimension); transformParameters.Fill(0.0); - if (m_ArgsInfo.rotate_given) - { + if (m_ArgsInfo.rotate_given) { if (Dimension == 2) - transformParameters[0] = m_ArgsInfo.rotate_arg[0]; + transformParameters[0] = m_ArgsInfo.rotate_arg[0]; else - for (unsigned int i = 0; i < 3; i++) - transformParameters[i] = m_ArgsInfo.rotate_arg[i]; - } - if (m_ArgsInfo.translate_given) - { + for (unsigned int i = 0; i < 3; i++) + transformParameters[i] = m_ArgsInfo.rotate_arg[i]; + } + if (m_ArgsInfo.translate_given) { int pos = 3; if (Dimension == 2) pos = 1; for (unsigned int i = 0; i < Dimension && i < 3; i++) transformParameters[pos++] = m_ArgsInfo.translate_arg[i]; - } - if (Dimension == 4) - { - matrix.SetIdentity(); - itk::Matrix tmp = GetForwardAffineMatrix3D(transformParameters); - for (unsigned int i = 0; i < 3; ++i) - for (unsigned int j = 0; j < 3; ++j) - matrix[i][j] = tmp[i][j]; - for (unsigned int i = 0; i < 3; ++i) - matrix[i][4] = tmp[i][3]; - } - else - matrix = GetForwardAffineMatrix(transformParameters); - } - else - { - if (m_ArgsInfo.matrix_given) - { + } + matrix = GetForwardAffineMatrix(transformParameters); + } + else { + if (m_ArgsInfo.matrix_given) { matrix= clitk::ReadMatrix(m_ArgsInfo.matrix_arg); - if (m_Verbose) std::cout << "Reading the matrix..." << std::endl; - } + if (m_Verbose) + std::cout << "Reading the matrix..." << std::endl; + } else { if (m_ArgsInfo.elastix_given) { std::string filename(m_ArgsInfo.elastix_arg); matrix = createMatrixFromElastixFile(filename, m_Verbose); } - else - matrix.SetIdentity(); + else + matrix.SetIdentity(); } - } + } if (m_Verbose) - std::cout << "Using the following matrix:" << std::endl - << matrix << std::endl; + std::cout << "Using the following matrix:" << std::endl + << matrix << std::endl; typename itk::Matrix rotationMatrix = clitk::GetRotationalPartMatrix(matrix); typename itk::Vector translationPart = clitk::GetTranslationPartMatrix(matrix); @@ -720,54 +706,38 @@ namespace clitk // Matrix typename itk::Matrix matrix; - if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given) - { - if (m_ArgsInfo.matrix_given) - { + if (m_ArgsInfo.rotate_given || m_ArgsInfo.translate_given) { + if (m_ArgsInfo.matrix_given) { std::cerr << "You must use either rotate/translate or matrix options" << std::endl; return; - } + } itk::Array transformParameters(2 * Dimension); transformParameters.Fill(0.0); - if (m_ArgsInfo.rotate_given) - { + if (m_ArgsInfo.rotate_given) { if (Dimension == 2) transformParameters[0] = m_ArgsInfo.rotate_arg[0]; else for (unsigned int i = 0; i < 3; i++) transformParameters[i] = m_ArgsInfo.rotate_arg[i]; - } - if (m_ArgsInfo.translate_given) - { + } + if (m_ArgsInfo.translate_given) { int pos = 3; if (Dimension == 2) pos = 1; for (unsigned int i = 0; i < Dimension && i < 3; i++) transformParameters[pos++] = m_ArgsInfo.translate_arg[i]; - } - if (Dimension == 4) - { - matrix.SetIdentity(); - itk::Matrix tmp = GetForwardAffineMatrix3D(transformParameters); - for (unsigned int i = 0; i < 3; ++i) - for (unsigned int j = 0; j < 3; ++j) - matrix[i][j] = tmp[i][j]; - for (unsigned int i = 0; i < 3; ++i) - matrix[i][4] = tmp[i][3]; - } - else - matrix = GetForwardAffineMatrix(transformParameters); - } - else - { - if (m_ArgsInfo.matrix_given) - { + } + matrix = GetForwardAffineMatrix(transformParameters); + } + else { + if (m_ArgsInfo.matrix_given) { matrix= clitk::ReadMatrix(m_ArgsInfo.matrix_arg); - if (m_Verbose) std::cout << "Reading the matrix..." << std::endl; - } + if (m_Verbose) + std::cout << "Reading the matrix..." << std::endl; + } else - matrix.SetIdentity(); - } + matrix.SetIdentity(); + } if (m_Verbose) std::cout << "Using the following matrix:" << std::endl << matrix << std::endl; diff --git a/tools/clitkBlurImageGenericFilter.txx b/tools/clitkBlurImageGenericFilter.txx index ac0a459b..95a25eed 100644 --- a/tools/clitkBlurImageGenericFilter.txx +++ b/tools/clitkBlurImageGenericFilter.txx @@ -30,6 +30,7 @@ // itk include #include "itkDiscreteGaussianImageFilter.h" #include +#include namespace clitk { @@ -110,21 +111,42 @@ BlurImageGenericFilter::UpdateWithInputImageType() typename InputImageType::Pointer input = this->template GetInput(0); // Main filter - typedef typename InputImageType::PixelType PixelType; + typedef typename InputImageType::PixelType InputPixelType; typedef itk::Image OutputImageType; + typedef itk::Image DoubleOutputImageType; // Filter - typedef itk::DiscreteGaussianImageFilter DiscreteGaussianImageFilterType; - typename DiscreteGaussianImageFilterType::Pointer gaussianFilter=DiscreteGaussianImageFilterType::New(); - gaussianFilter->SetInput(input); - gaussianFilter->SetVariance(varianceArray); - gaussianFilter->SetUseImageSpacing(true); - gaussianFilter->Update(); + if(typeid(InputPixelType) != typeid(double)) { + if(mArgsInfo.verbose_flag) { + std::cout<<"OutputPixelType is set to float"< DiscreteGaussianImageFilterType; + typename DiscreteGaussianImageFilterType::Pointer gaussianFilter=DiscreteGaussianImageFilterType::New(); + gaussianFilter->SetInput(input); + gaussianFilter->SetVariance(varianceArray); + gaussianFilter->SetUseImageSpacing(true); + gaussianFilter->Update(); + + //std::cout<<"variance value="<GetVariance()<template SetNextOutput(gaussianFilter->GetOutput()); + } else { + if(mArgsInfo.verbose_flag) { + std::cout<<"OutputPixelType is set to double"< DiscreteGaussianImageFilterType; + typename DiscreteGaussianImageFilterType::Pointer gaussianFilter=DiscreteGaussianImageFilterType::New(); + gaussianFilter->SetInput(input); + gaussianFilter->SetVariance(varianceArray); + gaussianFilter->SetUseImageSpacing(true); + gaussianFilter->Update(); - //std::cout<<"variance value="<GetVariance()<SetInputDirectory(folderName); @@ -87,7 +91,7 @@ int main(int argc, char * argv[]) #endif for(unsigned int i=0; i= 2 gdcm::Reader hreader; hreader.SetFileName(input_files[i].c_str()); @@ -161,6 +165,16 @@ int main(int argc, char * argv[]) std::vector origin = theorigin[*sn]; std::vector instanceNumberSerie = instanceNumber[*sn]; std::vector files = seriesFiles[*sn]; + //Let's process the filenames -- it is mandatory for the line "if (tempFilename == files[i])" + for(unsigned int i=0; i sliceIndex(files.size()); //clitk::GetSortedIndex(locs, sliceIndex); //Look for files into GDCMSeriesFileNames, because it sorts files correctly and take the order @@ -169,10 +183,18 @@ int main(int argc, char * argv[]) int j(0); bool found(false); while (!found && jSetOutputOrigin(origin[0], origin[1], locs[sliceIndex[0]]); modifier->Update(); vvImage::Pointer focal_image = vvImage::New(); - focal_image->AddVtkImage(modifier->GetOutput()); + focal_image->AddVtkImage(modifier->GetOutput(), image->GetTransform()[0]); image = focal_image; } @@ -289,7 +311,11 @@ int main(int argc, char * argv[]) std::ostringstream name; std::vector directory = clitk::SplitFilename(args_info.output_arg); if (directory.size() == 2) +#ifdef _WIN32 + name << directory[0] << "\\" << *sn << "_" << directory[1]; +#else name << directory[0] << "/" << *sn << "_" << directory[1]; +#endif else name << *sn << "_" << args_info.output_arg; outfile = name.str(); diff --git a/tools/clitkDicomRTStruct2Image.cxx b/tools/clitkDicomRTStruct2Image.cxx index 3790ab7b..a62cee06 100644 --- a/tools/clitkDicomRTStruct2Image.cxx +++ b/tools/clitkDicomRTStruct2Image.cxx @@ -22,6 +22,31 @@ #include "clitkDicomRTStruct2Image_ggo.h" #include "clitkIO.h" +//-------------------------------------------------------------------- +std::string outputFileName(clitk::DicomRT_ROI::Pointer roi, const args_info_clitkDicomRTStruct2Image& args_info) +{ + std::string name = roi->GetName(); + int num = roi->GetROINumber(); + name.erase(remove_if(name.begin(), name.end(), isspace), name.end()); + std::string n; + n = std::string(args_info.output_arg).append(clitk::toString(num)).append("_").append(name); + if (args_info.mha_flag) { + n=n.append(".mha"); + } + else if (args_info.nii_flag) { + n=n.append(".nii"); + } + else if (args_info.niigz_flag) { + n=n.append(".nii.gz"); + } + else { + n=n.append(".mhd"); + } + if (args_info.verbose_flag) { + std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl; + } + return n; +} //-------------------------------------------------------------------- int main(int argc, char * argv[]) { @@ -31,27 +56,33 @@ int main(int argc, char * argv[]) { // Read and display information clitk::DicomRT_StructureSet::Pointer s = clitk::DicomRT_StructureSet::New(); - s->Read(args_info.input_arg); + s->Read(args_info.input_arg, args_info.tolerance_arg); if (args_info.verboseFile_flag) { s->Print(std::cout); } - - // New filter to convert to binary image - clitk::DicomRTStruct2ImageFilter filter; - filter.SetCropMaskEnabled(args_info.crop_flag); - filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin - if (args_info.vtk_flag) { - filter.SetWriteMesh(true); - } - if (args_info.roiName_given) { - filter.SetROI(s->GetROIFromROIName(args_info.roiName_arg)); - filter.SetOutputImageFilename(args_info.output_arg); - filter.Update(); - } - else if (args_info.roi_given && args_info.roi_arg != -1) { - filter.SetROI(s->GetROIFromROINumber(args_info.roi_arg)); - filter.SetOutputImageFilename(args_info.output_arg); - filter.Update(); + if (args_info.roiName_given || (args_info.roi_given && args_info.roi_arg != -1)) { + clitk::DicomRT_ROI::Pointer roi; + if (args_info.roiName_given) { + roi = s->GetROIFromROIName(args_info.roiName_arg); + } + else if (args_info.roi_given && args_info.roi_arg != -1) { + roi = s->GetROIFromROINumber(args_info.roi_arg); + } + if (roi) { + // New filter to convert to binary image + clitk::DicomRTStruct2ImageFilter filter; + filter.SetCropMaskEnabled(args_info.crop_flag); + filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin + if (args_info.vtk_flag) { + filter.SetWriteMesh(true); + } + filter.SetROI(roi); + filter.SetOutputImageFilename(outputFileName(roi, args_info)); + filter.Update(); + } else { + std::cerr<<"No ROI with this name/id"<begin(); iter != rois->end(); iter++) { clitk::DicomRT_ROI::Pointer roi = iter->second; clitk::DicomRTStruct2ImageFilter filter; - std::string name = roi->GetName(); - int num = roi->GetROINumber(); - filter.SetROI(roi); filter.SetCropMaskEnabled(args_info.crop_flag); filter.SetImageFilename(args_info.image_arg); // Used to get spacing + origin if (args_info.vtk_flag) { filter.SetWriteMesh(true); } - name.erase(remove_if(name.begin(), name.end(), isspace), name.end()); - std::string n; - if (args_info.mha_flag) { - n = std::string(args_info.output_arg).append - (clitk::toString(num)).append - ("_").append - (name).append - (".mha"); - } - else { - n = std::string(args_info.output_arg).append - (clitk::toString(num)).append - ("_").append - (name).append - (".mhd"); - } - if (args_info.verbose_flag) { - std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl; - } - filter.SetOutputImageFilename(n); - filter.Update(); + filter.SetROI(roi); + filter.SetOutputImageFilename(outputFileName(roi, args_info)); + filter.Update(); } + } else { + std::cerr<<"No ROIs with this substring of ROI name"< void InitializeImageType(); - bool mIsOperationUseASecondImage; + bool mIsOperationUseASecondImage;//if yes then - need to define more variables + std::string mFirstImageFileName; + int mFirstImageDimension; + std::string mFirstImagePixelType; + int mFirstImageComponents; + std::string mSecondImageFileName; + int mSecondImageDimension; + std::string mSecondImagePixelType; + int mSecondImageComponents; + double mScalar; double mDefaultPixelValue; int mTypeOfOperation; diff --git a/tools/clitkImageArithmGenericFilter.txx b/tools/clitkImageArithmGenericFilter.txx index 6bf79d51..a941b777 100644 --- a/tools/clitkImageArithmGenericFilter.txx +++ b/tools/clitkImageArithmGenericFilter.txx @@ -77,6 +77,40 @@ void ImageArithmGenericFilter::SetArgsInfo(const args_info_type if (mArgsInfo.input2_given) { mIsOperationUseASecondImage = true; this->AddInputFilename(mArgsInfo.input2_arg); + mFirstImageFileName = mArgsInfo.input1_arg; + mFirstImageDimension = 0; + mFirstImagePixelType = ""; + mFirstImageComponents = 0; + clitk::ReadImageDimensionAndPixelType(mFirstImageFileName, + mFirstImageDimension, + mFirstImagePixelType, + mFirstImageComponents); + mSecondImageFileName = mArgsInfo.input2_arg; + mSecondImageDimension = 0; + mSecondImagePixelType = ""; + mSecondImageComponents = 0; + clitk::ReadImageDimensionAndPixelType(mSecondImageFileName, + mSecondImageDimension, + mSecondImagePixelType, + mSecondImageComponents); + if(mSecondImageDimension != mFirstImageDimension) { + std::cerr << "ERROR : input and input2 must have the same dimensions" << std::endl; + std::cerr << "input is "<< mFirstImageDimension <<"D" << std::endl; + std::cerr << "input2 is "<< mSecondImageDimension <<"D" << std::endl; + exit(-1); + } + if(mSecondImageComponents != mFirstImageComponents) { + std::cerr << "ERROR : input and input2 must have the same number of components" << std::endl; + std::cerr << "input is "<< mFirstImageComponents << std::endl; + std::cerr << "input2 is "<< mSecondImageComponents << std::endl; + exit(-1); + } + //if(mSecondImagePixelType.compare(mFirstImagePixelType) != 0) { + // std::cerr << "ERROR : input and input2 must have the same pixel type" << std::endl; + // std::cerr << "input is "<< mFirstImagePixelType << std::endl; + // std::cerr << "input2 is "<< mSecondImagePixelType << std::endl; + // exit(-1); + //} } if (mArgsInfo.output_given) this->SetOutputFilename(mArgsInfo.output_arg); @@ -135,6 +169,10 @@ void ImageArithmGenericFilter::UpdateWithInputImageType() itkWarningMacro(<< "The images (input and input2) do not have the same spacing. " << "Using first input's information."); } + if(!clitk::HaveSameOrigin(input1, input2)) { + itkWarningMacro(<< "The images (input and input2) do not have the same origin. " + << "Using first input's information."); + } } // Check if overwrite and outputisfloat and pixeltype is not float -> do not overwrite diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx index 82a11ab5..57bf5fa2 100644 --- a/tools/clitkImageStatisticsGenericFilter.txx +++ b/tools/clitkImageStatisticsGenericFilter.txx @@ -248,13 +248,48 @@ namespace clitk // Output if (m_Verbose) std::cout<<"N° of pixels: "; - std::cout<GetCount(label)<GetCount(label); + std::cout<GetMean(label)<GetMean(label); + std::cout<GetSigma(label)<GetVariance(label)< ItI(input_adaptor, input_adaptor->GetLargestPossibleRegion()); + itk::ImageRegionIterator ItM(labelImage, labelImage->GetLargestPossibleRegion()); + for ( ItI.GoToBegin(), ItM.GoToBegin(); !ItI.IsAtEnd(); ++ItI, ++ItM ) { + if ( ItM.Get() == label ) { + PixelType value = ItI.Get(); + sigma+=(value-mean)*(value-mean)/nbPixels; + double diff = value - mean; + skewness += ( diff * diff * diff ) /nbPixels; + kurtosis += ( diff * diff * diff * diff ) /nbPixels; + } + } + sigma=std::sqrt(sigma); + if(sigma == 0) { + skewness=0; + kurtosis=3; + } else { + skewness/=(sigma*sigma*sigma); + kurtosis/=(sigma*sigma*sigma*sigma); + } + //Show results + if (m_Verbose) std::cout<<"SD_N: "; + std::cout<GetMinimum(label)<GetBinMin(0,i)<<"\t"<GetMeasurement(i,0)<<"\t"<GetBinMax(0,i)<<"\t"<GetFrequency(i)<GetBinMin(0,i)<<"\t"<GetMeasurement(i,0)<<"\t"<GetBinMax(0,i)<<"\t"<GetFrequency(i))/ double (histogram->GetTotalFrequency())<GetBinMin(0,i)<<"\t"<GetMeasurement(i,0)<<"\t"<GetBinMax(0,i)<<"\t"<GetFrequency(i)<GetBinMin(0,i)<<"\t"<GetMeasurement(i,0)<<"\t"<GetBinMax(0,i)<<"\t"<GetFrequency(i))/ double (histogram->GetTotalFrequency())<GetTotalFrequency(); + + for( int i =0; i GetMeasurement(i,0); + unsigned int freqVal = histogram->GetFrequency(i); + mean+=binVal*freqVal/totalFreq; + } + for( int i =0; i GetMeasurement(i,0); + unsigned int freqVal = histogram->GetFrequency(i); + sigma+=(binVal-mean)*(binVal-mean)*freqVal/totalFreq; + skewness+=(binVal-mean)* + (binVal-mean)* + (binVal-mean)* + freqVal/totalFreq; + kurtosis+=(binVal-mean)* + (binVal-mean)* + (binVal-mean)* + (binVal-mean)* + freqVal/totalFreq; + } + sigma=std::sqrt(sigma); + if(sigma == 0) { + skewness=0; + kurtosis=3; + } else { + skewness/=(sigma*sigma*sigma); + kurtosis/=(sigma*sigma*sigma*sigma); + } + + std::cout<<"Histogram statistics"<GetSpacing(), like_spacing = like_image->GetSpacing(); - if (spacing != like_spacing) { - std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl; - return PAD_ERR_NOT_SAME_SPACING; + SpacingType spacing = input->GetSpacing(), like_spacing = like_image->GetSpacing(); + for (unsigned int i = 0; i < dim; i++) { + double diff_spacing = std::fabs((double) spacing[i] - (double) like_spacing[i]); + if (diff_spacing > 1e-6) { + std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl; + return PAD_ERR_NOT_SAME_SPACING; + } } SizeType size = input->GetLargestPossibleRegion().GetSize(), like_size = like_image->GetLargestPossibleRegion().GetSize(); diff --git a/tools/clitkSplitImage.cxx b/tools/clitkSplitImage.cxx index 260e220a..56f6ed4e 100644 --- a/tools/clitkSplitImage.cxx +++ b/tools/clitkSplitImage.cxx @@ -39,7 +39,7 @@ int main(int argc, char * argv[]) itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg); if (header.IsNull()) { std::cerr << "Unable to read image file " << args_info.input_arg << std::endl; - std::exit(1); + std::exit(EXIT_FAILURE); } unsigned int dim = header->GetNumberOfDimensions(); @@ -55,9 +55,12 @@ int main(int argc, char * argv[]) filter.SetSplitDimension(args_info.dimension_arg); filter.SetPng(args_info.png_flag); filter.SetWindowLevel(args_info.window_arg, args_info.level_arg); + filter.SetMha(args_info.mha_flag); + filter.SetNii(args_info.nii_flag); + filter.SetNiigz(args_info.niigz_flag); filter.SetVerbose(args_info.verbose_flag); filter.Update(); // this is the end my friend - return 0; + return EXIT_SUCCESS; } // end main diff --git a/tools/clitkSplitImage.ggo b/tools/clitkSplitImage.ggo index 5d427eb7..62b0e5f1 100644 --- a/tools/clitkSplitImage.ggo +++ b/tools/clitkSplitImage.ggo @@ -10,6 +10,11 @@ option "output" o "Output image base filename" string yes option "verbose" v "Verbose" flag off option "dimension" d "Dimension to split on" int yes -option "png" p "Png file format" flag off + +text "\nOutput options - the default output format is mhd" +option "png" p "png file format" flag off option "window" w "Window" double no option "level" l "Level" double no +option "mha" - "mha file format" flag off +option "nii" - "nii file format" flag off +option "niigz" - "nii.gz file format" flag off diff --git a/tools/clitkSplitImageGenericFilter.cxx b/tools/clitkSplitImageGenericFilter.cxx index 58732ab2..ab1cd12d 100644 --- a/tools/clitkSplitImageGenericFilter.cxx +++ b/tools/clitkSplitImageGenericFilter.cxx @@ -142,6 +142,18 @@ void clitk::SplitImageGenericFilter::UpdateWithInputImageType() output = png.Do(this->m_Window, this->m_Level, informationFilter->GetOutput()); this->template SetNextOutput::OutputPngImageType>(output); } + else if(this->m_mha){ + SetOutputFilename(base_filename+"_"+ss.str()+".mha"); + SetNextOutput(informationFilter->GetOutput()); + } + else if(this->m_nii){ + SetOutputFilename(base_filename+"_"+ss.str()+".nii"); + SetNextOutput(informationFilter->GetOutput()); + } + else if(this->m_niigz){ + SetOutputFilename(base_filename+"_"+ss.str()+".nii.gz"); + SetNextOutput(informationFilter->GetOutput()); + } else { SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); SetNextOutput(informationFilter->GetOutput()); @@ -156,6 +168,18 @@ void clitk::SplitImageGenericFilter::UpdateWithInputImageType() output = png.Do(this->m_Window, this->m_Level, filter->GetOutput()); this->template SetNextOutput::OutputPngImageType>(output); } + else if(this->m_mha){ + SetOutputFilename(base_filename+"_"+ss.str()+".mha"); + SetNextOutput(filter->GetOutput()); + } + else if(this->m_nii){ + SetOutputFilename(base_filename+"_"+ss.str()+".nii"); + SetNextOutput(filter->GetOutput()); + } + else if(this->m_niigz){ + SetOutputFilename(base_filename+"_"+ss.str()+".nii.gz"); + SetNextOutput(filter->GetOutput()); + } else { SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); SetNextOutput(filter->GetOutput()); diff --git a/tools/clitkSplitImageGenericFilter.h b/tools/clitkSplitImageGenericFilter.h index 4b6d6762..9fc987fe 100644 --- a/tools/clitkSplitImageGenericFilter.h +++ b/tools/clitkSplitImageGenericFilter.h @@ -60,6 +60,9 @@ namespace clitk { void SetVerbose (const bool v) { m_Verbose = v; } void SetPng (const bool v) { m_Png = v; } void SetWindowLevel(const double w, const double l){ m_Window = w; m_Level = l;} + void SetMha (const bool v) { m_mha = v; } + void SetNii (const bool v) { m_nii = v; } + void SetNiigz (const bool v) { m_niigz = v; } //-------------------------------------------------------------------- // Main function called each time the filter is updated @@ -89,6 +92,9 @@ namespace clitk { bool m_Verbose; bool m_Png; double m_Window, m_Level; + bool m_mha; + bool m_nii; + bool m_niigz; }; // end class SplitImageGenericFilter //-------------------------------------------------------------------- diff --git a/vv/vvIntensityValueSlider.h b/vv/vvIntensityValueSlider.h index b123f404..08ddbe39 100644 --- a/vv/vvIntensityValueSlider.h +++ b/vv/vvIntensityValueSlider.h @@ -20,11 +20,11 @@ // qt #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include // clitk diff --git a/vv/vvLabelImageLoaderWidget.h b/vv/vvLabelImageLoaderWidget.h index 178acb2a..c1a81aba 100644 --- a/vv/vvLabelImageLoaderWidget.h +++ b/vv/vvLabelImageLoaderWidget.h @@ -24,11 +24,11 @@ // qt #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include #include "ui_vvLabelImageLoaderWidget.h" diff --git a/vv/vvSegmentationDialog.h b/vv/vvSegmentationDialog.h index 277abc17..400c8fea 100644 --- a/vv/vvSegmentationDialog.h +++ b/vv/vvSegmentationDialog.h @@ -37,11 +37,11 @@ #include "vtkPolyData.h" #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include //==================================================================== diff --git a/vv/vvSurfaceViewerDialog.h b/vv/vvSurfaceViewerDialog.h index 9601e9af..e7b8a19f 100644 --- a/vv/vvSurfaceViewerDialog.h +++ b/vv/vvSurfaceViewerDialog.h @@ -28,11 +28,11 @@ class vtkPolyDataMapper; class vtkActor; class vtkOBJReader; -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include //==================================================================== diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index 4cdaa851..72448255 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -19,11 +19,11 @@ #define VVTOOLBINARIZE_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolCropImage.h b/vv/vvToolCropImage.h index c5d8ce15..85440bd7 100644 --- a/vv/vvToolCropImage.h +++ b/vv/vvToolCropImage.h @@ -20,11 +20,11 @@ //qt #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include #include // vv diff --git a/vv/vvToolHistogram.h b/vv/vvToolHistogram.h index 84813782..f75d8431 100644 --- a/vv/vvToolHistogram.h +++ b/vv/vvToolHistogram.h @@ -19,11 +19,11 @@ #define VVTOOLHISTOGRAM_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolImageArithm.h b/vv/vvToolImageArithm.h index 964b9c81..5dbdb6d4 100644 --- a/vv/vvToolImageArithm.h +++ b/vv/vvToolImageArithm.h @@ -19,11 +19,11 @@ #define VVTOOLImageArithm_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolInputSelectorWidget.h b/vv/vvToolInputSelectorWidget.h index 76e0c34f..3879e007 100644 --- a/vv/vvToolInputSelectorWidget.h +++ b/vv/vvToolInputSelectorWidget.h @@ -20,11 +20,11 @@ // qt #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include // vv diff --git a/vv/vvToolMIP.h b/vv/vvToolMIP.h index e915525c..b40564fb 100644 --- a/vv/vvToolMIP.h +++ b/vv/vvToolMIP.h @@ -48,11 +48,11 @@ along with this program. If not, see . #include #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "vvToolBase.h" #include "QWidget" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolMedianFilter.h b/vv/vvToolMedianFilter.h index b075ac17..abb43bf1 100644 --- a/vv/vvToolMedianFilter.h +++ b/vv/vvToolMedianFilter.h @@ -46,11 +46,11 @@ #define VVTOOLMedianFilter_H #include -#if QT_VERSION >= 0x050000 - #include -#else - #include -#endif +//#if QT_VERSION >= 0x050000 +// #include +//#else +// #include +//#endif #include "vvToolBase.h" #include "QWidget" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h index 8297a90d..fe8ed83f 100644 --- a/vv/vvToolProfile.h +++ b/vv/vvToolProfile.h @@ -19,11 +19,11 @@ #define VVTOOLPROFILE_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolROIManager.cxx b/vv/vvToolROIManager.cxx index 00eff1df..1eb7d481 100644 --- a/vv/vvToolROIManager.cxx +++ b/vv/vvToolROIManager.cxx @@ -330,7 +330,7 @@ void vvToolROIManager::SelectedImageHasChanged(vvSlicerManager * m) void vvToolROIManager::Open() { // Open images - QString Extensions = "Images or Dicom-Struct files ( *.mha *.mhd *.hdr *.his *.dcm RS*)"; + QString Extensions = "Images or Dicom-Struct files (*.nii *.nii.gz *.mha *.mhd *.hdr *.his *.dcm RS*)"; Extensions += ";;All Files (*)"; QStringList filename = QFileDialog::getOpenFileNames(this,tr("Open binary image or DICOM RT Struct"), @@ -392,7 +392,7 @@ void vvToolROIManager::OpenBinaryImage(QStringList & filename) //------------------------------------------------------------------------------ -void vvToolROIManager::OpenDicomImage(std::string filename) +void vvToolROIManager::OpenDicomImage(std::string filename, double tol) { // GUI selector of roi vvMeshReader reader; @@ -412,7 +412,7 @@ void vvToolROIManager::OpenDicomImage(std::string filename) vtkSmartPointer transformMatrix = vtkSmartPointer::New(); transformMatrix = mCurrentImage->GetTransform()[0]->GetMatrix(); s->SetTransformMatrix(transformMatrix); - s->Read(filename); + s->Read(filename, tol); // Loop on selected struct std::vector list = selector.getSelectedItems(); @@ -428,7 +428,7 @@ void vvToolROIManager::OpenDicomImage(std::string filename) // Get image vvImage::Pointer binaryImage = vvImage::New(); - binaryImage->AddVtkImage(filter.GetOutput()); + binaryImage->AddVtkImage(filter.GetOutput(), mCurrentImage->GetTransform()[0]); // Add to gui AddImage(binaryImage, s->GetROIFromROINumber(list[i])->GetName(), "", 0, true); // "" = no filename diff --git a/vv/vvToolROIManager.h b/vv/vvToolROIManager.h index db630c64..4879ccd5 100644 --- a/vv/vvToolROIManager.h +++ b/vv/vvToolROIManager.h @@ -20,11 +20,11 @@ #define VVTOOLROIMANAGER_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include #include "vvToolBase.h" @@ -63,7 +63,7 @@ class vvToolROIManager: void SelectedImageHasChanged(vvSlicerManager *); void Open(); void OpenBinaryImage(QStringList & filenames); - void OpenDicomImage(std::string filaneme); + void OpenDicomImage(std::string filaneme, double tol=0); void SelectedItemChangedInTree(); void VisibleROIToggled(bool b); void VisibleContourROIToggled(bool b); diff --git a/vv/vvToolSegmentation.h b/vv/vvToolSegmentation.h index 7e49dc46..1250b7d5 100644 --- a/vv/vvToolSegmentation.h +++ b/vv/vvToolSegmentation.h @@ -19,11 +19,11 @@ #define VVTOOLSEGMENTATION_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "vvToolBase.h" #include "vvToolWidgetBase.h" diff --git a/vv/vvToolSimpleInputSelectorWidget.h b/vv/vvToolSimpleInputSelectorWidget.h index 4b8028fa..d3276d07 100644 --- a/vv/vvToolSimpleInputSelectorWidget.h +++ b/vv/vvToolSimpleInputSelectorWidget.h @@ -19,11 +19,11 @@ #define VVTOOLSIMPLEINPUTSELECTORWIDGET_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include #include "ui_vvToolSimpleInputSelectorWidget.h" diff --git a/vv/vvToolWidgetBase.h b/vv/vvToolWidgetBase.h index 7a3a5dfd..2c9af33c 100644 --- a/vv/vvToolWidgetBase.h +++ b/vv/vvToolWidgetBase.h @@ -20,11 +20,11 @@ #define VVTOOLWIDGETBASE_H #include -#if QT_VERSION >= 0x050000 -#include -#else -#include -#endif +//#if QT_VERSION >= 0x050000 +//#include +//#else +//#include +//#endif #include "ui_vvToolWidgetBase.h" #include "clitkImageToImageGenericFilter.h"