Update tests

This commit is contained in:
Mael Rouxel-Labbé 2020-03-25 18:48:44 +01:00
parent 79aa6a755a
commit 546f943c6e
8 changed files with 719 additions and 204 deletions

View File

@ -0,0 +1,323 @@
OFF
121 200 0
0 0 0
0.10000000000000001 0 0
0.20000000000000001 0 0
0.29999999999999999 0 0
0.40000000000000002 0 0
0.5 0 0
0.59999999999999998 0 0
0.69999999999999996 0 0
0.80000000000000004 0 0
0.90000000000000002 0 0
1 0 0
0 0.10000000000000001 0.10000000000000001
0.10000000000000001 0.10000000000000001 0.10000000000000001
0.20000000000000001 0.10000000000000001 0.10000000000000001
0.29999999999999999 0.10000000000000001 0.10000000000000001
0.40000000000000002 0.10000000000000001 0.10000000000000001
0.5 0.10000000000000001 0.10000000000000001
0.59999999999999998 0.10000000000000001 0.10000000000000001
0.69999999999999996 0.10000000000000001 0.10000000000000001
0.80000000000000004 0.10000000000000001 0.10000000000000001
0.90000000000000002 0.10000000000000001 0.10000000000000001
1 0.10000000000000001 0.10000000000000001
0 0.20000000000000001 0.20000000000000001
0.10000000000000001 0.20000000000000001 0.20000000000000001
0.20000000000000001 0.20000000000000001 0.20000000000000001
0.29999999999999999 0.20000000000000001 0.20000000000000001
0.40000000000000002 0.20000000000000001 0.20000000000000001
0.5 0.20000000000000001 0.20000000000000001
0.59999999999999998 0.20000000000000001 0.20000000000000001
0.69999999999999996 0.20000000000000001 0.20000000000000001
0.80000000000000004 0.20000000000000001 0.20000000000000001
0.90000000000000002 0.20000000000000001 0.20000000000000001
1 0.20000000000000001 0.20000000000000001
0 0.29999999999999999 0.29999999999999999
0.10000000000000001 0.29999999999999999 0.29999999999999999
0.20000000000000001 0.29999999999999999 0.29999999999999999
0.29999999999999999 0.29999999999999999 0.29999999999999999
0.40000000000000002 0.29999999999999999 0.29999999999999999
0.5 0.29999999999999999 0.29999999999999999
0.59999999999999998 0.29999999999999999 0.29999999999999999
0.69999999999999996 0.29999999999999999 0.29999999999999999
0.80000000000000004 0.29999999999999999 0.29999999999999999
0.90000000000000002 0.29999999999999999 0.29999999999999999
1 0.29999999999999999 0.29999999999999999
0 0.40000000000000002 0.40000000000000002
0.10000000000000001 0.40000000000000002 0.40000000000000002
0.20000000000000001 0.40000000000000002 0.40000000000000002
0.29999999999999999 0.40000000000000002 0.40000000000000002
0.40000000000000002 0.40000000000000002 0.40000000000000002
0.5 0.40000000000000002 0.40000000000000002
0.59999999999999998 0.40000000000000002 0.40000000000000002
0.69999999999999996 0.40000000000000002 0.40000000000000002
0.80000000000000004 0.40000000000000002 0.40000000000000002
0.90000000000000002 0.40000000000000002 0.40000000000000002
1 0.40000000000000002 0.40000000000000002
0 0.5 0.5
0.10000000000000001 0.5 0.5
0.20000000000000001 0.5 0.5
0.29999999999999999 0.5 0.5
0.40000000000000002 0.5 0.5
0.5 0.5 0.5
0.59999999999999998 0.5 0.5
0.69999999999999996 0.5 0.5
0.80000000000000004 0.5 0.5
0.90000000000000002 0.5 0.5
1 0.5 0.5
0 0.59999999999999998 0.59999999999999998
0.10000000000000001 0.59999999999999998 0.59999999999999998
0.20000000000000001 0.59999999999999998 0.59999999999999998
0.29999999999999999 0.59999999999999998 0.59999999999999998
0.40000000000000002 0.59999999999999998 0.59999999999999998
0.5 0.59999999999999998 0.59999999999999998
0.59999999999999998 0.59999999999999998 0.59999999999999998
0.69999999999999996 0.59999999999999998 0.59999999999999998
0.80000000000000004 0.59999999999999998 0.59999999999999998
0.90000000000000002 0.59999999999999998 0.59999999999999998
1 0.59999999999999998 0.59999999999999998
0 0.69999999999999996 0.69999999999999996
0.10000000000000001 0.69999999999999996 0.69999999999999996
0.20000000000000001 0.69999999999999996 0.69999999999999996
0.29999999999999999 0.69999999999999996 0.69999999999999996
0.40000000000000002 0.69999999999999996 0.69999999999999996
0.5 0.69999999999999996 0.69999999999999996
0.59999999999999998 0.69999999999999996 0.69999999999999996
0.69999999999999996 0.69999999999999996 0.69999999999999996
0.80000000000000004 0.69999999999999996 0.69999999999999996
0.90000000000000002 0.69999999999999996 0.69999999999999996
1 0.69999999999999996 0.69999999999999996
0 0.80000000000000004 0.80000000000000004
0.10000000000000001 0.80000000000000004 0.80000000000000004
0.20000000000000001 0.80000000000000004 0.80000000000000004
0.29999999999999999 0.80000000000000004 0.80000000000000004
0.40000000000000002 0.80000000000000004 0.80000000000000004
0.5 0.80000000000000004 0.80000000000000004
0.59999999999999998 0.80000000000000004 0.80000000000000004
0.69999999999999996 0.80000000000000004 0.80000000000000004
0.80000000000000004 0.80000000000000004 0.80000000000000004
0.90000000000000002 0.80000000000000004 0.80000000000000004
1 0.80000000000000004 0.80000000000000004
0 0.90000000000000002 0.90000000000000002
0.10000000000000001 0.90000000000000002 0.90000000000000002
0.20000000000000001 0.90000000000000002 0.90000000000000002
0.29999999999999999 0.90000000000000002 0.90000000000000002
0.40000000000000002 0.90000000000000002 0.90000000000000002
0.5 0.90000000000000002 0.90000000000000002
0.59999999999999998 0.90000000000000002 0.90000000000000002
0.69999999999999996 0.90000000000000002 0.90000000000000002
0.80000000000000004 0.90000000000000002 0.90000000000000002
0.90000000000000002 0.90000000000000002 0.90000000000000002
1 0.90000000000000002 0.90000000000000002
0 1 1
0.10000000000000001 1 1
0.20000000000000001 1 1
0.29999999999999999 1 1
0.40000000000000002 1 1
0.5 1 1
0.59999999999999998 1 1
0.69999999999999996 1 1
0.80000000000000004 1 1
0.90000000000000002 1 1
1 1 1
3 0 1 11
3 1 12 11
3 11 12 22
3 12 23 22
3 22 23 33
3 23 34 33
3 33 34 44
3 34 45 44
3 44 45 55
3 45 56 55
3 55 56 66
3 56 67 66
3 66 67 77
3 67 78 77
3 77 78 88
3 78 89 88
3 88 89 99
3 89 100 99
3 99 100 110
3 100 111 110
3 1 2 12
3 2 13 12
3 12 13 23
3 13 24 23
3 23 24 34
3 24 35 34
3 34 35 45
3 35 46 45
3 45 46 56
3 46 57 56
3 56 57 67
3 57 68 67
3 67 68 78
3 68 79 78
3 78 79 89
3 79 90 89
3 89 90 100
3 90 101 100
3 100 101 111
3 101 112 111
3 2 3 13
3 3 14 13
3 13 14 24
3 14 25 24
3 24 25 35
3 25 36 35
3 35 36 46
3 36 47 46
3 46 47 57
3 47 58 57
3 57 58 68
3 58 69 68
3 68 69 79
3 69 80 79
3 79 80 90
3 80 91 90
3 90 91 101
3 91 102 101
3 101 102 112
3 102 113 112
3 3 4 14
3 4 15 14
3 14 15 25
3 15 26 25
3 25 26 36
3 26 37 36
3 36 37 47
3 37 48 47
3 47 48 58
3 48 59 58
3 58 59 69
3 59 70 69
3 69 70 80
3 70 81 80
3 80 81 91
3 81 92 91
3 91 92 102
3 92 103 102
3 102 103 113
3 103 114 113
3 4 5 15
3 5 16 15
3 15 16 26
3 16 27 26
3 26 27 37
3 27 38 37
3 37 38 48
3 38 49 48
3 48 49 59
3 49 60 59
3 59 60 70
3 60 71 70
3 70 71 81
3 71 82 81
3 81 82 92
3 82 93 92
3 92 93 103
3 93 104 103
3 103 104 114
3 104 115 114
3 5 6 16
3 6 17 16
3 16 17 27
3 17 28 27
3 27 28 38
3 28 39 38
3 38 39 49
3 39 50 49
3 49 50 60
3 50 61 60
3 60 61 71
3 61 72 71
3 71 72 82
3 72 83 82
3 82 83 93
3 83 94 93
3 93 94 104
3 94 105 104
3 104 105 115
3 105 116 115
3 6 7 17
3 7 18 17
3 17 18 28
3 18 29 28
3 28 29 39
3 29 40 39
3 39 40 50
3 40 51 50
3 50 51 61
3 51 62 61
3 61 62 72
3 62 73 72
3 72 73 83
3 73 84 83
3 83 84 94
3 84 95 94
3 94 95 105
3 95 106 105
3 105 106 116
3 106 117 116
3 7 8 18
3 8 19 18
3 18 19 29
3 19 30 29
3 29 30 40
3 30 41 40
3 40 41 51
3 41 52 51
3 51 52 62
3 52 63 62
3 62 63 73
3 63 74 73
3 73 74 84
3 74 85 84
3 84 85 95
3 85 96 95
3 95 96 106
3 96 107 106
3 106 107 117
3 107 118 117
3 8 9 19
3 9 20 19
3 19 20 30
3 20 31 30
3 30 31 41
3 31 42 41
3 41 42 52
3 42 53 52
3 52 53 63
3 53 64 63
3 63 64 74
3 64 75 74
3 74 75 85
3 75 86 85
3 85 86 96
3 86 97 96
3 96 97 107
3 97 108 107
3 107 108 118
3 108 119 118
3 9 10 20
3 10 21 20
3 20 21 31
3 21 32 31
3 31 32 42
3 32 43 42
3 42 43 53
3 43 54 53
3 53 54 64
3 54 65 64
3 64 65 75
3 65 76 75
3 75 76 86
3 76 87 86
3 86 87 97
3 87 98 97
3 97 98 108
3 98 109 108
3 108 109 119
3 109 120 119

