33 std::list<mitk::DICOMFileReader::Pointer>
44 const std::vector<us::ModuleResource> configs =
47 for (
auto iter = configs.cbegin(); iter != configs.cend(); ++iter )
57 stream.seekg(0, std::ios::end);
58 s.reserve(stream.tellg());
59 stream.seekg(0, std::ios::beg);
61 s.assign((std::istreambuf_iterator<char>(stream)),
62 std::istreambuf_iterator<char>());
80 stream.seekg(0, std::ios::end);
81 s.reserve(stream.tellg());
82 stream.seekg(0, std::ios::beg);
84 s.assign((std::istreambuf_iterator<char>(stream)),
85 std::istreambuf_iterator<char>());
96 this->AddConfigFromResource(r);
103 if (reader.IsNotNull())
105 m_Readers.push_back( reader );
115 this->AddConfigFromResource(
"configurations/3D/instancenumber.xml");
116 this->AddConfigFromResource(
"configurations/3D/instancenumber_soft.xml");
117 this->AddConfigFromResource(
"configurations/3D/slicelocation.xml");
118 this->AddConfigFromResource(
"configurations/3D/imageposition.xml");
119 this->AddConfigFromResource(
"configurations/3D/imageposition_byacquisition.xml");
127 this->AddConfigsFromResources(
"configurations/3DnT");
134 DICOMReaderConfigurator::Pointer configurator = DICOMReaderConfigurator::New();
135 DICOMFileReader::Pointer reader = configurator->CreateFromUTF8ConfigString(xmlDescription);
137 if (reader.IsNotNull())
139 m_Readers.push_back( reader );
140 m_PossibleConfigurations.push_back(xmlDescription);
144 std::stringstream ss;
145 ss <<
"Could not parse reader configuration. Ignoring it.";
146 throw std::invalid_argument( ss.str() );
154 std::ifstream file(filename.c_str());
157 file.seekg(0, std::ios::end);
158 s.reserve(file.tellg());
159 file.seekg(0, std::ios::beg);
161 s.assign((std::istreambuf_iterator<char>(file)),
162 std::istreambuf_iterator<char>());
171 m_InputFilenames = filenames;
178 return m_InputFilenames;
181 mitk::DICOMFileReader::Pointer
188 DICOMGDCMTagScanner::Pointer gdcmScanner = DICOMGDCMTagScanner::New();
189 gdcmScanner->SetInputFiles( m_InputFilenames );
192 for (
auto rIter = m_Readers.cbegin(); rIter != m_Readers.cend(); ++rIter )
194 gdcmScanner->AddTagPaths((*rIter)->GetTagsOfInterest());
200 unsigned int readerIndex(0);
201 for (
auto rIter = m_Readers.cbegin(); rIter != m_Readers.cend(); ++readerIndex, ++rIter )
203 (*rIter)->SetInputFiles( m_InputFilenames );
204 (*rIter)->SetTagCache( gdcmScanner->GetScanCache() );
207 (*rIter)->AnalyzeInputFiles();
208 workingCandidates.push_back( *rIter );
209 MITK_INFO <<
"Reader " << readerIndex <<
" (" << (*rIter)->GetConfigurationLabel() <<
") suggests " << (*rIter)->GetNumberOfOutputs() <<
" 3D blocks";
210 if ((*rIter)->GetNumberOfOutputs() == 1)
212 MITK_DEBUG <<
"Early out with reader #" << readerIndex <<
" (" << (*rIter)->GetConfigurationLabel() <<
"), less than 1 block is not possible";
216 catch (
const std::exception& e )
218 MITK_ERROR <<
"Reader " << readerIndex <<
" (" << (*rIter)->GetConfigurationLabel() <<
") threw exception during file analysis, ignoring this reader. Exception: " << e.what();
222 MITK_ERROR <<
"Reader " << readerIndex <<
" (" << (*rIter)->GetConfigurationLabel() <<
") threw unknown exception during file analysis, ignoring this reader.";
226 DICOMFileReader::Pointer bestReader;
230 unsigned int bestReaderIndex(0);
232 for (
auto rIter = workingCandidates.cbegin(); rIter != workingCandidates.cend(); ++readerIndex, ++rIter )
234 const unsigned int thisReadersNumberOfOutputs = (*rIter)->GetNumberOfOutputs();
235 if ( thisReadersNumberOfOutputs > 0
236 && thisReadersNumberOfOutputs < minimumNumberOfOutputs )
238 minimumNumberOfOutputs = (*rIter)->GetNumberOfOutputs();
240 bestReaderIndex = readerIndex;
244 MITK_DEBUG <<
"Decided for reader #" << bestReaderIndex <<
" (" << bestReader->GetConfigurationLabel() <<
")";
245 MITK_DEBUG << m_PossibleConfigurations[bestReaderIndex];
ReaderList GetAllConfiguredReaders() const
Return all the DICOMFileReaders that are currently used for selection by this class. The readers returned by this method depend on what config files have been added earlier (or which of the built-in readers have been loaded)
void AddConfigFile(const std::string &filename)
Add a configuration as expected by DICOMReaderConfigurator. Configs can only be reset by instantiatin...
const StringList & GetInputFiles() const
Input files.
std::list< DICOMFileReader::Pointer > ReaderList
void AddConfig(const std::string &xmlDescription)
Add a configuration as expected by DICOMReaderConfigurator. Configs can only be reset by instantiatin...
void SetInputFiles(StringList filenames)
Input files.
void AddConfigFromResource(const std::string &resourcename)
Module * GetModule() const
~DICOMFileReaderSelector() override
void AddConfigsFromResources(const std::string &path)
std::vector< std::string > StringList
DICOMFileReaderSelector()
void LoadBuiltIn3DnTConfigs()
Load 3D+t image creating configurations from the MITK module system (see us::Module::FindResources())...
DICOMFileReader::Pointer GetFirstReaderWithMinimumNumberOfOutputImages()
Execute the analysis and selection process. The first reader with a minimal number of outputs will be...
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
void LoadBuiltIn3DConfigs()
Load 3D image creating configurations from the MITK module system (see us::Module::FindResources()). For a default set of configurations, look into the directory Resources of the DICOMReader module.
void AddFileReaderCanditate(DICOMFileReader::Pointer reader)
Add a whole pre-configured reader to the selection process.