www.pudn.com > colortracker.rar > mainutil.h


#ifndef __MAINUTIL__H__ 
#define __MAINUTIL__H__ 
 
#include  
#include  
#include  
#include  
 
// ================================================================================================ 
 
struct ROISequence { 
	int numframes; 
	float beginx, endx, beginy, endy, begins, ends, curx, cury, curs, incrx, incry, incrs; 
 
	ROISequence(float _bx, float _ex, float _by, float _ey, float _bs, float _es, int _n) { 
		beginx = _bx;	endx = _ex; 
		beginy = _by; endy = _ey; 
		begins = _bs; ends = _es; 
		numframes = _n; 
		curx = _bx; cury = _by; curs = _bs; 
		incrx = fabs(endx-beginx)/numframes; 
		incry = fabs(endy-beginy)/numframes; 
		incrs = fabs(ends-begins)/numframes; 
	} 
	 
	inline void getnext (float &x, float &y, float &s) { 
			x = (beginx < endx) ? curx += incrx : curx -= incrx; 
			y = (beginy < endy) ? cury += incry : cury -= incry; 
			s = (begins < ends) ? curs += incrs : curs -= incrs; 
	} 
}; 
 
// ================================================================================================ 
 
struct Timeline { 
	int numframes, curframe; 
	typedef multimap< pair, ROISequence> EntryMap; 
	EntryMap entries; 
 
	Timeline() : numframes(0), curframe(0) {} 
 
	void addEntry(int timept, float bx, float ex, float by, float ey, float bs, float es, int nf) { 
		numframes = (numframes>timept+nf) ? numframes : timept + nf; 
		entries.insert(EntryMap::value_type(make_pair(timept, timept+nf), ROISequence(bx, ex, by, ey, bs, es, nf))); 
	} 
 
	void getROISequences(int timept, list &seq) { 
		seq.clear(); 
		for (EntryMap::iterator pos = entries.begin(); pos != entries.end(); ++pos) { 
			pair timerange = pos->first; 
			ROISequence &ROIs = pos->second; 
 
			if (timept >= timerange.first && timept < timerange.second) 
				seq.push_back(&ROIs); 
		} 
	} 
}; 
 
// ================================================================================================ 
 
/* draw number from normal random distribution */ 
inline double normal(const double &mean, const double &std) 
{  
  static const double pii=3.1415927; 
  static const double r_max=RAND_MAX+1; 
  return std*sqrt(-2*log((rand()+1)/r_max))*sin(2*pii*rand()/r_max)+mean; 
}  
 
// ================================================================================================ 
 
inline void drawBack(TIntegral &likratimage, float mean, float var) { 
	for (int y = 0; y < likratimage.getImHeight(); y++) { 
		for (int x = 0; x < likratimage.getImWidth(); x++) 
			likratimage.setImPixel(x, y, normal(mean, var)); 
	} 
} 
 
// ================================================================================================ 
 
inline void drawROI(TIntegral &likratimage, TBox &roi, float mean, float var) { 
	for (int y=roi.y; y < roi.y+roi.size; y++) { 
		for (int x=roi.x; x < roi.x+roi.size; x++) { 
			if (x > likratimage.getImWidth()-1 ||  
					y > likratimage.getImHeight()-1 || 
					x < 0 || y < 0) 
				continue; 
			likratimage.setImPixel(x, y, normal(mean, var));	 
		} 
	} 
} 
 
// ================================================================================================ 
 
 
#endif __MAINUTIL__H__