]> Creatis software - bbtk.git/commitdiff
#3385 BBTK Bug New Normal - box FilesFromDirectory CreateImage InvertCrop ComboBox...
authorEduardo DAVILA <davila@localhost.localdomain>
Thu, 16 Apr 2020 08:35:03 +0000 (10:35 +0200)
committerEduardo DAVILA <davila@localhost.localdomain>
Thu, 16 Apr 2020 08:35:03 +0000 (10:35 +0200)
kernel/src/bbtkBlackBox.cxx
packages/std/src/bbstdFilesFromDirectory.cxx
packages/vtk/src/bbvtkCreateImage.cxx
packages/vtk/src/bbvtkInversCrop.cxx
packages/wx/src/bbwxComboBox.cxx
packages/wx/src/bbwxComboBox.h
packages/wx/src/bbwxLayoutTab.cxx

index dbab39b7cb736c860741938d46adec180e771bb6..4b000f0e65acf32f76f242175a99c702252436b0 100644 (file)
@@ -183,13 +183,11 @@ namespace bbtk
   std::string BlackBox::bbGetNameWithParent() const
   {
     if (bbmParent.lock()) 
-      {
-       return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
-      }
-    else 
-      {
-       return bbmName;
-      }
+       {
+               return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName;
+       } else {
+               return bbmName;
+    }
   } 
   //=========================================================================
 
index 3a694d2d48d8070c607089deeff434af2a53fdac..387b5ad77aacfd7a2043b9048daed5491c20cdec 100644 (file)
@@ -293,24 +293,27 @@ if (recursiveLevel>=0){
 void FilesFromDirectory::CleanFilenames( std::string basePath )
 {
        std::string tmpString;
-       int i,ii,sizeFilenames = Filenames.size();
-       int j,sizeFileEnd = bbGetInputFileEnd().size();
-
+       int i,ii,sizeFilenames  = Filenames.size();
+       int j,sizeFileEnd               = bbGetInputFileEnd().size();
        int okEraseElement;
-       
+       int posStr;
 //Selecting just the files in the FileEnd List
        if (bbGetInputFileEnd().size()!=0)
        {
                for (i=sizeFilenames-1; i>=0; i--)
                {
-                       okEraseElement=0;
+                       okEraseElement = 0;
                        for (j=0; j<sizeFileEnd; j++)
                        {
-                               std::string tmp=Filenames[i].substr( (Filenames[i].length()) - (bbGetInputFileEnd()[j]).length() ) ;
-                               if (bbGetInputFileEnd()[j].compare( tmp )==0 )
+                               posStr=(Filenames[i].length()) - (bbGetInputFileEnd()[j]).length();
+                               if (posStr>=0)
                                {
-                                       okEraseElement++;
-                               } // if FileEnd
+                                       std::string tmp=Filenames[i].substr( posStr ) ;
+                                       if (bbGetInputFileEnd()[j].compare( tmp )==0 )
+                                       {
+                                               okEraseElement++;
+                                       } // if FileEnd
+                               }// if posStr
                        } // for j                                      
 
                        if (okEraseElement==0) 
@@ -319,14 +322,11 @@ void FilesFromDirectory::CleanFilenames( std::string basePath )
                        }
                } // for i      
        } // if FileEnd !=0
-
        sizeFilenames = Filenames.size();
-
 // Cleanning paths with spaces 
        for (i=0; i<sizeFilenames; i++)
        {
                tmpString=Filenames[i];
-
                std::string::size_type  spacePosition = tmpString.find_first_of(' ');
                if (spacePosition != std::string::npos)
                {
@@ -338,7 +338,6 @@ void FilesFromDirectory::CleanFilenames( std::string basePath )
                } // if spacePosition
        }
 
-
 // Alphabetical order  
        for (i=0; i<sizeFilenames; i++)
        {
@@ -352,14 +351,12 @@ void FilesFromDirectory::CleanFilenames( std::string basePath )
                } // if 
        } // for ii
        } // for i
-
 // Creating SimpleFilenames
        unsigned int lenghtBasePath = basePath.length();
        for (i=0; i<sizeFilenames; i++)
        {
                SimpleFilenames.push_back( Filenames[i].substr( lenghtBasePath ) );
        } // for i
-
 }
 
 
index c534252a5b3452d7c440b579464a69e342790b80..499d3364e26d89a9613e0af4f9a5be8ffa28b509 100644 (file)
@@ -53,97 +53,104 @@ void CreateImage::Process()
 //    * TYPE is the C++ type of the input/output
 //      (the one provided in the attribute 'type' of the tag 'input')
 
