-
Notifications
You must be signed in to change notification settings - Fork 15
/
vtkPowerCrustSurfaceReconstruction.cxx
4551 lines (3948 loc) · 126 KB
/
vtkPowerCrustSurfaceReconstruction.cxx
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
/*=========================================================================
vtkPowerCrustSurfaceReconstruction algorithm reconstructs surfaces from
unorganized point data.
Copyright (C) 2017 Arash Akbarinia, Tim Hutton, Bruce Lamond
Dieter Pfeffer, Oliver Moss, Alessandro Volz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=========================================================================*/
#include "vtkPowerCrustSurfaceReconstruction.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include <assert.h>
#include <float.h>
//=====================================================================
class vtkPowerCrustSurfaceReconstructionException : public std::exception
{
public:
vtkPowerCrustSurfaceReconstructionException ( const char* m = "vtkPowerCrustSurfaceReconstructionException!" ) : msg ( m ) { }
~vtkPowerCrustSurfaceReconstructionException() throw() {}
virtual const char* what() const throw()
{
return msg;
}
private:
const char* msg;
};
//=====================================================================
typedef double Coord;
typedef Coord* point;
typedef point site;
#define MAXBLOCKS 10000
#define Nobj 10000
#define STORAGE_GLOBALS(X) \
\
extern size_t X##_size; \
extern X *X##_list; \
extern X *new_block_##X(int); \
void free_##X##_storage(void); \
#define INCP(X,p,k) ((X*) ( (char*)p + (k) * X##_size)) /* portability? */
#define STORAGE(X) \
\
size_t X##_size; \
X *X##_list = 0; \
\
X *new_block_##X(int make_blocks) \
{ int i; \
static X *X##_block_table[MAXBLOCKS]; \
X *xlm, *xbt; \
static int num_##X##_blocks; \
if (make_blocks) { \
assert(num_##X##_blocks<MAXBLOCKS); \
DEB(0, before) DEBEXP(0, Nobj * X##_size) \
\
xbt = X##_block_table[num_##X##_blocks++] = (X*)malloc(Nobj * X##_size); \
memset(xbt,0,Nobj * X##_size); \
if (!xbt) { \
DEBEXP(-10,num_##X##_blocks) \
} \
assert(xbt); \
\
xlm = INCP(X,xbt,Nobj); \
for (i=0;i<Nobj; i++) { \
xlm = INCP(X,xlm,(-1)); \
xlm->next = X##_list; \
X##_list = xlm; \
} \
\
return X##_list; \
} \
\
for (i=0; i<num_##X##_blocks; i++) \
free(X##_block_table[i]); \
num_##X##_blocks = 0; \
X##_list = 0; \
return 0; \
} \
\
void free_##X##_storage(void) {new_block_##X(0);} \
/*end of STORAGE*/
#define NEWL(X,p) \
{ \
p = X##_list ? X##_list : new_block_##X(1); \
assert(p); \
X##_list = p->next; \
} \
#define NEWLRC(X,p) \
{ \
p = X##_list ? X##_list : new_block_##X(1); \
assert(p); \
X##_list = p->next; \
p->ref_count = 1; \
} \
#define FREEL(X,p) \
{ \
memset((p),0,X##_size); \
(p)->next = X##_list; \
X##_list = p; \
} \
#define dec_ref(X,v) {if ((v) && --(v)->ref_count == 0) FREEL(X,(v));}
#define inc_ref(X,v) {if (v) v->ref_count++;}
#define NULLIFY(X,v) {dec_ref(X,v); v = NULL;}
#define mod_refs(op,s) \
{ \
int i; \
neighbor *mrsn; \
\
for (i=-1,mrsn=s->neigh-1;i<cdim;i++,mrsn++) \
op##_ref(basis_s, mrsn->basis); \
}
#define copy_simp(new,s) \
{ NEWL(simplex,new); \
memcpy(new,s,simplex_size); \
mod_refs(inc,s); \
} \
#define DEBS(qq) {if (DEBUG>qq) {
#define EDEBS }}
#define DEBOUT 0
#define DEB(ll,mes) DEBS(ll) if(DEBOUT){fprintf(DEBOUT,#mes "\n");fflush(DEBOUT);} EDEBS
#define DEBEXP(ll,exp) DEBS(ll) if(DEBOUT){fprintf(DEBOUT,#exp "=%G\n", (double) exp); fflush(DEBOUT);} EDEBS
#define MAXDIM 8
#define BLOCKSIZE 100000
#define DEBUG -7
#define EXACT 1 /* sunghee */
#define CNV 0 /* sunghee : status of simplex, if it's on convex hull */
#define VV 1 /* sunghee : if it's regular simplex */
#define SLV -1 /* sunghee : if orient3d=0, sliver simplex */
#define AV 2 /* if av contains the averaged pole vector */
#define POLE_OUTPUT 3 /* VV is pole and it's ouput */
#define SQ(a) ((a)*(a)) /* sunghee */
#define BAD_POLE -1
// next two lines added by TJH to avoid name collision
#undef IN
#undef OUT
#define IN 2
#define OUT 1
#define INIT 0
#define NO 1
#define FIRST_EDGE 0
#define POW 1
#define VISITED 3
#define VALIDEDGE 24
#define ADDAXIS 13
/* for priority queue */
#define LEFT(i) ((i) * 2)
#define RIGHT(i) ((i) * 2 + 1)
#define PARENT(i) ((i) / 2)
typedef struct basis_s
{
struct basis_s *next; /* free list */
int ref_count; /* storage management */
int lscale; /* the log base 2 of total scaling of vector */
Coord sqa, sqb; /* sums of squared norms of a part and b part */
Coord vecs[1]; /* the actual vectors, extended by malloc'ing bigger */
} basis_s;
typedef struct neighbor
{
site vert; /* vertex of simplex */
/* short edgestatus[3]; FIRST_EDGE if not visited
NOT_POW if not dual to powercrust faces
POW if dual to powercrust faces */
struct simplex *simp; /* neighbor sharing all vertices but vert */
basis_s *basis; /* derived vectors */
} neighbor;
typedef struct simplex
{
simplex() : isVvNull ( false ) {}
simplex *next; /* used in free list */
short mark;
double vv[3];
bool isVvNull;
double sqradius; /* squared radius of Voronoi ball */
short status;/* sunghee : 0(CNV) if on conv hull so vv contains normal vector;
1(VV) if vv points to circumcenter of simplex;
-1(SLV) if cond=0 so vv points to hull
2(AV) if av contains averaged pole */
long poleindex; /* for 1st DT, if status==POLE_OUTPUT, contains poleindex; for 2nd, contains vertex index for powercrust output for OFF file format */
short edgestatus[6]; /* edge status :(01)(02)(03)(12)(13)(23)
FIRST_EDGE if not visited
VISITED
NOT_POW if not dual to powercrust faces
POW if dual to powercrust faces */
/* short tristatus[4]; triangle status :
FIRST if not visited
NO if not a triangle
DEG if degenerate triangle
SURF if surface triangle
NORM if fails normal test
VOR if falis voronoi edge test
VOR_NORM if fails both test */
/* NOTE!!! neighbors has to be the LAST field in the simplex stucture,
since it's length gets altered by some tricky Clarkson-move.
Also peak has to be the one before it.
Don't try to move these babies!! */
long visit; /* number of last site visiting this simplex */
basis_s* normal; /* normal vector pointing inward */
neighbor peak; /* if null, remaining vertices give facet */
neighbor neigh[1]; /* neighbors of simplex */
} simplex;
/* structure for list of opposite poles, opplist. */
typedef struct plist
{
long pid;
double angle;
plist *next;
} plist;
/* regular triangulation edge, between pole pid to center of simp? */
typedef struct edgesimp
{
short kth;
double angle; /* angle between balls */
simplex *simp;
long pid;
edgesimp *next;
} edgesimp;
/* additional info about poles: label for pole, pointer to list of regular
triangulation edges, squared radius of polar ball. adjlist is an
array of polelabels. */
typedef struct polelabel
{
edgesimp *eptr;
short bad;
short label;
double in; /* 12/7/99 Sunghee for priority queue */
double out; /* 12/7/99 Sunghee for priority queue */
int hid; /* 0 if not in the heap, otherwise heap index 1..heap_size*/
double sqradius;
double oppradius; /* minimum squared radius of this or any opposite ball */
double samp_distance;
int grafindex; /* index in thinning graph data structure */
} polelabel;
typedef struct fg_node fg;
typedef struct tree_node Tree;
struct tree_node
{
Tree *left, *right;
site key;
int size; /* maintained to be the number of nodes rooted here */
fg *fgs;
Tree *next; /* freelist */
};
typedef struct fg_node
{
Tree *facets;
double dist, vol; /* of Voronoi face dual to this */
fg *next; /* freelist */
short mark;
int ref_count;
} fg_node;
typedef struct heap_array
{
int pid;
double pri;
} heap_array;
STORAGE_GLOBALS ( basis_s )
STORAGE_GLOBALS ( fg )
STORAGE_GLOBALS ( Tree )
STORAGE_GLOBALS ( simplex )
STORAGE ( basis_s )
STORAGE ( fg )
STORAGE ( Tree )
STORAGE ( simplex )
//=====================================================================
class vtkPowerCrustSurfaceReconstructionImpl
{
private:
typedef void* ( vtkPowerCrustSurfaceReconstructionImpl::*visit_func ) ( simplex *, void * );
typedef int ( vtkPowerCrustSurfaceReconstructionImpl::*test_func ) ( simplex *, int, void * );
void ASSERT ( int b, const char* message = "" );
int pcFALSE;
int pcTRUE;
site p;
std::vector<point> site_blocks;
std::vector<point> site_blocks_pointers;
int num_blocks;
int pdim;
Coord infinity[10]; /* point at infinity for Delaunay triang */
int rdim, /* region dimension: (max) number of sites specifying region */
cdim, /* number of sites currently specifying region */
site_size; /* size of malloc needed for a site */
site get_site_offline ( long );
double bound[8][3];
double mult_up;
Coord mins[MAXDIM];
Coord maxs[MAXDIM];
double Huge;
void read_bounding_box ( long );
void construct_face ( simplex *, short );
void compute_distance ( simplex**, int, double* );
#define MAXPOINTS 10000
short mi[MAXPOINTS], mo[MAXPOINTS];
int correct_orientation ( double*,double*,double*,double*,double* );
#ifndef _RAND48_H_
#define _RAND48_H_
void _dorand48 ( unsigned short xseed[3] );
#define RAND48_MULT_0 (0xe66d)
#define RAND48_MULT_1 (0xdeec)
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
#endif /* _RAND48_H_ */
double omaxs[3], omins[3]; /* 8 vertices for bounding box */
int num_vtxs;
int num_poles;
/* Data structures for poles */
simplex **pole1, **pole2; /* arrays of poles - per sample*/
std::vector<polelabel> adjlist;
std::vector<plist*> opplist;
double* lfs_lb; /* array of lower bounds for lfs of each sample */
double est_r; /* estimated value of r - user input */
double *pole1_distance, *pole2_distance;
/* for priority queue */
int heap_size;
int scount;
int v1[6];
int v2[6];
int v3[6];
int v4[6];
long num_sites;
short vd_new;
short power_diagram; /* 1 if power diagram */
int dim;
long s_num; /* site number */
double theta; /* input argument - angle defining deep intersection */
double deep; /* input argument.. same as theta for labeling unlabled pole */
long site_numm ( site p );
site new_site ( site p, long j );
// TJH: trying to replace file use
site vtk_read_next_site ( long j );
site vtk_pole_read_next_site ( long j );
std::vector<long> shufmat;
long mat_size; // EPRO set to global to reinitialize
void make_shuffle ( void );
long shufflef ( long i );
long ( vtkPowerCrustSurfaceReconstructionImpl::*shuf ) ( long );
long ( vtkPowerCrustSurfaceReconstructionImpl::*site_num ) ( site );
site ( vtkPowerCrustSurfaceReconstructionImpl::*get_site ) ( );
site ( vtkPowerCrustSurfaceReconstructionImpl::*get_site_n ) ( long );
site get_next_site ( void );
void make_output ( simplex *root, void * ( vtkPowerCrustSurfaceReconstructionImpl::*visit_gen ) ( simplex*, visit_func ), visit_func visit );
neighbor p_neigh; // EPRO added set to global
basis_s *seesB;
simplex **st_search;
simplex **st_visit_triang_gen;
basis_s *check_perps_b;
#define swap_points(a,b) {point t; t=a; a=b; b=t;}
double alpha_test_alpha;
/* variables for tracking infinite loop */
/* (This should never occur, but it did in early versions) */
int loopStart;
int count;
int lastCount;
#define compare(i,j) (( this->*site_num )(i)-( this->*site_num )(j))
#define node_size(x) ((x) ? ((x)->size) : 0 )
heap_array *heap_A;
int heap_length;
long pnum;
#define push(x, st, tms) *(st + tms++) = x;
#define pop(x, st, tms) x = *(st + --tms);
long visit_triang_gen_vnum;
long visit_triang_gen_ss;
simplex *make_facets_ns;
long search_ss;
simplex *ch_root;
#define NEARZERO(d) ((d) < FLT_EPSILON && (d) > -FLT_EPSILON)
#define SWAP(X,a,b) {X t; t = a; a = b; b = t;}
#define DELIFT 0
int basis_vec_size;
int exact_bits;
float b_err_min, b_err_min_sq;
short vd;
basis_s tt_basis;
basis_s *tt_basisp;
basis_s *infinity_basis;
#define VA(x) ((x)->vecs+rdim)
#define VB(x) ((x)->vecs)
#define two_to(x) ( ((x)<20) ? 1<<(x) : ldexp(1.0,(x)) ) // EPRO added
int sc_lscale;
double sc_max_scale, sc_ldetbound, sc_Sb;
Coord Vec_dot ( point x, point y );
Coord Vec_dot_pdim ( point x, point y );
Coord Norm2 ( point x );
void Ax_plus_y ( Coord a, point x, point y );
void Ax_plus_y_test ( Coord a, point x, point y );
void Vec_scale_test ( int n, Coord a, Coord *x );
double sc ( basis_s *v,simplex *s, int k, int j );
int reduce_inner ( basis_s *v, simplex *s, int k );
void trans ( point z, point p, point q );
#define lift(z,s) {if (vd) z[2*rdim-1] =z[rdim-1]= ldexp(Vec_dot_pdim(z,z), -DELIFT);}
int reduce ( basis_s **v, point p, simplex *s, int k );
void get_basis_sede ( simplex *s );
int out_of_flat ( simplex *root, point p );
double cosangle_sq ( basis_s* v,basis_s* w );
int check_perps ( simplex *s );
void get_normal_sede ( simplex *s );
void get_normal ( simplex *s );
int sees ( site p, simplex *s );
double radsq ( simplex *s );
void* zero_marks ( simplex* s, void* dum );
void* one_marks ( simplex* s, void* dum );
void* conv_facetv ( simplex* s, void* dum );
void* mark_points ( simplex* s, void* dum );
int alph_test ( simplex *s, int i, void *alphap );
void* visit_outside_ashape ( simplex *root, visit_func visit );
int check_ashape ( simplex *root, double alpha );
simplex *build_convex_hull ( short dim, short vdd );
void free_hull_storage ( void );
void *compute_vv ( simplex *s, void *p );
void *compute_pole2 ( simplex *s, void *p );
void *compute_3d_power_vv ( simplex *s, void *p );
void *compute_axis ( simplex *s, void *p );
int close_pole ( double* v, double* p, double lfs_lb );
int antiLabel ( int label );
/* computes angle between two opposite poles */
double computePoleAngle ( simplex* pole1, simplex* pole2, double* samp );
/* Adds a new pair of opposite poles to each other's lists */
void newOpposite ( int p1index, int p2index, double pole_angle );
/* Outputs a pole, saving it's squared radius in adjlist */
void outputPole ( simplex* pole, int poleid, double* samp, int* num_poles,double distance );
/* Splay using the key i (which may or may not be in the tree.) */
/* The starting root is t, and the tree used is defined by rat */
/* size fields are maintained */
Tree * splay ( site i, Tree *t );
Tree * insert ( site i, Tree * t );
void free_heap ();
void init_heap ( int num );
void heapify ( int hi );
int extract_max();
int insert_heap ( int pi, double pr );
/* make the element heap_A[hi].pr = pr ... */
void update ( int hi, double pr );
void *visit_triang_gen ( simplex *s, visit_func visit, test_func test );
int truet ( simplex *s, int i, void *dum );
void *visit_triang ( simplex *root, visit_func visit );
int hullt ( simplex *s, int i, void *dummy );
void *facet_test ( simplex *s, void *dummy );
/* visit all simplices with facets of the current hull */
void *visit_hull ( simplex *root, visit_func visit );
#define lookup(a, b, what) \
{ \
int i; \
neighbor *x; \
for (i = 0, x = a->neigh; (x->what != b) && (i < cdim) ; i++, x++); \
if (i < cdim) \
return x; \
else { \
ASSERT(pcFALSE, "adjacency failure!"); \
return 0; \
} \
} \
neighbor *op_simp ( simplex *a, simplex *b );
neighbor *op_vert ( simplex *a, site b );
void connect ( simplex *s );
simplex *make_facets ( simplex *seen );
simplex *extend_simplices ( simplex *s );
simplex *search ( simplex *root );
point get_another_site ( void );
void buildhull ( simplex *root );
int propagate();
void opp_update ( int pi );
void sym_update ( int pi );
void update_pri ( int hi, int pi );
void label_unlabeled ( int num );
double sqdist ( double a[3], double b[3] );
void dir_and_dist ( double a[3], double b[3], double dir[3], double* dist );
void tetcircumcenter ( double a[3], double b[3], double c[3], double d[3], double circumcenter[3], double *cond );
void tetorthocenter ( double a[4], double b[4], double c[4], double d[4], double orthocenter[3], double *cnum );
#define INEXACT /* Nothing */
#define REAL double /* float or double */
#define Absolute(a) ((a) >= 0.0 ? (a) : -(a))
#define Fast_Two_Sum_Tail(a, b, x, y) \
bvirt = x - a; \
y = b - bvirt
#define Fast_Two_Sum(a, b, x, y) \
x = (REAL) (a + b); \
Fast_Two_Sum_Tail(a, b, x, y)
#define Two_Sum_Tail(a, b, x, y) \
bvirt = (REAL) (x - a); \
avirt = x - bvirt; \
bround = b - bvirt; \
around = a - avirt; \
y = around + bround
#define Two_Sum(a, b, x, y) \
x = (REAL) (a + b); \
Two_Sum_Tail(a, b, x, y)
#define Two_Diff_Tail(a, b, x, y) \
bvirt = (REAL) (a - x); \
avirt = x + bvirt; \
bround = bvirt - b; \
around = a - avirt; \
y = around + bround
#define Two_Diff(a, b, x, y) \
x = (REAL) (a - b); \
Two_Diff_Tail(a, b, x, y)
#define Split(a, ahi, alo) \
c = (REAL) (splitter * a); \
abig = (REAL) (c - a); \
ahi = c - abig; \
alo = a - ahi
#define Two_Product_Tail(a, b, x, y) \
Split(a, ahi, alo); \
Split(b, bhi, blo); \
err1 = x - (ahi * bhi); \
err2 = err1 - (alo * bhi); \
err3 = err2 - (ahi * blo); \
y = (alo * blo) - err3
#define Two_Product(a, b, x, y) \
x = (REAL) (a * b); \
Two_Product_Tail(a, b, x, y)
/* Two_Product_Presplit() is Two_Product() where one of the inputs has */
/* already been split. Avoids redundant splitting. */
#define Two_Product_Presplit(a, b, bhi, blo, x, y) \
x = (REAL) (a * b); \
Split(a, ahi, alo); \
err1 = x - (ahi * bhi); \
err2 = err1 - (alo * bhi); \
err3 = err2 - (ahi * blo); \
y = (alo * blo) - err3
/* Macros for summing expansions of various fixed lengths. These are all */
/* unrolled versions of Expansion_Sum(). */
#define Two_One_Diff(a1, a0, b, x2, x1, x0) \
Two_Diff(a0, b , _i, x0); \
Two_Sum( a1, _i, x2, x1)
#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \
Two_One_Diff(a1, a0, b0, _j, _0, x0); \
Two_One_Diff(_j, _0, b1, x3, x2, x1)
#define Two_One_Product(a1, a0, b, x3, x2, x1, x0) \
Split(b, bhi, blo); \
Two_Product_Presplit(a0, b, bhi, blo, _i, x0); \
Two_Product_Presplit(a1, b, bhi, blo, _j, _0); \
Two_Sum(_i, _0, _k, x1); \
Fast_Two_Sum(_j, _k, x3, x2)
REAL splitter; /* = 2^ceiling(p / 2) + 1. Used to split floats in half. */
REAL epsilon; /* = 2^(-p). Used to estimate roundoff errors. */
/* A set of coefficients used to calculate maximum roundoff errors. */
REAL resulterrbound;
REAL ccwerrboundA, ccwerrboundB, ccwerrboundC;
REAL o3derrboundA, o3derrboundB, o3derrboundC;
void exactinit();
int fast_expansion_sum_zeroelim ( int elen,REAL *e,int flen,REAL *f,REAL *h );
int scale_expansion_zeroelim ( int elen,REAL *e,REAL b,REAL *h );
REAL estimate ( int elen, REAL *e );
REAL orient2dadapt ( REAL* pa, REAL* pb, REAL* pc, REAL detsum );
REAL orient3dadapt ( REAL* pa, REAL* pb, REAL* pc, REAL* pd, REAL permanent );
REAL orient3d ( REAL* pa, REAL* pb, REAL* pc, REAL* pd );
unsigned short X[3];
double double_rand ( void );
void init_rand ( void );
double logb ( double x );
double local_erand48 ( unsigned short xseed[3] ) throw();
unsigned short _rand48_mult[3];
unsigned short _rand48_add;
public:
vtkPowerCrustSurfaceReconstructionImpl ( void );
void pcInit();
void freeAll ( void );
void adapted_main ( double m_mult_up );
// these globals are here so we can access them from anywhere in the powercrust code
// if you can find a neat way to improve this then please feel free
vtkPolyData* vtk_input;
vtkPolyData* vtk_output;
vtkPolyData* vtk_medial_surface;
// some hacks to enable us to have useful error reporting
vtkPowerCrustSurfaceReconstruction *our_filter;
};
//=====================================================================
vtkPowerCrustSurfaceReconstructionImpl::vtkPowerCrustSurfaceReconstructionImpl ( void )
{
}
long vtkPowerCrustSurfaceReconstructionImpl::site_numm ( site p )
{
if ( ( vd_new || power_diagram ) && p==infinity ) return -1;
if ( !p ) return -2;
for ( int i = 0; i<num_blocks; i++ )
{
long j;
if ( ( j = p-site_blocks[i] ) >= 0 && j < BLOCKSIZE * dim )
return j / dim + BLOCKSIZE * i;
}
return -3;
}
site vtkPowerCrustSurfaceReconstructionImpl::new_site ( site p, long j )
{
assert ( num_blocks + 1 < MAXBLOCKS );
if ( 0 == ( j % BLOCKSIZE ) )
{
num_blocks++;
site_blocks.resize ( num_blocks );
site_blocks[num_blocks - 1] = ( site ) malloc ( BLOCKSIZE * site_size );
site_blocks_pointers.push_back ( site_blocks[num_blocks - 1] );
return site_blocks[num_blocks - 1];
}
else
return p + dim;
}
void vtkPowerCrustSurfaceReconstructionImpl::read_bounding_box ( long j )
{
int i,k;
double center[3],width;
omaxs[0] = maxs[0];
omins[0] = mins[0];
omaxs[1] = maxs[1];
omins[1] = mins[1];
omaxs[2] = maxs[2];
omins[2] = mins[2];
center[0] = ( maxs[0] - mins[0] ) /2;
center[1] = ( maxs[1] - mins[1] ) /2;
center[2] = ( maxs[2] - mins[2] ) /2;
if ( ( maxs[0] - mins[0] ) > ( maxs[1] - mins[1] ) )
{
if ( ( maxs[2] - mins[2] ) > ( maxs[0] - mins[0] ) )
width = maxs[2] - mins[2];
else width = maxs[0] - mins[0];
}
else
{
if ( ( maxs[1] - mins[1] ) > ( maxs[2] - mins[2] ) )
width = maxs[1] - mins[1];
else width = maxs[2] - mins[2];
}
width = width * 4;
bound[0][0] = center[0] + width;
bound[1][0] = bound[0][0];
bound[2][0] = bound[0][0];
bound[3][0] = bound[0][0];
bound[0][1] = center[1] + width;
bound[1][1] = bound[0][1];
bound[4][1] = bound[0][1];
bound[5][1] = bound[0][1];
bound[0][2] = center[2] + width;
bound[2][2] = bound[0][2];
bound[4][2] = bound[0][2];
bound[6][2] = bound[0][2];
bound[4][0] = center[0] - width;
bound[5][0] = bound[4][0];
bound[6][0] = bound[4][0];
bound[7][0] = bound[4][0];
bound[2][1] = center[1] - width;
bound[3][1] = bound[2][1];
bound[6][1] = bound[2][1];
bound[7][1] = bound[2][1];
bound[1][2] = center[2] - width;
bound[3][2] = bound[1][2];
bound[5][2] = bound[1][2];
bound[7][2] = bound[1][2];
for ( k = 0; k < 3; k++ )
{
p[k] = bound[0][k];
}
for ( i = 1; i < 8; i++ )
{
p = new_site ( p, j+i );
for ( k=0; k<3; k++ )
{
p[k] = bound[i][k];
}
}
maxs[0] = bound[0][0];
mins[0] = bound[4][0];
maxs[1] = bound[0][1];
mins[1] = bound[2][1];
maxs[2] = bound[0][2];
mins[2] = bound[1][2];
}
site vtkPowerCrustSurfaceReconstructionImpl::vtk_read_next_site ( long j )
{
ASSERT ( j >= 0, "vtk_read_next_site " );
p = new_site ( p, j );
for ( int i=0; i<dim; i++ )
{
p[i] = ( double ) vtk_input->GetPoint ( j ) [i];
p[i] = floor ( mult_up*p[i]+0.5 );
mins[i] = ( mins[i]<p[i] ) ? mins[i] : p[i];
maxs[i] = ( maxs[i]>p[i] ) ? maxs[i] : p[i];
}
return p;
}
site vtkPowerCrustSurfaceReconstructionImpl::vtk_pole_read_next_site ( long j )
{
ASSERT ( j >= 0, "vtk_pole_read_next_site" );
p = new_site ( p, j );
for ( int i = 0; i < dim; i++ )
{
if ( i < 3 )
p[i] = ( double ) vtk_medial_surface->GetPoint ( j ) [i];
else
p[i] = ( double ) vtk_medial_surface->GetPointData()->GetScalars()->GetTuple1 ( j );
p[i] = floor ( mult_up*p[i]+0.5 );
mins[i] = ( mins[i]<p[i] ) ? mins[i] : p[i];
maxs[i] = ( maxs[i]>p[i] ) ? maxs[i] : p[i];
}
return p;
}
site vtkPowerCrustSurfaceReconstructionImpl::get_site_offline ( long i )
{
if ( i >= num_sites ) return NULL;
else
{
return site_blocks[i / BLOCKSIZE]+ ( i % BLOCKSIZE ) * dim;
}
}
void vtkPowerCrustSurfaceReconstructionImpl::make_shuffle ( void )
{
if ( mat_size<=num_sites )
{
mat_size = num_sites+1;
shufmat.resize ( mat_size );
}
for ( long i = 0; i <= num_sites; i++ )
{
shufmat[i] = i;
}
for ( long i = 0; i < num_sites; i++ )
{
long t = shufmat[i];
long j = i + ( long ) ( ( num_sites-i ) *double_rand() ); // cast to long added by TJH
shufmat[i] = shufmat[j];
shufmat[j] = t;
}
}
long vtkPowerCrustSurfaceReconstructionImpl::shufflef ( long i )
{
return shufmat[i];
}
site vtkPowerCrustSurfaceReconstructionImpl::get_next_site ( void )
{
return ( this->*get_site_n ) ( ( this->*shuf ) ( s_num++ ) );
}
void vtkPowerCrustSurfaceReconstructionImpl::make_output ( simplex *root, void * ( vtkPowerCrustSurfaceReconstructionImpl::*visit_gen ) ( simplex*, visit_func ), visit_func visit )
{
// ( this->*visit ) ( 0, ( void ( * ) ) out_funcp );
( this->*visit_gen ) ( root, visit );
}
void vtkPowerCrustSurfaceReconstructionImpl::ASSERT ( int b, const char* message )
{
if ( !b )
{
our_filter->Error ( message );
}
}
void vtkPowerCrustSurfaceReconstructionImpl::freeAll ( void )
{
for ( unsigned int i = 0; i < adjlist.size(); i++ )
{
edgesimp *tmpEdgesimp;
edgesimp *curEdgesimp;
curEdgesimp = adjlist[i].eptr;
while ( curEdgesimp )
{
tmpEdgesimp = curEdgesimp;
curEdgesimp = tmpEdgesimp->next;
free ( tmpEdgesimp );
}
}
for ( unsigned int i = 0; i < opplist.size(); i++ )
{
if ( opplist[i] != NULL )
{
plist *tmpPlist;
plist *curPlist;
curPlist = opplist[i];
while ( curPlist )
{
tmpPlist = curPlist;
curPlist = tmpPlist->next;
free ( tmpPlist );