]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOGimmickView.cpp
Validation changed and added number of children to the database.
[creaImageIO.git] / src2 / creaImageIOGimmickView.cpp
index 9d2b3dcb199d5a61c17dcb10a0bfdcf1b4bde850..16ad8ff9ae8926e23b522ab9ad520810ce983808 100644 (file)
@@ -8,6 +8,54 @@ namespace fs = boost::filesystem;
 namespace creaImageIO
 {
 
+       ///Class used to represent the actual state of the image selected and to perform comparisons on its values
+  class ImageExtent
+  {
+  public:
+    ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t)
+       {
+                sscanf(x.c_str(),"%d",&mExtent[0]);
+                sscanf(y.c_str(),"%d",&mExtent[1]);
+                sscanf(z.c_str(),"%d",&mExtent[2]);
+                sscanf(t.c_str(),"%d",&mExtent[3]);
+                if(x==""){mExtent[0]=1;}
+            if(y==""){mExtent[1]=1;}
+            if(z==""){mExtent[2]=1;}
+                if(t==""){mExtent[3]=1;}
+
+                if (mExtent[3]>1) mDim=4;
+                else if (mExtent[2]>1) mDim=3;
+            else if (mExtent[1]>1) mDim=2;
+            else if (mExtent[0]>1) mDim=1;
+                else mDim=0;
+       }
+       
+
+       ///Clears the extent
+    void Clear() { mExtent[0] = mExtent[1] = mExtent[2] = mExtent[3] = 1; }
+
+       ///Returns true if the two extents are compatible
+    bool IsCompatible( const ImageExtent& );
+
+       ///Adds the extent passed as a parameter to the current extent
+    void Add ( const ImageExtent& );
+               
+       ///Returns the ieth position of the extent
+    int Get(int i) { return mExtent[i]; }
+    
+       ///Returns the dimension of the current image
+    void SetDimension(int dim) { mDim=dim; }
+
+       ///Returns the dimension of the current image
+    int GetDimension() { return mDim; }
+
+  private:
+    int mExtent[4];
+    int mDim;
+  };
+
+  //======================================================================
+
   //======================================================================
   // CTor
   GimmickView::GimmickView(Gimmick* gimmick, int threads)
@@ -19,7 +67,7 @@ namespace creaImageIO
        // Anciently started the threads ...
     // Threads now automatically start at first image request
     //mReader.Start();
-
+       
   }
   //======================================================================
 
@@ -38,10 +86,7 @@ namespace creaImageIO
   /// 
   void GimmickView::Initialize()
   {
-         row="";
-         col="";
-         plane="";
-         selectionSize=0;
+       mImageExtent=0;
   }
   //======================================================================
   
@@ -84,152 +129,129 @@ namespace creaImageIO
   }
   //======================================================================
   /// Clears the status and begins a new selection process
-  void GimmickView::ClearStatus()
+  void GimmickView::ResetExtent()
   {
-         row="";
-         col="";
-         plane="";
-         selectionSize=0;
+         if(mImageExtent!=0)
+         {
+         mImageExtent=0;
+         }
          valid=true;
   }
 
 
-  class ImageExtent
+  //======================================================================
+  
+  //======================================================================
+  bool ImageExtent::IsCompatible(const ImageExtent& ie)
   {
-  public:
-    ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t);
-
-    void Clear() { mExtent[0] = mExtent[1] = mExtent[2] = mExtent[3] = 1; }
-
-    bool IsCompatible( const ImageExtent& );
-
-    void Add ( const ImageExtent& );
-               
-    int Get(int i) { return mExtent[i]; }
-    
-    int GetDimension() { return mDim; }
-
-  private:
-    int mExtent[4];
-    int mDim;
-  };
+         bool compatible=true;
+         ImageExtent * extent= (ImageExtent*)&ie;
+         if((*extent).Get(0)!=Get(0)
+                || (*extent).Get(1)!=Get(1))
+         {
+                 compatible=false;
+         }
+         return compatible;
+  }
 
