this->GetImageName(this->m_ImgUndoDeque.size(), true));
imageInfo->SetImage(img);
imageInfo->SetImageMManager(imMManager);
- ///---------------------------------------------------------------------------------------------------
- // Uncoment the following line
- //imageInfo->SaveImageAsMHD(this->m_GlobalPath);
- ///------------------------------------------------------------------------------------------------
//Adding to deque
this->m_ImgUndoDeque.push_back(imageInfo);
this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1;
+ //Managing memory
+ this->ManageMemory();
}
//virtual
ImageInfoUR* Image3DDequeUR::Undo() {
}
//virtual
void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) {
- for (int i = index; i < this->m_ImgUndoDeque.size(); i++) {
+ int count = 0;
+ for (unsigned int i = index; i < this->m_ImgUndoDeque.size(); i++) {
this->m_ImgUndoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath);
this->m_ImgUndoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath);
- this->m_ImgUndoDeque.pop_back();
+ count++;
}
+ for (int i = 0; i < count; i++) {
+ this->m_ImgUndoDeque.pop_back();
+ } //rof
+
}
//virtual
void Image3DDequeUR::CleanRedoContainerFromIndex(const int& index) {
- for (int i = index; i < this->m_ImgRedoDeque.size(); i++) {
- this->m_ImgRedoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath);
- this->m_ImgRedoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath);
- this->m_ImgRedoDeque.pop_back();
- }
}
//virtual
void Image3DDequeUR::CleanContainers() {
this->m_ImgUndoDeque.clear();
}
+//virtual
+void Image3DDequeUR::ManageMemory() {
+ for (int i = 0; (unsigned int) i < this->m_ImgUndoDeque.size(); i++) {
+ if (this->m_ImgUndoDeque[i]->GetStatus()) {
+ this->m_ImgUndoDeque[i]->RemoveImageFromMemory(this->m_GlobalPath);
+ } //fi
+ } //rof
+ //Adding CurrentUndoPos to memory
+ if ((this->m_CurrentUndoPos != -1)
+ && !(this->m_ImgUndoDeque[this->m_CurrentUndoPos]->GetStatus())) {
+ this->m_ImgUndoDeque[this->m_CurrentUndoPos]->LoadImageMHDToMemory(
+ this->m_GlobalPath);
+ }
+ //The same for the redo queue
+}
+
void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) {
this->m_GlobalPath = globalPath;
}
virtual void CleanUndoContainerFromIndex(const int& index);
virtual void CleanRedoContainerFromIndex(const int& index);
virtual void CleanContainers();
+ virtual void ManageMemory();
virtual ImageInfoUR* Undo();
virtual ImageInfoUR* Redo();
protected:
}
+void ImageDequeUR::ManageMemory() {
+
+}
+
ImageInfoUR* ImageDequeUR::Undo() {
return NULL;
}
virtual void CleanUndoContainerFromIndex(const int& index);
virtual void CleanRedoContainerFromIndex(const int& index);
virtual void CleanContainers();
+ virtual void ManageMemory();
virtual ImageInfoUR* Undo();
virtual ImageInfoUR* Redo();
};
}
ImageMManager::ImageMManager(ImageMManager* manager) {
- this->m_PixelMap = manager->GetModificationMap();
this->m_RegionStruct = manager->GetModifiedRegion();
}
ImageMManager::~ImageMManager() {
this->m_RegionStruct.maxY = min;
this->m_RegionStruct.minZ = max;
this->m_RegionStruct.maxZ = min;
- this->m_PixelMap.clear();
+ this->m_ValidRegion = false;
} //DFCH
void ImageMManager::CalculateMinMaxRegion(const int& i, const int& j,
const int& k) {
- if (i <= this->m_RegionStruct.minX) {
- this->m_RegionStruct.minX = i;
+ if (i >= 0 && j >= 0 && k >= 0) {
+ if (i <= this->m_RegionStruct.minX) {
+ this->m_RegionStruct.minX = i;
+ } //fi
+ if (i > this->m_RegionStruct.maxX) {
+ this->m_RegionStruct.maxX = i;
+ } //esle
+ if (j <= this->m_RegionStruct.minY) {
+ this->m_RegionStruct.minY = j;
+ } //fi
+ if (j > this->m_RegionStruct.maxY) {
+ this->m_RegionStruct.maxY = j;
+ } //esle
+ if (k <= this->m_RegionStruct.minZ) {
+ this->m_RegionStruct.minZ = k;
+ } //fi
+ if (k > this->m_RegionStruct.maxZ) {
+ this->m_RegionStruct.maxZ = k;
+ } //esle
+ this->m_ValidRegion = true;
} //fi
- if (i > this->m_RegionStruct.maxX) {
- this->m_RegionStruct.maxX = i;
- } //esle
- if (j <= this->m_RegionStruct.minY) {
- this->m_RegionStruct.minY = j;
- } //fi
- if (j > this->m_RegionStruct.maxY) {
- this->m_RegionStruct.maxY = j;
- } //esle
- if (k <= this->m_RegionStruct.minZ) {
- this->m_RegionStruct.minZ = k;
- } //fi
- if (k > this->m_RegionStruct.maxZ) {
- this->m_RegionStruct.maxZ = k;
+ else {
+ this->m_ValidRegion = false;
} //esle
} //DFCH
void ImageMManager::AddModifiedPixel(const int& i, const int& j, const int& k) {
- this->m_PixelMap[i][j][k] = true;
+ //this->m_PixelMap[i][j][k] = true;
this->CalculateMinMaxRegion(i, j, k);
} //DFCH
-RegionStructUR ImageMManager::GetModifiedRegion() {
- return (this->m_RegionStruct);
+bool ImageMManager::ValidateRegion() {
+ return (m_ValidRegion);
}
-ImageMManager::PixelModMap ImageMManager::GetModificationMap() {
- return (this->m_PixelMap);
+RegionStructUR ImageMManager::GetModifiedRegion() {
+ return (this->m_RegionStruct);
}
virtual ~ImageMManager();
void CleanModifiedRegion(); //DFCH
void AddModifiedPixel(const int& i, const int& j, const int& k); //DFCH
- //void SetRegion(const RegionStructUR& region);
- //void SetPixelModMap(const PixelModMap& map); //DFCH
+ bool ValidateRegion();//DFCH
RegionStructUR GetModifiedRegion(); //DFCH
- PixelModMap GetModificationMap(); //DFCH
private:
void CalculateMinMaxRegion(const int& i, const int& j, const int& k); //DFCH
private:
RegionStructUR m_RegionStruct;
- PixelModMap m_PixelMap;
+ bool m_ValidRegion;
};
#endif /* IMAGEMANAGEMENT_H_ */
{
//this->SetRedoImage(imageInfo->GetRegion());
this->DrawUR(imageInfo);
+ this->UpdateUndoImage();
}
}
//virtual
void ImageUndoRedo::Redo() {
- ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
- 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) {
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 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 ImageMManagerType* imMManager) {
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(
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_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;
}
void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
VTKImageDataPointerType img = imageInfo->GetImage();
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();
}
virtual void SetImage(VTKImageDataPointerType image);
virtual void SetUndoImage(ImageMManagerType* imMManager);
virtual void SetRedoImage(const ImageMManagerType* imMManager);
- void SetOriginalImage(VTKImageDataPointerType img);
+ void UpdateUndoImage();
void SetCurrentImage(VTKImageDataPointerType img);
VTKImageDataPointerType GetImageRegion(const RegionSType& region,
VTKImageDataPointerType img);
protected:
IDequeType* m_ImagesDeque;
- VTKImageDataPointerType m_OriginalImage;
+ VTKImageDataPointerType m_UndoImage;
VTKImageDataPointerType m_CurrentImage;
};
_mBarSlices->setRepresentedValues(min, max);
_mBarSlices->SetStart(min);
_mBarSlices->SetEnd(max);
+ _mBarSlices->Update();
//DFCH -- End BarSlices
wxString lst2D3D[2];