-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayEdgeFunctors.cpp
570 lines (492 loc) · 16.7 KB
/
DisplayEdgeFunctors.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
/**
* @file DisplayEdgeFunctors.h
* @author Dan R. Lipsa
* @date 25 Oct. 2010
*
* Implementation for functors that display an edge
*/
#include "Debug.h"
#include "Disk.h"
#include "DisplayEdgeFunctors.h"
#include "Edge.h"
#include "Face.h"
#include "Foam.h"
#include "Settings.h"
#include "OrientedEdge.h"
#include "OrientedFace.h"
#include "OpenGLUtils.h"
#include "Utils.h"
#include "Vertex.h"
#include "ViewSettings.h"
void DisplayEdgeVertices (const Edge& edge, bool useZPos, double zPos)
{
for (size_t i = 0; i < edge.GetPointCount (); ++i)
{
G3D::Vector3 p = edge.GetPoint (i);
if (useZPos)
p = G3D::Vector3 (p.xy (), zPos);
::glVertex (p);
}
}
void DisplayEdgeVerticesNoEnds (const Edge& edge)
{
for (size_t i = 1; i < edge.GetPointCount () - 1; ++i)
::glVertex (edge.GetPoint (i));
}
void perpendicularEnd (const G3D::Vector3& normal,
G3D::Vector3* twelveOclock, G3D::Vector3* threeOclock)
{
G3D::Plane plane (normal, G3D::Vector3::zero ());
*twelveOclock = plane.closestPoint (G3D::Vector3::unitX ()).unit ();
*threeOclock = twelveOclock->cross (normal);
}
void perpendicularEnd (const G3D::Vector3& begin, const G3D::Vector3& end,
G3D::Vector3* twelveOclock, G3D::Vector3* threeOclock)
{
G3D::Vector3 normal = (end - begin).unit ();
perpendicularEnd (normal, twelveOclock, threeOclock);
}
void angledEnd (const G3D::Vector3& before,
const G3D::Vector3& p,
const G3D::Vector3& after,
G3D::Vector3* twelveOclock, G3D::Vector3* threeOclock)
{
G3D::Vector3 firstNormal = (p - before).unit ();
G3D::Vector3 secondNormal = (after - p).unit ();
G3D::Vector3 normal = (firstNormal + secondNormal).unit ();
perpendicularEnd (normal, twelveOclock, threeOclock);
}
// DisplayVtkArrow
// ======================================================================
void DisplaySegmentArrow2D (G3D::Vector2 where, G3D::Vector2 v,
float lineWidth,
float onePixelInObjectSpace, bool clamped)
{
const float arrowDegrees = 15.0;
const float arrowLengthInPixels = 10;
G3D::Vector2 center = where + v / 2;
float arrowLength = min (
v.length (), arrowLengthInPixels * onePixelInObjectSpace);
G3D::Vector2 arrow = v.direction () * arrowLength;
glPushMatrix ();
glLineWidth (lineWidth);
glTranslate (center);
glBegin (GL_LINES);
::glVertex (- v / 2);
::glVertex (v / 2);
glEnd ();
glTranslate (v / 2);
glBegin (GL_TRIANGLES);
::glVertex (- rotateDegrees (arrow, arrowDegrees));
::glVertex (G3D::Vector2::zero ());
::glVertex (- rotateDegrees (arrow, -arrowDegrees));
glEnd ();
if (clamped)
{
glTranslate (- v / 2);
arrow = G3D::Vector2 (- arrow.y, arrow.x) /2;
glBegin (GL_LINES);
::glVertex (- arrow);
::glVertex (arrow);
glEnd ();
}
glPopMatrix ();
glLineWidth (1.0);
}
// DisplayVtkArrow
// ======================================================================
void DisplayVtkArrow (GLUquadricObj* quadric)
{
DisplayArrowQuadric (quadric, 0.1, 0.03, 0.35)
(G3D::Vector3::zero (), G3D::Vector3 (1.0, 0, 0));
}
void DisplayVtkArrow ()
{
boost::array<G3D::Vector2, 4> shaft = {{
G3D::Vector2 (0, -0.03),
G3D::Vector2 (0, 0.03),
G3D::Vector2 (0.65, 0.03),
G3D::Vector2 (0.65, -0.03),
}};
boost::array<G3D::Vector2, 3> head = {{
G3D::Vector2 (0.65, 0.1),
G3D::Vector2 (1.0, 0.0),
G3D::Vector2 (0.65, -0.1),
}};
glBegin (GL_QUADS);
BOOST_FOREACH (G3D::Vector2 point, shaft)
::glVertex (point);
glEnd ();
glBegin (GL_TRIANGLES);
BOOST_FOREACH (G3D::Vector2 point, head)
::glVertex (point);
glEnd ();
}
void DisplayVtkArrow (
G3D::Vector3 where, G3D::Vector3 v, GLUquadricObj* quadric)
{
G3D::Matrix3 rot = GetAxisRotation (v, G3D::Vector3::X_AXIS);
glPushMatrix ();
glTranslate (where);
glMultMatrix (rot);
glPushMatrix ();
glScale (v.length ());
if (quadric)
DisplayVtkArrow (quadric);
else
DisplayVtkArrow ();
glPopMatrix ();
glPopMatrix ();
}
// DisplaySegmentLine
// ======================================================================
void DisplaySegmentLine::operator() (
const G3D::Vector3& begin, const G3D::Vector3& end, bool context)
{
glLineWidth (context ? m_contextRadius : m_radius);
glBegin(GL_LINES);
::glVertex(begin);
::glVertex(end);
glEnd();
glLineWidth (1.0);
}
// DisplaySegmentQuadric
// ======================================================================
void DisplaySegmentQuadric::operator() (
const G3D::Vector3& begin, const G3D::Vector3& end)
{
G3D::Matrix3 rotation = GetAxisRotation (begin, end, G3D::Vector3::Z_AXIS);
G3D::CoordinateFrame frame (rotation, begin);
glPushMatrix ();
glMultMatrix (frame);
gluCylinder (
m_quadric, m_radius, m_radius, (end - begin).length (),
Settings::QUADRIC_SLICES, Settings::QUADRIC_STACKS);
glPopMatrix ();
}
// DisplaySegmentTube
// ======================================================================
Disk DisplaySegmentTube::perpendicularDisk (
const G3D::Vector3& beginEdge, const G3D::Vector3& endEdge,
const G3D::Vector3& origin) const
{
G3D::Vector3 twelveOclock, threeOclock;
perpendicularEnd (beginEdge, endEdge, &twelveOclock, &threeOclock);
return Disk (origin, twelveOclock, threeOclock, m_radius);
}
Disk DisplaySegmentTube::angledDisk (
const G3D::Vector3& beforeP, const G3D::Vector3& p,
const G3D::Vector3& afterP,
const G3D::Vector3& origin) const
{
G3D::Vector3 twelveOclock, threeOclock;
angledEnd (beforeP, p, afterP, &twelveOclock, &threeOclock);
return Disk (origin, twelveOclock, threeOclock, m_radius);
}
void DisplaySegmentTube::operator() (const Segment& segment)
{
Disk beginDisk, endDisk;
switch (segment.m_perpendicularEnd)
{
case SegmentPerpendicularEnd::BEGIN_SEGMENT:
{
beginDisk = perpendicularDisk (segment.m_begin, segment.m_end,
segment.m_begin);
endDisk = angledDisk (segment.m_begin, segment.m_end,
segment.m_afterEnd, segment.m_end);
break;
}
case SegmentPerpendicularEnd::END_SEGMENT:
{
beginDisk = angledDisk (segment.m_beforeBegin, segment.m_begin,
segment.m_end, segment.m_begin);
endDisk = perpendicularDisk (segment.m_begin, segment.m_end,
segment.m_end);
break;
}
case SegmentPerpendicularEnd::BEGIN_END_SEGMENT:
{
beginDisk = perpendicularDisk (segment.m_begin, segment.m_end,
segment.m_begin);
endDisk = perpendicularDisk (segment.m_begin, segment.m_end,
segment.m_end);
break;
}
case SegmentPerpendicularEnd::NONE:
{
beginDisk = angledDisk (
segment.m_beforeBegin, segment.m_begin, segment.m_end,
segment.m_begin);
endDisk = angledDisk (
segment.m_begin, segment.m_end, segment.m_afterEnd, segment.m_end);
break;
}
default:
ThrowException ("Invalid SegmentPerpendicularEnd::Enum: ",
segment.m_perpendicularEnd);
}
displayTube (beginDisk, endDisk);
}
void displayNormal (const Disk& disk, size_t i)
{
DisplayOrientedSegmentLine () (
disk.GetCenter (),
disk.GetCenter () + disk.GetVertexNormal (i) * disk.GetRadius () *
(1 + 2*static_cast<double>((i + 1)) / disk.size ()));
}
void DisplaySegmentTube::displayTube (const Disk& begin, const Disk& end) const
{
glBegin (GL_QUAD_STRIP);
for (size_t i = 0; i < begin.size (); ++i)
{
glNormal (begin.GetVertexNormal (i));
::glVertex (begin.GetVertex (i));
glNormal (end.GetVertexNormal (i));
::glVertex (end.GetVertex (i));
}
glNormal (begin.GetVertexNormal (0));
::glVertex (begin.GetVertex (0));
glNormal (end.GetVertexNormal (0));
::glVertex (end.GetVertex (0));
glEnd ();
}
// DisplayThickFirstHalf
// ======================================================================
DisplayThickFirstHalf::DisplayThickFirstHalf (
GLUquadricObj* quadric,
double arrowHeadRadius, double shaftRadius, double arrowHeadHeight,
ArrowHeadPosition position) :
m_quadric (quadric),
m_arrowHeadRadius (arrowHeadRadius),
m_arrowHeadHeight (arrowHeadHeight),
m_shaftRadius(shaftRadius),
m_position (position)
{
}
void DisplayThickFirstHalf::operator () (
const G3D::Vector3& begin, const G3D::Vector3& end)
{
glLineWidth (3.0);
glBegin(GL_LINES);
::glVertex(begin);
::glVertex((begin + end) / 2);
glEnd();
glLineWidth (1.0);
}
// DisplayArrowHeadQuadric
// ======================================================================
DisplayArrowHeadQuadric::DisplayArrowHeadQuadric (
GLUquadricObj* quadric,
double arrowHeadRadius, double shaftRadius, double arrowHeadHeight,
ArrowHeadPosition position) :
DisplayThickFirstHalf (
quadric, arrowHeadRadius, shaftRadius, arrowHeadHeight, position)
{
}
G3D::Vector3 DisplayArrowHeadQuadric::GetBasePosition (
const G3D::Vector3& begin, const G3D::Vector3& end)
{
return ((m_position == BASE_MIDDLE) ?
(begin + end) / 2 :
(end - (end - begin).direction () * m_arrowHeadHeight));
}
void DisplayArrowHeadQuadric::operator () (
const G3D::Vector3& begin, const G3D::Vector3& end)
{
G3D::Vector3 translation = GetBasePosition (begin, end);
G3D::Matrix3 rotation = GetAxisRotation (begin, end, G3D::Vector3::Z_AXIS);
G3D::CoordinateFrame objectToWorld (rotation, translation);
glPushMatrix ();
{
glMultMatrix (objectToWorld);
gluCylinder (
m_quadric,
m_arrowHeadRadius,
m_position == BASE_MIDDLE ? m_shaftRadius : 0,
m_arrowHeadHeight,
Settings::QUADRIC_SLICES, Settings::QUADRIC_STACKS);
gluQuadricOrientation (m_quadric, GLU_INSIDE);
gluDisk (m_quadric, 0, m_arrowHeadRadius, Settings::QUADRIC_SLICES,
Settings::QUADRIC_STACKS);
gluQuadricOrientation (m_quadric, GLU_OUTSIDE);
}
glPopMatrix ();
}
// DisplayArrowQuadric
// ======================================================================
DisplayArrowQuadric::DisplayArrowQuadric (
GLUquadricObj* quadric,
double arrowHeadRadius, double shaftRadius, double arrowHeadHeight,
ArrowHeadPosition position) :
DisplayThickFirstHalf (
quadric, arrowHeadRadius, shaftRadius, arrowHeadHeight, position)
{
}
void DisplayArrowQuadric::operator () (
const G3D::Vector3& begin, const G3D::Vector3& end)
{
DisplaySegmentQuadric displayEdge (m_quadric, m_shaftRadius);
DisplayArrowHeadQuadric displayArrowHead (
m_quadric, m_arrowHeadRadius,
m_shaftRadius, m_arrowHeadHeight, m_position);
displayEdge (begin, m_position == BASE_MIDDLE ? end :
displayArrowHead.GetBasePosition (begin, end));
displayArrowHead (begin, end);
}
// DisplayOrientedSegmentLine
// ======================================================================
void DisplayOrientedSegmentLine::operator () (
const G3D::Vector3& begin, const G3D::Vector3& end)
{
DisplaySegmentLine displayEdge (m_quadric, m_shaftRadius);
DisplayThickFirstHalf displayThickHalf (
m_quadric, m_arrowHeadRadius, m_shaftRadius, m_arrowHeadHeight,
m_position);
displayEdge (begin, end);
displayThickHalf (begin, end);
}
// DisplayEdgeTorus
// ======================================================================
template <typename DisplayEdge, typename DisplayThickFirstHalf,
bool showDuplicates>
DisplayEdgeTorus<DisplayEdge, DisplayThickFirstHalf, showDuplicates>::
DisplayEdgeTorus (
const Settings& settings, ViewNumber::Enum viewNumber, bool is2D,
FocusContext focus, bool useZPos, double zPos,
GLUquadricObj* quadric) :
DisplayElementFocus (settings, viewNumber, is2D, focus, useZPos, zPos),
m_displayEdge (
quadric, GetViewSettings ().GetEdgeRadius ()),
m_displayArrow (quadric,
GetViewSettings ().GetArrowHeadRadius (),
GetViewSettings ().GetEdgeRadius (),
GetViewSettings ().GetArrowHeadHeight ())
{
}
template <typename DisplayEdge, typename DisplayThickFirstHalf,
bool showDuplicates>
void DisplayEdgeTorus<DisplayEdge, DisplayThickFirstHalf, showDuplicates>::
operator () (const OrientedEdge& oe)
{
operator () (oe.GetEdge ());
}
template <typename DisplayEdge, typename DisplayThickFirstHalf,
bool showDuplicates>
void DisplayEdgeTorus<DisplayEdge, DisplayThickFirstHalf, showDuplicates>::
operator() (const boost::shared_ptr<OrientedEdge> oe)
{
operator() (oe->GetEdge());
}
template <typename DisplayEdge, typename DisplayThickFirstHalf,
bool showDuplicates>
void DisplayEdgeTorus<DisplayEdge, DisplayThickFirstHalf, showDuplicates>::
operator() (const boost::shared_ptr<Edge> e)
{
if (showDuplicates
|| e->GetDuplicateStatus () != ElementStatus::DUPLICATE)
display (e);
}
template <typename DisplayEdge, typename DisplayThickFirstHalf,
bool showDuplicates>
void DisplayEdgeTorus<DisplayEdge, DisplayThickFirstHalf, showDuplicates>::
display (const boost::shared_ptr<Edge> e)
{
glPushAttrib (GL_CURRENT_BIT);
const Vertex& begin = e->GetBegin ();
const Vertex& end = e->GetEnd ();
G3D::Vector3int16 endLocation = e->GetEndTranslation ();
glColor (m_settings.GetEndTranslationColor (endLocation));
if (endLocation != Vector3int16Zero)
m_displayArrow(begin.GetVector (), end.GetVector ());
m_displayEdge(begin.GetVector (), end.GetVector ());
glPopAttrib ();
}
// DisplayEdgePropertyColor
// ======================================================================
template <DisplayElement::TessellationEdgesDisplay tesselationEdgesDisplay>
DisplayEdgePropertyColor<tesselationEdgesDisplay>::
DisplayEdgePropertyColor (
const Settings& settings, ViewNumber::Enum viewNumber, bool is2D,
FocusContext focus, bool useZPos, double zPos) :
DisplayElementFocus (settings, viewNumber, is2D, focus, useZPos, zPos)
{
}
template <DisplayElement::TessellationEdgesDisplay tesselationEdgesDisplay>
void DisplayEdgePropertyColor<tesselationEdgesDisplay>::
operator () (const boost::shared_ptr<Edge> edge) const
{
operator () (*edge);
}
template <DisplayElement::TessellationEdgesDisplay tesselationEdgesDisplay>
void DisplayEdgePropertyColor<tesselationEdgesDisplay>::
operator () (const Edge& edge) const
{
ViewSettings& vs = this->m_settings.GetViewSettings (m_viewNumber);
bool isPhysical = edge.IsPhysical (m_is2D);
if (isPhysical ||
(tesselationEdgesDisplay == DISPLAY_TESSELLATION_EDGES &&
m_settings.EdgesTessellationShown () &&
m_focus == FOCUS))
{
bool hasConstraints = edge.HasConstraints ();
if (hasConstraints && ! m_settings.ConstraintsShown ())
return;
double alpha =
(m_focus == FOCUS ? 1.0 : vs.GetContextAlpha ());
QColor color = edge.GetColor (Qt::black);
glColor (
QColor::fromRgbF(
color.redF (), color.greenF (), color.blueF (), alpha));
glBegin(GL_LINE_STRIP);
DisplayEdgeVertices (edge, m_useZPos, m_zPos);
glEnd ();
if (hasConstraints && m_settings.ConstraintPointsShown ())
{
glPointSize (5);
glBegin(GL_POINTS);
DisplayEdgeVerticesNoEnds (edge);
glEnd ();
}
}
}
template <DisplayElement::TessellationEdgesDisplay tesselationEdgesDisplay>
void DisplayEdgePropertyColor<tesselationEdgesDisplay>::
operator() (const boost::shared_ptr<OrientedEdge> oe) const
{
operator () (oe->GetEdge ());
}
// DisplayEdge
// ======================================================================
DisplayEdge::DisplayEdge (
const Settings& settings, ViewNumber::Enum viewNumber, bool is2D,
FocusContext focus,
bool useZPos, double zPos) :
DisplayElementFocus (settings, viewNumber, is2D, focus, useZPos, zPos)
{
}
void DisplayEdge::operator () (const boost::shared_ptr<Edge> edge) const
{
operator () (*edge);
}
void DisplayEdge::operator () (const Edge& edge) const
{
glBegin(GL_LINE_STRIP);
DisplayEdgeVertices (edge, m_useZPos, m_zPos);
glEnd ();
}
void DisplayEdge::operator() (const boost::shared_ptr<OrientedEdge> oe) const
{
operator () (oe->GetEdge ());
}
// Template instantiations
// ======================================================================
// DisplayEdgeTorus
// ======================================================================
template class DisplayEdgeTorus<DisplaySegmentQuadric, DisplayArrowHeadQuadric, false>;
template class DisplayEdgeTorus<DisplaySegmentQuadric, DisplayArrowHeadQuadric, true>;
template class DisplayEdgeTorus<DisplaySegmentLine, DisplayThickFirstHalf, false>;
template class DisplayEdgeTorus<DisplaySegmentLine, DisplayThickFirstHalf, true>;
// DisplayEdgePropertyColor
// ======================================================================
template class DisplayEdgePropertyColor <DisplayElement::DISPLAY_TESSELLATION_EDGES>;
template class DisplayEdgePropertyColor <DisplayElement::DONT_DISPLAY_TESSELLATION_EDGES>;