31 #include <gsl/gsl_rng.h> 47 CentroidApolloPan::CentroidApolloPan(
double pixelSizeMicrons)
49 if( pixelSizeMicrons > 0)
50 this->m_pixelSize = pixelSizeMicrons;
52 this->m_pixelSize = 5.0;
59 CentroidApolloPan::~CentroidApolloPan(){};
68 bool CentroidApolloPan::setPixelSize(
double microns)
70 if( microns <= 0)
return false;
71 this->m_pixelSize = microns;
85 int CentroidApolloPan::selectAdaptive(
Chip *inputChip,
Chip *selectionChip) {
104 double minDN,maxDN,temp;
108 lines = inputChip->
Lines();
109 samples = inputChip->
Samples();
112 if (lines <= 0 || samples <= 0)
116 minDN = this->getMinDN();
117 maxDN = this->getMaxDN();
120 for (i=1;i<=lines;i++) {
121 if (i == 1 || i == lines) {
127 for(j=1;j<=samples;j+=step) {
128 dn.push_back(inputChip->
GetValue(j,i));
138 for (k=1;k<int(dn.size());k++) {
145 if (i <
int(j/10)) dn.erase(dn.begin()+l);
149 if( temp > minDN) this->setDNRange(temp,maxDN);
153 this->select(inputChip,selectionChip);
155 this->setDNRange(minDN,maxDN);
203 int CentroidApolloPan::elipticalReduction(
Chip *selectionChip,
double percent_selected,
204 double play,
int patience_limit)
212 std::vector< std::vector<int> > pts;
213 std::vector< std::vector<double> > cen_pts;
215 std::vector<double> pt(2);
219 double a = 60.0*5.0/m_pixelSize,
220 b = 60.0*5.0/m_pixelSize,
224 gsl_rng *randGen = gsl_rng_alloc(gsl_rng_taus);
225 gsl_rng_set(randGen, time(NULL));
227 samples = selectionChip->
Samples();
228 lines = selectionChip->
Lines();
232 k = int(ceil(
double(samples) - a));
233 l = int(ceil(
double(lines ) - b));
244 double searchStep = 5.0*5.0/m_pixelSize;
245 double aSearch,centerSample,centerLine,delta,cSearch;
246 cSearch = searchStep/5.0;
247 centerSample = double((k+i)/2.0);
248 centerLine = double((l+j)/2.0);
249 delta = (centerSample-double(i))*(centerSample-
double(i)) + (centerLine -
double(l))*(centerLine -
double(l));
251 aSearch = (searchStep-cSearch)/delta;
253 for (pt[0]=floor(a+1.0); pt[0]<k; pt[0]+=searchStep) {
254 for (pt[1]=floor(b+1.0); pt[1]<l; pt[1]+=searchStep) {
255 cen_pts.push_back(pt);
256 delta = (centerSample-double(pt[0]))*(centerSample-
double(pt[0])) + (centerLine-
double(pt[1]))*(centerLine-
double(pt[1]));
257 searchStep = aSearch*delta + cSearch;
258 if (searchStep > l - pt[1] && l - pt[1] > 1e-4)
259 searchStep = l - pt[1];
261 if (searchStep > k - pt[0] && k - pt[0] > 1e-4)
262 searchStep = k - pt[0];
266 selectionEdge(selectionChip,&pts);
269 if (pts.size() ==0)
return 0;
274 while (emptySets < patience_limit && cen_pts.size()>0) {
277 randPt = gsl_rng_uniform_int( randGen ,cen_pts.size() );
278 dpt[0] = cen_pts[randPt][0];
279 dpt[1] = cen_pts[randPt][1];
281 cen_pts.erase( cen_pts.begin() + randPt);
284 ellipseFromCenterAxesAngle(&ellNew, dpt[0], dpt[1], a, b, 0.0);
288 if (!bestFitEllipse(&ellNew, &pts, play, 50)) {
294 if (ellNew.area < ellBest.area) {
299 if (!ellipseInChip(&ellNew,selectionChip)) {
305 if (elipsePercentSelected(selectionChip,&ellNew) < percent_selected) {
313 ellBest.area = ellNew.area;
314 ellBest.A[0] = ellNew.A[0];
315 ellBest.A[1] = ellNew.A[1];
316 ellBest.A[2] = ellNew.A[2];
318 ellBest.cen[0] = ellNew.cen[0];
319 ellBest.cen[1] = ellNew.cen[1];
321 ellBest.semiMajor = ellNew.semiMajor;
322 ellBest.semiMinor = ellNew.semiMinor;
323 ellBest.majorAxis[0] = ellNew.majorAxis[0];
324 ellBest.majorAxis[1] = ellNew.majorAxis[1];
325 ellBest.minorAxis[0] = ellNew.minorAxis[0];
326 ellBest.minorAxis[1] = ellNew.minorAxis[1];
329 if( ellBest.area == 0)
335 for (i=1;i<=samples;i++) {
336 for (j=1;j<=lines;j++) {
340 if (!pointInEllipse(&ellBest,dpt,play)) {
341 if( selectionChip->
GetValue(i,j) == 1)
A small chip of data used for pattern matching.
Namespace for the standard library.
void SetValue(int sample, int line, const double &value)
Sets a value in the chip.
Namespace for ISIS/Bullet specific routines.
double GetValue(int sample, int line)
Loads a Chip with a value.