X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FimageUndoRedo%2FimageUndoRedo.cxx;h=bf524449210ba8fbfb52bd3bb26f211cce39ca59;hb=d725af03e25b41e03b212c26068be2c04dacd270;hp=a459e8598a21a793d1986f6758d9f91c56a9ae94;hpb=d0338585b83d4b0422ad465dedd0f885b3441600;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 a459e85..bf52444 100755 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx @@ -17,51 +17,94 @@ ImageUndoRedo::~ImageUndoRedo() { //virtual void ImageUndoRedo::Undo() { ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo(); - this->SetRedoImage(imageInfo->GetRegion()); - std::cout<<"undooooooooooooooooooooooooooo"<DrawUR(imageInfo); + if (imageInfo != NULL) + { + //this->SetRedoImage(imageInfo->GetImageMManager()); + this->DrawUR(imageInfo); + 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(vtkImageData *image) { +void ImageUndoRedo::SetImage(VTKImageDataPointerType image) { this->m_CurrentImage = image; this->m_CurrentImage->Update(); - this->m_OriginalImage = ImageType::New(); - this->m_OriginalImage->DeepCopy(m_CurrentImage); + this->UpdateUndoImage(); } //virtual -void ImageUndoRedo::SetUndoImage(const RegionSType& region) { - vtkSmartPointer extract = - vtkSmartPointer::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); - vtkImageData* imgResult = extract->GetOutput(); - this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region); +void ImageUndoRedo::SetUndoImage(ImageMManagerType* imMManager) { + ImageMManagerType* newImageManager = new ImageMManagerType(imMManager); + if (newImageManager->ValidateRegion()) { + RegionSType region = newImageManager->GetModifiedRegion(); + VTKImageDataPointerType imgResult = this->GetImageRegion(region, + this->m_UndoImage); + this->m_ImagesDeque->AddImageToUndoContainer(imgResult, + newImageManager); + this->UpdateUndoImage(); + } else { + std::cerr << "INVALID REGION" << std::endl; + } } //virtual -void ImageUndoRedo::SetRedoImage(const RegionSType& region) { - vtkSmartPointer extract = - vtkSmartPointer::New(); +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() { + 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(); extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY, region.minZ, region.maxZ); extract->SetSampleRate(1, 1, 1); - extract->SetInput(this->m_CurrentImage); - vtkImageData* imgResult = extract->GetOutput(); - this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region); -} -void ImageUndoRedo::SetOriginalImage(ImageType* img) { - this->m_OriginalImage = img; + extract->SetInput(this->m_UndoImage); + VTKImageDataPointerType imgResult = extract->GetOutput(); + imgResult->Update(); + return (imgResult); } -void ImageUndoRedo::SetCurrentImage(ImageType* img) { + +void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) { this->m_CurrentImage = img; } //virtual void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) { - + VTKImageDataPointerType img = imageInfo->GetImage(); + RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion(); + 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++) { + 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(); }