-       double  spc[3];
        int             dim[3]; 
-       int             outputformat = VTK_UNSIGNED_SHORT;
-       
-       if (bbGetInputOutputFormat()=="VTK_BIT")                                        outputformat = VTK_BIT;                 // 1
-       else if (bbGetInputOutputFormat()=="VTK_CHAR")                          outputformat = VTK_CHAR;                                // 2
-       else if (bbGetInputOutputFormat()=="MET_CHAR")                          outputformat = VTK_CHAR;                                // 2
-       else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;         // 15
-       else if (bbGetInputOutputFormat()=="MET_UCHAR")                         outputformat = VTK_UNSIGNED_CHAR;       // 3
-       else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;       // 3
-       else if (bbGetInputOutputFormat()=="VTK_SHORT")                         outputformat = VTK_SHORT;               // 4
-       else if (bbGetInputOutputFormat()=="MET_SHORT")                         outputformat = VTK_SHORT;               // 4
-       else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT;      // 5
-       else if (bbGetInputOutputFormat()=="MET_USHORT")                        outputformat = VTK_UNSIGNED_SHORT;      // 5
-       else if (bbGetInputOutputFormat()=="VTK_INT")                           outputformat = VTK_INT;                 // 6
-       else if (bbGetInputOutputFormat()=="MET_INT")                           outputformat = VTK_INT;                 // 6
-       else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;        // 7 
-       else if (bbGetInputOutputFormat()=="MEY_UINT")                          outputformat = VTK_UNSIGNED_INT;        // 7 
-       else if (bbGetInputOutputFormat()=="VTK_LONG")                          outputformat = VTK_LONG;                // 8
-       else if (bbGetInputOutputFormat()=="MET_LONG")                          outputformat = VTK_LONG;                // 8
-       else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;       // 9
-       else if (bbGetInputOutputFormat()=="MET_ULONG")                         outputformat = VTK_UNSIGNED_LONG;       // 9
-       else if (bbGetInputOutputFormat()=="VTK_FLOAT")                         outputformat = VTK_FLOAT;               // 10
-       else if (bbGetInputOutputFormat()=="MET_FLOAT")                         outputformat = VTK_FLOAT;               // 10
-       else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11           
-       else if (bbGetInputOutputFormat()=="MET_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11  
-
-       spc[0] = bbGetInputSpacing()[0];
-       spc[1] = bbGetInputSpacing()[1];
-       spc[2] = bbGetInputSpacing()[2];
-       dim[0] =  bbGetInputDimensions()[0];
-       dim[1] =  bbGetInputDimensions()[1];
-       dim[2] =  bbGetInputDimensions()[2];
-       if ((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0))
-       {
-               dim[0]=1;
-               dim[1]=1;
-               dim[2]=1;
-       }
-       if ((spc[0]<=0)||(spc[1]<=0)||(spc[2]<=0))
-       {
-               spc[0]=1;
-               spc[1]=1;
-               spc[2]=1;
-       }
-//EED 2017-12-7
-       if (imageoutput!=NULL) {imageoutput->Delete();} 
-       imageoutput = vtkImageData::New();
-       imageoutput->Initialize();
-       imageoutput->SetSpacing( spc );
-       imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
-
-//EED 2017-01-01 Migration VTK7
-#if (VTK_MAJOR_VERSION <= 5) 
-       imageoutput->SetScalarType( outputformat );     
-       imageoutput->AllocateScalars();
-#endif
-#if (VTK_MAJOR_VERSION >= 6) 
-       imageoutput->AllocateScalars( outputformat,1 );
-#endif
-       
-       int i,j,k;
-       long sizeBlock; 
+       dim[0] = bbGetInputDimensions()[0];
+       dim[1] = bbGetInputDimensions()[1];
+       dim[2] = bbGetInputDimensions()[2];
 
-       for (i=0; i<dim[0]; i++)
+       if (imageoutput!=NULL) 
        {
-               imageoutput->SetScalarComponentFromDouble(i,0,0, 0, bbGetInputInitialValue() );
-       } // for i
-       
-       sizeBlock= dim[0] * imageoutput->GetScalarSize();
-    for (j=1; j<dim[1]; j++)
-       {
-               memcpy(  imageoutput->GetScalarPointer(0,j,0), imageoutput->GetScalarPointer()  , sizeBlock );
-       } // for j              
+               imageoutput->Delete();
+               imageoutput = NULL;
+       } // if imageoutput
 
