123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- #include "rlist.h"
- #include <stdio.h>
- #include <stdlib.h>
-
-
-
- RegionList::RegionList(int maxRegions_, int L_, int N_)
- {
-
-
- if((maxRegions = maxRegions_) <= 0)
- ErrorHandler((char *)"RegionList", (char *)"Maximum number of regions is zero or negative.", FATAL);
-
-
- if((N = N_) <= 0)
- ErrorHandler((char *)"RegionList", (char *)"Dimension is zero or negative.", FATAL);
-
- if((L = L_) <= 0)
- ErrorHandler((char *)"RegionList", (char *)"Length of data set is zero or negative.", FATAL);
-
- if(!(indexTable = new int [L]))
- ErrorHandler((char *)"RegionList", (char *)"Not enough memory.", FATAL);
-
- if(!(regionList = new REGION [maxRegions]))
- ErrorHandler((char *)"RegionList", (char *)"Not enough memory.", FATAL);
-
- numRegions = freeRegion = 0;
-
- freeBlockLoc = 0;
-
- return;
- }
- RegionList::~RegionList( void )
- {
-
- delete [] regionList;
- delete [] indexTable;
-
- return;
- }
-
-
-
- void RegionList::AddRegion(int label, int pointCount, int *indeces)
- {
-
-
- if(numRegions >= maxRegions)
- ErrorHandler((char *)"AddRegion", (char *)"Not enough memory allocated.", FATAL);
-
- if((label < 0)||(pointCount <= 0))
- ErrorHandler((char *)"AddRegion", (char *)"Label is negative or number of points in region is invalid.", FATAL);
-
-
- if((freeBlockLoc + pointCount) > L)
- ErrorHandler((char *)"AddRegion", (char *)"Adding more points than what is contained in data set.", FATAL);
-
-
- regionList[freeRegion].label = label;
- regionList[freeRegion].pointCount = pointCount;
- regionList[freeRegion].region = freeBlockLoc;
-
- int i;
- for(i = 0; i < pointCount; i++)
- indexTable[freeBlockLoc+i] = indeces[i];
-
-
- freeBlockLoc += pointCount;
-
-
-
- freeRegion++;
- numRegions++;
-
- return;
- }
- void RegionList::Reset( void )
- {
-
- freeRegion = numRegions = freeBlockLoc = 0;
-
- return;
- }
-
-
-
- int RegionList::GetNumRegions( void )
- {
-
- return numRegions;
- }
- int RegionList::GetLabel(int regionNum)
- {
-
- return regionList[regionNum].label;
- }
- int RegionList::GetRegionCount(int regionNum)
- {
-
- return regionList[regionNum].pointCount;
- }
- int *RegionList::GetRegionIndeces(int regionNum)
- {
-
- return &indexTable[regionList[regionNum].region];
- }
-
-
-
- void RegionList::ErrorHandler(char *functName, char* errmsg, ErrorType status)
- {
-
-
- if(status == NONFATAL)
- fprintf(stderr, (char *)"\n%s Error: %s\n", functName, errmsg);
- else
- {
- fprintf(stderr, (char *)"\n%s Fatal Error: %s\n\nAborting Program.\n\n", functName, errmsg);
- exit(1);
- }
- }
|