18 #include "../CSOLabelPlacement.h"
20 #include <ThirdPartyWarningsDisable.h>
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>
29 #include <ThirdPartyWarningsRestore.h>
34 typedef boost::tuple <MLint, MLint>
Point2D;
43 HULL_POINTS_FROM_CSO_LIST
49 const std::map < int, SbVec2f>& labelBoxes,
69 struct LabelBoundingBox
74 bool overlaps(
const LabelBoundingBox& labelBoundingBox)
const
78 const MLdouble bb1v1x = labelBoundingBox.upper[0] - augment;
79 const MLdouble bb1v1y = labelBoundingBox.upper[1] - augment;
80 const MLdouble bb1v2x = labelBoundingBox.upper[0] + augment + labelBoundingBox.width;
81 const MLdouble bb1v2y = labelBoundingBox.upper[1] + augment + labelBoundingBox.height;
83 const MLdouble bb2v1x = upper[0] - augment;
84 const MLdouble bb2v1y = upper[1] - augment;
85 const MLdouble bb2v2x = upper[0] + width + augment;
86 const MLdouble bb2v2y = upper[1] + height + augment;
89 const MLdouble minX = (bb1v1x > bb2v1x) ? bb1v1x : bb2v1x;
90 const MLdouble minY = (bb1v1y > bb2v1y) ? bb1v1y : bb2v1y;
93 const MLdouble maxX = (bb1v2x < bb2v2x) ? bb1v2x : bb2v2x;
94 const MLdouble maxY = (bb1v2y < bb2v2y) ? bb1v2y : bb2v2y;
99 result = result && (minX <= maxX);
100 result = result && (minY <= maxY);
106 void computeDeviceConvexHullOfAllCSOs(
const std::vector<CSODrawCSOInfos>& drawCSOInfos,
107 boost::geometry::model::polygon < Point2D >& convexHull);
108 void computeCSODevicePositions(
const std::vector<CSODrawCSOInfos>& drawCSOInfos,
110 bool seedPointIsInSlicePlane(CSO* cso,
int index,
const CSODrawView2DInfos& view2DInfos)
const;
113 boost::geometry::model::polygon<Point2D>& convexHull)
const;
115 void offsetConvexHull(boost::geometry::model::polygon < Point2D >& convexHull,
const Point2D& centroidOfHull,
float deviceOffset)
const;
116 static float computeMaxDistanceOfConvexHullFromCentroid(
const boost::geometry::model::polygon < Point2D >& convexHull,
const Point2D& centroidOfHull);
117 void computeLabelRays(
size_t numCSOs,
float rayLength,
const Point2D& centroidOfHull, std::vector <Point2D>& labelRayEndPositions)
const;
118 static void computeLabelSlotPositions(
const boost::geometry::model::polygon < Point2D >& convexHull,
const Point2D& centroidOfHull,
119 const std::vector <Point2D>& labelRayEndPositions, std::vector <Point2D>& labelSlotPositions );
121 std::vector < std::pair < int, int> > computeNearestCSOForLabelPositionSlot(
const std::vector <Point2D>& labelSlotPositions,
const std::vector<unsigned int>& csoIds);
122 void computeCSOToSlotDistanceMatrix(
const std::vector <Point2D>& labelSlotPositions,
const std::vector<unsigned int>& csoIds, std::vector < std::vector < float > >& csoSlotDistancesMatrix);
124 static float computeMinDistanceCSOToSlot(
const std::vector<Point2D>& csoDevicePositions,
const Point2D& slotPosition);
125 void setLabelPositionsForCSOs(
const std::vector< std::pair< int, int > >& csoToSlotMapping,
126 const std::vector<unsigned int>& csoIds,
127 const std::map< int, SbVec2f>& labelBoxes,
128 const std::vector<Point2D>& labelSlotPositions,
130 static SbVec2f getLabelBoxForCSO(
const std::map < int, SbVec2f >& labelBoxes,
int csoId);
132 void avoidLabelOverlap(
const std::map < int, SbVec2f >& labelBoxes);
134 void setupLabelBoundingBoxes(
const std::map< int, SbVec2f >& labelBoxes, std::map< int, LabelBoundingBox >& labelBoundingBoxes );
135 static bool boundingBoxHasOverlap(
int csoId,
const LabelBoundingBox& labelBoundingBox,
const std::map< int, LabelBoundingBox >& labelBoundingBoxes );
136 bool moveLabelOutwards(LabelBoundingBox& labelBoundingBox);
138 std::map <unsigned int, Point2D> _labelPositions;
139 std::map <unsigned int, std::vector<Point2D> > _csoDevicePositions;
140 CSOListPtr _hullCSOList;
#define SOCSO_EXPORT
Header file for system independent resolution.
Extension for rendering labels for CSOs.
Field to encapsulate a pointer to an ML base object.
Label placement strategy.
CSOLabelPlacementGlobal()
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.
Base class for all fields used in the ML.
Field to encapsulate a float value.
Field to encapsulate an integer value.
#define ML_MODULE_CLASS_HEADER(className)
Similar to ML_CLASS_HEADER for the usage of derived classes from Module.
INT64 MLint64
Include 64-bit integer support for Windows or Unix.
boost::tuple< MLint, MLint > Point2D