35 #include "segm/rlist.h"
67 RegionList::RegionList(
int maxRegions_,
int L_,
int N_)
72 if((maxRegions = maxRegions_) <= 0)
73 ErrorHandler(
"RegionList",
"Maximum number of regions is zero or negative.", FATAL);
78 ErrorHandler(
"RegionList",
"Dimension is zero or negative.", FATAL);
82 ErrorHandler(
"RegionList",
"Length of data set is zero or negative.", FATAL);
85 if(!(indexTable =
new int [L]))
86 ErrorHandler(
"RegionList",
"Not enough memory.", FATAL);
89 if(!(regionList =
new REGION [maxRegions]))
90 ErrorHandler(
"RegionList",
"Not enough memory.", FATAL);
93 numRegions = freeRegion = 0;
113 RegionList::~RegionList(
void )
116 delete [] regionList;
117 delete [] indexTable;
147 void RegionList::AddRegion(
int label,
int pointCount,
int *indeces)
152 if(numRegions >= maxRegions)
153 ErrorHandler(
"AddRegion",
"Not enough memory allocated.", FATAL);
156 if((label < 0)||(pointCount <= 0))
157 ErrorHandler(
"AddRegion",
"Label is negative or number of points in region is invalid.", FATAL);
161 if((freeBlockLoc + pointCount) > L)
162 ErrorHandler(
"AddRegion",
"Adding more points than what is contained in data set.", FATAL);
166 regionList[freeRegion].label = label;
167 regionList[freeRegion].pointCount = pointCount;
168 regionList[freeRegion].region = freeBlockLoc;
172 for(i = 0; i < pointCount; i++)
173 indexTable[freeBlockLoc+i] = indeces[i];
177 freeBlockLoc += pointCount;
199 void RegionList::Reset(
void )
203 freeRegion = numRegions = freeBlockLoc = 0;
224 int RegionList::GetNumRegions(
void )
243 int RegionList::GetLabel(
int regionNum)
246 return regionList[regionNum].label;
263 int RegionList::GetRegionCount(
int regionNum)
266 return regionList[regionNum].pointCount;
283 int *RegionList::GetRegionIndeces(
int regionNum)
286 return &indexTable[regionList[regionNum].region];
320 void RegionList::ErrorHandler(
const char *functName,
const char* errmsg, ErrorType status)
325 if(status == NONFATAL)
326 fprintf(stderr,
"\n%s Error: %s\n", functName, errmsg);
329 fprintf(stderr,
"\n%s Fatal Error: %s\n\nAborting Program.\n\n", functName, errmsg);