32 #include "../point.hpp"
38 A3Histogram(
const std::vector<Eigen::Vector3f>& points,
int bins = 10)
39 : MAX_SAMPLES(100000), MAX_TRIOS(100000)
42 m_a3Histogram = makeHistogram(bins, calculateAngles(points));
45 A3Histogram(
const std::pair<std::string, std::vector<Eigen::Vector3f>>& points,
int bins = 10)
46 : MAX_SAMPLES(100000), MAX_TRIOS(100000)
49 m_a3Histogram = makeHistogram(bins, calculateAngles(points.second));
73 return compareHistograms(m_a3Histogram, casted->
a3Histogram());
81 virtual void serialize(
const ObjectSerializerBasePtr& serializer,
const Ice::Current&)
const
91 featureObj->setDoubleArray(
m_name, m_a3Histogram);
95 featureObj = obj->createElement();
96 featureObj->setDoubleArray(
m_name, m_a3Histogram);
101 virtual void deserialize(
const ObjectSerializerBasePtr& serializer,
const Ice::Current&)
106 featureObj->getDoubleArray(
m_name, m_a3Histogram);
109 virtual std::ostream&
output(std::ostream& out)
const
113 if (!m_a3Histogram.empty())
115 out << m_a3Histogram[0];
117 for (
unsigned int i = 1; i < m_a3Histogram.size(); i++)
119 out <<
", " << m_a3Histogram[i];
128 const int MAX_SAMPLES;
131 std::vector<double> normalize(
const std::vector<double>& x)
const
133 std::vector<double> n(x.size());
134 double max = *std::max_element(x.begin(), x.end());
136 for (
unsigned int i = 0; i < n.size(); i++)
144 double compareHistograms(
const std::vector<double>&
a,
const std::vector<double>& b)
const
147 std::vector<double> an = normalize(
a);
148 std::vector<double> bn = normalize(b);
150 for (
unsigned int i = 0; i < an.size(); i++)
152 diff += std::pow(an[i] - bn[i], 2);
158 std::vector<double> calculateAngles(
const std::vector<Eigen::Vector3f>& points)
const
160 int numPoints = points.size();
161 std::vector<int>
indices = std::vector<int>(
std::min(numPoints, MAX_SAMPLES));
163 if (numPoints < MAX_SAMPLES)
166 for (
unsigned int i = 0; i <
indices.size(); i++)
174 for (
unsigned int i = 0; i <
indices.size(); i++)
176 indices[i] = rand() % numPoints;
180 std::vector<double> angles(MAX_TRIOS);
184 int numIndices =
indices.size();
187 for (
int i = 0; i < MAX_TRIOS; i++)
189 first = rand() % numIndices;
194 second = rand() % numIndices;
196 while (first == second);
200 third = rand() % numIndices;
202 while (first == third || second == third);
211 std::vector<double> makeHistogram(
const int bins,
const std::vector<double>&
values)
const
213 std::vector<double> histogram(bins);
214 double width = *std::max_element(
values.begin(),
values.end()) / (double) bins;
216 for (
unsigned int i = 0; i <
values.size(); i++)
223 std::vector<double> m_a3Histogram;