INCLUDE(${crea_USE_FILE})
ENDIF(crea_FOUND)
-SET(USE_GDCM ON)
-#SET(USE_GDCM2 ON)
+
+
+
SET(USE_GDCM_VTK ON)
SET(USE_VTK ON)
SET(USE_BOOST ON)
SET(USE_WXWIDGETS ON)
+OPTION(USE_GDCM ON)
+OPTION(USE_GDCM2 OFF)
+
CREA_FIND_AND_USE_LIBRARIES()
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
ENDIF(WIN32)
+
OPTION(BUILD_V2 "Build Version 2 ?" ON)
IF (BUILD_V2)
SUBDIRS(src)
ENDIF (BUILD_V2)
-
OPTION(BUILD_CREA_BRUKER "Build creaIRM with creaBruker?" ON)
IF (BUILD_CREA_BRUKER)
SUBDIRS(bbtk)
SUBDIRS(win32)
SUBDIRS(install)
+
creaImageIOListener.cpp
)
+
+
# Attributed tree data structure
FILE(GLOB SOURCES_CREAIMAGEIO_TREE
creaImageIOTree.cpp
creaImageIOTreeHandlerImageAdder.cpp
creaImageIOSQLiteTreeHandler.cpp
)
-
+IF(USE_GDCM)
+ FILE(GLOB SOURCES_CREAIMAGEIO_IMG_DICOM_READER
+ creaImageIODicomImageReader.cpp)
+ENDIF(USE_GDCM)
+
+
+IF(USE_GDCM2)
+ FILE(GLOB SOURCES_CREAIMAGEIO_IMG_DICOM_READER
+ creaImageIODicomImageReader2.cpp)
+ENDIF(USE_GDCM2)
+
# Image Readers
FILE(GLOB SOURCES_CREAIMAGEIO_IMG_READER
creaImageIOAbstractImageReader.cpp
- creaImageIODicomImageReader.cpp
creaImageIOImageReader.cpp
creaImageIOUltrasonixImageReader.cpp
creaImageIOVtkImageReader.cpp
creaImageIOMultiThreadImageReader.cpp
+ ${SOURCES_CREAIMAGEIO_IMG_DICOM_READER}
)
SOURCE_GROUP("Source Files\\PACS" FILES ${SOURCES_CREAIMAGEIO_PACS})
SOURCE_GROUP("Header Files\\PACS" FILES ${HEADER_CREAIMAGEIO_PACS})
endif(BUILD_CREA_PACS)
-SOURCE_GROUP("Source Files\\Readers" FILES ${SOURCES_CREAIMAGEIO_IMG_READER})
+SOURCE_GROUP("Source Files\\Readers" FILES ${SOURCES_CREAIMAGEIO_IMG_READER}
+ ${SOURCES_CREAIMAGEIO_IMG_DICOM_READER})
SOURCE_GROUP("Source Files\\Tree" FILES ${SOURCES_CREAIMAGEIO_TREE})
${SOURCES_CREAIMAGEIO}
${HEADER_CREAIMAGEIO}
${SOURCES_CREAIMAGEIO_IMG_READER}
+ ${SOURCES_CREAIMAGEIO_IMG_DICOM_READER}
${SOURCES_CREAIMAGEIO_WX}
${SOURCES_CREAIMAGEIO_TREE}
)
#include <creaImageIODicomImageReader.h>
#include <vtkGdcmReader.h>
+
+
+
#include <creaImageIOSystem.h>
#include "boost/filesystem/path.hpp"
mReader = vtkGdcmReader::New();
//EED mReader->SetFlipY(false);
SetName ( "Dicom" );
+
};
//=====================================================================
--- /dev/null
+#include <creaImageIODicomImageReader2.h>
+
+
+
+#include <creaImageIOSystem.h>
+#include "boost/filesystem/path.hpp"
+
+#include <creaImageIOTreeAttributeDescriptor.h>
+#include <vtkStringArray.h>
+#include <creaImageIOGimmick.h>
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+namespace creaImageIO
+{
+
+ //=====================================================================
+ DicomImageReader::DicomImageReader()
+ {
+ mReader = vtkGDCMImageReader::New();
+ SetName ( "Dicom" );
+
+ };
+ //=====================================================================
+
+ //=====================================================================
+ DicomImageReader::~DicomImageReader()
+ {
+ mReader->Delete();
+ }
+ //=====================================================================
+
+ //=====================================================================
+ bool DicomImageReader::CanRead(const std::string& filename)
+ {
+ gdcm::Reader reader;
+ reader.SetFileName( filename.c_str() );
+ return reader.Read();
+
+ }
+ //=====================================================================
+
+ //=====================================================================
+ vtkImageData* DicomImageReader::ReadImage(const std::string& filename)
+ {
+ vtkImageData* im = 0;
+ try
+ {
+ mReader->SetFileName(filename.c_str());
+ mReader->Update();
+ im = vtkImageData::New();
+ im->ShallowCopy(mReader->GetOutput());
+ }
+ catch (...)
+ {
+ if (im!=0) im->Delete();
+ im = 0;
+ }
+ return im;
+ }
+
+ //=====================================================================
+ void DicomImageReader::PushBackExtensions(std::vector<std::string>& v)
+ {
+ v.push_back("dcm");
+ v.push_back("");
+ }
+ //=====================================================================
+
+ //========================================================================
+ std::string irclean(const std::string& str)
+ {
+ if(str.size() > 0)
+ {
+ if (str == "GDCM::Unfound")
+ {
+ return "";
+ }
+ if (str[str.size()-1]==' ')
+ {
+ return irclean(str.substr(0,str.size()-1));
+ }
+ if (str[str.size()-1]==0)
+ {
+ return irclean(str.substr(0,str.size()-1));
+ }
+ }
+
+ return str;
+ }
+ //========================================================================
+
+ //=====================================================================
+ void DicomImageReader::ReadAttributes(const std::string& filename,
+ std::map<std::string,std::string>& attr)
+ {
+ GimmickMessage(2,"Reading attributes from DICOM file '"
+ <<filename<<"'"<<std::endl);
+
+
+ gdcm::Reader reader;
+ reader.SetFileName( filename.c_str() );
+ if (reader.Read())
+ {
+ std::map<std::string,std::string>::iterator i;
+ for (i=attr.begin();i!=attr.end();++i)
+ {
+ if ( i->first == "D0004_1500" )
+ {
+ boost::filesystem::path full_path(filename);
+ std::string f = full_path.leaf();
+ i->second = f;
+ }
+ else if ( i->first == "FullFileName" )
+ {
+ i->second = filename;
+ }
+ else if ( i->first == "FullFileDirectory" )
+ {
+ std::string::size_type last_pos = filename.find_last_of("//");
+ //find first separator
+ i->second = filename.substr(0, last_pos);
+ }
+ else
+ {
+ uint16_t el;
+ uint16_t gr;
+
+ tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el);
+ if ( ( gr!=0 ) && ( el!=0 ) )
+ {
+ gdcm::DataElement de( gdcm::Tag(gr,el) );
+ std::string val = GetStringValueFromTag(reader.GetFile().GetHeader().GetDataElement(gdcm::Tag(gr,el)));
+ i->second = irclean(val);
+ }
+ }
+ }
+ }
+ }
+
+ const std::string DicomImageReader::GetStringValueFromTag(const gdcm::DataElement& de)
+{
+ static std::string buffer;
+ buffer = ""; // cleanup previous call
+
+
+ const gdcm::ByteValue *bv = de.GetByteValue();
+ if( bv ) // Can be Type 2
+ {
+ buffer = std::string( bv->GetPointer(), bv->GetLength() );
+ // Will be padded with at least one \0
+ }
+
+
+ // Since return is a const char* the very first \0 will be considered
+ return buffer.c_str();
+}
+ //=====================================================================
+
+} // namespace creaImageIO
+
--- /dev/null
+#ifndef __creaImageIODicomImageReader_h_INCLUDED__
+#define __creaImageIODicomImageReader_h_INCLUDED__
+
+
+#include <creaImageIOAbstractImageReader.h>
+#if defined(USE_GDCM2)
+#include <gdcmReader.h>
+#include <vtkGDCMImageReader.h>
+#endif
+
+class vtkGDCMImageReader;
+
+namespace creaImageIO
+{
+
+
+ /**
+ * \ingroup IO
+ */
+
+ //=====================================================================
+ /// Concrete image reader for DICOM images
+ class DicomImageReader : virtual public AbstractImageReader
+ {
+ public:
+ DicomImageReader();
+ virtual ~DicomImageReader();
+
+ /// Add file extensions read by the reader
+ virtual void PushBackExtensions(std::vector<std::string>&);
+ /// Test if file is read by this reader
+ virtual bool CanRead(const std::string& filename);
+ /// return for a file a 2D VTkImage
+ virtual vtkImageData* ReadImage(const std::string& filename);
+ /// Read the attributes for a file
+ virtual void ReadAttributes(const std::string& filename,
+ tree::AttributeMapType& attr);
+
+ private:
+ const std::string GetStringValueFromTag( const gdcm::DataElement& ds);
+ vtkGDCMImageReader *mReader;
+ struct deleter
+ {
+ void operator()(gdcm::File* p)
+ {
+ delete p;
+ }
+ };
+ friend struct deleter;
+ };
+ //=====================================================================
+
+
+
+} // namespace creaImageIO
+
+
+
+#endif // #ifndef __creaImageIODicomImageReader_h_INCLUDED__
#include <creaImageIOGimmickView.h>
#include <creaImageIOSystem.h>
#include "boost/filesystem.hpp"
+
+#if defined(USE_GDCM)
#include <gdcmGlobal.h>
#include <gdcmSerieHelper.h>
#include <vtkGdcmReader.h>
+#endif
+
+#if defined(USE_GDCM2)
+#include <vtkGDCMImageReader.h>
+#endif
+
+
namespace fs = boost::filesystem;
namespace creaImageIO
{
double spc[3];
first->GetSpacing(spc);
spc[2]=OrderTheFileNameVector(im);
+
out->SetSpacing(spc);
+
int slice = 0;
std::vector<std::string>::iterator it;
}
//======================================================================
-
-double GimmickView::OrderTheFileNameVector(std::vector<std::string> &im)
+#if defined(USE_GDCM)
+ double GimmickView::OrderTheFileNameVector(std::vector<std::string> &im)
{
double spacing=1;
typedef std::vector<GDCM_NAME_SPACE::File* > FileList;
}
+#endif
+
+#if defined(USE_GDCM2)
+ // TO DO
+ double GimmickView::OrderTheFileNameVector(std::vector<std::string> &im)
+ {
+ return 1;
+ }
+#endif
//======================================================================
#include <creaImageIOSystem.h>
#include <creaImageIOVtkImageReader.h>
-#include <creaImageIODicomImageReader.h>
+#if defined (USE_GDCM)
+ #include <creaImageIODicomImageReader.h>
+#endif
+#if defined(USE_GDCM2)
+ #include <creaImageIODicomImageReader2.h>
+#endif
#include <creaImageIOUltrasonixImageReader.h>
-
#include <vtkPNGReader.h>
#include <vtkTIFFReader.h>
#include <vtkJPEGReader.h>
Register(boost::shared_ptr<AbstractImageReader>(new DicomImageReader));
Register(boost::shared_ptr<AbstractImageReader>(new UltrasonixImageReader));
+ UnRegister(".txt");
mUnreadableImage = vtkImageData::New();
int dim[3];
{
mReader.push_back(r);
+ }
+
+ void ImageReader::UnRegister(const std::string i_val)
+ {
+ mUnReader.push_back(i_val);
+
}
//=====================================================================
+ //=====================================================================
+ // Returns true iff the file is readable
+ bool ImageReader::ShallNotRead( const std::string& filename )
+ {
+ bool ok = true;
+ if(filename != "")
+ {
+ std::vector<std::string >::iterator i ;
+ for (i=mUnReader.begin(); i!=mUnReader.end(); i++)
+ {
+
+ if ( (*i).c_str() == filename)
+ {
+ ok = false;
+ break;
+ }
+ }
+ }
+ return ok;
+
+ }
+
+
//=====================================================================
// Returns true iff the file is readable
bool ImageReader::CanRead( const std::string& filename )
{
bool ok = false;
+
+ if( !ShallNotRead(filename))
+ {
+ return ok;
+ }
if(filename != "")
{
std::vector<boost::shared_ptr<AbstractImageReader> >::iterator i;
std::string mLastFilename;
boost::shared_ptr<AbstractImageReader> mLastReader;
+
+ bool ShallNotRead( const std::string& filename );
+
+ void UnRegister(const std::string i_val);
+
+ std::vector <std::string> mUnReader;
private:
#include <creaImageIOTreeAttributeDescriptor.h>
#include <creaImageIOSystem.h>
+
+#if defined(USE_GDCM)
#include <gdcmGlobal.h>
#include <gdcmDictSet.h>
+#endif
+
+#if defined(USE_GDCM2)
+#include <gdcmGlobal.h>
+#include <gdcmDicts.h>
+#include <gdcmDict.h>
+#endif
#include <boost/algorithm/string/replace.hpp>
GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
<<"' ["<<flags<<"]"<<std::endl);
+#if defined(USE_GDCM)
// Retrieve the name from gdcm dict
GDCM_NAME_SPACE::DictEntry* entry =
GDCM_NAME_SPACE::Global::GetDicts()
mName = "UNKNOWN";
mGroup = mElement = 0;
}
-
+#endif
+
+
+
+
+#if defined(USE_GDCM2)
+ // Retrieve the name from gdcm dict
+ gdcm::Dicts dicts;
+ gdcm::DictEntry dictentry = dicts.GetDictEntry(gdcm::Tag(mGroup, mElement));
+
+ mName = dictentry.GetName();
+ if(!mName.empty())
+ {
+ CleanName(mName);
+ GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
+ }
+ else
+ {
+ GimmickMessage(1,"!! WARNING : tag '"<<mKey
+ <<"' is not in DICOM dictionnary ! "
+ <<"Considering it as a user attribute"
+ << std::endl);
+ mName = "UNKNOWN";
+ mGroup = mElement = 0;
+ }
+#endif
+
}
//=====================================================================
bool btest = false;
// Retrieve the name from gdcm dict
+#if defined(USE_GDCM)
GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
if( entry != 0)
{
btest = true;
}
}
+#endif
+#if defined(USE_GDCM2)
+ const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
+ const gdcm::Dicts &dicts = g.GetDicts();
+ const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
+
+ if(mGroup != 0 && mElement != 0)
+ {
+ gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(GetGroup(), GetElement()));
+ if( gdcm::VR::GetVRString(dictentry.GetVR()) == "DA")
+ {
+ btest = true;
+ }
+ }
+#endif
return btest;
}
{
bool btest = false;
+#if defined(USE_GDCM)
// Retrieve the name from gdcm dict
GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
if( entry != 0)
btest = true;
}
}
+#endif
+
+#if defined(USE_GDCM2)
+ const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
+ const gdcm::Dicts &dicts = g.GetDicts();
+ const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
+ if(mGroup != 0 && mElement != 0)
+ {
+ gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
+ if(gdcm::VR::GetVRString(dictentry.GetVR()) == "TM")
+ {
+ btest = true;
+ }
+ }
+#endif
+
return btest;
}
/// Decodes the type of the attribute
void AttributeDescriptor::DecodeType(unsigned int& typ) const
{
-
-
+ std::string type="";
+#if defined(USE_GDCM)
// Retrieve the name from gdcm dict
GDCM_NAME_SPACE::DictEntry* entry =
GDCM_NAME_SPACE::Global::GetDicts()
typ = 2;
return;
}
- std::string type = entry->GetVR().str();
+ type = entry->GetVR().str();
+#endif
+#if defined(USE_GDCM2)
+ const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
+ const gdcm::Dicts &dicts = g.GetDicts();
+ const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
+ gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
+ type = gdcm::VR::GetVRString(dictentry.GetVR());
+#endif
+
GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
if(type=="AS" ||
type=="DA" ||
#include "creaImageIOUltrasonixImageReader.h"
#include <creaVtk.h>
#include <boost/filesystem/path.hpp>
-
namespace creaImageIO
{
#define HEADER_SIZE 19
fclose(Ultrasonix_file);
- im = crea::NewVtkImageDataFromRaw( dataB8, h.width, h.height, h.frame);
+ im = crea::NewVtkImageDataFromRaw( dataB8, h.width, h.height, h.frame);
break;
case TYPE_B32:
fclose(Ultrasonix_file);
- im = crea::NewVtkImageDataFromRaw( dataB32, h.width, h.height, h.frame);
+ im = crea::NewVtkImageDataFromRaw( dataB32, h.width, h.height, h.frame);
break;
}
#include <creaImageIOWxCustomizeConfigPanel.h>
#include <creaImageIOSystem.h>
-
namespace creaImageIO
{
// CTor
#include "creaImageIOWxDescriptorPanel.h"
#include <creaImageIOSystem.h>
+#if defined(USE_GDCM)
#include <gdcmGlobal.h>
#include <gdcmDictSet.h>
+#endif
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string.hpp>
val.clear();
val << std::dec << el ;
val >> std::hex >> element;
-
+#if defined(USE_GDCM)
// Retrieve the name from gdcm dict
GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, element);
// AttributeCombo->Clear();
AttributeCombo->Delete(0);
AttributeCombo->Insert(_T("Unknown Attribute"),0);
}
+#endif
AttributeCombo->SetSelection(0);
}
compose += descriptors[1];
compose += "_";
compose += descriptors[2];
+#if defined(USE_GDCM)
GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, element);
if(ilevel>0)
{
onAddAttribute( entry->GetName(),compose, level);
}
+#endif
}
else if(descriptors[0].find("#") != -1)
{
#include <creaImageIOWxDumpPanel.h>
#include <creaImageIOSystem.h>
#include <creaImageIOGimmick.h>
+#if defined(USE_GDCM)
#include <gdcmGlobal.h>
#include <gdcmDictSet.h>
#include "gdcmFile.h"
#include "gdcmDocument.h"
#include "gdcmFileHelper.h"
+#endif
#include "icons/save.xpm"
namespace creaImageIO
std::stringstream os;
if ( !filename.empty()) // ====== Deal with a single file ======
{
- GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
+ /* GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
f->SetFileName( filename );
f->SetMaxSizeLoadEntry(0xffff);
f->Load();
GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
+ f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW);
fh->SetPrintLevel( 0 );
fh->Print(os);
std::string result;
std::string line;
while(std::getline(os, line))
{
- result +=line;
+ result +=clean(line.c_str());
result += "\n";
}
DumpText->SetValue(crea::std2wx(result));
+
+ std::string pixelType =f->GetPixelType();
+ int nX,nY,nZ,nT,sPP,planarConfig;
+
+ nX=f->GetXSize();
+ nY=f->GetYSize();
+ nZ=f->GetZSize();
+ nT=f->GetTSize();*/
}
}
+
+ const std::string WxDumpPanel::clean(const std::string &i_line)
+ {
+
+ if (i_line.substr(4,1) == "|")
+ {
+ std::string tag;
+ std::string line;
+ std:string signification;
+ std::string value;
+ std::string resultat;
+
+ tag = "(" + i_line.substr(0,9) + ")";
+ line = i_line.substr(14,i_line.size()-10);
+ int pos1 = line.find_first_of("[");
+ int pos2 = line.find_first_of("]");
+ signification = line.substr(pos1+1, pos2-pos1-1);
+ line = line.substr(pos2+1);
+ pos1 = line.find_first_of("[");
+ pos2 = line.find_first_of("]");
+ value = line.substr(pos1+1, pos2-pos1-1);
+ resultat = tag + " " + signification + ": " +value;
+ return resultat;
+ }
+ else
+ {
+ return i_line;
+ }
+ }
+
///////////////////////////////////////////////////
/// wxEvent to save Dicom Tags in a text file //
///////////////////////////////////////////////////
private :
+ const std::string clean(const std::string &i_line);
/// Display in a control Text all dicom tags
void Print();
*/
//=====================================================================
//=====================================================================
- class CREAIMAGEIO_EXPORT WxGimmickPanel : public wxPanel
+ class CREAIMAGEIO_EXPORT WxGimmickPanel : public wxPanel
{
public:
WxGimmickPanel();
wxCheckBox *mcheck;
/// Associated wxvtk interactor
- crea::creawxVTKRenderWindowInteractor *mInteractor;
+ crea::creawxVTKRenderWindowInteractor *mInteractor;
/// Current extent
int mx1,mx2,my1,my2,mz1,mz2;