]> Creatis software - creaVtk.git/commitdiff
#3531 ImageMaskDice box
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Mon, 4 Nov 2024 12:27:22 +0000 (13:27 +0100)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Mon, 4 Nov 2024 12:27:22 +0000 (13:27 +0100)
bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.h

index 23b4330339a562f11da6206434d468022e0c97a4..5272ac33efc01fd0bcdd293669e984c36d527782 100644 (file)
 //===== 
 #include "bbcreaVtkImageMaskDice.h"
 #include "bbcreaVtkPackage.h"
+
+#include "creaVtk_MACROS.h"
+
 namespace bbcreaVtk
 {
 
 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageMaskDice)
 BBTK_BLACK_BOX_IMPLEMENTATION(ImageMaskDice,bbtk::AtomicBlackBox);
-//===== 
-// 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)
-//===== 
+
+
+#define ACUMULATE(VMA,VMM,TP,FP,FN)           \
+            if ( (VMA>0) || (VMM>0) )                 \
+            {                                         \
+                    if ((VMA>0)&&(VMM>0))             \
+                    {                                 \
+                        TP++;                         \
+                    } else if ((VMA>0)&&(VMM==0)) {   \
+                        FP++;                         \
+                    } else if ((VMA==0)&&(VMM>0)) {   \
+                        FN++;                         \
+                    }                                 \
+            }
+
+#define INSERTINVECTOR(TP,FP,FN)                                                           \
+        LstTitles.push_back( "tp");     LstValues.push_back( std::to_string(TP) );         \
+        LstTitles.push_back( "fp");     LstValues.push_back( std::to_string(FP) );         \
+        LstTitles.push_back( "fn");     LstValues.push_back( std::to_string(FN) );         \
+        LstTitles.push_back( "vol1");   LstValues.push_back( std::to_string(TP+FP) );      \
+        LstTitles.push_back( "vol2");   LstValues.push_back( std::to_string(TP+FN) );      \
+        if ((TP==0) && (FP==0) && (FN==0)) {                                               \
+            LstTitles.push_back( "_dice"); LstValues.push_back( "---" );                   \
+        }else {                                                                            \
+            tmp = 2 * (double)TP / (2 * (double)TP + (double)FP +  (double)FN );           \
+            LstTitles.push_back( "dice"); LstValues.push_back( std::to_string(tmp) );      \
+        }
+
 void ImageMaskDice::Process()
 {
-
 // THE MAIN PROCESSING METHOD BODY
 //   Here we simply set the input 'In' value to the output 'Out'
 //   And print out the output value
 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
 //    void bbSet{Input|Output}NAME(const TYPE&)
-//    const TYPE& bbGet{Input|Output}NAME() const 
+//    const TYPE& bbGet{Input|Output}NAME() const
 //    Where :
 //    * NAME is the name of the input/output
 //      (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')
 
-    
-    printf("EED ImageMaskDice::Process  Error, this method is not implemented \n");
-    printf("EED ImageMaskDice::Process  Error, this method is not implemented \n");
-    printf("EED ImageMaskDice::Process  Error, this method is not implemented \n");
-    printf("EED ImageMaskDice::Process  Error, this method is not implemented \n");
-    printf("EED ImageMaskDice::Process  Error, this method is not implemented \n");
-    printf("EED ImageMaskDice::Process  Error, this method is not implemented \n");
-
-    bbSetOutputOut( -1 );
+    if ( (bbGetInputIn1()!=NULL) && (bbGetInputIn2()!=NULL) )
+    {
+        int     ext[6];
+        int dimX1,dimY1,dimZ1;
+        bbGetInputIn1()->GetExtent(ext);
+        dimX1 = ext[1]-ext[0]+1;
+        dimY1 = ext[3]-ext[2]+1;
+        dimZ1 = ext[5]-ext[4]+1;
+        int dimX2,dimY2,dimZ2;
+        bbGetInputIn2()->GetExtent(ext);
+        dimX2 = ext[1]-ext[0]+1;
+        dimY2 = ext[3]-ext[2]+1;
+        dimZ2 = ext[5]-ext[4]+1;
+        if ( (dimX1==dimX2) &&
+             (dimY1==dimY2) &&
+             (dimZ1==dimZ2) )
+        {
+            long int tpAll=0        ,fpAll=0        ,fnAll=0        ;
+            DEF_POINTER_IMAGE_VTK_CREA(vMA,ssMA,pMA,stMA,bbGetInputIn1())
+            DEF_POINTER_IMAGE_VTK_CREA(vMM,ssMM,pMM,stMM,bbGetInputIn2())
+            long int i,size=dimX1*dimY1*dimZ1;
+            for (i=0;i<size;i++)
+            {
+                GETVALUE2_VTK_CREA(vMA,pMA,stMA,i)
+                GETVALUE2_VTK_CREA(vMM,pMM,stMM,i)
+                ACUMULATE(vMA, vMM, tpAll, fpAll, fnAll)
+            } // for
+            double tmp;
+            std::vector<std::string> LstTitles;
+            std::vector<std::string> LstValues;
+            INSERTINVECTOR(tpAll,fpAll,fnAll)
+            bbSetOutputLstTitles(LstTitles);
+            bbSetOutputLstValues(LstValues);
+        } else {
+            printf ("EED Warning...  creaSDRAVisu VolumeMassDice::Process  Size of images are not the same. \n");
+        } // if dimXYZ I MA MM
+    } else {
+        printf ("EED Warning...  VolumeMassDice::Process  Missing input files...\n");
+    }// if
 }
