X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FimageUndoRedo%2FimageUndoRedo.cxx;h=2137a713e5d4fcd57277cf17a94598dfcba30bea;hb=2725f81fc97c9faa92749159bdbaf9cedeef7af4;hp=2f80bd6594ff3352d3a53f0e57b1eb5c917d7c88;hpb=f4bdb751aba1f5fce1d4305365d6309f993d9c32;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 2f80bd6..2137a71 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx @@ -17,37 +17,47 @@ ImageUndoRedo::~ImageUndoRedo() { //virtual void ImageUndoRedo::Undo() { ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo(); - if (imageInfo != NULL) - { - //this->SetRedoImage(imageInfo->GetRegion()); - this->DrawUR(imageInfo); + if (imageInfo != NULL) { + //this->SetRedoImage(imageInfo->GetImageMManager()); + this->DrawUR(imageInfo, true); + this->UpdateUndoImage(); } } //virtual void ImageUndoRedo::Redo() { - ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo(); - this->DrawUR(imageInfo); + /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo(); + if (imageInfo != NULL) + { + this->DrawUR(imageInfo); + }*/ } 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->UpdateUndoImage(); } //virtual -void ImageUndoRedo::SetUndoImage(ImageMManagerType* imMManager) { +void ImageUndoRedo::SetURImages(ImageMManagerType* imMManager) { ImageMManagerType* newImageManager = new ImageMManagerType(imMManager); - RegionSType region = newImageManager->GetModifiedRegion(); - VTKImageDataPointerType imgResult = this->GetImageRegion(region, - this->m_OriginalImage); - this->m_ImagesDeque->AddImageToUndoContainer(imgResult, newImageManager); + 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 ImageMManagerType* imMManager) { - /*RegionSType region = imMManager.GetModifiedRegion(); - VTKImageDataPointerType imgResult = this->ImageMManagerType(region, - this->m_CurrentImage); - this->m_ImagesDeque->AddImageToRedoContainer(imgResult, imMManager);*/ + +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( @@ -56,40 +66,37 @@ 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_OriginalImage); + extract->SetInput(this->m_UndoImage); VTKImageDataPointerType imgResult = extract->GetOutput(); imgResult->Update(); return (imgResult); } -void ImageUndoRedo::SetOriginalImage(VTKImageDataPointerType img) { - this->m_OriginalImage = img; -} void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) { this->m_CurrentImage = img; } //virtual -void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) { - VTKImageDataPointerType img = imageInfo->GetImage(); +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(); - ImageMManager::PixelModMap map = - imageInfo->GetImageMManager()->GetModificationMap(); - std::cout << "Region " << "(" << region.maxX << "," << region.maxY << "," - << region.maxZ << ")" << std::endl; if (img != NULL) { for (int i = region.minX, x = 0; i <= region.maxX; i++, x++) { for (int j = region.minY, y = 0; j <= region.maxY; j++, y++) { for (int k = region.minZ, z = 0; k <= region.maxZ; k++, z++) { - if (map[i][j][k]) { - float value = img->GetScalarComponentAsFloat(i, j, k, - 0); - this->m_CurrentImage->SetScalarComponentFromFloat(i, j, - k, 0, value); - } + float value = img->GetScalarComponentAsFloat(x, y, z, 0); + this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k, + 0, value); } //rof } //rof } //rof this->m_CurrentImage->Modified(); } + this->m_ImagesDeque->ManageMemory(); }