+  //======================================================================
+  
+  //======================================================================
+  void ImageExtent::Add(const ImageExtent& ie)
+  {
+         ImageExtent * extent= (ImageExtent*)&ie;
+         mExtent[2]+=(*extent).Get(2);
+         SetDimension(3);
+  }
 
   //======================================================================
   ///Validates the dimension compliance of the images with the maximum and 
   ///minimum given, and between their sizes
   bool GimmickView::ValidateSelected (tree::Node* sel, int min_dim, int max_dim)
   {
-       GimmickMessage(2,"Validating selected"<<std::endl);
+       GimmickDebugMessage(2,"Validating selected"<<std::endl);
        std::string mMessage;
+       
        if(sel==0)
        {
                mMessage="Cannot have 0 images selected!";
                valid=false;
        }
-       if(valid)
+       else
        {
-       selectionSize++;
-         /*// EED validate all
-         mValidationSignal(valid);
-         return valid;*/
-         
-       int level;
-       
-       
-       if(row.compare("")==0 || col.compare("")==0)
+       ImageExtent* ie=new ImageExtent((*sel).GetAttribute("D0028_0010"),
+                                                (*sel).GetAttribute("D0028_0011"),
+                                                                        (*sel).GetAttribute("D0028_0012"), 
+                                                                        "");
+       if(mImageExtent==0)
        {
-               row=(*sel).GetAttribute("D0028_0010");
-               col=(*sel).GetAttribute("D0028_0011");
-               plane=(*sel).GetAttribute("D0028_0012");
-               level=(*sel).GetLevel();
+               mImageExtent=ie;
+               if((mImageExtent->Get(min_dim-1)<2)||(mImageExtent->Get(max_dim)>1))
+               {
+                       valid=false;
+               }
+               else
+               {
+                       std::stringstream out;
+                       out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
+               mMessage = out.str();
+                       mImageExtent->SetDimension(2);
+                       valid=true;
+               }
        }
        else
        {
-               if(((*sel).GetAttribute("D0028_0010"))!=row ||
-                       ((*sel).GetAttribute("D0028_0011"))!=col ||
-                       ((*sel).GetAttribute("D0028_0012"))!=plane)
+               if(mImageExtent->IsCompatible(*ie))
+               {
+                       if(mImageExtent->GetDimension()==max_dim && mImageExtent->Get(max_dim)>2)
+                       {
+                               std::stringstream out;
+                               out<<"Cannot add this image to selection : would result in a "<<mImageExtent->GetDimension()+1<<"D image!";
+                               mMessage=out.str();
+                               valid=false;
+                       }
+                       else if(max_dim<3)
+                       {
+                               std::stringstream out;
+                               out<<"Selecting "<<mImageExtent->GetDimension()<<"D images is not allowed !";
+                               mMessage=out.str();
+                               valid=false;
+                       }
+                       else if(min_dim==3 && (ie->Get(2)+mImageExtent->Get(2))<2)
                        {
-                               mMessage="The selected images are not compatible.";
+                               std::stringstream out;
+                               out << "Cannot build the selection as it would result in a ";
+                               out << mImageExtent->GetDimension();
+                               out << "D image, and the minimum is ";
+                               out << min_dim;
+                               out << "D!";
+                               mMessage=out.str();
                                valid=false;
                        }
+                       else
+                       {
+            mImageExtent->Add(*ie);
+                       std::stringstream out;
+                       out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
+               mMessage = out.str();
+                       }
+                       
+               }
+               else
+               {
+                       mMessage="The selected images are not compatible.";
+                       valid=false;
+               }
+       }
        }
-               
-       
-       int dim = 0;
-       int rows;
-       int cols;
-       int planes;
-       
-       //Dimention validation
-       //Compatibility with maximum and minimum
-       if(valid)
-         {     
-                   sscanf(row.c_str(),"%d",&rows);
-           sscanf(col.c_str(),"%d",&cols);
-           sscanf(plane.c_str(),"%d",&planes);
-           if(row==""){rows=1;}
-           if(col==""){cols=1;}
-           if(plane==""){planes=1;}
-           
-           std::cout << cols << "x"<<rows<<"x"<<planes << std::endl;
 
-           if (planes>1) dim=3;
-           else if (cols>1) dim=2;
-           else if (rows>1) dim=1;
-           
-           if (dim == 0) 
-             {
-               mMessage="Unknown image dimension : cannot select !";
-               valid= false;
-             }
-           else if (dim>max_dim)
-             {
-               mMessage="Selecting ";
-               mMessage+=dim;
-               mMessage+="D images is not allowed !";
-               valid= false;
-             }
-           if ( dim == max_dim )
-             {
-               mMessage="Cannot add this image to selection : would result in a ";
-               mMessage+=(dim+1);
-               mMessage+="D image!";
-               
-               valid= false;
-             }
-           if ( dim < min_dim )
-             {
-               GimmickMessage(1, "State Check: Dim: "
-                              <<dim
-                              <<" Dim min:"
-                              <<min_dim
-                              <<std::endl);
-               std::stringstream out;
-               out << "Cannot build the selection as it would result in a ";
-               out << dim;
-               out << "D image, and the minimum is ";
-               out << min_dim;
-               out << "D!";
-               mMessage+=out.str();
-               valid= false;
-             }
-         }
-       
        
-       if(valid)
-         {
-           std::stringstream out;
-           out << dim << "D image " << cols << "x"<< rows << "x"<< planes <<" selected";
-           mMessage = out.str();
-         }
-       }
        mValidationSignal(valid);
        SetMessage(mMessage);
        return valid;
   }
 
-   //======================================================================
+//======================================================================
 
    //======================================================================
   ///Reads Images (Non Threaded)