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 | RuntimeLeaf::RuntimeLeaf(void)
|
---|
56 | {
|
---|
57 | vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] = 0;
|
---|
58 | parent = root = childLeft = childRight = -1;
|
---|
59 | }
|
---|
60 |
|
---|
61 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
62 | // Copy constructor
|
---|
63 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
64 | RuntimeLeaf::RuntimeLeaf (const RuntimeLeaf& aLeaf)
|
---|
65 | {
|
---|
66 | for (int i = 0L; i < 4; i++)
|
---|
67 | vertsLeaf[i] = aLeaf.vertsLeaf[i];
|
---|
68 | parent = aLeaf.parent;
|
---|
69 | childLeft = aLeaf.childLeft;
|
---|
70 | childRight = aLeaf.childRight;
|
---|
71 | root = aLeaf.root;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
76 | // CALCULA LA DISTANCIA ENTRE HOJAS
|
---|
77 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
78 |
|
---|
79 | float Leaf::Distance (Leaf& leaf)
|
---|
80 | {
|
---|
81 | float dist =0;
|
---|
82 | float x1,y1,z1;
|
---|
83 |
|
---|
84 | x1 = leaf.center[0]; y1 = leaf.center[1] ; z1 = leaf.center[2];
|
---|
85 |
|
---|
86 |
|
---|
87 | //DISTANCIA BETWEEN CENTERS
|
---|
88 |
|
---|
89 | dist = ((center[0]-x1)*(center[0]-x1)) + ((center[1]-y1)*(center[1]-y1)) + ((center[2]-z1)*(center[2]-z1));
|
---|
90 |
|
---|
91 | return dist;
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
96 | // CALCULA LA COPLANARIDAD ENTRE HOJAS
|
---|
97 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
98 |
|
---|
99 | float Leaf::Coplanarity (Leaf& leaf)
|
---|
100 | {
|
---|
101 | float cop =0;
|
---|
102 | float modulo1, modulo2;
|
---|
103 | float x1,y1,z1, nx1, ny1, nz1;
|
---|
104 | float nx, ny, nz;
|
---|
105 |
|
---|
106 | //hoja pasada como parametro, normalizo las componentes
|
---|
107 | x1 = leaf.normal[0]; y1 = leaf.normal[1] ; z1 = leaf.normal[2];
|
---|
108 | modulo1 = sqrt ( (x1*x1) + (y1*y1) + (z1*z1));
|
---|
109 | nx1 = x1 / modulo1;
|
---|
110 | ny1 = y1 / modulo1;
|
---|
111 | nz1 = z1 / modulo1;
|
---|
112 |
|
---|
113 | // hoja desde la que llamo
|
---|
114 |
|
---|
115 | modulo2 = sqrt ( (normal[0]*normal[0]) + (normal[1]*normal[1]) + (normal[2]*normal[2]));
|
---|
116 | nx = normal[0] / modulo2;
|
---|
117 | ny = normal[1] / modulo2;
|
---|
118 | nz = normal[2] / modulo2;
|
---|
119 |
|
---|
120 | // producto escalar : si es proximo a 0, perpendiculares, a 1, coplanares
|
---|
121 |
|
---|
122 | cop = (nx1*nx) + (ny1*ny) + (nz1*nz);
|
---|
123 |
|
---|
124 |
|
---|
125 | return (fabs(cop));
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|