void Leaf::computeBboxAA() { mat3 R( vec3::X, vec3::Y, vec3::Z); vec3 halfSize, center; fitBox(R, center, halfSize); mBbox.halfSize = halfSize; mBbox.setTran( transf(R, center ) ); }
void fitBox( TH1D* hist, double& mean, double& sigma, double sensorWidth, bool display) { double max = 0; double background = 0; fitBox(hist, mean, sigma, max, background, sensorWidth, display); }
void Leaf::computeBboxOO() { //compute the covariance matrix double covMat[3][3], v[3][3]; areaWeightedCovarianceMatrix(covMat); DBGP("Cov mat:"); DBGST(print(covMat)); //perform singular value decomposition Jacobi(covMat, v); DBGP("eigenvalues:"); DBGST(print(covMat)); DBGP("eigenVectors:"); DBGST(print(v)); int first = 0, second = 1, third = 2; if (covMat[1][1] > covMat[0][0]) { std::swap(first, second); } if (covMat[2][2] > covMat[first][first]) { std::swap(first, third); } if (covMat[third][third] > covMat[second][second]) { std::swap(second, third); } DBGP("Eigenvalues: " << covMat[first][first] << " " << covMat[second][second] << " " << covMat[third][third]); //set up rotation matrix vec3 xAxis(v[0][first], v[1][first], v[2][first]); vec3 yAxis(v[0][second], v[1][second], v[2][second]); vec3 zAxis = normalise(xAxis) * normalise(yAxis); yAxis = zAxis * normalise(xAxis); xAxis = yAxis * zAxis; mat3 R(xAxis, yAxis, zAxis); DBGP("Matrix: " << R); //compute bbox extents vec3 halfSize, center; fitBox(R, center, halfSize); //rotate box so that x axis always points in the direction of largest extent first = 0; if (halfSize.y() > halfSize.x()) first = 1; if (halfSize.z() > halfSize[first]) first = 2; transf rotate = transf::IDENTITY; if (first == 1) { // y has the largest extent, rotate around z rotate = rotate_transf(M_PI/2.0, vec3(0,0,1)); } else if (first == 2) { // z has the largest extent, rotate around y rotate = rotate_transf(M_PI/2.0, vec3(0,1,0)); } halfSize = halfSize * rotate; for (int i=0; i<3; i++) { if (halfSize[i] < 0) halfSize[i] = -halfSize[i]; } mat3 RR; rotate.rotation().ToRotationMatrix(RR); R = RR * R; mBbox.halfSize = halfSize; mBbox.setTran( transf(R, center ) ); }