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=d6d6d0169b2ef4d6d84cddc110ed6c131b7ebe3e;hpb=49c71c0601fad68cadb5f01aa0c5decabc1c6495;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx b/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx index d6d6d01..a87830a 100644 --- a/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx +++ b/lib/maracasVisuLib/src/kernel/PlanesOperations.cxx @@ -5,6 +5,8 @@ ** Start of data viewmanagerData *********************************************************************************************/ +using namespace std; + PlanesOperations::PlanesOperations() { } @@ -35,7 +37,7 @@ double PlanesOperations::getMagnitud(double* vect) 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; +} +