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

Fixing DCMTK code to work when DICOM support is not enabled.

parent 260e337e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@

inline tnlDicomHeader::tnlDicomHeader()
{
#ifdef HAVE_DCMTK_H
    fileFormat = new DcmFileFormat();
#endif    
    isLoaded = false;
    imageInfoObj = new tnlDicomImageInfo(*this);
    patientInfoObj = new tnlDicomPatientInfo(*this);
@@ -37,25 +39,31 @@ inline tnlDicomHeader::~tnlDicomHeader()
    delete imageInfoObj;
    delete patientInfoObj;
    delete seriesInfoObj;
#ifdef HAVE_DCMTK_H    
    delete fileFormat;
#endif    
}

inline bool tnlDicomHeader::loadFromFile( const tnlString& fileName )
{
#ifdef HAVE_DCMTK_H
    OFCondition status = fileFormat->loadFile( fileName.getString() );
    if(status.good())
    {
        isLoaded = true;
        return true;
    }
#endif    
    isLoaded = false;
    return false;
}

#ifdef HAVE_DCMTK_H
inline DcmFileFormat &tnlDicomHeader::getFileFormat()
{
    return *fileFormat;
}
#endif

inline tnlDicomImageInfo &tnlDicomHeader::getImageInfo()
{
+8 −4
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
 *                                                                         *
 ***************************************************************************/

#include "tnlDicomImageInfo.h"
#include "tnlDicomHeader.h"
#include <core/images/tnlDicomImageInfo.h>
#include <core/images/tnlDicomHeader.h>

inline tnlDicomImageInfo::tnlDicomImageInfo( tnlDicomHeader& dicomHeader )
: dicomHeader( dicomHeader )
@@ -34,7 +34,7 @@ inline tnlDicomImageInfo::~tnlDicomImageInfo()

inline bool tnlDicomImageInfo::retrieveInfo()
{

#ifdef HAVE_DCMTK_H
   dicomHeader.getFileFormat().getDataset()->findAndGetFloat64(DCM_ImagePositionPatient,imagePositionToPatient.x,0);
   dicomHeader.getFileFormat().getDataset()->findAndGetFloat64(DCM_ImagePositionPatient,imagePositionToPatient.y,1);
   dicomHeader.getFileFormat().getDataset()->findAndGetFloat64(DCM_ImagePositionPatient,imagePositionToPatient.z,2);
@@ -57,7 +57,11 @@ inline bool tnlDicomImageInfo::retrieveInfo()
   dicomHeader.getFileFormat().getDataset()->findAndGetFloat64(DCM_PixelSpacing,pixelSpacing.y,1);

   isObjectRetrieved = true;
   return 0;
   return true;
#else
   cerr << "DICOM format is not supported in this build of TNL." << endl;
   return false;
#endif   
}

inline ImagePositionToPatient tnlDicomImageInfo::getImagePositionToPatient()
+6 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ inline tnlDicomPatientInfo::~tnlDicomPatientInfo()

inline bool tnlDicomPatientInfo::retrieveInfo()
{
#ifdef HAVE_DCMTK_H
   OFString str;
   dicomHeader.getFileFormat().getDataset()->findAndGetOFString(DCM_PatientName, str );
   this->name.setString( str.data() );
@@ -55,7 +56,11 @@ inline bool tnlDicomPatientInfo::retrieveInfo()
   this->patientOrientation.setString( str.data() ); 

   isObjectRetrieved = true;
   return 0;
   return true;
#else
   cerr << "DICOM format is not supported in this build of TNL." << endl;
   return false;
#endif   
}

inline const tnlString& tnlDicomPatientInfo::getName()
+6 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ inline tnlDicomSeriesInfo::~tnlDicomSeriesInfo()

inline bool tnlDicomSeriesInfo::retrieveInfo()
{
#ifdef HAVE_DCMTK_H
   OFString str;    
   dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_Modality, str );
   this->modality.setString( str.data() );
@@ -90,7 +91,11 @@ inline bool tnlDicomSeriesInfo::retrieveInfo()
    //std::cout << faDateTime << " " << faRefTime << " "<< AFD << " " << AT << std::endl;

    isObjectRetrieved = true;
    return 0;
    return true;
#else
    cerr << "DICOM format is not supported in this build of TNL." << endl;
    return false;
#endif    
}

inline const tnlString& tnlDicomSeriesInfo::getModality()
+22 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
#include <dirent.h>


int findLastIndexOf(tnlString &str, char * const c)
int findLastIndexOf(tnlString &str, const char* c)
{
    for (int i = str.getLength(); i > -1; i--)
    {
@@ -46,8 +46,10 @@ int filter(const struct dirent *dire)
inline tnlDicomSeries::tnlDicomSeries( const tnlString& filePath)
{
    fileList = new tnlList<tnlString *>();
#ifdef HAVE_DCMTK_H
    dicomImage = 0;
    pixelData = 0;
#endif    
    imagesInfo.imagesCount = 0;
    imagesInfo.maxColorValue = 0;
    imagesInfo.minColorValue = 128000;
@@ -71,11 +73,13 @@ inline tnlDicomSeries::~tnlDicomSeries()
        header = 0;
    }

#ifdef HAVE_DCMTK_H    
    if(dicomImage)
        delete dicomImage;

    if(pixelData)
        delete pixelData;
#endif    
}

template< typename Real,
@@ -89,6 +93,7 @@ getImage( const int imageIdx,
          const tnlRegionOfInterest< int > roi,
          Vector& vector )
{
#ifdef HAVE_DCMTK_H
   const Uint16* imageData = this->getData( imageIdx );
   typedef tnlGrid< 2, Real, Device, Index > GridType;
   typedef typename GridType::CoordinatesType CoordinatesType;
@@ -105,13 +110,17 @@ getImage( const int imageIdx,
                                                                  roi.getBottom() - 1 - i ) );
            Uint16 col = imageData[ position ];
            vector.setElement( cellIndex, ( Real ) col / ( Real ) 65535 );
            cout << vector.getElement( cellIndex ) << " ";
            //cout << vector.getElement( cellIndex ) << " ";
         }
         position++;
      }
      cout << endl;
      //cout << endl;
   }
   return true;
#else
   cerr << "DICOM format is not supported in this build of TNL." << endl;
   return false;     
#endif
}

inline bool tnlDicomSeries::retrieveFileList( const tnlString& filePath)
@@ -178,6 +187,7 @@ inline bool tnlDicomSeries::retrieveFileList( const tnlString& filePath)

inline bool tnlDicomSeries::loadImage( const tnlString& filePath, int number)
{
#ifdef HAVE_DCMTK_H
   //load header
   tnlDicomHeader *header = new tnlDicomHeader();
   dicomSeriesHeaders.setSize( fileList->getSize() );
@@ -307,6 +317,10 @@ inline bool tnlDicomSeries::loadImage( const tnlString& filePath, int number)
    delete dicomImage;
    dicomImage = NULL;
    return true;
#else
    cerr << "DICOM format is not supported in this build of TNL." << endl;
    return false;
#endif    
}


@@ -338,10 +352,12 @@ inline int tnlDicomSeries::getImagesCount()
    return imagesInfo.imagesCount;
}

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

inline int tnlDicomSeries::getColorCount()
{
@@ -370,9 +386,11 @@ inline int tnlDicomSeries::getMaxColorValue()

inline void tnlDicomSeries::freeData()
{
#ifdef HAVE_DCMTK_H
    if (pixelData)
        delete pixelData;
    pixelData = NULL;
#endif    
}

inline tnlDicomHeader &tnlDicomSeries::getHeader(int image)