Commit cfcd049e authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing the DICOM reader.

parent 2f0b73d8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -160,6 +160,10 @@ if( DCMTK_FOUND )
   set( HAVE_DCMTK_H "#define HAVE_DCMTK_H 1" )
   include_directories( ${DCMTK_INCLUDE_DIRS} )
   set( HAVE_DCMTK TRUE)
   set( DCMTK_LD_FLAGS "" )
   foreach( arg ${DCMTK_LIBRARIES} )
      set( DCMTK_LD_FLAGS "${DCMTK_LD_FLAGS} ${arg}" )
   endforeach( arg ${DCMTK_LIBRARIES} )
else()
   set( HAVE_DCMTK_H "//#define HAVE_DCMTK_H 1" )
endif()
+6 −2
Original line number Diff line number Diff line
@@ -72,13 +72,17 @@ class tnlDicomSeries : public tnlImage< int >

      inline int getImagesCount();
            
      template< typename Vector >
      template< typename Real,
                typename Device,
                typename Index,
                typename Vector >
      bool getImage( const int imageIdx,
                     const tnlGrid< 2, Real, Device, Index >& grid,
                     const tnlRegionOfInterest< int > roi,
                     Vector& vector );
       
#ifdef HAVE_DCMTK_H       
      inline const Uint16 *getData();
      inline const Uint16 *getData( int imageNumber = 0 );
#endif       
       
      inline int getColorCount();
+94 −48
Original line number Diff line number Diff line
@@ -78,20 +78,61 @@ inline tnlDicomSeries::~tnlDicomSeries()
        delete pixelData;
}

template< typename Real,
          typename Device,
          typename Index,
          typename Vector >
bool
tnlDicomSeries::
getImage( const int imageIdx,
          const tnlGrid< 2, Real, Device, Index >& grid,
          const tnlRegionOfInterest< int > roi,
          Vector& vector )
{
   const Uint16* imageData = this->getData( imageIdx );
   typedef tnlGrid< 2, Real, Device, Index > GridType;
   typedef typename GridType::CoordinatesType CoordinatesType;
   
   Index i, j;
   int position( 0 );
   for( i = 0; i < this->height; i ++ )
   {
      for( j = 0; j < this->width; j ++ )
      {
         if( roi.isIn( i, j ) )
         {
            Index cellIndex = grid.getCellIndex( CoordinatesType( j - roi.getLeft(),
                                                                  roi.getBottom() - 1 - i ) );
            Uint16 col = imageData[ position ];
            vector.setElement( cellIndex, ( Real ) col / ( Real ) this->getMaxColorValue() );
            cout << vector.getElement( cellIndex ) << " ";
         }
         position++;
      }
      cout << endl;
   }
   return true;
}

