From 413fe3d099587b0dd30c8bd228a9c5f2cdf09284 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Mon, 4 Nov 2024 13:27:22 +0100 Subject: [PATCH] #3531 ImageMaskDice box --- .../src/bbcreaVtkImageMaskDice.cxx | 107 +++++++++++++----- bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.h | 8 +- 2 files changed, 85 insertions(+), 30 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.cxx index 23b4330..5272ac3 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.cxx @@ -3,77 +3,130 @@ //===== #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 LstTitles; + std::vector 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 diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.h b/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.h index 5caeea7..316e4bd 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageMaskDice.h @@ -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 ); + BBTK_DECLARE_OUTPUT(LstValues, std::vector ); 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 ,""); + BBTK_OUTPUT(ImageMaskDice,LstValues,"List of values", std::vector ,""); 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) -- 2.47.1