SimpleActiveList.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 CSIRO ICT Centre
00003  *
00004  * $Id: SimpleActiveList.cpp 5491 2009-02-05 18:09:29Z RossCollins $
00005  */
00006 
00007 #include <deque>
00008 
00009 #include "ActiveObject.h"
00010 #include "Object.h"
00011 #include "ObjectPairConsumer.h"
00012 #include "ObjectConsumer.h"
00013 #include "Profiler.h"
00014 #include "SimpleActiveList.h"
00015 
00016 
00017 SimpleActiveList::SimpleActiveList()
00018     : ActiveList(),
00019       activeStructure()
00020 {
00021 }
00022 
00023 SimpleActiveList::~SimpleActiveList()
00024 {
00025 }
00026 
00027 void SimpleActiveList::pushBack(Object const * object, bool matchedPreviously)
00028 {
00029   activeStructure.push_back(new ActiveObject(object, matchedPreviously));
00030 }
00031 
00032 void SimpleActiveList::deletePriorObjects(double boundary,
00033                                           ObjectConsumer * uActiveCons)
00034 {
00035   while (!activeStructure.empty())
00036   {
00037     ActiveObject * activeObject = activeStructure.front();
00038     Object const * object = activeObject->getObject();
00039     if (object->getDec() < boundary)
00040     {
00041       if (!(activeObject->isMatched()))
00042         uActiveCons->report(object);
00043 
00044       activeStructure.pop_front();
00045       delete object;
00046       delete activeObject;
00047     }
00048     else
00049     {
00050       break;
00051     }
00052   }
00053 }
00054 
00055 /* Find all objects in the active list that are near a test object.
00056  * By the time we get to this object, we already know that all
00057  * the objects in the active list are nearby in the declination
00058  * dimension, so we only need to check for proximity in right
00059  * ascension. */
00060 
00061 bool SimpleActiveList::testObject(Object const * testObject,
00062                                   double upperLimitOnDistance,
00063                                   ObjectPairConsumer * matchedConsumer)
00064 {
00065   if (profiler != 0)
00066   {
00067     profiler->registerActiveListSize(activeStructure.size());
00068   }
00069 
00070   bool testObjectMatched = false;
00071 
00072   // compute an upper bound on the distance away in ra of a matching object
00073   double upperLimitOnRaDistance = Object::computeRACorrection(
00074                                                           upperLimitOnDistance,
00075                                                           testObject->getDec());
00076 
00077   // compute a lower bound on right ascension.
00078   double lowerBound = testObject->getRa() - upperLimitOnRaDistance;
00079 
00080   // compute an upper bound on right ascension.
00081   double upperBound = testObject->getRa() + upperLimitOnRaDistance;
00082 
00083   // adjust bounds as required
00084   if (lowerBound < 0.0)
00085     lowerBound += 360.0;
00086 
00087   if (upperBound > 360.0)
00088     upperBound -= 360.0;
00089 
00090   // Test all objects as intersecting the RA upper and lower
00091   // bounds, being careful of "wrapping" at the prime meridian.
00092   for (SAL::iterator i = activeStructure.begin();
00093                             i != activeStructure.end(); i++)
00094   {
00095     ActiveObject * activeObject = *i;
00096     Object const * matchingObject = activeObject->getObject();
00097 
00098     if (((matchingObject->getRa() >= lowerBound) ==
00099          (matchingObject->getRa() <= upperBound)) ==
00100           (lowerBound <= upperBound))
00101     {
00102       if (matchedConsumer->report(testObject, matchingObject))
00103       {
00104         testObjectMatched = true;
00105         activeObject->markMatched();
00106       }
00107     }
00108   }
00109 
00110   return testObjectMatched;
00111 }
00112 
00113 /* clear out the active list, reporting things unmatched if
00114  * necessary. */
00115 void SimpleActiveList::clear(ObjectConsumer * uActiveCons)
00116 {
00117   while (!activeStructure.empty())
00118   {
00119     ActiveObject * activeObject = activeStructure.front();
00120     Object const * object = activeObject->getObject();
00121     if (!(activeObject->isMatched()))
00122       uActiveCons->report(object);
00123 
00124     activeStructure.pop_front();
00125     delete object;
00126     delete activeObject;
00127   }
00128 }
00129 
00130 /* clean up the active list, then announce completion */
00131 void SimpleActiveList::finished(ObjectConsumer * uActiveCons)
00132 {
00133   clear(uActiveCons);
00134 }
00135 
00136 bool SimpleActiveList::isEmpty()
00137 {
00138   return (activeStructure.empty());
00139 }
00140 
00141 ActiveObject * SimpleActiveList::popFront()
00142 {
00143   ActiveObject * front = activeStructure.front();
00144   activeStructure.pop_front();
00145   return front;
00146 }
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3