From: Diego Caceres Date: Mon, 7 Nov 2011 10:21:48 +0000 (+0000) Subject: DFCH: ManualPaint + ImageUndoRedo. undo 90% (with memory management but it doesn... X-Git-Tag: v1.0.4~46 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ada3e60bcd998550327dac4f95b65f0c113f063b;p=creaMaracasVisu.git DFCH: ManualPaint + ImageUndoRedo. undo 90% (with memory management but it doesn't erase the files from disk automatically) --- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx index 2b7f140..93efb5b 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx @@ -20,13 +20,11 @@ void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img, this->GetImageName(this->m_ImgUndoDeque.size(), true)); imageInfo->SetImage(img); imageInfo->SetImageMManager(imMManager); - ///--------------------------------------------------------------------------------------------------- - // Uncoment the following line - //imageInfo->SaveImageAsMHD(this->m_GlobalPath); - ///------------------------------------------------------------------------------------------------ //Adding to deque this->m_ImgUndoDeque.push_back(imageInfo); this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1; + //Managing memory + this->ManageMemory(); } //virtual ImageInfoUR* Image3DDequeUR::Undo() { @@ -49,19 +47,19 @@ ImageInfoUR* Image3DDequeUR::Redo() { } //virtual void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) { - for (int i = index; i < this->m_ImgUndoDeque.size(); i++) { + int count = 0; + for (unsigned int i = index; i < this->m_ImgUndoDeque.size(); i++) { this->m_ImgUndoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath); this->m_ImgUndoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath); - this->m_ImgUndoDeque.pop_back(); + count++; } + for (int i = 0; i < count; i++) { + this->m_ImgUndoDeque.pop_back(); + } //rof + } //virtual void Image3DDequeUR::CleanRedoContainerFromIndex(const int& index) { - for (int i = index; i < this->m_ImgRedoDeque.size(); i++) { - this->m_ImgRedoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath); - this->m_ImgRedoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath); - this->m_ImgRedoDeque.pop_back(); - } } //virtual void Image3DDequeUR::CleanContainers() { @@ -77,6 +75,22 @@ void Image3DDequeUR::CleanContainers() { this->m_ImgUndoDeque.clear(); } +//virtual +void Image3DDequeUR::ManageMemory() { + for (int i = 0; (unsigned int) i < this->m_ImgUndoDeque.size(); i++) { + if (this->m_ImgUndoDeque[i]->GetStatus()) { + this->m_ImgUndoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath); + } //fi + } //rof + //Adding CurrentUndoPos to memory + if ((this->m_CurrentUndoPos != -1) + && !(this->m_ImgUndoDeque[this->m_CurrentUndoPos]->GetStatus())) { + this->m_ImgUndoDeque[this->m_CurrentUndoPos]->LoadImageMHDToMemory( + this->m_GlobalPath); + } + //The same for the redo queue +} + void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) { this->m_GlobalPath = globalPath; } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h index 9f46cb2..cdcdefb 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h @@ -25,6 +25,7 @@ public: virtual void CleanUndoContainerFromIndex(const int& index); virtual void CleanRedoContainerFromIndex(const int& index); virtual void CleanContainers(); + virtual void ManageMemory(); virtual ImageInfoUR* Undo(); virtual ImageInfoUR* Redo(); protected: diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx index ae2b970..a97ee3d 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx @@ -21,6 +21,10 @@ void ImageDequeUR::CleanContainers() { } +void ImageDequeUR::ManageMemory() { + +} + ImageInfoUR* ImageDequeUR::Undo() { return NULL; } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h index c66c75b..a20630a 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h @@ -32,6 +32,7 @@ public: virtual void CleanUndoContainerFromIndex(const int& index); virtual void CleanRedoContainerFromIndex(const int& index); virtual void CleanContainers(); + virtual void ManageMemory(); virtual ImageInfoUR* Undo(); virtual ImageInfoUR* Redo(); }; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.cxx index bdbed37..4857a7d 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.cxx @@ -11,7 +11,6 @@ ImageMManager::ImageMManager() { } ImageMManager::ImageMManager(ImageMManager* manager) { - this->m_PixelMap = manager->GetModificationMap(); this->m_RegionStruct = manager->GetModifiedRegion(); } ImageMManager::~ImageMManager() { @@ -28,40 +27,46 @@ void ImageMManager::CleanModifiedRegion() { this->m_RegionStruct.maxY = min; this->m_RegionStruct.minZ = max; this->m_RegionStruct.maxZ = min; - this->m_PixelMap.clear(); + this->m_ValidRegion = false; } //DFCH void ImageMManager::CalculateMinMaxRegion(const int& i, const int& j, const int& k) { - if (i <= this->m_RegionStruct.minX) { - this->m_RegionStruct.minX = i; + if (i >= 0 && j >= 0 && k >= 0) { + if (i <= this->m_RegionStruct.minX) { + this->m_RegionStruct.minX = i; + } //fi + if (i > this->m_RegionStruct.maxX) { + this->m_RegionStruct.maxX = i; + } //esle + if (j <= this->m_RegionStruct.minY) { + this->m_RegionStruct.minY = j; + } //fi + if (j > this->m_RegionStruct.maxY) { + this->m_RegionStruct.maxY = j; + } //esle + if (k <= this->m_RegionStruct.minZ) { + this->m_RegionStruct.minZ = k; + } //fi + if (k > this->m_RegionStruct.maxZ) { + this->m_RegionStruct.maxZ = k; + } //esle + this->m_ValidRegion = true; } //fi - if (i > this->m_RegionStruct.maxX) { - this->m_RegionStruct.maxX = i; - } //esle - if (j <= this->m_RegionStruct.minY) { - this->m_RegionStruct.minY = j; - } //fi - if (j > this->m_RegionStruct.maxY) { - this->m_RegionStruct.maxY = j; - } //esle - if (k <= this->m_RegionStruct.minZ) { - this->m_RegionStruct.minZ = k; - } //fi - if (k > this->m_RegionStruct.maxZ) { - this->m_RegionStruct.maxZ = k; + else { + this->m_ValidRegion = false; } //esle } //DFCH void ImageMManager::AddModifiedPixel(const int& i, const int& j, const int& k) { - this->m_PixelMap[i][j][k] = true; + //this->m_PixelMap[i][j][k] = true; this->CalculateMinMaxRegion(i, j, k); } //DFCH -RegionStructUR ImageMManager::GetModifiedRegion() { - return (this->m_RegionStruct); +bool ImageMManager::ValidateRegion() { + return (m_ValidRegion); } -ImageMManager::PixelModMap ImageMManager::GetModificationMap() { - return (this->m_PixelMap); +RegionStructUR ImageMManager::GetModifiedRegion() { + return (this->m_RegionStruct); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.h index 3e11b7e..196d65e 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.h @@ -23,15 +23,13 @@ public: virtual ~ImageMManager(); void CleanModifiedRegion(); //DFCH void AddModifiedPixel(const int& i, const int& j, const int& k); //DFCH - //void SetRegion(const RegionStructUR& region); - //void SetPixelModMap(const PixelModMap& map); //DFCH + bool ValidateRegion();//DFCH RegionStructUR GetModifiedRegion(); //DFCH - PixelModMap GetModificationMap(); //DFCH private: void CalculateMinMaxRegion(const int& i, const int& j, const int& k); //DFCH private: RegionStructUR m_RegionStruct; - PixelModMap m_PixelMap; + bool m_ValidRegion; }; #endif /* IMAGEMANAGEMENT_H_ */ diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx index 2f80bd6..dd9bcec 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx @@ -21,26 +21,31 @@ void ImageUndoRedo::Undo() { { //this->SetRedoImage(imageInfo->GetRegion()); this->DrawUR(imageInfo); + this->UpdateUndoImage(); } } //virtual void ImageUndoRedo::Redo() { - ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo(); - this->DrawUR(imageInfo); + } void ImageUndoRedo::SetImage(VTKImageDataPointerType image) { this->m_CurrentImage = image; this->m_CurrentImage->Update(); - this->m_OriginalImage = VTKImageDataPointerType::New(); - this->m_OriginalImage->DeepCopy(m_CurrentImage); + this->UpdateUndoImage(); } //virtual void ImageUndoRedo::SetUndoImage(ImageMManagerType* imMManager) { ImageMManagerType* newImageManager = new ImageMManagerType(imMManager); - RegionSType region = newImageManager->GetModifiedRegion(); - VTKImageDataPointerType imgResult = this->GetImageRegion(region, - this->m_OriginalImage); - this->m_ImagesDeque->AddImageToUndoContainer(imgResult, newImageManager); + if (newImageManager->ValidateRegion()) { + RegionSType region = newImageManager->GetModifiedRegion(); + VTKImageDataPointerType imgResult = this->GetImageRegion(region, + this->m_UndoImage); + this->m_ImagesDeque->AddImageToUndoContainer(imgResult, + newImageManager); + this->UpdateUndoImage(); + } else { + std::cerr << "INVALID REGION" << std::endl; + } } //virtual void ImageUndoRedo::SetRedoImage(const ImageMManagerType* imMManager) { @@ -50,21 +55,25 @@ void ImageUndoRedo::SetRedoImage(const ImageMManagerType* imMManager) { this->m_ImagesDeque->AddImageToRedoContainer(imgResult, imMManager);*/ } +void ImageUndoRedo::UpdateUndoImage() { + this->m_CurrentImage->Update(); + this->m_UndoImage = VTKImageDataPointerType::New(); + this->m_UndoImage->DeepCopy(m_CurrentImage); + this->m_UndoImage->Update(); +} + ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion( const RegionSType& region, VTKImageDataPointerType img) { VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New(); extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY, region.minZ, region.maxZ); extract->SetSampleRate(1, 1, 1); - extract->SetInput(this->m_OriginalImage); + extract->SetInput(this->m_UndoImage); VTKImageDataPointerType imgResult = extract->GetOutput(); imgResult->Update(); return (imgResult); } -void ImageUndoRedo::SetOriginalImage(VTKImageDataPointerType img) { - this->m_OriginalImage = img; -} void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) { this->m_CurrentImage = img; } @@ -72,24 +81,18 @@ void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) { void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) { VTKImageDataPointerType img = imageInfo->GetImage(); RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion(); - ImageMManager::PixelModMap map = - imageInfo->GetImageMManager()->GetModificationMap(); - std::cout << "Region " << "(" << region.maxX << "," << region.maxY << "," - << region.maxZ << ")" << std::endl; if (img != NULL) { for (int i = region.minX, x = 0; i <= region.maxX; i++, x++) { for (int j = region.minY, y = 0; j <= region.maxY; j++, y++) { for (int k = region.minZ, z = 0; k <= region.maxZ; k++, z++) { - if (map[i][j][k]) { - float value = img->GetScalarComponentAsFloat(i, j, k, - 0); - this->m_CurrentImage->SetScalarComponentFromFloat(i, j, - k, 0, value); - } + float value = img->GetScalarComponentAsFloat(x, y, z, 0); + this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k, + 0, value); } //rof } //rof } //rof this->m_CurrentImage->Modified(); } + this->m_ImagesDeque->ManageMemory(); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h index 78ff99b..c06caa7 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h @@ -19,7 +19,7 @@ public: virtual void SetImage(VTKImageDataPointerType image); virtual void SetUndoImage(ImageMManagerType* imMManager); virtual void SetRedoImage(const ImageMManagerType* imMManager); - void SetOriginalImage(VTKImageDataPointerType img); + void UpdateUndoImage(); void SetCurrentImage(VTKImageDataPointerType img); VTKImageDataPointerType GetImageRegion(const RegionSType& region, VTKImageDataPointerType img); @@ -29,7 +29,7 @@ protected: protected: IDequeType* m_ImagesDeque; - VTKImageDataPointerType m_OriginalImage; + VTKImageDataPointerType m_UndoImage; VTKImageDataPointerType m_CurrentImage; }; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp index 75cb61d..7c659eb 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp @@ -44,6 +44,7 @@ wxManualPaintPanel::wxManualPaintPanel(wxWindow * parent) : _mBarSlices->setRepresentedValues(min, max); _mBarSlices->SetStart(min); _mBarSlices->SetEnd(max); + _mBarSlices->Update(); //DFCH -- End BarSlices wxString lst2D3D[2];