-//===== 
+
+//=====
 // 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 ImageMaskDice::bbUserSetDefaultValues()
 {
-
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
     bbSetInputIn1(NULL);
     bbSetInputIn2(NULL);
-
 }
-//===== 
+
+//=====
 // 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 ImageMaskDice::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 ImageMaskDice::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
 //    if any
-  
-}
 }
-// EO namespace bbcreaVtk
+
+}// EO namespace bbcreaVtk
 
 
index 5caeea7a47e4a76f9d8718b396602fab9dfa70bb..316e4bd60626918739fb95af94ef5e0378db1170 100644 (file)
@@ -23,7 +23,8 @@ class bbcreaVtk_EXPORT ImageMaskDice
 //===== 
   BBTK_DECLARE_INPUT(In1,vtkImageData*);
   BBTK_DECLARE_INPUT(In2,vtkImageData*);
-  BBTK_DECLARE_OUTPUT(Out,double);
+  BBTK_DECLARE_OUTPUT(LstTitles, std::vector<std::string> );
+  BBTK_DECLARE_OUTPUT(LstValues, std::vector<std::string> );
   BBTK_PROCESS(Process);
   void Process();
 //===== 
@@ -34,11 +35,12 @@ class bbcreaVtk_EXPORT ImageMaskDice
 BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImageMaskDice,bbtk::AtomicBlackBox);
   BBTK_NAME("ImageMaskDice");
   BBTK_AUTHOR("InfoDev");
-  BBTK_DESCRIPTION("(C++?????,Python)");
+  BBTK_DESCRIPTION("(C++,Python)");
   BBTK_CATEGORY("empty");
   BBTK_INPUT(ImageMaskDice,In1,"Image 1",vtkImageData*,"");
   BBTK_INPUT(ImageMaskDice,In2,"Image 2",vtkImageData*,"");
-  BBTK_OUTPUT(ImageMaskDice,Out,"Dice",double,"");
+  BBTK_OUTPUT(ImageMaskDice,LstTitles,"List of titles", std::vector<std::string>  ,"");
+  BBTK_OUTPUT(ImageMaskDice,LstValues,"List of values", std::vector<std::string>  ,"");
 BBTK_END_DESCRIBE_BLACK_BOX(ImageMaskDice);
 //===== 
 // 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)