Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkModelGenerator.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkModelGenerator.h"
14 #include "mitkIModelFitProvider.h"
15 
16 #include "usModuleContext.h"
17 #include "usGetModuleContext.h"
18 
20 {
21  mitk::IModelFitProvider* result = nullptr;
22  std::string filter = "(" + mitk::IModelFitProvider::PROP_MODEL_CLASS_ID() + "=" + id + ")";
23  std::vector<us::ServiceReference<mitk::IModelFitProvider> > providerRegisters = us::GetModuleContext()->GetServiceReferences<mitk::IModelFitProvider>(filter);
24 
25  if (!providerRegisters.empty())
26  {
27  if (providerRegisters.size() > 1)
28  {
29  MITK_WARN << "Multiple provider for class id'"<<id<<"' found. Using just one.";
30  }
31  result = us::GetModuleContext()->GetService<mitk::IModelFitProvider>(providerRegisters.front());
32  }
33 
34  return result;
35 };
36 
38 = default;
39 
41 = default;
42 
43 mitk::ModelFactoryBase::Pointer mitk::ModelGenerator::GetModelFactory(const ModelClassIDType& id)
44 {
45  mitk::ModelFactoryBase::Pointer factory = nullptr;
46 
47  auto service = GetProviderService(id);
48 
49  if (service)
50  {
51  factory = service->GenerateFactory();
52  }
53 
54 
55  return factory;
56 }
57 
58 
60  const modelFit::ModelFitInfo& fit)
61 {
63 
64  mitk::ModelFactoryBase::Pointer factory = GetModelFactory(fit.functionClassID);
65 
66  if (factory.IsNotNull())
67  {
68  result = factory->CreateParameterizer(&fit);
69  }
70 
71  return result;
72 }
static std::string PROP_MODEL_CLASS_ID()
Service property name for the model ID handled by the provider.
static ModelFactoryBase::Pointer GetModelFactory(const ModelClassIDType &id)
void * GetService(const ServiceReferenceBase &reference)
static ModelParameterizerBase::Pointer GenerateModelParameterizer(const modelFit::ModelFitInfo &fit)
#define MITK_WARN
Definition: mitkLogMacros.h:19
virtual ~ModelGenerator()
Data class that stores all information about a modelfit that is relevant to the visualization and sto...
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
ModelFactoryBase::ModellClassIDType ModelClassIDType
The common interface for all model providers for model fitting.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
static IModelFitProvider * GetProviderService(const ModelClassIDType &id)