X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FimageUndoRedo%2Fimage3DDequeUR.cxx;h=cac5bd6507bd95ee5c44149bbddaeee6cf3a9268;hb=4dcdcabb81ce9f9e9b7ccdb86a64995d7b18ea23;hp=2f6cdb73ddc9e8f71f0f0c551741874d6b84b42f;hpb=8185e042f64574ca43bba733ec2158a2aa994220;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx index 2f6cdb7..cac5bd6 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx @@ -1,158 +1,192 @@ +/*# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ */ + +/*! + * @file image3DDequeUR.cxx + * @brief This file contains the implementation of the Image3DDequeUR class. + * @author Info-Dev + * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr) + * @date 2011-11-15 + */ + #include "image3DDequeUR.h" +#include +#include + +// ---------------------------------------------------------------------------------- +Image3DDequeUR::Image3DDequeUR( ) +{ + -Image3DDequeUR::Image3DDequeUR() { +#ifdef _WIN32 + this->m_GlobalPath = std::getenv("TEMP"); +#endif +#ifdef _WIN64 + this->m_GlobalPath = std::getenv("TEMP"); +#endif +#ifdef LINUX this->m_GlobalPath = "/tmp/"; - this->m_CurrentUndoPos = -1; - this->m_CurrentRedoPos = -1; +#endif // MACOSX + this->m_CurrentURPos = -1; } +// ---------------------------------------------------------------------------------- //virtual -Image3DDequeUR::~Image3DDequeUR() { - +Image3DDequeUR::~Image3DDequeUR( ) +{ + this->CleanHardDisk( ); } +// ---------------------------------------------------------------------------------- //virtual -void Image3DDequeUR::AddImageToUndoContainer(ImageType* 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; - imageInfo.SetImageName(this->GetImageName()); - imageInfo.SetImage(img); - imageInfo.SetRegion(region); - imageInfo.SaveImageAsMHD(this->m_GlobalPath); - //cleaning deque from current position - this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos); - this->CleanRedoContainerFromIndex(0); - this->m_ImgRedoDeque.clear(); +void Image3DDequeUR::AddImagesToURContainer( VTKImageDataPointerType imgUndo, + VTKImageDataPointerType imgRedo, ImageMManager* imMManager ) +{ + this->CleanURContainerFromIndex( this->m_CurrentURPos + 1 ); + //Adding image + ImageInfoUR* imageInfo = new ImageInfoUR( ); + imageInfo->SetImageName( this->GetImageName( this->m_ImgURDeque.size( ) ) ); + imageInfo->SetImages( imgUndo, imgRedo ); + imageInfo->SetImageMManager( imMManager ); //Adding to deque - this->m_ImgUndoDeque.push_back(imageInfo); - this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1; + this->m_ImgURDeque.push_back( imageInfo ); + this->m_CurrentURPos = this->m_ImgURDeque.size( ) - 1; + //Managing memory + this->ManageMemory( ); } +// ---------------------------------------------------------------------------------- //virtual -void Image3DDequeUR::AddImageToRedoContainer(ImageType* img, - const RegionS& region) { - //managing memory - if (this->m_ImgRedoDeque.size() > 0) { - this->m_ImgRedoDeque.back().RemoveImageFromMemory(this->m_GlobalPath); +ImageInfoUR* Image3DDequeUR::Undo( ) +{ + ImageInfoUR* imgRet = NULL; + 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 - //adding image - ImageInfoUR imageInfo; - imageInfo.SetImageName(this->GetImageName()); - 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; + return ( imgRet ); } +// ---------------------------------------------------------------------------------- //virtual -void Image3DDequeUR::CleanUndoContainerFromIndex(const unsigned int& index) { - for (int i = this->m_ImgUndoDeque.size() - 1; i > this->m_CurrentUndoPos; - i--) { - this->m_ImgUndoDeque[i].RemoveImageFromMemory(this->m_GlobalPath); - this->m_ImgUndoDeque[i].RemoveImageFromDisk(this->m_GlobalPath); - this->m_ImgUndoDeque.pop_back(); +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 -void Image3DDequeUR::CleanRedoContainerFromIndex(const unsigned int& index) { - for (int i = this->m_ImgRedoDeque.size() - 1; i > this->m_CurrentRedoPos; - i--) { - this->m_ImgRedoDeque[i].RemoveImageFromMemory(this->m_GlobalPath); - this->m_ImgRedoDeque[i].RemoveImageFromDisk(this->m_GlobalPath); - this->m_ImgRedoDeque.pop_back(); +void Image3DDequeUR::CleanURContainerFromIndex( const int& index ) +{ + int count = 0; + for( unsigned int i = index; i < this->m_ImgURDeque.size( ); i++ ) + { + this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath ); + this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath ); + count++; } + for( int i = 0; i < count; i++ ) + { + this->m_ImgURDeque.pop_back( ); + } //rof } - -//virtual -ImageInfoUR Image3DDequeUR::Undo() { - ImageInfoUR imgRet; - if ((this->m_ImgUndoDeque.size() > 0) && (this->m_CurrentUndoPos != -1)) { - //removing from memory - if ((this->m_CurrentUndoPos + 1) < this->m_ImgUndoDeque.size()) { - this->m_ImgUndoDeque[(m_CurrentUndoPos + 1)].RemoveImageFromMemory( - this->m_GlobalPath); - } //fi - ImageInfoUR imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos]; - this->m_CurrentUndoPos--; - //adding to memory - if (this->m_CurrentUndoPos != -1) { - //Loading image - std::string 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; - //managing undo deque - if (this->m_ImgUndoDeque.size() > 0) { - if ((m_CurrentUndoPos - 1) != -1) { - this->m_ImgUndoDeque[m_CurrentUndoPos - 1].RemoveImageFromMemory( - this->m_GlobalPath); +void Image3DDequeUR::ManageMemory( ) +{ + 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 - 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++) { - this->m_ImgUndoDeque[i].RemoveImageFromMemory(this->m_GlobalPath); - this->m_ImgUndoDeque[i].RemoveImageFromDisk(this->m_GlobalPath); - } //rof - 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); } //rof - this->m_ImgRedoDeque.clear(); - this->m_ImgUndoDeque.clear(); + //Adding CurrentUndoPos to memory + if( ( this->m_CurrentURPos != -1 ) + && !( this->m_ImgURDeque[ this->m_CurrentURPos ]->GetStatus( ) ) ) + { + 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 std::string& globalPath) { +// ---------------------------------------------------------------------------------- +void Image3DDequeUR::SetGlobalPath( const StringType& globalPath ) +{ this->m_GlobalPath = globalPath; } - -std::string Image3DDequeUR::GetGlobalPath() { - return (this->m_GlobalPath); +// ---------------------------------------------------------------------------------- +void Image3DDequeUR::CleanHardDisk( ) +{ + for( unsigned int i = 0; i < this->m_ImgURDeque.size( ); i++ ) + { + this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath ); + } } - -std::string Image3DDequeUR::GetImageName() { +// ---------------------------------------------------------------------------------- +Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath( ) +{ + return ( this->m_GlobalPath ); +} +// ---------------------------------------------------------------------------------- +Image3DDequeUR::StringType Image3DDequeUR::GetImageName( const int & pos ) +{ //Giving a name to an image using the date and time - 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); - std::string aux(buffer); - std::string imageName = "img_" + aux; - return (imageName); + if( this->m_IDImages.empty( ) ) + { + time_t rawtime; + struct tm * timeinfo; + char buffer[ 80 ]; + time( &rawtime ); + timeinfo = localtime( &rawtime ); + strftime( buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo ); + StringType date( buffer ); + StringType aux( buffer ); + this->m_IDImages = "img_" + aux; + } + std::stringstream ss; //create a stringstream + ss << pos; //add number to the stream + StringType imageName = this->m_IDImages + ss.str( ); + return ( imageName ); } +// ----------------------------------------------------------------------------------