]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: imageUndoRedo beta1 (Undo Working - problems saving to disk)
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Fri, 28 Oct 2011 12:47:32 +0000 (12:47 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Fri, 28 Oct 2011 12:47:32 +0000 (12:47 +0000)
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx

index a497b1673450b0e029bfc3041b8c1a89704acf3f..22224c51493b13d508d55d27dbe7e4e34a63d828 100755 (executable)
@@ -14,42 +14,38 @@ Image3DDequeUR::~Image3DDequeUR() {
 //virtual
 void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img,
                const RegionS& region) {
-       //managing memory
-       if (this->m_ImgUndoDeque.size() > 0) {
-        this->m_ImgUndoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
-        } //fi
        //Adding image
        ImageInfoUR* imageInfo = new ImageInfoUR();
        imageInfo->SetImageName(
                        this->GetImageName(this->m_ImgUndoDeque.size(), true));
        imageInfo->SetImage(img);
        imageInfo->SetRegion(region);
+       ///---------------------------------------------------------------------------------------------------
+       // Uncoment the following line
        imageInfo->SaveImageAsMHD(this->m_GlobalPath);
-       //cleaning deque from current position
-       this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos + 1);
-       this->CleanRedoContainerFromIndex(0);
-       this->m_ImgRedoDeque.clear();
+       ///------------------------------------------------------------------------------------------------
        //Adding to deque
        this->m_ImgUndoDeque.push_back(imageInfo);
        this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1;
 }
 //virtual
+ImageInfoUR* Image3DDequeUR::Undo() {
+       ImageInfoUR* imgRet = NULL;
+       if ((this->m_ImgUndoDeque.size() > 0) && (this->m_CurrentUndoPos != -1)) {
+               imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos];
+               this->m_CurrentUndoPos--;
+       } //fi
+       return (imgRet);
+}
+//virtual
 void Image3DDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img,
                const RegionS& region) {
-       //managing memory
-       /*if (this->m_ImgRedoDeque.size() > 0) {
-               this->m_ImgRedoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
-       } //fi
-         //adding image
-       ImageInfoUR* imageInfo = new ImageInfoUR();
-       imageInfo->SetImageName(
-                       this->GetImageName(this->m_ImgRedoDeque.size(), false));
-       imageInfo->SetImage(img);
-       imageInfo->SetRegion(region);
-       imageInfo->SaveImageAsMHD(this->m_GlobalPath);
-       //Adding to deque
-       this->m_ImgRedoDeque.push_back(imageInfo);
-       this->m_CurrentUndoPos = this->m_ImgRedoDeque.size() - 1;*/
+}
+//virtual
+ImageInfoUR* Image3DDequeUR::Redo() {
+
+       ImageInfoUR* imgRet = new ImageInfoUR();
+       return (imgRet);
 }
 //virtual
 void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) {
@@ -67,64 +63,6 @@ void Image3DDequeUR::CleanRedoContainerFromIndex(const int& index) {
                this->m_ImgRedoDeque.pop_back();
        }
 }
