From 62c20109b437bef1b9df091dfe7728a0fdf98bbc Mon Sep 17 00:00:00 2001 From: srit Date: Mon, 11 Apr 2011 09:54:16 +0000 Subject: [PATCH] Moved vvImageReader and vvImageWriter to clitkCommon for use in tools. Removed vvConstants.h, the typedef is now in vvImageReader. Made vvImageReader Qt independent since the inheritance of QThread did not seem useful. --- common/CMakeLists.txt | 6 ++++-- {vv => common}/vvImageReader.cxx | 12 ----------- {vv => common}/vvImageReader.h | 17 ++++++++++++---- {vv => common}/vvImageReader.txx | 2 -- {vv => common}/vvImageWriter.cxx | 0 {vv => common}/vvImageWriter.h | 0 {vv => common}/vvImageWriter.txx | 0 vv/CMakeLists.txt | 4 ---- vv/vv.cxx | 8 +++----- vv/vvConstants.h | 35 -------------------------------- vv/vvDeformableRegistration.cxx | 2 +- vv/vvMainWindow.cxx | 31 ++++++++++++++-------------- vv/vvMainWindow.h | 4 ++-- vv/vvSlicerManager.cxx | 16 +++++++-------- vv/vvSlicerManager.h | 7 +++---- vv/vvToolStructureSetManager.cxx | 4 ++-- 16 files changed, 51 insertions(+), 97 deletions(-) rename {vv => common}/vvImageReader.cxx (94%) rename {vv => common}/vvImageReader.h (92%) rename {vv => common}/vvImageReader.txx (99%) rename {vv => common}/vvImageWriter.cxx (100%) rename {vv => common}/vvImageWriter.h (100%) rename {vv => common}/vvImageWriter.txx (100%) delete mode 100644 vv/vvConstants.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index bc11149..5458f01 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -27,12 +27,14 @@ SET(clitkCommon_SRC clitkDicomRTDoseIO.cxx clitkDicomRTDoseIOFactory.cxx clitkOrientation.cxx - vvImage.cxx clitkImageToImageGenericFilterBase.cxx clitkExceptionObject.cxx clitkFilterBase.cxx clitkMemoryUsage.cxx -) + vvImage.cxx + vvImageReader.cxx + vvImageWriter.cxx +) ### Declare clitkCommon library ADD_LIBRARY(clitkCommon STATIC ${clitkCommon_SRC}) diff --git a/vv/vvImageReader.cxx b/common/vvImageReader.cxx similarity index 94% rename from vv/vvImageReader.cxx rename to common/vvImageReader.cxx index 25e235a..4aad9b8 100644 --- a/vv/vvImageReader.cxx +++ b/common/vvImageReader.cxx @@ -18,7 +18,6 @@ #ifndef VVIMAGEREADER_CXX #define VVIMAGEREADER_CXX -#include #include #include "vvImageReader.h" #include "vvImageReader.txx" @@ -74,18 +73,7 @@ void vvImageReader::Update(int dim,std::string inputPixelType, LoadedImageType t mType = type; mDim = dim; mInputPixelType=inputPixelType; - this->start(); //Start heavy read operation in a separate thread - while (this->isRunning()) { - qApp->processEvents(); - this->wait(50); - } -} -//------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -void vvImageReader::run() -{ switch(mDim) { case 2: UpdateWithDim<2>(mInputPixelType); diff --git a/vv/vvImageReader.h b/common/vvImageReader.h similarity index 92% rename from vv/vvImageReader.h rename to common/vvImageReader.h index cbe7d16..2056880 100644 --- a/vv/vvImageReader.h +++ b/common/vvImageReader.h @@ -19,15 +19,25 @@ #define vvImageReader_H #include #include -#include #include "itkCommand.h" #include "vvImage.h" -#include "vvConstants.h" -class vvImageReader : public itk::LightObject, public QThread { +class vvImageReader : public itk::LightObject { public: + //Image types + typedef enum _IMAGETYPE { + IMAGE = 20, + DICOM, + MERGED, + SLICED, + IMAGEWITHTIME, + MERGEDWITHTIME, + VECTORFIELD, + UNDEFINEDIMAGETYPE + } LoadedImageType; + typedef vvImageReader Self; typedef itk::SmartPointer Pointer; itkNewMacro(Self); @@ -52,7 +62,6 @@ public: void Update(int dim, std::string InputPixelType, LoadedImageType type); protected: - void run(); //==================================================================== std::vector mInputFilenames; ///Method used to load the image, see vvConstants.h for definition diff --git a/vv/vvImageReader.txx b/common/vvImageReader.txx similarity index 99% rename from vv/vvImageReader.txx rename to common/vvImageReader.txx index 3c5e154..e3c2bca 100644 --- a/vv/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -29,8 +29,6 @@ #include "clitkCommon.h" #include "clitkConfiguration.h" #include "vvFromITK.h" -#include "vvConstants.h" - //---------------------------------------------------------------------------- template void vvImageReader::UpdateWithDim(std::string InputPixelType) diff --git a/vv/vvImageWriter.cxx b/common/vvImageWriter.cxx similarity index 100% rename from vv/vvImageWriter.cxx rename to common/vvImageWriter.cxx diff --git a/vv/vvImageWriter.h b/common/vvImageWriter.h similarity index 100% rename from vv/vvImageWriter.h rename to common/vvImageWriter.h diff --git a/vv/vvImageWriter.txx b/common/vvImageWriter.txx similarity index 100% rename from vv/vvImageWriter.txx rename to common/vvImageWriter.txx diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 12e38a5..e91c2bf 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -73,10 +73,6 @@ SET(vv_SRCS vtkVOXImageWriter.cxx vvInteractorStyleNavigator.cxx vvSlicer.cxx - vvImageReader.cxx - vvImageReader.txx - vvImageWriter.cxx - vvImageWriter.txx vvLandmarks.cxx vvLandmarksGlyph.cxx vvGlyphSource.cxx diff --git a/vv/vv.cxx b/vv/vv.cxx index 59cacb5..2a04dc0 100644 --- a/vv/vv.cxx +++ b/vv/vv.cxx @@ -30,8 +30,6 @@ #include "clitkIO.h" #include "vvMainWindow.h" -#include "vvConstants.h" - #include #include #include @@ -99,7 +97,7 @@ int main( int argc, char** argv ) std::string current = argv[i]; if (!current.compare(0,2,"--")) { //We are parsing an option if (parse_mode == P_SEQUENCE) {//First finish the current sequence - window.LoadImages(sequence_filenames,MERGEDWITHTIME); + window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME); sequence_filenames.clear(); parse_mode=P_NORMAL; } @@ -161,12 +159,12 @@ int main( int argc, char** argv ) } else { std::vector image; image.push_back(current); - window.LoadImages(image,IMAGE); + window.LoadImages(image, vvImageReader::IMAGE); n_image_loaded++; } } if (parse_mode == P_SEQUENCE) { //Finish any current sequence - window.LoadImages(sequence_filenames,MERGEDWITHTIME); + window.LoadImages(sequence_filenames, vvImageReader::MERGEDWITHTIME); sequence_filenames.clear(); parse_mode=P_NORMAL; } diff --git a/vv/vvConstants.h b/vv/vvConstants.h deleted file mode 100644 index dfc7b75..0000000 --- a/vv/vvConstants.h +++ /dev/null @@ -1,35 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong 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 See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ -#ifndef vvConstants_h -#define vvConstants_h - -//Constants used everywhere in the program - -//Image types -typedef enum _IMAGETYPE { -IMAGE = 20, -DICOM, -MERGED, -SLICED, -IMAGEWITHTIME, -MERGEDWITHTIME, -VECTORFIELD, -UNDEFINEDIMAGETYPE -} LoadedImageType; - -#endif diff --git a/vv/vvDeformableRegistration.cxx b/vv/vvDeformableRegistration.cxx index 1586808..2274964 100644 --- a/vv/vvDeformableRegistration.cxx +++ b/vv/vvDeformableRegistration.cxx @@ -182,7 +182,7 @@ void vvDeformableRegistration::run() } vvImageReader::Pointer reader = vvImageReader::New(); reader->SetInputFilename(output_filename); - reader->Update(VECTORFIELD); + reader->Update(vvImageReader::VECTORFIELD); finish=clock(); DD((finish - start)/static_cast(CLOCKS_PER_SEC)); mOutput = reader->GetOutput(); diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 2d1feeb..7a95ae6 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -42,7 +42,6 @@ #include "vvMesh.h" #include "vvStructSelector.h" #include "vvMeshReader.h" -#include "vvConstants.h" #include "clitkConfiguration.h" // ITK include @@ -603,7 +602,7 @@ void vvMainWindow::MergeImages() } } if (vector.size() > 0) - LoadImages(vector, MERGED); + LoadImages(vector, vvImageReader::MERGED); } //------------------------------------------------------------------------------ @@ -620,7 +619,7 @@ void vvMainWindow::SliceImages() std::vector vector; for (int i = 0; i < files.size(); i++) vector.push_back(files[i].toStdString()); - LoadImages(vector, SLICED); + LoadImages(vector, vvImageReader::SLICED); } //------------------------------------------------------------------------------ @@ -682,7 +681,7 @@ void vvMainWindow::MergeImagesWithTime() } sort(vector.begin(),vector.end()); if (vector.size() > 1) - LoadImages(vector, MERGEDWITHTIME); + LoadImages(vector, vvImageReader::MERGEDWITHTIME); else QMessageBox::warning(this,tr("Reading problem"),"You need to select at least two images to merge images with time.\nIf you only want to open one image, please use the \"Open Image\" function."); } @@ -697,7 +696,7 @@ void vvMainWindow::OpenDicom() std::cout << "dicomSeriesSelector " << std::endl; if (dicomSeriesSelector->exec() == QDialog::Accepted) { files = *(dicomSeriesSelector->GetFilenames()); - LoadImages(files,DICOM); + LoadImages(files, vvImageReader::DICOM); } } //------------------------------------------------------------------------------ @@ -715,7 +714,7 @@ void vvMainWindow::OpenImages() std::vector vector; for (int i = 0; i < files.size(); i++) vector.push_back(files[i].toStdString()); - LoadImages(vector, IMAGE); + LoadImages(vector, vvImageReader::IMAGE); } //------------------------------------------------------------------------------ void vvMainWindow::OpenRecentImage() @@ -724,7 +723,7 @@ void vvMainWindow::OpenRecentImage() std::vector images; images.push_back(caller->text().toStdString()); mInputPathName = itksys::SystemTools::GetFilenamePath(images[0]).c_str(); - LoadImages(images,IMAGE); + LoadImages(images, vvImageReader::IMAGE); } //------------------------------------------------------------------------------ @@ -743,17 +742,17 @@ void vvMainWindow::OpenImageWithTime() for (int i = 0; i < files.size(); i++) { vector.push_back(files[i].toStdString()); } - LoadImages(vector, IMAGEWITHTIME); + LoadImages(vector, vvImageReader::IMAGEWITHTIME); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvMainWindow::LoadImages(std::vector files, LoadedImageType filetype) +void vvMainWindow::LoadImages(std::vector files, vvImageReader::LoadedImageType filetype) { //Separate the way to open images and dicoms int fileSize; - if (filetype == IMAGE || filetype == IMAGEWITHTIME) + if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME) fileSize = files.size(); else fileSize = 1; @@ -762,7 +761,7 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi std::vector nSlices; nSlices.resize(files.size()); std::fill(nSlices.begin(), nSlices.end(), 1); - if (filetype == SLICED) { + if (filetype == vvImageReader::SLICED) { for (int i = 0; i < fileSize; i++) { itk::ImageIOBase::Pointer header = clitk::readImageHeader(files[i]); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -813,7 +812,7 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi // Change filename if an image with the same already exist int number = GetImageDuplicateFilenameNumber(files[i] + std::string("_slice")); - if (filetype == IMAGE || filetype == IMAGEWITHTIME || filetype == SLICED) + if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED) SetImageSucceed = imageManager->SetImage(files[i],filetype, number, j); else { SetImageSucceed = imageManager->SetImages(files,filetype, number); @@ -1461,12 +1460,12 @@ void vvMainWindow::DisplaySliders(int slicer, int window) bool showVertical = false; if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3 || (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 2 - && mSlicerManagers[slicer]->GetType() != IMAGEWITHTIME - && mSlicerManagers[slicer]->GetType() != MERGEDWITHTIME)) + && mSlicerManagers[slicer]->GetType() != vvImageReader::IMAGEWITHTIME + && mSlicerManagers[slicer]->GetType() != vvImageReader::MERGEDWITHTIME)) showVertical = true; if (mSlicerManagers[slicer]->GetSlicer(window)->GetImage()->GetNumberOfDimensions() > 3 - || mSlicerManagers[slicer]->GetType() == IMAGEWITHTIME - || mSlicerManagers[slicer]->GetType() == MERGEDWITHTIME) + || mSlicerManagers[slicer]->GetType() == vvImageReader::IMAGEWITHTIME + || mSlicerManagers[slicer]->GetType() == vvImageReader::MERGEDWITHTIME) showHorizontal = true; if (showVertical) diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index cc53aa6..b1052cf 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -24,7 +24,7 @@ #include "ui_vvMainWindow.h" #include "vvMainWindowBase.h" #include "vvToolManager.h" -#include "vvConstants.h" +#include "vvImageReader.h" #include "vvMesh.h" #include "clitkMemoryUsage.h" @@ -50,7 +50,7 @@ class vvMainWindow: public vvMainWindowBase, public: vvMainWindow(); ~vvMainWindow(); - void LoadImages(std::vector filenames, LoadedImageType type); + void LoadImages(std::vector filenames, vvImageReader::LoadedImageType type); vvSlicerManager * AddImage(vvImage::Pointer image,std::string filename); void AddField(QString file,int index); void AddOverlayImage(int index, QString filename); diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 0278de0..a44889f 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -50,7 +50,7 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers) mFusionName = ""; mVFId = ""; mLastError = ""; - mType = UNDEFINEDIMAGETYPE; + mType = vvImageReader::UNDEFINEDIMAGETYPE; mColorMap = 0; mPreset = 0; mOverlayColor = 130; @@ -123,7 +123,7 @@ void vvSlicerManager::ToggleContourSuperposition() //---------------------------------------------------------------------------- -bool vvSlicerManager::SetImage(std::string filename, LoadedImageType type, int n, unsigned int slice) +bool vvSlicerManager::SetImage(std::string filename, vvImageReader::LoadedImageType type, int n, unsigned int slice) { mType = type; if (mReader.IsNull()) @@ -169,15 +169,15 @@ void vvSlicerManager::SetImage(vvImage::Pointer image) //---------------------------------------------------------------------------- -bool vvSlicerManager::SetImages(std::vector filenames,LoadedImageType type, int n) +bool vvSlicerManager::SetImages(std::vector filenames, vvImageReader::LoadedImageType type, int n) { mType = type; std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]); - if (type == DICOM) + if (type == vvImageReader::DICOM) fileWithoutExtension += "_dicom"; - else if (type == MERGED) + else if (type == vvImageReader::MERGED) fileWithoutExtension += "_merged"; - else if (type == MERGEDWITHTIME) + else if (type == vvImageReader::MERGEDWITHTIME) fileWithoutExtension += "_merged_wt"; mFileName = vtksys::SystemTools::GetFilenameName(mFileName); @@ -273,7 +273,7 @@ bool vvSlicerManager::SetVF(std::string filename) if (mVectorReader.IsNull()) mVectorReader = vvImageReader::New(); mVectorReader->SetInputFilename(filename); - mVectorReader->Update(VECTORFIELD); + mVectorReader->Update(vvImageReader::VECTORFIELD); if (mVectorReader->GetLastError().size() != 0) { mLastError = mVectorReader->GetLastError(); return false; @@ -751,7 +751,7 @@ void vvSlicerManager::ReloadOverlay() //---------------------------------------------------------------------------- void vvSlicerManager::ReloadVF() { - mVectorReader->Update(VECTORFIELD); //deletes the old images through the VF::Init() function + mVectorReader->Update(vvImageReader::VECTORFIELD); //deletes the old images through the VF::Init() function mVF=mVectorReader->GetOutput(); for ( unsigned int i = 0; i < mSlicers.size(); i++) { mSlicers[i]->SetVF(mVF); diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index eda2d22..f5a338b 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -36,7 +36,6 @@ class vtkRenderWindow; class vtkPolyData; // VV -#include "vvConstants.h" #include "clitkCommon.h" #include "vvImage.h" #include "vvMesh.h" @@ -60,9 +59,9 @@ class vvSlicerManager : public QObject { return mLastError; } - bool SetImage(std::string filename,LoadedImageType type, int n=0, unsigned int slice=0); + bool SetImage(std::string filename, vvImageReader::LoadedImageType type, int n=0, unsigned int slice=0); void SetImage(vvImage::Pointer image); - bool SetImages(std::vector filenames, LoadedImageType type, int n=0); + bool SetImages(std::vector filenames, vvImageReader::LoadedImageType type, int n=0); bool SetOverlay(std::string filename, int dim, std::string component); bool SetFusion(std::string filename, int dim, std::string component); @@ -234,7 +233,7 @@ protected: double mFusionLevel; int mPreset; - LoadedImageType mType; + vvImageReader::LoadedImageType mType; std::string mVFComponent; std::string mOverlayComponent; std::string mFusionComponent; diff --git a/vv/vvToolStructureSetManager.cxx b/vv/vvToolStructureSetManager.cxx index fd09b11..3c4b5c1 100644 --- a/vv/vvToolStructureSetManager.cxx +++ b/vv/vvToolStructureSetManager.cxx @@ -261,7 +261,7 @@ void vvToolStructureSetManager::OpenBinaryImage() std::vector filenames; filenames.push_back(filename[i].toStdString()); reader->SetInputFilenames(filenames); - reader->Update(IMAGE); + reader->Update(vvImageReader::IMAGE); QApplication::restoreOverrideCursor(); if (reader->GetLastError().size() != 0) { @@ -593,7 +593,7 @@ void vvToolStructureSetManager::ReloadCurrentROI() { // Reload image vvImageReader::Pointer reader = vvImageReader::New(); reader->SetInputFilename(mCurrentROI->GetFilename()); - reader->Update(IMAGE); + reader->Update(vvImageReader::IMAGE); if (reader->GetLastError() != "") { QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), reader->GetLastError().c_str()); return; -- 2.45.1