From f761578b6f9d1e87c03d64cf8019fb116fc142e1 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Wed, 4 Feb 2026 16:48:14 +0100 Subject: [PATCH] #3536 BestPoint --- bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx | 185 ++++++++++++++++++++ bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.h | 56 ++++++ 2 files changed, 241 insertions(+) create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx create mode 100644 bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.h diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx new file mode 100644 index 0000000..f444ed9 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx @@ -0,0 +1,185 @@ +//===== +// 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) +//===== +#include "bbcreaVtkBestPoint.h" +#include "bbcreaVtkPackage.h" +namespace bbcreaVtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,BestPoint) +BBTK_BLACK_BOX_IMPLEMENTATION(BestPoint,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) +//===== +void BestPoint::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 + // 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') +// bbSetOutputOut( bbGetInputIn() ); +// std::cout << "Output value = " < outPoint; + outPoint.push_back(-999); + outPoint.push_back(-999); + outPoint.push_back(-999); + + if ( (bbGetInputIn()!=NULL) && (bbGetInputInPoint().size()==3) ) + { + bool ok; + int i,j,k; + int size; + int dimX; + int dimY; + int dimZ; + double value; + double dx,dy,dz; + int x,y,z; + double M1,M2,D2,G; + double FG,FGback; + int minX,minY,minZ; + int maxX,maxY,maxZ; + int ext[6]; + G = 1; + M1 = 1; + bbGetInputIn()->GetExtent(ext); + dimX=ext[1]-ext[0]+1; + dimY=ext[3]-ext[2]+1; + dimZ=ext[5]-ext[4]+1; + + x = bbGetInputInPoint()[0]; + y = bbGetInputInPoint()[1]; + z = bbGetInputInPoint()[2]; + + if (bbGetInputType()==1) { outputValue = -9999999; } // finding max + if (bbGetInputType()==2) { outputValue = 9999999; } // finding min + if (bbGetInputType()==3) { FGback = -9999999; } // finding FG max + if (bbGetInputType()==4) { FGback = 9999999; } // finding FG min + + minX = x - bbGetInputBoxSize(); + minY = y - bbGetInputBoxSize(); + minZ = z - bbGetInputBoxSize(); + maxX = x + bbGetInputBoxSize(); + maxY = y + bbGetInputBoxSize(); + maxZ = z + bbGetInputBoxSize(); + + if (minX<0) { minX = 0; } + if (minY<0) { minY = 0; } + if (minZ<0) { minZ = 0; } + if (maxX>=dimX) { maxX = dimX-1; } + if (maxY>=dimY) { maxY = dimY-1; } + if (maxZ>=dimZ) { maxZ = dimZ-1; } + + for (i=minX;iGetScalarComponentAsDouble(i,j,k,0); + if (bbGetInputType()==1) // max + { + if ( value > outputValue) + { + ok=true; + } // if max + } // if Type == 1 + if (bbGetInputType()==2) // min + { + if ( value < outputValue) + { + ok=true; + } // if max + } // if Type == 2 + if ((bbGetInputType()==3) || (bbGetInputType()==4) ) // FG + { + M2 = value; + dx = x - i; + dy = y - j; + dz = z - k; + D2 = dx*dx + dy*dy + dz*dz; + if (D2==0) {D2=0.000000001;} + FG = G * M1 * M2 / D2; + } // if Type == 3 or 4 + if (bbGetInputType()==3) // max + { + if ( FG > FGback) + { + ok = true; + FGback = FG; + } // if max + } // if Type == 3 + if (bbGetInputType()==4) // min + { + if ( FG < FGback) + { + ok = true; + FGback = FG; + } // if max + } // if Type == 4 + + if ( ok==true) + { + outputValue = value; + outPoint[0] = i; + outPoint[1] = j; + outPoint[2] = k; + printf("EED BestPoint::Process %d %d %d - %d %d %d \n",x,y,z,i,j,k); + } // if ok + + + }// for k + }// for j + }// for i + } // if In != NULL && InPoint.size ==3 + + bbSetOutputOut(outPoint); + bbSetOutputValue(outputValue); +} + +//===== +// 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 BestPoint::bbUserSetDefaultValues() +{ + // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX + // Here we initialize the input 'In' to 0 + bbSetInputIn(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 BestPoint::bbUserInitializeProcessing() +{ + // THE INITIALIZATION METHOD BODY : + // Here does nothing + // but this is where you should allocate the internal/output pointers + // 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 BestPoint::bbUserFinalizeProcessing() +{ + // THE FINALIZATION METHOD BODY : + // Here does nothing + // but this is where you should desallocate the internal/output pointers + // if any +} + +}// EO namespace bbcreaVtk + + diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.h b/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.h new file mode 100644 index 0000000..ee0aa02 --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.h @@ -0,0 +1,56 @@ +//===== +// 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) +//===== +#ifndef __bbcreaVtkBestPoint_h_INCLUDED__ +#define __bbcreaVtkBestPoint_h_INCLUDED__ + +#include "bbcreaVtk_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "iostream" + +#include + +namespace bbcreaVtk +{ + +class bbcreaVtk_EXPORT BestPoint + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(BestPoint,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) +//===== + BBTK_DECLARE_INPUT(In,vtkImageData*); + BBTK_DECLARE_INPUT(Type,int); + BBTK_DECLARE_INPUT(BoxSize,int); + BBTK_DECLARE_INPUT(InPoint,std::vector); + BBTK_DECLARE_OUTPUT(Out,std::vector); + BBTK_DECLARE_OUTPUT(Value,double); + BBTK_PROCESS(Process); + void Process(); +//===== +// 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) +//===== +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(BestPoint,bbtk::AtomicBlackBox); + BBTK_NAME("BestPoint"); + BBTK_AUTHOR("InfoDev"); + BBTK_DESCRIPTION("No Description."); + BBTK_CATEGORY("empty"); + BBTK_INPUT(BestPoint,In,"Input image",vtkImageData*,""); + BBTK_INPUT(BestPoint,Type,"0:nothing, 1:point max value, 2:point mininum value 3:Gravitational max point, 4:Gravitational min point",int,""); + BBTK_INPUT(BestPoint,BoxSize,"Box size to searche the best point (impar number)",int,""); + BBTK_INPUT(BestPoint,InPoint,"Input point",std::vector,""); + BBTK_OUTPUT(BestPoint,Out,"Output point",std::vector,""); + BBTK_OUTPUT(BestPoint,Value,"Output value",double,""); +BBTK_END_DESCRIBE_BLACK_BOX(BestPoint); +//===== +// 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) +//===== +} +// EO namespace bbcreaVtk + +#endif // __bbcreaVtkBestPoint_h_INCLUDED__ + -- 2.52.0