42 D2Histogram(
const std::vector<Eigen::Vector3f>& points,
int bins = 10) :
43 MAX_SAMPLES(100000), MAX_PAIRS(100000)
46 m_d2Histogram = makeHistogram(bins, calculateDistances(points));
49 D2Histogram(
const std::pair<std::string, std::vector<Eigen::Vector3f>>& points,
int bins = 10) :
50 MAX_SAMPLES(100000), MAX_PAIRS(100000)
53 m_d2Histogram = makeHistogram(bins, calculateDistances(points.second));
81 return compareHistograms(m_d2Histogram, casted->
d2Histogram());
85 return std::numeric_limits<double>::max();
90 serialize(
const ObjectSerializerBasePtr& serializer,
const Ice::Current&)
const
100 featureObj->setDoubleArray(
m_name, m_d2Histogram);
104 featureObj = obj->createElement();
105 featureObj->setDoubleArray(
m_name, m_d2Histogram);
111 deserialize(
const ObjectSerializerBasePtr& serializer,
const Ice::Current&)
116 featureObj->getDoubleArray(
m_name, m_d2Histogram);
119 virtual std::ostream&
124 if (!m_d2Histogram.empty())
126 out << m_d2Histogram[0];
128 for (
unsigned int i = 1; i < m_d2Histogram.size(); i++)
130 out <<
", " << m_d2Histogram[i];
139 const int MAX_SAMPLES;
143 normalize(
const std::vector<double>&
x)
const
145 std::vector<double> n(
x.size());
146 double max = *std::max_element(
x.begin(),
x.end());
148 for (
unsigned int i = 0; i < n.size(); i++)
157 compareHistograms(
const std::vector<double>& a,
const std::vector<double>& b)
const
160 std::vector<double> an = normalize(a);
161 std::vector<double> bn = normalize(b);
163 for (
unsigned int i = 0; i < an.size(); i++)
165 diff += std::pow(an[i] - bn[i], 2);
172 calculateDistances(
const std::vector<Eigen::Vector3f>& points)
const
174 int numPoints = points.size();
175 std::vector<int>
indices = std::vector<int>(std::min(numPoints, MAX_SAMPLES));
177 if (numPoints < MAX_SAMPLES)
180 for (
unsigned int i = 0; i <
indices.size(); i++)
188 for (
unsigned int i = 0; i <
indices.size(); i++)
190 indices[i] = rand() % numPoints;
194 std::vector<double> distances = std::vector<double>(MAX_PAIRS);
197 int numIndices =
indices.size();
200 for (
int i = 0; i < MAX_PAIRS; i++)
202 first = rand() % numIndices;
207 second = rand() % numIndices;
208 }
while (first == second);
211 distances[i] =
distance(points[indices[first]], points[indices[second]]);
218 makeHistogram(
const int bins,
const std::vector<double>& values)
const
220 std::vector<double> histogram(bins);
221 double width = *std::max_element(
values.begin(),
values.end()) / (double)bins;
223 for (
unsigned int i = 0; i <
values.size(); i++)
225 histogram[std::min((
int)(
values.at(i) / width), bins - 1)]++;
231 std::vector<double> m_d2Histogram;
const std::string FEATURE_FIELD_NAME
std::shared_ptr< Feature > FeaturePtr
double compare(const Feature &other) const
std::vector< double > d2Histogram() const
FeaturePtr calculate(const TaggedPoints &points)
FeaturePtr calculate(const Points &points)
D2Histogram(const std::pair< std::string, std::vector< Eigen::Vector3f > > &points, int bins=10)
D2Histogram(const std::vector< Eigen::Vector3f > &points, int bins=10)
virtual void serialize(const ObjectSerializerBasePtr &serializer, const Ice::Current &) const
virtual void deserialize(const ObjectSerializerBasePtr &serializer, const Ice::Current &)
virtual std::ostream & output(std::ostream &out) const
std::vector< Eigen::Vector3f > Points
std::shared_ptr< Feature > FeaturePtr
std::pair< std::string, Points > TaggedPoints
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< AbstractObjectSerializer > AbstractObjectSerializerPtr
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
constexpr auto n() noexcept
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
double distance(const Point &a, const Point &b)