]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdVectorFilterDouble.cxx
#3348 BBTK Feature New Normal - VectorFilterDouble (find nearest point) WriteColumn...
[bbtk.git] / packages / std / src / bbstdVectorFilterDouble.cxx
index 0fb6621500aef7c3ae2277947cf6a8754e689a10..812f6469d399f802bc97db34172ee1609e9789f3 100644 (file)
@@ -3,6 +3,8 @@
 //===== 
 #include "bbstdVectorFilterDouble.h"
 #include "bbstdPackage.h"
+#include "math.h"
+
 namespace bbstd
 {
 
@@ -113,7 +115,7 @@ void VectorFilterDouble::Process()
                int             ipLstvec2;
                double  iLine;
                int     sizeLines       = (*pLstVec[0]).size();
-               double  step            = (double)sizeLines/(double)bbGetInputk1();
+               double  step            = (double)sizeLines/((double)bbGetInputk1()-1);
                for (iLine=0 ; iLine<sizeLines ; iLine=iLine+step)
                {
                        for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
@@ -121,9 +123,16 @@ void VectorFilterDouble::Process()
                                (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)iLine] );
                        } // for                        
                } // for ipLstVec
+
+               // adding the lastone
+               for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
+               {
+                       (*pLstVecOut[ipLstvec2]).push_back( (*pLstVec[ipLstvec2])[(int)(sizeLines-1)] );
+               } // for                        
+
        } // Type==1
 
-       if (bbGetInputType()==2) // Insert intermediate pointss
+       if (bbGetInputType()==2) // Insert intermediate points
        {
                int             ipLstvec;
                int     i;
@@ -146,6 +155,238 @@ void VectorFilterDouble::Process()
        } // Type==2
 
 
+       if (bbGetInputType()==3) // Addition  k1
+       {
+               int             ipLstvec;
+               int     i;
+               int     size;
+               double  result;
+               for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
+               {
+                       size=(*pLstVec[ipLstvec]).size();
+                       for (i=0;i<size;i++)
+                       {
+                               result= (*pLstVec[ipLstvec])[i] + bbGetInputk1() ;
+                               (*pLstVecOut[ipLstvec]).push_back( result );                            
+                       }// for size
+               } // for pLstVec                
+       } // Type==3
+
+       if (bbGetInputType()==4) // Substraction  k1
+       {
+               int             ipLstvec;
+               int     i;
+               int     size;
+               double  result;
+               for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
+               {
+                       size=(*pLstVec[ipLstvec]).size();
+                       for (i=0;i<size;i++)
+                       {
+                               result= (*pLstVec[ipLstvec])[i] - bbGetInputk1() ;
+                               (*pLstVecOut[ipLstvec]).push_back( result );                            
+                       }// for size
+               } // for pLstVec                
+       } // Type==4
+
+       if (bbGetInputType()==5) // Multiplication  k1
+       {
+               int     ipLstvec;
+               int     i;
+               int     size;
+               double  result;
+               for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
+               {
+                       size=(*pLstVec[ipLstvec]).size();
+                       for (i=0;i<size;i++)
+                       {
+                               result= (*pLstVec[ipLstvec])[i] * bbGetInputk1() ;
+                               (*pLstVecOut[ipLstvec]).push_back( result );                            
+                       }// for size
+               } // for pLstVec                
+       } // Type==5
+
+       if (bbGetInputType()==6) // Division  k1ng gadget (node check, owner GtkCheckButton)
+
+
+       {
+               int     ipLstvec;
+               int     i;
+               int     size;
+               double  result;
+               for (ipLstvec=0 ; ipLstvec<pLstVec.size() ; ipLstvec++)
+               {
+                       size=(*pLstVec[ipLstvec]).size();
+                       for (i=0;i<size;i++)
+                       {
+                               if (bbGetInputk1()!=0)
+                               {
+                                       result= (*pLstVec[ipLstvec])[i] / bbGetInputk1() ;
+                                       (*pLstVecOut[ipLstvec]).push_back( result );                            
+                               } else {
+                                       printf("EED VectorFilterDouble::Process  Warning!! Div by 0 in Type 6 \n");
+                                       (*pLstVecOut[ipLstvec]).push_back( -1 );                                
+                               }
+                       }// for size
+               } // for pLstVec                
+       } // Type==6
+
+
+
+       if (bbGetInputType()==7) 
+       {
+               int i,j;
+               for (j=0;j<In4.size(); j++)
+               {
+                       Out0.push_back( In4[j] );
+                       Out1.push_back( In5[j] );
+                       Out2.push_back( In6[j] );
+               } //
+
+
+               int iGeneral=0,sizeI,sizeLst1Indexes=In3.size();
+               for (i=0; i<sizeLst1Indexes-1;i++) { iGeneral=iGeneral+In3[i]; }
+               sizeI=iGeneral+In3[ sizeLst1Indexes-1 ];
+
+               int jGeneral = 0;
+               int sizeJ        = In7[ 0 ];
+
+               double dist2,dist2Min,dx,dy,dz;
+               int iBack;
+
+               for (j=jGeneral;j<sizeJ;j++) 
+               {
+                       dist2Min=1000000;
+                       for (i=iGeneral;i<sizeI;i++) 
+                       {       
+                               dx              = In0[i]-In4[j];
+                               dy              = In1[i]-In5[j];
+                               dz              = In2[i]-In6[j];
+                               dist2           = dx*dx + dy*dy + dz*dz;
+                               if (dist2<dist2Min) 
+                               {
+                                               dist2Min=dist2;
+                                               iBack=i;
+                               } // if
+                       } // for j
+                       Out0[j]=In0[iBack]; 
+                       Out1[j]=In1[iBack]; 
+                       Out2[j]=In2[iBack]; 
+               } // for i
+
+
+       }       // Type 7
+
+
+
+       if (bbGetInputType()==8)   // order all vectors using as base the vector In0
+       {
+               double tmp;
+               int i,j,ii,sizeII;
+               sizeII=pLstVec.size();
+
+
+               int size=In0.size();
+               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<size;i++)
+               {
+                       for (j=i;j<size;j++)
+                       {
+                               if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] ) 
+                               {       
+                                       
+                                       for (ii=0;ii<sizeII;ii++)
+                                       {
+                                               tmp = (*pLstVecOut[ii])[i]; 
+                                               (*pLstVecOut[ii])[i] = (*pLstVecOut[ii])[j]; 
+                                               (*pLstVecOut[ii])[j] = tmp; 
+                                       } // for ii
+                               } // if <
+                       } // for j
+               } // for i
+       } // 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
+
+
+printf("EED VectorFilterDouble::Process() start\n");
+       if (bbGetInputType()==10)   // Invert vectors
+       {
+               int     sizeLstX        =       In0.size();   // lstX
+               int     sizeLstY        =       In1.size();   // lstY
+               int     sizeLstZ        =       In2.size();   // lstZ
+               printf("EED Warnning VectorFilterDouble::Process() %d  %d  %d  %d\n", sizeLstX,sizeLstY,sizeLstZ,In3.size() );
+               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
+
+printf("EED VectorFilterDouble::Process() end\n");
+
+
        bbSetOutputOut0( Out0 );
        bbSetOutputOut1( Out1 );
        bbSetOutputOut2( Out2 );
@@ -166,6 +407,7 @@ void VectorFilterDouble::bbUserSetDefaultValues()
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
    bbSetInputType(0);
+   bbSetInputk1(0);
   
 }
 //=====