forked from krm15/Powercrust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPowerCrustSurfaceReconstruction.cxx
11977 lines (10097 loc) · 423 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
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkPowerCrustSurfaceReconstruction.cxx,v $
Language: C++
Date: $Date: 2002/07/11 15:05:51 $
Version: $Revision: 1.4 $
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPowerCrustSurfaceReconstruction.h"
#include "vtkFloatArray.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkDataObject.h"
#include "vtkSmartPointer.h"
vtkStandardNewMacro(vtkPowerCrustSurfaceReconstruction);
vtkPowerCrustSurfaceReconstruction::vtkPowerCrustSurfaceReconstruction()
{
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
this->medial_surface = vtkPolyData::New();
m_estimate_r = 0.6; // EPRO-added to change the default value
}
vtkPowerCrustSurfaceReconstruction::~vtkPowerCrustSurfaceReconstruction()
{
this->medial_surface->Delete();
}
//=================================================================================================
/* -----------------------------------------------------------------
"Porting PowerCrust to VTK"
or
"The Things We Do for Fun These Days"
Tim J. Hutton 28/6/2002
T.Hutton@eastman.ucl.ac.uk
Some history:
Nina Amenta et al. came up with a lovely algorithm for surface
reconstruction - the PowerCrust. With humbling generosity they made
their code available to the world, under the GNU Public License.
To make it easier to use for everyone, I (with much encouragement
and help from many others) decided to port it to VTK. This is that story.
The original code can be found at:
http://www.cs.utexas.edu/users/amenta/powercrust/welcome.html
Getting it to compile and run on my Windows box was fun. Notes on how to
do this can be found at the bottom of this file.
Getting it to compile under VTK was a battle and a half. The word 'beast'
doesn't begin to describe it. A lot of little changes were necessary, many
of them concerned with getting rid of the use of files as temporary
storage. More details are at the bottom of this file.
The powercrust code includes robust routines for computing voronoi triangularizations.
I wanted to make this available for other routines in VTK but was beaten back
by the thicket. It would take a better person than I to make this useful elsewhere.
It is a sign of defeat that I've munged the source files into one - it does makes
it neater from a VTK point of view since there is only one file.
------------------------------------------------------------------- */
/* -----------------------------------------------------------------
Modification of Tim's VTK port
by Dieter Pfeffer d.pfeffer@eprosoft.de
and Oliver Moss o.moss@eprosoft.de
10/06/03
all changed sourcecode is mentioned with EPRO
modifications:
- to change est_r - because this value has a great influence on the output
GetEstimate_r ()
SetEstimate_r (double)
- to implement an init function to reuse an instance of the filter for doing surface reconstruction again
void pcInit ();
it's running but not all global or static variables are reinitialized - some functional
static variables are set global to reinitialize these variables
still Memory leaks
--------------------------------------------------------------------- */
// 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
vtkDataSet* vtk_input;
vtkPolyData* vtk_output;
vtkPolyData* vtk_medial_surface;
// some hacks to enable us to have useful error reporting
vtkPowerCrustSurfaceReconstruction *our_filter;
void ASSERT(int b,const char* message="") {
if(!b)
our_filter->Error(message);
}
void vtkPowerCrustSurfaceReconstruction::Error(const char *message)
{
vtkErrorMacro(<<"ASSERT:"<<message);
}
int pcFALSE = (1==0);
int pcTRUE = (1==1);
void pcInit (); // EPRO added
void free_heap (); // EPRO added
//========points.h=============================================================
/*
* Power Crust software, by Nina Amenta, Sunghee Choi and Ravi Krishna Kolluri.
* Copyright (c) 2000 by the University of Texas
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee under the GNU Public License is hereby granted,
* provided that this entire notice is included in all copies of any software
* which is or includes a copy or modification of this software and in all copies
* of the supporting documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#ifndef PNTSH
#define PNTSH 1
typedef double Coord;
typedef Coord* point;
extern int pdim; /* point dimension */
#endif
//========pointsites.h=============================================================
/*
* Power Crust software, by Nina Amenta, Sunghee Choi and Ravi Krishna Kolluri.
* Copyright (c) 2000 by the University of Texas
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee under the GNU Public License is hereby granted,
* provided that this entire notice is included in all copies of any software
* which is or includes a copy or modification of this software and in all copies
* of the supporting documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#ifndef PNTSTSH
#define PNTSTSH 1
#define MAXBLOCKS 10000
typedef point site;
typedef Coord* normalp;
point site_blocks[MAXBLOCKS];
int num_blocks;
#endif
//========stormacs.h=============================================================
/*
* Ken Clarkson wrote this. Copyright (c) 1995 by AT&T..
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#define max_blocks 10000
#define Nobj 10000
#define STORAGE_GLOBALS(X) \
\
extern size_t X##_size; \
extern X *X##_list; \
extern X *new_block_##X(int); \
extern void flush_##X##_blocks(void); \
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[max_blocks]; \
X *xlm, *xbt; \
static int num_##X##_blocks; \
if (make_blocks) { \
assert(num_##X##_blocks<max_blocks); \
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 free_simp(s) \
{ mod_refs(dec,s); \
FREEL(basis_s,s->normal); \
FREEL(simplex, s); \
} \
#define copy_simp(new,s) \
{ NEWL(simplex,new); \
memcpy(new,s,simplex_size); \
mod_refs(inc,s); \
} \
#if 0
STORAGE_GLOBALS(type)
STORAGE(type)
NEWL(type,xxx)
FREEL(type,xxx)
dec_ref(type,xxxx)
inc_ref(type,xxxx)
NULLIFY(type,xxxx)
#endif
//========hull.h=============================================================
/* hull.h */
// Some small changes made by Tim J. Hutton trying to port the code into VTK...
/*
* Power Crust software, by Nina Amenta, Sunghee Choi and Ravi Krishna Kolluri.
* Copyright (c) 2000 by the University of Texas
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee under the GNU Public License is hereby granted,
* provided that this entire notice is included in all copies of any software
* which is or includes a copy or modification of this software and in all copies
* of the supporting documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
/*
* This file is a significant modification of Ken Clarkson's file hull.h
* We include his copyright notice in accordance with its terms.
* - Nina, Sunghee and Ravi
*/
/*
* Ken Clarkson wrote this. Copyright (c) 1995 by AT&T..
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#ifndef HDR
#define HDR 1
//#include "points.h" TJH: we've munged this file into this one
//#include "stormacs.h" TJH: we've munged this file into this one
#define MAXDIM 8
#define BLOCKSIZE 100000
//#define MAXBLOCKS 1000 TJH: defined above
#define DEBUG -7
#define CHECK_OVERSHOOT 1
#define EXACT 1 /* sunghee */
#define NRAND 5 /* number of random points chosen to check orientation */
#define SMALL_ENOUGH .0001
#define MAXNF 100 /* max number of conv hull triangles adjacent to a vertex */
#define MAXTA 100000
#define MAXTEMPA 100000
#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 PSLV -2 /* probably sliver */
#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 NONE -1
#define FIRST 0
#define NO 1
#define DEG -1
#define NORM 2
#define VOR 3
#define VOR_NORM 4
#define SLVT 7
#define PSLVT 8
#define SURF 5
#define OPP 6
#define FIRST_EDGE 0
#define POW 1
#define NOT_POW 2
#define VISITED 3
/*RAVI */
#define VALIDEDGE 24
#define INVALIDEDGE 23
#define INEDGE 25
#define OUTEDGE 26
#define ADDAXIS 13
#define PRESENT 19
#define FIXED 20
#define REMOVED 21 /* for the thinning stuff */
/* for priority queue */
#define LEFT(i) ((i)*2)
#define RIGHT(i) ((i)*2+1)
#define PARENT(i) ((i)/2)
extern char tmpfilenam[L_tmpnam];
extern short check_overshoot_f;
// TJH: stripping out all file use
//FILE* efopen(char *, char *);
//void efclose(FILE* file);
extern FILE *DFILE;
static int messcount=0; // EPRO set to global (local removed from warning) to give the same warnings to all runs
#define DEBS(qq) {if (DEBUG>qq) {
#define EDEBS }}
#define DEBOUT DFILE
#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 DEBTR(ll) DEBS(ll) if(DEBOUT){fprintf(DEBOUT, __FILE__ " line %d \n" ,__LINE__);fflush(DEBOUT);} EDEBS
#define warning(lev, x) \
{ if (++messcount<=10) {DEB(lev,x) DEBTR(lev)} \
if (messcount==10) DEB(lev, consider yourself warned) \
} \
#define SBCHECK(s) /* \
{double Sb_check=0; \
int i; \
for (i=1;i<cdim;i++) if (s->neigh[i].basis) \
Sb_check+=s->neigh[i].basis->sqb; \
if ((float)(Sb_check - s->Sb) !=0.0) \
{DEBTR DEB(bad Sb); DEBEXP(s->Sb) DEBEXP(Sb_check);print_simplex(s); exit(1);}}*/\
typedef point site;
extern site p; /* the current site */
extern Coord infinity[10]; /* point at infinity for Delaunay triang */
extern 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 */
point_size; /* size of malloc needed for a point */
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;
STORAGE_GLOBALS(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 {
struct simplex *next; /* used in free list */
short mark;
site vv; /* Voronoi vertex of simplex ; sunghee */
double sqradius; /* squared radius of Voronoi ball */
/* site av; */ /* averaged pole */
/* double cond; */
/* float Sb; */
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;
STORAGE_GLOBALS(simplex)
/* Ravi: for the thinning stuff */
/* represent a node in the graph */
typedef struct spole { /* simple version to rep neighbors */
long index;
struct spole *next;
} snode;
typedef struct vpole{
long index; /* index of the node */
long pindex; /* index in the actual list of poles */
double px;
double py;
double pz;
double pr; /* the radius of the ball centered here */
double perpma; /* perpendicular distance from sample to medial axis */
double pw;
snode *adj;
int status; /* for thinning */
int label; /* might be useful for computing the crust again */
long substitute; /* if removed points to the substitute node */
double estlfs; /* the estimated lfs of each ball */
} vnode ;
/* edges in the powerface */
typedef struct enode {
long sindex;
long dindex;
} edge;
typedef struct fnode {
long index1;
long index2;
long index3;
} face;
/* end defn for medial axis thinning */
/* structure for list of opposite poles, opplist. */
typedef struct plist {
long pid;
double angle;
struct plist *next;
} plist;
/* regular triangulation edge, between pole pid to center of simp? */
typedef struct edgesimp {
short kth;
double angle; /* angle between balls */
struct simplex *simp;
long pid;
struct 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 {
struct 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 queuenode {
long pid;
struct queuenode *next;
} queuenode;
typedef struct temp {
struct simplex *simp;
int vertptr[3];
int novert;
/* 0,1,2,3 : 3 vertices but ts->neigh[ti].vert are vertices of triangle */
} temp;
typedef struct tarr {
int tempptr[50];
int num_tempptr;
long vert;
} tarr;
/*
typedef struct tlist {
int tempptr;
struct tlist *next;
} tlist;
*/
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 */
};
STORAGE_GLOBALS(Tree)
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;
STORAGE_GLOBALS(fg)
typedef void* visit_func(simplex *, void *);
typedef int test_func(simplex *, int, void *);
typedef void out_func(point *, int, FILE*, int);
/* Ravi thin axis */
void thinaxis();
void printaxis();
void initialize();
/* from driver, e.g., hullmain.c */
typedef site gsitef(void);
extern gsitef *get_site;
typedef long site_n(site);
extern site_n *site_num;
site get_site_offline(long); /* sunghee */
extern double bound[8][3];
void read_bounding_box(long);
extern double mult_up;
extern Coord mins[MAXDIM], maxs[MAXDIM];
typedef short zerovolf(simplex *);
extern double Huge;
extern double bound[8][3];
void read_bounding_box(long);
void construct_face(simplex *, short);
/* from segt.c or ch.c */
simplex *build_convex_hull(gsitef*, site_n*, short, short);
void free_hull_storage(void);
int sees(site, simplex *);
void get_normal(simplex *s);
int out_of_flat(simplex*, site);
void set_ch_root(simplex*);
void print_site(site, FILE*);
void print_normal(simplex*);
visit_func check_marks;
double find_alpha(simplex*);
test_func alph_test;
void* visit_outside_ashape(simplex*, visit_func);
void get_basis_sede(simplex *);
void compute_distance(simplex**,int,double*);
/* for debugging */
int check_perps(simplex*);
void find_volumes(fg*, FILE*);
#define MAXPOINTS 10000
extern short mi[MAXPOINTS], mo[MAXPOINTS];
/* from hull.c */
void *visit_triang_gen(simplex *, visit_func, test_func);
void *visit_triang(simplex *, visit_func);
void* visit_hull(simplex *, visit_func);
neighbor *op_simp(simplex *a, simplex *b);
neighbor *op_vert(simplex *a, site b);
simplex *new_simp(void);
void buildhull(simplex *);
/* from io.c */
void panic(char *fmt, ...);
typedef void print_neighbor_f(FILE*, neighbor*);
extern print_neighbor_f
print_neighbor_full,
print_neighbor_snum;
void check_triang(simplex*);
short is_bound(simplex *);
void check_new_triangs(simplex *);
void print_extra_facets(void);
void *print_facet(FILE*, simplex*, print_neighbor_f*);
void print_basis(FILE*, basis_s*);
void *print_simplex_f(simplex*, FILE*, print_neighbor_f*);
void *print_simplex(simplex*, void*);
void print_triang(simplex*, FILE*, print_neighbor_f*);
out_func vlist_out, ps_out, cpr_out, mp_out, off_out, vv_out;
/* sunghee : added vlist_out */
/* functions for different formats */
/* added compute axis RAVI */
visit_func facets_print, afacets_print, ridges_print,
compute_vv, compute_pole1, compute_pole2, test_surface,
compute_2d_power_vv, compute_3d_power_vv, compute_3d_power_edges,compute_axis;
/* to print facets, alpha facets, ridges */
/* Sunghee added compute_cc, compute_pole1, compute_pole2, test_surface */
void test_temp();
/* Nina's functions in crust.c */
short is_bound(simplex *);
int close_pole(double*,double*,double);
int antiLabel(int);
int cantLabelAnything(int);
void labelPole(int,int);
void newOpposite(int, int, double);
double computePoleAngle(simplex*, simplex*, double*);
void outputPole(/* TJH FILE*, FILE*, */simplex*, int, double*, int*,double);
void print_edge_dat(fg *, FILE *);
/* from pointops.c */
void print_point(FILE*, int, point);
void print_point_int(FILE*, int, point);
Coord maxdist(int,point p1, point p2);
/* from rand.c */
double double_rand(void);
void init_rand(long seed);
/* from fg.c, for face graphs */
fg *build_fg(simplex*);
void print_fg(fg*, FILE *);
void print_fg_alt(fg*, FILE *, int);
void print_hist_fg(simplex *, fg*, FILE *);
/* void arena_check(void); */ /* from hobby's debugging malloc */
/* from predicates.c, math.c */
void normalize(double*);
double sqdist(double*, double*);
void dir_and_dist(double*, double*, double*, double*);
double dotabac(double*, double*, double*);
double maxsqdist(double*, double*, double*, double*);
double dotabc(double*, double*, double*);
void crossabc(double*, double*, double*, double*);
void tetcircumcenter(double*, double*, double*, double*, double*,double*);
void tricircumcenter3d(double*, double*, double*, double*,double*);
void exactinit();
double orient3d(double*, double*, double*, double*);
double orient2d(double*, double*, double*);
/* heap.c */
typedef struct heap_array {
int pid;
double pri;
} heap_array;
void init_heap(int);
void heapify(int);
int extract_max();
int insert_heap(int , double);
void update(int , double);
/* label.c */
void opp_update(int);
void sym_update(int);
void update_pri(int,int);
int propagate();
void label_unlabeled(int);
/*power.c */
int correct_orientation(double*,double*,double*,double*,double*);
#endif
//========tim_defs.h=============================================================
#define random rand
#define srandom srand
/* TJH: old attempts at solving compilation problem (don't work on other OS's)
int random() { return rand(); }
void srandom(int s) { srand(s); }
/* TJH: these were put here to allow compiling under windows, getting problems on other OS's now
#define popen _popen
#define pclose _pclose*/
//========rand48.h=============================================================
/*
* Copyright (c) 1993 Martin Birgmeier
* All rights reserved.
*
* You may redistribute unmodified or modified versions of this source
* code provided that the above copyright notice and this and the
* following conditions are retained.
*
* This software is provided ``as is'', and comes with no warranties
* of any kind. I shall in no event be liable for anything that happens
* to anyone/anything when using this software.
*
* $OpenBSD: rand48.h,v 1.2 1996/08/19 08:33:45 tholo Exp $
*/
#ifndef _RAND48_H_
#define _RAND48_H_
#include <math.h>
#include <stdlib.h>
void _dorand48(unsigned short xseed[3]);
//void __dorand48(unsigned short xseed[3]);
//void __dorand48 __P((unsigned short[3]));
#define RAND48_SEED_0 (0x330e)
#define RAND48_SEED_1 (0xabcd)
#define RAND48_SEED_2 (0x1234)
#define RAND48_MULT_0 (0xe66d)
#define RAND48_MULT_1 (0xdeec)
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
#endif /* _RAND48_H_ */
//========hullmain.c=============================================================
// Some modifications made by Tim J. Hutton (T.Hutton@eastman.ucl.ac.uk) as TJH
/*
* Power Crust software, by Nina Amenta, Sunghee Choi and Ravi Krishna Kolluri.
* Copyright (c) 2000 by the University of Texas
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee under the GNU Public License is hereby granted,
* provided that this entire notice is included in all copies of any software
* which is or includes a copy or modification of this software and in all copies
* of the supporting documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
/*
* This file is a significant modification of Ken Clarkson's file hullmain.c.
* We include his copyright notice in accordance with its terms.
* - Nina, Sunghee and Ravi
*/
/*
* Ken Clarkson wrote this. Copyright (c) 1995 by AT&T..
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#include <float.h>
#include <math.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
//#include <getopt.h> TJH: we no longer need option handling
#include <ctype.h>
#define POINTSITES 1
//#include "hull.h" TJH: this file is above
//#include "tim_defs.h" TJH: this file is above
double bound[8][3], omaxs[3], omins[3]; /* 8 vertices for bounding box */
//point site_blocks[MAXBLOCKS]; TJH: this is declared above
//int num_blocks; TJH: this is declared above
extern int numfaces;
struct queuenode *queue;
struct queuenode *qend;
int num_vtxs=0, num_faces=0;
/* Data structures for poles */
struct simplex **pole1, **pole2; /* arrays of poles - per sample*/
struct polelabel *adjlist; /* array of additional info - per pole */
struct plist **opplist; /* opposite pid and angle between poles - per pole */
double* lfs_lb; /* array of lower bounds for lfs of each sample */
double est_r = 0.6; /* estimated value of r - user input */
int num_poles=0,num_axedgs=0,num_axfaces=0;
double *pole1_distance,*pole2_distance;
/* for priority queue */
extern int heap_size;