#include "image3DDequeUR.h"
Image3DDequeUR::Image3DDequeUR() {
- this->m_currentPos = 0;
+ this->m_globalPath = "/tmp/";
+ this->m_currentPos = -1;
}
//virtual
Image3DDequeUR::~Image3DDequeUR() {
//virtual
void Image3DDequeUR::addImageToContainer(ImageType* img,
const RegionS& region) {
+ //managing memory
+ if (this->m_ImgDeque.size() > 0) {
+ this->m_ImgDeque.back().removeImageFromMemory();
+ this->m_ImgDeque.back().setStatus(false);
+ } //fi
+ //This is to take actual Date
+ 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);
+ //end
+ std::string aux(buffer);
+ std::string imageName = "img_" + aux;
+ ImageInfoUR imageInfo;
+ imageInfo.setImageName(imageName);
+ imageInfo.setImage(img);
+ imageInfo.setRegion(region);
+ imageInfo.setStatus(true);
+ //saving to disk
+ std::string fullpath = this->m_globalPath + imageName;
+ this->saveImageAsMHD(img, fullpath);
+ //Adding to deque
+ this->m_ImgDeque.push_back(imageInfo);
+ this->m_currentPos = this->m_ImgDeque.size() - 1;
+
}
//virtual
-void Image3DDequeUR::loadImageToPMemory() {
+void Image3DDequeUR::loadImageToPMemory(const unsigned int& index) {
+ creaImageIO::ImageReader reader;
+ std::string fullPath = this->m_globalPath
+ + this->m_ImgDeque[index].getImageName();
+ this->m_ImgDeque[index].setImage(reader.ReadImage(fullPath));
}
//virtual
-void Image3DDequeUR::removeImageFromPMemory() {
-
+void Image3DDequeUR::removeImageFromPMemory(const unsigned int& index) {
+ this->m_ImgDeque[index].removeImageFromMemory();
}
+//virtual
+void Image3DDequeUR::saveImageAsMHD(ImageType* img,
+ const std::string& filename) {
+ vtkMetaImageWriter* w = vtkMetaImageWriter::New();
+ w->SetInput(img);
+ w->SetCompression(false);
+ w->SetFileDimensionality(img->GetDataDimension());
+ w->SetFileName(filename.c_str());
+ w->Update();
+ w->Write();
+ w->Delete();
+}
+
+//ATENCIIIOOOON TIENE QUE HACER POP PARA PONER EL REDO
+//virtual
ImageType* Image3DDequeUR::undo() {
- return NULL;
+ if (this->m_currentPos == -1) {
+ return NULL;
+ } //fi
+ this->m_currentPos--;
+ return (NULL);
}
+//virtual
ImageType* Image3DDequeUR::redo() {
- return NULL;
+ if (this->m_currentPos == ( this->m_ImgDeque.size() - 1 )) {
+ return NULL;
+ } //fi
+ this->m_currentPos++;
+ return (NULL);
+}
+void Image3DDequeUR::setGlobalPath(const std::string& globalPath) {
+ this->m_globalPath = globalPath;
}
void Image3DDequeUR::removeFirstImageFromContainer() {
this->m_ImgDeque.pop_front();
this->m_ImgDeque.clear();
}
void Image3DDequeUR::cleanContainerFromIndex(const unsigned int& index) {
- for (int i = this->m_ImgDeque.size(); i >= index; i--) {
+ for (unsigned int i = this->m_ImgDeque.size(); i >= index; i--) {
this->m_ImgDeque.pop_back();
}
}
+std::string Image3DDequeUR::getGlobalPath() {
+ return (this->m_globalPath);
+}
#define IMAGE3DDEQUEUR_H_
#include "imageDequeUR.h"
+#include <ctime>
+#include "vtkMetaImageWriter.h"
+#include "creaImageIOImageReader.h"
class Image3DDequeUR : public ImageDequeUR
{
private:
ImageInfoDeque m_ImgDeque;
unsigned int m_currentPos;
+ std::string m_globalPath;
public:
Image3DDequeUR();
- virtual ~ImageDequeUR();
+ virtual ~Image3DDequeUR();
virtual void addImageToContainer(ImageType* img, const RegionS& region);
- virtual void loadImageToPMemory();
- virtual void removeImageFromPMemory();
+ virtual void loadImageToPMemory( const unsigned int& index );
+ virtual void removeImageFromPMemory( const unsigned int& index );
+ virtual void saveImageAsMHD( ImageType* img, const std::string& filename );
virtual ImageType* undo();
virtual ImageType* redo();
+ void setGlobalPath( const std::string& globalPath );
void removeFirstImageFromContainer();
void removeLastImageFromContainer();
void cleanContainer();
+ std::string getGlobalPath( );
private:
void cleanContainerFromIndex(const unsigned int& index);
};
ImageInfoUR::~ImageInfoUR()
{
- this->deleteImage();
+ this->removeImageFromMemory();
}
void ImageInfoUR::setImageName(const std::string &imgName)
{
this->m_Region = region;
}
-void ImageInfoUR::setStatus(bool onDisk)
+void ImageInfoUR::setStatus(const bool& onMemory)
{
- this->m_OnDisk = onDisk;
+ this->m_OnMemory = onMemory;
}
void ImageInfoUR::setImage(vtkImageData* img)
{
}
bool ImageInfoUR::getStatus()
{
- return( this->m_OnDisk );
+ return( this->m_OnMemory );
}
-void ImageInfoUR::deleteImage()
+void ImageInfoUR::removeImageFromMemory()
{
this->m_Image->Delete();
}