Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vtkgdcmSerieViewer2.cxx File Reference

#include <vtkRenderWindowInteractor.h>
#include <vtkImageViewer2.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsWriter.h>
#include <vtkCommand.h>
#include <vtkRenderer.h>
#include <vtkImageMapToColors.h>
#include <vtkLookupTable.h>
#include "vtkGdcmReader.h"
#include "gdcmDocument.h"
#include "gdcmSerieHelper.h"
#include "gdcmDebug.h"
#include "gdcmDataEntry.h"
#include "gdcmArgMgr.h"
#include <string.h>

Include dependency graph for vtkgdcmSerieViewer2.cxx:

Go to the source code of this file.

Classes

class  vtkgdcmObserver

Defines

#define vtkFloatingPointType   float
#define UF(ty)
#define UF2(ty)

Functions

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)
int main (int argc, char *argv[])

Variables

int orderNb
uint16_t * elemsToOrderOn


Define Documentation

#define UF ty   ) 
 

Value:

int i, j;                            \
   ty *imj;                             \
   ty tamp;                             \
   for (j=0;j<ny;j++)                   \
   {                                    \
      imj = (ty *)im +j*nx;             \
      for (i=0;i<nx/2;i++)              \
      {                                 \
        tamp       =imj[i];             \
        imj[i]     =imj[nx-1-i];        \
        imj[nx-1-i]=tamp;               \
      }                                 \
   }                                    \
   if (nx%2 != 0)                       \
   {                                    \
      i = nx / 2;                       \
      for (j=0;j<ny;j++)                \
      {                                 \
        imj = (ty *)im  +j*nx;          \
        tamp       =imj[i];             \
        imj[i]     =imj[nx/2+1];        \
        imj[nx/2+1]=tamp;               \
      }                                 \
   }

Definition at line 326 of file vtkgdcmSerieViewer2.cxx.

#define UF2 ty   ) 
 

Value:

int i, j;                            \
   ty *imj, *imJ;                       \
   ty tamp;                             \
   for (j=0;j<ny/2;j++)                 \
   {                                    \
      imj = (ty *)im +j*nx;             \
      imJ = (ty *)im +(ny-1-j)*nx;      \
      for (i=0;i<nx;i++)                \
      {                                 \
        tamp       =imj[i];             \
        imj[i]     =imJ[i];             \
        imJ[i]     =tamp;               \
      }                                 \
   }

Definition at line 391 of file vtkgdcmSerieViewer2.cxx.

#define vtkFloatingPointType   float
 

Definition at line 51 of file vtkgdcmSerieViewer2.cxx.


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 99 of file vtkgdcmSerieViewer2.cxx.

References gdcm::Debug::DebugOn(), gdcm::RefCounter::Delete(), elemsToOrderOn, FINISH_USAGE, gdcm::SerieHelper::GetFirstSingleSerieUIDFileSet(), gdcm::SerieHelper::GetNextSingleSerieUIDFileSet(), vtkgdcmObserver::ImageViewer, gdcm::SerieHelper::IsCoherent(), gdcm::LD_ALL, gdcm::LD_NOSEQ, gdcm::LD_NOSHADOW, gdcm::LD_NOSHADOWSEQ, vtkgdcmObserver::New(), vtkGdcmReader::New(), gdcm::SerieHelper::New(), gdcm::SerieHelper::OrderFileList(), orderNb, vtkGdcmReader::SetCoherentFileList(), gdcm::SerieHelper::SetDirectory(), gdcm::SerieHelper::SetLoadMode(), gdcm::SerieHelper::SetSortOrderToReverse(), vtkGdcmReader::SetUserFunction(), gdcm::SerieHelper::SetUserLessThanFunction(), START_USAGE, userSuppliedLessThanFunction(), userSuppliedLessThanFunction2(), userSuppliedMirrorFunction(), userSuppliedTopDownFunction(), and vtkFloatingPointType.

