00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008 #include "TripleMatchSetCorner.h"
00009
00010 #include <vcl_cassert.h>
00011 #include <vcl_vector.h>
00012 #include <mvl/HomgInterestPointSet.h>
00013 #include <mvl/PairMatchSetCorner.h>
00014
00015 static void set_size(vcl_vector<HomgPoint2D>& v, unsigned n)
00016 {
00017 v.resize(n);
00018 }
00019
00020
00021 TripleMatchSetCorner::TripleMatchSetCorner():
00022 TripleMatchSet(0,0)
00023 {
00024 }
00025
00026
00027 TripleMatchSetCorner::TripleMatchSetCorner(HomgInterestPointSet const* lines1,
00028 HomgInterestPointSet const* lines2,
00029 HomgInterestPointSet const* lines3):
00030 TripleMatchSet(new PairMatchSetCorner(lines1, lines2),
00031 new PairMatchSetCorner(lines2, lines3))
00032 {
00033 }
00034
00035
00036 TripleMatchSetCorner::TripleMatchSetCorner(const PairMatchSetCorner& match12,
00037 const PairMatchSetCorner& match23):
00038 TripleMatchSet(new PairMatchSetCorner(match12.get_corners1(), match12.get_corners2()),
00039 new PairMatchSetCorner(match23.get_corners1(), match23.get_corners2()))
00040 {
00041 assert(match23.get_corners1() == match12.get_corners2());
00042 set_from_pairwise_matches(match12, match23);
00043 }
00044
00045
00046 TripleMatchSetCorner::TripleMatchSetCorner(const TripleMatchSetCorner& that):
00047 TripleMatchSet(new PairMatchSetCorner(that.get_corners1(), that.get_corners2()),
00048 new PairMatchSetCorner(that.get_corners2(), that.get_corners3()))
00049 {
00050 set_from_pairwise_matches(*that.match12_, *that.match23_);
00051 }
00052
00053
00054
00055 void TripleMatchSetCorner::extract_matches(vcl_vector<HomgPoint2D> &points1, vcl_vector<int> &indices1,
00056 vcl_vector<HomgPoint2D> &points2, vcl_vector<int> &indices2,
00057 vcl_vector<HomgPoint2D> &points3, vcl_vector<int> &indices3) const
00058 {
00059 const HomgInterestPointSet* corners1 = get_corners1();
00060 const HomgInterestPointSet* corners2 = get_corners2();
00061 const HomgInterestPointSet* corners3 = get_corners3();
00062
00063 unsigned size = count();
00064 set_size(points1, size);
00065 set_size(points2, size);
00066 set_size(points3, size);
00067
00068 indices1.resize(size);
00069 indices2.resize(size);
00070 indices3.resize(size);
00071
00072 unsigned i = 0;
00073 for (iterator p = begin(); p; ++p, ++i) {
00074 indices1[i] = p.get_i1();
00075 indices2[i] = p.get_i2();
00076 indices3[i] = p.get_i3();
00077 points1[i] = corners1->get_homg(indices1[i]);
00078 points2[i] = corners2->get_homg(indices2[i]);
00079 points3[i] = corners3->get_homg(indices3[i]);
00080 }
00081 }
00082
00083
00084 void TripleMatchSetCorner::extract_matches(vcl_vector <HomgPoint2D>& points1,
00085 vcl_vector <HomgPoint2D>& points2,
00086 vcl_vector <HomgPoint2D>& points3) const
00087 {
00088 const HomgInterestPointSet* corners1 = get_corners1();
00089 const HomgInterestPointSet* corners2 = get_corners2();
00090 const HomgInterestPointSet* corners3 = get_corners3();
00091
00092 unsigned size = count();
00093 set_size(points1, size);
00094 set_size(points2, size);
00095 set_size(points3, size);
00096
00097 int i = 0;
00098 for (iterator p = begin(); p; ++p, ++i) {
00099 points1[i] = corners1->get_homg(p.get_i1());
00100 points2[i] = corners2->get_homg(p.get_i2());
00101 points3[i] = corners3->get_homg(p.get_i3());
00102 }
00103 }
00104
00105 #ifdef MAIN
00106 main()
00107 {
00108 HomgInterestPointSet c1;
00109 HomgInterestPointSet c2;
00110 HomgInterestPointSet c3;
00111
00112 c1.add(1, 1, 0);
00113 c1.add(1, 2, 0);
00114 c1.add(1, 3, 0);
00115 c1.add(1, 4, 0);
00116
00117 c2.add(2, 1, 0);
00118 c2.add(2, 2, 0);
00119 c2.add(2, 3, 0);
00120 c2.add(2, 4, 0);
00121
00122 c3.add(3, 1, 0);
00123 c3.add(3, 2, 0);
00124 c3.add(3, 3, 0);
00125 c3.add(3, 4, 0);
00126
00127 TripleMatchSetCorner fred(c1, c2, c3);
00128 fred.add_match(1,2,1);
00129 fred.add_match(2,1,2);
00130 fred.add_match(3,3,3);
00131
00132 vcl_vector<HomgPoint2D> p1;
00133 vcl_vector<HomgPoint2D> p2;
00134 vcl_vector<HomgPoint2D> p3;
00135
00136 vcl_cerr << "count = " << fred.count() << vcl_endl;
00137
00138 fred.extract_matches(p1, p2, p3);
00139
00140 vcl_cerr << p1 << vcl_endl;
00141 }
00142 #endif