X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FimageUndoRedo%2FimageUndoRedo.cxx;h=d49b1b21d2e980660400992d2b84cd30d8182835;hb=f29cb8ab22a8fa3befdefa314bb4c58d9e827e16;hp=8864148e34df0ea8c7962e50bd881635c88a5776;hpb=b37bd791f88bd4c1a6146fadcb88864d7cd1a5c3;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx index 8864148..d49b1b2 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx @@ -1,85 +1,131 @@ -/* - * imageUndoRedo.cxx - * - * Created on: Sep 26, 2011 - * Author: caceres +/*! + * @file imageUndoRedo.cxx + * @brief This file contains the implementation of the ImageUndoRedo class. + * @author Info-Dev + * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr) + * @date 2011-11-15 */ #include "imageUndoRedo.h" -ImageUndoRedo::ImageUndoRedo() { - this->m_ImagesDeque = new IDequeType(); +// ---------------------------------------------------------------------------------- +ImageUndoRedo::ImageUndoRedo( ) +{ + this->m_ImagesDeque = new IDequeType( ); } +// ---------------------------------------------------------------------------------- //virtual -ImageUndoRedo::~ImageUndoRedo() { +ImageUndoRedo::~ImageUndoRedo( ) +{ } +// ---------------------------------------------------------------------------------- //virtual -void ImageUndoRedo::Undo() { - ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo(); - if (imageInfo != NULL) +void ImageUndoRedo::Undo( ) +{ + ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo( ); + if( imageInfo != NULL) { - this->SetRedoImage(imageInfo->GetRegion()); - this->DrawUR(imageInfo); + this->DrawUR( imageInfo, true ); + this->UpdateUndoImage( ); } } +// ---------------------------------------------------------------------------------- //virtual -void ImageUndoRedo::Redo() { - ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo(); - this->DrawUR(imageInfo); +void ImageUndoRedo::Redo( ) +{ + ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo( ); + if( imageInfo != NULL) + { + this->DrawUR( imageInfo, false ); + this->UpdateUndoImage( ); + } } -void ImageUndoRedo::SetImage(VTKImageDataPointerType image) { +// ---------------------------------------------------------------------------------- +void ImageUndoRedo::SetImage( VTKImageDataPointerType image ) +{ this->m_CurrentImage = image; - this->m_CurrentImage->Update(); - this->m_OriginalImage = VTKImageDataPointerType::New(); - this->m_OriginalImage->DeepCopy(m_CurrentImage); + this->m_CurrentImage->Update( ); + this->UpdateUndoImage( ); } +// ---------------------------------------------------------------------------------- //virtual -void ImageUndoRedo::SetUndoImage(const RegionSType& region) { - VTKImageDataPointerType imgResult = this->GetImageRegion(region, - this->m_OriginalImage); - this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region); +void ImageUndoRedo::SetURImages( ImageMManagerType* imMManager ) +{ + ImageMManagerType* newImageManager = new ImageMManagerType( imMManager ); + if( newImageManager->ValidateRegion( ) ) + { + RegionSType region = newImageManager->GetModifiedRegion( ); + VTKImageDataPointerType imgUndo = this->GetImageRegion( region, + this->m_UndoImage ); + VTKImageDataPointerType imgRedo = this->GetImageRegion( region, + this->m_CurrentImage ); + this->m_ImagesDeque->AddImagesToURContainer( imgUndo, imgRedo, + newImageManager ); + this->UpdateUndoImage( ); + } + else + { + std::cerr << "INVALID REGION" << std::endl; + } } -//virtual -void ImageUndoRedo::SetRedoImage(const RegionSType& region) { - VTKImageDataPointerType imgResult = this->GetImageRegion(region, - this->m_CurrentImage); - this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region); +// ---------------------------------------------------------------------------------- +void ImageUndoRedo::UpdateUndoImage( ) +{ + this->m_CurrentImage->Update( ); + this->m_UndoImage = VTKImageDataPointerType::New( ); + this->m_UndoImage->DeepCopy( m_CurrentImage ); + this->m_UndoImage->Update( ); } - +// ---------------------------------------------------------------------------------- ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion( - const RegionSType& region, VTKImageDataPointerType img) { - VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New(); - VTKImageDataPointerType imgResult = VTKImageDataPointerType::New(); - extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY, - region.minZ, region.maxZ); - extract->SetSampleRate(1, 1, 1); - extract->SetInput(this->m_OriginalImage); - imgResult = extract->GetOutput(); - return (imgResult); + const RegionSType& region, VTKImageDataPointerType img ) +{ + VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New( ); + extract->SetVOI( region.minX, region.maxX, region.minY, region.maxY, + region.minZ, region.maxZ ); + extract->SetSampleRate( 1, 1, 1 ); + extract->SetInput( img ); + VTKImageDataPointerType imgResult = extract->GetOutput( ); + imgResult->Update( ); + return ( imgResult ); } - -void ImageUndoRedo::SetOriginalImage(VTKImageDataPointerType img) { - this->m_OriginalImage = img; -} -void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) { +// ---------------------------------------------------------------------------------- +void ImageUndoRedo::SetCurrentImage( VTKImageDataPointerType img ) +{ this->m_CurrentImage = 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); - } //rof - } //rof - } //rof - this->m_CurrentImage->Modified(); +void ImageUndoRedo::DrawUR( ImageInfoUR* imageInfo, const bool& undo ) +{ + VTKImageDataPointerType img; + if( undo ) + { + img = imageInfo->GetUndoImage( ); + } //fi + else + { + img = imageInfo->GetRedoImage( ); + } //else + RegionSType region = imageInfo->GetImageMManager( )->GetModifiedRegion( ); + if( img != NULL) + { + int *dim = img->GetDimensions( ); + int sizeXImageIn = dim[ 0 ]; + size_t linesize = sizeXImageIn * sizeof(unsigned short); + for( int j = region.minY, y = 0; j <= region.maxY; j++, y++ ) + { + for( int k = region.minZ, z = 0; k <= region.maxZ; k++, z++ ) + { + void* ptrsrc = img->GetScalarPointer( 0, y, z ); + void* ptrdest = this->m_CurrentImage->GetScalarPointer( + region.minX, j, k ); + memcpy( ptrdest, ptrsrc, linesize ); + } + } + this->m_CurrentImage->Modified( ); + } + this->m_ImagesDeque->ManageMemory( ); } - +// ----------------------------------------------------------------------------------