View File

@ -0,0 +1,8 @@
413065776.152494 326396843.840397 326457757.911644
413065776.152494 326396843.840397 326457757.911644
413065776.152494 326396843.840397 326457757.911644
413065776.152494 326396843.840397 326457757.911644
413065776.152494 326396843.840397 326457757.911644
413065776.152494 326396843.840397 326457757.911644
413065776.152494 326396843.840397 326457757.911644

View File

@ -0,0 +1,7 @@
0 0 0
0 1 2
0 2 4
0 3 6
0 10 20
0 0.5 1

View File

@ -0,0 +1,282 @@
413065776.152494 326396843.840397 0
413057847.377906 326403660.329056 0
413052569.655378 326399341.810968 0
412964155.996695 326429557.407149 0
412960887.449993 326443760.793625 0
412939753.084117 326436727.039421 0
412939894.318992 326428463.667967 0
412947664.119328 326419882.748586 0
412970476.46515 326451966.912356 0
412968925.050862 326458160.301721 0
412963543.512664 326454495.012767 0
412985746.970294 326424302.733302 0
412983665.865636 326410836.59751 0
412996088.235308 326419469.954289 0
412998096.793163 326423084.180324 0
413003418.285576 326419809.050109 0
413002038.294065 326427600.699796 0
412945313.935335 326454359.672656 0
412943663.154485 326452834.040025 0
412952251.09554 326452986.901051 0
412950732.333508 326457757.911644 0
412943971.574173 326459149.099198 0
412934361.648126 326445041.605944 0
412936751.268924 326454822.208572 0
412964758.701994 326486192.337374 0
412966490.855253 326478259.235383 0
412973194.081713 326482046.898235 0
412950650.516328 326468707.808723 0
412957725.270744 326476103.847023 0
412950026.231257 326477412.439015 0
412988174.944206 326470661.339091 0
412986909.075808 326462858.270384 0
413000669.61306 326456348.730054 0
412966234.090172 326488146.292068 0
413023232.123734 326461197.560115 0
413023550.270655 326471002.013297 0
413016185.260894 326465438.977186 0
412987141.775588 326489693.339605 0
412982918.043107 326488237.152808 0
412985980.280763 326483135.425286 0
413001196.353514 326479715.175257 0
413008202.547705 326474962.703983 0
413003755.131316 326481400.115507 0
412929683.198695 326465491.420262 0
412920189.499339 326451860.04878 0
412931611.507502 326452533.708517 0
412992581.061321 326477132.127848 0
412989279.419663 326480089.894799 0
412935705.096519 326482202.861555 0
412925307.138482 326466637.344135 0
413076469.52736 326433412.768228 0
413075298.398716 326444763.979995 0
413065834.246237 326440647.027719 0
413009745.175265 326502212.1638 0
413001718.895276 326508920.841833 0
413002418.144751 326497753.488837 0
413060741.401393 326423820.134531 0
413060876.676061 326428728.639701 0
413058999.571918 326423687.390799 0
413025105.511534 326478606.208507 0
413037158.816855 326472407.974956 0
413026100.112628 326483530.179333 0
413079758.83472 326425207.53598 0
413076210.923893 326422944.976439 0
413078151.988242 326416248.664714 0
413053952.794291 326463144.972745 0
413055684.722689 326475529.630202 0
413045099.788495 326474825.69738 0
413062042.967186 326437063.922844 0
413066790.302583 326430817.2269 0
413004709.107113 326490135.418709 0
413005093.685865 326489983.127837 0
413098251.972367 326408565.921651 0
413098367.233587 326415127.45218 0
413097944.35044 326413442.449707 0
413070518.763323 326460355.49692 0
413066193.752266 326467461.946737 0
413087099.80728 326418237.162439 0
412932643.127595 326424163.465682 0
412947239.568275 326415586.45517 0
412929877.917135 326420120.542778 0
413010920.918128 326399072.312299 0
412915060.825449 326423803.643013 0
412963212.559984 326417484.293606 0
412974527.414159 326428576.196833 0
412992373.377627 326455620.014196 0
413010074.272151 326418465.382469 0
413011850.753162 326417002.217271 0
413014406.991439 326420203.661922 0
412977637.839421 326432544.829395 0
412986148.487405 326429359.611152 0
412995280.156846 326431026.989975 0
412990626.28213 326425374.845568 0
413032797.62091 326426191.034153 0
413029970.570148 326419936.329868 0
413044681.544615 326417464.080029 0
412999129.25698 326438072.80725 0
413007734.056563 326423851.649794 0
413016471.93654 326426364.913717 0
412968431.452864 326491828.041548 0
412958675.073533 326494006.076801 0
413012148.256747 326487804.579704 0
413016405.832048 326480671.32311 0
412975768.001435 326448708.020146 0
412979720.162501 326436886.822391 0
412982917.886679 326443564.393356 0
412988678.510158 326449487.248631 0
412985417.106869 326452678.469145 0
412971510.871442 326435116.950769 0
412983109.808175 326457244.32078 0
412957466.876904 326451325.256978 0
412959384.40943 326448781.181773 0
412966768.138142 326473363.04219 0
412971910.952526 326476870.046921 0
412963392.569735 326463111.127056 0
412924771.98365 326432849.602577 0
412917475.177804 326429370.043518 0
412911569.816167 326425718.742949 0
412924489.589924 326449937.575511 0
412956933.247292 326455774.007997 0
412955340.545694 326460219.517522 0
412977018.754996 326466258.738995 0
412970686.301222 326466481.954067 0
412978255.629151 326461355.571957 0
412939153.439846 326465339.238827 0
412923821.154719 326426918.928828 0
412975936.409656 326502806.20831 0
412963303.14509 326498679.785427 0
412969138.482087 326493922.342246 0
412956467.21651 326489106.767098 0
412959578.052441 326480365.162202 0
412977352.621415 326497109.261795 0
412941422.08486 326477143.510512 0
412936831.795868 326467205.375027 0
412961266.195768 326503954.723704 0
412958703.392685 326524881.814902 0
412953249.527674 326518460.235631 0
412935010.36184 326494112.455851 0
412931570.65415 326484602.04937 0
412985374.324569 326513222.867276 0
412978227.727596 326510871.926542 0
412984173.754694 326502503.840454 0
412985688.206537 326494576.776311 0
412978009.820415 326492658.751496 0
412993618.008235 326491281.852681 0
412997947.150272 326492521.079555 0
412976873.960635 326486185.606476 0
412981478.037092 326484421.347501 0
412980418.065914 326478321.690068 0
412979438.184438 326473334.846215 0
413010215.690383 326443409.550491 0
413008228.44707 326458894.052728 0
413035617.465636 326446767.558378 0
413027230.055638 326446990.503477 0
413030854.849802 326440245.461135 0
412979140.451061 326454242.503581 0
412985468.6174 326450604.80651 0
413015771.02389 326453064.045201 0
413021991.755036 326445142.840934 0
413008006.052746 326469763.695134 0
413048901.884808 326422501.5037 0
413045028.78386 326426372.15428 0
413005007.536883 326484301.633515 0
413002785.535959 326490180.214403 0
413014109.69202 326461894.536067 0
413017207.888265 326470063.830947 0
413045293.513014 326449673.312107 0
413044019.75301 326447988.572283 0
413047003.614678 326443105.313308 0
412999003.436139 326487344.001445 0
412996651.65689 326491134.958733 0
413012316.245006 326479912.254408 0
413012587.728747 326484153.816803 0
413016871.37429 326476971.655283 0
413019842.625853 326474794.530385 0
413039469.406178 326437529.843339 0
413041502.67459 326485107.978727 0
413036035.620497 326461314.614016 0
413031490.325583 326456799.67237 0
413020789.72965 326452093.515847 0
413020692.119972 326434154.560939 0
413029690.023638 326438011.408021 0
413043486.972873 326454746.798277 0
413033511.062177 326430679.751046 0
413067488.089213 326425961.293338 0
413083753.259443 326426175.344791 0
413067460.916052 326410232.697374 0
413068622.531383 326416317.705612 0
413061037.102135 326415163.721378 0
413071143.181797 326424762.764848 0
413060387.108431 326414188.28851 0
413060445.58895 326451275.748613 0
413036317.30909 326431883.117032 0
413045873.300553 326435644.793299 0
413048794.267495 326389319.436376 0
413030291.769546 326411368.835099 0
413024488.398109 326415338.686016 0
413021905.956926 326410737.878939 0
413027639.836779 326415641.265719 0
413017857.083999 326417952.301599 0
413029827.400431 326406821.764259 0
413001443.929946 326407150.378482 0
413036041.452869 326405791.758584 0
413033454.48341 326399656.242176 0
413018633.129927 326413338.952301 0
413045368.965357 326402337.610635 0
413048447.394379 326395169.908511 0
412986849.902761 326405367.534053 0
413065081.744554 326401671.778183 0
413092397.837156 326422086.08121 0
413095318.341189 326412788.599152 0
413093695.254875 326400330.203004 0
413099020.077932 326406314.05352 0
413093140.218869 326403110.903958 0
413056121.776141 326406403.684953 0
413089620.108842 326414007.091517 0
413089387.417624 326419721.87399 0
413093404.232693 326395001.998282 0
413085896.789345 326396361.60811 0
413085454.676931 326391470.731474 0
413074508.839395 326394470.397757 0
413068350.570434 326395560.501438 0
413070143.96055 326386445.935889 0
412918858.560132 326434979.970278 0
412955394.145789 326449536.682215 0
412971144.038673 326433652.368538 0
412965073.360409 326439051.77804 0
412970981.692447 326409503.990341 0
413014840.087809 326404397.988193 0
412994018.136075 326445298.914892 0
412990097.829467 326437133.362141 0
412965842.792609 326448792.291328 0
412961763.785867 326445852.010028 0
412947255.093497 326463668.462422 0
412939952.26946 326466492.382176 0
412943709.427436 326472618.681827 0
412952246.783422 326483371.121473 0
412944807.921928 326491083.247909 0
412940579.938471 326495813.432763 0
412945630.90436 326501939.425427 0
412938409.182245 326503335.780256 0
412951371.196888 326498868.583434 0
412949313.764109 326504296.763374 0
412945558.683443 326510754.714855 0
413008766.713556 326484732.391891 0
412990390.280433 326484843.195428 0
412995165.502732 326483367.864039 0
413016256.164946 326494798.780171 0
413017224.89391 326461129.632116 0
413029625.683716 326471350.776378 0
413025019.999494 326476200.095554 0
413048766.414482 326435871.77665 0
413051725.256746 326438529.947023 0
413052007.160945 326422036.946841 0
413058067.843268 326435775.445353 0
413083660.953967 326393424.812132 0
413083336.161107 326400813.355748 0
413066349.33981 326419281.508749 0
413068090.500382 326410610.12681 0
413074241.401196 326404770.242276 0
413081317.053152 326414171.97812 0
413073381.651167 326406897.136775 0
413095766.46998 326387248.540458 0
413097047.640536 326395426.23288 0
413098209.521961 326406637.959602 0
413089554.505615 326388294.334232 0
413074403.539056 326415367.945363 0
413040020.425247 326411046.731682 0
413045679.434506 326406659.04965 0
413039095.903129 326409071.668118 0
413031306.230818 326393733.283998 0
413052303.600823 326400659.626307 0
413081695.584061 326380509.699198 0
413077541.674433 326389883.685777 0
413082416.500748 326382824.511316 0
413073027.473224 326382906.090405 0
413088349.695199 326383000.125606 0
413094911.539918 326387536.877598 0
413092119.400999 326388985.514422 0
413093374.909798 326384034.886791 0
413096500.785907 326395520.129613 0
413094014.467295 326377700.363085 0

