MeVisLab Resolution Independence API
Toggle main menu visibility
Loading...
Searching...
No Matches
SoCoordinateSystem.h
Go to the documentation of this file.
1
/*************************************************************************************
2
**
3
** Copyright 2021, 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
#pragma once
14
15
#include <ThirdPartyWarningsDisable.h>
16
17
#include <Inventor/nodes/SoShape.h>
18
#include <Inventor/fields/SoSFBool.h>
19
#include <Inventor/fields/SoSFVec3f.h>
20
#include <Inventor/fields/SoSFFloat.h>
21
#include <Inventor/fields/SoSFDouble.h>
22
#include <Inventor/fields/SoSFColor.h>
23
#include <Inventor/fields/SoSFEnum.h>
24
#include <Inventor/fields/SoSFNode.h>
25
26
#include <
SoSFMLImage.h
>
27
#include <
SoSFMLBase.h
>
28
29
#include <ThirdPartyWarningsRestore.h>
30
31
#include <sstream>
32
#include <iostream>
33
34
namespace
35
{
36
37
inline
float
sign(
float
number)
38
{
39
return
(number < 0) ? -1.f : 1.f;
40
}
41
42
}
// namespace
43
44
struct
CoordinateAxis
45
{
46
CoordinateAxis
(
const
SbVec3f&
worldStart
,
const
SbVec3f&
worldEnd
,
const
std::string&
label
,
int
logicalDirection
)
47
:
label
(
label
)
48
,
logicalDirection
(
logicalDirection
)
49
{
50
isMaxPointingToScreenZ
=
false
;
51
52
setWorldPositions
(
worldStart
,
worldEnd
);
53
}
54
55
void
setWorldPositions
(
const
SbVec3f& start,
const
SbVec3f& end)
56
{
57
worldStart
= start;
58
worldEnd
= end;
59
worldDirection
= end - start;
60
worldLength
=
worldDirection
.length();
61
worldDirection
.normalize();
62
63
renderLengthForArrowPlacement
=
worldLength
;
64
}
65
66
void
setScreenPositions
(
const
SbVec3f& start,
const
SbVec3f& end)
67
{
68
screenStart
= start;
69
screenEnd
= end;
70
screenDirection
= end - start;
71
screenDirection
.normalize();
72
}
73
74
std::string
label
;
75
76
int
logicalDirection
;
77
78
SbVec3f
worldStart
;
79
SbVec3f
worldEnd
;
80
SbVec3f
worldDirection
;
81
float
worldLength
;
82
83
SbVec3f
screenStart
;
84
SbVec3f
screenEnd
;
85
SbVec3f
screenDirection
;
86
87
SbVec3f
tickDirection
;
88
SbVec2f
textScreenShift
;
89
90
float
renderLengthForArrowPlacement
;
91
bool
isMaxPointingToScreenZ
;
92
};
93
94
struct
LabelText
95
{
96
LabelText
()
97
{
98
fontSize
= 10.f;
99
textColor
.setValue(1, 1, 1);
100
textAlpha
= 1.f;
101
useTextShadow
=
true
;
102
textShadowColor
.setValue(0, 0, 0);
103
}
104
105
std::string
text
;
106
107
SbVec3f
textPosition
;
108
SbVec2f
textShiftFactorScreen
;
109
110
float
fontSize
;
111
112
SbColor
textColor
;
113
float
textAlpha
;
114
115
bool
useTextShadow
;
116
SbColor
textShadowColor
;
117
};
118
119
struct
Label
120
{
121
Label
()
122
{
123
initializeScreenBoundingBox
();
124
}
125
126
void
initializeScreenBoundingBox
()
127
{
128
screenBoundingBox
[0].setValue(FLT_MAX, FLT_MAX);
129
screenBoundingBox
[1].setValue(FLT_MAX, FLT_MAX);
130
isVisible
=
true
;
131
isOnScreen
=
false
;
132
}
133
134
bool
overlaps
(
const
Label
& otherLabel)
const
135
{
136
const
auto
margin = 3.0f;
137
138
const
auto
ax0 =
screenBoundingBox
[0][0] - margin;
139
const
auto
ay0 =
screenBoundingBox
[0][1] - margin;
140
const
auto
ax1 =
screenBoundingBox
[1][0] + margin;
141
const
auto
ay1 =
screenBoundingBox
[1][1] + margin;
142
143
const
auto
bx0 = otherLabel.
screenBoundingBox
[0][0] - margin;
144
const
auto
by0 = otherLabel.
screenBoundingBox
[0][1] - margin;
145
const
auto
bx1 = otherLabel.
screenBoundingBox
[1][0] + margin;
146
const
auto
by1 = otherLabel.
screenBoundingBox
[1][1] + margin;
147
148
const
auto
awidth = abs(ax0 - ax1);
149
const
auto
aheight = abs(ay0 - ay1);
150
151
const
auto
bwidth = abs(bx0 - bx1);
152
const
auto
bheight = abs(by0 - by1);
153
154
return
(abs((ax0 + awidth / 2) - (bx0 + bwidth / 2)) * 2 < (awidth + bwidth)) &&
155
(abs((ay0 + aheight / 2) - (by0 + bheight / 2)) * 2 < (aheight + bheight));
156
}
157
158
SbVec3f
tickPosition
;
159
SbVec3f
tickDirection
;
160
SbColor
tickColor
;
161
float
tickAlpha
;
162
163
SbVec2f
screenBoundingBox
[2];
164
bool
isVisible
;
165
bool
isOnScreen
;
166
167
LabelText
labelText
;
168
};
169
170
class
SoCoordinateSystem
:
public
SoShape
171
{
172
SO_NODE_HEADER(
SoCoordinateSystem
);
173
174
public
:
175
static
void
initClass
();
176
177
SoCoordinateSystem
();
178
179
enum
StrideMode
{
180
AUTO
= 0,
181
USER
= 1
182
};
183
184
enum
EndTickMode
{
185
ROUND_UP
= 0,
186
ROUND_DOWN
= 1,
187
ROUND_NEAREST
= 2,
188
PRECISE
= 3
189
};
190
191
enum
UserTransformMode
{
192
NO_USER_TRANSFORM
= 0,
193
USER_TRANSFORM_INSTEAD_OF_INPUT
= 1,
194
APPLY_USER_TRANSFORM_TO_INPUT
= 2
195
};
196
197
SoSFTypedEnum<StrideMode>
strideMode
;
198
SoSFDouble
userStride
;
199
200
SoSFTypedEnum<EndTickMode>
endTickMode
;
201
202
SoSFColor
axisColor
;
203
SoSFFloat
axisAlpha
;
204
205
SoSFColor
tickColor
;
206
SoSFFloat
tickAlpha
;
207
208
SoSFColor
numbersFontColor
;
209
SoSFFloat
numbersFontAlpha
;
210
211
SoSFColor
lettersFontColor
;
212
SoSFFloat
lettersFontAlpha
;
213
SoSFFloat
lettersFontSizeOffset
;
214
215
SoSFBool
useTextShadow
;
216
SoSFColor
textShadowColor
;
217
218
SoSFFloat
fontSize
;
219
220
SoSFFloat
arrowLengthFactor
;
221
SoSFFloat
letterOffsetFactor
;
222
SoSFBool
useVoxelAlignedBoundingBox
;
223
224
SoSFMLImage
inImage
;
225
SoSFNode
inNode
;
226
SoSFVec3f
userScale
;
227
SoSFVec3f
userTranslate
;
228
SoSFTypedEnum<UserTransformMode>
userTransformMode
;
229
230
protected
:
231
~SoCoordinateSystem
()
override
;
232
233
private
:
234
std::vector<CoordinateAxis> axes;
235
int
_maxZAxisIndex;
236
237
void
initializeAxes();
238
void
applyUserTransform();
239
240
void
computeScreenCoordinates(
CoordinateAxis
& axis);
241
void
computeAndSetTickDirections();
242
SbVec2f computeTextShiftFactorVector(
int
axisIndex);
243
float
computeTextShiftFactor(
float
angle0,
float
angle1);
244
void
computeAndSetLabelVisibility(std::vector<Label>& labels);
245
246
float
getTickScale();
247
int
getEndTickModifier(
int
numTicks,
float
length);
248
249
double
getStride();
250
double
getAutoStride(
float
maxRange);
251
double
getUserStride(
float
maxRange);
252
float
getMaxAxisRange();
253
254
bool
anyLabelOverlap(
const
std::vector<Label>& labels);
255
void
generatePrimitives(SoAction*)
override
256
{}
257
258
void
GLRender(SoGLRenderAction* action)
override
;
259
void
glRenderTicks();
260
void
glRenderAxisLines();
261
void
glRenderOrigin();
262
263
void
computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center)
override
;
264
265
266
void
updateAxes(SoField*);
267
268
void
updateFromInputInventorScene();
269
void
updateFromInputImage();
270
271
SbVec3f getImageExtent();
272
SbMatrix getImageVoxelToWorldMatrix();
273
float
getScaleForLogicalDirection(
const
CoordinateAxis
& axis);
274
275
void
message(
const
std::string& messageText)
const
276
{
277
std::cout << messageText << std::endl;
278
}
279
};
SoSFMLBase.h
SoSFMLImage.h
SoCoordinateSystem::initClass
static void initClass()
SoCoordinateSystem::useVoxelAlignedBoundingBox
SoSFBool useVoxelAlignedBoundingBox
Definition
SoCoordinateSystem.h:222
SoCoordinateSystem::userStride
SoSFDouble userStride
Definition
SoCoordinateSystem.h:198
SoCoordinateSystem::axisColor
SoSFColor axisColor
Definition
SoCoordinateSystem.h:202
SoCoordinateSystem::endTickMode
SoSFTypedEnum< EndTickMode > endTickMode
Definition
SoCoordinateSystem.h:200
SoCoordinateSystem::numbersFontColor
SoSFColor numbersFontColor
Definition
SoCoordinateSystem.h:208
SoCoordinateSystem::lettersFontAlpha
SoSFFloat lettersFontAlpha
Definition
SoCoordinateSystem.h:212
SoCoordinateSystem::userTransformMode
SoSFTypedEnum< UserTransformMode > userTransformMode
Definition
SoCoordinateSystem.h:228
SoCoordinateSystem::arrowLengthFactor
SoSFFloat arrowLengthFactor
Definition
SoCoordinateSystem.h:220
SoCoordinateSystem::SoCoordinateSystem
SoCoordinateSystem()
SoCoordinateSystem::tickColor
SoSFColor tickColor
Definition
SoCoordinateSystem.h:205
SoCoordinateSystem::numbersFontAlpha
SoSFFloat numbersFontAlpha
Definition
SoCoordinateSystem.h:209
SoCoordinateSystem::inImage
SoSFMLImage inImage
Definition
SoCoordinateSystem.h:224
SoCoordinateSystem::strideMode
SoSFTypedEnum< StrideMode > strideMode
Definition
SoCoordinateSystem.h:197
SoCoordinateSystem::inNode
SoSFNode inNode
Definition
SoCoordinateSystem.h:225
SoCoordinateSystem::UserTransformMode
UserTransformMode
Definition
SoCoordinateSystem.h:191
SoCoordinateSystem::APPLY_USER_TRANSFORM_TO_INPUT
@ APPLY_USER_TRANSFORM_TO_INPUT
Definition
SoCoordinateSystem.h:194
SoCoordinateSystem::USER_TRANSFORM_INSTEAD_OF_INPUT
@ USER_TRANSFORM_INSTEAD_OF_INPUT
Definition
SoCoordinateSystem.h:193
SoCoordinateSystem::NO_USER_TRANSFORM
@ NO_USER_TRANSFORM
Definition
SoCoordinateSystem.h:192
SoCoordinateSystem::textShadowColor
SoSFColor textShadowColor
Definition
SoCoordinateSystem.h:216
SoCoordinateSystem::letterOffsetFactor
SoSFFloat letterOffsetFactor
Definition
SoCoordinateSystem.h:221
SoCoordinateSystem::~SoCoordinateSystem
~SoCoordinateSystem() override
SoCoordinateSystem::EndTickMode
EndTickMode
Definition
SoCoordinateSystem.h:184
SoCoordinateSystem::PRECISE
@ PRECISE
Definition
SoCoordinateSystem.h:188
SoCoordinateSystem::ROUND_DOWN
@ ROUND_DOWN
Definition
SoCoordinateSystem.h:186
SoCoordinateSystem::ROUND_NEAREST
@ ROUND_NEAREST
Definition
SoCoordinateSystem.h:187
SoCoordinateSystem::ROUND_UP
@ ROUND_UP
Definition
SoCoordinateSystem.h:185
SoCoordinateSystem::useTextShadow
SoSFBool useTextShadow
Definition
SoCoordinateSystem.h:215
SoCoordinateSystem::userScale
SoSFVec3f userScale
Definition
SoCoordinateSystem.h:226
SoCoordinateSystem::userTranslate
SoSFVec3f userTranslate
Definition
SoCoordinateSystem.h:227
SoCoordinateSystem::tickAlpha
SoSFFloat tickAlpha
Definition
SoCoordinateSystem.h:206
SoCoordinateSystem::fontSize
SoSFFloat fontSize
Definition
SoCoordinateSystem.h:218
SoCoordinateSystem::lettersFontColor
SoSFColor lettersFontColor
Definition
SoCoordinateSystem.h:211
SoCoordinateSystem::axisAlpha
SoSFFloat axisAlpha
Definition
SoCoordinateSystem.h:203
SoCoordinateSystem::StrideMode
StrideMode
Definition
SoCoordinateSystem.h:179
SoCoordinateSystem::USER
@ USER
Definition
SoCoordinateSystem.h:181
SoCoordinateSystem::AUTO
@ AUTO
Definition
SoCoordinateSystem.h:180
SoCoordinateSystem::lettersFontSizeOffset
SoSFFloat lettersFontSizeOffset
Definition
SoCoordinateSystem.h:213
SoSFMLImage
Definition
SoSFMLImage.h:84
CoordinateAxis
Definition
SoCoordinateSystem.h:45
CoordinateAxis::worldEnd
SbVec3f worldEnd
Definition
SoCoordinateSystem.h:79
CoordinateAxis::screenStart
SbVec3f screenStart
Definition
SoCoordinateSystem.h:83
CoordinateAxis::textScreenShift
SbVec2f textScreenShift
Definition
SoCoordinateSystem.h:88
CoordinateAxis::label
std::string label
Definition
SoCoordinateSystem.h:74
CoordinateAxis::isMaxPointingToScreenZ
bool isMaxPointingToScreenZ
Definition
SoCoordinateSystem.h:91
CoordinateAxis::worldDirection
SbVec3f worldDirection
Definition
SoCoordinateSystem.h:80
CoordinateAxis::setWorldPositions
void setWorldPositions(const SbVec3f &start, const SbVec3f &end)
Definition
SoCoordinateSystem.h:55
CoordinateAxis::setScreenPositions
void setScreenPositions(const SbVec3f &start, const SbVec3f &end)
Definition
SoCoordinateSystem.h:66
CoordinateAxis::CoordinateAxis
CoordinateAxis(const SbVec3f &worldStart, const SbVec3f &worldEnd, const std::string &label, int logicalDirection)
Definition
SoCoordinateSystem.h:46
CoordinateAxis::screenDirection
SbVec3f screenDirection
Definition
SoCoordinateSystem.h:85
CoordinateAxis::logicalDirection
int logicalDirection
Definition
SoCoordinateSystem.h:76
CoordinateAxis::renderLengthForArrowPlacement
float renderLengthForArrowPlacement
Definition
SoCoordinateSystem.h:90
CoordinateAxis::screenEnd
SbVec3f screenEnd
Definition
SoCoordinateSystem.h:84
CoordinateAxis::tickDirection
SbVec3f tickDirection
Definition
SoCoordinateSystem.h:87
CoordinateAxis::worldStart
SbVec3f worldStart
Definition
SoCoordinateSystem.h:78
CoordinateAxis::worldLength
float worldLength
Definition
SoCoordinateSystem.h:81
LabelText
Definition
SoCoordinateSystem.h:95
LabelText::textShiftFactorScreen
SbVec2f textShiftFactorScreen
Definition
SoCoordinateSystem.h:108
LabelText::text
std::string text
Definition
SoCoordinateSystem.h:105
LabelText::useTextShadow
bool useTextShadow
Definition
SoCoordinateSystem.h:115
LabelText::textPosition
SbVec3f textPosition
Definition
SoCoordinateSystem.h:107
LabelText::textShadowColor
SbColor textShadowColor
Definition
SoCoordinateSystem.h:116
LabelText::textAlpha
float textAlpha
Definition
SoCoordinateSystem.h:113
LabelText::fontSize
float fontSize
Definition
SoCoordinateSystem.h:110
LabelText::LabelText
LabelText()
Definition
SoCoordinateSystem.h:96
LabelText::textColor
SbColor textColor
Definition
SoCoordinateSystem.h:112
Label::tickAlpha
float tickAlpha
Definition
SoCoordinateSystem.h:161
Label::isOnScreen
bool isOnScreen
Definition
SoCoordinateSystem.h:165
Label::tickDirection
SbVec3f tickDirection
Definition
SoCoordinateSystem.h:159
Label::initializeScreenBoundingBox
void initializeScreenBoundingBox()
Definition
SoCoordinateSystem.h:126
Label::labelText
LabelText labelText
Definition
SoCoordinateSystem.h:167
Label::tickColor
SbColor tickColor
Definition
SoCoordinateSystem.h:160
Label::isVisible
bool isVisible
Definition
SoCoordinateSystem.h:164
Label::tickPosition
SbVec3f tickPosition
Definition
SoCoordinateSystem.h:158
Label::overlaps
bool overlaps(const Label &otherLabel) const
Definition
SoCoordinateSystem.h:134
Label::screenBoundingBox
SbVec2f screenBoundingBox[2]
Definition
SoCoordinateSystem.h:163
Label::Label
Label()
Definition
SoCoordinateSystem.h:121
MeVisLab
Standard
Sources
Inventor
SoUtils
SoCoordinateSystem.h
Generated by
1.18.0