]> Creatis software - gdcm.git/blobdiff - vtk/vtkgdcmSerieViewer2.cxx
Fix mistypings
[gdcm.git] / vtk / vtkgdcmSerieViewer2.cxx
index 73b18dc590293e3ccc9d53d013b9c32456f96285..7b108e37ae1fd6e8a12206b95fb005cd79aceb71 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: vtkgdcmSerieViewer2.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/02/03 16:37:50 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2007/06/21 14:47:16 $
+  Version:   $Revision: 1.11 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
                                                                                 
 =========================================================================*/
 // This example illustrates how the vtkGdcmReader vtk class can 
-// use the result of gdcm::SerieHelper constructor and check
+// use the result of GDCM_NAME_SPACE::SerieHelper constructor and check
 // the various Setters :
 //     SerieHelper::SetOrderToReverse, 
 //     SerieHelper::SetUserLessThanFunction
 //     SerieHelper::SetLoadMode
+//     SerieHelper::SetDropDuplicatePositions
 //     vtkGdcmReader::SetUserFunction
 //     vtkGdcmReader::SetCoherentFileList
 // Usage:
 #define vtkFloatingPointType float
 #endif
 
-void userSuppliedMirrorFunction (uint8_t *im, gdcm::File *f);
-void userSuppliedTopDownFunction(uint8_t *im, gdcm::File *f);
-bool userSuppliedLessThanFunction(gdcm::File *f1, gdcm::File *f2);
-bool userSuppliedLessThanFunction2(gdcm::File *f1, gdcm::File *f2);
+void userSuppliedMirrorFunction (uint8_t *im, GDCM_NAME_SPACE::File *f);
+void userSuppliedUpsideDownFunction(uint8_t *im, GDCM_NAME_SPACE::File *f);
+bool userSuppliedLessThanFunction(GDCM_NAME_SPACE::File *f1, GDCM_NAME_SPACE::File *f2);
+bool userSuppliedLessThanFunction2(GDCM_NAME_SPACE::File *f1, GDCM_NAME_SPACE::File *f2);
 
 int orderNb;
 uint16_t *elemsToOrderOn;
@@ -85,10 +86,19 @@ public:
       {
          if ( event == vtkCommand::CharEvent )
          {
+#if (VTK_MAJOR_VERSION >= 5)
+            int max = ImageViewer->GetSliceMax();
+            int slice = (ImageViewer->GetSlice() + 1 ) % ++max;
+            ImageViewer->SetSlice( slice );
+#else
             int max = ImageViewer->GetWholeZMax();
             int slice = (ImageViewer->GetZSlice() + 1 ) % ++max;
             ImageViewer->SetZSlice( slice );
+#endif
+#if !( (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION >= 5 ) )
+         // This used to be a bug in version VTK 4.4 and earlier
             ImageViewer->GetRenderer()->ResetCameraClippingRange();
+#endif
             ImageViewer->Render();
          }
       }
@@ -105,29 +115,30 @@ int main(int argc, char *argv[])
    " usage: vtkgdcmSerieViewer dirname=sourcedirectory                        ",
    "                           [noshadowseq][noshadow][noseq]                 ",
    "                           [reverse] [{[mirror]|[topdown]|[rotate]}]      ",
-   "                           [order=] [check][debug]                        ",
+   "                           [order=] [nodup][check][debug]                 ",
    "      sourcedirectory : name of the directory holding the images          ",
    "                        if it holds more than one serie,                  ",
-   "                        only the first one id displayed.                  ",
+   "                        only the first one is displayed.                  ",
    "      noshadowseq: user doesn't want to load Private Sequences            ",
    "      noshadow   : user doesn't want to load Private groups (odd number)  ",
    "      noseq      : user doesn't want to load Sequences                    ",
    "      reverse    : user wants to sort the images reverse order            ",