-
-//virtual
-ImageInfoUR* Image3DDequeUR::Undo() {
-       ImageInfoUR* imgRet = NULL;
-       if ((this->m_ImgUndoDeque.size() > 0) && (this->m_CurrentUndoPos != -1)) {
-               std::cout<<"Controooool"<<std::endl;
-               //removing from memory
-               if ((this->m_CurrentUndoPos + 1) < this->m_ImgUndoDeque.size()) {
-                this->m_ImgUndoDeque[(m_CurrentUndoPos + 1)]->RemoveImageFromMemory(
-                this->m_GlobalPath);
-                } //fi
-               imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos];
-               std::cout << "imageName:  " << imgRet->GetImageName() << std::endl;
-               this->m_CurrentUndoPos--;
-               //adding to memory
-               if (this->m_CurrentUndoPos != -1) {
-                       //Loading image
-                       StringType fullPath = this->m_GlobalPath
-                                       + this->m_ImgUndoDeque[m_CurrentUndoPos]->GetImageName();
-                       this->m_ImgUndoDeque[m_CurrentUndoPos]->LoadImageMHDToMemory(
-                                       this->m_GlobalPath);
-               } //fi
-       } //fi
-       return (imgRet);
-}
-//virtual
-ImageInfoUR* Image3DDequeUR::Redo() {
-
-       ImageInfoUR* imgRet = new ImageInfoUR();
-       //managing undo deque
-       if (this->m_ImgUndoDeque.size() > 0) {
-               if ((m_CurrentUndoPos - 1) != -1) {
-                       this->m_ImgUndoDeque[m_CurrentUndoPos - 1]->RemoveImageFromMemory(
-                                       this->m_GlobalPath);
-               } //fi
-               this->m_CurrentUndoPos++; //ready to do undo
-               if (this->m_CurrentUndoPos < ((int) this->m_ImgUndoDeque.size())) {
-                       this->m_ImgUndoDeque[m_CurrentUndoPos]->LoadImageMHDToMemory(
-                                       this->m_GlobalPath);
-               } //fi
-                 //end of undo management
-       } //fi
-         //managing redo
-       if ((this->m_ImgRedoDeque.size() > 0) && (this->m_CurrentRedoPos != -1)) {
-               if ((this->m_CurrentRedoPos + 1) < this->m_ImgRedoDeque.size()) {
-                       this->m_ImgRedoDeque[(m_CurrentRedoPos + 1)]->RemoveImageFromMemory(
-                                       this->m_GlobalPath);
-               } //fi
-               imgRet = this->m_ImgRedoDeque[this->m_CurrentRedoPos];
-               this->m_CurrentRedoPos--;
-               if (this->m_CurrentRedoPos != -1) {
-                       this->m_ImgRedoDeque[m_CurrentRedoPos]->LoadImageMHDToMemory(
-                                       this->m_GlobalPath);
-               } //fi
-                 //end of redo management
-       }
-       return (imgRet);
-}
 //virtual
 void Image3DDequeUR::CleanContainers() {
        for (unsigned int i = 0; i < this->m_ImgUndoDeque.size(); i++) {
index 8864148e34df0ea8c7962e50bd881635c88a5776..55a4e1f24b9fc907f100e6396a65247d05ab75f2 100755 (executable)
@@ -19,7 +19,7 @@ void ImageUndoRedo::Undo() {
        ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
        if (imageInfo != NULL)
        {
-               this->SetRedoImage(imageInfo->GetRegion());
+               //this->SetRedoImage(imageInfo->GetRegion());
                this->DrawUR(imageInfo);
        }
 }
@@ -68,18 +68,21 @@ void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
 //virtual
 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
        VTKImageDataPointerType img = imageInfo->GetImage();
-       for (int i = imageInfo->GetRegion().minX, x = 0;
-                       i <= imageInfo->GetRegion().maxX; i++, x++) {
-               for (int j = imageInfo->GetRegion().minY, y = 0;
-                               j <= imageInfo->GetRegion().maxY; j++, y++) {
-                       for (int k = imageInfo->GetRegion().minZ, z = 0;
-                                       k <= imageInfo->GetRegion().maxZ; k++, z++) {
-                               float value = img->GetScalarComponentAsFloat(i, j, k, 0);
-                               this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k, 0,
-                                               value);
+       if( img != NULL )
+       {
+               for (int i = imageInfo->GetRegion().minX, x = 0;
+                               i <= imageInfo->GetRegion().maxX; i++, x++) {
+                       for (int j = imageInfo->GetRegion().minY, y = 0;
+                                       j <= imageInfo->GetRegion().maxY; j++, y++) {
+                               for (int k = imageInfo->GetRegion().minZ, z = 0;
+                                               k <= imageInfo->GetRegion().maxZ; k++, z++) {
+                                       float value = img->GetScalarComponentAsFloat(i, j, k, 0);
+                                       this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k, 0,
+                                                       value);
+                               } //rof
                        } //rof
                } //rof
-       } //rof
-       this->m_CurrentImage->Modified();
+               this->m_CurrentImage->Modified();
+       }
 }