NIREP

NIREPRelativeOverlap.cxx

Go to the documentation of this file.
00001 #include "NIREPRelativeOverlap.h"
00002 #include "gecObjectMap.h"
00003 
00004 
00005 TextTable NIREPRelativeOverlap::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* Union = new int[objmap1->GetObjectEntryTableSize()];
00014 
00015   for(int i=0; i<objmap1->GetObjectEntryTableSize(); i++) {
00016     Intersection[i] = 0;
00017     Union[i] = 0;
00018   }
00019 
00020   const int* dim = objmap1->GetVTKData()->GetDimensions();
00021   const int size = dim[0] * dim[1] * dim[2];
00022 
00023   // For fast indexing
00024   const unsigned char* objptr1 =
00025     static_cast<const unsigned char *>(objmap1->GetVTKData()->GetScalarPointer());
00026   const unsigned char* objptr2 =
00027     static_cast<const unsigned char *>(objmap2->GetVTKData()->GetScalarPointer());
00028 
00029   for(int i=0; i<size; i++) {
00030     int obj1 = static_cast<int>(*objptr1++);
00031     int obj2 = static_cast<int>(*objptr2++);
00032     Union[obj1]++;
00033     Union[obj2]++;
00034     if(obj1 == obj2) {
00035       Intersection[obj1]++;
00036       Union[obj1]--;
00037     }
00038   }
00039 
00040   TextTable result;
00041   result.Title = "Relative Overlap of " + arg[0] + " and " + arg[1];
00042   result.ColumnHeading.push_back("Name");
00043   result.ColumnHeading.push_back("Relative Overlap");
00044   std::vector<float> column;
00045   for(int i=0; i<objmap1->GetObjectEntryTableSize(); i++) {
00046     column.push_back(static_cast<float>(Intersection[i])/static_cast<float>(Union[i]));
00047   }
00048   result.Value.push_back(column);
00049 
00050   delete [] Intersection;
00051   delete [] Union;
00052 
00053   return result;
00054 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines