]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOGimmickView.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOGimmickView.cpp
index c2ece7433afe15826af0a878010a2f7b059c1135..30ca0d5d094b9bd430e6e1824da392bb64057bf7 100644 (file)
@@ -2,6 +2,11 @@
 #include <creaImageIOSystem.h>
 #include "boost/filesystem.hpp"
 
+#include <gdcmSerieHelper.h>    // JPR
+#include <gdcmFile.h>           // JPR
+#include <vtkGdcmReader.h>      // JPR
+#include <gdcmDebug.h>
+
 namespace fs = boost::filesystem;
 
 namespace creaImageIO
@@ -13,20 +18,20 @@ namespace creaImageIO
   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;
+          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
@@ -296,15 +301,9 @@ void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s, std::vect
        // Create the output data
        if (im.size()==1) 
        {
-               // Only one image : give it
-               vtkImageData* out = vtkImageData::New();
-               GimmickDebugMessage(3, "State Check: Full Filename: "
-                                       <<im.front()
-                                       <<std::endl);
-               out->ShallowCopy(mReader.GetImage(im.front()));
-               s.push_back( out );
+               // O0.
        }
-       else if (im.size()>1) // Test inutile ? JPR
+    else if (im.size()>1) // Test inutile ? JPR
        {
                // Read the FIRST image to get info ... about all the other ones. ?!? // JPR
                vtkImageData* first = mReader.GetImage( im.front());
@@ -328,16 +327,12 @@ void GimmickView::ReadImagesNotThreaded(std::vector<vtkImageData*>& s, std::vect
                        vtkImageData* out = vtkImageData::New();
                        out->CopyStructure(first);      
                        out->SetScalarType(first->GetScalarType());
+                       out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
                        int ext[6];
                        //first->GetExtent(ext);     // JPR
                        first->GetWholeExtent(ext);  // renvoie egalement 0,0 en Z // JPR
                                                     // Normal :
 
-std::cout <<"in GimmickView::ReadImagesNotThreaded GetWholeExtent ext =";
-for (int jjj=0;jjj<6;jjj++)
-       std:cout << "   [" << jjj << "]=" << ext[jjj];
-std::cout << std::endl;
-
                        if(ext[5] == 0)
                        {
                                ext[5] = im.size()-1;
@@ -350,31 +345,96 @@ std::cout << std::endl;
 
                        // LG : TODO : Z Spacing  ?  // Voir + loin // JPR
 
-                       out->AllocateScalars();
-
                        int dim[3];
                        first->GetDimensions(dim);
+
+                       out->SetDimensions(dim[0], dim[1], im.size() );
+                       out->AllocateScalars();
+                       out->Update();
+
                        unsigned long imsize = dim[0] * dim[1];
                        imsize = imsize * dim[2] ;  // deal with multiframes // JPR
+
+
 //EED 03-11-2009
-                       imsize = imsize * first->GetScalarSize();
+                       // differents formats char , short, etc...
+                       // differents components 1..3  ex. jpg ->RGB 3
+                       imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
+
+
+                       // Order the file name vector
 
+                       double spc[3];
+                       out->GetSpacing(spc);
+                       spc[2]=OrderTheFileNameVector(im);      
+                       out->SetSpacing(spc);
                        int slice = 0;
                        std::vector<std::string>::iterator it;
+
                        for (it=im.begin(); it!=im.end(); ++it) 
                        {
-                               vtkImageData* cur = mReader.GetImage( (*it));
-                       //      void* src = cur->GetScalarPointer(0,0,0);
-                       //      void* dst = out->GetScalarPointer(0,0,slice);
+                               vtkImageData* cur = mReader.GetImage( (*it) );
                                memcpy(out->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize);
-
                                slice++;
                        }       
                        s.push_back(out);
+
+               }  // dimension == 3
+
+       }  // size >1
+
+}
+  //======================================================================
+
+
+double GimmickView::OrderTheFileNameVector(std::vector<std::string> &im)
+{
+       double spacing=1;
+       typedef std::vector<GDCM_NAME_SPACE::File* > FileList;
+       FileList fileVector;
+       //GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
+       GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New();
+       std::vector<std::string> lstAux;
+       std::vector<std::string>::iterator it;
+       for (it=im.begin(); it!=im.end(); ++it)
+       {
+               ///\TODO liberer les GDCM_NAME_SPACE::File a la fin!  // JPR
+               GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
+               f->SetFileName(*it);
+               f->Load();
+               if (f->IsReadable())
+               {
+                       fileVector.push_back(f);
+               } else {
+                       lstAux.push_back(*it);
                }
+       } // for
+                       
+       
+       if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector )))
+       {
+                       sh->OrderFileList(&fileVector);
+                       spacing= sh->GetZSpacing();
+                       im.clear();
+                       int i;
+                       for (i=0; i<fileVector.size(); i++)
+                       {
+                               im.push_back( (fileVector[i])->GetFileName() );
+                       }
+                       for (i=0; i<lstAux.size(); i++)
+                       {
+                               im.push_back( lstAux[i] );
+                       }
+       }else {
+               std::sort( im.begin(), im.end() );
        }
+                       
+   return spacing;
 }
-  //======================================================================
+
+
+//======================================================================
+
 
 void GimmickView::ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s, std::vector<std::string> im, int dimension)
 {