22 const std::string LayoutAnnotationRenderer::ANNOTATIONRENDERER_ID =
"LayoutAnnotationRenderer";
29 void LayoutAnnotationRenderer::SetMargin2D(Annotation *Annotation,
const Point2D &OffsetVector)
35 Point2D LayoutAnnotationRenderer::GetMargin2D(Annotation *Annotation)
43 LayoutAnnotationRenderer::LayoutAnnotationRenderer(
const std::string &rendererId)
48 void LayoutAnnotationRenderer::AddAlignmentProperty(Annotation *Annotation,
49 Alignment activeAlignment,
54 alignmentProperty->AddEnum(
"TopLeft", TopLeft);
55 alignmentProperty->AddEnum(
"Top", Top);
56 alignmentProperty->AddEnum(
"TopRight", TopRight);
57 alignmentProperty->AddEnum(
"BottomLeft ", BottomLeft);
58 alignmentProperty->AddEnum(
"Bottom", Bottom);
59 alignmentProperty->AddEnum(
"BottomRight", BottomRight);
60 alignmentProperty->AddEnum(
"Left", Left);
61 alignmentProperty->AddEnum(
"Right", Right);
62 alignmentProperty->SetValue(activeAlignment);
63 Annotation->AddProperty(PROP_LAYOUT_ALIGNMENT, alignmentProperty.GetPointer());
64 Annotation->SetIntProperty(PROP_LAYOUT_PRIORITY, priority);
65 SetMargin2D(Annotation, margin);
68 void LayoutAnnotationRenderer::OnAnnotationRenderersChanged()
70 if (!this->GetCurrentBaseRenderer())
72 m_AnnotationContainerMap.clear();
73 for (Annotation *annotation : this->GetServices())
77 BaseProperty *prop = annotation->GetProperty(PROP_LAYOUT_ALIGNMENT);
78 auto *enumProb =
dynamic_cast<EnumerationProperty *
>(prop);
79 Alignment currentAlignment = TopLeft;
83 annotation->GetIntProperty(PROP_LAYOUT_PRIORITY, priority);
86 AddAlignmentProperty(annotation, currentAlignment, margin, priority);
90 currentAlignment =
static_cast<Alignment
>(enumProb->GetValueAsId());
92 AnnotationRankedMap &AnnotationVec = m_AnnotationContainerMap[currentAlignment];
93 if (!AnnotationVec.empty() && priority < 0)
95 int max = AnnotationVec.rbegin()->first;
101 AnnotationVec.insert(std::pair<int, Annotation *>(priority, annotation));
103 this->PrepareLayout();
113 if (registeredService)
125 const std::string &rendererID,
131 GetAnnotationRenderer(rendererID);
139 AddAlignmentProperty(Annotation, alignment, margin, priority);
143 Annotation *Annotation,
BaseRenderer *renderer,
Alignment alignment,
double marginX,
double marginY,
int priority)
145 AddAnnotation(Annotation, renderer->
GetName(), alignment, marginX, marginY, priority);
150 if (!this->GetCurrentBaseRenderer())
152 int *size = this->GetCurrentBaseRenderer()->GetVtkRenderer()->GetSize();
153 PrepareTopLeftLayout(size);
154 PrepareTopLayout(size);
155 PrepareTopRightLayout(size);
156 PrepareBottomLeftLayout(size);
157 PrepareBottomLayout(size);
158 PrepareBottomRightLayout(size);
159 PrepareLeftLayout(size);
160 PrepareRightLayout(size);
162 void LayoutAnnotationRenderer::PrepareTopLeftLayout(
int *displaySize)
167 posY = displaySize[1];
170 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
172 Annotation *Annotation = it->second;
173 margin = GetMargin2D(Annotation);
176 posY -= bounds.
Size[1] + margin[1];
177 bounds.
Position[0] = posX + margin[0];
182 void LayoutAnnotationRenderer::PrepareTopLayout(
int *displaySize)
187 posY = displaySize[1];
190 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
192 Annotation *Annotation = it->second;
193 margin = GetMargin2D(Annotation);
196 posX = displaySize[0] / 2 - bounds.
Size[0] / 2;
197 posY -= bounds.
Size[1] + margin[1];
203 void LayoutAnnotationRenderer::PrepareTopRightLayout(
int *displaySize)
208 posY = displaySize[1];
211 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
213 Annotation *Annotation = it->second;
214 margin = GetMargin2D(Annotation);
217 posX = displaySize[0] - (bounds.
Size[0] + margin[0]);
218 posY -= bounds.
Size[1] + margin[1];
225 void LayoutAnnotationRenderer::PrepareRightLayout(
int *displaySize)
229 double height = GetHeight(m_AnnotationContainerMap[Right], GetCurrentBaseRenderer());
230 posY = (height / 2.0 + displaySize[1]) / 2.0;
233 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
235 Annotation *Annotation = it->second;
236 margin = GetMargin2D(Annotation);
239 posY -= bounds.
Size[1] + margin[1];
240 bounds.
Position[0] = displaySize[0] - (bounds.
Size[0] + margin[0]);
241 bounds.
Position[1] = posY + margin[1];
246 void LayoutAnnotationRenderer::PrepareLeftLayout(
int *displaySize)
250 double height = GetHeight(m_AnnotationContainerMap[Left], GetCurrentBaseRenderer());
251 posY = (height / 2.0 + displaySize[1]) / 2.0;
254 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
256 Annotation *Annotation = it->second;
257 margin = GetMargin2D(Annotation);
260 posY -= bounds.
Size[1] + margin[1];
267 void LayoutAnnotationRenderer::PrepareBottomLeftLayout(
int * )
275 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
277 Annotation *Annotation = it->second;
278 margin = GetMargin2D(Annotation);
281 bounds.
Position[0] = posX + margin[0];
282 bounds.
Position[1] = posY + margin[1];
284 posY += bounds.
Size[1] + margin[1];
287 void LayoutAnnotationRenderer::PrepareBottomLayout(
int *displaySize)
295 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
297 Annotation *Annotation = it->second;
298 margin = GetMargin2D(Annotation);
301 posX = displaySize[0] / 2 - bounds.
Size[0] / 2;
303 bounds.
Position[1] = posY + margin[1];
305 posY += bounds.
Size[1] + margin[1];
308 void LayoutAnnotationRenderer::PrepareBottomRightLayout(
int *displaySize)
316 for (
auto it = AnnotationMap.cbegin(); it != AnnotationMap.cend(); ++it)
318 Annotation *Annotation = it->second;
319 margin = GetMargin2D(Annotation);
322 posX = displaySize[0] - (bounds.
Size[0] + margin[0]);
324 bounds.
Position[1] = posY + margin[1];
326 posY += bounds.
Size[1] + margin[1];
333 for (
auto it = annotations.cbegin(); it != annotations.cend(); ++it)
335 Annotation *annotation = it->second;
337 height += bounds.
Size[0];
338 height += GetMargin2D(annotation)[0];
Point< ScalarType, 2 > Point2D
static const std::string PROP_LAYOUT
The LayoutAnnotationRenderer is used for the layouted placement of mitk::Annotation Objects...
Container for position and size on the display.
virtual void RegisterAsMicroservice(us::ServiceProperties props)
Registers this object as a Microservice, making it available to every module and/or plugin...
static const std::string PROP_LAYOUT_MARGIN
itk::Point< double, 2 > Size
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
static void RegisterAnnotationRenderer(AbstractAnnotationRenderer *annotationRenderer)
RegisterAnnotationRenderer registers an AnnotationRenderer as a microservice and saves a reference to...
static void AddAnnotation(Annotation *annotation, const std::string &rendererID, Alignment alignment=TopLeft, double marginX=5, double marginY=5, int priority=-1)
void OnRenderWindowModified() override
static AbstractAnnotationRenderer * GetAnnotationRenderer(const std::string &arTypeID, const std::string &rendererID)
GetAnnotationRenderer returns a registered AnnotationRenderer of a specific type and for a BaseRender...
virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const
Returns position and size of the Annotation on the display.
AbstractAnnotationRenderer(const std::string &rendererID, const std::string &arID)
itk::Point< double, 2 > Position
itk::SmartPointer< Self > Pointer
~LayoutAnnotationRenderer() override
virtual destructor in order to derive from this class
Baseclass of Annotation layouters An AbstractAnnotationRenderer can be implemented to control a set o...
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
std::multimap< int, mitk::Annotation * > AnnotationRankedMap
const std::string GetID() const
static const std::string PROP_LAYOUT_ALIGNMENT
static const std::string US_PROPKEY_RENDERER_ID
static const std::string PROP_LAYOUT_PRIORITY
static const std::string US_PROPKEY_AR_ID
static LayoutAnnotationRenderer * GetAnnotationRenderer(const std::string &rendererID)
virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &)
Sets position and size of the Annotation on the display.
const char * GetName() const
get the name of the Renderer