]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdVectorFilterDouble.cxx
#3507 BackFace in PolyDataToActor Box
[bbtk.git] / packages / std / src / bbstdVectorFilterDouble.cxx
index 88370e28fa392ebd62d14121e3afddb1f0a6323d..c132e918a19f4bdf67b98d34977c885849eeb50b 100644 (file)
@@ -15,7 +15,6 @@ BBTK_BLACK_BOX_IMPLEMENTATION(VectorFilterDouble,bbtk::AtomicBlackBox);
 //===== 
 void VectorFilterDouble::Process()
 {
-
 // THE MAIN PROCESSING METHOD BODY
 //   Here we simply set the input 'In' value to the output 'Out'
 //   And print out the output value
@@ -27,7 +26,6 @@ void VectorFilterDouble::Process()
 //      (the one provided in the attribute 'name' of the tag 'input')
 //    * TYPE is the C++ type of the input/output
 //      (the one provided in the attribute 'type' of the tag 'input')
-
        std::vector< std::vector<double> * >  pLstVec;  
        std::vector< std::vector<double> * >  pLstVecOut;  
        std::vector<double> In0 = bbGetInputIn0();
@@ -40,7 +38,6 @@ void VectorFilterDouble::Process()
        std::vector<double> In7 = bbGetInputIn7();
        std::vector<double> In8 = bbGetInputIn8();
        std::vector<double> In9 = bbGetInputIn9();
-
        if (bbGetInputIn0().size()!=0) { pLstVec.push_back( &In0 ); }
        if (bbGetInputIn1().size()!=0) { pLstVec.push_back( &In1 ); }
        if (bbGetInputIn2().size()!=0) { pLstVec.push_back( &In2 ); }
@@ -51,7 +48,6 @@ void VectorFilterDouble::Process()
        if (bbGetInputIn7().size()!=0) { pLstVec.push_back( &In7 ); }
        if (bbGetInputIn8().size()!=0) { pLstVec.push_back( &In8 ); }
        if (bbGetInputIn9().size()!=0) { pLstVec.push_back( &In9 ); }
-
        std::vector<double> Out0;
        std::vector<double> Out1;
        std::vector<double> Out2;
@@ -62,7 +58,6 @@ void VectorFilterDouble::Process()
        std::vector<double> Out7;
        std::vector<double> Out8;
        std::vector<double> Out9;
-
        pLstVecOut.push_back( &Out0 );
        pLstVecOut.push_back( &Out1 );
        pLstVecOut.push_back( &Out2 );
@@ -73,8 +68,6 @@ void VectorFilterDouble::Process()
        pLstVecOut.push_back( &Out7 );
        pLstVecOut.push_back( &Out8 );
        pLstVecOut.push_back( &Out9 );
-
-
        if (bbGetInputType()==0)  // Erase duplicate lines
        {
                if (bbGetInputIn0().size()!=0)  // At least one element 
@@ -111,14 +104,12 @@ void VectorFilterDouble::Process()
                        } // if okSizeVec
                } // bbGetInputIn0()  size
        } // Type==0
-
-
        if (bbGetInputType()==1) // Resize vector
        {
                int             ipLstvec2;
                double  iLine;
                int     sizeLines       = (*pLstVec[0]).size();
-               double  step            = (double)sizeLines/((double)bbGetInputk1()-1);
+               double  step            = (double)sizeLines/((double)bbGetInputk1()[0]-1);
                for (iLine=0 ; iLine<sizeLines ; iLine=iLine+step)
                {
                        for (ipLstvec2=0 ; ipLstvec2<pLstVec.size() ; ipLstvec2++)
@@ -126,15 +117,12 @@ 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                        
-
+               } // for
        } // Type==1
-
        if (bbGetInputType()==2) // Insert intermediate points
        {
                int             ipLstvec;
@@ -156,9 +144,7 @@ void VectorFilterDouble::Process()
                        } // if size>=2
                } // for pLstVec                
        } // Type==2
-
-
-       if (bbGetInputType()==3) // Addition  k1
+       if (bbGetInputType()==3) // Addition  k1[0]
        {
                int             ipLstvec;
                int     i;
@@ -169,13 +155,12 @@ void VectorFilterDouble::Process()
                        size=(*pLstVec[ipLstvec]).size();
                        for (i=0;i<size;i++)
                        {
-                               result= (*pLstVec[ipLstvec])[i] + bbGetInputk1() ;
+                               result= (*pLstVec[ipLstvec])[i] + bbGetInputk1()[0] ;
                                (*pLstVecOut[ipLstvec]).push_back( result );                            
                        }// for size
                } // for pLstVec                
        } // Type==3