-   "      mirror     : user wants to 'mirror' the images | just some simple   ",
-   "      topdown    : user wants to 'topdown' the images| examples of user   ",
-   "      rotate     : NOT YET MADE (useless?)           | supplied functions ",
+   "      mirror     : user wants to 'mirror' the images    | just some simple",
+   "      upsidedown : user wants to 'upsidedown' the images| examples of user",
+   "                                                        | suppliedfunction",
    "      check      : user wants to force more coherence checking            ",
    "      order=     : group1-elem1,group2-elem2,... (in hexa, no space)      ",
    "                   if we want to use them as a sort criterium             ",
    "                   Right now : ValEntries only -just an example-          ",
    "        or                                                                ",
    "      order=     : order=name if we want to sort on file name (why not ?) ",
-   "      debug      : user wants to run the program in 'debug mode'          ",
+   "      nodup       : user wants to drop duplicate positions                ",
+   "      debug      : developper wants to run the program in 'debug mode'    ",
    FINISH_USAGE
 
 
    // Initialize Arguments Manager   
-   gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
+   GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
   
    if (argc == 1 || am->ArgMgrDefined("usage") )
    {
@@ -138,35 +149,29 @@ int main(int argc, char *argv[])
 
    char *dirName = am->ArgMgrWantString("dirname",usage);
 
-   int loadMode = gdcm::LD_ALL;
+   int loadMode = GDCM_NAME_SPACE::LD_ALL;
    if ( am->ArgMgrDefined("noshadowseq") )
-      loadMode |= gdcm::LD_NOSHADOWSEQ;
+      loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
    else 
    {
       if ( am->ArgMgrDefined("noshadow") )
-         loadMode |= gdcm::LD_NOSHADOW;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
       if ( am->ArgMgrDefined("noseq") )
-         loadMode |= gdcm::LD_NOSEQ;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
    }
 
    int reverse = am->ArgMgrDefined("reverse");
+   int nodup   = am->ArgMgrDefined("nodup");
+   int mirror     = am->ArgMgrDefined("mirror");
+   int upsidedown = am->ArgMgrDefined("upsidedown");
 
-   int mirror  = am->ArgMgrDefined("mirror");
-   int topdown = am->ArgMgrDefined("topdown");
-   int rotate  = am->ArgMgrDefined("rotate");
-
-   if ( mirror && topdown )
+   if ( mirror && upsidedown )
    {
-      std::cout << "mirror *OR* topDown !"
+      std::cout << "*EITHER* mirror *OR* upsidedown !"
                 << std::endl;
       delete am;
       return 0;
    }
-   if ( rotate )
-   {
-      std::cout << "'rotate' undealt with -> ignored !"
-                << std::endl;
-   }
 
    int check   = am->ArgMgrDefined("check");
   
@@ -176,7 +181,7 @@ int main(int argc, char *argv[])
       elemsToOrderOn = am->ArgMgrGetXInt16Enum("order", &orderNb);
 
    if (am->ArgMgrDefined("debug"))
-      gdcm::Debug::DebugOn();
+      GDCM_NAME_SPACE::Debug::DebugOn();
 
    /* if unused Param we give up */
    if ( am->ArgMgrPrintUnusedLabels() )
@@ -190,7 +195,7 @@ int main(int argc, char *argv[])
 
    // ----------------------- End Arguments Manager ----------------------
   
-   gdcm::SerieHelper *sh = gdcm::SerieHelper::New();
+   GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New();
    sh->SetLoadMode(loadMode);
    if (reverse)
       sh->SetSortOrderToReverse();
@@ -199,8 +204,8 @@ int main(int argc, char *argv[])
    // Just to see
 
    int nbFiles;
-   // For all the 'Single Serie UID' FileSets of the gdcm::Serie
-   gdcm::FileList *l = sh->GetFirstSingleSerieUIDFileSet();
+   // For all the 'Single Serie UID' FileSets of the GDCM_NAME_SPACE::Serie
+   GDCM_NAME_SPACE::FileList *l = sh->GetFirstSingleSerieUIDFileSet();
    if (l == 0 )
    {
       std::cout << "Oops! No 'Single Serie UID' FileSet found ?!?" << std::endl;
@@ -212,14 +217,22 @@ int main(int argc, char *argv[])
    else if (orderNb != 0)
       sh->SetUserLessThanFunction(userSuppliedLessThanFunction);
 
+   if (nodup)
+      sh->SetDropDuplicatePositions(true);
+      
    while (l)
    { 
       nbFiles = l->size() ;
       if ( l->size() > 1 )
       {
          std::cout << "Sort list : " << nbFiles << " long" << std::endl;
-         sh->OrderFileList(l);  // sort the list
-         std::cout << "List sorted" << std::endl;
+         //---------------------------------------------------------
+         sh->OrderFileList(l);  // sort the list (and compute ZSpacing !)
+         //---------------------------------------------------------
+         double zsp = sh->GetZSpacing();
+         std::cout << "List sorted, ZSpacing = " << zsp << std::endl;
          break;  // The first one is OK. user will have to check
       }
       else
@@ -245,8 +258,8 @@ int main(int argc, char *argv[])
 
    if (mirror)
       reader->SetUserFunction (userSuppliedMirrorFunction);
-   else if (topdown)
-      reader->SetUserFunction (userSuppliedTopDownFunction);
+   else if (upsidedown)
+      reader->SetUserFunction (userSuppliedUpsideDownFunction);
 
    // Only the first FileList is dealt with (just an example)
    // (The files will not be parsed twice by the reader)
@@ -349,7 +362,7 @@ int main(int argc, char *argv[])
       }                                 \
    }
 
-void userSuppliedMirrorFunction(uint8_t *im, gdcm::File *f)
+void userSuppliedMirrorFunction(uint8_t *im, GDCM_NAME_SPACE::File *f)
 {
    if (f->GetZSize() != 1)
    {
@@ -384,7 +397,7 @@ void userSuppliedMirrorFunction(uint8_t *im, gdcm::File *f)
 
 // --------------------------------------------------------
 // This is just a *very* simple example of user supplied function
-//      to topdown (why not ?) the image
+//      to upsidedown (why not ?) the image
 // It's *not* part of gdcm.
 // --------------------------------------------------------
 
@@ -404,7 +417,7 @@ void userSuppliedMirrorFunction(uint8_t *im, gdcm::File *f)
       }                                 \
    }
 
-void userSuppliedTopDownFunction(uint8_t *im, gdcm::File *f)
+void userSuppliedUpsideDownFunction(uint8_t *im, GDCM_NAME_SPACE::File *f)
 {
    if (f->GetZSize() != 1)
    {
@@ -450,12 +463,12 @@ void userSuppliedTopDownFunction(uint8_t *im, gdcm::File *f)
 // --------------------------------------------------------
 
 
-bool userSuppliedLessThanFunction(gdcm::File *f1, gdcm::File *f2)
+bool userSuppliedLessThanFunction(GDCM_NAME_SPACE::File *f1, GDCM_NAME_SPACE::File *f2)
 {
    // for *this* user supplied function, I supposed only ValEntries are checked.
 // 
    std::string s1, s2;
-   gdcm::DataEntry *e1,*e2;
+   GDCM_NAME_SPACE::DataEntry *e1,*e2;
    for (int ri=0; ri<orderNb; ri++)
    {
       std::cout << std::hex << elemsToOrderOn[2*ri] << "|" 
@@ -495,7 +508,7 @@ bool userSuppliedLessThanFunction(gdcm::File *f1, gdcm::File *f2)
 // Warning : it's up to 'vtkgdcmSerieViewer' user to find a suitable data set !
 // --------------------------------------------------------
 
-bool userSuppliedLessThanFunction2(gdcm::File *f1, gdcm::File *f2)
+bool userSuppliedLessThanFunction2(GDCM_NAME_SPACE::File *f1, GDCM_NAME_SPACE::File *f2)
 {
    std::cout << "[" << f1->GetFileName() << "] vs [" 
                     << f2->GetFileName() << "]" << std::endl;