]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: Undo/Redo 65% :) :) Tener cuidado con el manejo de la pila :)
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Wed, 28 Sep 2011 09:08:26 +0000 (09:08 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Wed, 28 Sep 2011 09:08:26 +0000 (09:08 +0000)
CMakeLists.txt
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/image3DDequeUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/image3DDequeUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/imageDequeUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/imageInfoUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/imageInfoUR.h

index 8cac05722c236e1127c567cfcedbcc1ee134b960..0f417366128f1685e21f123d2c4e2006413178a2 100644 (file)
@@ -29,6 +29,14 @@ FIND_PACKAGE(crea REQUIRED)
 IF (crea_FOUND)
   INCLUDE(${crea_USE_FILE})
 ENDIF(crea_FOUND)
+
+#==================================
+FIND_PACKAGE(creaImageIO REQUIRED)
+IF (creaImageIO_FOUND)
+  INCLUDE(${creaImageIO_USE_FILE})
+ENDIF(creaImageIO_FOUND)
+#==================================
+
 CREA_PREVENT_IN_SOURCE_BUILD()
 
 #SET(USE_GDCM ON)
index 38b6fa2d9d4a0e4353cbbd664847aecf337079c8..c5c4e221a6e15509d9402a538c9c0dc84d4e1c8c 100644 (file)
@@ -1,7 +1,8 @@
 #include "image3DDequeUR.h"
 
 Image3DDequeUR::Image3DDequeUR() {
-       this->m_currentPos = 0;
+       this->m_globalPath = "/tmp/";
+       this->m_currentPos = -1;
 }
 //virtual
 Image3DDequeUR::~Image3DDequeUR() {
@@ -10,19 +11,78 @@ Image3DDequeUR::~Image3DDequeUR() {
 //virtual
 void Image3DDequeUR::addImageToContainer(ImageType* img,
                const RegionS& region) {
+       //managing memory
+       if (this->m_ImgDeque.size() > 0) {
+               this->m_ImgDeque.back().removeImageFromMemory();
+               this->m_ImgDeque.back().setStatus(false);
+       } //fi
+         //This is to take actual Date
+       time_t rawtime;
+       struct tm * timeinfo;
+       char buffer[80];
+       time(&rawtime);
+       timeinfo = localtime(&rawtime);
+       strftime(buffer, 80, "%a_%d_%b_%y_%H_%M_S", timeinfo);
+       std::string date(buffer);
+       //end
+       std::string aux(buffer);
+       std::string imageName = "img_" + aux;
+       ImageInfoUR imageInfo;
+       imageInfo.setImageName(imageName);
+       imageInfo.setImage(img);
+       imageInfo.setRegion(region);
+       imageInfo.setStatus(true);
+       //saving to disk
+       std::string fullpath = this->m_globalPath + imageName;
+       this->saveImageAsMHD(img, fullpath);
+       //Adding to deque
+       this->m_ImgDeque.push_back(imageInfo);
+       this->m_currentPos = this->m_ImgDeque.size() - 1;
+
 }
 //virtual
-void Image3DDequeUR::loadImageToPMemory() {
+void Image3DDequeUR::loadImageToPMemory(const unsigned int& index) {
+       creaImageIO::ImageReader reader;
+       std::string fullPath = this->m_globalPath
+                       + this->m_ImgDeque[index].getImageName();
+       this->m_ImgDeque[index].setImage(reader.ReadImage(fullPath));
 }
 //virtual
-void Image3DDequeUR::removeImageFromPMemory() {
-
+void Image3DDequeUR::removeImageFromPMemory(const unsigned int& index) {
+       this->m_ImgDeque[index].removeImageFromMemory();
 }
+//virtual
+void Image3DDequeUR::saveImageAsMHD(ImageType* img,
+               const std::string& filename) {
+       vtkMetaImageWriter* w = vtkMetaImageWriter::New();
+       w->SetInput(img);
+       w->SetCompression(false);
+       w->SetFileDimensionality(img->GetDataDimension());
+       w->SetFileName(filename.c_str());
+       w->Update();
+       w->Write();
+       w->Delete();
+}
+
+//ATENCIIIOOOON TIENE QUE HACER POP PARA PONER EL REDO
+//virtual
 ImageType* Image3DDequeUR::undo() {
-       return NULL;
+       if (this->m_currentPos == -1) {
+               return NULL;
+       } //fi
+       this->m_currentPos--;
+       return (NULL);
 }
+//virtual
 ImageType* Image3DDequeUR::redo() {
-       return NULL;
+       if (this->m_currentPos ==  ( this->m_ImgDeque.size() - 1 )) {
+               return NULL;
+       } //fi
+       this->m_currentPos++;
+       return (NULL);
+}
+void Image3DDequeUR::setGlobalPath(const std::string& globalPath) {
+       this->m_globalPath = globalPath;
 }
 void Image3DDequeUR::removeFirstImageFromContainer() {
        this->m_ImgDeque.pop_front();
@@ -34,7 +94,10 @@ void Image3DDequeUR::cleanContainer() {
        this->m_ImgDeque.clear();
 }
 void Image3DDequeUR::cleanContainerFromIndex(const unsigned int& index) {
-       for (int i = this->m_ImgDeque.size(); i >= index; i--) {
+       for (unsigned int i = this->m_ImgDeque.size(); i >= index; i--) {
                this->m_ImgDeque.pop_back();
        }
 }
+std::string Image3DDequeUR::getGlobalPath() {
+       return (this->m_globalPath);
+}
index f62aacac9ee022a3cd41cf305d3e921c42223ac5..db9a2232246fb554df8145ce1a2f3085fd310ec9 100644 (file)
@@ -9,23 +9,30 @@
 #define IMAGE3DDEQUEUR_H_
 
 #include "imageDequeUR.h"
+#include <ctime>
+#include "vtkMetaImageWriter.h"
+#include "creaImageIOImageReader.h"
 
 class Image3DDequeUR : public ImageDequeUR
 {
 private:
        ImageInfoDeque m_ImgDeque;
        unsigned int m_currentPos;
+       std::string m_globalPath;
 public:
        Image3DDequeUR();
-       virtual ~ImageDequeUR();
+       virtual ~Image3DDequeUR();
        virtual void addImageToContainer(ImageType* img, const RegionS& region);
-       virtual void loadImageToPMemory();
-       virtual void removeImageFromPMemory();
+       virtual void loadImageToPMemory( const unsigned int& index );
+       virtual void removeImageFromPMemory( const unsigned int& index );
+       virtual void saveImageAsMHD( ImageType* img, const std::string& filename );
        virtual ImageType* undo();
        virtual ImageType* redo();
+       void setGlobalPath( const std::string& globalPath );
        void removeFirstImageFromContainer();
        void removeLastImageFromContainer();
        void cleanContainer();
+       std::string getGlobalPath( );
 private:
        void cleanContainerFromIndex(const unsigned int& index);
 };
index 3da03117ca00b8fa2ba71cb6458bf16651cb66b7..a12887ed3bb3a3cfda9a03fe627b0f7f29d6ebb5 100644 (file)
@@ -24,8 +24,9 @@ public:
        ImageDequeUR();
        virtual ~ImageDequeUR();
        virtual void addImageToContainer(ImageType* img, const RegionS& region);
-       virtual void loadImageToPMemory();
-       virtual void removeImageFromPMemory();
+       virtual void loadImageToPMemory( const unsigned int& index );
+       virtual void removeImageFromPMemory( const unsigned int& index );
+       virtual void saveImageAsMHD( ImageType* img, const std::string& filename );
        virtual ImageType* undo();
        virtual ImageType* redo();
 private:
index 9f0db9c3616ec069c57b0a611c92ca5d574833c5..d91a428ed72ad1da309a5bafce49b44783daad06 100644 (file)
@@ -13,7 +13,7 @@ ImageInfoUR::ImageInfoUR()
 
 ImageInfoUR::~ImageInfoUR()
 {
-       this->deleteImage();
+       this->removeImageFromMemory();
 }
 
 void ImageInfoUR::setImageName(const std::string &imgName)
@@ -24,9 +24,9 @@ void ImageInfoUR::setRegion(const RegionStructUR &region)
 {
        this->m_Region = region;
 }
-void ImageInfoUR::setStatus(bool onDisk)
+void ImageInfoUR::setStatus(const bool& onMemory)
 {
-       this->m_OnDisk = onDisk;
+       this->m_OnMemory = onMemory;
 }
 void ImageInfoUR::setImage(vtkImageData* img)
 {
@@ -42,9 +42,9 @@ RegionStructUR ImageInfoUR::getRegion()
 }
 bool ImageInfoUR::getStatus()
 {
-       return( this->m_OnDisk );
+       return( this->m_OnMemory );
 }
-void ImageInfoUR::deleteImage()
+void ImageInfoUR::removeImageFromMemory()
 {
        this->m_Image->Delete();
 }
index 7a59b54e31f67389141d0d2a76f4aa835a77f6ca..1cf91f3f2f7d8a539f8f3c020fa406b6b95da007 100644 (file)
@@ -18,18 +18,18 @@ private:
        vtkImageData* m_Image;
        std::string m_ImageName;
        RegionStructUR m_Region;
-       bool m_OnDisk;
+       bool m_OnMemory;
 public:
        ImageInfoUR();
        virtual ~ImageInfoUR();
        void setImageName( const std::string &imgName );
        void setRegion( const RegionStructUR &region );
-       void setStatus( bool onDisk );
+       void setStatus( const bool& onMemory );
        void setImage( vtkImageData* img );
        std::string getImageName( );
        RegionStructUR getRegion( );
        bool getStatus( );
-       void deleteImage();
+       void removeImageFromMemory();
 };