[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;
|
---|
| 12 | normal[0] = normal[1] = normal[2] = 0;
|
---|
| 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];
|
---|
| 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 |
|
---|
| 55 |
|
---|
| 56 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
[834] | 57 | // Destructor. We must deallocate the memory allocated for pointers to vertices and edges
|
---|
[830] | 58 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
[1019] | 59 | Leaf::~Leaf (void)
|
---|
[830] | 60 | {
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
[834] | 64 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 65 | // CALCULA LA DISTANCIA ENTRE HOJAS
|
---|
| 66 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 67 |
|
---|
[1019] | 68 | float Leaf::Distance (Leaf& leaf)
|
---|
[834] | 69 | {
|
---|
| 70 | float dist =0;
|
---|
| 71 | float x1,y1,z1;
|
---|
| 72 |
|
---|
[1019] | 73 | x1 = leaf.center[0]; y1 = leaf.center[1] ; z1 = leaf.center[2];
|
---|
[834] | 74 |
|
---|
| 75 |
|
---|
[1019] | 76 | //DISTANCIA BETWEEN CENTERS
|
---|
[834] | 77 |
|
---|
[1019] | 78 | dist = ((center[0]-x1)*(center[0]-x1)) + ((center[1]-y1)*(center[1]-y1)) + ((center[2]-z1)*(center[2]-z1));
|
---|
[834] | 79 |
|
---|
[1019] | 80 | return dist;
|
---|
[834] | 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 85 | // CALCULA LA COPLANARIDAD ENTRE HOJAS
|
---|
| 86 | //--------------------------------------------------------------------------------------------------------------------------------
|
---|
| 87 |
|
---|
[1019] | 88 | float Leaf::Coplanarity (Leaf& leaf)
|
---|
[834] | 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
|
---|
[1019] | 96 | x1 = leaf.normal[0]; y1 = leaf.normal[1] ; z1 = leaf.normal[2];
|
---|
[834] | 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 |
|
---|
[1019] | 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;
|
---|
[834] | 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 |
|
---|