-       sizeBlock= dim[0] * dim[1] * imageoutput->GetScalarSize();
-       for (k=0; k<dim[2]; k++)
+       if ( !((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0)) )
        {
-               memcpy(  imageoutput->GetScalarPointer(0,0,k) ,imageoutput->GetScalarPointer()  , sizeBlock );
-       } // for k
-       
-
-//EED 2017-01-01 Migration VTK7
-#if (VTK_MAJOR_VERSION <= 5) 
-       imageoutput->Update();
-#endif
-#if (VTK_MAJOR_VERSION >= 6) 
-       // ..
-#endif
+               double  spc[3];
+               int             outputformat = VTK_UNSIGNED_SHORT;
+               spc[0] = bbGetInputSpacing()[0];
+               spc[1] = bbGetInputSpacing()[1];
+               spc[2] = bbGetInputSpacing()[2];
+               if (bbGetInputOutputFormat()=="VTK_BIT")                                        outputformat = VTK_BIT;                 // 1
+               else if (bbGetInputOutputFormat()=="VTK_CHAR")                          outputformat = VTK_CHAR;                                // 2
+               else if (bbGetInputOutputFormat()=="MET_CHAR")                          outputformat = VTK_CHAR;                                // 2
+               else if (bbGetInputOutputFormat()=="VTK_SIGNED_CHAR")           outputformat = VTK_SIGNED_CHAR;         // 15
+               else if (bbGetInputOutputFormat()=="MET_UCHAR")                         outputformat = VTK_UNSIGNED_CHAR;       // 3
+               else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_CHAR")         outputformat = VTK_UNSIGNED_CHAR;       // 3
+               else if (bbGetInputOutputFormat()=="VTK_SHORT")                         outputformat = VTK_SHORT;               // 4
+               else if (bbGetInputOutputFormat()=="MET_SHORT")                         outputformat = VTK_SHORT;               // 4
+               else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_SHORT")        outputformat = VTK_UNSIGNED_SHORT;      // 5
+               else if (bbGetInputOutputFormat()=="MET_USHORT")                        outputformat = VTK_UNSIGNED_SHORT;      // 5
+               else if (bbGetInputOutputFormat()=="VTK_INT")                           outputformat = VTK_INT;                 // 6
+               else if (bbGetInputOutputFormat()=="MET_INT")                           outputformat = VTK_INT;                 // 6
+               else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_INT")          outputformat = VTK_UNSIGNED_INT;        // 7 
+               else if (bbGetInputOutputFormat()=="MEY_UINT")                          outputformat = VTK_UNSIGNED_INT;        // 7 
+               else if (bbGetInputOutputFormat()=="VTK_LONG")                          outputformat = VTK_LONG;                // 8
+               else if (bbGetInputOutputFormat()=="MET_LONG")                          outputformat = VTK_LONG;                // 8
+               else if (bbGetInputOutputFormat()=="VTK_UNSIGNED_LONG")         outputformat = VTK_UNSIGNED_LONG;       // 9
+               else if (bbGetInputOutputFormat()=="MET_ULONG")                         outputformat = VTK_UNSIGNED_LONG;       // 9
+               else if (bbGetInputOutputFormat()=="VTK_FLOAT")                         outputformat = VTK_FLOAT;               // 10
+               else if (bbGetInputOutputFormat()=="MET_FLOAT")                         outputformat = VTK_FLOAT;               // 10
+               else if (bbGetInputOutputFormat()=="VTK_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11           
+               else if (bbGetInputOutputFormat()=="MET_DOUBLE")                        outputformat = VTK_DOUBLE;              // 11  
+
+               if ((dim[0]<=0)||(dim[1]<=0)||(dim[2]<=0))
+               {
+                       dim[0]=1;
+                       dim[1]=1;
+                       dim[2]=1;
+               }
+               if ((spc[0]<=0)||(spc[1]<=0)||(spc[2]<=0))
+               {
+                       spc[0]=1;
+                       spc[1]=1;
+                       spc[2]=1;
+               }
+               imageoutput = vtkImageData::New();
+               imageoutput->Initialize();
+               imageoutput->SetSpacing( spc );
+               imageoutput->SetDimensions(  dim[0], dim[1], dim[2] );
+
+       //EED 2017-01-01 Migration VTK7
+       #if (VTK_MAJOR_VERSION <= 5) 
+               imageoutput->SetScalarType( outputformat );     
+               imageoutput->AllocateScalars();
+       #endif
+       #if (VTK_MAJOR_VERSION >= 6) 
+               imageoutput->AllocateScalars( outputformat,1 );
+       #endif
+               
+               int i,j,k;
+               long sizeBlock; 
+
+               for (i=0; i<dim[0]; i++)
+               {
+                       imageoutput->SetScalarComponentFromDouble(i,0,0, 0, bbGetInputInitialValue() );
+               } // for i
+               
+               sizeBlock= dim[0] * imageoutput->GetScalarSize();
+               for (j=1; j<dim[1]; j++)
+               {
+                       memcpy(  imageoutput->GetScalarPointer(0,j,0), imageoutput->GetScalarPointer()  , sizeBlock );
+               } // for j              
+
+               sizeBlock= dim[0] * dim[1] * imageoutput->GetScalarSize();
+               for (k=0; k<dim[2]; k++)
+               {
+                       memcpy(  imageoutput->GetScalarPointer(0,0,k) ,imageoutput->GetScalarPointer()  , sizeBlock );
+               } // for k
+               
+
+       //EED 2017-01-01 Migration VTK7
+       #if (VTK_MAJOR_VERSION <= 5) 
+               imageoutput->Update();
+       #endif
+       #if (VTK_MAJOR_VERSION >= 6) 
+               // ..
+       #endif
+               imageoutput->Modified();
+       } // if dim = 0
 
