X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Fkernel%2FPlanesOperations.cxx;h=a87830acf664837290cc268f1b654c38797f02cb;hb=a3bf4fd2420496a16c98c8490101f54d25eeb7d3;hp=001f2722e1f6a0f1c1422dcb910f5cf94e60915e;hpb=e42ecf415793e6f85e5de98b41385fe53b6d00e0;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx b/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx index 001f272..a87830a 100644 --- a/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx +++ b/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx @@ -5,16 +5,21 @@ ** Start of data viewmanagerData *********************************************************************************************/ -PlanesOperations::PlanesOperations(){ +using namespace std; + +PlanesOperations::PlanesOperations() +{ } -PlanesOperations::~PlanesOperations(){ +PlanesOperations::~PlanesOperations() +{ } -double* PlanesOperations::getCrossProduct(double* vect0,double* vect1){ +double* PlanesOperations::getCrossProduct(double* vect0,double* vect1) +{ double* vectCross; vectCross = new double[3]; vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]); @@ -26,29 +31,28 @@ double* PlanesOperations::getCrossProduct(double* vect0,double* vect1){ /** ** Returns the magnitud of the given vector **/ -double PlanesOperations::getMagnitud(double* vect){ - +double PlanesOperations::getMagnitud(double* vect) +{ double mag; mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2)); - std::cout<<"mag "< PlanesOperations::getCrossProduct(vector vect0,vector vect1){ + + vector vectCross; + + for(unsigned i = 0; i < vect0.size(); i++){ + + unsigned ii = (i + 1 == vect0.size())? 0: i + 1; + unsigned iii = (ii + 1 == vect0.size())? 0: ii + 1; + + vectCross.push_back( vect0[ii]*vect1[iii]- vect0[iii]*vect1[ii] ); + + } + return vectCross; + +} +double PlanesOperations::getDotProduct(vector vect0,vector vect1){ + + double sum = 0; + + for(unsigned i = 0; i < vect0.size(); i++) sum += vect0[i]*vect1[i]; + + return sum; +} +vector PlanesOperations::getNormal(vector vect){ + vector vectnorm; + double mag = getMagnitud(vect); + + for(unsigned i = 0; i < vect.size(); i++){ + + if(mag != 0){ + vectnorm.push_back(vect[i]/mag); + }else{ + vectnorm.push_back(0); + } + } + return vectnorm; +} +double PlanesOperations::getMagnitud(vector vect){ + double mag = 0; + + for(unsigned i = 0; i < vect.size(); i++) mag += pow(vect[i], 2); + + mag = sqrt(mag); + + //std::cout<<"mag "< PlanesOperations::makeVector(vector podouble0, vector podouble1){ + + vector vector; + + for(unsigned i = 0; i < podouble0.size(); i++){ + vector.push_back(podouble1[i] - podouble0[i]); + } + return vector; +} + +/** +* Adds to vectors, the result is in vectres; +*@param double* vect0, the first vector +*@param double* vect1, the second vector +*@param double* vectres, the resulting vector +*/ +vector PlanesOperations::addVectors(vector vect0, vector vect1){ + vector vectres; + for(unsigned i = 0; i < vect0.size(); i++){ + vectres.push_back(vect0[i] + vect1[i]); + } + return vectres; +} + +/** +* multiply a vector with a given scalar +*@param double* vect0, the vector +*@param double scalar, the scalar value +*@param double* vectres, the resulting vector +*/ +vector PlanesOperations::scalarVector(vector vect0, double scalar){ + vector vectres; + for(unsigned i = 0; i < vect0.size(); i++){ + vectres.push_back(vect0[i]*scalar); + } + return vectres; +} -} \ No newline at end of file