PrimitiveShape.h
Go to the documentation of this file.
1#ifndef PRIMITIVESHAPE_HEADER
2#define PRIMITIVESHAPE_HEADER
3#include <stdio.h>
4
5#include <deque>
6#include <iostream>
7#include <string>
8#include <utility>
9
10#include "LevMarFunc.h"
11#include "PointCloud.h"
12#include "basic.h"
13#include <GfxTL/VectorXD.h>
15#include <MiscLib/RefCount.h>
16#include <MiscLib/RefCountPtr.h>
17#include <MiscLib/Vector.h>
18
19#ifndef DLL_LINKAGE
20#define DLL_LINKAGE
21#endif
22
24
25/** PrimtiveShape is a shape primitive in conjunction with a parametrization.
26 The parametrization is used for connected component computations.
27 There are some deprecated serialization functions that do
28 not always store the parametrization (at least for some shape types). These
29 functions should no longer be used anywhere!
30 Note: Computing connected components may change the parametrization! (Some
31 shapes align the parametrization so that the memory for the bitmap is
32 reduced)
33*/
35{
36public:
37 // returns a unique identifier of the shape type
38 virtual size_t Identifier() const = 0;
39 // returns the number of point samples required to uniquely determine a shape
40 virtual unsigned int RequiredSamples() const = 0;
41 virtual PrimitiveShape* Clone() const = 0;
42 virtual float Distance(const Vec3f& p) const = 0;
43 virtual float SignedDistance(const Vec3f& p) const = 0;
44 virtual float NormalDeviation(const Vec3f& p, const Vec3f& n) const = 0;
45 // computes the distance to the shape and the deviation of the normal
46 // to the normal at the nearest point on the shape
47 virtual void DistanceAndNormalDeviation(const Vec3f& p,
48 const Vec3f& n,
49 std::pair<float, float>* dn) const = 0;
50 // projects a point p onto the nearest point on the shape
51 virtual void Project(const Vec3f& p, Vec3f* pp) const = 0;
52 // gets the normal of the shape at the projection of p
53 virtual void Normal(const Vec3f& p, Vec3f* n) const = 0;
54 // finds the largest connected component in the points indexed by indices
55 // Upon return the indices of the points that belong to the largest component
56 // have been moved to the front of indices and their number is returned.
57 // The remaining indices are stored at the end of the indices array
58 virtual size_t ConnectedComponent(const PointCloud& pc,
59 float epsilon,
61 bool doFiltering = true,
62 float* borderRatio = 0) = 0;
63 virtual unsigned int ConfidenceTests(unsigned int numTests,
64 float epsilon,
65 float normalThresh,
66 float rms,
67 const PointCloud& pc,
68 const MiscLib::Vector<size_t>& indices) const = 0;
69 // returns descriptive string
70 virtual void Description(std::string* s) const = 0;
71 // refitting
72 virtual bool Fit(const PointCloud& pc,
73 float epsilon,
74 float normalThresh,
77 virtual PrimitiveShape* LSFit(const PointCloud& pc,
78 float epsilon,
79 float normalThresh,
82 std::pair<size_t, float>* score) const = 0;
86 virtual void TrimmingPolygons(const PointCloud& pc,
87 float epsilon,
88 size_t begin,
89 size_t end,
90 std::deque<ComponentPolygons>* polys) const = 0;
91 // generates points on the shape from the primitive's bitmap i.e. where the bitmap is set
92 virtual void GenerateBitmapPoints(const PointCloud& pc,
93 float epsilon,
94 size_t begin,
95 size_t end,
96 PointCloud* bmpPc) const = 0;
97 /** This is the one and only serialization function
98 It stores all the parameters of the shape as well as the parametrization.
99 The first byte written (in both, binary and ascii mode) is the shape identifier */
100 virtual void Serialize(std::ostream* o, bool binary = true) const = 0;
101 virtual size_t SerializedSize() const = 0;
102 // Serialize parameters to float array
103 virtual void Serialize(float* array) const = 0;
104 virtual size_t SerializedFloatSize() const = 0;
105 virtual void Transform(float scale, const Vec3f& translate) = 0;
106 virtual void Visit(PrimitiveShapeVisitor* visitor) const = 0;
107
108 virtual void
116
117 virtual void
118 OptimizeParametrization(const PointCloud& pc, size_t begin, size_t end, float epsilon)
119 {
120 }
121
122 // gets the 2D parametrization coordinates of a point p in 3-space (it is projected first)
123 virtual void Parameters(const Vec3f& p, std::pair<float, float>* param) const = 0;
124 // computes the point and normal in 3-space from coordinates in the parametrization
125 virtual bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const = 0;
126};
127
128#endif
class DLL_LINKAGE PrimitiveShapeVisitor
#define DLL_LINKAGE
Definition basic.h:12
PrimtiveShape is a shape primitive in conjunction with a parametrization.
virtual size_t SerializedFloatSize() const =0
virtual void GenerateBitmapPoints(const PointCloud &pc, float epsilon, size_t begin, size_t end, PointCloud *bmpPc) const =0
virtual size_t SerializedSize() const =0
virtual void Project(const Vec3f &p, Vec3f *pp) const =0
virtual float NormalDeviation(const Vec3f &p, const Vec3f &n) const =0
virtual void Parameters(const Vec3f &p, std::pair< float, float > *param) const =0
virtual unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const =0
virtual void TrimmingPolygons(const PointCloud &pc, float epsilon, size_t begin, size_t end, std::deque< ComponentPolygons > *polys) const =0
virtual PrimitiveShape * LSFit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, std::pair< size_t, float > *score) const =0
virtual void Visit(PrimitiveShapeVisitor *visitor) const =0
virtual void Transform(float scale, const Vec3f &translate)=0
virtual float SignedDistance(const Vec3f &p) const =0
virtual bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const =0
virtual size_t Identifier() const =0
virtual void Serialize(float *array) const =0
virtual void OptimizeParametrization(const PointCloud &pc, size_t begin, size_t end, float epsilon)
virtual LevMarFunc< float > * SignedDistanceFunc() const =0
virtual void Normal(const Vec3f &p, Vec3f *n) const =0
MiscLib::Vector< BitmapPolygon > ComponentPolygons
virtual void SuggestSimplifications(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, float distThresh, MiscLib::Vector< MiscLib::RefCountPtr< PrimitiveShape > > *suggestions) const
virtual void Description(std::string *s) const =0
virtual void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const =0
virtual float Distance(const Vec3f &p) const =0
virtual void Serialize(std::ostream *o, bool binary=true) const =0
This is the one and only serialization function It stores all the parameters of the shape as well as ...
virtual bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)=0
virtual PrimitiveShape * Clone() const =0
virtual unsigned int RequiredSamples() const =0
MiscLib::Vector< GfxTL::VectorXD< 2, size_t > > BitmapPolygon
virtual size_t ConnectedComponent(const PointCloud &pc, float epsilon, MiscLib::Vector< size_t > *indices, bool doFiltering=true, float *borderRatio=0)=0
Definition basic.h:18