-
-       if (bbGetInputType()==4) // Substraction  k1
+       if (bbGetInputType()==4) // Substraction  k1[0]
        {
                int             ipLstvec;
                int     i;
@@ -186,13 +171,12 @@ void VectorFilterDouble::Process()
                        size=(*pLstVec[ipLstvec]).size();
                        for (i=0;i<size;i++)
                        {
-                               result= (*pLstVec[ipLstvec])[i] - bbGetInputk1() ;
+                               result= (*pLstVec[ipLstvec])[i] - bbGetInputk1()[0] ;
                                (*pLstVecOut[ipLstvec]).push_back( result );                            
                        }// for size
                } // for pLstVec                
        } // Type==4
-
-       if (bbGetInputType()==5) // Multiplication  k1
+       if (bbGetInputType()==5) // Multiplication  k1[0]
        {
                int     ipLstvec;
                int     i;
@@ -203,15 +187,12 @@ void VectorFilterDouble::Process()
                        size=(*pLstVec[ipLstvec]).size();
                        for (i=0;i<size;i++)
                        {
-                               result= (*pLstVec[ipLstvec])[i] * bbGetInputk1() ;
+                               result= (*pLstVec[ipLstvec])[i] * bbGetInputk1()[0] ;
                                (*pLstVecOut[ipLstvec]).push_back( result );                            
                        }// for size
                } // for pLstVec                
        } // Type==5
-
-       if (bbGetInputType()==6) // Division  k1ng gadget (node check, owner GtkCheckButton)
-
-
+       if (bbGetInputType()==6) // Division  k1
        {
                int     ipLstvec;
                int     i;
@@ -222,9 +203,9 @@ void VectorFilterDouble::Process()
                        size=(*pLstVec[ipLstvec]).size();
                        for (i=0;i<size;i++)
                        {
-                               if (bbGetInputk1()!=0)
+                               if (bbGetInputk1()[0]!=0)
                                {
-                                       result= (*pLstVec[ipLstvec])[i] / bbGetInputk1() ;
+                                       result= (*pLstVec[ipLstvec])[i] / bbGetInputk1()[0] ;
                                        (*pLstVecOut[ipLstvec]).push_back( result );                            
                                } else {
                                        printf("EED VectorFilterDouble::Process  Warning!! Div by 0 in Type 6 \n");
@@ -233,9 +214,6 @@ void VectorFilterDouble::Process()
                        }// for size
                } // for pLstVec                
        } // Type==6
-
-
-
        if (bbGetInputType()==7) 
        {
                int i,j;
@@ -245,18 +223,13 @@ void VectorFilterDouble::Process()
                        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;
@@ -276,19 +249,12 @@ void VectorFilterDouble::Process()
                        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++)
                {
@@ -302,8 +268,7 @@ void VectorFilterDouble::Process()
                        for (j=i;j<size;j++)
                        {
                                if ((*pLstVecOut[0])[j] <= (*pLstVecOut[0])[i] ) 
-                               {       
-                                       
+                               {
                                        for (ii=0;ii<sizeII;ii++)
                                        {
                                                tmp = (*pLstVecOut[ii])[i]; 
@@ -314,14 +279,11 @@ void VectorFilterDouble::Process()
                        } // 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++)
@@ -331,7 +293,6 @@ void VectorFilterDouble::Process()
                                 (*pLstVecOut[ii]).push_back( (*pLstVec[ii])[i] ); 
                        } // for ii
                } // i
-
                for (i=0;i<size2;i++)
                {
                        for (ii=0;ii<sizeII;ii++)
@@ -343,8 +304,6 @@ void VectorFilterDouble::Process()
                        } // for ii
                } // for i
        } // Type 9
-
-
        if (bbGetInputType()==10)   // Nearest point in vector
        {
                int     sizeLstX        =       In0.size();   // lstX
@@ -384,8 +343,130 @@ void VectorFilterDouble::Process()
                        printf("EED Warnning VectorFilterDouble::Process()   For Type 10 the size of the vectors are not coherent.\n");
                }// if size
        } // Type 10
