#include #include "Leaf.h" //-------------------------------------------------------------------------------------------------------------------------------- // Void constructor // Parameters --> None //-------------------------------------------------------------------------------------------------------------------------------- Leaf::Leaf(void) { vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] =0; center[0] = center[1] = center[2] = 0; // normal[0] = normal[1] = normal[2] = 0; leafNear=-1; parentLeafCount = 1; dist = -1; coplanar = -1; criteria = -1; leafCop = -1; leafCrit =-1; exists = false; parent=-1; childLeft = childRight = -1; root = visible= -1; } //-------------------------------------------------------------------------------------------------------------------------------- // Copy constructor //-------------------------------------------------------------------------------------------------------------------------------- Leaf::Leaf (const Leaf& aLeaf) { parentLeafCount = aLeaf.parentLeafCount;; leafNear = aLeaf.leafNear; leafCrit = aLeaf.leafCrit; dist = aLeaf.dist; exists = aLeaf.exists; coplanar = aLeaf.coplanar; leafCop = aLeaf.leafCop; criteria = aLeaf.criteria; for ( int i=0;i<3;i++){ center[i] = aLeaf.center[i]; // normal[i] = aLeaf.normal[i]; } for (i = 0L; i < 4; i++) vertsLeaf[i] = aLeaf.vertsLeaf[i]; parent = aLeaf.parent; childLeft = aLeaf.childLeft; childRight = aLeaf.childRight; visible = aLeaf.visible; root = aLeaf.root; } RuntimeLeaf::RuntimeLeaf(void) { vertsLeaf[0] = vertsLeaf[1] = vertsLeaf[2] = vertsLeaf[3] = 0; parent = root = childLeft = childRight = -1; } //-------------------------------------------------------------------------------------------------------------------------------- // Copy constructor //-------------------------------------------------------------------------------------------------------------------------------- RuntimeLeaf::RuntimeLeaf (const RuntimeLeaf& aLeaf) { for (int i = 0L; i < 4; i++) vertsLeaf[i] = aLeaf.vertsLeaf[i]; parent = aLeaf.parent; childLeft = aLeaf.childLeft; childRight = aLeaf.childRight; root = aLeaf.root; } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA LA DISTANCIA ENTRE HOJAS //-------------------------------------------------------------------------------------------------------------------------------- float Leaf::Distance (Leaf& leaf) { float dist =0; float x1,y1,z1; x1 = leaf.center[0]; y1 = leaf.center[1] ; z1 = leaf.center[2]; //DISTANCIA BETWEEN CENTERS dist = ((center[0]-x1)*(center[0]-x1)) + ((center[1]-y1)*(center[1]-y1)) + ((center[2]-z1)*(center[2]-z1)); return dist; } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA LA COPLANARIDAD ENTRE HOJAS //-------------------------------------------------------------------------------------------------------------------------------- float Leaf::Coplanarity (Leaf& leaf) { float cop =0; float modulo1, modulo2; float x1,y1,z1, nx1, ny1, nz1; float nx, ny, nz; //hoja pasada como parametro, normalizo las componentes x1 = leaf.normal[0]; y1 = leaf.normal[1] ; z1 = leaf.normal[2]; modulo1 = sqrt ( (x1*x1) + (y1*y1) + (z1*z1)); nx1 = x1 / modulo1; ny1 = y1 / modulo1; nz1 = z1 / modulo1; // hoja desde la que llamo modulo2 = sqrt ( (normal[0]*normal[0]) + (normal[1]*normal[1]) + (normal[2]*normal[2])); nx = normal[0] / modulo2; ny = normal[1] / modulo2; nz = normal[2] / modulo2; // producto escalar : si es proximo a 0, perpendiculares, a 1, coplanares cop = (nx1*nx) + (ny1*ny) + (nz1*nz); return (fabs(cop)); }