1 | #include <math.h>
|
---|
2 | #include "Leaf.h"
|
---|
3 |
|
---|
4 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
5 | // Void constructor
|
---|
6 | // Parameters --> None
|
---|
7 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
8 | Leaf::Leaf(void)
|
---|
9 | {
|
---|
10 | vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] =0;
|
---|
11 | center[0] = center[1] = center[2] = 0;
|
---|
12 | normal[0] = normal[1] = normal[2] = 0;
|
---|
13 | leafNear=-1;
|
---|
14 | parentLeafCount = 1;
|
---|
15 | dist = -1;
|
---|
16 | coplanar = -1;
|
---|
17 | criteria = -1;
|
---|
18 | leafCop = -1;
|
---|
19 | leafCrit =-1;
|
---|
20 | exists = false;
|
---|
21 | parent=-1;
|
---|
22 | childLeft = childRight = -1;
|
---|
23 | root = visible= -1;
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
28 | // Copy constructor
|
---|
29 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
30 | Leaf::Leaf (const Leaf& aLeaf)
|
---|
31 | {
|
---|
32 | parentLeafCount = aLeaf.parentLeafCount;;
|
---|
33 | leafNear = aLeaf.leafNear;
|
---|
34 | leafCrit = aLeaf.leafCrit;
|
---|
35 | dist = aLeaf.dist;
|
---|
36 | exists = aLeaf.exists;
|
---|
37 | coplanar = aLeaf.coplanar;
|
---|
38 | leafCop = aLeaf.leafCop;
|
---|
39 | criteria = aLeaf.criteria;
|
---|
40 | for ( int i=0;i<3;i++){
|
---|
41 | center[i] = aLeaf.center[i];
|
---|
42 | normal[i] = aLeaf.normal[i];
|
---|
43 | }
|
---|
44 | for (i = 0L; i < 4; i++)
|
---|
45 | vertsLeaf[i] = aLeaf.vertsLeaf[i];
|
---|
46 |
|
---|
47 | parent = aLeaf.parent;
|
---|
48 | childLeft = aLeaf.childLeft;
|
---|
49 | childRight = aLeaf.childRight;
|
---|
50 | visible = aLeaf.visible;
|
---|
51 | root = aLeaf.root;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
57 | // Destructor. We must deallocate the memory allocated for pointers to vertices and edges
|
---|
58 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
59 | Leaf::~Leaf (void)
|
---|
60 | {
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
65 | // CALCULA LA DISTANCIA ENTRE HOJAS
|
---|
66 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
67 |
|
---|
68 | float Leaf::Distance (Leaf& leaf)
|
---|
69 | {
|
---|
70 | float dist =0;
|
---|
71 | float x1,y1,z1;
|
---|
72 |
|
---|
73 | x1 = leaf.center[0]; y1 = leaf.center[1] ; z1 = leaf.center[2];
|
---|
74 |
|
---|
75 |
|
---|
76 | //DISTANCIA BETWEEN CENTERS
|
---|
77 |
|
---|
78 | dist = ((center[0]-x1)*(center[0]-x1)) + ((center[1]-y1)*(center[1]-y1)) + ((center[2]-z1)*(center[2]-z1));
|
---|
79 |
|
---|
80 | return dist;
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
85 | // CALCULA LA COPLANARIDAD ENTRE HOJAS
|
---|
86 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
87 |
|
---|
88 | float Leaf::Coplanarity (Leaf& leaf)
|
---|
89 | {
|
---|
90 | float cop =0;
|
---|
91 | float modulo1, modulo2;
|
---|
92 | float x1,y1,z1, nx1, ny1, nz1;
|
---|
93 | float nx, ny, nz;
|
---|
94 |
|
---|
95 | //hoja pasada como parametro, normalizo las componentes
|
---|
96 | x1 = leaf.normal[0]; y1 = leaf.normal[1] ; z1 = leaf.normal[2];
|
---|
97 | modulo1 = sqrt ( (x1*x1) + (y1*y1) + (z1*z1));
|
---|
98 | nx1 = x1 / modulo1;
|
---|
99 | ny1 = y1 / modulo1;
|
---|
100 | nz1 = z1 / modulo1;
|
---|
101 |
|
---|
102 | // hoja desde la que llamo
|
---|
103 |
|
---|
104 | modulo2 = sqrt ( (normal[0]*normal[0]) + (normal[1]*normal[1]) + (normal[2]*normal[2]));
|
---|
105 | nx = normal[0] / modulo2;
|
---|
106 | ny = normal[1] / modulo2;
|
---|
107 | nz = normal[2] / modulo2;
|
---|
108 |
|
---|
109 | // producto escalar : si es proximo a 0, perpendiculares, a 1, coplanares
|
---|
110 |
|
---|
111 | cop = (nx1*nx) + (ny1*ny) + (nz1*nz);
|
---|
112 |
|
---|
113 |
|
---|
114 | return (fabs(cop));
|
---|
115 |
|
---|
116 | }
|
---|
117 |
|
---|