18 #include "mapRegistration.h" 19 #include "mapRegistrationFileWriter.h" 20 #include "mapRegistrationFileReader.h" 21 #include "mapLazyFileFieldKernelLoader.h" 37 : m_OldLocale(
std::setlocale(LC_ALL, nullptr))
38 , m_NewLocale(newLocale)
40 if (m_OldLocale ==
nullptr)
44 else if (m_NewLocale != m_OldLocale)
47 if (std::setlocale(LC_ALL, m_NewLocale.c_str()) ==
nullptr)
49 MITK_INFO <<
"Could not set locale " << m_NewLocale;
50 m_OldLocale =
nullptr;
57 if (m_OldLocale !=
nullptr && std::setlocale(LC_ALL, m_OldLocale) ==
nullptr)
59 MITK_INFO <<
"Could not reset locale " << m_OldLocale;
64 const char* m_OldLocale;
65 const std::string m_NewLocale;
73 template<
unsigned int i,
unsigned int j,
template <
unsigned int,
unsigned int>
class TFunctor>
79 if (TFunctor<i,j>::Execute(obj, data))
83 return DimHelperSub<i,j-1,TFunctor>::Execute(obj, data);
90 template<
unsigned int i,
template <
unsigned int,
unsigned int>
class TFunctor>
91 class DimHelperSub<i,1,TFunctor >
109 template<
unsigned int i,
unsigned int j,
template <
unsigned int,
unsigned int>
class TFunctor>
114 if (DimHelperSub<i,j,TFunctor>::Execute(obj, data))
118 return DimHelper<i-1,j,TFunctor>::Execute(obj, data);
125 template<
unsigned int j,
template <
unsigned int,
unsigned int>
class TFunctor>
126 class DimHelper<1,j, TFunctor >
139 template<
unsigned int i,
unsigned int j>
147 result =
dynamic_cast<const map::core::Registration<i,j> *
>(obj->
GetRegistration()) !=
nullptr;
155 template<
unsigned int i,
unsigned int j>
161 const map::core::Registration<i,j>* pReg =
dynamic_cast<const map::core::Registration<i,j>*
>(obj->
GetRegistration());
167 typedef map::io::RegistrationFileWriter<i,j> WriterType;
168 typename WriterType::Pointer writer = WriterType::New();
170 writer->setExpandLazyKernels(
false);
174 writer->write(pReg,data);
176 catch (
const itk::ExceptionObject& e)
178 std::cout << e.what() << std::endl;
193 std::string category =
"MatchPoint Registration File";
212 bool success =
false;
214 if (input ==
nullptr)
216 mitkThrow() <<
"Cannot write data. Data pointer is nullptr.";
220 if (wrapper ==
nullptr)
222 mitkThrow() <<
"Cannot write data. Data pointer is not a Registration wrapper.";
237 success = DimHelper<3,3,WriteReg>::Execute(wrapper, fileName);
239 catch (
const std::exception& e)
246 mitkThrow() <<
"Cannot write registration. Currently only registrations up to 4D are supported.";
254 if (regWrapper ==
nullptr)
260 if (! DimHelper<3,3,CanWrite>::Execute(regWrapper))
270 std::vector<BaseData::Pointer > result;
275 if ( fileName.empty() )
277 mitkThrow() <<
"Cannot read file. Filename has not been set!";
282 map::io::RegistrationFileReader::LoaderStackType::unregisterProvider(map::io::LazyFileFieldKernelLoader<2,2>::getStaticProviderName());
283 map::io::RegistrationFileReader::LoaderStackType::unregisterProvider(map::io::LazyFileFieldKernelLoader<3,3>::getStaticProviderName());
285 map::io::RegistrationFileReader::Pointer spReader = map::io::RegistrationFileReader::New();
286 spReader->setPreferLazyLoading(
true);
287 map::core::RegistrationBase::Pointer spReg = spReader->read(fileName);
289 spRegWrapper->SetRegistration(spReg);
291 result.push_back(spRegWrapper.GetPointer());
300 std::ifstream
in( fileName.c_str() );
Base of all data objects.
std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
MAPRegistrationWrapperIO()
DataCollection - Class to facilitate loading/accessing structured data.
ConfidenceLevel GetWriterConfidenceLevel() const override
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
std::string GetLocalFileName() const
Get a local file name for reading.
::map::core::RegistrationBase * GetRegistration()
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Convenience class to temporarily change the current locale.
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
void SetDescription(const std::string &description)
const BaseData * GetInput() const override
Get the input data set via SetInput().
void AddExtension(const std::string &extension)
ConfidenceLevel GetReaderConfidenceLevel() const override
LocaleSwitch(const std::string &newLocale)
void SetCategory(const std::string &category)
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
std::ostream * GetOutputStream() const override
Get the output stream.
void SetMimeType(const CustomMimeType &mimeType)
std::string GetOutputLocation() const override
Get the current output location.
Abstract class for implementing a reader and writer.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.
void Write() override
Write the base data to the specified location or output stream.