00001 #ifndef Impala_Core_Geometry_InterestCircle_h
00002 #define Impala_Core_Geometry_InterestCircle_h
00003
00004 #include "Core/Geometry/InterestPoint.h"
00005 #include "Core/Vector/VectorTem.h"
00006 #include "Util/StringParser.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Geometry
00013 {
00014
00017 class InterestCircle : public InterestPoint {
00018 public:
00019
00020
00021 Real64 mCornerness;
00022 Real64 mDetectionScale;
00023 Real64 mScale;
00024 Real64 mOrientation;
00025
00026 InterestCircle() : InterestPoint(), mCornerness(0), mDetectionScale(0), mScale(0), mOrientation(0)
00027 {
00028 }
00029
00030 InterestCircle(Real64 xCoord, Real64 yCoord, Real64 cornerness, Real64 detectionScale=0.0)
00031 : InterestPoint(xCoord, yCoord), mCornerness(cornerness), mDetectionScale(detectionScale), mScale(0.0), mOrientation(0.0)
00032 {
00033 }
00034
00035 InterestCircle(CString region, Real64 shiftX=0, Real64 shiftY=0) : InterestPoint(), mDetectionScale(0)
00036 {
00037 if(region.substr(0, 8) != "<CIRCLE ") {
00038 throw "Get your act together: <CIRCLE should be the start!";
00039 }
00040 Util::StringParser sp(region);
00041 std::string temp = sp.GetString(' ');
00042 mX = sp.GetDouble(' ') - shiftX;
00043 mY = sp.GetDouble(' ') - shiftY;
00044 mScale = sp.GetDouble(' ');
00045 mOrientation = sp.GetDouble(' ');
00046 mCornerness = sp.GetDouble('>');
00047 }
00048
00049 InterestCircle(Vector::VectorTem<Real64>& pointVector, Real64 shiftX=0,
00050 Real64 shiftY=0)
00051 : InterestPoint(), mDetectionScale(0.0), mOrientation(0.0), mCornerness(0.0)
00052 {
00053 if(pointVector.Size() < 3)
00054 {
00055 std::cerr << "Invalid data for InterestCircle" << std::endl;
00056 throw "Invalid data";
00057 }
00058 mX = pointVector.Elem(0) - shiftX;
00059 mY = pointVector.Elem(1) - shiftY;
00060 mScale = pointVector.Elem(2);
00061 if(pointVector.Size() > 3)
00062 mOrientation = pointVector.Elem(3);
00063 if(pointVector.Size() > 4)
00064 mCornerness = pointVector.Elem(4);
00065 }
00066
00067 std::string
00068 geometryType()
00069 {
00070 return "CircleZ";
00071 }
00072
00073 std::string
00074 Serialize(Real64 shiftX=0, Real64 shiftY=0)
00075 {
00076 std::ostringstream os;
00077 os << "<CIRCLE " << mX+shiftX << " " << mY+shiftY << " " << mScale << " " << mOrientation << " " << mCornerness << ">;";
00078 return os.str();
00079 }
00080
00081 Vector::VectorTem<Real64>*
00082 PointAsVector(Real64 shiftX=0, Real64 shiftY=0)
00083 {
00084 Vector::VectorTem<Real64>* temp = new Vector::VectorTem<Real64>(5);
00085 temp->Elem(0) = mX + shiftX;
00086 temp->Elem(1) = mY + shiftY;
00087 temp->Elem(2) = mScale;
00088 temp->Elem(3) = mOrientation;
00089 temp->Elem(4) = mCornerness;
00090 return temp;
00091 }
00092 };
00093
00094 InterestCircle*
00095 MakeInterestCircle(double x, double y, double scale)
00096 {
00097 InterestCircle* c = new InterestCircle(x, y, 0);
00098 c->mScale = scale;
00099 return c;
00100 }
00101
00102 bool
00103 uniq_InterestCircle (InterestPoint* lhs2, InterestPoint* rhs2)
00104 {
00105 if(lhs2->geometryType() != "CircleZ") return false;
00106 if(rhs2->geometryType() != "CircleZ") return false;
00107 InterestCircle* lhs(dynamic_cast<InterestCircle*>(lhs2));
00108 InterestCircle* rhs(dynamic_cast<InterestCircle*>(rhs2));
00109 return (abs(lhs->mX-rhs->mX) < 0.000000001) && (abs(lhs->mY-rhs->mY)< 0.000000001) && (abs(lhs->mScale-rhs->mScale) < 0.000000001);
00110 }
00111
00112 bool
00113 compare_InterestCircle (InterestPoint* lhs2, InterestPoint* rhs2)
00114 {
00115 if((lhs2->geometryType() != "CircleZ") || (rhs2->geometryType() != "CircleZ")) {
00116 throw "compare_InterestCircle cannot compare these types!";
00117 }
00118 InterestCircle* lhs(dynamic_cast<InterestCircle*>(lhs2));
00119 InterestCircle* rhs(dynamic_cast<InterestCircle*>(rhs2));
00120
00121 if(lhs->mX < rhs->mX) {
00122 return true;
00123 } else if(abs(lhs->mX-rhs->mX) < 0.000000001) {
00124 if(lhs->mY < rhs->mY) {
00125 return true;
00126 } else if(abs(lhs->mY-rhs->mY)< 0.000000001) {
00127 if(lhs->mScale < rhs->mScale) {
00128 return true;
00129 } else if(lhs->mScale == rhs->mScale) {
00130 return false;
00131 } else {
00132 return false;
00133 }
00134 } else {
00135
00136 return false;
00137 }
00138 } else {
00139
00140 return false;
00141 }
00142 }
00143
00144 bool
00145 compare_InterestCircle_cornerness (InterestPoint* lhs2, InterestPoint* rhs2)
00146 {
00147 if((lhs2->geometryType() != "CircleZ") || (rhs2->geometryType() != "CircleZ")) {
00148 throw "compare_InterestCircle cannot compare these types!";
00149 }
00150 InterestCircle* lhs(dynamic_cast<InterestCircle*>(lhs2));
00151 InterestCircle* rhs(dynamic_cast<InterestCircle*>(rhs2));
00152
00153 if(lhs->mCornerness > rhs->mCornerness) {
00154 return true;
00155 }
00156 return false;
00157 }
00158
00159 }
00160 }
00161 }
00162
00163 #endif