10 #include "aliceVision/numeric/numeric.hpp"
26 friend std::ostream& operator<<(std::ostream& out,
const PointFeature& obj);
27 friend std::istream& operator>>(std::istream& in,
PointFeature& obj);
31 PointFeature(
float x,
float y,
float scale,
float orient)
37 float x()
const {
return _coords(0); }
38 float y()
const {
return _coords(1); }
39 const Vec2f& coords()
const {
return _coords; }
40 float scale()
const {
return _scale; }
41 float& scale() {
return _scale; }
43 float& x() {
return _coords(0); }
44 float& y() {
return _coords(1); }
45 Vec2f& coords() {
return _coords; }
47 float orientation()
const {
return _orientation; }
48 float& orientation() {
return _orientation; }
64 return (_scale == b.scale()) && (_orientation == b.orientation()) && (x() == b.x()) && (y() == b.y());
67 bool operator!=(
const PointFeature& b)
const {
return !((*this) == b); }
70 Vec2f _coords = {0.0f, 0.0f};
72 float _orientation = 0.0f;
75 typedef std::vector<PointFeature> PointFeatures;
78 inline std::ostream& operator<<(std::ostream& out,
const PointFeature& obj)
80 return out << obj._coords(0) <<
" " << obj._coords(1) <<
" " << obj._scale <<
" " << obj._orientation;
83 inline std::istream& operator>>(std::istream& in, PointFeature& obj)
85 return in >> obj._coords(0) >> obj._coords(1) >> obj._scale >> obj._orientation;
89 template<
typename FeaturesT>
90 inline void loadFeatsFromFile(
const std::string& sfileNameFeats, FeaturesT& vec_feat)
94 std::ifstream fileIn(sfileNameFeats);
96 if (!fileIn.is_open())
97 throw std::runtime_error(
"Can't load features file, can't open '" + sfileNameFeats +
"' !");
99 std::copy(std::istream_iterator<typename FeaturesT::value_type>(fileIn),
100 std::istream_iterator<typename FeaturesT::value_type>(),
101 std::back_inserter(vec_feat));
103 throw std::runtime_error(
"Can't load features file, '" + sfileNameFeats +
"' is incorrect !");
108 template<
typename FeaturesT>
109 inline void saveFeatsToFile(
const std::string& sfileNameFeats, FeaturesT& vec_feat)
111 std::ofstream file(sfileNameFeats);
114 throw std::runtime_error(
"Can't save features file, can't open '" + sfileNameFeats +
"' !");
116 std::copy(vec_feat.begin(), vec_feat.end(), std::ostream_iterator<typename FeaturesT::value_type>(file,
"\n"));
119 throw std::runtime_error(
"Can't save features file, '" + sfileNameFeats +
"' is incorrect !");
125 template<
typename FeaturesT,
typename MatT>
126 void PointsToMat(
const FeaturesT& vec_feats, MatT& m)
128 m.resize(2, vec_feats.size());
129 typedef typename FeaturesT::value_type ValueT;
132 for (
typename FeaturesT::const_iterator iter = vec_feats.begin(); iter != vec_feats.end(); ++iter, ++i)
134 const ValueT& feat = *iter;
135 m.col(i) << feat.x(), feat.y();