]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: ManualPaint + imageUndoRedo: Undo/Redo functionality its now working =) =)
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Tue, 15 Nov 2011 08:31:39 +0000 (08:31 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Tue, 15 Nov 2011 08:31:39 +0000 (08:31 +0000)
Project status = 90%
- Management of temporary files (Its not working)
- Documentation (0%)
- Clean code (50%)
God Job!! =)

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/imageUndoRedo.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp

index d1d959d251faa709fb5cc9dd2728293ab9b615a3..c010cb9e69b28709e5081700c245eff657eb3fca 100755 (executable)
@@ -3,7 +3,7 @@
 #include <sstream>
 
 Image3DDequeUR::Image3DDequeUR() {
-       this->m_GlobalPath = "/home/pechan/temporal/";
+       this->m_GlobalPath = "/home/caceres/temporal/";
        this->m_CurrentURPos = -1;
 }
 //virtual
@@ -16,8 +16,7 @@ void Image3DDequeUR::AddImagesToURContainer(VTKImageDataPointerType imgUndo,
        this->CleanURContainerFromIndex(this->m_CurrentURPos + 1);
        //Adding image
        ImageInfoUR* imageInfo = new ImageInfoUR();
-       imageInfo->SetImageName(
-                       this->GetImageName(this->m_ImgURDeque.size(), true));
+       imageInfo->SetImageName(this->GetImageName(this->m_ImgURDeque.size()));
        imageInfo->SetImages(imgUndo, imgRedo);
        imageInfo->SetImageMManager(imMManager);
        //Adding to deque
@@ -29,7 +28,9 @@ void Image3DDequeUR::AddImagesToURContainer(VTKImageDataPointerType imgUndo,
 //virtual
 ImageInfoUR* Image3DDequeUR::Undo() {
        ImageInfoUR* imgRet = NULL;
-       if ((this->m_ImgURDeque.size() > 0) && (this->m_CurrentURPos != -1)) {
+       int imgURDequeSize = this->m_ImgURDeque.size();
+       if ((this->m_ImgURDeque.size() > 0) && (this->m_CurrentURPos != -1)
+                       && (this->m_CurrentURPos < imgURDequeSize)) {
                imgRet = this->m_ImgURDeque[m_CurrentURPos];
                this->m_CurrentURPos--;
        } //fi
@@ -39,6 +40,15 @@ ImageInfoUR* Image3DDequeUR::Undo() {
 //virtual
 ImageInfoUR* Image3DDequeUR::Redo() {
        ImageInfoUR* imgRet = NULL;
+       this->m_CurrentURPos++;
+       int imgURDequeSize = this->m_ImgURDeque.size();
+       if ((this->m_ImgURDeque.size() > 0) && (this->m_CurrentURPos != -1)
+                       && (this->m_CurrentURPos < imgURDequeSize)) {
+               imgRet = this->m_ImgURDeque[m_CurrentURPos];
+       } //fi
+       else {
+               this->m_CurrentURPos--;
+       }
        return (imgRet);
 }
 //virtual
@@ -56,7 +66,8 @@ void Image3DDequeUR::CleanURContainerFromIndex(const int& index) {
 
 //virtual
 void Image3DDequeUR::ManageMemory() {
-       for (int i = 0; (unsigned int) i < this->m_ImgURDeque.size(); i++) {
+       int imgURDequeSize = this->m_ImgURDeque.size();
+       for (int i = 0; i < imgURDequeSize; i++) {
                if (this->m_ImgURDeque[i]->GetStatus()) {
                        this->m_ImgURDeque[i]->RemoveImagesFromMemory(this->m_GlobalPath);
                } //fi
@@ -67,6 +78,12 @@ void Image3DDequeUR::ManageMemory() {
                this->m_ImgURDeque[this->m_CurrentURPos]->LoadImagesToMemory(
                                this->m_GlobalPath);
        }
+       int currentRedoPos = this->m_CurrentURPos + 1;
+       if ((currentRedoPos < imgURDequeSize)
+                       && !(this->m_ImgURDeque[currentRedoPos]->GetStatus())) {
+               this->m_ImgURDeque[currentRedoPos]->LoadImagesToMemory(
+                               this->m_GlobalPath);
+       }
 }
 
 void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) {
@@ -83,8 +100,7 @@ Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath() {
        return (this->m_GlobalPath);
 }
 
-Image3DDequeUR::StringType Image3DDequeUR::GetImageName(const int & pos,
-               const bool& undo) {
+Image3DDequeUR::StringType Image3DDequeUR::GetImageName(const int & pos) {
 //Giving a name to an image using the date and time
        if (this->m_IDImages.empty()) {
                time_t rawtime;
index 689a1d7002a87f599b7b557963c858584630d4b3..53e3e4a0cf18bb2bcbe4c4f603b27ffab94b5351 100755 (executable)
@@ -23,7 +23,7 @@ public:
        virtual ImageInfoUR* Redo();
        void SetGlobalPath(const StringType& globalPath);
        StringType GetGlobalPath();
-       StringType GetImageName(const int & pos, const bool& undo);
+       StringType GetImageName(const int & pos);
        void CleanHardDisk();
 protected:
        ImageInfoDeque m_ImgURDeque;
index 2137a713e5d4fcd57277cf17a94598dfcba30bea..7cc28e581fffdbc62336b41e51f9e950192b1ec5 100755 (executable)
@@ -18,18 +18,17 @@ ImageUndoRedo::~ImageUndoRedo() {
 void ImageUndoRedo::Undo() {
        ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
        if (imageInfo != NULL) {
-               //this->SetRedoImage(imageInfo->GetImageMManager());
                this->DrawUR(imageInfo, true);
                this->UpdateUndoImage();
        }
 }
 //virtual
 void ImageUndoRedo::Redo() {
-       /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
-        if (imageInfo != NULL)
-        {
-        this->DrawUR(imageInfo);
-        }*/
+       ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
+       if (imageInfo != NULL) {
+               this->DrawUR(imageInfo, false);
+               this->UpdateUndoImage();
+       }
 }
 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
        this->m_CurrentImage = image;
@@ -66,7 +65,7 @@ ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
        extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
                        region.minZ, region.maxZ);
        extract->SetSampleRate(1, 1, 1);
-       extract->SetInput(this->m_UndoImage);
+       extract->SetInput(img);
        VTKImageDataPointerType imgResult = extract->GetOutput();
        imgResult->Update();
        return (imgResult);
index ed3aba2477bad42c9eb01913c6b5341ff8ce431c..7c45bee86fc82ca40c259f929f36b3659bbc5bd0 100644 (file)
@@ -4,7 +4,7 @@ ManualPaintModel::ManualPaintModel() {
        _tool = 0; // 0 pencil         ,   1 fill
        _brushfilter = new BrushFilter();
        _fillfilter = new FillFilter();
-       //_imageUndoRedo = new ImageUndoRedo();
+       _imageUndoRedo = new ImageUndoRedo();
 }
 
 //---------------------------------------------------------------------------
@@ -40,7 +40,7 @@ void ManualPaintModel::Set2D3D(int dim2D3D) {
 void ManualPaintModel::SetImage(vtkImageData *image) {
        _brushfilter->SetImage(image);
        _fillfilter->SetImage(image);
-       //_imageUndoRedo->SetImage(image);
+       _imageUndoRedo->SetImage(image);
 }
 
 //---------------------------------------------------------------------------
@@ -92,7 +92,7 @@ void ManualPaintModel::GetScalarRange(double * range) {
 }
 //---------------------------------------------------------------------------
 void ManualPaintModel::SetUndoImage() {
-       /*ImageMManager* imMManager = NULL;
+       ImageMManager* imMManager = NULL;
         if (_tool == 0) {
         imMManager = this->_brushfilter->GetImageMManager();
         }
@@ -101,14 +101,14 @@ void ManualPaintModel::SetUndoImage() {
         }
         this->_imageUndoRedo->SetURImages(imMManager);
         this->_brushfilter->CleanImageMManager();
-        this->_fillfilter->CleanImageMManager();*/
+        this->_fillfilter->CleanImageMManager();
 }
 //---------------------------------------------------------------------------
 
 void ManualPaintModel::Undo() {
-       //this->_imageUndoRedo->Undo();
+       this->_imageUndoRedo->Undo();
 }
 
 void ManualPaintModel::Redo() {
-       //this->_imageUndoRedo->Redo();
+       this->_imageUndoRedo->Redo();
 }