From: Diego Caceres Date: Tue, 15 Nov 2011 08:31:39 +0000 (+0000) Subject: DFCH: ManualPaint + imageUndoRedo: Undo/Redo functionality its now working =) =) X-Git-Tag: v1.0.4~40 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c128e1b6226fcf4e036de57411dee1b7740c1627;p=creaMaracasVisu.git DFCH: ManualPaint + imageUndoRedo: Undo/Redo functionality its now working =) =) Project status = 90% - Management of temporary files (Its not working) - Documentation (0%) - Clean code (50%) God Job!! =) --- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx index d1d959d..c010cb9 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx @@ -3,7 +3,7 @@ #include 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; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h index 689a1d7..53e3e4a 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h @@ -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; diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx index 2137a71..7cc28e5 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx @@ -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); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp index ed3aba2..7c45bee 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp @@ -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(); }