-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBoundBox.h
95 lines (76 loc) · 2.16 KB
/
BoundBox.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
//-----------------------------------------------------------
// Copyright (C) 2019 Piotr (Peter) Beben <[email protected]>
// See LICENSE included with this distribution.
#ifndef BOUNDBOX_H
#define BOUNDBOX_H
#include "pt_to_pt_distsq.h"
#include <qopengl.h>
#include <Eigen/Dense>
#include <array>
class MessageLogger;
class Cloud;
class BoundBox
{
using Index = Eigen::Index;
using Vector3f = Eigen::Vector3f;
public:
BoundBox(MessageLogger* msgLogger = nullptr): m_msgLogger(msgLogger){}
BoundBox(
const float minBBox[3], const float maxBBox[3],
MessageLogger* msgLogger = nullptr);
BoundBox(const Cloud& cloud, MessageLogger* msgLogger = nullptr);
void set(const float minBBox[3], const float maxBBox[3]);
void set(const Cloud& cloud);
void pad(float padX, float padY, float padZ);
void rescale(float frac);
void setParentCloud(Cloud *cloud);
int vertCount() const { return m_vertCount; }
void getExtents(float minBBox[], float maxBBox[]) const {
for(int i=0; i < 3; ++i){
minBBox[i] = m_minBBox[i];
maxBBox[i] = m_maxBBox[i];
}
}
float diagonalSize() const {
return sqrt(pt_to_pt_distsq(m_minBBox, m_maxBBox));
}
const GLfloat *vertGLData();
const GLuint *elemGLData() const
{ return static_cast<const GLuint*>(m_elemGL.data()); }
bool pointInBBox(const Vector3f& p) const {
return p(0) >= m_minBBox[0] && p(0) <= m_maxBBox[0] &&
p(1) >= m_minBBox[1] && p(1) <= m_maxBBox[1] &&
p(2) >= m_minBBox[2] && p(2) <= m_maxBBox[2];
}
float ballInBBox(const Vector3f& p, float radius) const {
return p(0) - m_minBBox[0] >= radius &&
p(1) - m_minBBox[1] >= radius &&
p(2) - m_minBBox[2] >= radius &&
m_maxBBox[0] - p(0) >= radius &&
m_maxBBox[1] - p(1) >= radius &&
m_maxBBox[2] - p(2) >= radius;
}
void logMessageBBox() const;
private:
float m_minBBox[3] = {0.0f,0.0f,0.0f};
float m_maxBBox[3] = {0.0f,0.0f,0.0f};
int m_vertCount = 0;
std::array<GLfloat, 8*6> m_vertGL;
Cloud* m_cloud = nullptr;
static constexpr std::array<GLuint, 24> m_elemGL = {
0, 1,
0, 2,
0, 4,
1, 3,
1, 5,
2, 3,
2, 6,
3, 7,
4, 5,
4, 6,
5, 7,
6, 7
};
MessageLogger* m_msgLogger;
};
#endif // BOUNDBOX_H