]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: ManualPaint- imageUNDOREDO (Undo now working but still some big changes to...
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Tue, 8 Nov 2011 16:38:50 +0000 (16:38 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Tue, 8 Nov 2011 16:38:50 +0000 (16:38 +0000)
12 files changed:
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/imageInfoUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/managerUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.cpp
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/wxManualPaintPanel.h

index d24c809cd3da16102cb71b97bdcad5167331c336..41d7c56ec0b673f7a0d54b7066c55d1a2957dc8d 100755 (executable)
@@ -14,6 +14,7 @@ Image3DDequeUR::~Image3DDequeUR() {
 //virtual
 void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img,
                ImageMManagerType* imMManager) {
+       this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos + 1);
        //Adding image
        ImageInfoUR* imageInfo = new ImageInfoUR();
        imageInfo->SetImageName(
@@ -25,6 +26,8 @@ void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img,
        this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1;
        //Managing memory
        this->ManageMemory();
+       //clean redo container
+       this->CleanRedoContainer();
 }
 //virtual
 ImageInfoUR* Image3DDequeUR::Undo() {
@@ -38,11 +41,27 @@ ImageInfoUR* Image3DDequeUR::Undo() {
 //virtual
 void Image3DDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img,
                ImageMManagerType* imMManager) {
+       //Adding image
+       ImageInfoUR* imageInfo = new ImageInfoUR();
+       imageInfo->SetImageName(
+                       this->GetImageName(this->m_ImgRedoDeque.size(), false));
+       imageInfo->SetImage(img);
+       imageInfo->SetImageMManager(imMManager);
+       //Adding to deque
+       this->m_ImgRedoDeque.push_back(imageInfo);
+       this->m_CurrentRedoPos = this->m_ImgRedoDeque.size() - 1;
+       //Managing memory
+       this->ManageMemory();
+
 }
 //virtual
 ImageInfoUR* Image3DDequeUR::Redo() {
-
-       ImageInfoUR* imgRet = new ImageInfoUR();
+       ImageInfoUR* imgRet = NULL;
+       if ((this->m_ImgRedoDeque.size() > 0) && (this->m_CurrentRedoPos != -1)) {
+               imgRet = this->m_ImgRedoDeque[m_CurrentRedoPos];
+               this->m_CurrentRedoPos--;
+               this->m_CurrentUndoPos++;
+       } //fi
        return (imgRet);
 }
 //virtual
@@ -56,10 +75,13 @@ void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) {
        for (int i = 0; i < count; i++) {
                this->m_ImgUndoDeque.pop_back();
        } //rof
-
 }
 //virtual
-void Image3DDequeUR::CleanRedoContainerFromIndex(const int& index) {
+void Image3DDequeUR::CleanRedoContainer() {
+       for (unsigned int i = 0; i < this->m_ImgRedoDeque.size(); i++) {
+               this->m_ImgRedoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath);
+               this->m_ImgRedoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath);
+       }
 }
 //virtual
 void Image3DDequeUR::CleanContainers() {
@@ -89,6 +111,17 @@ void Image3DDequeUR::ManageMemory() {
                                this->m_GlobalPath);
        }
        //The same for the redo queue
+       for (int i = 0; (unsigned int) i < this->m_ImgRedoDeque.size(); i++) {
+               if (this->m_ImgRedoDeque[i]->GetStatus()) {
+                       this->m_ImgRedoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath);
+               } //fi
+       } //rof
+         //Adding CurrentUndoPos to memory
+       if ((this->m_CurrentRedoPos != -1)
+                       && !(this->m_ImgRedoDeque[this->m_CurrentRedoPos]->GetStatus())) {
+               this->m_ImgRedoDeque[this->m_CurrentRedoPos]->LoadImageMHDToMemory(
+                               this->m_GlobalPath);
+       }
 }
 
 void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) {
@@ -128,6 +161,5 @@ Image3DDequeUR::StringType Image3DDequeUR::GetImageName(const int & pos,
                imgType = "redo";
        }
        StringType imageName = this->m_IDImages + imgType + ss.str();
-       imageName.append(".mhd");
        return (imageName);
 }