00100 {
00101    START_USAGE(usage)
00102    " \n vtkgdcmSerieViewer2 : \n",
00103    " Display a 'Serie' (same Serie UID) within a Directory                    ",
00104    " You can navigate through the stack by hitting any character key.         ",
00105    " usage: vtkgdcmSerieViewer dirname=sourcedirectory                        ",
00106    "                           [noshadowseq][noshadow][noseq]                 ",
00107    "                           [reverse] [{[mirror]|[topdown]|[rotate]}]      ",
00108    "                           [order=] [check][debug]                        ",
00109    "      sourcedirectory : name of the directory holding the images          ",
00110    "                        if it holds more than one serie,                  ",
00111    "                        only the first one id displayed.                  ",
00112    "      noshadowseq: user doesn't want to load Private Sequences            ",
00113    "      noshadow   : user doesn't want to load Private groups (odd number)  ",
00114    "      noseq      : user doesn't want to load Sequences                    ",
00115    "      reverse    : user wants to sort the images reverse order            ",
00116    "      mirror     : user wants to 'mirror' the images | just some simple   ",
00117    "      topdown    : user wants to 'topdown' the images| examples of user   ",
00118    "      rotate     : NOT YET MADE (useless?)           | supplied functions ",
00119    "      check      : user wants to force more coherence checking            ",
00120    "      order=     : group1-elem1,group2-elem2,... (in hexa, no space)      ",
00121    "                   if we want to use them as a sort criterium             ",
00122    "                   Right now : ValEntries only -just an example-          ",
00123    "        or                                                                ",
00124    "      order=     : order=name if we want to sort on file name (why not ?) ",
00125    "      debug      : user wants to run the program in 'debug mode'          ",
00126    FINISH_USAGE
00127 
00128 
00129    // Initialize Arguments Manager   
00130    gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
00131   
00132    if (argc == 1 || am->ArgMgrDefined("usage") )
00133    {
00134       am->ArgMgrUsage(usage); // Display 'usage'
00135       delete am;
00136       return 0;
00137    }
00138 
00139    char *dirName = am->ArgMgrWantString("dirname",usage);
00140 
00141    int loadMode = gdcm::LD_ALL;
00142    if ( am->ArgMgrDefined("noshadowseq") )
00143       loadMode |= gdcm::LD_NOSHADOWSEQ;
00144    else 
00145    {
00146       if ( am->ArgMgrDefined("noshadow") )
00147          loadMode |= gdcm::LD_NOSHADOW;
00148       if ( am->ArgMgrDefined("noseq") )
00149          loadMode |= gdcm::LD_NOSEQ;
00150    }
00151 
00152    int reverse = am->ArgMgrDefined("reverse");
00153 
00154    int mirror  = am->ArgMgrDefined("mirror");
00155    int topdown = am->ArgMgrDefined("topdown");
00156    int rotate  = am->ArgMgrDefined("rotate");
00157 
00158    if ( mirror && topdown )
00159    {
00160       std::cout << "mirror *OR* topDown !"
00161                 << std::endl;
00162       delete am;
00163       return 0;
00164    }
00165    if ( rotate )
00166    {
00167       std::cout << "'rotate' undealt with -> ignored !"
00168                 << std::endl;
00169    }
00170 
00171    int check   = am->ArgMgrDefined("check");
00172   
00173    // This is so ugly, a cstring is NOT a char * (god damit!)
00174    bool bname = ( strcmp(am->ArgMgrGetString("order", (char*)"not found"),"name")==0 );
00175    if (bname)
00176       elemsToOrderOn = am->ArgMgrGetXInt16Enum("order", &orderNb);
00177 
00178    if (am->ArgMgrDefined("debug"))
00179       gdcm::Debug::DebugOn();
00180 
00181    /* if unused Param we give up */
00182    if ( am->ArgMgrPrintUnusedLabels() )
00183    {
00184       am->ArgMgrUsage(usage);
00185       delete am;
00186       return 0;
00187    } 
00188 
00189    delete am;  // we don't need Argument Manager any longer
00190 
00191    // ----------------------- End Arguments Manager ----------------------
00192   
00193    gdcm::SerieHelper *sh = gdcm::SerieHelper::New();
00194    sh->SetLoadMode(loadMode);
00195    if (reverse)
00196       sh->SetSortOrderToReverse();
00197    sh->SetDirectory( dirName, true);
00198     
00199    // Just to see
00200 
00201    int nbFiles;
00202    // For all the 'Single Serie UID' FileSets of the gdcm::Serie
00203    gdcm::FileList *l = sh->GetFirstSingleSerieUIDFileSet();
00204    if (l == 0 )
00205    {
00206       std::cout << "Oops! No 'Single Serie UID' FileSet found ?!?" << std::endl;
00207       return 0;
00208    }
00209 
00210    if (bname)
00211      sh->SetUserLessThanFunction(userSuppliedLessThanFunction2);
00212    else if (orderNb != 0)
00213       sh->SetUserLessThanFunction(userSuppliedLessThanFunction);
00214 
00215    while (l)
00216    { 
00217       nbFiles = l->size() ;
00218       if ( l->size() > 1 )
00219       {
00220          std::cout << "Sort list : " << nbFiles << " long" << std::endl;
00221          sh->OrderFileList(l);  // sort the list
00222          std::cout << "List sorted" << std::endl;
00223          break;  // The first one is OK. user will have to check
00224       }
00225       else
00226       {
00227          std::cout << "Oops! Empty 'Single Serie UID' FileSet found ?!?"
00228                    << std::endl;
00229       }
00230       l = sh->GetNextSingleSerieUIDFileSet();
00231    }
00232 
00233    if (check)
00234    {
00235       if ( !sh->IsCoherent(l) ) // just be sure (?)
00236       {
00237          std::cout << "Files are not coherent. Stop everything " << std::endl;
00238          sh->Delete();
00239          return 0;
00240       }
00241    }
00242 
00243    vtkGdcmReader *reader = vtkGdcmReader::New();
00244    reader->AllowLookupTableOff();
00245 
00246    if (mirror)
00247       reader->SetUserFunction (userSuppliedMirrorFunction);
00248    else if (topdown)
00249       reader->SetUserFunction (userSuppliedTopDownFunction);
00250 
00251    // Only the first FileList is dealt with (just an example)
00252    // (The files will not be parsed twice by the reader)
00253 
00254    //---------------------------------------------------------
00255    reader->SetCoherentFileList(l);
00256    //---------------------------------------------------------
00257 
00258    // because we passed a Coherent File List from a SerieHelper,
00259    // setting LoadMode is useless in this case
00260    //  reader->SetLoadMode(NO_SHADOWSEQ);  
00261    reader->Update();
00262 
00263    //print debug info:
00264    reader->GetOutput()->Print( cout );
00265 
00266    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
00267 
00268    vtkImageViewer2 *viewer = vtkImageViewer2::New();
00269 
00270    if( reader->GetLookupTable() )
00271    {
00272       //convert to color:
00273       vtkImageMapToColors *map = vtkImageMapToColors::New ();
00274       map->SetInput (reader->GetOutput());
00275       map->SetLookupTable (reader->GetLookupTable());
00276       map->SetOutputFormatToRGB();
00277       viewer->SetInput ( map->GetOutput() );
00278       map->Delete();
00279    }
00280    else
00281    {
00282       vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
00283       viewer->SetColorLevel (0.5 * (range[1] + range[0]));
00284       viewer->SetColorWindow (range[1] - range[0]);
00285 
00286       viewer->SetInput ( reader->GetOutput() );
00287    }
00288    viewer->SetupInteractor (iren);
00289   
00290    //vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
00291    //viewer->SetColorWindow (range[1] - range[0]);
00292    //viewer->SetColorLevel (0.5 * (range[1] + range[0]));
00293 
00294    // Here is where we setup the observer, 
00295    vtkgdcmObserver *obs = vtkgdcmObserver::New();
00296    obs->ImageViewer = viewer;
00297    iren->AddObserver(vtkCommand::CharEvent,obs);
00298    obs->Delete();
00299 
00300    //viewer->Render();
00301    iren->Initialize();
00302    iren->Start();
00303 
00304    //if you wish you can export dicom to a vtk file  
00305    vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
00306    writer->SetInput( reader->GetOutput());
00307    writer->SetFileName( "foo.vtk" );
00308    writer->SetFileTypeToBinary();
00309    //writer->Write();
00310 
00311    reader->Delete();
00312    iren->Delete();
00313    viewer->Delete();
00314    writer->Delete();
00315 
00316    return 0;
00317 }

bool userSuppliedLessThanFunction gdcm::File f1,
gdcm::File f2
 

bool userSuppliedLessThanFunction2 gdcm::File f1,
gdcm::File f2
 

void userSuppliedMirrorFunction uint8_t *  im,
gdcm::File f
 

void userSuppliedTopDownFunction uint8_t *  im,
gdcm::File f
 


Variable Documentation

uint16_t* elemsToOrderOn
 

Definition at line 60 of file vtkgdcmSerieViewer2.cxx.

int orderNb
 

Definition at line 59 of file vtkgdcmSerieViewer2.cxx.


Generated on Fri Jan 20 10:14:29 2006 for gdcm by  doxygen 1.4.4