#include "image3DDequeUR.h"
+#include <iostream>
+#include <sstream>
Image3DDequeUR::Image3DDequeUR() {
- this->m_GlobalPath = "/tmp/";
+ this->m_GlobalPath = "/home/caceres/temporal/";
this->m_CurrentUndoPos = -1;
this->m_CurrentRedoPos = -1;
}
const RegionS& region) {
//managing memory
if (this->m_ImgUndoDeque.size() > 0) {
- this->m_ImgUndoDeque.back().RemoveImageFromMemory(this->m_GlobalPath);
+ this->m_ImgUndoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
} //fi
//Adding image
- ImageInfoUR imageInfo;
- imageInfo.SetImageName(this->GetImageName());
- imageInfo.SetImage(img);
- imageInfo.SetRegion(region);
- imageInfo.SaveImageAsMHD(this->m_GlobalPath);
+ ImageInfoUR* imageInfo = new ImageInfoUR();
+ imageInfo->SetImageName(
+ this->GetImageName(this->m_ImgUndoDeque.size(), true));
+ imageInfo->SetImage(img);
+ imageInfo->SetRegion(region);
+ imageInfo->SaveImageAsMHD(this->m_GlobalPath);
//cleaning deque from current position
- this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos);
+ this->CleanUndoContainerFromIndex(this->m_CurrentUndoPos + 1);
this->CleanRedoContainerFromIndex(0);
this->m_ImgRedoDeque.clear();
//Adding to deque
this->m_ImgUndoDeque.push_back(imageInfo);
+ std::cout<<"Parceeeeeeeee: aaa " << this->m_ImgUndoDeque.size()<<std::endl;
this->m_CurrentUndoPos = this->m_ImgUndoDeque.size() - 1;
}
//virtual
const RegionS& region) {
//managing memory
if (this->m_ImgRedoDeque.size() > 0) {
- this->m_ImgRedoDeque.back().RemoveImageFromMemory(this->m_GlobalPath);
+ this->m_ImgRedoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
} //fi
//adding image
- ImageInfoUR imageInfo;
- imageInfo.SetImageName(this->GetImageName());
- imageInfo.SetImage(img);
- imageInfo.SetRegion(region);
- imageInfo.SaveImageAsMHD(this->m_GlobalPath);
+ 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
-void Image3DDequeUR::CleanUndoContainerFromIndex(const unsigned int& index) {
- for (int i = this->m_ImgUndoDeque.size() - 1; i > this->m_CurrentUndoPos;
- i--) {
- this->m_ImgUndoDeque[i].RemoveImageFromMemory(this->m_GlobalPath);
- this->m_ImgUndoDeque[i].RemoveImageFromDisk(this->m_GlobalPath);
+void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) {
+ for (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();
}
}
//virtual
-void Image3DDequeUR::CleanRedoContainerFromIndex(const unsigned int& index) {
- for (int i = this->m_ImgRedoDeque.size() - 1; i > this->m_CurrentRedoPos;
- i--) {
- this->m_ImgRedoDeque[i].RemoveImageFromMemory(this->m_GlobalPath);
- this->m_ImgRedoDeque[i].RemoveImageFromDisk(this->m_GlobalPath);
+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
-ImageInfoUR Image3DDequeUR::Undo() {
- ImageInfoUR imgRet;
+ImageInfoUR* Image3DDequeUR::Undo() {
+ ImageInfoUR* imgRet = new ImageInfoUR();
if ((this->m_ImgUndoDeque.size() > 0) && (this->m_CurrentUndoPos != -1)) {
//removing from memory
if ((this->m_CurrentUndoPos + 1) < this->m_ImgUndoDeque.size()) {
- this->m_ImgUndoDeque[(m_CurrentUndoPos + 1)].RemoveImageFromMemory(
+ this->m_ImgUndoDeque[(m_CurrentUndoPos + 1)]->RemoveImageFromMemory(
this->m_GlobalPath);
} //fi
- ImageInfoUR imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos];
+ imgRet = this->m_ImgUndoDeque[m_CurrentUndoPos];
this->m_CurrentUndoPos--;
//adding to memory
if (this->m_CurrentUndoPos != -1) {
//Loading image
std::string fullPath = this->m_GlobalPath
- + this->m_ImgUndoDeque[m_CurrentUndoPos].GetImageName();
- this->m_ImgUndoDeque[m_CurrentUndoPos].LoadImageMHDToMemory(
+ + this->m_ImgUndoDeque[m_CurrentUndoPos]->GetImageName();
+ this->m_ImgUndoDeque[m_CurrentUndoPos]->LoadImageMHDToMemory(
this->m_GlobalPath);
} //fi
} //fi
return (imgRet);
}
//virtual
-ImageInfoUR Image3DDequeUR::Redo() {
+ImageInfoUR* Image3DDequeUR::Redo() {
- ImageInfoUR imgRet;
+ 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_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_ImgUndoDeque[m_CurrentUndoPos]->LoadImageMHDToMemory(
this->m_GlobalPath);
} //fi
//end of undo management
//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_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_ImgRedoDeque[m_CurrentRedoPos]->LoadImageMHDToMemory(
this->m_GlobalPath);
} //fi
//end of redo management
//virtual
void Image3DDequeUR::CleanContainers() {
for (unsigned int i = 0; 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[i]->RemoveImageFromMemory(this->m_GlobalPath);
+ this->m_ImgUndoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath);
} //rof
for (unsigned int i = 0; 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[i]->RemoveImageFromMemory(this->m_GlobalPath);
+ this->m_ImgRedoDeque[i]->RemoveImageFromDisk(this->m_GlobalPath);
} //rof
this->m_ImgRedoDeque.clear();
this->m_ImgUndoDeque.clear();
return (this->m_GlobalPath);
}
-std::string Image3DDequeUR::GetImageName() {
+std::string Image3DDequeUR::GetImageName(const int & pos, const bool& undo) {
//Giving a name to an image using the date and time
- time_t rawtime;
- struct tm * timeinfo;
- char buffer[80];
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(buffer, 80, "%a_%d_%b_%y_%H_%M_S", timeinfo);
- std::string date(buffer);
- std::string aux(buffer);
- std::string imageName = "img_" + aux;
+ if (this->m_IDImages.empty()) {
+ time_t rawtime;
+ struct tm * timeinfo;
+ char buffer[80];
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ strftime(buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo);
+ std::string date(buffer);
+ std::string aux(buffer);
+ this->m_IDImages = "img_" + aux;
+ }
+ std::stringstream ss; //create a stringstream
+ ss << pos; //add number to the stream
+ std::string imgType;
+ if (undo) {
+ imgType = "undo";
+ }
+ else
+ {
+ imgType = "redo";
+ }
+ std::string imageName = this->m_IDImages + imgType + ss.str();
+ imageName.append(".mhd");
return (imageName);
}
#include "imageDequeUR.h"
#include <ctime>
+
class Image3DDequeUR: public ImageDequeUR {
private:
ImageInfoDeque m_ImgUndoDeque;
int m_CurrentUndoPos;
int m_CurrentRedoPos;
std::string m_GlobalPath;
+ std::string m_IDImages;
public:
Image3DDequeUR();
virtual ~Image3DDequeUR();
void SetGlobalPath(const std::string& globalPath);
std::string GetGlobalPath();
- std::string GetImageName();
+ std::string GetImageName(const int & pos, const bool& undo);
virtual void AddImageToUndoContainer(ImageType* img, const RegionS& region);
virtual void AddImageToRedoContainer(ImageType* img, const RegionS& region);
- virtual void CleanUndoContainerFromIndex(const unsigned int& index);
- virtual void CleanRedoContainerFromIndex(const unsigned int& index);
+ virtual void CleanUndoContainerFromIndex(const int& index);
+ virtual void CleanRedoContainerFromIndex(const int& index);
virtual void CleanContainers();
- virtual ImageInfoUR Undo();
- virtual ImageInfoUR Redo();
+ virtual ImageInfoUR* Undo();
+ virtual ImageInfoUR* Redo();
};
#endif /* IMAGE3DDEQUEUR_H_ */
void ImageDequeUR::AddImageToRedoContainer(ImageType* img,
const RegionS& region) {
}
-void ImageDequeUR::CleanUndoContainerFromIndex(const unsigned int& index) {
+void ImageDequeUR::CleanUndoContainerFromIndex(const int& index) {
}
-void ImageDequeUR::CleanRedoContainerFromIndex(const unsigned int& index) {
+void ImageDequeUR::CleanRedoContainerFromIndex(const int& index) {
}
+void ImageDequeUR::CleanContainers() {
-ImageInfoUR ImageDequeUR::Undo() {
- ImageInfoUR im;
+}
+
+ImageInfoUR* ImageDequeUR::Undo() {
+ ImageInfoUR* im;
return im;
}
-ImageInfoUR ImageDequeUR::Redo() {
- ImageInfoUR im;
+ImageInfoUR* ImageDequeUR::Redo() {
+ ImageInfoUR* im;
return im;
}
#include "imageInfoUR.h"
#include "regionStructUR.h"
-typedef std::deque<ImageInfoUR> ImageInfoDeque;
+typedef std::deque<ImageInfoUR*> ImageInfoDeque;
typedef vtkImageData ImageType;
typedef RegionStructUR RegionS;
virtual ~ImageDequeUR();
virtual void AddImageToUndoContainer(ImageType* img, const RegionS& region);
virtual void AddImageToRedoContainer(ImageType* img, const RegionS& region);
- virtual void CleanUndoContainerFromIndex(const unsigned int& index);
- virtual void CleanRedoContainerFromIndex(const unsigned int& index);
+ virtual void CleanUndoContainerFromIndex(const int& index);
+ virtual void CleanRedoContainerFromIndex(const int& index);
virtual void CleanContainers();
- virtual ImageInfoUR Undo();
- virtual ImageInfoUR Redo();
+ virtual ImageInfoUR* Undo();
+ virtual ImageInfoUR* Redo();
};
#endif /* IMAGEDEQUE_H_ */
}
ImageInfoUR::~ImageInfoUR() {
- this->m_Image->Delete();
}
void ImageInfoUR::SetImageName(const std::string &imgName) {
if (!this->m_OnDisk) {
this->SaveImageAsMHD(gPath);
}
- this->m_Image->Delete();
+ this->m_Image = NULL;
this->SetStatus(false);
}
void ImageInfoUR::LoadImageMHDToMemory(const std::string& gPath) {
w->SetCompression(false);
w->SetFileDimensionality(this->m_Image->GetDataDimension());
w->SetFileName(filename.c_str());
- w->Update();
w->Write();
- w->Delete();
}
void ImageInfoUR::RemoveImageFromDisk(const std::string& gPath)
}
//virtual
void ImageUndoRedo::Undo() {
- ImageInfoUR imageInfo = this->m_ImagesDeque->Undo();
- this->SetRedoImage(imageInfo.GetRegion());
+ ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
+ this->SetRedoImage(imageInfo->GetRegion());
+ std::cout<<"undooooooooooooooooooooooooooo"<<std::endl;
this->DrawUR(imageInfo);
}
//virtual
void ImageUndoRedo::Redo() {
- ImageInfoUR imageInfo = this->m_ImagesDeque->Redo();
+ ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
this->DrawUR(imageInfo);
}
void ImageUndoRedo::SetImage(vtkImageData *image) {
this->m_CurrentImage = image;
this->m_CurrentImage->Update();
this->m_OriginalImage = ImageType::New();
- this->m_OriginalImage->ShallowCopy(m_CurrentImage);
+ this->m_OriginalImage->DeepCopy(m_CurrentImage);
}
//virtual
void ImageUndoRedo::SetUndoImage(const RegionSType& region) {
region.minZ, region.maxZ);
extract->SetSampleRate(1, 1, 1);
extract->SetInput(this->m_OriginalImage);
- this->m_ImagesDeque->AddImageToUndoContainer(extract->GetOutput(), region);
- extract->Delete();
+ vtkImageData* imgResult = extract->GetOutput();
+ this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region);
}
//virtual
void ImageUndoRedo::SetRedoImage(const RegionSType& region) {
region.minZ, region.maxZ);
extract->SetSampleRate(1, 1, 1);
extract->SetInput(this->m_CurrentImage);
- this->m_ImagesDeque->AddImageToUndoContainer(extract->GetOutput(), region);
- extract->Delete();
+ vtkImageData* imgResult = extract->GetOutput();
+ this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region);
}
void ImageUndoRedo::SetOriginalImage(ImageType* img) {
this->m_OriginalImage = img;
this->m_CurrentImage = img;
}
//virtual
-void ImageUndoRedo::DrawUR(ImageInfoUR imageInfo) {
+void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
}
void SetOriginalImage(ImageType* img);
void SetCurrentImage(ImageType* img);
private:
- virtual void DrawUR(ImageInfoUR imageInfo);
+ virtual void DrawUR(ImageInfoUR* imageInfo);
};
zz=zz*zz;
if (_brushform==0)
{
- //this->CalculateMinMaxRegion(i,j,k); //DFCH
+ this->CalculateMinMaxRegion(i,j,k); //DFCH
_image->SetScalarComponentFromFloat (i,j,k, 0, value );
} else if (_brushform==1)
{
if ((xx+yy+zz)<=rr)
{
- //this->CalculateMinMaxRegion(i,j,k); //DFCH
+ this->CalculateMinMaxRegion(i,j,k); //DFCH
_image->SetScalarComponentFromFloat (i,j,k, 0, value );
}
} // _brushform
{
if (_usingAuxImageFill==true)
{
- //this->CalculateMinMaxRegion(px,py,pz); //DFCH
+ this->CalculateMinMaxRegion(px,py,pz); //DFCH
_auxImageFill->SetScalarComponentFromFloat (px, py, pz,0, 0);
}
_tmpDistfill=(px-_pxfill)*(px-_pxfill) + (py-_pyfill)*(py-_pyfill) + (pz-_pzfill)*(pz-_pzfill);
if ( _auxGrayLevelValidationFill==true )
{
- //this->CalculateMinMaxRegion(px,py,pz); //DFCH
+ this->CalculateMinMaxRegion(px,py,pz); //DFCH
_image->SetScalarComponentFromFloat (px,py,pz, 0, (float)_graylevel );
if (_countRecursiveFill< _limitRecursionFill)
{
if ((px>=_minX) && (px<=_maxX) && (py>=_minY) && (py<=_maxY) && (pz>=_minZ) && (pz<=_maxZ))
{
- //this->CalculateMinMaxRegion(px,py,pz); //DFCH
+ this->CalculateMinMaxRegion(px,py,pz); //DFCH
_auxImageFill->SetScalarComponentFromFloat (px, py, pz,0, 1);
}
}
}
//---------------------------------------------------------------------------
-/*void ManualPaintControler::SetImageUndo()
+void ManualPaintControler::SetImageUndo()
{
_manualPaintModel->SetUndoImage();
-}*/
+}
_tool = 0; // 0 pencil , 1 fill
_brushfilter = new BrushFilter();
_fillfilter = new FillFilter();
- //_imageUndoRedo = new ImageUndoRedo();
+ _imageUndoRedo = new ImageUndoRedo();
}
//---------------------------------------------------------------------------
void ManualPaintModel::SetImage(vtkImageData *image) {
_brushfilter->SetImage(image);
_fillfilter->SetImage(image);
- //_imageUndoRedo->SetImage(image);
+ std::cout<<"setIMAAAAAAGEEEEEE"<<std::endl;
+ _imageUndoRedo->SetImage(image);
}
//---------------------------------------------------------------------------
_fillfilter->GetScalarRange(range);
}
//---------------------------------------------------------------------------
-/*void ManualPaintModel::SetUndoImage() {
+void ManualPaintModel::SetUndoImage() {
RegionStructUR* region = NULL;
if (_tool == 0) {
region = this->_brushfilter->GetModifiedRegion();
//---------------------------------------------------------------------------
void ManualPaintModel::Undo() {
- //this->_imageUndoRedo->Undo();
-}*/
+ this->_imageUndoRedo->Undo();
+}
void SetRangeMin( int min );
void SetRangeMax( int max );
void GetScalarRange( double * range );
- //void SetUndoImage();//DFCH
- //void Undo();//DFCH
+ void SetUndoImage();//DFCH
+ void Undo();//DFCH
private:
int _tool;
BrushFilter *_brushfilter;
FillFilter *_fillfilter;
- //ImageUndoRedo *_imageUndoRedo;
+ ImageUndoRedo *_imageUndoRedo;
protected:
void SetRangeMax( int max );
void GetScalarRange( double * range);
-private:
- ManualPaintModel *_manualPaintModel;
-
protected:
+ ManualPaintModel *_manualPaintModel;
};
#include "baseFilterManualPaint.h"
baseFilterManualPaint::baseFilterManualPaint() {
- //_MRegion = new RegionStructUR();
- //CleanModifiedRegion();
+ _MRegion = new RegionStructUR();
+ CleanModifiedRegion();
_graylevel = 0.0;
_2D3D = 1; // 0 2D , 1 true 3D
_direction = 0; // 1 XZ , 0 YZ , 2 XY
void baseFilterManualPaint::GetScalarRange(double * range) {
range = this->_image->GetScalarRange();
}
-/*
+
RegionStructUR* baseFilterManualPaint::GetModifiedRegion() {
return (this->_MRegion);
} //DFCH
this->_MRegion->maxZ = k;
} //fi
}
-*/
+
void ResetGeneralMinMax();
void SetGeneralMinMax(int minX,int maxX,int minY,int maxY,int minZ,int maxZ);
void GetScalarRange( double * range );
- /* RegionStructUR* GetModifiedRegion();//DFCH
+ RegionStructUR* GetModifiedRegion();//DFCH
void CleanModifiedRegion();//DFCH
- void CalculateMinMaxRegion( const int& i, const int& j, const int& k);//DFCH*/
+ void CalculateMinMaxRegion( const int& i, const int& j, const int& k);//DFCH
virtual void Run();
private:
protected:
- //RegionStructUR *_MRegion; //Saves the last modified region (MinX, MaxX, MinY, MaxY, MinZ, MaxZ).
+ RegionStructUR *_MRegion; //Saves the last modified region (MinX, MaxX, MinY, MaxY, MinZ, MaxZ).
vtkImageData *_image;
int _direction;
int _px; // start point of the brush
_manualPaintControler = mpc;
_state = false;
_stateKey = false;
+ _stateMouse = false;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
bool vtkInteractorManualPaint::OnLeftButtonUp() {
- //_manualPaintControler->SetImageUndo();
+ if((_state == true) || (_stateKey == true))
+ _manualPaintControler->SetImageUndo();
_state = false;
return true;
}
private:
bool _state;
bool _stateKey;
+ bool _stateMouse;
ManualPaintControler *_manualPaintControler;
protected:
wxButton *btnCopy = new wxButton(panel, -1, _T("Copy"));
btnCopy->Disable();
wxButton *btnUndo = new wxButton(panel, -1, _T("Undo"));
- btnUndo->Disable();
+ //btnUndo->Disable();
Connect(
_sldBrushSize->GetId(),
//---------------------------------------------------------------------------
void wxManualPaintPanel::OnUndo(wxCommandEvent &event) {
- //this->_manualPaintModel->Undo();
+ this->_manualPaintModel->Undo();
}
//--------------------------------------------------------------------------------------------------------------------------------