30 #include <mitkRawImageFileReader.h>
39 #include <itkGDCMImageIO.h>
40 #include <itkNiftiImageIO.h>
87 std::string additionalPath = programPath;
89 for (
int i = 0; i < 3; ++i)
91 std::size_t index = additionalPath.find_last_of(
'/');
92 if (index != std::string::npos)
94 additionalPath = additionalPath.substr(0, index);
113 virtual void Close()
override
119 virtual void Open()
override
140 for (std::vector<us::Module *>::const_iterator iter = modules.begin(), endIter = modules.end(); iter != endIter;
143 this->AddModuleShaderToRepository(*iter, shaderRepo);
146 m_ShaderRepositories.push_back(shaderRepo);
151 void RemovedService(
const ServiceReferenceType & , TrackedType tracked)
override
153 m_ShaderRepositories.erase(std::remove(m_ShaderRepositories.begin(), m_ShaderRepositories.end(), tracked),
154 m_ShaderRepositories.end());
161 std::vector<mitk::IShaderRepository *> shaderRepos;
163 shaderMapIter = m_ModuleIdToShaderIds.begin(),
164 shaderMapEndIter = m_ModuleIdToShaderIds.end();
165 shaderMapIter != shaderMapEndIter;
168 if (shaderMapIter->second.find(moduleEvent.
GetModule()->
GetModuleId()) == shaderMapIter->second.end())
170 shaderRepos.push_back(shaderMapIter->first);
173 AddModuleShadersToRepositories(moduleEvent.
GetModule(), shaderRepos);
177 RemoveModuleShadersFromRepositories(moduleEvent.
GetModule(), m_ShaderRepositories);
181 void AddModuleShadersToRepositories(
us::Module *module,
const std::vector<mitk::IShaderRepository *> &shaderRepos)
184 std::vector<us::ModuleResource> shaderResources = module->
FindResources(
"Shaders",
"*.xml",
true);
185 for (std::vector<us::ModuleResource>::iterator i = shaderResources.begin(); i != shaderResources.end(); ++i)
190 for (
const auto &shaderRepo : shaderRepos)
192 int id = (shaderRepo)->LoadShader(rs, i->GetBaseName());
195 m_ModuleIdToShaderIds[shaderRepo][module->
GetModuleId()].push_back(
id);
198 rs.seekg(0, std::ios_base::beg);
205 std::vector<mitk::IShaderRepository *> shaderRepos;
206 shaderRepos.push_back(shaderRepo);
207 this->AddModuleShadersToRepositories(module, shaderRepos);
210 void RemoveModuleShadersFromRepositories(
us::Module *module,
211 const std::vector<mitk::IShaderRepository *> &shaderRepos)
213 for (
const auto &shaderRepo : shaderRepos)
215 std::map<long, std::vector<int>> &moduleIdToShaderIds = m_ModuleIdToShaderIds[shaderRepo];
216 std::map<long, std::vector<int>>::iterator shaderIdsIter = moduleIdToShaderIds.find(module->
GetModuleId());
217 if (shaderIdsIter != moduleIdToShaderIds.end())
219 for (std::vector<int>::iterator idIter = shaderIdsIter->second.begin(); idIter != shaderIdsIter->second.end();
222 (shaderRepo)->UnloadShader(*idIter);
224 moduleIdToShaderIds.erase(shaderIdsIter);
232 std::map<mitk::IShaderRepository *, std::map<long, std::vector<int>>> m_ModuleIdToShaderIds;
233 std::vector<mitk::IShaderRepository *> m_ShaderRepositories;
236 class FixedNiftiImageIO :
public itk::NiftiImageIO
240 typedef FixedNiftiImageIO Self;
248 itkTypeMacro(FixedNiftiImageIO, Superclass)
250 virtual
bool SupportsDimension(
unsigned long dim)
override
252 return dim > 1 && dim < 5;
261 this->m_Context = context;
266 if (programPath.empty())
268 MITK_WARN <<
"Could not get the program path.";
275 m_ShaderRepositoryTracker.reset(
new ShaderRepositoryTracker);
298 m_MimeTypeProvider->Start();
301 this->RegisterDefaultMimeTypes();
302 this->RegisterItkReaderWriter();
303 this->RegisterVtkReaderWriter();
313 m_ShaderRepositoryTracker->Open();
324 this->RegisterLegacyWriter();
329 for (
auto &elem : m_FileReaders)
334 for (
auto &elem : m_FileWriters)
339 for (
auto &elem : m_FileIOs)
344 for (
auto &elem : m_LegacyWriters)
359 m_MimeTypeProvider->Stop();
361 for (std::vector<mitk::CustomMimeType *>::const_iterator mimeTypeIter = m_DefaultMimeTypes.begin(),
362 iterEnd = m_DefaultMimeTypes.end();
363 mimeTypeIter != iterEnd;
366 delete *mimeTypeIter;
369 m_ShaderRepositoryTracker->Close();
372 void MitkCoreActivator::RegisterDefaultMimeTypes()
377 for (std::vector<mitk::CustomMimeType *>::const_iterator mimeTypeIter = mimeTypes.begin(), iterEnd = mimeTypes.end();
378 mimeTypeIter != iterEnd;
381 m_DefaultMimeTypes.push_back(*mimeTypeIter);
382 m_Context->RegisterService(m_DefaultMimeTypes.back());
386 void MitkCoreActivator::RegisterItkReaderWriter()
388 std::list<itk::LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance(
"itkImageIOBase");
390 for (
auto &allobject : allobjects)
392 itk::ImageIOBase *io =
dynamic_cast<itk::ImageIOBase *
>(allobject.GetPointer());
396 if (dynamic_cast<itk::NiftiImageIO *>(io))
400 if (dynamic_cast<itk::GDCMImageIO *>(allobject.GetPointer()))
412 MITK_WARN <<
"Error ImageIO factory did not return an ImageIOBase: " << (allobject)->GetNameOfClass();
418 m_FileIOs.push_back(niftiIO);
421 void MitkCoreActivator::RegisterVtkReaderWriter()
431 void MitkCoreActivator::RegisterLegacyWriter()
433 std::list<itk::LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance(
"IOWriter");
435 for (std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i)
440 std::string description = std::string(
"Legacy ") + io->GetNameOfClass() +
" Writer";
442 m_LegacyWriters.push_back(writer);
446 MITK_ERROR <<
"Error IOWriter override is not of type mitk::FileWriter: " << (*i)->GetNameOfClass() << std::endl;
Interface of property aliases service.
itk::SmartPointer< Self > Pointer
static std::vector< CustomMimeType * > Get()
void RemoveModuleListener(const ModuleListener &delegate)
void Load(us::ModuleContext *context) override
static void AddAutoLoadPath(const std::string &path)
void RemovedService(const ServiceReferenceType &reference, T service)
Interface of property extensions service.
itkEventMacroDeclaration(FocusChangedEvent, itk::AnyEvent) class MITKCORE_EXPORT TestingRenderingManager typedef RenderingManager Superclass
#define US_INITIALIZE_MODULE
Creates initialization code for a module.
void Unload(us::ModuleContext *) override
T AddingService(const ServiceReferenceType &reference)
Interface of property descriptions service.
Module * GetModule() const
Management class for vtkShader XML descriptions.
The IMimeTypeProvider service interface allows to query all registered mime types.
Interface class of writers that write data to files.
static CustomMimeType NIFTI_MIMETYPE()
static std::vector< Module * > GetLoadedModules()
static std::string GetProgramPath()
Interface of property persistence service.
MsgHandler installMsgHandler(MsgHandler h)
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
void AddModuleListener(const ModuleListener &delegate)
void HandleMicroServicesMessages(us::MsgType type, const char *msg)
std::vector< ModuleResource > FindResources(const std::string &path, const std::string &filePattern, bool recurse) const
Interface of property filters service.
void AddMitkAutoLoadPaths(const std::string &programPath)
The common interface of all MITK file writers.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
US_EXPORT_MODULE_ACTIVATOR(mitk::SimulationActivator)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.