-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayBodyFunctors.cpp
611 lines (528 loc) · 18.8 KB
/
DisplayBodyFunctors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/**
* @file DisplayBodyFunctors.h
* @author Dan R. Lipsa
* @date 26 Oct. 2010
*
* Implementation for functors to display a body
*/
#include "Body.h"
#include "BodySelector.h"
#include "ColorBarModel.h"
#include "Debug.h"
#include "DisplayBodyFunctors.h"
#include "DisplayFaceFunctors.h"
#include "DisplayEdgeFunctors.h"
#include "Simulation.h"
#include "Settings.h"
#include "OpenGLUtils.h"
#include "ViewSettings.h"
#include "VectorAverage.h"
// Private Classes/Functions
// ======================================================================
struct ContextSegment : public Segment
{
ContextSegment () : Segment ()
{
}
ContextSegment (const QColor& color, const Segment& segment) :
Segment (segment), m_color (color)
{
}
QColor m_color;
};
struct FocusTextureSegment : public Segment
{
FocusTextureSegment () : Segment (), m_textureCoordinate (0)
{
}
FocusTextureSegment (GLfloat textureCoordinate,
const Segment& segment) :
Segment (segment), m_textureCoordinate (textureCoordinate)
{
}
GLfloat m_textureCoordinate;
};
struct FocusColorSegment : public Segment
{
FocusColorSegment () : Segment ()
{
}
FocusColorSegment (const QColor& color,
const Segment& segment) :
Segment (segment), m_color (color)
{
}
QColor m_color;
};
// returns multiplier for velocity
float clampMax (float length, float maxLength, bool* clamped)
{
if (length > maxLength)
{
*clamped = true;
return maxLength;
}
else
{
*clamped = false;
return length;
}
}
// DisplayBodyBase
// ======================================================================
template <typename PropertySetter>
DisplayBodyBase<PropertySetter>::
DisplayBodyBase (
const Settings& settings, const BodySelector& bodySelector,
PropertySetter propertySetter, Context::Enum context,
bool useZPos, double zPos) :
DisplayElementProperty<PropertySetter> (
settings, propertySetter, useZPos, zPos),
m_bodySelector (bodySelector),
m_context (context)
{
}
template <typename PropertySetter>
void DisplayBodyBase<PropertySetter>::
BeginContext ()
{
glEnable (GL_BLEND);
glDepthMask (GL_FALSE);
}
template <typename PropertySetter>
void DisplayBodyBase<PropertySetter>::
EndContext ()
{
glDepthMask (GL_TRUE);
glDisable (GL_BLEND);
}
template <typename PropertySetter>
bool DisplayBodyBase<PropertySetter>::IsFocus (boost::shared_ptr<Body> b) const
{
return m_bodySelector (b) && m_context == Context::UNSELECTED;
}
template <typename PropertySetter>
void DisplayBodyBase<PropertySetter>::
operator () (boost::shared_ptr<Body> b)
{
if (IsFocus (b))
display (b);
else
{
BeginContext ();
display (b);
EndContext ();
}
}
// DisplayBodyDeformation
// ======================================================================
DisplayBodyDeformation::DisplayBodyDeformation (
const Settings& settings, ViewNumber::Enum viewNumber, bool is2D,
const BodySelector& bodySelector, float deformationSizeInitialRatio,
bool useZPos, double zPos):
DisplayBodyBase<> (
settings, bodySelector,
SetterTextureCoordinate(settings, viewNumber, is2D), Context::UNSELECTED,
useZPos, zPos),
m_deformationSizeInitialRatio (deformationSizeInitialRatio)
{}
void DisplayBodyDeformation::display (boost::shared_ptr<Body> body)
{
if (body->IsObject ())
return;
ViewNumber::Enum viewNumber = GetViewNumber ();
ViewSettings& vs = m_settings.GetViewSettings (viewNumber);
float size = m_deformationSizeInitialRatio * vs.GetDeformationSize ();
float lineWidth = vs.GetDeformationLineWidth ();
if (GetFocusContext (body) == FOCUS)
glColor (m_settings.GetHighlightColor (viewNumber, HighlightNumber::H0));
else
glColor (QColor::fromRgbF (0, 0, 0, vs.GetContextAlpha ()));
G3D::Matrix3 rotation = MatrixFromColumns (
body->GetDeformationEigenVector (0),
body->GetDeformationEigenVector (1),
body->GetDeformationEigenVector (2));
G3D::CoordinateFrame cf (rotation, body->GetCenter ());
glPushMatrix ();
glMultMatrix (cf);
drawEllipsis2D (body->GetDeformationEigenValue (0),
body->GetDeformationEigenValue (1), size, lineWidth);
glPopMatrix ();
}
// DisplayBodyVelocity
// ======================================================================
DisplayBodyVelocity::DisplayBodyVelocity (
const Settings& settings, ViewNumber::Enum viewNumber, bool is2D,
const BodySelector& bodySelector, float bubbleSize,
float velocitySizeInitialRatio, float onePixelInObjectSpace,
GLUquadricObj* quadric,
bool sameSize, bool clampingShown, bool useZPos, double zPos):
DisplayBodyBase<> (
settings, bodySelector,
SetterTextureCoordinate(settings, viewNumber, is2D),
Context::UNSELECTED, useZPos, zPos),
m_bubbleDiameter (bubbleSize),
m_onePixelInObjectSpace (onePixelInObjectSpace),
m_velocitySizeInitialRatio (velocitySizeInitialRatio),
m_sameSize (sameSize),
m_clampingShown (clampingShown),
m_is2D (is2D),
m_quadric (quadric)
{}
void DisplayBodyVelocity::display (boost::shared_ptr<Body> body)
{
if (body->IsObject ())
return;
ViewNumber::Enum viewNumber = GetViewNumber ();
ViewSettings& vs = m_settings.GetViewSettings (viewNumber);
bool clamped = false;
G3D::Vector3 displayVelocity;
G3D::Vector3 velocity = body->GetVelocity ();
float velocityLength = velocity.length ();
glPushAttrib (GL_CURRENT_BIT);
if (m_sameSize)
{
// set all velocity magnitudes to be bubbleDiameter
clamped = true;
displayVelocity = velocity;
displayVelocity *= m_bubbleDiameter / displayVelocity.length ();
}
else
{
// size = bubbleDiameter / (clampInterval.max () - interval.min ())
float size =
m_velocitySizeInitialRatio * vs.GetVelocityInverseClampMaxRatio ();
displayVelocity = velocity *
(clampMax (velocityLength * size, m_bubbleDiameter, &clamped) /
velocityLength);
}
if (GetFocusContext (body) == FOCUS)
{
float texCoord = vs.GetColorMapVelocity ()->TexCoord (velocityLength);
glTexCoord1f (texCoord);
}
else
glColor (QColor::fromRgbF (0, 0, 0, vs.GetContextAlpha ()));
if (m_is2D)
DisplaySegmentArrow2D (
body->GetCenter ().xy () - displayVelocity.xy () / 2,
displayVelocity.xy (), vs.GetVelocityLineWidth (),
m_onePixelInObjectSpace, clamped && m_clampingShown);
else
DisplayVtkArrow (body->GetCenter (), displayVelocity, m_quadric);
glPopAttrib ();
}
// DisplayBodyCenter
// ======================================================================
DisplayBodyCenter::DisplayBodyCenter (
const Settings& settings, const BodySelector& bodySelector,
bool useZPos, double zPos):
DisplayBodyBase<> (
settings, bodySelector,
// the setter is not used
SetterTextureCoordinate(settings, ViewNumber::VIEW0, true),
Context::UNSELECTED, useZPos, zPos)
{}
void DisplayBodyCenter::display (boost::shared_ptr<Body> b)
{
if (GetFocusContext (b) == FOCUS)
{
G3D::Vector3 v = b->GetCenter ();
v = (m_useZPos ? G3D::Vector3 (v.xy (), m_zPos) : v);
glBegin(GL_POINTS);
::glVertex(v);
glEnd ();
}
}
// DisplayBody
// ======================================================================
template<typename displayFace, typename PropertySetter>
DisplayBody<displayFace, PropertySetter>::
DisplayBody (
const Settings& settings, bool is2D, const BodySelector& bodySelector,
Context::Enum context,
ContextInvisible::Enum contextDisplay,
ViewNumber::Enum viewNumber, bool useZPos, double zPos) :
DisplayBodyBase<PropertySetter> (
settings, bodySelector,
PropertySetter (settings, viewNumber, is2D), context,
useZPos, zPos),
m_contextInvisible (contextDisplay)
{
}
template<typename displayFace, typename PropertySetter>
DisplayBody<displayFace, PropertySetter>::
DisplayBody (
const Settings& settings,
const BodySelector& bodySelector,
PropertySetter setter, Context::Enum context,
ContextInvisible::Enum contextDisplay,
bool useZPos, double zPos) :
DisplayBodyBase<PropertySetter> (
settings, bodySelector, setter, context, useZPos, zPos),
m_contextInvisible (contextDisplay)
{
}
template<typename displayFace, typename PropertySetter>
void DisplayBody<displayFace, PropertySetter>::
display (boost::shared_ptr<Body> b)
{
ViewSettings& vs = this->m_settings.GetViewSettings (this->GetViewNumber ());
DisplayElement::FocusContext bodyFc =
DisplayBodyBase<PropertySetter>::GetFocusContext (b);
if (bodyFc == DisplayElement::CONTEXT &&
(m_contextInvisible == ContextInvisible::ALWAYS ||
(m_contextInvisible == ContextInvisible::USER_DEFINED &&
! vs.IsSelectionContextShown ()))
)
return;
if (vs.IsScalarContext ())
bodyFc = DisplayElement::CONTEXT;
vector<boost::shared_ptr<OrientedFace> > v = b->GetOrientedFaces ();
for_each (
v.begin (), v.end (),
displayFace (
this->m_settings, this->m_propertySetter, bodyFc,
this->m_useZPos, this->m_zPos));
}
// DisplayBubblePath
// ======================================================================
template<typename PropertySetter, typename DisplaySegment>
DisplayBubblePath<PropertySetter, DisplaySegment>::
DisplayBubblePath (
const Settings& settings, ViewNumber::Enum viewNumber, bool is2D,
const BodySelector& bodySelector, GLUquadricObj* quadric,
const Simulation& simulation, size_t timeBegin, size_t timeEnd,
bool useTimeDisplacement,
double timeDisplacement) :
DisplayBodyBase<PropertySetter> (
settings, bodySelector,
PropertySetter (settings, viewNumber, is2D), Context::UNSELECTED,
useTimeDisplacement, timeDisplacement),
m_displaySegment (
quadric,
this->GetViewSettings ().IsBubblePathsLineUsed () ?
this->GetViewSettings ().GetEdgeWidth () :
this->GetViewSettings ().GetEdgeRadius ()),
m_simulation (simulation),
m_timeBegin (timeBegin),
m_timeEnd (timeEnd)
{
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
operator () (size_t bodyId)
{
m_focusTextureSegments.resize (0);
m_focusColorSegments.resize (0);
m_contextSegments.resize (0);
const BodyAlongTime& bat = m_simulation.GetBodyAlongTime (bodyId);
StripIterator it = bat.GetStripIterator (m_simulation);
it.ForEachSegment (
boost::bind (&DisplayBubblePath::valueStep, this, _1, _2, _3, _4),
m_timeBegin, m_timeEnd);
displaySegments ();
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
valueStep (
const StripIteratorPoint& beforeBegin,
const StripIteratorPoint& begin,
const StripIteratorPoint& end,
const StripIteratorPoint& afterEnd)
{
static_cast<void>(beforeBegin);
static_cast<void>(afterEnd);
G3D::Vector3 pointBegin = getPoint (begin);
G3D::Vector3 pointEnd = getPoint (end);
G3D::Vector3 middle = (pointBegin + pointEnd) / 2;
ViewSettings& vs = this->m_settings.GetViewSettings (
this->GetViewNumber ());
halfValueStep (
begin,
Segment (
beforeBegin.IsEmpty () ? SegmentPerpendicularEnd::BEGIN_END_SEGMENT :
SegmentPerpendicularEnd::END_SEGMENT,
getPoint (beforeBegin), pointBegin, middle, G3D::Vector3 (),
vs.IsContextDisplayBody (begin.m_body->GetId ())));
halfValueStep (
end,
Segment (
afterEnd.IsEmpty () ? SegmentPerpendicularEnd::BEGIN_END_SEGMENT :
SegmentPerpendicularEnd::BEGIN_SEGMENT,
G3D::Vector3 (), middle, pointEnd, getPoint (afterEnd),
vs.IsContextDisplayBody (end.m_body->GetId ())));
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
halfValueStep (const StripIteratorPoint& p, const Segment& segment)
{
ViewNumber::Enum viewNumber = this->GetViewNumber ();
ViewSettings& vs = this->m_settings.GetViewSettings (viewNumber);
bool focus = this->IsFocus (p.m_body);
if (focus)
{
BodyScalar::Enum property = BodyScalar::FromSizeT (
this->m_propertySetter.GetBodyOrOtherScalar ());
bool deduced;
bool exists = p.m_body->HasScalarValue (property, &deduced);
if (exists &&
(! deduced ||
(deduced && this->m_settings.IsMissingPropertyShown (property))))
storeFocusSegment (
p.m_body->GetScalarValue (
property), segment);
else
storeFocusSegment (
this->m_settings.GetHighlightColor (
this->GetViewNumber (),
HighlightNumber::H0), segment);
}
else
storeContextSegment (vs.GetBubblePathsContextColor (), segment);
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
displaySegments ()
{
ViewSettings& vs = this->m_settings.GetViewSettings (
this->GetViewNumber ());
// focus segments
size_t focusSegmentsSize =
m_focusTextureSegments.size () + m_focusColorSegments.size();
for_each (
m_focusTextureSegments.begin (), m_focusTextureSegments.end (),
boost::bind (&DisplayBubblePath<PropertySetter, DisplaySegment>::
displayFocusTextureSegment, this, _1));
if (m_focusColorSegments.size () > 0)
{
glDisable (GL_TEXTURE_1D);
for_each (
m_focusColorSegments.begin (), m_focusColorSegments.end (),
boost::bind (&DisplayBubblePath<PropertySetter, DisplaySegment>::
displayFocusColorSegment, this, _1));
glEnable (GL_TEXTURE_1D);
}
// context segments
if (m_contextSegments.size () > 0 &&
((focusSegmentsSize == 0 && vs.IsSelectionContextShown ()) ||
(focusSegmentsSize != 0 && ! vs.IsPartialPathHidden ())))
{
glDisable (GL_TEXTURE_1D);
DisplayBodyBase<>::BeginContext ();
for_each (
m_contextSegments.begin (), m_contextSegments.end (),
boost::bind (&DisplayBubblePath<PropertySetter, DisplaySegment>::
displayContextSegment, this, _1));
DisplayBodyBase<>::EndContext ();
glEnable (GL_TEXTURE_1D);
}
}
template<typename PropertySetter, typename DisplaySegment>
G3D::Vector3 DisplayBubblePath<PropertySetter, DisplaySegment>::
getPoint (StripIteratorPoint p) const
{
if (this->m_useZPos)
{
G3D::Vector3 v = p.m_point;
v.z = p.m_timeStep * this->m_zPos;
return v;
}
else
return p.m_point;
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
storeFocusSegment (double value, const Segment& segment)
{
double textureCoordinate =
this->m_settings.GetViewSettings (
this->GetViewNumber ()).GetColorMapScalar ()
->TexCoord (value);
boost::shared_ptr<FocusTextureSegment> fs =
boost::make_shared<FocusTextureSegment> (textureCoordinate, segment);
m_focusTextureSegments.push_back (fs);
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
storeFocusSegment (const QColor& color, const Segment& segment)
{
boost::shared_ptr<FocusColorSegment> fs =
boost::make_shared<FocusColorSegment> (color, segment);
m_focusColorSegments.push_back (fs);
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
storeContextSegment (
const QColor& color, const Segment& segment)
{
boost::shared_ptr<ContextSegment> cs = boost::make_shared<ContextSegment> (
color, segment);
m_contextSegments.push_back (cs);
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
displayContextSegment (
const boost::shared_ptr<ContextSegment>& contextSegment)
{
glColor (contextSegment->m_color);
m_displaySegment (*contextSegment);
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
displayFocusTextureSegment (
const boost::shared_ptr<FocusTextureSegment>& segment)
{
glColor (Qt::white);
glTexCoord1f (segment->m_textureCoordinate);
m_displaySegment (*segment);
}
template<typename PropertySetter, typename DisplaySegment>
void DisplayBubblePath<PropertySetter, DisplaySegment>::
displayFocusColorSegment (const boost::shared_ptr<FocusColorSegment>& segment)
{
glColor (segment->m_color);
m_displaySegment (*segment);
}
// Template instantiations
// ======================================================================
// DisplayBodyBase
// ======================================================================
template class DisplayBodyBase<SetterVertexAttribute>;
template class DisplayBodyBase<SetterTextureCoordinate>;
template class DisplayBodyBase<SetterDeformation>;
template class DisplayBodyBase<SetterNop>;
template class DisplayBodyBase<SetterVelocity>;
// DisplayBody
// ======================================================================
template class DisplayBody<
DisplayFaceHighlightColor<(HighlightNumber::Enum)0,
DisplayFaceEdges<
DisplayEdgePropertyColor<(DisplayElement::TessellationEdgesDisplay)0> >, SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<
DisplayFaceHighlightColor<(HighlightNumber::Enum)0,
DisplayFaceEdges<
DisplayEdgePropertyColor<(DisplayElement::TessellationEdgesDisplay)1> >, SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<
DisplayFaceHighlightColor<(HighlightNumber::Enum)0,
DisplayFaceEdges<
DisplayEdge>, SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<
DisplayFaceHighlightColor<HighlightNumber::H0, DisplayFaceLineStrip, SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<
DisplayFaceHighlightColor<HighlightNumber::H0, DisplayFaceTriangleFan, SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<
DisplayFaceBodyScalarColor<SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<DisplayFaceBodyScalarColor<SetterVelocity>, SetterVelocity>;
template class DisplayBody<
DisplayFaceBodyScalarColor<SetterVertexAttribute>,
SetterVertexAttribute>;
template class DisplayBody<DisplayFaceBodyScalarColor<SetterNop>, SetterNop>;
template class DisplayBody<DisplayFaceHighlightColor<HighlightNumber::H1, DisplayFaceLineStrip, SetterTextureCoordinate>, SetterTextureCoordinate>;
template class DisplayBody<DisplayFaceBodyScalarColor<SetterDeformation>, SetterDeformation>;
// DisplayBubblePath
// ======================================================================
template class DisplayBubblePath<SetterTextureCoordinate, DisplaySegmentTube>;
template class DisplayBubblePath<SetterTextureCoordinate,
DisplaySegmentQuadric>;
template class DisplayBubblePath<SetterTextureCoordinate, DisplaySegmentLine>;