]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdVectorFilterDouble.cxx
#3465 Spin in combobox Box and FilterString (find strings)
[bbtk.git] / packages / std / src / bbstdVectorFilterDouble.cxx
index 63d22719334da7b6bb2062b1bef187f4811664d7..88370e28fa392ebd62d14121e3afddb1f0a6323d 100644 (file)
@@ -3,6 +3,8 @@
 //===== 
 #include "bbstdVectorFilterDouble.h"
 #include "bbstdPackage.h"
+#include "math.h"
+
 namespace bbstd
 {
 
@@ -75,36 +77,39 @@ void VectorFilterDouble::Process()
 
        if (bbGetInputType()==0)  // Erase duplicate lines
        {
-               bool okSizeVec=true;
-               int ipLstvec; 
-               for (ipLstvec=1;ipLstvec<pLstVec.size();ipLstvec++)
-               {
-                       if ( (*pLstVec[ipLstvec]).size()!=(*pLstVec[0]).size() )  { okSizeVec=false; }
-               }
-               if ( okSizeVec==false)
+               if (bbGetInputIn0().size()!=0)  // At least one element 
                {
-                       printf("EED VectorFilterDouble::Process WARNING! vectors are not of the same size.\n");
-               } else {
-                       int iLine;
-                       int ipLstvec2; 
-                       bool okLine;
-                       for (iLine=0 ; iLine < (*pLstVec[0]).size() ; iLine++ ) 
+                       bool okSizeVec=true;
+                       int ipLstvec; 
+                       for (ipLstvec=1;ipLstvec<pLstVec.size();ipLstvec++)
                        {
-                               okLine=false;
-                               for ( ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
-                               {
-                                       if ( (*pLstVec[ipLstvec2])[iLine]!=(*pLstVec[ipLstvec2])[iLine-1] )  { okLine=true; }
-                               } // for ipLstVec2
-                                               
-                               if ( (okLine==true) || (iLine==0) ) 
+                               if ( (*pLstVec[ipLstvec]).size()!=(*pLstVec[0]).size() )  { okSizeVec=false; }
+                       }
+                       if ( okSizeVec==false)
+                       {
+                               printf("EED VectorFilterDouble::Process WARNING! vectors are not of the same size.\n");
+                       } else {
+                               int iLine;
+                               int ipLstvec2; 
+                               bool okLine;
+                               for (iLine=0 ; iLine < (*pLstVec[0]).size() ; iLine++ ) 
                                {
-                                       for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
+                                       okLine=false;
+                                       for ( ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
                                        {
-                                               (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[iLine] );
-                                       } // for
-                               } // if okLine
-                       } // for iLine
-               } // if okSizeVec
+                                               if ( (*pLstVec[ipLstvec2])[iLine]!=(*pLstVec[ipLstvec2])[iLine-1] )  { okLine=true; }
+                                       } // for ipLstVec2
+                                                       
+                                       if ( (okLine==true) || (iLine==0) ) 
+                                       {
+                                               for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
+                                               {
+                                                       (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[iLine] );
+                                               } // for
+                                       } // if okLine
+                               } // for iLine
+                       } // if okSizeVec
+               } // bbGetInputIn0()  size
        } // Type==0
 
 
@@ -279,7 +284,6 @@ void VectorFilterDouble::Process()
 
        if (bbGetInputType()==8)   // order all vectors using as base the vector In0
        {
-printf("EED VectorFilterDouble::Process Type 8 Start\n");
                double tmp;
                int i,j,ii,sizeII;
                sizeII=pLstVec.size();
@@ -305,16 +309,82 @@ printf("EED VectorFilterDouble::Process Type 8 Start\n");
                                                tmp = (*pLstVecOut[ii])[i]; 
                                                (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j]; 
                                                (*pLstVecOut[ii])[j] = tmp; 
-//                                             tmp=Out0[i]; Out0[i]=Out0[j]; Out0[j]=tmp; 
-                                       }
-                               }
+                                       } // for ii
+                               } // if <
                        } // for j
                } // for i
-printf("EED VectorFilterDouble::Process Type 8 End\n");
-
        } // Type 8
 
 
+       if (bbGetInputType()==9)   // Invert vectors
+       {
+               double tmp;
+               int i,j,ii,sizeII;
+               sizeII=pLstVec.size();
+
+               int size=In0.size();
+               int size2=size/2;
+               for (i=0;i<size; i++)
+               {
+                       for (ii=0;ii<sizeII;ii++)
+                       {
+                                (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] ); 
+                       } // for ii
+               } // i
+
+               for (i=0;i<size2;i++)
+               {
+                       for (ii=0;ii<sizeII;ii++)
+                       {
+                               j=size-1-i;     
+                               tmp = (*pLstVecOut[ii])[i]; 
+                               (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[ j ]; 
+                               (*pLstVecOut[ii])[j] = tmp; 
+                       } // for ii
+               } // for i
+       } // Type 9
+
+
+       if (bbGetInputType()==10)   // Nearest point in vector
+       {
+               int     sizeLstX        =       In0.size();   // lstX
+               int     sizeLstY        =       In1.size();   // lstY
+               int     sizeLstZ        =       In2.size();   // lstZ
+               if ( (sizeLstX==sizeLstY) && (sizeLstY==sizeLstZ) && (sizeLstX>0) && (In3.size()==3) )
+               {
+                       int i;
+                       double x1               =       In3[0];  // pointX of pointXYZ
+                       double y1               =       In3[1];  // pointY of pointXYZ
+                       double z1               =       In3[2];  // pointZ of pointXYZ
+                       double distMin  =       100000;
+                       double dist;
+                       double x2;
+                       double y2;
+                       double z2;
+                       Out0.push_back( -1 ); 
+                       Out1.push_back( -999 ); 
+                       Out1.push_back( -999 ); 
+                       Out1.push_back( -999 ); 
+                       for (i=0;i<sizeLstX; i++)
+                       {
+                               x2 = In0[i];    // lstX
+                               y2 = In1[i];    // lstY
+                               z2 = In2[i];    // lstZ
+                               dist = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
+                               if (dist<distMin) 
+                               {
+                                       distMin = dist;
+                                       Out0[0] = i;
+                                       Out1[0] = x2;
+                                       Out1[1] = y2;
+                                       Out1[2] = z2;
+                               }
+                       } // for i
+               } else {
+                       printf("EED Warnning VectorFilterDouble::Process()   For Type 10 the size of the vectors are not coherent.\n");
+               }// if size
+       } // Type 10
+
 
 
        bbSetOutputOut0( Out0 );