//virtual
void Image3DDequeUR::AddImageToUndoContainer(VTKImageDataPointerType 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 = new ImageInfoUR();
imageInfo->SetImageName(
this->GetImageName(this->m_ImgUndoDeque.size(), true));
imageInfo->SetImage(img);
imageInfo->SetRegion(region);
+ ///---------------------------------------------------------------------------------------------------
+ // Uncoment the following line
imageInfo->SaveImageAsMHD(this->m_GlobalPath);
- //cleaning deque from current position
- this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos + 1);
- this->CleanRedoContainerFromIndex(0);
- this->m_ImgRedoDeque.clear();
+ ///------------------------------------------------------------------------------------------------
//Adding to deque
this->m_ImgUndoDeque.push_back(imageInfo);
this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1;
}
//virtual
+ImageInfoUR* Image3DDequeUR::Undo() {
+ ImageInfoUR* imgRet = NULL;
+ if ((this->m_ImgUndoDeque.size() > 0) && (this->m_CurrentUndoPos != -1)) {
+ imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos];
+ this->m_CurrentUndoPos--;
+ } //fi
+ return (imgRet);
+}
+//virtual
void Image3DDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img,
const RegionS& region) {
- //managing memory
- /*if (this->m_ImgRedoDeque.size() > 0) {
- this->m_ImgRedoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
- } //fi
- //adding image
- ImageInfoUR* imageInfo = new ImageInfoUR();
- imageInfo->SetImageName(
- this->GetImageName(this->m_ImgRedoDeque.size(), false));
- 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;*/
+}
+//virtual
+ImageInfoUR* Image3DDequeUR::Redo() {
+
+ ImageInfoUR* imgRet = new ImageInfoUR();
+ return (imgRet);
}
//virtual
void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) {
this->m_ImgRedoDeque.pop_back();
}
}
-
-//virtual
-ImageInfoUR* Image3DDequeUR::Undo() {
- ImageInfoUR* imgRet = NULL;
- if ((this->m_ImgUndoDeque.size() > 0) && (this->m_CurrentUndoPos != -1)) {
- std::cout<<"Controooool"<<std::endl;
- //removing from memory
- if ((this->m_CurrentUndoPos + 1) < this->m_ImgUndoDeque.size()) {
- this->m_ImgUndoDeque[(m_CurrentUndoPos + 1)]->RemoveImageFromMemory(
- this->m_GlobalPath);
- } //fi
- imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos];
- std::cout << "imageName: " << imgRet->GetImageName() << std::endl;
- this->m_CurrentUndoPos--;
- //adding to memory
- if (this->m_CurrentUndoPos != -1) {
- //Loading image
- StringType 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 = new ImageInfoUR();
- //managing undo deque
- if (this->m_ImgUndoDeque.size() > 0) {
- if ((m_CurrentUndoPos - 1) != -1) {
- this->m_ImgUndoDeque[m_CurrentUndoPos - 1]->RemoveImageFromMemory(
- 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++) {
ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
if (imageInfo != NULL)
{
- this->SetRedoImage(imageInfo->GetRegion());
+ //this->SetRedoImage(imageInfo->GetRegion());
this->DrawUR(imageInfo);
}
}
//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);
+ if( img != NULL )
+ {
+ 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
- } //rof
- this->m_CurrentImage->Modified();
+ this->m_CurrentImage->Modified();
+ }
}