NIREP
|
00001 #include "NIREPTargetOverlap.h" 00002 #include "gecObjectMap.h" 00003 00004 00005 TextTable NIREPTargetOverlap::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* Y = new int[objmap1->GetObjectEntryTableSize()]; 00014 00015 for(int i=0; i<objmap1->GetObjectEntryTableSize(); i++) { 00016 Intersection[i] = 0; 00017 Y[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 Y[obj2]++; 00033 if(obj1 == obj2) { 00034 Intersection[obj1]++; 00035 } 00036 } 00037 00038 TextTable result; 00039 result.Title = "Target Overlap of " + arg[0] + " and " + arg[1]; 00040 result.ColumnHeading.push_back("Name"); 00041 result.ColumnHeading.push_back("Dice Coefficient"); 00042 std::vector<float> column; 00043 for(int i=0; i<objmap1->GetObjectEntryTableSize(); i++) { 00044 column.push_back((static_cast<float>(Intersection[i]) )/(Y[i])); 00045 } 00046 result.Value.push_back(column); 00047 00048 delete [] Intersection; 00049 delete [] Y; 00050 00051 return result; 00052 }