NIREP

NIREPDiceCoefficient.cpp

Go to the documentation of this file.
00001 #include "NIREPDiceCoefficient.h"
00002 #include "gecObjectMap.h"
00003 
00004 
00005 TextTable NIREPDiceCoefficient::ComputeStatistic(const std::vector<std::string>& arg, DisplayDescription * displayDescription)
00006 {
00007   const gec::ObjectMap* objmap1 =
00008     dynamic_cast<const gec::ObjectMap *>(this->evaluator->GetSpatialData(arg[0], displayDescription));
00009   const gec::ObjectMap* objmap2 =
00010     dynamic_cast<const gec::ObjectMap *>(this->evaluator->GetSpatialData(arg[1], displayDescription));
00011 
00012   int* Intersection = new int[objmap1->GetObjectEntryTableSize()];
00013   int* X = new int[objmap1->GetObjectEntryTableSize()];
00014   int* Y = new int[objmap1->GetObjectEntryTableSize()];
00015 
00016   for(int i=0; i<objmap1->GetObjectEntryTableSize(); i++) {
00017     Intersection[i] = 0;
00018     X[i] = 0;
00019     Y[i] = 0;
00020   }
00021 
00022   const int* dim = objmap1->GetVTKData()->GetDimensions();
00023   const int size = dim[0] * dim[1] * dim[2];
00024 
00025   // For fast indexing
00026   const unsigned char* objptr1 =
00027     static_cast<const unsigned char *>(objmap1->GetVTKData()->GetScalarPointer());
00028   const unsigned char* objptr2 =
00029     static_cast<const unsigned char *>(objmap2->GetVTKData()->GetScalarPointer());
00030 
00031   for(int i=0; i<size; i++) {
00032     int obj1 = static_cast<int>(*objptr1++);
00033     int obj2 = static_cast<int>(*objptr2++);
00034     X[obj1]++;
00035     Y[obj2]++;
00036     if(obj1 == obj2) {
00037       Intersection[obj1]++;
00038     }
00039   }
00040 
00041   TextTable result;
00042   result.Title = "Dice Coefficient of " + arg[0] + " and " + arg[1];
00043   result.ColumnHeading.push_back("Name");
00044   result.ColumnHeading.push_back("Dice Coefficient");
00045   std::vector<float> column;
00046   for(int i=0; i<objmap1->GetObjectEntryTableSize(); i++) {
00047     column.push_back((2 * static_cast<float>(Intersection[i]) )/(X[i] + Y[i]));
00048   }
00049   result.Value.push_back(column);
00050 
00051   delete [] Intersection;
00052   delete [] X;
00053   delete [] Y;
00054 
00055   return result;
00056 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines