]> Creatis software - bbtk.git/blobdiff - packages/vtk/src/bbvtkConcatImages.cxx
in 50 % of the scripts, LoadHola was called an 'image' in 50 % a 'reader'.
[bbtk.git] / packages / vtk / src / bbvtkConcatImages.cxx
index 301614fce13cd8adc25b0ca1725a4c5db1f0e187..39bc30555b07bcbbdf829b70eb06a7b375d7e96d 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbvtkConcatImages.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/04/08 14:39:45 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2010/04/28 22:10:07 $
+  Version:   $Revision: 1.2 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -87,8 +87,14 @@ namespace bbvtk
    void ConcatImages::Process()
    {
         int dim[3];
+       int nbComponents;
+       int scalarType;
        int nb = (unsigned int)bbGetInputIn().size();
-        if (nb == 0) {} // ??? JPR
+       int consistentNb(nb);
+
+        if (nb == 0) {
+          // ??? JPR
+       } 
        
        bbGetInputIn()[0]->GetDimensions(dim);
        if (dim[2] > 1  || nb == 1) // dim[2] > 1 : Hopeless for vtk : the first file contains already a 3D object
@@ -106,15 +112,29 @@ namespace bbvtk
                  //std::cout << "--------PrintSelf firstImage " << std::endl;
                  // firstImage->PrintSelf(std::cout, vtkIndent(2));       
           
-           int nbComponents = firstImage->GetNumberOfScalarComponents();
+           nbComponents = firstImage->GetNumberOfScalarComponents();
            mConcat->SetNumberOfScalarComponents(nbComponents);
-           mConcat->SetScalarType(firstImage->GetScalarType( ));       
-          firstImage->GetDimensions(dim);
-          dim[2]=nb;
-          mConcat->SetDimensions(dim);
-          mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
+          
+          mConcat->SetScalarType(firstImage->GetScalarType( ));
+          scalarType = firstImage->GetScalarType( );
+          mConcat->SetScalarType(scalarType);
+          
           mConcat->SetSpacing(firstImage->GetSpacing());
           
+          firstImage->GetDimensions(dim);         
+          // brute way to perform an ultra-mini consistency check :
+          // First image is supposed to be the reference image,
+          // any unconsistent image is just discarted...
+          for(int i=0; i<nb; i++)
+          {
+             if ( !CheckConsistency(firstImage, dim, nbComponents, scalarType))
+               consistentNb--;
+          }    
+
+          dim[2]=consistentNb;
+          mConcat->SetDimensions(dim);
+          mConcat->SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
+                  
           mConcat->AllocateScalars();
           mConcat->Update();      
                     
@@ -122,6 +142,8 @@ namespace bbvtk
           
           for(index_image=0; index_image<nb; index_image++)
           {
+             if (!CheckConsistency(bbGetInputIn()[index_image], dim, nbComponents, scalarType))
+                continue;  // discard unconsistent image !
              for(index_lignes=0; index_lignes<dim[0];index_lignes++)
              {
                 for(index_colonnes=0; index_colonnes<dim[1];index_colonnes++)
@@ -138,6 +160,25 @@ namespace bbvtk
    bbSetOutputOut(mConcat);    
    }              
 
+bool ConcatImages::CheckConsistency( vtkImageData *curImage, int dim[], int nbComponents, int scalarType )
+{
+   assert (curImage);
+   
+   if (scalarType != curImage->GetScalarType( ) )
+      return false;
+      
+   if (nbComponents != curImage->GetNumberOfScalarComponents() )
+      return false;
+      
+   int curDim[3];
+   curImage->GetDimensions(curDim);
+   if ( (curDim[0] =! dim[0]) || (curDim[1] =! dim[1]) )
+      return false;
+
+   return true;   
+}
+
+
 }//namespace bbtk
 
 #endif // _USE_VTK_