MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
CSOLabelPlacementGlobal.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2014, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13
15
16#pragma once
17
19
20#include <ThirdPartyWarningsDisable.h>
21
22#include <boost/unordered_map.hpp>
23#include <boost/geometry.hpp>
24#include <boost/geometry/geometries/point_xy.hpp>
25#include <boost/geometry/geometries/polygon.hpp>
26#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
27#include <boost/geometry/algorithms/convex_hull.hpp>
28
29#include <ThirdPartyWarningsRestore.h>
30
31
33
34typedef boost::tuple<MLint, MLint> Point2D;
35
38{
39public:
40 enum HullMode {
41 CONVEX_CSO_HULL = 0,
42 HULL_POINTS_FROM_CSO_LIST
43 };
44
46
47 void layoutVisibleCSOs(const std::vector<CSODrawCSOInfos>& drawCSOInfos, const std::map<int, SbVec2f>& labelBoxes,
48 const CSODrawView2DInfos& view2DInfos, SoCSOLabelRenderer* labelRenderer) override;
49
51 void getAttachedLabelPosition(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, int labelWidth,
52 int labelHeight, float& deviceX, float& deviceY) override;
53
54protected:
56
57private:
58 FloatField* _labelDeviceOffsetFld;
59 IntField* _additionalSlotsFld;
60 EnumField* _hullModeFld;
61 FloatField* _startAngleFld;
62 FloatField* _endAngleFld;
63 BaseField* _inHullCSOListFld;
64
65 struct LabelBoundingBox
66 {
67 SbVec2f upper;
68 float width;
69 float height;
70 bool overlaps(const LabelBoundingBox& labelBoundingBox) const
71 {
72 const MLdouble augment = 3.;
73
74 const MLdouble bb1v1x = labelBoundingBox.upper[0] - augment;
75 const MLdouble bb1v1y = labelBoundingBox.upper[1] - augment;
76 const MLdouble bb1v2x = labelBoundingBox.upper[0] + augment + labelBoundingBox.width;
77 const MLdouble bb1v2y = labelBoundingBox.upper[1] + augment + labelBoundingBox.height;
78
79 const MLdouble bb2v1x = upper[0] - augment;
80 const MLdouble bb2v1y = upper[1] - augment;
81 const MLdouble bb2v2x = upper[0] + width + augment;
82 const MLdouble bb2v2y = upper[1] + height + augment;
83
84 // store v1 maximum values in min-variables
85 const MLdouble minX = (bb1v1x > bb2v1x) ? bb1v1x : bb2v1x;
86 const MLdouble minY = (bb1v1y > bb2v1y) ? bb1v1y : bb2v1y;
87
88 // store v2 minimum values in max-variables
89 const MLdouble maxX = (bb1v2x < bb2v2x) ? bb1v2x : bb2v2x;
90 const MLdouble maxY = (bb1v2y < bb2v2y) ? bb1v2y : bb2v2y;
91
92 // if boxes intersect, all min values must be less/equal than the max values
93 bool result = true;
94
95 result = result && (minX <= maxX);
96 result = result && (minY <= maxY);
97
98 return result;
99 }
100 };
101
102 void computeDeviceConvexHullOfAllVisibleCSOs(const std::vector<CSODrawCSOInfos>& drawCSOInfos,
103 boost::geometry::model::polygon<Point2D>& convexHull);
104 void computeCSODevicePositions(const std::vector<CSODrawCSOInfos>& drawCSOInfos,
105 const CSODrawView2DInfos& view2DInfos);
106 bool seedPointIsOnSlice(CSO* cso, int index, const CSODrawView2DInfos& view2DInfos) const;
107 CSO* getFirstCSOWithAreaOnSlice(const CSODrawView2DInfos& view2DInfos) const;
108 bool computeDeviceHullForInputCSOList(const CSODrawView2DInfos& view2DInfos,
109 boost::geometry::model::polygon<Point2D>& convexHull) const;
110
111 void offsetConvexHull(boost::geometry::model::polygon<Point2D>& convexHull, const Point2D& centroidOfHull,
112 float deviceOffset) const;
113 static float computeMaxDistanceOfConvexHullFromCentroid(const boost::geometry::model::polygon<Point2D>& convexHull,
114 const Point2D& centroidOfHull);
115 void computeLabelRays(size_t numCSOs, float rayLength, const Point2D& centroidOfHull,
116 std::vector<Point2D>& labelRayEndPositions) const;
117 static void computeLabelSlotPositions(const boost::geometry::model::polygon<Point2D>& convexHull,
118 const Point2D& centroidOfHull, const std::vector<Point2D>& labelRayEndPositions,
119 std::vector<Point2D>& labelSlotPositions);
120
121 std::vector<std::pair<int, int>> computeNearestCSOForLabelPositionSlot(const std::vector<Point2D>& labelSlotPositions,
122 const std::vector<unsigned int>& csoIds);
123 void computeCSOToSlotDistanceMatrix(const std::vector<Point2D>& labelSlotPositions,
124 const std::vector<unsigned int>& csoIds,
125 std::vector<std::vector<float>>& csoSlotDistancesMatrix);
126
127 static float computeMinDistanceCSOToSlot(const std::vector<Point2D>& csoDevicePositions, const Point2D& slotPosition);
128 void setLabelPositionsForCSOs(const std::vector<std::pair<int, int>>& csoToSlotMapping,
129 const std::vector<unsigned int>& csoIds, const std::map<int, SbVec2f>& labelBoxes,
130 const std::vector<Point2D>& labelSlotPositions, const CSODrawView2DInfos& view2DInfos);
131 static SbVec2f getLabelBoxForCSO(const std::map<int, SbVec2f>& labelBoxes, int csoId);
132 void moveLabelByWidthHeight(const CSODrawView2DInfos& view2DInfos, int labelWidth, int labelHeight, MLint64& deviceX,
134 void avoidLabelOverlap(const std::map<int, SbVec2f>& labelBoxes);
135
136 void setupLabelBoundingBoxes(const std::map<int, SbVec2f>& labelBoxes,
137 std::map<int, LabelBoundingBox>& labelBoundingBoxes);
138 static bool boundingBoxHasOverlap(int csoId, const LabelBoundingBox& labelBoundingBox,
139 const std::map<int, LabelBoundingBox>& labelBoundingBoxes);
140 bool moveLabelOutwards(LabelBoundingBox& labelBoundingBox);
141
142 std::map<unsigned int, Point2D> _labelPositions;
143 std::map<unsigned int, std::vector<Point2D>> _csoDevicePositions;
144 CSOListPtr _hullCSOList;
145
146 Point2D _centroidOfConvexHull;
147
148 ML_MODULE_CLASS_HEADER(CSOLabelPlacementGlobal);
149};
150
#define SOCSO_EXPORT
Header file for system independent resolution.
Definition SoCSOSystem.h:21
Extension for rendering labels for CSOs.
Field to encapsulate a pointer to an ML base object.
Definition mlFields.h:813
void handleNotification(Field *field) override
Called when any field data in the field container of this module is modified.
void layoutVisibleCSOs(const std::vector< CSODrawCSOInfos > &drawCSOInfos, const std::map< int, SbVec2f > &labelBoxes, const CSODrawView2DInfos &view2DInfos, SoCSOLabelRenderer *labelRenderer) override
void getAttachedLabelPosition(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, int labelWidth, int labelHeight, float &deviceX, float &deviceY) override
Fills up the device position for an attached label.
Base module for providing custom label placement strategies.
Field to encapsulate an enumerated value.
Definition mlFields.h:185
Base class for all fields used in the ML.
Definition mlField.h:73
Field to encapsulate a float value.
Definition mlFields.h:449
Field to encapsulate an integer value.
Definition mlFields.h:123
#define ML_MODULE_CLASS_HEADER(className)
Similar to ML_CLASS_HEADER for the usage of derived classes from Module.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double MLdouble
Definition mlTypeDefs.h:217
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
Definition mlTypeDefs.h:411
boost::tuple< MLint, MLint > Point2D