Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef _MSC_VER
00019 #pragma warning ( disable : 4786 )
00020 #endif
00021
00022 #include "mitkBaseDataIOFactory.h"
00023 #include "mitkBaseProcess.h"
00024 #include "mitkIOAdapter.h"
00025 #include "mitkConfig.h"
00026
00027 namespace mitk
00028 {
00029
00030 std::vector<BaseData::Pointer> BaseDataIO::LoadBaseDataFromFile(const std::string path, const std::string filePrefix, const std::string filePattern, bool series)
00031 {
00032
00033
00034
00035 std::vector<BaseData::Pointer> result;
00036
00037 std::list<IOAdapterBase::Pointer> possibleIOAdapter;
00038 std::list<LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance("mitkIOAdapter");
00039
00040 for( std::list<LightObject::Pointer>::iterator i = allobjects.begin();
00041 i != allobjects.end();
00042 ++i)
00043 {
00044 IOAdapterBase* io = dynamic_cast<IOAdapterBase*>(i->GetPointer());
00045 if(io)
00046 {
00047 possibleIOAdapter.push_back(io);
00048 }
00049 else
00050 {
00051 MITK_ERROR << "Error BaseDataIO factory did not return an IOAdapterBase: "
00052 << (*i)->GetNameOfClass()
00053 << std::endl;
00054 }
00055 }
00056
00057 for( std::list<IOAdapterBase::Pointer>::iterator k = possibleIOAdapter.begin();
00058 k != possibleIOAdapter.end();
00059 ++k )
00060 {
00061 bool canReadFile = false;
00062
00063 if ( series )
00064 canReadFile = (*k)->CanReadFile(filePrefix, filePrefix, filePattern);
00065 else
00066 canReadFile = (*k)->CanReadFile(path, filePrefix, filePattern);
00067
00068 if( canReadFile )
00069 {
00070 BaseProcess::Pointer ioObject = (*k)->CreateIOProcessObject(path, filePrefix, filePattern);
00071 ioObject->Update();
00072 int numberOfContents = static_cast<int>(ioObject->GetNumberOfOutputs());
00073
00074 if (numberOfContents > 0)
00075 {
00076 BaseData::Pointer baseData;
00077 for(int i=0; i<numberOfContents; ++i)
00078 {
00079 baseData = dynamic_cast<BaseData*>(ioObject->GetOutputs()[i].GetPointer());
00080 if (baseData)
00081 {
00082 result.push_back( baseData );
00083 }
00084 }
00085 }
00086
00087 break;
00088 }
00089 }
00090
00091 return result;
00092 }
00093
00094 }