MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
SoCSOLabelRenderer.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2012, 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#include "CSOLabelPlacement.h"
20#include <set>
21
23class CSOLabelRenderer;
25
27
40
42
45{
46 SO_NODE_HEADER(SoCSOLabelRenderer);
47
48public:
51
52protected:
55
56public:
58 void setVisibleCSOs(const std::vector<CSODrawCSOInfos>& drawCSOInformation, const CSODrawView2DInfos& view2DInfos,
60
62 void draw(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
64 void drawSecondPass(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
66 void drawOverlay(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
68
70 static void initClass();
71
72 bool isModificationEditor() const override
73 {
74 return true;
75 }
76
79
81
84
86
87 // just overload the methods below since we do not work
88 // with the standard actions
90 {}
91 void createDragMoveTo(const SoPointerPosition&) override
92 {}
93 bool createEndPress(int) override
94 {
95 return false;
96 }
98 {}
99
101 {}
103 {}
105 {
106 return nullptr;
107 }
108
109 void pointerPosition(const SoPointerPosition& pos) override;
110 void pointerLeftWindow() override;
111
112 int cursorShape() const override
113 {
115 }
116
121
122 bool shouldRenderGeneral(ml::CSO*) const override
123 {
124 return true;
125 }
126
127 void startDrawing(View2DSliceList* slicelist) override;
128
130 ml::CSO* getLabelCSO(const std::string& currentViewerId, const SoPointerPosition& pos);
131
135 int& resizeHandlerCode);
136
139 {
140 _labelRendererModule = labelRendererModule;
141 }
142
145
147 void resetCache() override;
148
151
154
157
187
194
196
201
217
218
221
230
231
232private:
234 ml::CSOLabelRenderer* _labelRendererModule;
235
237 struct DeviceOffset
238 {
239 DeviceOffset()
240 {
241 xOffset = yOffset = 0;
242 }
243 int xOffset;
244 int yOffset;
245 };
246
248 std::map<int, std::string> _csoLabelStrings;
250 std::map<int, std::string> _csoLabelNames;
252 std::map<int, std::string> _csoLabelCaptions;
254 std::map<int, DeviceOffset> _csoDeviceOffsets;
256 std::map<int, bool> _shouldRenderLabel;
257
259 std::multimap<std::string, CSOLabelRenderInformation> _viewerLabelRenderInformation;
261 void filterCSOLabelsForLayout(const std::vector<CSODrawCSOInfos>& drawCSOInfos, const CSODrawView2DInfos& view2DInfos,
263 std::vector<CSODrawCSOInfos>& filteredDrawCSOInfos);
266 void clearInternalStructures();
268 void buildAllLabelStringsThatNeedUpdate(ml::CSOList* csoList);
270 void prepareLabel(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
273 bool getLabelRenderInformation(const std::string& viewerId, ml::CSO* cso, CSOLabelRenderInformation& labelRenderInfo);
275 bool getLabelRenderInformation(const std::string& viewerId, unsigned int csoId,
277
280 void removeLabelRenderInformation(const std::string& viewerId, ml::CSO* cso);
283 void removeAllLabelRenderInformationForCSOId(int id, bool removeAll = false);
285 void cacheLabelRenderInformation(const std::string& viewerId, const CSOLabelRenderInformation& renderInfo);
287 bool isHit(const CSOLabelRenderInformation& labelRenderInfo, const SoPointerPosition& pos) const;
288 bool isHit(const CSOLabelRenderInformation& labelRenderInfo, float deviceX, float deviceY) const;
290 bool shouldRenderBecauseOfSliceAlignment(const CSODrawSliceInformation& drawSliceInfo);
292 bool isCSOGhosting(const CSODrawSliceInformation& drawSliceInfo);
294 bool shouldRenderLabelOfCSO(const CSODrawSliceInformation& drawSliceInfo, const CSODrawCSOInfos& drawCSOInfo,
301 void buildLabelString(ml::CSO* cso);
303 void drawLabelBorder(const CSODrawCSOInfos& csoInfos, const CSODrawSliceInformation& drawSliceInfo,
304 const SbVec2f& upperLeft, const SbVec2f& size);
306 void drawResizeHandlers(const SbVec2f& upperLeft, const SbVec2f& size);
308 void drawLabelName(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float fontColor[4],
309 const std::string& labelName);
311 void drawLabelCSOConnectingLine(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
312 const CSODrawSliceInformation& drawSliceInfo, const SbVec2f& upperLeft,
313 const SbVec2f& size);
314
316 void computeConnectingLineCSOPosition(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
318 float& lineX1, float& lineY1);
319
321 bool isMouseOverLabelOrCSOForInteraction(ml::CSO* cso);
323 bool isMouseOverLabelOrCSOForHighlighting(ml::CSO* cso);
324
325
328 void getCSOPoints(const CSODrawCSOInfos& csoInfos, std::vector<ml::Vector3>& csoPoints);
329
331 void ensureLabelIsVisible(View2DSlice* slice, SbVec2f& labelUpperLeft, SbVec2f& labelSize);
333 bool isLabelInsideViewer(View2DSlice* slice, SbVec2f& labelUpperLeft, SbVec2f& labelSize);
335 float fitFontSizeToBox(const CSOLabelRenderInformation& labelRenderInformation, const std::string& labelString,
336 float originalFontSize);
337
339 void moveLabelRelative(const std::string& viewerId, ml::CSO* cso, const SoPointerPosition& pos,
341
343 void setLabelRelative(const std::string& viewerId, ml::CSO* cso, const SbVec2f relativePosition);
345 SbVec2f getRelativePositionOfCSOInViewer(const std::string& viewerId, ml::CSO* cso);
347 float getResizeDelta(const SbVec2f& currentDevicePosition, int resizeHandlerCode);
349 void drawGLRectangle(const SbVec2f& upperLeft, const SbVec2f& lowerRight, float offset = 0,
350 float lineWidth = 1) const;
352 bool isInRectangle(const SbVec2f& rectUpperLeft, const SbVec2f& rectLowerRight, const SbVec2f& position) const;
353
355 float distance(float x0, float y0, float x1, float y1) const;
357 void clipLineToRectangle(float& lineX0, float& lineY0, float& lineX1, float& lineY1, float rectMinX, float rectMinY,
358 float rectMaxX, float rectMaxY) const;
360 int outcode(float lineX, float lineY, float rectMinX, float rectMinY, float rectMaxX, float rectMaxY) const;
361
363 void getLabelSize(float fontSize, const std::string& labelString, int& labelWidth, int& labelHeight);
366 float getFontSize(ml::CSO* cso, SoView2D* viewer);
368 void setFontSize(ml::CSO* cso, SoView2D* viewer, float fontSize);
369
371 void computeLabelBoxes(const std::vector<CSODrawCSOInfos>& filteredDrawCSOInfos,
372 const CSODrawView2DInfos& view2DInfos, std::map<int, SbVec2f>& labelBoxes);
374 void getLabelBoxForCSO(ml::CSO* cso, const CSODrawView2DInfos& view2DInfos, int& labelWidth, int& labelHeight);
375
377 View2DSlice* getCurrentSlice(const SoPointerPosition& pos);
378
380 ml::CSOLabelPlacement* getLabelPlacement();
381
382
384 void getDetachedLabelPosition(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float& deviceX,
385 float& deviceY);
387 SbVec2f computeNewDetachedLabelPositionWhileInteracting(const SbVec2f& lastRelativeLabelPosition,
390 ml::CSO* cso, View2DSlice* slice);
392 ml::Vector3 getDeviceAnchorPosition(ml::CSO* cso);
393
396 void getFreePosition(float& deviceX, float& deviceY, const std::string& viewerId, float labelWidth, float labelHeight,
397 View2DSlice* slice);
399 bool boundingBoxesIntersect(const CSOLabelRenderInformation& labelRenderInfo, float deviceX, float deviceY,
400 float labelWidth, float labelHeight);
402 static void baseEventCB(void* userData, ml::BaseEvent* event);
405 bool needsUpdate(ml::CSO* cso);
408 void attachAsListenerTo(ml::CSOList* csoList);
410 static std::string getViewerId(const SoPointerPosition& pos);
411
413 bool shouldRenderLabelString(unsigned int csoId, const std::string& viewerId);
415 SbBox2f getLabelDeviceRect(const CSOLabelRenderInformation& labelRenderInfo) const;
416
418 ml::CSOList* _listenToCSOList;
420 std::set<int> _needsUpdateCSOIds;
421
423 SbVec2f _startDragDevicePosition;
425 SbVec2f _startDragOffsetToCenter;
427 SbVec2f _currentFrameUpperLeft;
429 SbVec2f _currentFrameLowerRight;
431 SbVec2f _relativeLabelPosition;
433 ml::CSO* _csoLabelUnderMouseForInteraction;
435 ml::CSO* _csoLabelUnderMouseForHighlighting;
436
438 float _minimumFontSize;
440 float _maximumFontSize;
441
443 ml::CSOLabelPlacement _labelPlacement;
444
446};
447
ResizeHotSpot
Enumeration of hot spots for resizing the label.
#define SOCSO_EXPORT
Header file for system independent resolution.
Definition SoCSOSystem.h:21
Base class for an editor extension for the SoView2DCSOExtensibleEditor.
Extension for rendering labels for CSOs.
int cursorShape() const override
Returns the cursor shape that indicates the next creation.
void setVisibleCSOs(const std::vector< CSODrawCSOInfos > &drawCSOInformation, const CSODrawView2DInfos &view2DInfos, SoView2DCSOExtensibleEditor *editor) override
Set information about all the CSOs that are to be rendered.
void labelResizeStartPressAt(ml::CSO *cso, const SoPointerPosition &pos)
SoSFEnum viewerBorderHandling
Handling of labels that move over the viewer's border.
SoSFString outputInfoLabelCaption
Output of the label's caption.
void drawOverlay(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, SoView2DCSOExtensibleEditor *editor) override
Routine for drawing after the main routine has drawn.
void selectAndMoveStartPressAt(const SoPointerPosition &) override
void labelMoveStartPressAt(ml::CSO *cso, const SoPointerPosition &pos)
SoSFBool shouldDrawResizeHandlers
Shall resize handlers be drawn?
void createStartPressAt(const SoPointerPosition &) override
SoSFBool outputInfoIsValid
Flag to indicate whether the output info is valid.
SoSFInt32 labelBorderMarginY
Sets the inner margin of the label border in y-direction.
bool createEndPress(int) override
void setLabelUnderMouseForHighlighting(ml::CSO *cso)
Sets the label for the given CSO as being under the mouse for highlighting.
void labelMoveDragMoveTo(ml::CSO *cso, const SoPointerPosition &pos)
void pointerPosition(const SoPointerPosition &pos) override
Called when the mouse moves over a viewer.
~SoCSOLabelRenderer() override
Destructor.
bool isModificationEditor() const override
Returns whether the editor is a modification editor.
SoSFTrigger repaintTrigger
Just a dummy field to trigger a repaint.
ml::CSO * getLabelCSO(const std::string &currentViewerId, const SoPointerPosition &pos)
Returns the pointer to a CSO whose label is on the given viewer under the given position.
SoSFInt32 labelBorderMarginX
Sets the inner margin of the label border in x-direction.
void drawSecondPass(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, SoView2DCSOExtensibleEditor *editor) override
Drawing routine that comes between 'main' and 'overlay'.
static void initClass()
init class in inventor runtime
SoSFEnum detachedLabelPlacement
Positioning strategy for detached (manually moved) labels.
void createDragMoveTo(const SoPointerPosition &) override
void computeOutputInformation()
Fills output information fields for a CSO on a viewer.
SoSFInt32 minConnectingLineLength
The minimum length of a connecting line to get drawn (in pixel).
ml::CSO * getHitResizeHandler(const std::string &currentViewerId, const SoPointerPosition &pos, int &resizeHandlerCode)
Returns the pointer to a CSO whose label is on the given viewer under the given position.
SoSFVec2f outputInfoLabelBoundingBoxStart
Output of the upper left corner of the label's bounding box.
void labelResizeDragMoveTo(ml::CSO *cso, const SoPointerPosition &pos, int resizeHandlerCode)
SoSFMLBase inLabelPlacement
Optional input of label placement.
SoSFBool shouldOnlyRenderOnSliceCSOs
Shall only labels be drawn of CSOs that are on the current slice?
SoSFBool shouldRenderLabelName
Shall the label name be rendered at the CSO when the label has been moved away?
SoSFVec2f outputInfoLabelBoundingBoxEnd
Output of the lower right corner of the label's bounding box.
SoSFBool shouldDrawConnectingLine
Shall a connecting line between the label and the CSO be drawn?
SoCSOLabelRenderer()
Standard constructor.
void pointerLeftWindow() override
Called when mouse pointer leaves the window.
SoSFFloat connectingLineAlpha
Global alpha factor that is multiplied to the local alpha factor of connecting lines.
SoSFBool shouldShowLabelStringOfOutputInfoLabel
Should the label string be hidden for the label.
SoSFBool allowLabelResize
Shall the user be allowed to resize a label?
SoSFInt32 fontSize
Sets the font size of the text.
SoPointingAction * selectAndMoveEndPress(int) override
void setOuterModule(ml::CSOLabelRenderer *labelRendererModule)
Sets a pointer to the 'outer' module.
SoPointingAction * labelResizeEndPress(ml::CSO *cso, int clickCount)
SoSFInt32 outputInfoLabelCaptionWidth
Output of the x-offset value of the label's string.
SoSFBool tryToPlaceLabelsWithoutOverlap
Should the renderer attempt to place a label without overlapping other labels?
SoSFBool drawLabelBorderForSelectedCSO
Shall a border be drawn around the label of a selected CSO?
void selectAndMoveDragMoveTo(const SoPointerPosition &) override
void resetCache() override
Resets the internal label string cache.
SoSFString inputInfoViewerId
Input of the viewer id string.
void pointerPositionIfAllowedAt(const SoPointerPosition &) override
Sets seed points while moving the mouse – but not while dragging.
SoPointingAction * labelMoveEndPress(ml::CSO *cso, int clickCount)
void updateStringsInCache()
Updates all label strings in the cache.
SoSFBool drawConnectingLineToCenterOfCSO
Shall the connecting line be drawn to th center of a CSO? Or to the nearest point on the CSO?
void setLabelUnderMouseForInteraction(ml::CSO *cso)
Sets the label for the given CSO as being under the mouse for interaction (select,...
void startDrawing(View2DSliceList *slicelist) override
Is called before drawing.
SoSFBool shouldHighlightBorderOnMouseOver
Shall the label's border be highlighted on mouse over?
void draw(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, SoView2DCSOExtensibleEditor *editor) override
Drawing routine.
bool shouldRenderGeneral(ml::CSO *) const override
Returns whether a given CSO should be rendered by this general extension.
SoSFInt32 inputInfoCSOId
Trade interface for retrieving the device position (and other information) of a label on a certain vi...
SoSFString outputInfoLabelString
Output of the label's string.
SoPointerPosition manages the current position of the mouse cursor.
SoPointingAction is the base class for any mouse based interaction.
The SoSFMLBase field is the interface used by Inventor nodes to output ML Base objects to the outside...
Definition SoSFMLBase.h:46
SoView2D is a 2D viewer for image data.
Definition SoView2D.h:62
a list that holds all View2DSlice objects (lazily created) of a SoView2D
a single slice that is stored in a View2DSliceList, typically created by a View2DSliceList
Definition View2DSlice.h:48
BaseEvent is the base class for all events emitted from EventSourceBase.
Base module for providing custom label placement strategies.
Module encapsulation the SoView2D extension for rendering labels for CSOs.
A CSOList comprises a number of CSOs and CSOGroups and is the central object for contour segmentation...
Definition CSOList.h:61
The CSO represents a contour segmentation object.
Definition CSO.h:44
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
Structure to store render information for a certain CSO and viewer.