]> Creatis software - creaMaracasVisu.git/commitdiff
DFCH: UndoRedo + ManualPaint - Code update. Undo beta1 working :) :) :)
authorDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Thu, 27 Oct 2011 18:41:53 +0000 (18:41 +0000)
committerDiego Caceres <Diego.Caceres@creatis.insa-lyon.fr>
Thu, 27 Oct 2011 18:41:53 +0000 (18:41 +0000)
14 files changed:
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageDequeUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/managerUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/regionStructUR.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/baseFilterManualPaint.cpp
lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/baseFilterManualPaint.h

index 10de209d1616c468e91738390a0487b77ddf5683..a497b1673450b0e029bfc3041b8c1a89704acf3f 100755 (executable)
@@ -12,13 +12,13 @@ Image3DDequeUR::~Image3DDequeUR() {
 
 }
 //virtual
-void Image3DDequeUR::AddImageToUndoContainer(ImageType* img,
+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
+        this->m_ImgUndoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
+        } //fi
+       //Adding image
        ImageInfoUR* imageInfo = new ImageInfoUR();
        imageInfo->SetImageName(
                        this->GetImageName(this->m_ImgUndoDeque.size(), true));
@@ -31,14 +31,13 @@ void Image3DDequeUR::AddImageToUndoContainer(ImageType* img,
        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
-void Image3DDequeUR::AddImageToRedoContainer(ImageType* img,
+void Image3DDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img,
                const RegionS& region) {
        //managing memory
-       if (this->m_ImgRedoDeque.size() > 0) {
+       /*if (this->m_ImgRedoDeque.size() > 0) {
                this->m_ImgRedoDeque.back()->RemoveImageFromMemory(this->m_GlobalPath);
        } //fi
          //adding image
@@ -50,7 +49,7 @@ void Image3DDequeUR::AddImageToRedoContainer(ImageType* img,
        imageInfo->SaveImageAsMHD(this->m_GlobalPath);
        //Adding to deque
        this->m_ImgRedoDeque.push_back(imageInfo);
-       this->m_CurrentUndoPos = this->m_ImgRedoDeque.size() - 1;
+       this->m_CurrentUndoPos = this->m_ImgRedoDeque.size() - 1;*/
 }
 //virtual
 void Image3DDequeUR::CleanUndoContainerFromIndex(const int& index) {
@@ -71,19 +70,21 @@ void Image3DDequeUR::CleanRedoContainerFromIndex(const int& index) {
 
 //virtual
 ImageInfoUR* Image3DDequeUR::Undo() {
-       ImageInfoUR* imgRet = new ImageInfoUR();
+       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
+                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
-                       std::string fullPath = this->m_GlobalPath
+                       StringType fullPath = this->m_GlobalPath
                                        + this->m_ImgUndoDeque[m_CurrentUndoPos]->GetImageName();
                        this->m_ImgUndoDeque[m_CurrentUndoPos]->LoadImageMHDToMemory(
                                        this->m_GlobalPath);
@@ -138,15 +139,15 @@ void Image3DDequeUR::CleanContainers() {
        this->m_ImgUndoDeque.clear();
 }
 
-void Image3DDequeUR::SetGlobalPath(const std::string& globalPath) {
+void Image3DDequeUR::SetGlobalPath(const StringType& globalPath) {
        this->m_GlobalPath = globalPath;
 }
 
-std::string Image3DDequeUR::GetGlobalPath() {
+StringType Image3DDequeUR::GetGlobalPath() {
        return (this->m_GlobalPath);
 }
 
-std::string Image3DDequeUR::GetImageName(const int & pos, const bool& undo) {
+StringType Image3DDequeUR::GetImageName(const int & pos, const bool& undo) {
 //Giving a name to an image using the date and time
        if (this->m_IDImages.empty()) {
                time_t rawtime;
@@ -155,21 +156,19 @@ std::string Image3DDequeUR::GetImageName(const int & pos, const bool& undo) {
                time(&rawtime);
                timeinfo = localtime(&rawtime);
                strftime(buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo);
-               std::string date(buffer);
-               std::string aux(buffer);
+               StringType date(buffer);
+               StringType aux(buffer);
                this->m_IDImages = "img_" + aux;
        }
        std::stringstream ss; //create a stringstream
        ss << pos; //add number to the stream
-       std::string imgType;
+       StringType imgType;
        if (undo) {
                imgType = "undo";
-       }
-       else
-       {
+       } else {
                imgType = "redo";
        }
-       std::string imageName = this->m_IDImages + imgType + ss.str();
+       StringType imageName = this->m_IDImages + imgType + ss.str();
        imageName.append(".mhd");
        return (imageName);
 }
index 414f33687c605ff7b8fa4736b195983742ca9052..63aaad24975bd6beed6f93cbc165bfc78b6f5a27 100755 (executable)
 #include "imageDequeUR.h"
 #include <ctime>
 
-
 class Image3DDequeUR: public ImageDequeUR {
 private:
        ImageInfoDeque m_ImgUndoDeque;
        ImageInfoDeque m_ImgRedoDeque;
        int m_CurrentUndoPos;
        int m_CurrentRedoPos;
-       std::string m_GlobalPath;
-       std::string m_IDImages;
+       StringType m_GlobalPath;
+       StringType m_IDImages;
 public:
        Image3DDequeUR();
        virtual ~Image3DDequeUR();
-       void SetGlobalPath(const std::string& globalPath);
-       std::string GetGlobalPath();
-       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);
+       void SetGlobalPath(const StringType& globalPath);
+       StringType GetGlobalPath();
+       StringType GetImageName(const int & pos, const bool& undo);
+       virtual void AddImageToUndoContainer(VTKImageDataPointerType img,
+                       const RegionS& region);
+       virtual void AddImageToRedoContainer(VTKImageDataPointerType img,
+                       const RegionS& region);
        virtual void CleanUndoContainerFromIndex(const int& index);
        virtual void CleanRedoContainerFromIndex(const int& index);
        virtual void CleanContainers();
index 66a3240cc235cc59a96d0b9d701fc860752731b5..25e95be01532547da4861d54e995f301aa830eb6 100755 (executable)
@@ -6,10 +6,10 @@ ImageDequeUR::ImageDequeUR() {
 ImageDequeUR::~ImageDequeUR() {
 
 }
-void ImageDequeUR::AddImageToUndoContainer(ImageType* img,
+void ImageDequeUR::AddImageToUndoContainer(VTKImageDataPointerType img,
                const RegionS& region) {
 }
-void ImageDequeUR::AddImageToRedoContainer(ImageType* img,
+void ImageDequeUR::AddImageToRedoContainer(VTKImageDataPointerType img,
                const RegionS& region) {
 }
 void ImageDequeUR::CleanUndoContainerFromIndex(const int& index) {
index 5367ce6afa66690f3616088fbac52e94b28def3b..761f56a0a5c9a7382be08f1634856a6edcf35820 100755 (executable)
 #include <string>
 #include <deque>
 #include <vtkImageData.h>
+#include <vtkSmartPointer.h>
 #include "imageInfoUR.h"
 #include "regionStructUR.h"
 
 typedef std::deque<ImageInfoUR*> ImageInfoDeque;
-typedef vtkImageData ImageType;
+typedef vtkSmartPointer<vtkImageData> VTKImageDataPointerType;
 typedef RegionStructUR RegionS;
+typedef std::string StringType;
 
 class ImageDequeUR {
 public:
        ImageDequeUR();
        virtual ~ImageDequeUR();
-       virtual void AddImageToUndoContainer(ImageType* img, const RegionS& region);
-       virtual void AddImageToRedoContainer(ImageType* img, const RegionS& region);
+       virtual void AddImageToUndoContainer(VTKImageDataPointerType img,
+                       const RegionS& region);
+       virtual void AddImageToRedoContainer(VTKImageDataPointerType img,
+                       const RegionS& region);
        virtual void CleanUndoContainerFromIndex(const int& index);
        virtual void CleanRedoContainerFromIndex(const int& index);
        virtual void CleanContainers();
index 18c255eeae6ce381f34d7cc203bf4fe96792cf06..3d1093752f0a67b7085eefb0e35d7e74bcd06568 100755 (executable)
@@ -7,7 +7,6 @@
 #include "imageInfoUR.h"
 
 ImageInfoUR::ImageInfoUR() {
-       this->m_Image = NULL;
        this->m_OnMemory = false;
        this->m_OnDisk = false;
 }
@@ -15,7 +14,7 @@ ImageInfoUR::ImageInfoUR() {
 ImageInfoUR::~ImageInfoUR() {
 }
 
-void ImageInfoUR::SetImageName(const std::string &imgName) {
+void ImageInfoUR::SetImageName(const StringType &imgName) {
        this->m_ImageName = imgName;
 }
 void ImageInfoUR::SetRegion(const RegionStructUR &region) {
@@ -24,39 +23,42 @@ void ImageInfoUR::SetRegion(const RegionStructUR &region) {
 void ImageInfoUR::SetStatus(const bool& onMemory) {
        this->m_OnMemory = onMemory;
 }
-void ImageInfoUR::SetImage(vtkImageData* img) {
+void ImageInfoUR::SetImage(VTKImageDataPointerType img) {
        this->m_Image = img;
        this->SetStatus(true);
 }
-std::string ImageInfoUR::GetImageName() {
+ImageInfoUR::StringType ImageInfoUR::GetImageName() {
        return (this->m_ImageName);
 }
+
+ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetImage() {
+       return (this->m_Image);
+}
+
 RegionStructUR ImageInfoUR::GetRegion() {
        return (this->m_Region);
 }
 bool ImageInfoUR::GetStatus() {
        return (this->m_OnMemory);
 }
-void ImageInfoUR::RemoveImageFromMemory(const std::string& gPath) {
+void ImageInfoUR::RemoveImageFromMemory(const StringType& gPath) {
        if (!this->m_OnDisk) {
                this->SaveImageAsMHD(gPath);
        }
        this->m_Image = NULL;
        this->SetStatus(false);
 }
-void ImageInfoUR::LoadImageMHDToMemory(const std::string& gPath) {
-       std::string filename = gPath + this->m_ImageName;
-       vtkSmartPointer<vtkMetaImageReader> reader = vtkSmartPointer<
-                       vtkMetaImageReader>::New();
+void ImageInfoUR::LoadImageMHDToMemory(const StringType& gPath) {
+       StringType filename = gPath + this->m_ImageName;
+       VTKMetaImageReaderPointerType reader = VTKMetaImageReaderPointerType::New();
        reader->SetFileName(filename.c_str());
        this->m_Image = reader->GetOutput();
        this->m_OnMemory = true;
 }
-void ImageInfoUR::SaveImageAsMHD(const std::string& gPath) {
+void ImageInfoUR::SaveImageAsMHD(const StringType& gPath) {
        this->m_OnDisk = true;
-       std::string filename = gPath + this->m_ImageName;
-       vtkSmartPointer<vtkMetaImageWriter> w =
-                       vtkSmartPointer<vtkMetaImageWriter>::New();
+       StringType filename = gPath + this->m_ImageName;
+       VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
        w->SetInput(this->m_Image);
        w->SetCompression(false);
        w->SetFileDimensionality(this->m_Image->GetDataDimension());
@@ -64,7 +66,6 @@ void ImageInfoUR::SaveImageAsMHD(const std::string& gPath) {
        w->Write();
 }
 
-void ImageInfoUR::RemoveImageFromDisk(const std::string& gPath)
-{
+void ImageInfoUR::RemoveImageFromDisk(const StringType& gPath) {
 
 }
index 9045e8f113d9afe420d4eb948280694767d4d86f..d55baf49708e53a9af820506bc74c760d9743d81 100755 (executable)
 #include "regionStructUR.h"
 
 class ImageInfoUR {
-private:
-       vtkImageData* m_Image;
-       std::string m_ImageName;
-       RegionStructUR m_Region;
-       bool m_OnMemory;
-       bool m_OnDisk;
+
+public:
+       typedef vtkSmartPointer<vtkImageData> VTKImageDataPointerType;
+       typedef vtkSmartPointer<vtkMetaImageReader> VTKMetaImageReaderPointerType;
+       typedef vtkSmartPointer<vtkMetaImageWriter> VTKMetaImageWriterPointerType;
+       typedef std::string StringType;
 public:
        ImageInfoUR();
        virtual ~ImageInfoUR();
-       void SetImageName(const std::string &imgName);
+       void SetImageName(const StringType &imgName);
        void SetRegion(const RegionStructUR &region);
        void SetStatus(const bool& onMemory);
-       void SetImage(vtkImageData* img);
-       void RemoveImageFromMemory(const std::string& gPath);
-       void LoadImageMHDToMemory(const std::string& gPath);
-       void SaveImageAsMHD(const std::string& gPath);
-       void RemoveImageFromDisk(const std::string& gPath);
-       std::string GetImageName();
+       void SetImage(VTKImageDataPointerType img);
+       void RemoveImageFromMemory(const StringType& gPath);
+       void LoadImageMHDToMemory(const StringType& gPath);
+       void SaveImageAsMHD(const StringType& gPath);
+       void RemoveImageFromDisk(const StringType& gPath);
+       VTKImageDataPointerType GetImage();
+       StringType GetImageName();
        RegionStructUR GetRegion();
        bool GetStatus();
+
+private:
+       VTKImageDataPointerType m_Image;
+       StringType m_ImageName;
+       RegionStructUR m_Region;
+       bool m_OnMemory;
+       bool m_OnDisk;
+
 };
 
 #endif /* IMAGEINFO_H_ */
index a459e8598a21a793d1986f6758d9f91c56a9ae94..8864148e34df0ea8c7962e50bd881635c88a5776 100755 (executable)
@@ -17,51 +17,69 @@ ImageUndoRedo::~ImageUndoRedo() {
 //virtual
 void ImageUndoRedo::Undo() {
        ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
-       this->SetRedoImage(imageInfo->GetRegion());
-       std::cout<<"undooooooooooooooooooooooooooo"<<std::endl;
-       this->DrawUR(imageInfo);
+       if (imageInfo != NULL)
+       {
+               this->SetRedoImage(imageInfo->GetRegion());
+               this->DrawUR(imageInfo);
+       }
 }
 //virtual
 void ImageUndoRedo::Redo() {
        ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
        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 = VTKImageDataPointerType::New();
        this->m_OriginalImage->DeepCopy(m_CurrentImage);
 }
 //virtual
 void ImageUndoRedo::SetUndoImage(const RegionSType& region) {
-       vtkSmartPointer<vtkExtractVOI> extract =
-                       vtkSmartPointer<vtkExtractVOI>::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();
+       VTKImageDataPointerType imgResult = this->GetImageRegion(region,
+                       this->m_OriginalImage);
        this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region);
 }
 //virtual
 void ImageUndoRedo::SetRedoImage(const RegionSType& region) {
-       vtkSmartPointer<vtkExtractVOI> extract =
-                       vtkSmartPointer<vtkExtractVOI>::New();
+       VTKImageDataPointerType imgResult = this->GetImageRegion(region,
+                       this->m_CurrentImage);
+       this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region);
+}
+
+ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
+               const RegionSType& region, VTKImageDataPointerType img) {
+       VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New();
+       VTKImageDataPointerType imgResult = VTKImageDataPointerType::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);
+       extract->SetInput(this->m_OriginalImage);
+       imgResult = extract->GetOutput();
+       return (imgResult);
 }
-void ImageUndoRedo::SetOriginalImage(ImageType* img) {
+
+void ImageUndoRedo::SetOriginalImage(VTKImageDataPointerType img) {
        this->m_OriginalImage = img;
 }
-void ImageUndoRedo::SetCurrentImage(ImageType* img) {
+void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
        this->m_CurrentImage = img;
 }
 //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);
+                       } //rof
+               } //rof
+       } //rof
+       this->m_CurrentImage->Modified();
 }
 
index f38de3d787b84cad3a78aec9be263e07d58c3c1e..087fbe5d81073321c23e91bb43832a539c97eb7b 100755 (executable)
@@ -9,30 +9,30 @@
 #define IMAGEUNDOREDO_H_
 
 #include "managerUR.h"
-#include <vtkExtractVOI.h>
-#include <vtkSmartPointer.h>
 
 class ImageUndoRedo: public ManagerUR {
 
-private:
-
-       IDequeType* m_ImagesDeque;
-       ImageType* m_OriginalImage;
-       ImageType* m_CurrentImage;
-
 public:
        ImageUndoRedo();
        virtual ~ImageUndoRedo();
        virtual void Undo();
        virtual void Redo();
-       virtual void SetImage(vtkImageData *image);
+       virtual void SetImage(VTKImageDataPointerType image);
        virtual void SetUndoImage(const RegionSType& region);
        virtual void SetRedoImage(const RegionSType& region);
-       void SetOriginalImage(ImageType* img);
-       void SetCurrentImage(ImageType* img);
-private:
+       void SetOriginalImage(VTKImageDataPointerType img);
+       void SetCurrentImage(VTKImageDataPointerType img);
+       VTKImageDataPointerType GetImageRegion(const RegionSType& region,
+                       VTKImageDataPointerType img);
+protected:
        virtual void DrawUR(ImageInfoUR* imageInfo);
 
+protected:
+
+       IDequeType* m_ImagesDeque;
+       VTKImageDataPointerType m_OriginalImage;
+       VTKImageDataPointerType m_CurrentImage;
+
 };
 
 #endif /* IMAGEUNDOREDO_H_ */
index d14ba32ef34e33bdd8bb5559793f037bcf143247..af4691157ebfb00058566d25b2c0a75f0e532a53 100755 (executable)
 #include <iostream>
 #include <string>
 #include <vtkImageData.h>
+#include <vtkSmartPointer.h>
+#include <vtkExtractVOI.h>
 
 #include "image3DDequeUR.h"
 
-typedef Image3DDequeUR IDequeType;
-typedef RegionStructUR RegionSType;
-typedef vtkImageData ImageType;
-
 class ManagerUR {
+public:
+       typedef Image3DDequeUR IDequeType;
+       typedef RegionStructUR RegionSType;
+       typedef vtkSmartPointer<vtkImageData> VTKImageDataPointerType;
+       typedef vtkSmartPointer<vtkExtractVOI> VTKExtractVOIPointerType;
+       typedef std::string StringType;
 public:
        ManagerUR();
        virtual ~ManagerUR();
@@ -27,7 +31,7 @@ public:
        virtual void Redo();
        virtual void SetUndoImage(const RegionSType& region);
        virtual void SetRedoImage(const RegionSType& region);
-private:
+protected:
        virtual void DrawUR(ImageInfoUR imageInfo);
 
 };
index 7cd244b42e01ed1c53a76fc7c4d33a233723d027..76e4a11ae173f9d20bae1a775dbecc061b15c39d 100755 (executable)
@@ -17,6 +17,7 @@ struct RegionStructUR{
        int maxY;
        int minZ;
        int maxZ;
+       float value;
 };
 
 
index d58d6db7d528ca24b7ef322d3fb07e85a81bbd94..bdbd267d4bdc75a3424c09640b00b6e91342c9b5 100644 (file)
-
 #include "BrushFilter.h"
 
-
-
-BrushFilter::BrushFilter()
-{
-    _brushsize          =   1;
-    _brushform          =   0;      // 0 rectangle-box  ,   1 circle-sphere
-    _brushtool          =   0;      // 0 pencil         ,   1 fill
+BrushFilter::BrushFilter() {
+       _brushsize = 1;
+       _brushform = 0; // 0 rectangle-box  ,   1 circle-sphere
+       _brushtool = 0; // 0 pencil         ,   1 fill
 }
 
 //---------------------------------------------------------------------------
-BrushFilter::~BrushFilter()  // virtual
+BrushFilter::~BrushFilter() // virtual
 {
 }
 
 //---------------------------------------------------------------------------
-void BrushFilter::FindMinMaxBrush(int &minX,int &maxX,int &minY,int &maxY,int &minZ,int &maxZ,int &size)
-{
-        size = _brushsize-1;
-        minX = _px-size;
-        maxX = _px+size;
-        minY = _py-size;
-        maxY = _py+size;
-        minZ = _pz-size;
-        maxZ = _pz+size;
-
-        if (_2D3D==0) //2D
-        {
-            if (_direction==0)  // YZ
-            {
-                minX=_px;
-                maxX=_px;
-            }
-            if (_direction==1) // XZ
-            {
-                minY=_py;
-                maxY=_py;
-            }
-            if (_direction==2) // XY
-            {
-                minZ=_pz;
-                maxZ=_pz;
-            }
-        }
-
-        if (_2D3D==1) // 3D
-        {
-        }
-
-       if (minX<_minX)
-        {
-               minX=_minX;
-        }
-
-       if (minY<_minY)
-        {
-               minY=_minY;
-        }
-
-       if (minZ<_minZ)
-        {
-               minZ=_minZ;
-        }
-
-       if (maxX>_maxX)
-        {
-               maxX=_maxX;
-        }
-
-       if (maxY>_maxY)
-        {
-               maxY=_maxY;
-        }
-
-       if (maxZ>_maxZ)
-        {
-               maxZ=_maxZ;
-        }
+void BrushFilter::FindMinMaxBrush(int &minX, int &maxX, int &minY, int &maxY,
+               int &minZ, int &maxZ, int &size) {
+       size = _brushsize - 1;
+       minX = _px - size;
+       maxX = _px + size;
+       minY = _py - size;
+       maxY = _py + size;
+       minZ = _pz - size;
+       maxZ = _pz + size;
+
+       if (_2D3D == 0) //2D
+                       {
+               if (_direction == 0) // YZ
+                               {
+                       minX = _px;
+                       maxX = _px;
+               }
+               if (_direction == 1) // XZ
+                               {
+                       minY = _py;
+                       maxY = _py;
+               }
+               if (_direction == 2) // XY
+                               {
+                       minZ = _pz;
+                       maxZ = _pz;
+               }
+       }
+
+       if (_2D3D == 1) // 3D
+                       {
+       }
+
+       if (minX < _minX) {
+               minX = _minX;
+       }
+
+       if (minY < _minY) {
+               minY = _minY;
+       }
+
+       if (minZ < _minZ) {
+               minZ = _minZ;
+       }
+
+       if (maxX > _maxX) {
+               maxX = _maxX;
+       }
+
+       if (maxY > _maxY) {
+               maxY = _maxY;
+       }
+
+       if (maxZ > _maxZ) {
+               maxZ = _maxZ;
+       }
 
        //--
-       SetGeneralMinMax(minX,maxX,minY,maxY,minZ,maxZ);
+       SetGeneralMinMax(minX, maxX, minY, maxY, minZ, maxZ);
 }
 
-
-
 //---------------------------------------------------------------------------
-void BrushFilter::Run()  // virtual
+void BrushFilter::Run() // virtual
 {
-    if (_image!=NULL)
-    {
-        float value=(float)_graylevel;
-        int i,j,k;
-
-       int size;
-        int minX,maxX,minY,maxY,minZ,maxZ;
-        FindMinMaxBrush(minX,maxX,minY,maxY,minZ,maxZ,size);
-
-        double xx,yy,zz,rr=size*size;
-
-        for (i=minX; i<=maxX; i++)
-        {
-            xx=_px-i;
-            xx=xx*xx;
-            for (j=minY; j<=maxY; j++)
-            {
-                yy=_py-j;
-                yy=yy*yy;
-                for (k=minZ; k<=maxZ; k++)
-                {
+       if (_image != NULL)
+       {
+               float value = (float) _graylevel;
+               this->_MRegion->value = (float) _graylevel;
+               int i, j, k;
+
+               int size;
+               int minX, maxX, minY, maxY, minZ, maxZ;
+               FindMinMaxBrush(minX, maxX, minY, maxY, minZ, maxZ, size);
+
+               double xx, yy, zz, rr = size * size;
+
+               for (i = minX; i <= maxX; i++) {
+                       xx = _px - i;
+                       xx = xx * xx;
+                       for (j = minY; j <= maxY; j++) {
+                               yy = _py - j;
+                               yy = yy * yy;
+                               for (k = minZ; k <= maxZ; k++) {
 //                    if ((i>=_minX) && (i<=_maxX) && (j>=_minY) && (j<=_maxY) && (k>=_minZ) && (k<=_maxZ))
 //                    {
 
-                         float scalarComponent = _image->GetScalarComponentAsFloat(i,j,k, 0);
-                         if( ( this->GetRangeMin() <=  scalarComponent ) && ( scalarComponent <=  this->GetRangeMax() ) )
-                         {
-                        zz=_pz-k;
-                        zz=zz*zz;
-                        if (_brushform==0)
-                        {
-                               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
-                                _image->SetScalarComponentFromFloat (i,j,k, 0, value );
-                            }
-                        } // _brushform
-                         } //   GetRangeMin && GetRangeMax
+                                       float scalarComponent = _image->GetScalarComponentAsFloat(i,
+                                                       j, k, 0);
+                                       if ((this->GetRangeMin() <= scalarComponent)
+                                                       && (scalarComponent <= this->GetRangeMax())) {
+                                               zz = _pz - k;
+                                               zz = zz * zz;
+                                               if (_brushform == 0) {
+                                                       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
+                                                               _image->SetScalarComponentFromFloat(i, j, k, 0,
+                                                                               value);
+                                                       }
+                                               } // _brushform
+                                       } //   GetRangeMin && GetRangeMax
 
 //                    } //if _minX _maxX _minY _maxY _minZ _maxZ
 
-                }//k
-            }//j
-        }//i
-        _image->Modified();
-    } else  {
-        printf("ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
-    } // _image
+                               } //k
+                       } //j
+               } //i
+               _image->Modified();
+       } else {
+               printf(
+                               "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
+       } // _image
 }
 
-
 //---------------------------------------------------------------------------
-void BrushFilter::SetBrushSize( int brushsize )
-{
-    _brushsize = brushsize;
+void BrushFilter::SetBrushSize(int brushsize) {
+       _brushsize = brushsize;
 }
 
 //---------------------------------------------------------------------------
-void BrushFilter::SetBrushForm( int brushform )
-{
-    _brushform = brushform;
+void BrushFilter::SetBrushForm(int brushform) {
+       _brushform = brushform;
 }
 
 //---------------------------------------------------------------------------
-void BrushFilter::SetBrushTool( int brushtool )
-{
-    _brushtool = brushtool;
+void BrushFilter::SetBrushTool(int brushtool) {
+       _brushtool = brushtool;
 }
 
 //---------------------------------------------------------------------------
-void BrushFilter::SetRangeMin( int min )
-{
-       _RangeMin  = min;
+void BrushFilter::SetRangeMin(int min) {
+       _RangeMin = min;
 }
 
 //---------------------------------------------------------------------------
-void BrushFilter::SetRangeMax( int max )
-{
-       _RangeMax  = max;
+void BrushFilter::SetRangeMax(int max) {
+       _RangeMax = max;
 }
 
 //---------------------------------------------------------------------------
-int BrushFilter::GetRangeMin( )
-{
-       return( _RangeMin );
+int BrushFilter::GetRangeMin() {
+       return (_RangeMin);
 }
 
 //---------------------------------------------------------------------------
-int BrushFilter::GetRangeMax(  )
-{
-       return( _RangeMax );
+int BrushFilter::GetRangeMax() {
+       return (_RangeMax);
 }
 
-
index 694c6abc8d92e852c5f4374795b4d78d0986ded4..9dc1cb43686f4e2334b74b99411d9c3ba2019a2a 100644 (file)
@@ -86,6 +86,7 @@ void FillFilter::Run() // virtual
 //---------------------------------------------------------------------------
 void FillFilter::FillToolRecursive(int px,int py, int pz)
 {
+       this->_MRegion->value = (float) _graylevel;
     _countRecursiveFill++;
 
     _countProgressingFill++;
index 3fda57bf49cc39b76705d4eb50672034f39a1fa6..e6b2fd85b2302a9481ebdb15240da3f1a68b4cfa 100644 (file)
@@ -114,30 +114,34 @@ RegionStructUR* baseFilterManualPaint::GetModifiedRegion() {
        return (this->_MRegion);
 } //DFCH
 void baseFilterManualPaint::CleanModifiedRegion() {
-       this->_MRegion->minX = 0;
-       this->_MRegion->maxX = 0;
-       this->_MRegion->minY = 0;
-       this->_MRegion->maxY = 0;
-       this->_MRegion->minZ = 0;
-       this->_MRegion->maxZ = 0;
+       int min = std::numeric_limits<int>::min();
+       int max = std::numeric_limits<int>::max();
+       this->_MRegion->minX = max;
+       this->_MRegion->maxX = min;
+       this->_MRegion->minY = max;
+       this->_MRegion->maxY = min;
+       this->_MRegion->minZ = max;
+       this->_MRegion->maxZ = min;
 } //DFCH
 void baseFilterManualPaint::CalculateMinMaxRegion(const int& i, const int& j,
                const int& k) {
-       if (i < this->_MRegion->minX) {
+       if (i <= this->_MRegion->minX) {
                this->_MRegion->minX = i;
-       } else {
-               this->_MRegion->maxX = i;
        } //fi
-       if (j < this->_MRegion->minY) {
+       if (i > this->_MRegion->maxX) {
+               this->_MRegion->maxX = i;
+       } //esle
+       if (j <= this->_MRegion->minY) {
                this->_MRegion->minY = j;
-       } else {
-               this->_MRegion->maxY = j;
        } //fi
-       if (k < this->_MRegion->minZ) {
+       if (j > this->_MRegion->maxY) {
+               this->_MRegion->maxY = j;
+       } //esle
+       if (k <= this->_MRegion->minZ) {
                this->_MRegion->minZ = k;
-       } else {
-               this->_MRegion->maxZ = k;
        } //fi
+       if (k > this->_MRegion->maxZ) {
+               this->_MRegion->maxZ = k;
+       } //esle
 }
 
-
index ad3f662ea1861e0c3642bf5d7ba4d454fc13c8d1..71e53988eea3a960a563f9fed2235ea85f6342a4 100644 (file)
@@ -2,6 +2,7 @@
 #define _BASE_FILTER_MANUAL_PAINT_H_
 
 #include <vtkImageData.h>
+#include <limits>
 #include "regionStructUR.h"
 
 class baseFilterManualPaint  {