From 7805f0d563d5ba9be6022f8016c589b57c287f1d Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 20 Aug 2018 16:54:26 +0200 Subject: [PATCH] #3218 creaImageIO Feature New Normal - vtk8itk4wx3-mingw64 --- src/creaImageIODicomImageReader.cpp | 24 +++-- src/creaImageIODicomImageReader2.cpp | 10 +- src/creaImageIOGimmick.cpp | 35 +++---- src/creaImageIOGimmickView.cpp | 8 +- src/creaImageIOImageReader.cpp | 65 +++++++------ src/creaImageIOImageReader.h | 8 +- src/creaImageIOListener.cpp | 22 ++--- src/creaImageIOListener.h | 11 ++- src/creaImageIOMultiThreadImageReader.cpp | 111 ++++++++++++++-------- src/creaImageIOMultiThreadImageReader.h | 23 +++-- src/creaImageIOSystem.h | 14 +-- src/creaImageIOTreeNode.h | 3 - src/creaImageIOWxGimmickView.cpp | 8 +- src/creaImageIOWxViewer.cpp | 17 +++- 14 files changed, 198 insertions(+), 161 deletions(-) diff --git a/src/creaImageIODicomImageReader.cpp b/src/creaImageIODicomImageReader.cpp index 0e92f02..7f608f0 100644 --- a/src/creaImageIODicomImageReader.cpp +++ b/src/creaImageIODicomImageReader.cpp @@ -66,14 +66,14 @@ namespace creaImageIO GDCM_NAME_SPACE::Document*doc; GDCM_NAME_SPACE::File* file = GDCM_NAME_SPACE::File::New(); file->SetLoadMode( GDCM_NAME_SPACE::LD_ALL); - file->SetFileName(filename.c_str()); + file->SetFileName( filename ); file->Load(); bool ok = file->IsReadable(); if(!ok) { doc = (GDCM_NAME_SPACE::Document*)file; ok = doc->IsReadable(); - } + } // if ok file->Delete(); return ok; } @@ -84,17 +84,15 @@ namespace creaImageIO { vtkImageData* im = 0; try - { - mReader->SetFileName(filename.c_str()); - mReader->Update(); - im = vtkImageData::New(); - im->ShallowCopy(mReader->GetOutput()); - } - catch (...) - { - if (im!=0) im->Delete(); - im = 0; - } + { + mReader->SetFileName(filename.c_str()); + mReader->Update(); + im = vtkImageData::New(); + im->ShallowCopy(mReader->GetOutput()); + } catch (...) { + if (im!=0) im->Delete(); + im = 0; + } return im; } diff --git a/src/creaImageIODicomImageReader2.cpp b/src/creaImageIODicomImageReader2.cpp index 5b6861c..e8ff7e1 100644 --- a/src/creaImageIODicomImageReader2.cpp +++ b/src/creaImageIODicomImageReader2.cpp @@ -267,18 +267,20 @@ void DicomImageReader::ReadAttributes2(const std::string& filename, const std::string DicomImageReader::GetStringValueFromTag(const gdcm::DataElement& de) { +printf("EED DicomImageReader::GetStringValueFromTag Start\n"); static std::string buffer; buffer = ""; // cleanup previous call - const gdcm::ByteValue *bv = de.GetByteValue(); - if( bv ) // Can be Type 2 - { + const gdcm::ByteValue *bv = de.GetByteValue(); + if( bv!=NULL ) // Can be Type 2 + { buffer = std::string( bv->GetPointer(), bv->GetLength() ); // Will be padded with at least one \0 - } + } // if bv // Since return is a const char* the very first \0 will be considered +printf("EED DicomImageReader::GetStringValueFromTag END\n"); return buffer.c_str(); } //===================================================================== diff --git a/src/creaImageIOGimmick.cpp b/src/creaImageIOGimmick.cpp index 898de34..47e5b4f 100644 --- a/src/creaImageIOGimmick.cpp +++ b/src/creaImageIOGimmick.cpp @@ -150,9 +150,7 @@ namespace creaImageIO GimmickError("ERROR CREATING '"<SetAttribute(0,"Name",i_name); - } - else - { + } else { /// Open and test it GimmickDebugMessage(1,"Opening local database '" <second; - } - } + } // for + } // if } //============================================================== @@ -361,7 +359,6 @@ path+= mLocalDescpName; const std::vector& filenames) { GimmickMessage(2,"Adding files to '"<::iterator it = map_attr.begin(); for(; it != map_attr.end(); it++) + { i_res[it->first] = it->second; - } - else - { + } // for + } else { std::vector::iterator it = i_attr.inside.begin(); - for(; it != i_attr.inside.end(); it++) + for(; it != i_attr.inside.end(); it++) + { i_res[(*it)] = map_attr[(*it)]; - } - } + } // for + } // if ALL + } // if size } @@ -556,13 +553,11 @@ void Gimmick::fillVectInfos(std::vector i_attr, OutputAttr &infos) { printf("EED Gimmick::fillVectInfos inside %s\n",(*it).c_str()); infos.inside.push_back((*it)); - } - else - { + } else { infos.outside.push_back((*it)); // Need to scan again the files printf("EED Gimmick::fillVectInfos outside %s\n",(*it).c_str()); - } - } + } // if + } // for } const std::string Gimmick::getSummary() diff --git a/src/creaImageIOGimmickView.cpp b/src/creaImageIOGimmickView.cpp index 9b4169f..47aa9cb 100644 --- a/src/creaImageIOGimmickView.cpp +++ b/src/creaImageIOGimmickView.cpp @@ -124,7 +124,6 @@ namespace creaImageIO /// Destructor GimmickView::~GimmickView() { - printf("EED GimmickView::~GimmickView DESTROCTEUR \n"); GimmickDebugMessage(1,"GimmickView::~GimmickView" <& s, std::vect OutputAttr i_attr, double i_zspc) { OutStrGimmick out; - vtkImageData* first = mReader.GetImage( im.front()); + vtkImageData* first = mReader.GetImage( im.front() ); out.img = vtkImageData::New(); int ext[6]; //EED 2017-01-01 Migration VTK7 @@ -564,7 +563,6 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect out.img->AllocateScalars(first->GetScalarType(), first->GetNumberOfScalarComponents()); #endif - unsigned long imsize = dim[0] * dim[1]; imsize = imsize * dim[2] ; // deal with multiframes here // differents formats char , short, etc... @@ -574,12 +572,13 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect //!!!!out.img->SetSpacing(i_zspc); int slice = 0; std::vector::iterator it; + for (it=im.begin(); it!=im.end(); ++it) { vtkImageData* cur = mReader.GetImage( (*it) ); memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize); slice++; - } + } // for it getAttributes(im.front(),out.infos, i_attr); o_output.push_back(out); @@ -768,7 +767,6 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect //EED UnMosaic step... //How to verifie if is a mosaic file , with how many images inside?? - } diff --git a/src/creaImageIOImageReader.cpp b/src/creaImageIOImageReader.cpp index cdb6cb5..c3b9070 100644 --- a/src/creaImageIOImageReader.cpp +++ b/src/creaImageIOImageReader.cpp @@ -54,11 +54,11 @@ namespace creaImageIO //===================================================================== ImageReader::ImageReader() : - mUnreadableImage(0), + mUnreadableImage(NULL), mLastFilename("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") { // std::cout << "#### ImageReader::ImageReader()"<(new VtkImageReader(vtkPNGReader::New() , "PNG", ".png"))); @@ -88,13 +88,18 @@ namespace creaImageIO #endif for (int i=0;iSetScalarComponentFromFloat(i,j,0,0,0); + { + for (int j=0;jSetScalarComponentFromFloat(i,j,0,0,0); + } // for j + } // for i + for (int i=0;iSetScalarComponentFromFloat(i,i,0,0,255); - mUnreadableImage->SetScalarComponentFromFloat(dim[0]-1-i,i,0,0,255); - } + { + mUnreadableImage->SetScalarComponentFromFloat(i,i,0,0,255); + mUnreadableImage->SetScalarComponentFromFloat(dim[0]-1-i,i,0,0,255); + } // for i } //===================================================================== @@ -107,11 +112,11 @@ namespace creaImageIO //delete (*i); // } // mReader.clear(); - if (mUnreadableImage!=0) - { - mUnreadableImage->Delete(); - mUnreadableImage = 0; - } + if (mUnreadableImage!=NULL) + { + mUnreadableImage->Delete(); + mUnreadableImage = NULL; + } } //===================================================================== @@ -119,7 +124,6 @@ namespace creaImageIO void ImageReader::Register(boost::shared_ptr r) { mReader.push_back(r); - } void ImageReader::UnRegister(const std::string i_val) @@ -139,7 +143,6 @@ namespace creaImageIO std::vector::iterator i ; for (i=mUnReader.begin(); i!=mUnReader.end(); i++) { - if ( (*i).c_str() == filename) { ok = false; @@ -182,22 +185,22 @@ namespace creaImageIO // Reads the file (CanRead must be called before : no test here) vtkImageData* ImageReader::ReadImage( const std::string& filename) { - if (mLastFilename!=filename) - { - if (!CanRead(filename)) - { - vtkImageData* im = vtkImageData::New(); - im->ShallowCopy(mUnreadableImage); - return im; - } - } - vtkImageData* i = mLastReader->ReadImage(mLastFilename); - if (i==0) - { - i = vtkImageData::New(); - i->ShallowCopy(mUnreadableImage); - } - return i; + if (mLastFilename!=filename) + { + if (!CanRead(filename)) + { + vtkImageData* im = vtkImageData::New(); + im->ShallowCopy(mUnreadableImage); + return im; + } // CanRead + } // for mLastFilename + vtkImageData* i = mLastReader->ReadImage(mLastFilename); + if (i==NULL) + { + i = vtkImageData::New(); + i->ShallowCopy(mUnreadableImage); + } // i + return i; } //===================================================================== // Another function to read attributes for a file diff --git a/src/creaImageIOImageReader.h b/src/creaImageIOImageReader.h index 80e30fb..698c011 100644 --- a/src/creaImageIOImageReader.h +++ b/src/creaImageIOImageReader.h @@ -60,17 +60,13 @@ namespace creaImageIO /// in a string to string map /// On return, the values of the map are the values /// of the attributes (empty string if not available). - void ReadAttributes(const std::string& filename, - tree::AttributeMapType& attr); + void ReadAttributes(const std::string& filename, tree::AttributeMapType& attr); /// Exclude specific readers /// TO DO... /// Another function to read attributes for a file - void getAttributes(const std::string filename, - std::map &infos, std::vector i_attr); + void getAttributes(const std::string filename, std::map &infos, std::vector i_attr); - - protected: /// Register a reader diff --git a/src/creaImageIOListener.cpp b/src/creaImageIOListener.cpp index d9085e0..2882369 100644 --- a/src/creaImageIOListener.cpp +++ b/src/creaImageIOListener.cpp @@ -43,15 +43,12 @@ namespace creaImageIO // CTor Listener::Listener() { - boost::mutex::scoped_lock lock(mMutex); - GimmickDebugMessage(6,"Listener::Listener" - < #include + #include + + #include #ifdef _DEBUG #define new DEBUG_NEW @@ -49,8 +52,22 @@ namespace creaImageIO } //===================================================================== + class wxThreadEED2 + { + public: + void Delete() { printf("EED wxThreadEED2::Delete() \n"); } + int Run() { printf("EED wxThreadEED2::Run() \n"); return 0;} + void Pause() { printf("EED wxThreadEED2::Pause() \n"); } + void Create() { printf("EED wxThreadEED2::Create() \n"); } + bool IsAlive() { printf("EED wxThreadEED2::IsAlive() \n"); return false; } + bool TestDestroy() { printf("EED wxThreadEED2::TestDestroy() \n"); return false; } + int GetCurrentId() { printf("EED wxThreadEED2::GetCurrentId() \n"); return -999; } + }; + //===================================================================== - class ThreadedImageReader: public wxThread +//EED 2018-08-20 +// class ThreadedImageReader: public wxThread + class ThreadedImageReader: public wxThreadEED2 { public: ThreadedImageReader(MultiThreadImageReader* tir) : @@ -79,7 +96,7 @@ namespace creaImageIO //===================================================================== MultiThreadImageReader::MultiThreadImageReader(int number_of_threads) : //mDoNotSignal(false), - mReader(0), + mReader(NULL), mTotalMem(0), mTotalMemMax(1000000) { @@ -89,16 +106,13 @@ namespace creaImageIO mDone = false; // Create the threads -printf("EED MultiThreadImageReader::MultiThreadImageReader %d \n", number_of_threads); - for (int i=0; i t(new ThreadedImageReader(this), ThreadedImageReader::deleter()); - mThreadedImageReaderList.push_back(t); - std::cout << " ===> Thread "< t(new ThreadedImageReader(this), ThreadedImageReader::deleter()); + mThreadedImageReaderList.push_back(t); + std::cout << " ===> Thread "< 0) return true; @@ -139,7 +152,6 @@ printf("EED MultiThreadImageReader::Start Start\n"); wxMutexLocker locker(GetMultiThreadImageReaderUserMutex()); // std::cout << "EO Start : #Threads running = " // << mNumberOfThreadedReadersRunning<first; - } //for - mImages.clear(); + + CleanMImagesMap(); + mDone = true; -printf("EED MultiThreadImageReader::Stop End\n"); + } //===================================================================== + + void MultiThreadImageReader::CleanMImagesMap() + { + ImageMapType::iterator j; + for (j=mImages.begin(); j!=mImages.end(); ++j) + { + delete j->first; + } //for + mImages.clear(); + } + //===================================================================== MultiThreadImageReader::~MultiThreadImageReader() { -printf("EED MultiThreadImageReader::~MultiThreadImageReader Start\n"); // std::cout << "#### MultiThreadImageReader::~MultiThreadImageReader()" // <GetFilename() ); + } // for it +*/ + } //===================================================================== @@ -359,29 +387,28 @@ printf("EED MultiThreadImageReader::~MultiThreadImageReader End\n"); // if (mNumberOfThreadedReadersRunning==0) // if (mThreadedImageReaderList.size()==0) if (true) - { + { ImageToLoad itl(this,filename); ImageMapType::iterator i = mImages.find(&itl); if (i!=mImages.end()) - { - ImageToLoadPtr pitl = const_cast(i->first); - // Already inserted - if (pitl->GetImage() != 0) - { - // Already read - UpdateUnloadPriority(pitl, - GetMaximalPriorityWithoutLocking()+1); - return pitl->GetImage(); - } - } + { + ImageToLoadPtr pitl = const_cast(i->first); + // Already inserted + if (pitl->GetImage() != NULL) + { + // Already read + UpdateUnloadPriority( pitl, GetMaximalPriorityWithoutLocking()+1 ); + return pitl->GetImage(); + } // if pitl->GetImage() + } // if i + ImageToLoadPtr pitl = new ImageToLoad(this,filename,0); - mImages[pitl] = 0; - pitl->SetImage(mReader->ReadImage(filename)); - UpdateUnloadPriority(pitl, - GetMaximalPriorityWithoutLocking()+1); + mImages[pitl] = NULL; + pitl->SetImage( mReader->ReadImage(filename) ); + UpdateUnloadPriority( pitl, GetMaximalPriorityWithoutLocking()+1 ); return pitl->GetImage(); - } - + } // if true + /* mRequestedFilename = filename; mRequestedImage = 0; @@ -448,6 +475,8 @@ printf("EED MultiThreadImageReader::~MultiThreadImageReader End\n"); while (true); // */ + printf("EED MultiThreadImageReader::GetImage END\n"); + } //===================================================================== diff --git a/src/creaImageIOMultiThreadImageReader.h b/src/creaImageIOMultiThreadImageReader.h index f2b5f83..01d91c5 100644 --- a/src/creaImageIOMultiThreadImageReader.h +++ b/src/creaImageIOMultiThreadImageReader.h @@ -175,17 +175,17 @@ namespace creaImageIO std::map getAttributes(const std::vector i_attr); private: - MultiThreadImageReaderUser* mUser; - std::string mFilename; - int mPriority; - int mIndex; - int mUnloadIndex; - vtkImageData* mImage; + MultiThreadImageReaderUser *mUser; + std::string mFilename; + int mPriority; + int mIndex; + int mUnloadIndex; + vtkImageData *mImage; }; // /// Type of pointer on an ImageToLoad struct - typedef ImageToLoad* ImageToLoadPtr; + typedef ImageToLoad *ImageToLoadPtr; /// ImageToLoadPtr comparator on priority (for image queue) struct ImageToLoadPtrPriorityComparator @@ -230,10 +230,13 @@ namespace creaImageIO /// The callback from threaded readers when an image is read void SignalImageRead(ImageToLoadPtr p, bool purge); - + + void CleanMImagesMap(); + + + /// The type of map of images - typedef std::map ImageMapType; + typedef std::map ImageMapType; /// The map of images ImageMapType mImages; /// Comparator for the image to load queue diff --git a/src/creaImageIOSystem.h b/src/creaImageIOSystem.h index bae87fe..d4699b4 100644 --- a/src/creaImageIOSystem.h +++ b/src/creaImageIOSystem.h @@ -51,13 +51,12 @@ namespace creaImageIO { static bool first_time = true; if (first_time) - { - crea::MessageManager::RegisterMessageType("Gimmick!", - "Gimmick",1); - crea::MessageManager::RegisterMessageType("Gimmick! DEBUG", - "Gimmick",0); - first_time = false; - } + { +printf("EED === System.h === RegisterGimmickMessageTypes \n"); + crea::MessageManager::RegisterMessageType("Gimmick!", "Gimmick",1); + crea::MessageManager::RegisterMessageType("Gimmick! DEBUG", "Gimmick",0); + first_time = false; + } // if } //============================================================== inline void SetGimmickMessageLevel(int l) @@ -83,6 +82,7 @@ namespace creaImageIO #define GimmickDebugMessage(LEV,MESS) \ creaDebugMessage("Gimmick! DEBUG",LEV,"[Gimmick!] DEBUG: "< AttributeMapType; - /// Ctor with parent Node(Node* parent); /// Ctor with parent and attributes map @@ -88,7 +87,6 @@ namespace creaImageIO /// Returns the level of the node in the tree virtual int GetLevel() const { return mParent->GetLevel()+1; } - /// Returns the parent of the node Node* GetParent() const { return mParent; } @@ -113,7 +111,6 @@ namespace creaImageIO /// Remove the given children from the children list int RemoveChildrenFromList(Node*); - /// Get the Attributes Map AttributeMapType& GetAttributeMap() { return mAttributeMap; } diff --git a/src/creaImageIOWxGimmickView.cpp b/src/creaImageIOWxGimmickView.cpp index ea691e3..5e706e7 100644 --- a/src/creaImageIOWxGimmickView.cpp +++ b/src/creaImageIOWxGimmickView.cpp @@ -138,6 +138,7 @@ namespace creaImageIO mProgressDialog(NULL), mConstructed(false) { + mViewer=NULL; GimmickDebugMessage(1,"WxGimmickView::WxGimmickView" <GetHomeDirectory()); @@ -784,15 +785,16 @@ namespace creaImageIO //================================================== void WxGimmickView::OnInternalIdle() { - if (!mConstructed) return; + if (!mConstructed) return; static bool first_time = true; + if (false) { first_time = false; } // GimmickMessage(1,"WxGimmickView : Refresh viewer"<StartPlayer(); - if(mViewer) + if(mViewer!=NULL) { mViewer->RefreshIfNecessary(); } @@ -811,14 +813,12 @@ namespace creaImageIO //================================================== void WxGimmickView::ClearSelection() { -printf("EED WxGimmickView::ClearSelection Start\n"); pointers.clear(); pointers.push_back(boost::shared_ptr(new ImagePointerHolder(GetDefaultImage()))); //pointers.push_back(new ImagePointerHolder(GetDefaultImage())); mViewer->SetImageVector(pointers); mViewer->RefreshIfNecessary(); ResetExtent(); -printf("EED WxGimmickView::ClearSelection End\n"); } //================================================= diff --git a/src/creaImageIOWxViewer.cpp b/src/creaImageIOWxViewer.cpp index 0b99b66..22e1b3d 100644 --- a/src/creaImageIOWxViewer.cpp +++ b/src/creaImageIOWxViewer.cpp @@ -43,7 +43,22 @@ namespace creaImageIO //===================================================================== + class wxThreadEED3 + { + public: + void Delete() { printf("EED wxThreadEED3::Delete() \n"); } + int Run() { printf("EED wxThreadEED3::Run() \n"); return 0;} + void Pause() { printf("EED wxThreadEED3::Pause() \n"); } + void Create() { printf("EED wxThreadEED3::Create() \n"); } + bool IsAlive() { printf("EED wxThreadEED3::IsAlive() \n"); return false; } + bool TestDestroy() { printf("EED wxThreadEED3::TestDestroy() \n"); return false; } + int GetCurrentId() { printf("EED wxThreadEED3::GetCurrentId() \n"); return -999; } + }; + + //===================================================================== +//EED 2018-08-20 +// class WxViewerPlayer: public wxThreadEED3 class WxViewerPlayer: public wxThread { public: @@ -293,7 +308,7 @@ std::cout << std::endl; //================================================================ bool WxViewer::RefreshIfNecessary() { - if (mNeedRefresh) + if (mNeedRefresh==true) { GimmickDebugMessage(10,"WxViewer : Refreshing"<Render(); -- 2.47.1