Factory, which creates instances of mitk::DataNodes filled with data read from a given file. More...
#include <mitkDataNodeFactory.h>
Public Member Functions | |
mitkClassMacro (DataNodeFactory, DataNodeSource) | |
virtual void | SetFileName (const char *_arg) |
virtual const char * | GetFileName () const |
virtual void | SetFilePrefix (const char *_arg) |
Set prefix for multiple load. | |
virtual const char * | GetFilePrefix () const |
Get prefix for multiple load. | |
virtual void | SetFilePattern (const char *_arg) |
Set pattern for multiple load. | |
virtual const char * | GetFilePattern () const |
Get pattern for multiple load. | |
void | SetDefaultCommonProperties (mitk::DataNode::Pointer &node) |
void | SetImageSerie (bool serie) |
virtual bool | GetUseSeriesDetails () |
virtual void | SetUseSeriesDetails (bool _arg) |
void | AddSeriesRestriction (const std::string &tag) |
Static Public Member Functions | |
static Pointer | New () |
static ColorProperty::Pointer | DefaultColorForOrgan (const std::string &) |
Static Public Attributes | |
static bool | m_TextureInterpolationActive = false |
Protected Member Functions | |
DataNodeFactory () | |
virtual | ~DataNodeFactory () |
virtual void | GenerateData () |
virtual void | ResizeOutputs (const unsigned int &num) |
virtual bool | FileNameEndsWith (const std::string &name) |
virtual bool | FilePatternEndsWith (const std::string &name) |
virtual std::string | GetBaseFileName () |
virtual std::string | GetBaseFilePrefix () |
virtual std::string | GetDirectory () |
virtual void | ReadFileSeriesTypeDCM () |
virtual void | ReadFileSeriesTypeITKImageSeriesReader () |
Protected Attributes | |
bool | m_Serie |
bool | m_UseSeriesDetails |
std::vector< std::string > | m_SeriesRestrictions |
int | m_OldProgress |
Factory, which creates instances of mitk::DataNodes filled with data read from a given file.
This class reads files, creates an appropriate mitk::BaseData and adds the BaseData to a mitk::DataNode. This filter may produce one or more outputs (i.e. mitk::DataNodes). The number of generated nodes can be retrieved by a call of GetNumberOfOutputs().
If you want to add a new file type, you have to register the factory of the file reader in the class mitk::BaseDataIOFactory.
Definition at line 37 of file mitkDataNodeFactory.h.
mitk::DataNodeFactory::DataNodeFactory | ( | ) | [protected] |
Constructor.
Definition at line 92 of file mitkDataNodeFactory.cpp.
References mitk::CoreObjectFactory::GetInstance(), m_OldProgress, and m_Serie.
: m_UseSeriesDetails(true) { m_Serie = false; m_OldProgress = 0; this->Modified(); //ensure that a CoreObjectFactory has been instantiated mitk::CoreObjectFactory::GetInstance(); }
mitk::DataNodeFactory::~DataNodeFactory | ( | ) | [protected, virtual] |
void mitk::DataNodeFactory::AddSeriesRestriction | ( | const std::string & | tag ) | [inline] |
Definition at line 77 of file mitkDataNodeFactory.h.
mitk::ColorProperty::Pointer mitk::DataNodeFactory::DefaultColorForOrgan | ( | const std::string & | organ ) | [static] |
Nice default colors for segmentations of some "normal" organs.
Definition at line 318 of file mitkDataNodeFactory.cpp.
References mitk::ColorProperty::New().
{ static bool initialized = false; static std::map< std::string, std::string > s_ColorMap; if (!initialized) { // all lowercase here, please! s_ColorMap.insert( std::make_pair( "ankle", "0xe38686") ); s_ColorMap.insert( std::make_pair( "appendix", "0xe38686") ); s_ColorMap.insert( std::make_pair( "blood vessels", "0xff3131") ); s_ColorMap.insert( std::make_pair( "bronchial tree", "0x3168ff") ); s_ColorMap.insert( std::make_pair( "bone", "0xd5d5d5") ); s_ColorMap.insert( std::make_pair( "brain", "0xff9cca") ); s_ColorMap.insert( std::make_pair( "coccyx", "0xe38686") ); s_ColorMap.insert( std::make_pair( "colon", "0xe38686") ); s_ColorMap.insert( std::make_pair( "cyst", "0xe38686") ); s_ColorMap.insert( std::make_pair( "elbow", "0xe38686") ); s_ColorMap.insert( std::make_pair( "eye", "0xe38686") ); s_ColorMap.insert( std::make_pair( "fallopian tube", "0xe38686") ); s_ColorMap.insert( std::make_pair( "fat", "0xff2bee") ); s_ColorMap.insert( std::make_pair( "hand", "0xe38686") ); s_ColorMap.insert( std::make_pair( "gall bladder", "0x567f18") ); s_ColorMap.insert( std::make_pair( "heart", "0xeb1d32") ); s_ColorMap.insert( std::make_pair( "hip", "0xe38686") ); s_ColorMap.insert( std::make_pair( "kidney", "0xd33f00") ); s_ColorMap.insert( std::make_pair( "knee", "0xe38686") ); s_ColorMap.insert( std::make_pair( "larynx", "0xe38686") ); s_ColorMap.insert( std::make_pair( "liver", "0xffcc3d") ); s_ColorMap.insert( std::make_pair( "lung", "0x6bdcff") ); s_ColorMap.insert( std::make_pair( "lymph node", "0xff0000") ); s_ColorMap.insert( std::make_pair( "muscle", "0xff456a") ); s_ColorMap.insert( std::make_pair( "nerve", "0xffea4f") ); s_ColorMap.insert( std::make_pair( "nose", "0xe38686") ); s_ColorMap.insert( std::make_pair( "oesophagus", "0xe38686") ); s_ColorMap.insert( std::make_pair( "ovaries", "0xe38686") ); s_ColorMap.insert( std::make_pair( "pancreas", "0xf9ab3d") ); s_ColorMap.insert( std::make_pair( "pelvis", "0xe38686") ); s_ColorMap.insert( std::make_pair( "penis", "0xe38686") ); s_ColorMap.insert( std::make_pair( "pharynx", "0xe38686") ); s_ColorMap.insert( std::make_pair( "prostate", "0xe38686") ); s_ColorMap.insert( std::make_pair( "rectum", "0xe38686") ); s_ColorMap.insert( std::make_pair( "sacrum", "0xe38686") ); s_ColorMap.insert( std::make_pair( "seminal vesicle", "0xe38686") ); s_ColorMap.insert( std::make_pair( "shoulder", "0xe38686") ); s_ColorMap.insert( std::make_pair( "spinal cord", "0xf5f93d") ); s_ColorMap.insert( std::make_pair( "spleen", "0xf96c3d") ); s_ColorMap.insert( std::make_pair( "stomach", "0xf96c3d") ); s_ColorMap.insert( std::make_pair( "teeth", "0xfffcd8") ); s_ColorMap.insert( std::make_pair( "testicles", "0xe38686") ); s_ColorMap.insert( std::make_pair( "thyroid", "0xfff694") ); s_ColorMap.insert( std::make_pair( "tongue", "0xe38686") ); s_ColorMap.insert( std::make_pair( "tumor", "0x937011") ); s_ColorMap.insert( std::make_pair( "urethra", "0xf8ff32") ); s_ColorMap.insert( std::make_pair( "urinary bladder", "0xf8ff32") ); s_ColorMap.insert( std::make_pair( "uterus", "0xe38686") ); s_ColorMap.insert( std::make_pair( "vagina", "0xe38686") ); s_ColorMap.insert( std::make_pair( "vertebra", "0xe38686") ); s_ColorMap.insert( std::make_pair( "wrist", "0xe38686") ); initialized = true; } std::string lowercaseOrgan(organ); for(unsigned int i = 0; i < organ.length(); i++) { lowercaseOrgan[i] = tolower(lowercaseOrgan[i]); } std::map< std::string, std::string >::iterator iter = s_ColorMap.find( lowercaseOrgan ); if ( iter != s_ColorMap.end() ) { std::string hexColor = iter->second; std::string hexRed = std::string("0x") + hexColor.substr( 2, 2 ); std::string hexGreen = std::string("0x") + hexColor.substr( 4, 2 ); std::string hexBlue = std::string("0x") + hexColor.substr( 6, 2 ); long int red = strtol( hexRed.c_str(), NULL, 16 ); long int green = strtol( hexGreen.c_str(), NULL, 16 ); long int blue = strtol( hexBlue.c_str(), NULL, 16 ); return ColorProperty::New( (float)red/ 255.0, (float)green/ 255.0, (float)blue/ 255.0 ); } else { // a default color (green) return ColorProperty::New( 0.0, 1.0, 0.0 ); } }
bool mitk::DataNodeFactory::FileNameEndsWith | ( | const std::string & | name ) | [protected, virtual] |
Checks if the file name m_FileName ends with the given name. Currently, this check is done by a dumb search for name in the filename.
name | the extension of the file |
Definition at line 191 of file mitkDataNodeFactory.cpp.
{ if (m_FileName.size() < name.size()) return false; return m_FileName.substr(m_FileName.size() - name.size()) == name; }
bool mitk::DataNodeFactory::FilePatternEndsWith | ( | const std::string & | name ) | [protected, virtual] |
Checks if the file pattern m_FilePattern ends with the given name. Currently, this check is done by a dumb search for name in the filename.
name | the extension of the file |
Definition at line 198 of file mitkDataNodeFactory.cpp.
{ return m_FilePattern.find( name ) != std::string::npos; }
void mitk::DataNodeFactory::GenerateData | ( | ) | [protected, virtual] |
Determines of which file type a given file is and calls the appropriate reader function.
Definition at line 110 of file mitkDataNodeFactory.cpp.
References int(), mitk::DicomSeriesReader::IsDicom(), mitk::BaseDataIO::LoadBaseDataFromFile(), MITK_ERROR, and mitk::DataNode::New().
{ // IF filename is something.pic, and something.pic does not exist, try to read something.pic.gz // if there are both, something.pic and something.pic.gz, only the requested file is read // not only for images, but for all formats std::ifstream exists(m_FileName.c_str()); if (!exists) { std::string testfilename = m_FileName + ".gz"; std::ifstream exists(testfilename.c_str()); if (exists.good()) { m_FileName += ".gz"; } else { testfilename = m_FileName + ".GZ"; std::ifstream exists(testfilename.c_str()); if (exists.good()) { m_FileName += ".GZ"; } else { std::string message("File does not exist, or cannot be read. Filename = "); message += m_FileName; MITK_ERROR << message; itkExceptionMacro( << message ); } } } // part for DICOM // const char *numbers = "0123456789."; // std::string::size_type first_non_number; // first_non_number = itksys::SystemTools::GetFilenameName(m_FileName).find_first_not_of ( numbers ); if (DicomSeriesReader::IsDicom(this->m_FileName) /*|| first_non_number == std::string::npos*/) { this->ReadFileSeriesTypeDCM(); } else { bool usedNewDTNF = false; // the mitkBaseDataIO class returns a pointer of a vector of BaseData objects std::vector<mitk::BaseData::Pointer> baseDataVector = mitk::BaseDataIO::LoadBaseDataFromFile( m_FileName, m_FilePrefix, m_FilePattern, m_Serie ); if( !baseDataVector.empty() ) this->ResizeOutputs((unsigned int)baseDataVector.size()); for(int i=0; i<(int)baseDataVector.size(); i++) { mitk::BaseData::Pointer baseData = baseDataVector.at(i); if( baseData.IsNotNull() ) { usedNewDTNF = true; mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(baseData); this->SetDefaultCommonProperties( node ); this->SetOutput(i, node); } } if(!usedNewDTNF && !( m_FileName != "" ) && !(m_Serie == false)) ReadFileSeriesTypeITKImageSeriesReader(); } }
std::string mitk::DataNodeFactory::GetBaseFileName | ( | ) | [protected, virtual] |
Definition at line 203 of file mitkDataNodeFactory.cpp.
{ return itksys::SystemTools::GetFilenameName( m_FileName ); }
std::string mitk::DataNodeFactory::GetBaseFilePrefix | ( | ) | [protected, virtual] |
Definition at line 208 of file mitkDataNodeFactory.cpp.
{ return itksys::SystemTools::GetFilenameName( m_FilePrefix ); }
std::string mitk::DataNodeFactory::GetDirectory | ( | ) | [protected, virtual] |
Definition at line 213 of file mitkDataNodeFactory.cpp.
{ if ( m_FileName != "" ) return itksys::SystemTools::GetFilenamePath( m_FileName ); else if ( m_FilePrefix != "" ) return itksys::SystemTools::GetFilenamePath( m_FilePrefix ); else return std::string( "" ); }
virtual const char* mitk::DataNodeFactory::GetFileName | ( | ) | const [virtual] |
Implements mitk::FileReader.
virtual const char* mitk::DataNodeFactory::GetFilePattern | ( | ) | const [virtual] |
Get pattern for multiple load.
Implements mitk::FileReader.
virtual const char* mitk::DataNodeFactory::GetFilePrefix | ( | ) | const [virtual] |
Get prefix for multiple load.
Implements mitk::FileReader.
virtual bool mitk::DataNodeFactory::GetUseSeriesDetails | ( | ) | [virtual] |
mitk::DataNodeFactory::mitkClassMacro | ( | DataNodeFactory | , |
DataNodeSource | |||
) |
static Pointer mitk::DataNodeFactory::New | ( | ) | [static] |
Reimplemented from mitk::DataNodeSource.
Referenced by QmitkDataManagerView::FileOpen(), CommonFunctionality::FileOpen(), CommonFunctionality::FileOpenImageSequence(), Step6::Load(), SceneIOTestClass::LoadBaseData(), mitkSegmentationInterpolationTestClass::LoadImage(), main(), mitkCompressedImageContainerTest(), mitkCylindricToCartesianFilterTest(), mitkDataNodeFactoryTest(), mitkDICOMLocaleTestWithReferenceImage(), mitkExtractImageFilterTest(), mitkImageSliceSelectorTest(), mitkImageTest(), mitkImageTimeSelectorTest(), mitkImageWriterTest(), mitkLabeledImageToSurfaceFilterTest(), mitkManualSegmentationToSurfaceFilterTest(), mitkOverwriteSliceImageFilterTest(), mitkPicFileWriterTest(), mitkSurfaceToImageFilterTest(), QmitkFileOpenAction::Run(), and QmitkExtFileOpenAction::Run().
void mitk::DataNodeFactory::ReadFileSeriesTypeDCM | ( | ) | [protected, virtual] |
Definition at line 223 of file mitkDataNodeFactory.cpp.
References mitk::ProgressBar::AddStepsToDo(), mitk::ProgressBar::GetInstance(), mitk::DicomSeriesReader::GetSeries(), mitk::DicomSeriesReader::LoadDicomSeries(), MITK_ERROR, MITK_INFO, and mitk::ProgressBar::Progress().
{ MITK_INFO << "loading image series with prefix " << m_FilePrefix << " and pattern " << m_FilePattern << " as DICOM..." << std::endl; const char* previousCLocale = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "C"); std::locale previousCppLocale( std::cin.getloc() ); std::locale l( "C" ); std::cin.imbue(l); DicomSeriesReader::UidFileNamesMap names_map = DicomSeriesReader::GetSeries(this->GetDirectory(), this->m_UseSeriesDetails, this->m_SeriesRestrictions); const unsigned int size = names_map.size(); this->ResizeOutputs(size); ProgressBar::GetInstance()->AddStepsToDo(size); ProgressBar::GetInstance()->Progress(); unsigned int i = 0u; const DicomSeriesReader::UidFileNamesMap::const_iterator n_end = names_map.end(); for (DicomSeriesReader::UidFileNamesMap::const_iterator n_it = names_map.begin(); n_it != n_end; ++n_it) { const std::string &uid = n_it->first; DataNode::Pointer node = this->GetOutput(i); MITK_INFO << "Reading series #" << i << ": " << uid << std::endl; if (DicomSeriesReader::LoadDicomSeries(n_it->second, *node)) { ++i; node->SetName(uid); } else { MITK_ERROR << "skipping series #" << i << " due to exception" << std::endl; } ProgressBar::GetInstance()->Progress(); } setlocale(LC_NUMERIC, previousCLocale); std::cin.imbue(previousCppLocale); }
void mitk::DataNodeFactory::ReadFileSeriesTypeITKImageSeriesReader | ( | ) | [protected, virtual] |
Definition at line 268 of file mitkDataNodeFactory.cpp.
References mitk::StringProperty::New(), and mitk::Image::New().
{ typedef itk::Image<int, 3> ImageType; typedef itk::ImageSeriesReader< ImageType > ReaderType; typedef itk::NumericSeriesFileNames NameGenerator; if ( ! this->GenerateFileList() ) { itkWarningMacro( "Sorry, file list could not be generated!" ); return ; } if ( m_MatchedFileNames.size() == 0 ) { itkWarningMacro( "Sorry, no files matched the given filename ("<< m_FileName <<")!" ); return ; } // // Finally, initialize the ITK-reader and load the files! // ReaderType::Pointer reader = ReaderType::New(); reader->SetFileNames( m_MatchedFileNames ); try { reader->Update(); ResizeOutputs( reader->GetNumberOfOutputs() ); for ( unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i ) { //Initialize mitk image from itk mitk::Image::Pointer image = mitk::Image::New(); image->InitializeByItk( reader->GetOutput( i ) ); image->SetVolume( reader->GetOutput( i )->GetBufferPointer() ); //add the mitk image to the node mitk::DataNode::Pointer node = this->GetOutput( i ); node->SetData( image ); mitk::StringProperty::Pointer nameProp = mitk::StringProperty::New( m_FileName ); node->SetProperty( "name", nameProp ); } } catch ( const std::exception & e ) { itkWarningMacro( << e.what() ); return ; } }
void mitk::DataNodeFactory::ResizeOutputs | ( | const unsigned int & | num ) | [protected, virtual] |
Resizes the number of outputs of the factory. The outputs are initialized by empty DataNodes
num | the new number of outputs |
Definition at line 181 of file mitkDataNodeFactory.cpp.
{ unsigned int prevNum = this->GetNumberOfOutputs(); this->SetNumberOfOutputs( num ); for ( unsigned int i = prevNum; i < num; ++i ) { this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() ); } }
void mitk::DataNodeFactory::SetDefaultCommonProperties | ( | mitk::DataNode::Pointer & | node ) |
Definition at line 409 of file mitkDataNodeFactory.cpp.
References mitk::StringProperty::New(), and mitk::StringProperty::PATH.
{ // path mitk::StringProperty::Pointer pathProp = mitk::StringProperty::New( itksys::SystemTools::GetFilenamePath( m_FileName ) ); node->SetProperty( StringProperty::PATH, pathProp ); // name already defined? mitk::StringProperty::Pointer nameProp = dynamic_cast<mitk::StringProperty*>(node->GetProperty("name")); if(nameProp.IsNull() || (strcmp(nameProp->GetValue(),"No Name!")==0)) { // name already defined in BaseData mitk::StringProperty::Pointer baseDataNameProp = dynamic_cast<mitk::StringProperty*>(node->GetData()->GetProperty("name").GetPointer() ); if(baseDataNameProp.IsNull() || (strcmp(baseDataNameProp->GetValue(),"No Name!")==0)) { // name neither defined in node, nor in BaseData -> name = filename if (FileNameEndsWith( ".gz" )) m_FileName = m_FileName.substr( 0, m_FileName.length()-3 ); nameProp = mitk::StringProperty::New( itksys::SystemTools::GetFilenameWithoutLastExtension( m_FileName ) ); node->SetProperty( "name", nameProp ); } else { // name defined in BaseData! nameProp = mitk::StringProperty::New( baseDataNameProp->GetValue() ); node->SetProperty( "name", nameProp ); } } // visibility if(!node->GetProperty("visible")) node->SetVisibility(true); }
virtual void mitk::DataNodeFactory::SetFileName | ( | const char * | _arg ) | [virtual] |
Sets the filename of the file to read.
FileName | the name of the file to read. |
Implements mitk::FileReader.
virtual void mitk::DataNodeFactory::SetFilePattern | ( | const char * | _arg ) | [virtual] |
Set pattern for multiple load.
Implements mitk::FileReader.
virtual void mitk::DataNodeFactory::SetFilePrefix | ( | const char * | _arg ) | [virtual] |
Set prefix for multiple load.
Implements mitk::FileReader.
void mitk::DataNodeFactory::SetImageSerie | ( | bool | serie ) |
if true -> loaded image is part of a serie
Definition at line 105 of file mitkDataNodeFactory.cpp.
{ m_Serie = serie; }
virtual void mitk::DataNodeFactory::SetUseSeriesDetails | ( | bool | _arg ) | [virtual] |
int mitk::DataNodeFactory::m_OldProgress [protected] |
Definition at line 159 of file mitkDataNodeFactory.h.
Referenced by DataNodeFactory().
bool mitk::DataNodeFactory::m_Serie [protected] |
Definition at line 94 of file mitkDataNodeFactory.h.
Referenced by DataNodeFactory().
std::vector<std::string> mitk::DataNodeFactory::m_SeriesRestrictions [protected] |
Definition at line 158 of file mitkDataNodeFactory.h.
bool mitk::DataNodeFactory::m_TextureInterpolationActive = false [static] |
Definition at line 80 of file mitkDataNodeFactory.h.
Referenced by mitk::ImageMapperGL2D::SetDefaultProperties().
bool mitk::DataNodeFactory::m_UseSeriesDetails [protected] |
Definition at line 157 of file mitkDataNodeFactory.h.