vtkWriteDicomExtended.cxx File Reference

#include <iostream>
#include <vtkImageMapToColors.h>
#include <vtkLookupTable.h>
#include <vtkImageData.h>
#include "vtkGdcmReader.h"
#include "vtkGdcmWriter.h"
#include "gdcmArgMgr.h"
#include "gdcmFile.h"

Include dependency graph for vtkWriteDicomExtended.cxx:

Go to the source code of this file.

Defines

#define vtkFloatingPointType   float

Functions

int main (int argc, char *argv[])


Define Documentation

#define vtkFloatingPointType   float
 

Definition at line 17 of file vtkWriteDicomExtended.cxx.


Function Documentation

int main int  argc,
char *  argv[]
 

Todo:
: fix stupid generated image names (later : JPRx)

Definition at line 24 of file vtkWriteDicomExtended.cxx.

References FINISH_USAGE, and START_USAGE.

00025 {
00026    START_USAGE(usage)
00027    " \n vtkWriteDicomExtended : \n",
00028    " Reads a DICOM file and re writes it according to user's requierements.   ",
00029    "                                                                          ",
00030    " usage: vtkWriteDicomExtended filein=dicom file to read                   ",
00031    "                           [filecontent = ] [2D]                          ",
00032    "                           [noshadowseq][noshadow][noseq]                 ",
00033    "                           [debug]                                        ",
00034    "      filecontent = 1 : USER_OWN_IMAGE                                    ",
00035    "                  = 2 : FILTERED_IMAGE                                    ",
00036    "                  = 3 : CREATED_IMAGE                                     ",
00037    "                  = 4 : UNMODIFIED_PIXELS_IMAGE                           ",
00038    "      noshadowseq: user doesn't want to load Private Sequences            ",
00039    "      noshadow   : user doesn't want to load Private groups (odd number)  ",
00040    "      noseq      : user doesn't want to load Sequences                    ",
00041    "      debug      : user wants to run the program in 'debug mode'          ",
00042    FINISH_USAGE
00043    
00044    
00045     // Initialize Arguments Manager   
00046    GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
00047   
00048    if (argc == 1 || am->ArgMgrDefined("usage") )
00049    {
00050       am->ArgMgrUsage(usage); // Display 'usage'
00051       delete am;
00052       return 0;
00053    }
00054    
00055    int loadMode = GDCM_NAME_SPACE::LD_ALL;
00056    if ( am->ArgMgrDefined("noshadowseq") )
00057       loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
00058    else 
00059    {
00060       if ( am->ArgMgrDefined("noshadow") )
00061          loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
00062       if ( am->ArgMgrDefined("noseq") )
00063          loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
00064    }
00065    
00066    int filecontent =  am->ArgMgrGetInt("filecontent", 1);
00067    
00068    char *filein = am->ArgMgrWantString("filein",usage);
00069    char *fileout = (char *)(am->ArgMgrGetString("fileout","fileout"));
00070    
00071    if (am->ArgMgrDefined("debug"))
00072       GDCM_NAME_SPACE::Debug::DebugOn();
00073       
00074    int deuxD = am->ArgMgrDefined("2D");
00075 
00076    /* if unused Param we give up */
00077    if ( am->ArgMgrPrintUnusedLabels() )
00078    {
00079       am->ArgMgrUsage(usage);
00080       delete am;
00081       return 0;
00082    }
00083    
00084 // ------------------------------------------------------------  
00085    std::vector<GDCM_NAME_SPACE::File* > cfl;
00086          
00087    GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
00088    f->SetFileName(filein);
00089    f->Load();
00090    cfl.push_back(f);
00091   
00092    vtkGdcmReader *reader = vtkGdcmReader::New();
00093    reader->AllowLookupTableOff();
00094    //reader->SetFileName( filein );
00095    // in order not to parse twice the input file.
00096    reader->SetCoherentFileList(&cfl);
00097    reader->Update();
00098 
00099    vtkImageData *output;
00100    if( reader->GetLookupTable() )
00101    {
00102       //convert to color:
00103       vtkImageMapToColors *map = vtkImageMapToColors::New ();
00104       map->SetInput (reader->GetOutput());
00105       map->SetLookupTable (reader->GetLookupTable());
00106       map->SetOutputFormatToRGB();
00107       output = map->GetOutput();
00108       map->Delete();
00109    }
00110    else
00111    {
00112       output = reader->GetOutput();
00113    }
00114   
00115    //print debug info:
00116    output->Print(cout);
00117 
00119    // WRITE...
00120    //if you wish you can export dicom to a vtk file 
00121    // this file will have the add of .tmp.dcm extention
00122    
00123    std::string fileName(filein);
00124    vtkGdcmWriter *writer = vtkGdcmWriter::New();
00125       
00126    switch (filecontent)
00127    {
00128       case 1:
00129          writer->SetContentTypeToUserOwnImage();
00130          fileName = fileName + "_UserOwnImage.dcm";
00131          break;
00132  
00133       case 2:
00134          writer->SetContentTypeToFilteredImage();
00135          writer->SetGdcmFile( f );
00136          fileName = fileName + "_FilteredImage.dcm";
00137          break;
00138  
00139       case 3:
00140          writer->SetContentTypeToUserCreatedImage();
00141          writer->SetGdcmFile( f );
00142          fileName = fileName + "_UserCreatedImage.dcm";
00143          break;
00144  
00145       case 4:
00146          writer->SetContentTypeToUserCreatedImage();
00147          writer->SetGdcmFile( f ); 
00148          fileName = fileName + "_UnmodifiedPixelsImage.dcm";
00149          break; 
00150    }
00151    
00153 
00154    if(deuxD)
00155    {
00156          writer->SetFileDimensionality(2);
00157          writer->SetFilePrefix(fileout);
00158          writer->SetFilePattern("%s%d.dcm");
00159    }
00160    else
00161    {
00162       fileName += ".dcm";
00163       // For 3D
00164       writer->SetFileDimensionality(3);
00165       writer->SetFileName(fileName.c_str());   
00166    }
00167 
00168    writer->SetInput(output);
00169    writer->Write();
00171 
00172    // Clean up
00173    writer->Delete();
00174    reader->Delete();
00175 
00176    return 0;
00177 }


Generated on Fri Aug 24 12:56:18 2007 for gdcm by  doxygen 1.4.6