From: dsarrut Date: Wed, 24 Mar 2010 20:35:08 +0000 (+0000) Subject: - correct bug: string pixeltype is different in ITK and VTK X-Git-Tag: v1.2.0~746 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ec98e4a8aed11c9daa9bd7e2439d1ac489c933c7;p=clitk.git - correct bug: string pixeltype is different in ITK and VTK --- diff --git a/common/clitkCommon.txx b/common/clitkCommon.txx index bb4508a9..2441dcd 100644 --- a/common/clitkCommon.txx +++ b/common/clitkCommon.txx @@ -112,6 +112,9 @@ void GetSortedIndex(const std::vector & toSort, std::vector & index, //-------------------------------------------------------------------- template std::string GetTypeAsString() { + // http://www.vtk.org/doc/release/3/html/vtkSetGet_8h-source.html + // and + // itkImageIOBase.cxx const std::type_info & PixType = typeid(TPixel); std::string pixelName; if (PixType == typeid(char)) pixelName = "char"; // 'plain" char is different from signed char and unsigned char ... diff --git a/common/clitkImageToImageGenericFilter.txx b/common/clitkImageToImageGenericFilter.txx index 6d2a7cd..fe34518 100644 --- a/common/clitkImageToImageGenericFilter.txx +++ b/common/clitkImageToImageGenericFilter.txx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: clitkImageToImageGenericFilter.txx,v $ Language: C++ - Date: $Date: 2010/03/02 13:28:42 $ - Version: $Revision: 1.8 $ + Date: $Date: 2010/03/24 20:35:08 $ + Version: $Revision: 1.9 $ Author : Joel Schaerer David Sarrut @@ -117,9 +117,9 @@ std::string clitk::ImageToImageGenericFilter::GetAvailableImageTypes i++) { for (MCompItType j=(*i).second.begin(); j!= (*i).second.end(); j++) { for (MPixelItType k=(*j).second.begin(); k!= (*j).second.end(); k++) { - oss << "Dim: " << (*i).first - << ", Components: " << (*j).first - << ", Type: " << (*k).first << std::endl; + oss << "Dim: " << (*i).first; + if ((*j).first != 1) oss << ", Components: " << (*j).first; + oss << ", Type: " << (*k).first << std::endl; } } } diff --git a/common/vvImage.cxx b/common/vvImage.cxx index ae5c5a6..8bb06f1 100644 --- a/common/vvImage.cxx +++ b/common/vvImage.cxx @@ -3,27 +3,27 @@ /*------------------------------------------------------------------------- -Program: vv -Language: C++ -Author : Pierre Seroul (pierre.seroul@gmail.com) + Program: vv + Language: C++ + Author : Pierre Seroul (pierre.seroul@gmail.com) -Copyright (C) 2008 -Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr -CREATIS-LRMN http://www.creatis.insa-lyon.fr + Copyright (C) 2008 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS-LRMN http://www.creatis.insa-lyon.fr -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . --------------------------------------------------------------------------*/ + -------------------------------------------------------------------------*/ #include "vvImage.h" #include "vtkImageData.h" @@ -32,157 +32,177 @@ along with this program. If not, see . //-------------------------------------------------------------------- vvImage::vvImage() { - mVtkImages.resize(0); + mVtkImages.resize(0); } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- vvImage::~vvImage() { - for (unsigned int i = 0; i < mVtkImages.size(); i++) { - if (mVtkImages[i] != NULL) - mVtkImages[i]->Delete(); - } + for (unsigned int i = 0; i < mVtkImages.size(); i++) { + if (mVtkImages[i] != NULL) + mVtkImages[i]->Delete(); + } } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- void vvImage::SetImage(std::vector images) { - for (unsigned int i = 0; i < mVtkImages.size(); i++) { - if (mVtkImages[i] != NULL) - mVtkImages[i]->Delete(); - } - mVtkImages.resize(0); - for (unsigned int i = 0; i < images.size(); i++) { - mVtkImages.push_back(images[i]); - } + for (unsigned int i = 0; i < mVtkImages.size(); i++) { + if (mVtkImages[i] != NULL) + mVtkImages[i]->Delete(); + } + mVtkImages.resize(0); + for (unsigned int i = 0; i < images.size(); i++) { + mVtkImages.push_back(images[i]); + } } //-------------------------------------------------------------------- //-------------------------------------------------------------------- void vvImage::AddImage(vtkImageData* image) { - mVtkImages.push_back(image); + mVtkImages.push_back(image); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- void vvImage::Init() { - for (unsigned int i = 0; i < mVtkImages.size(); i++) { - if (mVtkImages[i] != NULL) - mVtkImages[i]->Delete(); - } - mVtkImages.resize(0); + for (unsigned int i = 0; i < mVtkImages.size(); i++) { + if (mVtkImages[i] != NULL) + mVtkImages[i]->Delete(); + } + mVtkImages.resize(0); } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- int vvImage::GetNumberOfSpatialDimensions() { - int dim=GetNumberOfDimensions(); - if (IsTimeSequence()) - return dim-1; - else - return dim; + int dim=GetNumberOfDimensions(); + if (IsTimeSequence()) + return dim-1; + else + return dim; } //-------------------------------------------------------------------- -// + + //-------------------------------------------------------------------- int vvImage::GetNumberOfDimensions() const { - if (mVtkImages.size()) + if (mVtkImages.size()) { - int dimension = 2; - int extent[6]; - mVtkImages[0]->GetWholeExtent(extent); - if (extent[5] - extent[4] >= 1) - dimension++; - if (mVtkImages.size() > 1) - dimension++; - return dimension; + int dimension = 2; + int extent[6]; + mVtkImages[0]->GetWholeExtent(extent); + if (extent[5] - extent[4] >= 1) + dimension++; + if (mVtkImages.size() > 1) + dimension++; + return dimension; } - return 0; + return 0; } +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void vvImage::GetScalarRange(double* range) { - assert(mVtkImages.size()); - double * temp = mVtkImages[0]->GetScalarRange(); - range[0]=temp[0];range[1]=temp[1]; - for (unsigned int i=1;iGetScalarRange(); + range[0]=temp[0];range[1]=temp[1]; + for (unsigned int i=1;iGetScalarRange(); - if (temp[0] < range[0]) range[0]=temp[0]; - if (temp[1] > range[1]) range[1]=temp[1]; + temp = mVtkImages[i]->GetScalarRange(); + if (temp[0] < range[0]) range[0]=temp[0]; + if (temp[1] > range[1]) range[1]=temp[1]; } } +//-------------------------------------------------------------------- + //-------------------------------------------------------------------- std::string vvImage::GetScalarTypeAsString() { - return mVtkImages[0]->GetScalarTypeAsString(); + // WARNING VTK pixel type different from ITK Pixel type + std::string vtktype = mVtkImages[0]->GetScalarTypeAsString(); + if (vtktype == "unsigned char") return "unsigned_char"; + if (vtktype == "unsigned short") return "unsigned_short"; + if (vtktype == "unsigned int") return "unsigned_int"; + return vtktype; } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- int vvImage::GetNumberOfScalarComponents() { - return mVtkImages[0]->GetNumberOfScalarComponents(); + return mVtkImages[0]->GetNumberOfScalarComponents(); } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- int vvImage::GetScalarSize() { - return mVtkImages[0]->GetScalarSize(); + return mVtkImages[0]->GetScalarSize(); } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- std::vector vvImage::GetSpacing() { - std::vector spacing; - int dim = this->GetNumberOfDimensions(); - for (int i = 0; i < dim; i++) + std::vector spacing; + int dim = this->GetNumberOfDimensions(); + for (int i = 0; i < dim; i++) { - if (i == 3) - spacing.push_back(1); - else - spacing.push_back(mVtkImages[0]->GetSpacing()[i]); + if (i == 3) + spacing.push_back(1); + else + spacing.push_back(mVtkImages[0]->GetSpacing()[i]); } - return spacing; + return spacing; } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- std::vector vvImage::GetOrigin() const { - std::vector origin; - int dim = this->GetNumberOfDimensions(); - for (int i = 0; i < dim; i++) + std::vector origin; + int dim = this->GetNumberOfDimensions(); + for (int i = 0; i < dim; i++) { - if (i == 3) - origin.push_back(0); - else - origin.push_back(mVtkImages[0]->GetOrigin()[i]); + if (i == 3) + origin.push_back(0); + else + origin.push_back(mVtkImages[0]->GetOrigin()[i]); } - return origin; + return origin; } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- std::vector vvImage::GetSize() { - std::vector size0; - int dim = this->GetNumberOfDimensions(); - for (int i = 0; i < dim; i++) + std::vector size0; + int dim = this->GetNumberOfDimensions(); + for (int i = 0; i < dim; i++) { - if (i == 3) - size0.push_back(mVtkImages.size()); - else - size0.push_back(mVtkImages[0]->GetDimensions()[i]); + if (i == 3) + size0.push_back(mVtkImages.size()); + else + size0.push_back(mVtkImages[0]->GetDimensions()[i]); } - return size0; + return size0; } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- unsigned long vvImage::GetActualMemorySize() { - unsigned long size = 0; - for (unsigned int i = 0; i < mVtkImages.size(); i++) { - size += mVtkImages[i]->GetActualMemorySize(); - } - return size; + unsigned long size = 0; + for (unsigned int i = 0; i < mVtkImages.size(); i++) { + size += mVtkImages[i]->GetActualMemorySize(); + } + return size; } //-------------------------------------------------------------------- @@ -216,6 +236,7 @@ bool vvImage::IsScalarTypeInteger() { } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- bool vvImage::IsScalarTypeInteger(int t) { if ((t == VTK_BIT) || diff --git a/filters/clitkBinarizeImageGenericFilter.txx b/filters/clitkBinarizeImageGenericFilter.txx index 747412a..11b75f9 100644 --- a/filters/clitkBinarizeImageGenericFilter.txx +++ b/filters/clitkBinarizeImageGenericFilter.txx @@ -34,6 +34,7 @@ namespace clitk template void BinarizeImageGenericFilter::InitializeImageType() { ADD_IMAGE_TYPE(Dim, char); + ADD_IMAGE_TYPE(Dim, uchar); ADD_IMAGE_TYPE(Dim, short); ADD_IMAGE_TYPE(Dim, int); ADD_IMAGE_TYPE(Dim, float); diff --git a/filters/clitkImageArithmGenericFilter.txx b/filters/clitkImageArithmGenericFilter.txx index 6d40681..643fe13 100644 --- a/filters/clitkImageArithmGenericFilter.txx +++ b/filters/clitkImageArithmGenericFilter.txx @@ -34,6 +34,7 @@ namespace clitk template void ImageArithmGenericFilter::InitializeImageType() { ADD_IMAGE_TYPE(Dim, char); + ADD_IMAGE_TYPE(Dim, uchar); ADD_IMAGE_TYPE(Dim, short); ADD_IMAGE_TYPE(Dim, float); } @@ -269,12 +270,14 @@ namespace clitk case 3: // Max while (!it.IsAtEnd()) { if (it.Get() < mScalar) ito.Set(PixelTypeDownCast(mScalar)); + else ito.Set(PixelTypeDownCast(it.Get())); ++it; ++ito; } break; case 4: // Min while (!it.IsAtEnd()) { if (it.Get() > mScalar) ito.Set(PixelTypeDownCast(mScalar)); + else ito.Set(PixelTypeDownCast(it.Get())); ++it; ++ito; } break; @@ -282,6 +285,7 @@ namespace clitk while (!it.IsAtEnd()) { if (it.Get() <= 0) ito.Set(PixelTypeDownCast(-it.Get())); // <= zero to avoid warning for unsigned types + else ito.Set(PixelTypeDownCast(it.Get())); ++it; ++ito; } break; diff --git a/filters/clitkImageResampleGenericFilter.cxx b/filters/clitkImageResampleGenericFilter.cxx index ac9d0c5..2473ca4 100644 --- a/filters/clitkImageResampleGenericFilter.cxx +++ b/filters/clitkImageResampleGenericFilter.cxx @@ -45,7 +45,7 @@ clitk::ImageResampleGenericFilter::ImageResampleGenericFilter(): template void clitk::ImageResampleGenericFilter::InitializeImageTypeWithDim() { ADD_IMAGE_TYPE(Dim, char); - ADD_IMAGE_TYPE(Dim, unsigned char); + ADD_IMAGE_TYPE(Dim, uchar); ADD_IMAGE_TYPE(Dim, short); ADD_IMAGE_TYPE(Dim, int); ADD_IMAGE_TYPE(Dim, float); diff --git a/vv/vvToolCropImage.cxx b/vv/vvToolCropImage.cxx index c9a0c0d..98b8e34 100644 --- a/vv/vvToolCropImage.cxx +++ b/vv/vvToolCropImage.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolCropImage.cxx,v $ Language: C++ - Date: $Date: 2010/03/24 10:48:18 $ - Version: $Revision: 1.5 $ + Date: $Date: 2010/03/24 20:35:13 $ + Version: $Revision: 1.6 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -193,9 +193,9 @@ void vvToolCropImage::InputIsSelected(vvSlicerManager * slicer) { mReducedExtent = mCurrentSlicerManager->GetImage()->GetFirstVTKImageData()->GetWholeExtent(); for(int i=0; i<6; i++) mInitialExtent[i] = mReducedExtent[i]; for(int i=0; iNumberOfSlicers(); i++) { - DD(i); - DD(mReducedExtent[i]); - DD(mInitialExtent[i]); + //DD(i); + //DD(mReducedExtent[i]); + //DD(mInitialExtent[i]); mCurrentSlicerManager->GetSlicer(i)->EnableReducedExtent(true); } diff --git a/vv/vvToolInputSelectorWidget.cxx b/vv/vvToolInputSelectorWidget.cxx index 1542c4b..42c3b7c 100644 --- a/vv/vvToolInputSelectorWidget.cxx +++ b/vv/vvToolInputSelectorWidget.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolInputSelectorWidget.cxx,v $ Language: C++ - Date: $Date: 2010/03/24 10:48:18 $ - Version: $Revision: 1.5 $ + Date: $Date: 2010/03/24 20:35:13 $ + Version: $Revision: 1.6 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -70,7 +70,7 @@ void vvToolInputSelectorWidget::AddInputSelector(QString & s, // add input->SetInputList(*ll, index); - input->setObjectName(QString::fromUtf8("TOTO")); + // input->setObjectName(QString::fromUtf8("TOTO")); mVerticalLayout->addWidget(input); // Enable or disable @@ -135,7 +135,7 @@ void vvToolInputSelectorWidget::reject() { //------------------------------------------------------------------------------ void vvToolInputSelectorWidget::skip() { - DD("SKIP"); + // DD("SKIP"); mSkipInput[mNumberOfAcceptedInputs] = true; accept();//mNumberOfAcceptedInputs++; } diff --git a/vv/vvToolSimpleInputSelectorWidget.cxx b/vv/vvToolSimpleInputSelectorWidget.cxx index fcc1361..4f7d55e 100644 --- a/vv/vvToolSimpleInputSelectorWidget.cxx +++ b/vv/vvToolSimpleInputSelectorWidget.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolSimpleInputSelectorWidget.cxx,v $ Language: C++ - Date: $Date: 2010/03/24 10:48:18 $ - Version: $Revision: 1.2 $ + Date: $Date: 2010/03/24 20:35:13 $ + Version: $Revision: 1.3 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2010 @@ -48,10 +48,12 @@ void vvToolSimpleInputSelectorWidget::Initialize() { connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int))); - changeInput(0); if (mSlicerManagerList.size() == 1) { if (!mAllowSkip) accept(); } + if (mSlicerManagerList.size() == 0) { + reject(); + } } //------------------------------------------------------------------------------ @@ -78,6 +80,11 @@ void vvToolSimpleInputSelectorWidget::EnableAllowSkip(bool b) { //------------------------------------------------------------------------------ void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector & l, int index) { + if (l.size() == 0) { + // TODO !!! + DD("no input > error message"); + reject(); + } mInputSequenceBox->clear(); for(unsigned int i=0; iaddItem(mSlicerManagerList[i]->GetFileName().c_str()); } mInputSequenceBox->setCurrentIndex(mCurrentIndex); - if (mSlicerManagerList.size() == 0) { - // TODO !!! - DD("no input > error message"); - reject(); - } + changeInput(mCurrentIndex); } //------------------------------------------------------------------------------ diff --git a/vv/vvToolWidgetBase.cxx b/vv/vvToolWidgetBase.cxx index 28270dc..d32ac36 100644 --- a/vv/vvToolWidgetBase.cxx +++ b/vv/vvToolWidgetBase.cxx @@ -3,8 +3,8 @@ Program: vv Module: $RCSfile: vvToolWidgetBase.cxx,v $ Language: C++ - Date: $Date: 2010/03/24 10:48:18 $ - Version: $Revision: 1.4 $ + Date: $Date: 2010/03/24 20:35:13 $ + Version: $Revision: 1.5 $ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr) Copyright (C) 2008 @@ -84,10 +84,11 @@ void vvToolWidgetBase::AddInputSelector(QString s, clitk::ImageToImageGenericFil int j=0; mFilter = f; mSlicerManagersCompatible.clear(); - // mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str())); + mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str())); for(unsigned int i=0; iGetSlicerManagers().size(); i++) { // DD(i); vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage(); + // DD(s->GetScalarTypeAsString()); if (mFilter->CheckImageType(s->GetNumberOfDimensions(), s->GetNumberOfScalarComponents(), s->GetScalarTypeAsString())) { @@ -97,7 +98,7 @@ void vvToolWidgetBase::AddInputSelector(QString s, clitk::ImageToImageGenericFil } } if (mSlicerManagersCompatible.size() == 0) { - QMessageBox::information(this, "No image","Sorry, could not perform operation. No compatible opened image type."); + QMessageBox::information(this, "No image","Sorry, could not perform operation. No (compatible) opened image type."); close(); return; }