-
Notifications
You must be signed in to change notification settings - Fork 1
/
objectmodel.h
75 lines (56 loc) · 2.46 KB
/
objectmodel.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
#ifndef OBJECTMODEL_H
#define OBJECTMODEL_H
#include <vector>
#include <set>
#include <memory>
#include <utility>
#include <tuple>
#include <Eigen/Eigen>
#include <opencv2/core.hpp>
class PinholeCamera;
using VectorsXi = std::vector<Eigen::VectorXi, Eigen::aligned_allocator<Eigen::VectorXi>>;
using Vectors2f = std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f>>;
using Vectors3f = std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>>;
using Vectors2d = std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d>>;
using Vectors3d = std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>;
class ObjectModel
{
public:
struct less_pair_i
{
bool operator () (const std::pair<int, int> & lhs, const std::pair<int, int> & rhs) const
{
return (lhs.first < rhs.first) ? true : ((lhs.first == rhs.first) && (lhs.second < rhs.second));
}
};
using FlagsVector = Eigen::Matrix<uchar, Eigen::Dynamic, 1>;
struct Polygon
{
Eigen::VectorXi vertexIndices;
Eigen::Vector3f normal;
};
using Polygons = std::vector<Polygon, Eigen::aligned_allocator<Polygon>>;
static ObjectModel createBox(const Eigen::Vector3f & size = Eigen::Vector3f(1.0f, 1.0f, 1.0f));
static ObjectModel createCubikRubik(float border = 0.15f);
static ObjectModel createHouse();
static ObjectModel mirroredX(const ObjectModel & model);
ObjectModel & merge(const ObjectModel & model);
const Vectors3f & vertices() const;
const Polygons & polygons() const;
Vectors3f getControlPoints(const std::shared_ptr<PinholeCamera> & camera,
float controlPixelDistance,
const Eigen::Matrix3f & R,
const Eigen::Vector3f & t) const;
std::tuple<Vectors3f, Vectors2f> getControlAndImagePoints(const std::shared_ptr<PinholeCamera> & camera,
float controlPixelDistance,
const Eigen::Matrix3f & R, const Eigen::Vector3f & t) const;
void draw(const cv::Mat & image,
const std::shared_ptr<PinholeCamera> & camera,
const Eigen::Matrix3f & R, const Eigen::Vector3f & t) const;
private:
ObjectModel();
Vectors3f m_vertices;
Polygons m_polygons;
std::set<std::pair<int, int>> m_disabledEdges;
};
#endif // OBJECTMODEL_H