]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOGimmickView.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOGimmickView.cpp
index 0afd753353e7352663831cab8ad349ea8868950a..9d2b3dcb199d5a61c17dcb10a0bfdcf1b4bde850 100644 (file)
@@ -38,6 +38,10 @@ namespace creaImageIO
   /// 
   void GimmickView::Initialize()
   {
+         row="";
+         col="";
+         plane="";
+         selectionSize=0;
   }
   //======================================================================
   
@@ -78,120 +82,147 @@ namespace creaImageIO
       }
     i->second->UpdateLevel(l);    
   }
+  //======================================================================
+  /// Clears the status and begins a new selection process
+  void GimmickView::ClearStatus()
+  {
+         row="";
+         col="";
+         plane="";
+         selectionSize=0;
+         valid=true;
+  }
+
+
+  class ImageExtent
+  {
+  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;
+  };
+
+
   //======================================================================
   ///Validates the dimension compliance of the images with the maximum and 
   ///minimum given, and between their sizes
-  bool GimmickView::ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim)
+  bool GimmickView::ValidateSelected (tree::Node* sel, int min_dim, int max_dim)
   {
        GimmickMessage(2,"Validating selected"<<std::endl);
-         
-       bool valid=true;
-         
-         // EED validate all
+       std::string mMessage;
+       if(sel==0)
+       {
+               mMessage="Cannot have 0 images selected!";
+               valid=false;
+       }
+       if(valid)
+       {
+       selectionSize++;
+         /*// EED validate all
          mValidationSignal(valid);
-         return valid;
+         return valid;*/
          
        int level;
-       std::string mMessage;
-       if(sel.size()>0)
+       
+       
+       if(row.compare("")==0 || col.compare("")==0)
        {
-               std::vector<tree::Node*>::iterator i;
-               std::string row;
-               std::string col;
-               std::string plane;
-               
-               //Validation between image sizes
-               for (i=sel.begin(); i!=sel.end() && valid; ++i)
-               {
-                       if(i==sel.begin())
-                       {
-                               row=(*i)->GetAttribute("D0028_0010");
-                               col=(*i)->GetAttribute("D0028_0011");
-                               plane=(*i)->GetAttribute("D0028_0012");
-                               level=(*i)->GetLevel();
-                               
-                       }
-                       else
+               row=(*sel).GetAttribute("D0028_0010");
+               col=(*sel).GetAttribute("D0028_0011");
+               plane=(*sel).GetAttribute("D0028_0012");
+               level=(*sel).GetLevel();
+       }
+       else
+       {
+               if(((*sel).GetAttribute("D0028_0010"))!=row ||
+                       ((*sel).GetAttribute("D0028_0011"))!=col ||
+                       ((*sel).GetAttribute("D0028_0012"))!=plane)
                        {
-                               if(((*i)->GetAttribute("D0028_0010"))!=row ||
-                                       ((*i)->GetAttribute("D0028_0011"))!=col ||
-                                       ((*i)->GetAttribute("D0028_0012"))!=plane)
-                                       {
-                                               mMessage="The selected images are not compatible.";
-                                               valid=false;
-                                       }
+                               mMessage="The selected images are not compatible.";
+                               valid=false;
                        }
-               }
-
-               //Dimention validation
-               //Compatibility with maximum and minimum
-                       if(valid)
-                       {       
-                               
-                               int rows;
-                               int cols;
-                               int planes;
-                               std::string s;
-                               std::istringstream t(s);
-                               s=row;
-                               t >> rows;
-                               if(row==""){rows=1;}
-                               s=col;
-                               t >> cols;
-                               if(col==""){cols=1;}
-                               s=plane;
-                               t >> planes;
-                               if(plane==""){planes=1;}
+       }
+               
+       
+       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;
 
-                               int dim = 0;
-                               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 && sel.size()<2 )
-                               {
-                                       GimmickDebugMessage(2, "State Check: Dim: "
-                                               <<dim
-                                               <<" Dim min:"
-                                               <<min_dim
-                                               <<std::endl);
-                                       mMessage="Cannot build the selection as it would result in a ";
-                                       mMessage+=dim;
-                                       mMessage+="D image, and the minimum is ";
-                                       mMessage+=min_dim;
-                                       mMessage+="D!";
-                                       valid= false;
-                               }
-                       }
+           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;
+             }
          }
-       else
-       {
-               mMessage="Cannot have 0 images selected";
-               valid=false;
-       }
+       
+       
        if(valid)
-       {
-               mMessage="Selection OK !";
+         {
+           std::stringstream out;
+           out << dim << "D image " << cols << "x"<< rows << "x"<< planes <<" selected";
+           mMessage = out.str();
+         }
        }
        mValidationSignal(valid);
        SetMessage(mMessage);
@@ -303,10 +334,12 @@ namespace creaImageIO
        {
     if (filename.size()==0)
       {
+                 //What to do in this case?
+                 /*
                GimmickDebugMessage(5,
                                        "Pushing unknown image in queue"
                                        <<std::endl);
-               mImageEventQueue.push_back(ImageEventType(image));
+               mImageEventQueue.push_back(ImageEventType(image));*/
                return;
       }
     ImageEventTypeMap::iterator i;