-       imageoutput->Modified();
        bbSetOutputOut(imageoutput);
 }      
        
index 9e8c578b470416080901a12985baac01141fae44..b43fa796d68ca05f3d859f3d8a6eaca78aeaab86 100644 (file)
@@ -71,8 +71,6 @@ void InversCrop::Process()
                        _imageoutput=bbGetInputImageFix();
                }
 
-
-
                // Copy the Move Image
                int j,k; 
                int px,py,pz;
@@ -87,26 +85,24 @@ void InversCrop::Process()
                int dimMoveX    = ext[1]-ext[0]+1;
                int dimMoveY    = ext[3]-ext[2]+1;
                int dimMoveZ    = ext[5]-ext[4]+1;
-
                int spxM                = 0;  // start px MoveImage
                int sizeXM              = 0;  // sizeX MoveImage
-
                px                              = bbGetInputOrigin()[0];
                spxM                    = 0;
                if (px<0)
                { 
-                  spxM=px*(-1);
-                  px=0;
+                  spxM = px*(-1);
+                  px   = 0;
                }
                sizeXM = dimMoveX-spxM;
                if (px+sizeXM>=dim[0]) sizeXM=dim[0]-px;
-               sizeXM=sizeXM*bbGetInputImageFix()->GetScalarSize();
+               sizeXM = sizeXM * bbGetInputImageFix()->GetScalarSize();
                for (k=0; k<dimMoveZ; k++)
                {
                   for (j=0; j<dimMoveY; j++)
                   {
-                       py=j+bbGetInputOrigin()[1];
-                               pz=k+bbGetInputOrigin()[2];
+                       py = j+bbGetInputOrigin()[1];
+                               pz = k+bbGetInputOrigin()[2];
                                if ( (py<dim[1]) && (pz<dim[2]) &&
                                 (py>=0)    && (pz>=0)  &&
                                         (sizeXM>0) ) 
@@ -117,17 +113,15 @@ void InversCrop::Process()
                   } // for j
                } // for k
                _imageoutput->Modified();
-             } // If Image Fixe Move the same GetScalarType
-               else {
+       } else { // If Image Fixe Move the same GetScalarType
                   printf ("ERROR: InversCrop  both ImageFixe and ImageMove need the same format.\n");
                   printf ("       type ImageFix:%d   type ImageMove:%d\n", bbGetInputImageFix()->GetScalarType(), bbGetInputImageMove()->GetScalarType() );
 
              }  
-           } // If Image Fixe Move != NULL   
-            else {
-               printf ("ERROR: InversCrop  need ImageFixe and ImageMove to run.\n");
-           } 
-           bbSetOutputOut(_imageoutput);
+           } else { // If Image Fixe Move != NULL
+                       printf ("ERROR: InversCrop  need ImageFixe and ImageMove to run.\n");
+          } 
+        bbSetOutputOut(_imageoutput);
 
        } // if Active
 
