X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=bbtk_creaVtk_PKG%2Fsrc%2FbbcreaVtkKMeansStatistics.cxx;fp=bbtk_creaVtk_PKG%2Fsrc%2FbbcreaVtkKMeansStatistics.cxx;h=45370ac1ed028cf4fec6c0db3568ba805a95df90;hb=5295954f425da0c7c12d0bd458289ab82945423b;hp=0000000000000000000000000000000000000000;hpb=95ad6b166169711fa0fe3c1fd984d86430a6c603;p=creaVtk.git diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkKMeansStatistics.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkKMeansStatistics.cxx new file mode 100644 index 0000000..45370ac --- /dev/null +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkKMeansStatistics.cxx @@ -0,0 +1,214 @@ +//===== +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + + +#include "bbcreaVtkKMeansStatistics.h" +#include "bbcreaVtkPackage.h" +namespace bbcreaVtk +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,KMeansStatistics) +BBTK_BLACK_BOX_IMPLEMENTATION(KMeansStatistics,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 KMeansStatistics::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 = " < inputData; + int ext[6]; + int dimX,dimY,dimZ; + bbGetInputIn()->GetExtent(ext); + dimX = ext[1]-ext[0]+1; + dimY = ext[3]-ext[2]+1; + dimZ = ext[5]-ext[4]+1; + + vtkImageData *resultImage = vtkImageData::New(); + resultImage->Initialize(); + resultImage->SetSpacing( bbGetInputIn()->GetSpacing() ); + resultImage->SetDimensions( dimX, dimY, dimZ ); + resultImage->AllocateScalars( VTK_SHORT ,1 ); + + long int size= dimX*dimY*dimZ; + vtkDoubleArray *doubleArrayX = vtkDoubleArray::New(); + vtkDoubleArray *doubleArrayY = vtkDoubleArray::New(); + vtkDoubleArray *doubleArrayZ = vtkDoubleArray::New(); + vtkDoubleArray *doubleArrayValue1 = vtkDoubleArray::New(); + vtkDoubleArray *doubleArrayValue2 = vtkDoubleArray::New(); + vtkDoubleArray *doubleArrayValue3 = vtkDoubleArray::New(); + doubleArrayX->SetNumberOfComponents(1); + doubleArrayY->SetNumberOfComponents(1); + doubleArrayZ->SetNumberOfComponents(1); + doubleArrayValue1->SetNumberOfComponents(1); + doubleArrayValue2->SetNumberOfComponents(1); + doubleArrayValue3->SetNumberOfComponents(1); + doubleArrayX->SetName("X"); + doubleArrayY->SetName("Y"); + doubleArrayZ->SetName("Z"); + doubleArrayValue1->SetName("Value1"); + doubleArrayValue2->SetName("Value2"); + doubleArrayValue3->SetName("Value3"); + doubleArrayX->SetNumberOfTuples( size ); + doubleArrayY->SetNumberOfTuples( size ); + doubleArrayZ->SetNumberOfTuples( size ); + if (bbGetInputIn()->GetNumberOfScalarComponents()>=1) { doubleArrayValue1->SetNumberOfTuples( size ); } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=2) { doubleArrayValue2->SetNumberOfTuples( size ); } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=3) { doubleArrayValue3->SetNumberOfTuples( size ); } + + double value; + int x,y,z; + for ( z=0 ; zSetValue(x + y*dimX + z*dimX*dimY, x ); + doubleArrayY->SetValue(x + y*dimX + z*dimX*dimY, y ); + doubleArrayZ->SetValue(x + y*dimX + z*dimX*dimY, z ); + if (bbGetInputIn()->GetNumberOfScalarComponents()>=1) + { + value = bbGetInputIn()->GetScalarComponentAsDouble(x,y,z,0); + doubleArrayValue1->SetValue( x + y*dimX + z*dimX*dimY , value ); + } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=2) + { + value = bbGetInputIn()->GetScalarComponentAsDouble(x,y,z,1); + doubleArrayValue2->SetValue( x + y*dimX + z*dimX*dimY , value ); + } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=3) + { + value = bbGetInputIn()->GetScalarComponentAsDouble(x,y,z,2); + doubleArrayValue3->SetValue( x + y*dimX + z*dimX*dimY , value ); + } + } // for x + } // for y + }// for z + + inputData->AddColumn(doubleArrayX); + inputData->AddColumn(doubleArrayY); + inputData->AddColumn(doubleArrayZ); + if (bbGetInputIn()->GetNumberOfScalarComponents()>=1) { inputData->AddColumn(doubleArrayValue1); } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=2) { inputData->AddColumn(doubleArrayValue2); } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=3) { inputData->AddColumn(doubleArrayValue3); } + + + printf("EED KMeansStatistics::Process 1\n"); + + vtkNew kMeansStatistics; + kMeansStatistics->SetInputData(vtkStatisticsAlgorithm::INPUT_DATA, inputData); + kMeansStatistics->SetColumnStatus(inputData->GetColumnName(0), 1); + kMeansStatistics->SetColumnStatus(inputData->GetColumnName(1), 1); + kMeansStatistics->SetColumnStatus(inputData->GetColumnName(2), 1); + if (bbGetInputIn()->GetNumberOfScalarComponents()>=1) { kMeansStatistics->SetColumnStatus(inputData->GetColumnName(3), 1); } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=2) { kMeansStatistics->SetColumnStatus(inputData->GetColumnName(4), 1); } + if (bbGetInputIn()->GetNumberOfScalarComponents()>=3) { kMeansStatistics->SetColumnStatus(inputData->GetColumnName(5), 1); } + + kMeansStatistics->RequestSelectedColumns(); + kMeansStatistics->SetAssessOption(true); + kMeansStatistics->SetDefaultNumberOfClusters( bbGetInputNumberOfClusters() ); + kMeansStatistics->Update(); + +// Display the results +// kMeansStatistics->GetOutput()->Dump(); + for ( z=0 ; zGetOutput()->GetValue( r, kMeansStatistics->GetOutput()->GetNumberOfColumns() - 1); + resultImage->SetScalarComponentFromDouble(x,y,z,0,(double) (v.ToInt()) ); + } // for x + } // for y + }// for z + bbSetOutputOut( resultImage ); + printf("EED KMeansStatistics::Process Start\n"); +} +//===== +// 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 KMeansStatistics::bbUserSetDefaultValues() +{ + +// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX +// Here we initialize the input 'In' to 0 + bbSetInputIn(NULL); + bbSetInputNumberOfClusters(3); + +} +//===== +// 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 KMeansStatistics::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 KMeansStatistics::bbUserFinalizeProcessing() +{ + +// THE FINALIZATION METHOD BODY : +// Here does nothing +// but this is where you should desallocate the internal/output pointers +// if any + +} +} +// EO namespace bbcreaVtk + +