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_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 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 339 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 404 of file vtkgdcmSerieViewer2.cxx.

#define vtkFloatingPointType   float
 

Definition at line 52 of file vtkgdcmSerieViewer2.cxx.


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 109 of file vtkgdcmSerieViewer2.cxx.

References FINISH_USAGE, and START_USAGE.

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

bool userSuppliedLessThanFunction GDCM_NAME_SPACE::File f1,
GDCM_NAME_SPACE::File f2
 

bool userSuppliedLessThanFunction2 GDCM_NAME_SPACE::File f1,
GDCM_NAME_SPACE::File f2
 

void userSuppliedMirrorFunction uint8_t *  im,
GDCM_NAME_SPACE::File f
 

void userSuppliedUpsideDownFunction uint8_t *  im,
GDCM_NAME_SPACE::File f
 

Definition at line 420 of file vtkgdcmSerieViewer2.cxx.

References GDCM_NAME_SPACE::File::GetZSize().

00421 {
00422    if (f->GetZSize() != 1)
00423    {
00424       std::cout << "mirror : Multiframe images not yet dealt with" << std::endl;
00425       return;
00426    }
00427 
00428    if (f->GetSamplesPerPixel() != 1 || f->GetBitsAllocated() == 24)
00429    {
00430       std::cout << "mirror : RGB / YBR not yet dealt with" << std::endl;
00431       return;
00432    }
00433    int nx = f->GetXSize();
00434    int ny = f->GetYSize();
00435 
00436    std::string pixelType = f->GetPixelType();
00437    if ( pixelType ==  "8U" || pixelType == "8S" )
00438    {
00439       UF2(uint8_t)
00440       return;
00441    }
00442    if ( pixelType == "16U" || pixelType == "16S")
00443    {
00444       UF2(uint16_t)
00445       return;
00446    }
00447    std::cout << "topdown : Pixel Size (!=8, !=16) not yet dealt with" 
00448              << std::endl;
00449    return;
00450 }


Variable Documentation

uint16_t* elemsToOrderOn
 

Definition at line 61 of file vtkgdcmSerieViewer2.cxx.

int orderNb
 

Definition at line 60 of file vtkgdcmSerieViewer2.cxx.


Generated on Fri Aug 24 13:01:15 2007 for gdcm by  doxygen 1.4.6