-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathPointCloud.h
107 lines (102 loc) · 2.83 KB
/
PointCloud.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
#ifndef _POINTCLOUD_H
#define _POINTCLOUD_H
#include <cstdio>
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#include <MiscLib/Vector.h>
#include <limits>
#include <GfxTL/VectorXD.h>
#include "basic.h"
#include <MiscLib/Vector.h>
#include <MiscLib/AlignedAllocator.h>
#undef min
#undef max
#ifndef DLL_LINKAGE
#define DLL_LINKAGE
#endif
struct DLL_LINKAGE Point {
enum { Dim = 3 };
typedef float ScalarType;
typedef float value_type;
Vec3f pos;
Vec3f normal;
#ifdef POINTSWITHINDEX
size_t index;
#endif
//unsigned int meshFaceIndex;
Point() {}
Point(const Vec3f &Pos) {/*index = -1;*/ pos = Pos; normal = Vec3f(0,0,0); }
Point(const Vec3f &Pos, const Vec3f &Normal) { pos = Pos; normal = Normal; }
const float operator[](unsigned int i) const
{
return pos[i];
}
float &operator[](unsigned int i)
{
return pos[i];
}
operator const Vec3f &() const
{
return pos;
}
operator Vec3f &()
{
return pos;
}
operator GfxTL::VectorXD< 3, float > &()
{
return *reinterpret_cast< GfxTL::Vector3Df * >(&pos);
}
operator const GfxTL::VectorXD< 3, float > &() const
{
return *reinterpret_cast< const GfxTL::Vector3Df * >(&pos);
}
};
class DLL_LINKAGE PointCloud
: public MiscLib::Vector< Point >
{
public:
PointCloud();
PointCloud(Point *points, unsigned int size);
PointCloud &operator+=(const PointCloud &other)
{
size_t oldSize = size();
resize(oldSize + other.size());
std::copy(other.begin(), other.end(), begin() + oldSize);
m_min = Vec3f(std::min(m_min[0], other.m_min[0]),
std::min(m_min[1], other.m_min[1]),
std::min(m_min[2], other.m_min[2]));
m_max = Vec3f(std::max(m_max[0], other.m_max[0]),
std::max(m_max[1], other.m_max[1]),
std::max(m_max[2], other.m_max[2]));
return *this;
}
void swapPoints (unsigned int i, unsigned int j)
{
std::swap(at(i), at(j));
}
void calcNormals( float radius, unsigned int kNN = 20, unsigned int maxTries = 100 );
void reset(size_t s = 0);
void setBBox (Vec3f bbl, float size) { m_min = bbl; m_max = m_min + Vec3f(size,size,size); }
void setBBox (Vec3f min, Vec3f max) { m_min = min; m_max = max; }
void widenBBox (float delta) { Vec3f d(delta,delta,delta); m_min -=d; m_max += d; }
float getScale() const
{
Vec3f diff = m_max - m_min;
return std::max(std::max(diff[0], diff[1]), diff[2]);
}
const Vec3f &getOffset() const { return m_min; }
float *getBbox () const;
// returns a transfromed bbox if m_transformed is true
void GetCurrentBBox(Vec3f *min, Vec3f *max) const;
const Vec3f &GetBBoxMin() const { return m_min; }
const Vec3f &GetBBoxMax() const { return m_max; }
Vec3f &GetBBoxMin() { return m_min; }
Vec3f &GetBBoxMax() { return m_max; }
void Translate(const Vec3f &trans);
private:
Vec3f m_min, m_max;
};
#endif