-
-
+    if (bbGetInputType()==11)   // Nearest point in vector
+    {
+        int i;
+        int    sizeLstX    =    In0.size();   // lstX
+        int    sizeLstY    =    In1.size();   // lstY
+        int    sizeLstZ    =    In2.size();   // lstZ
+        std::vector<double> spc = bbGetInputk1();
+        if (spc.size()>=1)
+        {
+            for (i=0;i<sizeLstX; i++)
+            {
+                Out0.push_back( In0[i]*spc[0] );
+            } // for i
+        } else {
+            printf("EED Warnning VectorFilterDouble::Process()   For Type 11 the K1 vector (spacing) is not coherent.\n");
+        }// if size
+        if (spc.size()>=2)
+        {
+            for (i=0;i<sizeLstY; i++)
+            {
+                Out1.push_back( In1[i]*spc[1] );
+            } // for i
+        } else {
+            printf("EED Warnning VectorFilterDouble::Process()   For Type 11 the K1 vector (spacing) is not coherent.\n");
+        }// if size
+        if (spc.size()>=3)
+        {
+            for (i=0;i<sizeLstZ; i++)
+            {
+                Out2.push_back( In2[i]*spc[2] );
+            } // for i
+        } else {
+            printf("EED Warnning VectorFilterDouble::Process()   For Type 11 the K1 vector (spacing) is not coherent.\n");
+        }// if size
+     } // Type 11
+    if (bbGetInputType()==12)   // Nearest point in vector
+    {
+        int i;
+        int sizeLstX    =    In0.size();   // lstX
+        int sizeLstY    =    In1.size();   // lstY
+        int sizeLstZ    =    In2.size();   // lstZ
+        std::vector<double> spc = bbGetInputk1();
+        if (spc.size()>=1)
+        {
+            if (spc[0]!=0)
+            {
+                for (i=0;i<sizeLstX; i++)
+                {
+                    Out0.push_back( In0[i]/spc[0] );
+                } // for i
+            } // if spc !=0
+        } else {
+            printf("EED Warnning VectorFilterDouble::Process()   For Type 12 the K1 vector (spacing) is not coherent.\n");
+        }// if size
+        if (spc.size()>=2)
+        {
+            if (spc[0]!=0)
+            {
+                for (i=0;i<sizeLstY; i++)
+                {
+                    Out1.push_back( In1[i]/spc[1] );
+                } // for i
+            } // if spc !=0
+        } else {
+            printf("EED Warnning VectorFilterDouble::Process()   For Type 12 the K1 vector (spacing) is not coherent.\n");
+        }// if size
+        if (spc.size()>=3)
+        {
+            if (spc[0]!=0)
+            {
+                for (i=0;i<sizeLstZ; i++)
+                {
+                    Out2.push_back( In2[i]/spc[2] );
+                } // for i
+            } // if spc !=0
+        } else {
+            printf("EED Warnning VectorFilterDouble::Process()   For Type 12 the K1 vector (spacing) is not coherent.\n");
+        }// if size
+     } // Type 12
+    if (bbGetInputType()==13)   // Distance point 3D between In0 and In1
+    {
+        if ( In0.size()==3 and In1.size()==3)
+        {
+            double x = In0[0] - In1[0];
+            double y = In0[1] - In1[1];
+            double z = In0[2] - In1[2];
+            Out0.push_back( sqrt( x*x +y*y +z*z ) );
+        }
+     } // Type 13
+    if (bbGetInputType()==14)   // Select segments
+    {
+        if ( (In0.size()==In1.size()) && (In0.size()==In2.size() ) )
+        {
+            if (bbGetInputk1().size()==0)  // not filter , just passing all segmentes
+            {
+                Out0 = In0;
+                Out1 = In1;
+                Out2 = In2;
+                Out3 = In3;
+            } else {
+                std::vector<double> k1 =bbGetInputk1();
+                int iSeg, sizeLstIndex = In3.size();
+                int iGeneral=0;
+                int i, size;
+                for (iSeg = 0; iSeg<sizeLstIndex; iSeg++)
+                {
+                    size = In3[iSeg];
+                    if (std::find(k1.begin(), k1.end(),iSeg)!=k1.end() )  // checking if element exist inside
+                    {
+                        Out3.push_back(size);
+                        for (i=0; i<size; i++)
+                        {
+                            Out0.push_back( In0[iGeneral] );
+                            Out1.push_back( In1[iGeneral] );
+                            Out2.push_back( In2[iGeneral] );
+                            iGeneral++;
+                        } // for i
+                    } else {
+                        iGeneral=iGeneral+size;
+                    }
+                } // for iSeg
+            } // if k1 not empty
+        }
+     } // Type 14
 
        bbSetOutputOut0( Out0 );
        bbSetOutputOut1( Out1 );
@@ -398,44 +479,42 @@ void VectorFilterDouble::Process()
        bbSetOutputOut8( Out8 );
        bbSetOutputOut9( Out9 );
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 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);
-  
+    bbSetInputType(0);
+    std::vector<double> k1;
+    k1.push_back(0);
+    bbSetInputk1(k1);
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void VectorFilterDouble::bbUserInitializeProcessing()
 {
-
 //  THE INITIALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should allocate the internal/output pointers 
-//    if any 
-
-  
+//    if any
 }
+
 //===== 
 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
 //===== 
 void VectorFilterDouble::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
 //    if any
-  
-}
 }
-// EO namespace bbstd
+
+}// EO namespace bbstd