View File

@ -0,0 +1,9 @@
OFF
4 2 0
0 0 0
1 0 0
0 1 0
1 1 0
3 0 1 2
3 2 1 3

View File

@ -31,7 +31,7 @@ void check_equality(const FT d1, const FT d2)
}
}
void test_fitness_function()
void test_fitness_function(const Traits& traits)
{
std::array<Point_3, 4> points;
points[0] = Point_3(0.866802, 0.740808, 0.895304);
@ -50,7 +50,7 @@ void test_fitness_function()
rotation.set(2, 1, -0.991602);
rotation.set(2, 2, 0.042528);
const double fitness = CGAL::Optimal_bounding_box::internal::compute_fitness<Traits>(rotation, points);
const double fitness = CGAL::Optimal_bounding_box::internal::compute_fitness(rotation, points, traits);
check_equality(fitness, 0.58606);
}
@ -95,44 +95,13 @@ void test_eigen_matrix_interface()
check_equality(Q(2,0), -0.006573);
check_equality(Q(2,1), 0.024478);
check_equality(Q(2,2), 0.999679);
Matrix D;
D.set(0, 0, -0.809204);
D.set(0, 1, 0.124296);
D.set(0, 2, 0.574230);
D.set(1, 0, -0.574694);
D.set(1, 1, 0.035719);
D.set(1, 2, -0.817589);
D.set(2, 0, -0.122134);
D.set(2, 1, -0.991602);
D.set(2, 2, 0.042528);
Matrix E;
E.set(0, 0, -0.45070);
E.set(0, 1, -0.32769);
E.set(0, 2, -0.83035);
E.set(1, 0, -0.13619);
E.set(1, 1, -0.89406);
E.set(1, 2, 0.42675);
E.set(2, 0, -0.88222);
E.set(2, 1, 0.30543);
E.set(2, 2, 0.35833);
Matrix Sr = CGAL::Optimal_bounding_box::internal::reflection(D, E);
check_equality(Sr(0,0), -0.13359);
check_equality(Sr(0,1), -0.95986);
check_equality(Sr(0,2), -0.24664);
check_equality(Sr(1,0), -0.60307);
check_equality(Sr(1,1), -0.11875);
check_equality(Sr(1,2), 0.78880);
check_equality(Sr(2,0), -0.78642);
check_equality(Sr(2,1), 0.25411);
check_equality(Sr(2,2), -0.56300);
}
int main(int, char**)
{
test_fitness_function();
Traits traits;
test_fitness_function(traits);
test_eigen_matrix_interface();
std::cout << "Done!" << std::endl;

View File

@ -10,6 +10,7 @@ typedef K::Point_3 Point_3;
typedef CGAL::Oriented_bounding_box_traits_3<K> Traits;
typedef Traits::Matrix Matrix;
typedef CGAL::Optimal_bounding_box::internal::Population<Traits>::Vertex Vertex;
void check_equality(const FT d1, const FT d2)
{
@ -122,7 +123,7 @@ void test_nelder_mead(const Traits& traits)
points[3] = Point_3(0.166461, 0.149912, 0.364944);
// one simplex
std::array<Matrix, 4> simplex;
std::array<Vertex, 4> simplex;
Matrix v0, v1, v2, v3;
v0.set(0, 0, -0.2192721); v0.set(0, 1, 0.2792986); v0.set(0, 2, -0.9348326);
@ -141,15 +142,15 @@ void test_nelder_mead(const Traits& traits)
v3.set(1, 0, -0.20022); v3.set(1, 1, -0.71110); v3.set(1, 2, 0.67398);
v3.set(2, 0, -0.92372); v3.set(2, 1, 0.36630); v3.set(2, 2, 0.11207);
simplex[0] = v0;
simplex[1] = v1;
simplex[2] = v2;
simplex[3] = v3;
simplex[0] = Vertex{v0, points, traits};
simplex[1] = Vertex{v1, points, traits};
simplex[2] = Vertex{v2, points, traits};
simplex[3] = Vertex{v3, points, traits};
std::size_t nm_iterations = 19;
CGAL::Optimal_bounding_box::internal::nelder_mead(simplex, nm_iterations, points, traits);
const Matrix& v0_new = simplex[0];
const Matrix& v0_new = simplex[0].matrix();
check_equality(v0_new(0,0), -0.288975);
check_equality(v0_new(0,1), 0.7897657);
check_equality(v0_new(0,2), -0.541076);
@ -160,7 +161,7 @@ void test_nelder_mead(const Traits& traits)
check_equality(v0_new(2,1), 0.5111260);
check_equality(v0_new(2,2), 0.84094);
const Matrix& v1_new = simplex[1];
const Matrix& v1_new = simplex[1].matrix();
check_equality(v1_new(0,0), -0.458749);
check_equality(v1_new(0,1), 0.823283);
check_equality(v1_new(0,2), -0.334296);
@ -171,7 +172,7 @@ void test_nelder_mead(const Traits& traits)
check_equality(v1_new(2,1), 0.338040);
check_equality(v1_new(2,2), 0.937987);
const Matrix& v2_new = simplex[2];
const Matrix& v2_new = simplex[2].matrix();
check_equality(v2_new(0,0), -0.346582);
check_equality(v2_new(0,1), 0.878534);
check_equality(v2_new(0,2), -0.328724);
@ -182,7 +183,7 @@ void test_nelder_mead(const Traits& traits)
check_equality(v2_new(2,1), 0.334057);
check_equality(v2_new(2,2), 0.941423);
const Matrix& v3_new = simplex[3];
const Matrix& v3_new = simplex[3].matrix();
check_equality(v3_new(0,0), -0.394713);
check_equality(v3_new(0,1), 0.791782);
check_equality(v3_new(0,2), -0.466136);

View File

@ -1,8 +1,14 @@
#define CGAL_OPTIMAL_BOUNDING_BOX_DEBUG
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/boost/graph/generators.h>
#include <CGAL/optimal_bounding_box.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <array>
#include <iostream>
@ -10,211 +16,121 @@
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT FT;
typedef K::Point_3 Point_3;
typedef K::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;
typedef CGAL::Polyhedron_3<K> Mesh;
typedef CGAL::Oriented_bounding_box_traits_3<K> Traits;
typedef Traits::Matrix Matrix;
void check_equality(const FT d1, const FT d2)
bool is_equal(const FT d1, const FT d2)
{
const FT epsilon = 1e-3;
bool ok;
if(std::is_floating_point<FT>::value)
ok = CGAL::abs(d1 - d2) < epsilon * CGAL::abs(d2);
ok = CGAL::abs(d1 - d2) < std::max(epsilon * d1, epsilon);
else
ok = (d1 == d2);
if(!ok)
{
std::cout << "Error: got " << d1 << " but expected: " << d2 << std::endl;
assert(false);
return false;
}
return true;
}
void test_genetic_algorithm()
template <typename PointRange>
void test_OBB_data(const PointRange& points,
const double expected_vol,
const bool with_convex_hull = true)
{
std::array<Point_3, 4> points;
points[0] = Point_3(0.866802, 0.740808, 0.895304);
points[1] = Point_3(0.912651, 0.761565, 0.160330);
points[2] = Point_3(0.093661, 0.892578, 0.737412);
points[3] = Point_3(0.166461, 0.149912, 0.364944);
namespace PMP = CGAL::Polygon_mesh_processing;
CGAL::Optimal_bounding_box::internal::Population<Traits> pop(5);
CGAL::Optimal_bounding_box::internal::Evolution<Traits> evolution(pop, data_points);
evolution.genetic_algorithm();
assert(pop.size() == 5);
// the algorithm is allowed to fail, but not too often
int failure_count = 0;
for(int i=0; i<100; ++i)
{
CGAL::Surface_mesh<Point> obb_mesh;
CGAL::oriented_bounding_box(points, obb_mesh, CGAL::parameters::use_convex_hull(with_convex_hull));
PMP::triangulate_faces(obb_mesh);
// the triangulate algorithm might fail if the algorithm manages
// to fit perfectly the box to have a true 0 volume
if(CGAL::is_triangle_mesh(obb_mesh))
{
double vol = PMP::volume(obb_mesh);
std::cout << " volume is: " << vol << ", expected: " << expected_vol << std::endl;
if(!is_equal(vol, expected_vol))
{
std::cout << "Failure!" << std::endl;
++failure_count;
}
}
}
std::cout << "failures: " << failure_count << std::endl;
assert(failure_count < 5); // 5% failure
}
void test_random_unit_tetra()
void test_OBB_of_mesh(const std::string fname,
const double expected_vol)
{
std::array<Point_3, 4> points;
points[0] = Point_3(0.866802, 0.740808, 0.895304);
points[1] = Point_3(0.912651, 0.761565, 0.160330);
points[2] = Point_3(0.093661, 0.892578, 0.737412);
points[3] = Point_3(0.166461, 0.149912, 0.364944);
std::cout << "Test: " << fname << std::endl;
std::ifstream input(fname);
Mesh mesh;
CGAL::make_tetrahedron(points[0], points[1], points[2], points[3], mesh);
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
std::ofstream out("data/random_unit_tetra.off");
out << mesh;
out.close();
#endif
std::size_t generations = 10;
CGAL::Optimal_bounding_box::internal::Population<Traits> pop(50);
CGAL::Optimal_bounding_box::internal::Evolution<Traits> evolution(pop, data_points);
evolution.evolve(generations);
Matrix R = evolution.get_best();
check_equality(Traits::compute_determinant(R), 1);
check_equality(R(0,0), -0.25791);
check_equality(R(0,1), 0.796512);
check_equality(R(0,2), -0.546855);
check_equality(R(1,0), -0.947128);
check_equality(R(1,1), -0.320242);
check_equality(R(1,2), -0.0197553);
check_equality(R(2,0), -0.190861);
check_equality(R(2,1), 0.512847);
check_equality(R(2,2), 0.836992);
}
void test_reference_tetrahedron(const char* fname)
{
std::ifstream input(fname);
CGAL::Surface_mesh<Point_3> mesh;
if(!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file." << std::endl;
std::cerr << fname << " is not a valid input file." << std::endl;
std::exit(1);
}
// points in a matrix
Matrix points;
CGAL::Optimal_bounding_box::sm_to_matrix(mesh, points);
std::vector<Point> points;
for(const auto v : vertices(mesh))
points.push_back(v->point());
std::size_t generations = 10;
CGAL::Optimal_bounding_box::internal::Population<Traits> pop(50);
CGAL::Optimal_bounding_box::internal::Evolution<Traits> experiment(pop, points);
experiment.evolve(generations);
Matrix R = experiment.get_best();
check_equality(Traits::compute_determinant(R), 1);
test_OBB_data(points, expected_vol);
}
void test_long_tetrahedron(const std::string fname)
void test_OBB_of_point_set(const std::string fname,
const double expected_vol)
{
std::cout << "Test: " << fname << std::endl;
std::ifstream input(fname);
CGAL::Surface_mesh<Point_3> mesh;
if(!input || !(input >> mesh) || mesh.is_empty())
if(!input)
{
std::cerr << fname << " is not a valid off file." << std::endl;
std::cerr << fname << " is not a valid input file." << std::endl;
std::exit(1);
}
// points in a matrix
Matrix points;
CGAL::Optimal_bounding_box::sm_to_matrix(mesh, points);
std::deque<Point> points;
double x, y, z;
while(input >> x >> y >> z)
points.emplace_back(x, y, z);
std::size_t max_generations = 10;
CGAL::Optimal_bounding_box::internal::Population<Traits> pop(50);
CGAL::Optimal_bounding_box::internal::Evolution<Traits> experiment(pop, points);
experiment.evolve(max_generations);
Matrix R = experiment.get_best();
check_equality(Traits::compute_determinant(R), 1);
check_equality(R(0,0), -1);
check_equality(R(0,1), 0);
check_equality(R(0,2), 0);
check_equality(R(1,0), 0);
check_equality(R(1,1), -0.707107);
check_equality(R(1,2), 0.707106) || assert_doubles(R(1,2), -0.707106);
check_equality(R(2,0), 0);
check_equality(R(2,1), 0.707106) || assert_doubles(R(1,2), -0.707106);
check_equality(R(2,2), 0.707107);
}
void test_compute_obb_evolution(const std::string fname)
{
std::ifstream input(fname);
typedef CGAL::Surface_mesh<Point_3> SMesh;
SMesh mesh;
if(!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file." << std::endl;
std::exit(1);
}
Traits traits;
std::array<Point_3, 8> obb_points;
CGAL::oriented_bounding_box(sm, obb_points, CGAL::parameters::use_convex_hull(true)
.geom_traits(traits));
FT vol = CGAL::Optimal_bounding_box::calculate_volume(obb_points);
check_equality(vol, 0.883371);
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
CGAL::Surface_mesh<Point_3> result_mesh;
CGAL::make_hexahedron(obb_points[0], obb_points[1], obb_points[2], obb_points[3],
obb_points[4], obb_points[5], obb_points[6], obb_points[7], result_mesh);
std::ofstream out("data/obb_result.off");
out << result_mesh;
out.close();
#endif
}
void test_compute_obb_mesh(const std::string fname)
{
std::ifstream input(fname);
CGAL::Surface_mesh<Point_3> mesh;
if(!input || !(input >> mesh) || mesh.is_empty())
{
std::cerr << fname << " is not a valid off file." << std::endl;
std::exit(1);
}
CGAL::Surface_mesh<Point_3> obbmesh;
CGAL::oriented_bounding_box(mesh, obbmesh);
#ifdef CGAL_OPTIMAL_BOUNDING_BOX_DEBUG_TEST
std::ofstream out("/tmp/result_elephant.off");
out << obbmesh;
out.close();
#endif
}
void test_function_defaults_traits(const std::string fname1)
{
std::ifstream input1(fname1);
CGAL::Surface_mesh<Point_3> mesh1;
if(!input1 || !(input1 >> mesh1) || mesh1.is_empty())
{
std::cerr << fname1 << " is not a valid off file." << std::endl;
std::exit(1);
}
std::array<Point_3, 8> obb_points;
CGAL::oriented_bounding_box(sm_points, obb_points, CGAL::parameters::use_convex_hull(true));
const FT vol = CGAL::Optimal_bounding_box::calculate_volume(obb_points);
check_equality(vol, 0.883371);
test_OBB_data(points, expected_vol, false /*no convex hull due to degenerate data*/);
}
int main()
{
test_genetic_algorithm();
std::cout.precision(17);
test_random_unit_tetra();
test_reference_tetrahedron("data/reference_tetrahedron.off");
test_long_tetrahedron("data/long_tetrahedron.off");
test_compute_obb_evolution("data/random_unit_tetra.off");
test_compute_obb_mesh("data/elephant.off");
test_function_defaults_traits("data/random_unit_tetra.off");
test_OBB_of_mesh("data/elephant.off", 0.294296);
test_OBB_of_mesh("data/long_tetrahedron.off", 0.04);
test_OBB_of_mesh("data/reference_tetrahedron.off", 1);
// degenerate cases
test_OBB_of_mesh("data/triangles.off", 0); // 2D data set
test_OBB_of_mesh("data/flat_mesh.off", 0); // 2D data set
test_OBB_of_point_set("data/points_2D.xyz", 0); // 2D data set
test_OBB_of_point_set("data/points_1D.xyz", 0); // 1D data set
test_OBB_of_point_set("data/points_0D.xyz", 0); // 0D data set
std::cout << "Done!" << std::endl;
return 0;
}