index dd861b2f998981342378675e0a09fa161000e719..718b4e20ab597c2d6e418ba35eca8eadaf2bcbb2 100755 (executable)
@@ -24,7 +24,7 @@ public:
        virtual void AddImageToRedoContainer(VTKImageDataPointerType img,
                        ImageMManagerType* imMManager);
        virtual void CleanUndoContainerFromIndex(const int& index);
-       virtual void CleanRedoContainerFromIndex(const int& index);
+       virtual void CleanRedoContainer);
        virtual void CleanContainers();
        virtual void ManageMemory();
        virtual ImageInfoUR* Undo();
index a97ee3d451e37c41481354d902ef3ce9c103c46d..a51a77d26f4b8ae868c51c11df7c9a7476f8b74a 100755 (executable)
@@ -15,7 +15,7 @@ void ImageDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img,
 void ImageDequeUR::CleanUndoContainerFromIndex(const int& index) {
 
 }
-void ImageDequeUR::CleanRedoContainerFromIndex(const int& index) {
+void ImageDequeUR::CleanRedoContainer) {
 }
 void ImageDequeUR::CleanContainers() {
 
index b7b852267fd0833b8e1f4da4458b9be44105a8b4..a5660b6108afc67e625b4a15963e08afc710ef3a 100755 (executable)
@@ -31,7 +31,7 @@ public:
        virtual void AddImageToRedoContainer(VTKImageDataPointerType img,
                        ImageMManager* imMManager);
        virtual void CleanUndoContainerFromIndex(const int& index);
-       virtual void CleanRedoContainerFromIndex(const int& index);
+       virtual void CleanRedoContainer();
        virtual void CleanContainers();
        virtual void ManageMemory();
        virtual ImageInfoUR* Undo();
index 263bce86e31e90fed1592bef4f245f485f92bedb..c00e9725c8838d6ff4ecf72f2b58350f59a5de8b 100755 (executable)
@@ -50,6 +50,7 @@ void ImageInfoUR::RemoveImageFromMemory(const StringType& gPath) {
 }
 void ImageInfoUR::LoadImageMHDToMemory(const StringType& gPath) {
        StringType filename = gPath + this->m_ImageName;
+       filename.append(".mhd");
        VTKMetaImageReaderPointerType reader = VTKMetaImageReaderPointerType::New();
        reader->SetFileName(filename.c_str());
        this->m_Image = reader->GetOutput();
@@ -59,6 +60,7 @@ void ImageInfoUR::LoadImageMHDToMemory(const StringType& gPath) {
 void ImageInfoUR::SaveImageAsMHD(const StringType& gPath) {
        this->m_OnDisk = true;
        StringType filename = gPath + this->m_ImageName;
+       filename.append(".mhd");
        //managing temporary files
        mkstemp((char*) filename.c_str());
        VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
@@ -70,8 +72,11 @@ void ImageInfoUR::SaveImageAsMHD(const StringType& gPath) {
 }
 
 void ImageInfoUR::RemoveImageFromDisk(const StringType& gPath) {
-       std::cout << "Borrando archivo" << endl;
        StringType filename = gPath + this->m_ImageName;
-       std::cout << filename << std::endl;
+       filename.append(".mhd");
+       StringType filenameRaw = gPath + this->m_ImageName;
+       filenameRaw.append(".raw");
+       mkstemp((char*) filenameRaw.c_str());
        unlink((char*) filename.c_str());
+       unlink((char*) filenameRaw.c_str());
 }
index dd9bcecf4d3e6233b5a2d79d754f38d075b9b374..bf524449210ba8fbfb52bd3bb26f211cce39ca59 100755 (executable)
@@ -19,14 +19,18 @@ void ImageUndoRedo::Undo() {
        ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
        if (imageInfo != NULL)
        {
-               //this->SetRedoImage(imageInfo->GetRegion());
+               //this->SetRedoImage(imageInfo->GetImageMManager());
                this->DrawUR(imageInfo);
                this->UpdateUndoImage();
        }
 }
 //virtual
 void ImageUndoRedo::Redo() {
-
+       /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
+       if (imageInfo != NULL)
+       {
+               this->DrawUR(imageInfo);
+       }*/
 }
 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
        this->m_CurrentImage = image;
@@ -48,11 +52,19 @@ void ImageUndoRedo::SetUndoImage(ImageMManagerType* imMManager) {
        }
 }
 //virtual
-void ImageUndoRedo::SetRedoImage(const ImageMManagerType* imMManager) {
-       /*RegionSType region = imMManager.GetModifiedRegion();
-        VTKImageDataPointerType imgResult = this->ImageMManagerType(region,
-        this->m_CurrentImage);
-        this->m_ImagesDeque->AddImageToRedoContainer(imgResult, imMManager);*/
+void ImageUndoRedo::SetRedoImage(ImageMManagerType* imMManager) {
+       /*this->m_CurrentImage->Update();
+       ImageMManagerType* newImageManager = new ImageMManagerType(imMManager);
+       if (newImageManager->ValidateRegion()) {
+               RegionSType region = newImageManager->GetModifiedRegion();
+               VTKImageDataPointerType imgResult = this->GetImageRegion(region,
+                               this->m_CurrentImage);
+               this->m_ImagesDeque->AddImageToRedoContainer(imgResult,
+                               newImageManager);
+               imgResult->Update();
+       } else {
+               std::cerr << "INVALID REGION" << std::endl;
+       }*/
 }
 
 void ImageUndoRedo::UpdateUndoImage() {
index c06caa7c1369ac941b51b0ec5b67d79dd4ef81ca..d426d6f46c5d3b6aa27f39c22ab1ee6c46c894cd 100755 (executable)
@@ -18,7 +18,7 @@ public:
        virtual void Redo();
        virtual void SetImage(VTKImageDataPointerType image);
        virtual void SetUndoImage(ImageMManagerType* imMManager);
-       virtual void SetRedoImage(const ImageMManagerType* imMManager);
+       virtual void SetRedoImage(ImageMManagerType* imMManager);
        void UpdateUndoImage();
        void SetCurrentImage(VTKImageDataPointerType img);
        VTKImageDataPointerType GetImageRegion(const RegionSType& region,
index afd33b6ee5895e53c4a0ba0a1ffe3038961d1fd5..289662f04307f424600c938496005d7c0445973a 100755 (executable)
@@ -25,7 +25,7 @@ void ManagerUR::Redo() {
 void ManagerUR::SetUndoImage(ImageMManagerType* imMManager) {
 
 }
-void ManagerUR::SetRedoImage(ImageMManagerType* imMManager) {
+void ManagerUR::SetRedoImage(ImageMManagerType* imMManager){
 
 }
 void ManagerUR::DrawUR(ImageInfoUR imageInfo) {
index eec9a1ba950f10f90f6d2911e20d82f130cca1a9..6414f887227c789aa2de213d1f1a6abd6ddb9c0a 100644 (file)
@@ -108,3 +108,7 @@ void ManualPaintModel::SetUndoImage() {
 void ManualPaintModel::Undo() {
        this->_imageUndoRedo->Undo();
 }
+
+void ManualPaintModel::Redo() {
+       this->_imageUndoRedo->Redo();
+}
index 06d3142db77f6e26ce60888d6dd550c0beab7f52..55694ac4baf6064b94143b3f7e39bf140dfa7684 100644 (file)
@@ -26,6 +26,7 @@ public:
        void GetScalarRange(double * range);
        void SetUndoImage(); //DFCH
        void Undo(); //DFCH
+       void Redo(); //DFCH
 
 private:
        int _tool;
index 7c659ebc145075a2c374f1941ab717253c3e6a0e..ae063ce07ea340aeb4a085175a382c76ce89d8ac 100644 (file)
@@ -79,6 +79,7 @@ wxManualPaintPanel::wxManualPaintPanel(wxWindow * parent) :
        wxButton *btnCopy = new wxButton(panel, -1, _T("Copy"));
        btnCopy->Disable();
        wxButton *btnUndo = new wxButton(panel, -1, _T("Undo"));
+       wxButton *btnRedo = new wxButton(panel, -1, _T("Redo"));
        //btnUndo->Disable();
 
        Connect(
@@ -139,14 +140,19 @@ Connect   (
                        btnCopy->GetId(),
                        wxEVT_COMMAND_BUTTON_CLICKED,
                        (wxObjectEventFunction) (void(wxPanel::*)(
-                                       wxCommandEvent&)) &wxManualPaintPanel::OnCopy);Connect
-       (
+                                       wxCommandEvent&)) &wxManualPaintPanel::OnCopy);
+
+Connect        (
                        btnUndo->GetId(),
                        wxEVT_COMMAND_BUTTON_CLICKED,
                        (wxObjectEventFunction) (void(wxPanel::*)(
-                                       wxCommandEvent&)) &wxManualPaintPanel::OnUndo);
+                                       wxCommandEvent&)) &wxManualPaintPanel::OnUndo);this
+       ->Connect(btnRedo->GetId(),
+                       wxEVT_COMMAND_BUTTON_CLICKED,
+                       (wxObjectEventFunction) (void(wxPanel::*)(
+                                                       wxCommandEvent&)) &wxManualPaintPanel::OnRedo); //DFCH
 
-Connect        (
+       Connect(
                        _mBarSlices->GetId(),
                        wxEVT_TSBAR,
                        (wxObjectEventFunction) (wxCommandEventFunction) &wxManualPaintPanel::onBarrange);
@@ -215,6 +221,7 @@ Connect     (
        sizer1->Add(btnCopy, 1, wxGROW);
        sizer1->Add(new wxStaticText(panel, -1, _T("  ")));
        sizer1->Add(btnUndo, 1, wxGROW);
+       sizer1->Add(btnRedo, 1, wxGROW);
 
        sizer = sizer1;
        panel->SetSizer(sizer);
@@ -343,6 +350,11 @@ void wxManualPaintPanel::OnUndo(wxCommandEvent &event) {
        this->_manualPaintModel->Undo();
 }
 
+//---------------------------------------------------------------------------
+void wxManualPaintPanel::OnRedo(wxCommandEvent &event) {
+       this->_manualPaintModel->Redo();
+}
+
 //--------------------------------------------------------------------------------------------------------------------------------
 // Min-Max Barrange received events
 //--------------------------------------------------------------------------------------------------------------------------------
index 909759870ca012ede8fc3dad2beb40ad3d227517..f31216e8973760f6bc4cbc6896deea9b5e3fb2a3 100644 (file)
@@ -3,68 +3,62 @@
 
 #include "ManualPaintPanel.h"
 
-
 #include "mBarRange.h" //DFCH
 #include "creaWx.h" //DFCH
-
 #include <wx/wx.h>
 #include <wx/panel.h>
 
-class wxManualPaintPanel : public wxPanel , public ManualPaintPanel {
+class wxManualPaintPanel: public wxPanel, public ManualPaintPanel {
 public:
        wxManualPaintPanel(wxWindow * parent);
        virtual ~wxManualPaintPanel();
-    void OnBrushSize(wxScrollEvent& event);
-    void OnSldGrayLevel(wxScrollEvent& event);
-    void OnCtrTxtGrayLevel(wxCommandEvent &event);
-    void On2D3D(wxCommandEvent &event);
-    void OnBrushForm(wxCommandEvent &event);
-    void OnBrushTool(wxCommandEvent &event);
-    void OnCopy(wxCommandEvent &event);
-    void OnUndo(wxCommandEvent &event);
-    void DisableControls();
-    void OnSldToleranceFill(wxScrollEvent& event);
-    void OnCtrTxtToleranceFill(wxCommandEvent &event);
-    void OnSldDistanceFill(wxScrollEvent& event);
-    void OnCtrTxtDistanceFill(wxCommandEvent &event);
-    //This method changes the min/max in the Selected Range Widget
-    //--------------------------------------------------------------------------------------------------------------------------------
-    // Min-Max Barrange received events
-     //--------------------------------------------------------------------------------------------------------------------------------
-    void onBarrange(wxCommandEvent& event);
-    void onActualChange_Bar(wxCommandEvent& event);
-    void onStartChange_Bar(wxCommandEvent& event);
-    void onEndChange_Bar(wxCommandEvent& event);
-    void onSelectionEnd(wxCommandEvent& event);
-    void onMovedBar(wxCommandEvent& event);
+       void OnBrushSize(wxScrollEvent& event);
+       void OnSldGrayLevel(wxScrollEvent& event);
+       void OnCtrTxtGrayLevel(wxCommandEvent &event);
+       void On2D3D(wxCommandEvent &event);
+       void OnBrushForm(wxCommandEvent &event);
+       void OnBrushTool(wxCommandEvent &event);
+       void OnCopy(wxCommandEvent &event);
+       void OnUndo(wxCommandEvent &event);
+       void OnRedo(wxCommandEvent &event);
+       void DisableControls();
+       void OnSldToleranceFill(wxScrollEvent& event);
+       void OnCtrTxtToleranceFill(wxCommandEvent &event);
+       void OnSldDistanceFill(wxScrollEvent& event);
+       void OnCtrTxtDistanceFill(wxCommandEvent &event);
+       //This method changes the min/max in the Selected Range Widget
+       //--------------------------------------------------------------------------------------------------------------------------------
+       // Min-Max Barrange received events
+       //--------------------------------------------------------------------------------------------------------------------------------
+       void onBarrange(wxCommandEvent& event);
+       void onActualChange_Bar(wxCommandEvent& event);
+       void onStartChange_Bar(wxCommandEvent& event);
+       void onEndChange_Bar(wxCommandEvent& event);
+       void onSelectionEnd(wxCommandEvent& event);
+       void onMovedBar(wxCommandEvent& event);
 
 private:
-    wxStaticText    *_txtBrushSize;
-    wxSlider        *_sldBrushSize;
-
-    wxSlider        *_sldGrayLevel;
-    wxTextCtrl      *_graylevelCtrl;
-    wxRadioBox      *_rbBrushForm;
-    wxRadioBox      *_rb2D3D;
-    wxRadioBox      *_rbBrushTool;
-
-    wxStaticText    *_txtToleranceFill;
-    wxSlider        *_sldToleranceFill;
-    wxTextCtrl      *_tolerancefillCtrl;
-
-       wxStaticText    *_txtDistanceFill;
-    wxSlider        *_sldDistanceFill;
-    wxTextCtrl      *_distancefillCtrl;
-
-    mBarRange * _mBarSlices; //DFCH
+       wxStaticText *_txtBrushSize;
+       wxSlider *_sldBrushSize;
 
+       wxSlider *_sldGrayLevel;
+       wxTextCtrl *_graylevelCtrl;
+       wxRadioBox *_rbBrushForm;
+       wxRadioBox *_rb2D3D;
+       wxRadioBox *_rbBrushTool;
 
+       wxStaticText *_txtToleranceFill;
+       wxSlider *_sldToleranceFill;
+       wxTextCtrl *_tolerancefillCtrl;
 
+       wxStaticText *_txtDistanceFill;
+       wxSlider *_sldDistanceFill;
+       wxTextCtrl *_distancefillCtrl;
 
+       mBarRange * _mBarSlices; //DFCH
 
 protected:
 
 };
 
-
 #endif // _WX_MANUAL_PAINT_PANEL_H_