-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathV_QuadMetric.cpp
1564 lines (1276 loc) · 42.4 KB
/
V_QuadMetric.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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Module: V_QuadMetric.cpp
Copyright 2003,2006,2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
Under the terms of Contract DE-NA0003525 with NTESS,
the U.S. Government retains certain rights in this software.
See LICENSE for details.
=========================================================================*/
/*
*
* QuadMetric.cpp contains quality calculations for Quads
*
* This file is part of VERDICT
*
*/
#include "V_GaussIntegration.hpp"
#include "VerdictVector.hpp"
#include "verdict.h"
#include "verdict_defines.hpp"
namespace VERDICT_NAMESPACE
{
static constexpr double radius_ratio_normal_coeff = 1. / (2. * sqrt2);
/*!
weights based on the average size of a quad
*/
VERDICT_HOST_DEVICE static int quad_get_weight(
double& m11, double& m21, double& m12, double& m22, double average_quad_size)
{
m11 = 1;
m21 = 0;
m12 = 0;
m22 = 1;
double scale = sqrt(average_quad_size / (m11 * m22 - m21 * m12));
m11 *= scale;
m21 *= scale;
m12 *= scale;
m22 *= scale;
return 1;
}
//! returns whether the quad is collapsed or not
VERDICT_HOST_DEVICE static VerdictBoolean is_collapsed_quad(const double coordinates[][3])
{
if (coordinates[3][0] == coordinates[2][0] && coordinates[3][1] == coordinates[2][1] &&
coordinates[3][2] == coordinates[2][2])
{
return VERDICT_TRUE;
}
else
{
return VERDICT_FALSE;
}
}
VERDICT_HOST_DEVICE static void make_quad_edges(VerdictVector edges[4], const double coordinates[][3])
{
edges[0].set(coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
coordinates[1][2] - coordinates[0][2]);
edges[1].set(coordinates[2][0] - coordinates[1][0], coordinates[2][1] - coordinates[1][1],
coordinates[2][2] - coordinates[1][2]);
edges[2].set(coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
coordinates[3][2] - coordinates[2][2]);
edges[3].set(coordinates[0][0] - coordinates[3][0], coordinates[0][1] - coordinates[3][1],
coordinates[0][2] - coordinates[3][2]);
}
VERDICT_HOST_DEVICE static void signed_corner_areas(double areas[4], const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
VerdictVector corner_normals[4];
corner_normals[0] = edges[3] * edges[0];
corner_normals[1] = edges[0] * edges[1];
corner_normals[2] = edges[1] * edges[2];
corner_normals[3] = edges[2] * edges[3];
// principal axes
VerdictVector principal_axes[2];
principal_axes[0] = edges[0] - edges[2];
principal_axes[1] = edges[1] - edges[3];
// quad center unit normal
VerdictVector unit_center_normal;
unit_center_normal = principal_axes[0] * principal_axes[1];
unit_center_normal.normalize();
areas[0] = unit_center_normal % corner_normals[0];
areas[1] = unit_center_normal % corner_normals[1];
areas[2] = unit_center_normal % corner_normals[2];
areas[3] = unit_center_normal % corner_normals[3];
}
#if 0 /* Not currently used and not exposed in verdict.h */
/*!
localize the coordinates of a quad
localizing puts the centriod of the quad
at the orgin and also rotates the quad
such that edge (0,1) is aligned with the x axis
and the quad normal lines up with the y axis.
*/
static void localize_quad_coordinates(VerdictVector nodes[4])
{
int i;
VerdictVector global[4] = { nodes[0], nodes[1], nodes[2], nodes[3] };
VerdictVector center = (global[0] + global[1] + global[2] + global[3]) / 4.0;
for(i=0; i<4; i++)
{
global[i] -= center;
}
VerdictVector vector_diff;
VerdictVector vector_sum;
VerdictVector ref_point(0.0,0.0,0.0);
VerdictVector tmp_vector, normal(0.0,0.0,0.0);
VerdictVector vector1, vector2;
for(i=0; i<4; i++)
{
vector1 = global[i];
vector2 = global[(i+1)%4];
vector_diff = vector2 - vector1;
ref_point += vector1;
vector_sum = vector1 + vector2;
tmp_vector.set(vector_diff.y() * vector_sum.z(),
vector_diff.z() * vector_sum.x(),
vector_diff.x() * vector_sum.y());
normal += tmp_vector;
}
normal.normalize();
normal *= -1.0;
VerdictVector local_x_axis = global[1] - global[0];
local_x_axis.normalize();
VerdictVector local_y_axis = normal * local_x_axis;
local_y_axis.normalize();
for (i=0; i < 4; i++)
{
nodes[i].x(global[i] % local_x_axis);
nodes[i].y(global[i] % local_y_axis);
nodes[i].z(global[i] % normal);
}
}
/*!
moves and rotates the quad such that it enables us to
use components of ef's
*/
static void localize_quad_for_ef( VerdictVector node_pos[4] )
{
VerdictVector centroid(node_pos[0]);
centroid += node_pos[1];
centroid += node_pos[2];
centroid += node_pos[3];
centroid /= 4.0;
node_pos[0] -= centroid;
node_pos[1] -= centroid;
node_pos[2] -= centroid;
node_pos[3] -= centroid;
VerdictVector rotate = node_pos[1] + node_pos[2] - node_pos[3] - node_pos[0];
rotate.normalize();
double cosine = rotate.x();
double sine = rotate.y();
double xnew;
for (int i=0; i < 4; i++)
{
xnew = cosine * node_pos[i].x() + sine * node_pos[i].y();
node_pos[i].y( -sine * node_pos[i].x() + cosine * node_pos[i].y() );
node_pos[i].x(xnew);
}
}
#endif /* Not currently used and not exposed in verdict.h */
/*!
returns the normal vector of a quad
*/
VERDICT_HOST_DEVICE static VerdictVector quad_normal(const double coordinates[][3])
{
// get normal at node 0
VerdictVector edge0, edge1;
edge0.set(coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
coordinates[1][2] - coordinates[0][2]);
edge1.set(coordinates[3][0] - coordinates[0][0], coordinates[3][1] - coordinates[0][1],
coordinates[3][2] - coordinates[0][2]);
VerdictVector norm0 = edge0 * edge1;
norm0.normalize();
// because some faces may have obtuse angles, check another normal at
// node 2 for consistent sense
edge0.set(coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
coordinates[3][2] - coordinates[2][2]);
edge1.set(coordinates[1][0] - coordinates[2][0], coordinates[1][1] - coordinates[2][1],
coordinates[1][2] - coordinates[2][2]);
VerdictVector norm2 = edge0 * edge1;
norm2.normalize();
// if these two agree, we are done, else test a third to decide
if ((norm0 % norm2) > 0.0)
{
norm0 += norm2;
norm0 *= 0.5;
return norm0;
}
// test normal at node1
edge0.set(coordinates[2][0] - coordinates[1][0], coordinates[2][1] - coordinates[1][1],
coordinates[2][2] - coordinates[1][2]);
edge1.set(coordinates[0][0] - coordinates[1][0], coordinates[0][1] - coordinates[1][1],
coordinates[0][2] - coordinates[1][2]);
VerdictVector norm1 = edge0 * edge1;
norm1.normalize();
if ((norm0 % norm1) > 0.0)
{
norm0 += norm1;
norm0 *= 0.5;
return norm0;
}
else
{
norm2 += norm1;
norm2 *= 0.5;
return norm2;
}
}
VERDICT_HOST_DEVICE void quad_minimum_maximum_angle(double min_max_angles[2], const double coordinates[][3])
{
// if this is a collapsed quad, just pass it on to
// the tri_largest_angle routine
if (is_collapsed_quad(coordinates) == VERDICT_TRUE)
{
min_max_angles[0] = tri_minimum_angle(3, coordinates);
min_max_angles[1] = tri_maximum_angle(3, coordinates);
return;
}
double angle;
double max_angle = 0.0;
double min_angle = 360.0;
VerdictVector edges[4];
edges[0].set(coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
coordinates[1][2] - coordinates[0][2]);
edges[1].set(coordinates[2][0] - coordinates[1][0], coordinates[2][1] - coordinates[1][1],
coordinates[2][2] - coordinates[1][2]);
edges[2].set(coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
coordinates[3][2] - coordinates[2][2]);
edges[3].set(coordinates[0][0] - coordinates[3][0], coordinates[0][1] - coordinates[3][1],
coordinates[0][2] - coordinates[3][2]);
// go around each node and calculate the angle
// at each node
double length[4];
length[0] = edges[0].length();
length[1] = edges[1].length();
length[2] = edges[2].length();
length[3] = edges[3].length();
if (length[0] <= VERDICT_DBL_MIN || length[1] <= VERDICT_DBL_MIN ||
length[2] <= VERDICT_DBL_MIN || length[3] <= VERDICT_DBL_MIN)
{
min_max_angles[0] = 360.0;
min_max_angles[1] = 0.0;
return;
}
angle = acos(-(edges[0] % edges[1]) / (length[0] * length[1]));
min_angle = fmin(angle, min_angle);
max_angle = fmax(angle, max_angle);
angle = acos(-(edges[1] % edges[2]) / (length[1] * length[2]));
min_angle = fmin(angle, min_angle);
max_angle = fmax(angle, max_angle);
angle = acos(-(edges[2] % edges[3]) / (length[2] * length[3]));
min_angle = fmin(angle, min_angle);
max_angle = fmax(angle, max_angle);
angle = acos(-(edges[3] % edges[0]) / (length[3] * length[0]));
min_angle = fmin(angle, min_angle);
max_angle = fmax(angle, max_angle);
max_angle = max_angle * 180.0 / VERDICT_PI;
min_angle = min_angle * 180.0 / VERDICT_PI;
if (min_angle > 0)
{
min_max_angles[0] = (double)fmin(min_angle, VERDICT_DBL_MAX);
}
min_max_angles[0] = (double)fmax(min_angle, -VERDICT_DBL_MAX);
// if any signed areas are < 0, then you are getting the wrong angle
double areas[4];
signed_corner_areas(areas, coordinates);
if (areas[0] < 0 || areas[1] < 0 || areas[2] < 0 || areas[3] < 0)
{
max_angle = 360 - max_angle;
}
if (max_angle > 0)
{
min_max_angles[1] = (double)fmin(max_angle, VERDICT_DBL_MAX);
}
min_max_angles[1] = (double)fmax(max_angle, -VERDICT_DBL_MAX);
}
/*!
the edge ratio of a quad
NB (P. Pebay 01/19/07):
Hmax / Hmin where Hmax and Hmin are respectively the maximum and the
minimum edge lengths
*/
VERDICT_HOST_DEVICE double quad_edge_ratio(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
double a2 = edges[0].length_squared();
double b2 = edges[1].length_squared();
double c2 = edges[2].length_squared();
double d2 = edges[3].length_squared();
double mab, Mab, mcd, Mcd, m2, M2;
if (a2 < b2)
{
mab = a2;
Mab = b2;
}
else // b2 <= a2
{
mab = b2;
Mab = a2;
}
if (c2 < d2)
{
mcd = c2;
Mcd = d2;
}
else // d2 <= c2
{
mcd = d2;
Mcd = c2;
}
m2 = mab < mcd ? mab : mcd;
M2 = Mab > Mcd ? Mab : Mcd;
if (m2 < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MAX;
}
else
{
double edge_ratio = sqrt(M2 / m2);
if (edge_ratio > 0)
{
return (double)fmin(edge_ratio, VERDICT_DBL_MAX);
}
return (double)fmax(edge_ratio, -VERDICT_DBL_MAX);
}
}
/*!
maximum of edge ratio of a quad
maximum edge length ratio at quad center
*/
VERDICT_HOST_DEVICE double quad_max_edge_ratio(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector quad_nodes[4];
quad_nodes[0].set(coordinates[0][0], coordinates[0][1], coordinates[0][2]);
quad_nodes[1].set(coordinates[1][0], coordinates[1][1], coordinates[1][2]);
quad_nodes[2].set(coordinates[2][0], coordinates[2][1], coordinates[2][2]);
quad_nodes[3].set(coordinates[3][0], coordinates[3][1], coordinates[3][2]);
VerdictVector principal_axes[2];
principal_axes[0] = quad_nodes[1] + quad_nodes[2] - quad_nodes[0] - quad_nodes[3];
principal_axes[1] = quad_nodes[2] + quad_nodes[3] - quad_nodes[0] - quad_nodes[1];
double len1 = principal_axes[0].length();
double len2 = principal_axes[1].length();
if (len1 < VERDICT_DBL_MIN || len2 < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MAX;
}
double max_edge_ratio = fmax(len1 / len2, len2 / len1);
if (max_edge_ratio > 0)
{
return (double)fmin(max_edge_ratio, VERDICT_DBL_MAX);
}
return (double)fmax(max_edge_ratio, -VERDICT_DBL_MAX);
}
/*!
the aspect ratio of a quad
NB (P. Pebay 01/20/07):
this is a generalization of the triangle aspect ratio
using Heron's formula.
*/
VERDICT_HOST_DEVICE double quad_aspect_ratio(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
double a1 = edges[0].length();
double b1 = edges[1].length();
double c1 = edges[2].length();
double d1 = edges[3].length();
double ma = a1 > b1 ? a1 : b1;
double mb = c1 > d1 ? c1 : d1;
double hm = ma > mb ? ma : mb;
double corner_areas[4];
signed_corner_areas(corner_areas, coordinates);
double aspect_ratio = hm * (a1 + b1 + c1 + d1) / (corner_areas[0] + corner_areas[1] + corner_areas[2] + corner_areas[3]);
if (aspect_ratio > 0)
{
return (double)fmin(aspect_ratio, VERDICT_DBL_MAX);
}
return (double)fmax(aspect_ratio, -VERDICT_DBL_MAX);
}
/*!
the radius ratio of a quad
NB (P. Pebay 01/19/07):
this function is called "radius ratio" by extension of a concept that does
not exist in general with quads -- although a different name should probably
be used in the future.
*/
VERDICT_HOST_DEVICE double quad_radius_ratio(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
double a2 = edges[0].length_squared();
double b2 = edges[1].length_squared();
double c2 = edges[2].length_squared();
double d2 = edges[3].length_squared();
VerdictVector diag;
diag.set(coordinates[2][0] - coordinates[0][0], coordinates[2][1] - coordinates[0][1],
coordinates[2][2] - coordinates[0][2]);
double m2 = diag.length_squared();
diag.set(coordinates[3][0] - coordinates[1][0], coordinates[3][1] - coordinates[1][1],
coordinates[3][2] - coordinates[1][2]);
double n2 = diag.length_squared();
double t0 = a2 > b2 ? a2 : b2;
double t1 = c2 > d2 ? c2 : d2;
double t2 = m2 > n2 ? m2 : n2;
double h2 = t0 > t1 ? t0 : t1;
h2 = h2 > t2 ? h2 : t2;
VerdictVector ab = edges[0] * edges[1];
VerdictVector bc = edges[1] * edges[2];
VerdictVector cd = edges[2] * edges[3];
VerdictVector da = edges[3] * edges[0];
t0 = da.length();
t1 = ab.length();
t2 = bc.length();
double t3 = cd.length();
t0 = t0 < t1 ? t0 : t1;
t2 = t2 < t3 ? t2 : t3;
t0 = t0 < t2 ? t0 : t2;
if (t0 < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MAX;
}
double radius_ratio = radius_ratio_normal_coeff * sqrt((a2 + b2 + c2 + d2) * h2) / t0;
if (radius_ratio > 0)
{
return (double)fmin(radius_ratio, VERDICT_DBL_MAX);
}
return (double)fmax(radius_ratio, -VERDICT_DBL_MAX);
}
/*!
the average Frobenius aspect of a quad
NB (P. Pebay 01/20/07):
this function is calculated by averaging the 4 Frobenius aspects at
each corner of the quad, when the reference triangle is right isosceles.
*/
VERDICT_HOST_DEVICE double quad_med_aspect_frobenius(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
double a2 = edges[0].length_squared();
double b2 = edges[1].length_squared();
double c2 = edges[2].length_squared();
double d2 = edges[3].length_squared();
VerdictVector ab = edges[0] * edges[1];
VerdictVector bc = edges[1] * edges[2];
VerdictVector cd = edges[2] * edges[3];
VerdictVector da = edges[3] * edges[0];
double ab1 = ab.length();
double bc1 = bc.length();
double cd1 = cd.length();
double da1 = da.length();
if (ab1 < VERDICT_DBL_MIN || bc1 < VERDICT_DBL_MIN || cd1 < VERDICT_DBL_MIN ||
da1 < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MAX;
}
double qsum = (a2 + b2) / ab1;
qsum += (b2 + c2) / bc1;
qsum += (c2 + d2) / cd1;
qsum += (d2 + a2) / da1;
double med_aspect_frobenius = .125 * qsum;
if (med_aspect_frobenius > 0)
{
return (double)fmin(med_aspect_frobenius, VERDICT_DBL_MAX);
}
return (double)fmax(med_aspect_frobenius, -VERDICT_DBL_MAX);
}
/*!
the maximum Frobenius aspect of a quad
NB (P. Pebay 01/20/07):
this function is calculated by taking the maximum of the 4 Frobenius aspects at
each corner of the quad, when the reference triangle is right isosceles.
*/
VERDICT_HOST_DEVICE double quad_max_aspect_frobenius(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
double a2 = edges[0].length_squared();
double b2 = edges[1].length_squared();
double c2 = edges[2].length_squared();
double d2 = edges[3].length_squared();
VerdictVector ab = edges[0] * edges[1];
VerdictVector bc = edges[1] * edges[2];
VerdictVector cd = edges[2] * edges[3];
VerdictVector da = edges[3] * edges[0];
double ab1 = ab.length();
double bc1 = bc.length();
double cd1 = cd.length();
double da1 = da.length();
if (ab1 < VERDICT_DBL_MIN || bc1 < VERDICT_DBL_MIN || cd1 < VERDICT_DBL_MIN ||
da1 < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MAX;
}
double qmax = (a2 + b2) / ab1;
double qcur = (b2 + c2) / bc1;
qmax = qmax > qcur ? qmax : qcur;
qcur = (c2 + d2) / cd1;
qmax = qmax > qcur ? qmax : qcur;
qcur = (d2 + a2) / da1;
qmax = qmax > qcur ? qmax : qcur;
double max_aspect_frobenius = .5 * qmax;
if (max_aspect_frobenius > 0)
{
return (double)fmin(max_aspect_frobenius, VERDICT_DBL_MAX);
}
return (double)fmax(max_aspect_frobenius, -VERDICT_DBL_MAX);
}
/*!
skew of a quad
maximum ||cos A|| where A is the angle between edges at quad center
*/
VERDICT_HOST_DEVICE double quad_skew(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector node_pos[4];
for (int i = 0; i < 4; i++)
{
node_pos[i].set(coordinates[i][0], coordinates[i][1], coordinates[i][2]);
}
VerdictVector principle_axes[2];
principle_axes[0] = node_pos[1] + node_pos[2] - node_pos[3] - node_pos[0];
principle_axes[1] = node_pos[2] + node_pos[3] - node_pos[0] - node_pos[1];
if (principle_axes[0].normalize() < VERDICT_DBL_MIN)
{
return 0.0;
}
if (principle_axes[1].normalize() < VERDICT_DBL_MIN)
{
return 0.0;
}
double skew = fabs(principle_axes[0] % principle_axes[1]);
return (double)fmin(skew, VERDICT_DBL_MAX);
}
/*!
taper of a quad
maximum ratio of lengths derived from opposite edges
*/
VERDICT_HOST_DEVICE double quad_taper(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector node_pos[4];
for (int i = 0; i < 4; i++)
{
node_pos[i].set(coordinates[i][0], coordinates[i][1], coordinates[i][2]);
}
VerdictVector principle_axes[2];
principle_axes[0] = node_pos[1] + node_pos[2] - node_pos[3] - node_pos[0];
principle_axes[1] = node_pos[2] + node_pos[3] - node_pos[0] - node_pos[1];
VerdictVector cross_derivative = node_pos[0] + node_pos[2] - node_pos[1] - node_pos[3];
double lengths[2];
lengths[0] = principle_axes[0].length();
lengths[1] = principle_axes[1].length();
// get min length
lengths[0] = fmin(lengths[0], lengths[1]);
if (lengths[0] < VERDICT_DBL_MIN)
{
return VERDICT_DBL_MAX;
}
double taper = cross_derivative.length() / lengths[0];
return (double)fmin(taper, VERDICT_DBL_MAX);
}
/*!
warpage of a quad
deviation of element from planarity
*/
VERDICT_HOST_DEVICE double quad_warpage(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4];
make_quad_edges(edges, coordinates);
VerdictVector corner_normals[4];
corner_normals[0] = edges[3] * edges[0];
corner_normals[1] = edges[0] * edges[1];
corner_normals[2] = edges[1] * edges[2];
corner_normals[3] = edges[2] * edges[3];
if (corner_normals[0].normalize() < VERDICT_DBL_MIN ||
corner_normals[1].normalize() < VERDICT_DBL_MIN ||
corner_normals[2].normalize() < VERDICT_DBL_MIN ||
corner_normals[3].normalize() < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MIN;
}
double warpage = fmin(corner_normals[0] % corner_normals[2], corner_normals[1] % corner_normals[3]);
warpage = warpage * warpage * warpage;
if (warpage > 0)
{
return (double)fmin(warpage, VERDICT_DBL_MAX);
}
return (double)fmax(warpage, -VERDICT_DBL_MAX);
}
/*!
the area of a quad
jacobian at quad center
*/
VERDICT_HOST_DEVICE double quad_area(int num_nodes, const double coordinates[][3])
{
if (4 == num_nodes)
{
double corner_areas[4];
signed_corner_areas(corner_areas, coordinates);
double area = 0.25 * (corner_areas[0] + corner_areas[1] + corner_areas[2] + corner_areas[3]);
if (area > 0)
{
return (double)fmin(area, VERDICT_DBL_MAX);
}
return (double)fmax(area, -VERDICT_DBL_MAX);
}
else
{
double area = 0;
double tmp_coords[4][3];
if (5 == num_nodes)
{
int tri_conn[4][2] = { {0,1}, {1,2}, {2,3}, {3,0} };
//center node 4
tmp_coords[2][0] = coordinates[4][0];
tmp_coords[2][1] = coordinates[4][1];
tmp_coords[2][2] = coordinates[4][2];
for (auto v : tri_conn)
{
tmp_coords[0][0] = coordinates[v[0]][0];
tmp_coords[0][1] = coordinates[v[0]][1];
tmp_coords[0][2] = coordinates[v[0]][2];
tmp_coords[1][0] = coordinates[v[1]][0];
tmp_coords[1][1] = coordinates[v[1]][1];
tmp_coords[1][2] = coordinates[v[1]][2];
area += tri_area(3, tmp_coords);
}
}
else if (8 == num_nodes)
{
int tri_conn[4][3] = { {0,4,7}, {4,1,5}, {5,2,6}, {6,3,7} };
for (auto v : tri_conn)
{
tmp_coords[0][0] = coordinates[v[0]][0];
tmp_coords[0][1] = coordinates[v[0]][1];
tmp_coords[0][2] = coordinates[v[0]][2];
tmp_coords[1][0] = coordinates[v[1]][0];
tmp_coords[1][1] = coordinates[v[1]][1];
tmp_coords[1][2] = coordinates[v[1]][2];
tmp_coords[2][0] = coordinates[v[2]][0];
tmp_coords[2][1] = coordinates[v[2]][1];
tmp_coords[2][2] = coordinates[v[2]][2];
area += tri_area(3, tmp_coords);
}
//interior quad 4567
tmp_coords[0][0] = coordinates[4][0];
tmp_coords[0][1] = coordinates[4][1];
tmp_coords[0][2] = coordinates[4][2];
tmp_coords[1][0] = coordinates[5][0];
tmp_coords[1][1] = coordinates[5][1];
tmp_coords[1][2] = coordinates[5][2];
tmp_coords[2][0] = coordinates[6][0];
tmp_coords[2][1] = coordinates[6][1];
tmp_coords[2][2] = coordinates[6][2];
tmp_coords[3][0] = coordinates[7][0];
tmp_coords[3][1] = coordinates[7][1];
tmp_coords[3][2] = coordinates[7][2];
area += quad_area(4, tmp_coords);
}
else if (9 == num_nodes)
{
int tri_conn[8][2] = { {0,4}, {4,1}, {1,5}, {5,2}, {2,6}, {6,3}, {3,7}, {7,0} };
//quad center node
tmp_coords[2][0] = coordinates[8][0];
tmp_coords[2][1] = coordinates[8][1];
tmp_coords[2][2] = coordinates[8][2];
for (auto v : tri_conn)
{
tmp_coords[0][0] = coordinates[v[0]][0];
tmp_coords[0][1] = coordinates[v[0]][1];
tmp_coords[0][2] = coordinates[v[0]][2];
tmp_coords[1][0] = coordinates[v[1]][0];
tmp_coords[1][1] = coordinates[v[1]][1];
tmp_coords[1][2] = coordinates[v[1]][2];
area += tri_area(3, tmp_coords);
}
}
return area;
}
}
/*!
the stretch of a quad
sqrt(2) * minimum edge length / maximum diagonal length
*/
VERDICT_HOST_DEVICE double quad_stretch(int /*num_nodes*/, const double coordinates[][3])
{
VerdictVector edges[4], temp;
make_quad_edges(edges, coordinates);
double lengths_squared[4];
lengths_squared[0] = edges[0].length_squared();
lengths_squared[1] = edges[1].length_squared();
lengths_squared[2] = edges[2].length_squared();
lengths_squared[3] = edges[3].length_squared();
temp.set(coordinates[2][0] - coordinates[0][0], coordinates[2][1] - coordinates[0][1],
coordinates[2][2] - coordinates[0][2]);
double diag02 = temp.length_squared();
temp.set(coordinates[3][0] - coordinates[1][0], coordinates[3][1] - coordinates[1][1],
coordinates[3][2] - coordinates[1][2]);
double diag13 = temp.length_squared();
// 'diag02' is now the max diagonal of the quad
diag02 = fmax(diag02, diag13);
if (diag02 < VERDICT_DBL_MIN)
{
return (double)VERDICT_DBL_MAX;
}
else
{
double stretch = (double)(sqrt2 *
sqrt(fmin(fmin(lengths_squared[0], lengths_squared[1]),
fmin(lengths_squared[2], lengths_squared[3])) /
diag02));
return (double)fmin(stretch, VERDICT_DBL_MAX);
}
}
/*!
the largest angle of a quad
largest included quad area (degrees)
*/
VERDICT_HOST_DEVICE double quad_maximum_angle(int /*num_nodes*/, const double coordinates[][3])
{
// if this is a collapsed quad, just pass it on to
// the tri_largest_angle routine
if (is_collapsed_quad(coordinates) == VERDICT_TRUE)
{
return tri_maximum_angle(3, coordinates);
}
double angle;
double max_angle = 0.0;
VerdictVector edges[4];
edges[0].set(coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
coordinates[1][2] - coordinates[0][2]);
edges[1].set(coordinates[2][0] - coordinates[1][0], coordinates[2][1] - coordinates[1][1],
coordinates[2][2] - coordinates[1][2]);
edges[2].set(coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
coordinates[3][2] - coordinates[2][2]);
edges[3].set(coordinates[0][0] - coordinates[3][0], coordinates[0][1] - coordinates[3][1],
coordinates[0][2] - coordinates[3][2]);
// go around each node and calculate the angle
// at each node
double length[4];
length[0] = edges[0].length();
length[1] = edges[1].length();
length[2] = edges[2].length();
length[3] = edges[3].length();
if (length[0] <= VERDICT_DBL_MIN || length[1] <= VERDICT_DBL_MIN ||
length[2] <= VERDICT_DBL_MIN || length[3] <= VERDICT_DBL_MIN)
{
return 0.0;
}
angle = acos(-(edges[0] % edges[1]) / (length[0] * length[1]));
max_angle = fmax(angle, max_angle);
angle = acos(-(edges[1] % edges[2]) / (length[1] * length[2]));
max_angle = fmax(angle, max_angle);
angle = acos(-(edges[2] % edges[3]) / (length[2] * length[3]));
max_angle = fmax(angle, max_angle);
angle = acos(-(edges[3] % edges[0]) / (length[3] * length[0]));
max_angle = fmax(angle, max_angle);
max_angle = max_angle * 180.0 / VERDICT_PI;
// if any signed areas are < 0, then you are getting the wrong angle
double areas[4];
signed_corner_areas(areas, coordinates);
if (areas[0] < 0 || areas[1] < 0 || areas[2] < 0 || areas[3] < 0)
{
max_angle = 360 - max_angle;
}
if (max_angle > 0)
{
return (double)fmin(max_angle, VERDICT_DBL_MAX);
}
return (double)fmax(max_angle, -VERDICT_DBL_MAX);
}
/*!
the smallest angle of a quad
smallest included quad angle (degrees)
*/
VERDICT_HOST_DEVICE double quad_minimum_angle(int /*num_nodes*/, const double coordinates[][3])
{
// if this quad is a collapsed quad, then just
// send it to the tri_smallest_angle routine
if (is_collapsed_quad(coordinates) == VERDICT_TRUE)
{
return tri_minimum_angle(3, coordinates);
}
double angle;
double min_angle = 360.0;
VerdictVector edges[4];
edges[0].set(coordinates[1][0] - coordinates[0][0], coordinates[1][1] - coordinates[0][1],
coordinates[1][2] - coordinates[0][2]);
edges[1].set(coordinates[2][0] - coordinates[1][0], coordinates[2][1] - coordinates[1][1],
coordinates[2][2] - coordinates[1][2]);
edges[2].set(coordinates[3][0] - coordinates[2][0], coordinates[3][1] - coordinates[2][1],
coordinates[3][2] - coordinates[2][2]);
edges[3].set(coordinates[0][0] - coordinates[3][0], coordinates[0][1] - coordinates[3][1],
coordinates[0][2] - coordinates[3][2]);
// go around each node and calculate the angle
// at each node
double length[4];
length[0] = edges[0].length();
length[1] = edges[1].length();
length[2] = edges[2].length();
length[3] = edges[3].length();
if (length[0] <= VERDICT_DBL_MIN || length[1] <= VERDICT_DBL_MIN ||
length[2] <= VERDICT_DBL_MIN || length[3] <= VERDICT_DBL_MIN)
{
return 360.0;
}
angle = acos(-(edges[0] % edges[1]) / (length[0] * length[1]));
min_angle = fmin(angle, min_angle);
angle = acos(-(edges[1] % edges[2]) / (length[1] * length[2]));
min_angle = fmin(angle, min_angle);
angle = acos(-(edges[2] % edges[3]) / (length[2] * length[3]));
min_angle = fmin(angle, min_angle);
angle = acos(-(edges[3] % edges[0]) / (length[3] * length[0]));
min_angle = fmin(angle, min_angle);