Plane.h
Go to the documentation of this file.
1#ifndef _PLANE_H_
2#define _PLANE_H_
3#include <stdio.h>
4
5#include <istream>
6#include <ostream>
7
8#include "PointCloud.h"
9#include "basic.h"
10#include <GfxTL/Plane.h>
12#include <MiscLib/Vector.h>
13
14#ifndef DLL_LINKAGE
15#define DLL_LINKAGE
16#endif
17
19{
20public:
21 enum
22 {
24 };
25
27 {
28 }
29
30 Plane(Vec3f p1, Vec3f p2, Vec3f p3);
31 Plane(Vec3f p1, Vec3f normal);
32 virtual ~Plane();
33 bool Init(Vec3f p1, Vec3f p2, Vec3f p3);
34 bool Init(const MiscLib::Vector<Vec3f>& samples);
35 bool InitAverage(const MiscLib::Vector<Vec3f>& samples);
36 bool Init(bool binary, std::istream* i);
37 void Init(FILE* i);
38 void Init(float* array);
39
40 float
41 getDistance(const Vec3f& pos) const
42 {
43 return abs(m_dist - m_normal.dot(pos));
44 }
45
46 float
47 Distance(const Vec3f& pos) const
48 {
49 return abs(m_dist - m_normal.dot(pos));
50 }
51
52 float
53 SignedDistance(const Vec3f& pos) const
54 {
55 return m_normal.dot(pos) - m_dist;
56 }
57
58 void
59 Normal(const Vec3f&, Vec3f* n) const
60 {
61 *n = m_normal;
62 }
63
64 float
65 DistanceAndNormal(const Vec3f& pos, Vec3f* n) const
66 {
67 *n = m_normal;
68 return Distance(pos);
69 }
70
71 const Vec3f&
72 getNormal() const
73 {
74 return m_normal;
75 }
76
77 const Vec3f&
79 {
80 return m_pos;
81 }
82
83 bool equals(Plane plane);
84
85 float
87 {
88 return m_dist;
89 }
90
91 bool
98
99 bool LeastSquaresFit(const PointCloud& pc,
102 template <class IteratorT>
103 bool LeastSquaresFit(IteratorT begin, IteratorT end);
104 static bool Interpolate(const MiscLib::Vector<Plane>& planes,
105 const MiscLib::Vector<float>& weights,
106 Plane* ip);
107 void Serialize(bool binary, std::ostream* o) const;
108 static size_t SerializedSize();
109 void Serialize(FILE* o) const;
110 void Serialize(float* array) const;
111 static size_t SerializedFloatSize();
112
113 void Transform(float scale, const Vec3f& translate);
114 float Intersect(const Vec3f& p, const Vec3f& r) const;
115
116protected:
119 float m_dist;
120};
121
122template <class IteratorT>
123bool
124Plane::LeastSquaresFit(IteratorT begin, IteratorT end)
125{
127 GfxTL::Vector3Df mean;
128 GfxTL::Mean(begin, end, &mean);
129 pl.Fit(mean, begin, end);
130 *this = Plane(Vec3f(mean.Data()), Vec3f(pl.Normal().Data()));
131 return true;
132}
133
134#endif //_PLANE_H_
#define DLL_LINKAGE
Definition basic.h:12
bool Fit(const PointType &origin, PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights)
Definition Plane.h:71
void Normal(PointType *normal) const
Definition Plane.hpp:48
Definition Plane.h:19
Vec3f m_normal
Definition Plane.h:117
float getDistance(const Vec3f &pos) const
Definition Plane.h:41
Vec3f m_pos
Definition Plane.h:118
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition Plane.cpp:200
float DistanceAndNormal(const Vec3f &pos, Vec3f *n) const
Definition Plane.h:65
const Vec3f & getPosition() const
Definition Plane.h:78
const Vec3f & getNormal() const
Definition Plane.h:72
float Distance(const Vec3f &pos) const
Definition Plane.h:47
void Normal(const Vec3f &, Vec3f *n) const
Definition Plane.h:59
bool Fit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Definition Plane.h:92
@ RequiredSamples
Definition Plane.h:23
Plane()
Definition Plane.h:26
float m_dist
Definition Plane.h:119
float SignedDistance(const Vec3f &pos) const
Definition Plane.h:53
float SignedDistToOrigin() const
Definition Plane.h:86
Definition basic.h:18
void Mean(PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights, PointT *mean)
Definition Mean.h:14
VectorXD< 3, float > Vector3Df
Definition VectorXD.h:718