inline bool tnlDicomSeries::retrieveFileList( const tnlString& filePath)
{
    tnlString filePathString(filePath);
    tnlString suffix(filePath.getString(), filePathString.getLength() - 3);
    //char *ima = "ima";
    //char *dcm = "dcm";

    //check DICOM files
    /***
     * Check DICOM files
     */
   if( suffix != "ima" && suffix != "dcm" )
   {
       cerr << "The given file is not a DICOM file." << endl;
      return false;
   }

   int fileNamePosition = findLastIndexOf(filePathString,"/");

    //parse file path
   /***
    * Parse file path
    */
   tnlString fileName(filePath.getString(), fileNamePosition);
   tnlString directoryPath(filePath.getString(), 0, filePathString.getLength() - fileNamePosition);

@@ -271,9 +312,14 @@ inline bool tnlDicomSeries::loadImage( const tnlString& filePath, int number)

inline bool tnlDicomSeries::loadDicomSeries( const tnlString& filePath )
{
   //load list of files
   /***
    * Load list of files
    */
   if( ! retrieveFileList( filePath ) )
   {
      cerr << "I am not able to retrieve the files of the DICOM series in " << filePath << "." << endl;
      return false;
   }

   //load images
   int imagesCountToLoad = fileList->getSize();
@@ -292,9 +338,9 @@ inline int tnlDicomSeries::getImagesCount()
    return imagesInfo.imagesCount;
}

inline const Uint16 *tnlDicomSeries::getData()
inline const Uint16 *tnlDicomSeries::getData( int imageNumber )
{
    return pixelData;
    return &pixelData[ imageNumber * imagesInfo.frameUintsCount ];
}

inline int tnlDicomSeries::getColorCount()
+20 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <config/tnlConfigDescription.h>
#include <config/tnlParameterContainer.h>
#include <core/images/tnlDicomSeries.h>
#include <core/mfilename.h>

void setupConfig( tnlConfigDescription& config )
{
@@ -52,7 +53,12 @@ bool processDicomSeries( const tnlParameterContainer& parameters )
   for( int i = 0; i < dicomSeriesNames.getSize(); i++ )
   {
      const tnlString& seriesName = dicomSeriesNames[ i ];
      cout << "Reading a file " << seriesName << endl;   
      tnlDicomSeries dicomSeries( seriesName.getString() );
      if( !dicomSeries.isDicomSeriesLoaded() )
      {
         cerr << "Loading of the DICOM series " << seriesName << " failed." << endl;
      }
      if( i == 0 )
      {
         if( ! roi.setup( parameters, &dicomSeries ) )
@@ -61,9 +67,16 @@ bool processDicomSeries( const tnlParameterContainer& parameters )
         vector.setSize( grid.getNumberOfCells() );
         cout << "Writing grid to file " << meshFile << endl;
         grid.save( meshFile );

      }
      
      cout << "The series consists of " << dicomSeries.getImagesCount() << " images." << endl;
      for( int imageIdx = 0; imageIdx < dicomSeries.getImagesCount(); imageIdx++ )
      {
         dicomSeries.getImage( imageIdx, grid, roi, vector );
         tnlString fileName;
         FileNameBaseNumberEnding( seriesName.getString(), imageIdx, 2, ".tnl", fileName );
         cout << "Writing file " << fileName << " ... " << endl;
         vector.save( fileName );
      }      
   }
}
#endif
@@ -71,17 +84,18 @@ bool processDicomSeries( const tnlParameterContainer& parameters )
int main( int argc, char* argv[] )
{
   tnlParameterContainer parameters;
   tnlConfigDescription conf_desc;
   setupConfig( conf_desc );
   if( ! parseCommandLine( argc, argv, conf_desc, parameters ) )
   tnlConfigDescription configDescription;
   setupConfig( configDescription );
   if( ! parseCommandLine( argc, argv, configDescription, parameters ) )
   {
      conf_desc.printUsage( argv[ 0 ] );
      configDescription.printUsage( argv[ 0 ] );
      return EXIT_FAILURE;
   }   
   if( ! parameters.checkParameter( "dicom-files" ) &&
       ! parameters.checkParameter( "dicom-series") )
   {
       cerr << "Neither DICOM series nor DICOM files are given." << endl;
       configDescription.printUsage( argv[ 0 ] );
       return EXIT_FAILURE;
   }
#ifdef HAVE_DCMTK_H   
+7 −3
Original line number Diff line number Diff line
@@ -195,14 +195,18 @@ bool processTNLFiles( const tnlParameterContainer& parameters )
int main( int argc, char* argv[] )
{
   tnlParameterContainer parameters;
   tnlConfigDescription conf_desc;
   configSetup( conf_desc );
   if( ! parseCommandLine( argc, argv, conf_desc, parameters ) )
   tnlConfigDescription configDescription;
   configSetup( configDescription );
   if( ! parseCommandLine( argc, argv, configDescription, parameters ) )
   {
      configDescription.printUsage( argv[ 0 ] );
      return EXIT_FAILURE;
   }
   if( ! parameters.checkParameter( "input-images" ) &&
       ! parameters.checkParameter( "input-files") )
   {
       cerr << "Neither input images nor input .tnl files are given." << endl;
       configDescription.printUsage( argv[ 0 ] );
       return EXIT_FAILURE;
   }
   if( parameters.checkParameter( "input-images" ) && ! processImages( parameters ) )
Loading