index c075b701deaacff1bc4fd0753ac4fed913966bab..06ec5912e0d115e929e31be9711424aab6d10a51 100644 (file)
@@ -58,10 +58,9 @@ namespace bbwx
     mBox(box),
     mTypeForm(typeForm)
   {
-       wxPanel         *panel          = this;
        itemcontainer                   = NULL;
-       int i;
-
+       wxPanel                 *panel  = this;
+       int                     i;
     //---------------------------------------------------------------------
     // 2) Insertion of the components in the window
     
@@ -83,7 +82,6 @@ namespace bbwx
                wxChoice *wxchoice = new wxChoice ( panel , -1, wxDefaultPosition,wxSize(sizeX,sizeY));
                itemcontainer=wxchoice;
                sizer->Add( wxchoice,1,wxGROW ); 
-
                Connect( wxchoice->GetId(), 
                  wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
        }
@@ -123,9 +121,7 @@ namespace bbwx
                mBox->bbSetOutputOut( iSelection );
                mBox->bbSetOutputOutString(    bbtk::wx2std( itemcontainer->GetString(iSelection) )     );
                mBox->bbSignalOutputModification();
-
                VerifyDeselect(iSelection);
-
                if (mTypeForm==0) 
                { 
                        wxChoice *wxchoise=(wxChoice *)itemcontainer;
@@ -138,25 +134,27 @@ namespace bbwx
        } // if iSelection
   }
 
-  //--------------------------------------------------------------------------
-  void ComboBoxWidget::OnComboBox(wxEvent& event)
-  {
+//--------------------------------------------------------------------------
+void ComboBoxWidget::OnComboBox(wxEvent& event)
+{
        OnComboBoxSelection( itemcontainer->GetSelection() );
-  }
+}
+
 //--------------------------------------------------------------------------
-  void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
+void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
+{
+       int i;
+       itemcontainer->Clear();
+       for (i=0;i<lstIn.size(); i++)
        {
-               int i;
-               itemcontainer->Clear();
-       for (i=0;i<lstIn.size(); i++)
-       {
-                       itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
-               } // for i
-               if (iSelection>=0) itemcontainer->SetSelection(iSelection);
-       } 
+               itemcontainer->Append(  bbtk::std2wx( lstIn[i] )  ); 
+       } // for i
+       if (iSelection>=0) itemcontainer->SetSelection(iSelection);
+} 
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
@@ -174,7 +172,6 @@ void ComboBox::Process()
     { 
        bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
     } // if iSelection
-
        w->VerifyDeselect(iSelection);
 }
 //===== 
@@ -191,7 +188,10 @@ void ComboBox::CreateWidget(wxWindow* parent)
                                bbGetInputForm(),
                                                        bbGetInputWinWidth(), bbGetInputWinHeight()  );
    bbSetOutputOut( bbGetInputSelection() );
-   bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
+   if (bbGetInputIn().size()> bbGetInputSelection() )
+   {
+          bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
+   } // if InputIn size
    bbSetOutputWidget( w );
 }
 //===== 
index 1f1578153d02c276e1994ebbd1a841ce0b3faaaf..776a89f6a66bcd9bfdf3077e12004af2f94da249 100644 (file)
@@ -23,8 +23,10 @@ class bbwx_EXPORT ComboBox
   BBTK_DECLARE_INPUT(In,std::vector< std::string >);
   BBTK_DECLARE_INPUT(Form, int );
   BBTK_DECLARE_INPUT(Deselect, bool );
+
   BBTK_DECLARE_OUTPUT(Out, int );
   BBTK_DECLARE_OUTPUT(OutString, std::string );
+
   BBTK_PROCESS(Process);
   void Process();
   BBTK_CREATE_WIDGET(CreateWidget);
index a93b5d8efa7770b84d880075a8b41a956aee859b..3655a772c23dd7c17ce0d47d8c245b300775d623 100644 (file)
@@ -82,9 +82,8 @@ namespace bbwx
             (wxObjectEventFunction) 
             (void (wxPanel::*)(wxEvent&))
             &TabWidget::OnTabChange ); 
-    wxFlexGridSizer *sizer     = new wxFlexGridSizer(1);
-    sizer -> Add( mwxNotebook,1,wxGROW | wxALL,10 ); 
-    sizer      -> AddGrowableCol(0);
+    wxBoxSizer *sizer  = new wxBoxSizer(wxHORIZONTAL);
+    sizer -> Add( mwxNotebook,1,wxGROW,0 ); 
     panel      -> SetSizer(sizer);
     panel      -> SetAutoLayout(true);
     panel      -> Layout();
@@ -96,7 +95,6 @@ namespace bbwx
   
   void TabWidget::OnTabChange( wxEvent& )
   {
-   printf("EED TabWidget::OnTabChange %d\n",mwxNotebook->GetSelection() );
        mBox->bbSetOutputSelection( mwxNotebook->GetSelection() );
     mBox->bbSignalOutputModification();
   }
@@ -230,7 +228,7 @@ void LayoutTab::SetTitleTabs()
     TryInsertWindow(w,"Widget7");
     TryInsertWindow(w,"Widget8");
     TryInsertWindow(w,"Widget9");
-    
+
 //EED2020-04-06
 //    bbSetOutputWidget( w );
     bbSetOutputWidget( tabwidget );