-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdomset.h
141 lines (112 loc) · 4.26 KB
/
domset.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// This file is part of OpenMVG (Open Multiple View Geometry) C++ library.
// Copyright (c) 2016 nomoko AG, Srivathsan Murali<srivathsan@nomoko.camera>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _DOMSET_H_
#define _DOMSET_H_
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <limits>
#include <cmath>
#include <algorithm>
#include <Eigen/Core>
#include "types.h"
// 3D Party
#include "nanoflann.hpp"
using namespace nanoflann;
namespace nomoko {
class Domset{
private:
/* Generic clustering */
void findCommonPoints(const View& v1, const View& v2,
std::vector<size_t>& commonPts);
// similarity measures
const float computeViewSimilaity(const View&, const View&);
Eigen::MatrixXf getSimilarityMatrix(std::map<size_t,size_t>&);
// distance measures
void getAllDistances();
float getDistanceMedian(const std::map<size_t,size_t> &);
float computeViewDistance(const size_t& vId1, const size_t & vId2,
const float& medianDist);
void computeInformation();
// subsamples the initial point cloud
void voxelGridFilter(const float& leafSizeX,
const float& leafSizeY, const float& leafSizeZ);
// normalizing point distances
void normalizePointCloud();
void deNormalizePointCloud();
public:
/* cant read from file need to suply data */
Domset(const std::vector<Point>& _points,
const std::vector<View>& _views,
const std::vector<Camera>& _cameras,
const float& _kVoxelsize):
points(_points), views(_views),
cameras(_cameras), kVoxelSize(_kVoxelsize) {
std::cout << " [ Dominant set clustering of views ] " << std::endl;
computeInformation();
}
// AP clustering
void computeClustersAP(std::map<size_t,size_t>&, std::vector<std::vector<size_t> >&);
void clusterViews(std::map<size_t, size_t>& xId2vId, const size_t& minClustersize,
const size_t& maxClusterSize);
void clusterViews(const size_t& minClustersize,
const size_t& maxClusterSize);
/* export function */
void exportToPLY(const std::string& plyFile, bool exportPoints = false);
const std::vector<std::vector<size_t> >& getClusters() {
return finalClusters;
}
void setClusters(std::vector<std::vector<size_t> > clusters) {
finalClusters.clear();
finalClusters.swap(clusters);
}
void printClusters();
private:
std::vector<Point> points;
std::vector<Point> origPoints;
std::vector<Camera> cameras;
std::vector<View> views;
Eigen::MatrixXf viewDists;
std::vector<std::vector<size_t > > finalClusters;
const float kAngleSigma = 3.14159265358979323846 / 6;
const float kAngleSigma_2 = kAngleSigma * kAngleSigma;
size_t kMinClusterSize = 10;
size_t kMaxClusterSize = 20;
float kE = 0.01f;
// AP constants
const unsigned int kNumIter = 100;
const float lambda = 0.5;
// scale normalization
float normScale;
Point normMin;
Point normMax;
Point pcCentre;
// voxel grid stuff
const float kVoxelSize = 0.1f;
public:
/* nanoflann function */
// returns number of data points
inline size_t kdtree_get_point_count() const { return points.size(); }
inline float kdtree_distance
(const float* p1, const size_t idx_p2, size_t /**size**/) const {
const float d0 = p1[0]-points[idx_p2].pos(0);
const float d1 = p1[1]-points[idx_p2].pos(1);
const float d2 = p1[2]-points[idx_p2].pos(2);
return d0*d0 + d1*d1 + d2*d2;
}
inline float kdtree_get_pt(const size_t idx, int dim) const {
if (dim == 0) return points[idx].pos(0);
else if (dim == 1) return points[idx].pos(1);
else return points[idx].pos(2);
}
template <class BBOX>
bool kdtree_get_bbox(BBOX& /*bb*/) const { return false; }
}; // class Domset
} // namespace nomoko
#endif // _DOMSET_H_