]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: ManualPaint + ImageUndoRedo. undo 90% (with memory management but it doesn...
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Mon, 7 Nov 2011 10:21:48 +0000 (10:21 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Mon, 7 Nov 2011 10:21:48 +0000 (10:21 +0000)
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageModificationManager.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp

index 2b7f1401bf39bd0123633f38afb439d03ee1f8df..93efb5bd6752b03e74448dfa1a8f781ed1c6b69f 100755 (executable)
@@ -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;
 }
index 9f46cb2bbd68171847872da882ef7c3757bd2b7f..cdcdefb7ee7ee61abd2cd6a42f7a1dfbb9a4fbf0 100755 (executable)
@@ -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:
index ae2b970e58ebd86b49575e73cf2d2f85f0a51341..a97ee3d451e37c41481354d902ef3ce9c103c46d 100755 (executable)
@@ -21,6 +21,10 @@ void ImageDequeUR::CleanContainers() {
 
 }
 
+void ImageDequeUR::ManageMemory() {
+
+}
+
 ImageInfoUR* ImageDequeUR::Undo() {
        return NULL;
 }
index c66c75ba43fe9899143364a00a53a72fe61d6441..a20630aa8d844ef1a7fefc0d38179b7807a736b0 100755 (executable)
@@ -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();
 };
index bdbed3737e5d79dd2714fb5421a5a41284d73cbd..4857a7d1e7f3960e2a0d9626f3f495202cb96e01 100644 (file)
@@ -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);
 }
index 3e11b7e488806b9ead628a06551766833d9ec9f0..196d65eb552622012f2f3ee1a2199aa81ca79f7e 100644 (file)
@@ -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_ */
index 2f80bd6594ff3352d3a53f0e57b1eb5c917d7c88..dd9bcecf4d3e6233b5a2d79d754f38d075b9b374 100755 (executable)
@@ -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();
 }
 
index 78ff99b2e2497ec3f7d00d268ecaee68f10c4ff9..c06caa7c1369ac941b51b0ec5b67d79dd4ef81ca 100755 (executable)
@@ -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;
 
 };
index 75cb61de70a082a3046d295d87329f0c58af8af1..7c659ebc145075a2c374f1941ab717253c3e6a0e 100644 (file)
@@ -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];