[834] | 1 | #include <math.h>
|
---|
[1019] | 2 | #include "Leaf.h"
|
---|
[830] | 3 |
|
---|
| 4 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 5 | // Void constructor
|
---|
| 6 | // Parameters --> None
|
---|
| 7 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
[1019] | 8 | Leaf::Leaf(void)
|
---|
[834] | 9 | {
|
---|
[1019] | 10 | vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] =0;
|
---|
| 11 | center[0] = center[1] = center[2] = 0;
|
---|
[1526] | 12 | // normal[0] = normal[1] = normal[2] = 0;
|
---|
[1019] | 13 | leafNear=-1;
|
---|
| 14 | parentLeafCount = 1;
|
---|
[985] | 15 | dist = -1;
|
---|
| 16 | coplanar = -1;
|
---|
[1019] | 17 | criteria = -1;
|
---|
| 18 | leafCop = -1;
|
---|
| 19 | leafCrit =-1;
|
---|
| 20 | exists = false;
|
---|
| 21 | parent=-1;
|
---|
| 22 | childLeft = childRight = -1;
|
---|
| 23 | root = visible= -1;
|
---|
[830] | 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 28 | // Copy constructor
|
---|
| 29 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
[1019] | 30 | Leaf::Leaf (const Leaf& aLeaf)
|
---|
[830] | 31 | {
|
---|
[1019] | 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;
|
---|
[834] | 40 | for ( int i=0;i<3;i++){
|
---|
[1019] | 41 | center[i] = aLeaf.center[i];
|
---|
[1526] | 42 | // normal[i] = aLeaf.normal[i];
|
---|
[834] | 43 | }
|
---|
| 44 | for (i = 0L; i < 4; i++)
|
---|
[1019] | 45 | vertsLeaf[i] = aLeaf.vertsLeaf[i];
|
---|
[834] | 46 |
|
---|
[1019] | 47 | parent = aLeaf.parent;
|
---|
| 48 | childLeft = aLeaf.childLeft;
|
---|
| 49 | childRight = aLeaf.childRight;
|
---|
| 50 | visible = aLeaf.visible;
|
---|
| 51 | root = aLeaf.root;
|
---|
[830] | 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
[1526] | 55 | RuntimeLeaf::RuntimeLeaf(void)
|
---|
| 56 | {
|
---|
| 57 | vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] = 0;
|
---|
| 58 | parent = root = childLeft = childRight = -1;
|
---|
| 59 | }
|
---|
[830] | 60 |
|
---|
| 61 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
[1526] | 62 | // Copy constructor
|
---|
[830] | 63 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
[1526] | 64 | RuntimeLeaf::RuntimeLeaf (const RuntimeLeaf& aLeaf)
|
---|
[830] | 65 | {
|
---|
[1526] | 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;
|
---|
[830] | 72 | }
|
---|
| 73 |
|
---|
| 74 |
|
---|
[834] | 75 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 76 | // CALCULA LA DISTANCIA ENTRE HOJAS
|
---|
| 77 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 78 |
|
---|
[1019] | 79 | float Leaf::Distance (Leaf& leaf)
|
---|
[834] | 80 | {
|
---|
| 81 | float dist =0;
|
---|
| 82 | float x1,y1,z1;
|
---|
| 83 |
|
---|
[1019] | 84 | x1 = leaf.center[0]; y1 = leaf.center[1] ; z1 = leaf.center[2];
|
---|
[834] | 85 |
|
---|
| 86 |
|
---|
[1019] | 87 | //DISTANCIA BETWEEN CENTERS
|
---|
[834] | 88 |
|
---|
[1019] | 89 | dist = ((center[0]-x1)*(center[0]-x1)) + ((center[1]-y1)*(center[1]-y1)) + ((center[2]-z1)*(center[2]-z1));
|
---|
[834] | 90 |
|
---|
[1019] | 91 | return dist;
|
---|
[834] | 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 96 | // CALCULA LA COPLANARIDAD ENTRE HOJAS
|
---|
| 97 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 98 |
|
---|
[1019] | 99 | float Leaf::Coplanarity (Leaf& leaf)
|
---|
[834] | 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
|
---|
[1019] | 107 | x1 = leaf.normal[0]; y1 = leaf.normal[1] ; z1 = leaf.normal[2];
|
---|
[834] | 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 |
|
---|
[1019] | 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;
|
---|
[834] | 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 |
|
---|