| 1 |
#ifndef _POINTCLOUD_H |
| 2 |
#define _POINTCLOUD_H |
| 3 |
#include <cstdio> |
| 4 |
#ifndef _USE_MATH_DEFINES |
| 5 |
#define _USE_MATH_DEFINES |
| 6 |
#endif |
| 7 |
#include <cmath> |
| 8 |
#include <MiscLib/Vector.h> |
| 9 |
#include <limits> |
| 10 |
#include <GfxTL/VectorXD.h> |
| 11 |
#include "basic.h" |
| 12 |
#include <MiscLib/Vector.h> |
| 13 |
#include <MiscLib/AlignedAllocator.h> |
| 14 |
#undef min |
| 15 |
#undef max |
| 16 |
|
| 17 |
#ifndef DLL_LINKAGE |
| 18 |
#define DLL_LINKAGE |
| 19 |
#endif |
| 20 |
|
| 21 |
struct DLL_LINKAGE Point { |
| 22 |
enum { Dim = 3 }; |
| 23 |
typedef float ScalarType; |
| 24 |
typedef float value_type; |
| 25 |
Vec3f pos; |
| 26 |
Vec3f normal; |
| 27 |
#ifdef POINTSWITHINDEX |
| 28 |
unsigned index; |
| 29 |
#endif |
| 30 |
//unsigned int meshFaceIndex; |
| 31 |
Point() {} |
| 32 |
Point(const Vec3f &Pos) {/*index = -1;*/ pos = Pos; normal = Vec3f(0,0,0); } |
| 33 |
Point(const Vec3f &Pos, const Vec3f &Normal) { pos = Pos; normal = Normal; } |
| 34 |
const float operator[](unsigned int i) const |
| 35 |
{ |
| 36 |
return pos[i]; |
| 37 |
} |
| 38 |
float &operator[](unsigned int i) |
| 39 |
{ |
| 40 |
return pos[i]; |
| 41 |
} |
| 42 |
operator const Vec3f &() const |
| 43 |
{ |
| 44 |
return pos; |
| 45 |
} |
| 46 |
operator Vec3f &() |
| 47 |
{ |
| 48 |
return pos; |
| 49 |
} |
| 50 |
operator GfxTL::VectorXD< 3, float > &() |
| 51 |
{ |
| 52 |
return *reinterpret_cast< GfxTL::Vector3Df * >(&pos); |
| 53 |
} |
| 54 |
operator const GfxTL::VectorXD< 3, float > &() const |
| 55 |
{ |
| 56 |
return *reinterpret_cast< const GfxTL::Vector3Df * >(&pos); |
| 57 |
} |
| 58 |
}; |
| 59 |
|
| 60 |
class DLL_LINKAGE PointCloud |
| 61 |
: public MiscLib::Vector< Point > |
| 62 |
{ |
| 63 |
public: |
| 64 |
PointCloud(); |
| 65 |
PointCloud(Point *points, unsigned int size); |
| 66 |
PointCloud &operator+=(const PointCloud &other) |
| 67 |
{ |
| 68 |
size_t oldSize = size(); |
| 69 |
resize(oldSize + other.size()); |
| 70 |
std::copy(other.begin(), other.end(), begin() + oldSize); |
| 71 |
m_min = Vec3f(std::min(m_min[0], other.m_min[0]), |
| 72 |
std::min(m_min[1], other.m_min[1]), |
| 73 |
std::min(m_min[2], other.m_min[2])); |
| 74 |
m_max = Vec3f(std::max(m_max[0], other.m_max[0]), |
| 75 |
std::max(m_max[1], other.m_max[1]), |
| 76 |
std::max(m_max[2], other.m_max[2])); |
| 77 |
return *this; |
| 78 |
} |
| 79 |
void swapPoints (unsigned int i, unsigned int j) |
| 80 |
{ |
| 81 |
std::swap(at(i), at(j)); |
| 82 |
} |
| 83 |
void calcNormals( float radius, unsigned int kNN = 20, unsigned int maxTries = 100 ); |
| 84 |
void reset(size_t s = 0); |
| 85 |
void setBBox (Vec3f bbl, float size) { m_min = bbl; m_max = m_min + Vec3f(size,size,size); } |
| 86 |
void setBBox (Vec3f min, Vec3f max) { m_min = min; m_max = max; } |
| 87 |
void widenBBox (float delta) { Vec3f d(delta,delta,delta); m_min -=d; m_max += d; } |
| 88 |
float getScale() const |
| 89 |
{ |
| 90 |
Vec3f diff = m_max - m_min; |
| 91 |
return std::max(std::max(diff[0], diff[1]), diff[2]); |
| 92 |
} |
| 93 |
const Vec3f &getOffset() const { return m_min; } |
| 94 |
float *getBbox () const; |
| 95 |
// returns a transfromed bbox if m_transformed is true |
| 96 |
void GetCurrentBBox(Vec3f *min, Vec3f *max) const; |
| 97 |
const Vec3f &GetBBoxMin() const { return m_min; } |
| 98 |
const Vec3f &GetBBoxMax() const { return m_max; } |
| 99 |
Vec3f &GetBBoxMin() { return m_min; } |
| 100 |
Vec3f &GetBBoxMax() { return m_max; } |
| 101 |
void Translate(const Vec3f &trans); |
| 102 |
|
| 103 |
private: |
| 104 |
Vec3f m_min, m_max; |
| 105 |
}; |
| 106 |
|
| 107 |
#endif |