| 1 |
#ifndef PRIMITIVESHAPE_HEADER |
| 2 |
#define PRIMITIVESHAPE_HEADER |
| 3 |
#include "basic.h" |
| 4 |
#include <MiscLib/RefCount.h> |
| 5 |
#include "PointCloud.h" |
| 6 |
#include <GfxTL/VectorXD.h> |
| 7 |
#include <utility> |
| 8 |
#include <string> |
| 9 |
#include <MiscLib/Vector.h> |
| 10 |
#include <deque> |
| 11 |
#include <iostream> |
| 12 |
#include "LevMarFunc.h" |
| 13 |
#include <stdio.h> |
| 14 |
#include <MiscLib/NoShrinkVector.h> |
| 15 |
#include <MiscLib/RefCountPtr.h> |
| 16 |
|
| 17 |
#ifndef DLL_LINKAGE |
| 18 |
#define DLL_LINKAGE |
| 19 |
#endif |
| 20 |
|
| 21 |
class DLL_LINKAGE PrimitiveShapeVisitor; |
| 22 |
|
| 23 |
/** PrimtiveShape is a shape primitive in conjunction with a parametrization. |
| 24 |
The parametrization is used for connected component computations. |
| 25 |
There are some deprecated serialization functions that do |
| 26 |
not always store the parametrization (at least for some shape types). These |
| 27 |
functions should no longer be used anywhere! |
| 28 |
Note: Computing connected components may change the parametrization! (Some |
| 29 |
shapes align the parametrization so that the memory for the bitmap is |
| 30 |
reduced) |
| 31 |
*/ |
| 32 |
class DLL_LINKAGE PrimitiveShape |
| 33 |
: public MiscLib::RefCount |
| 34 |
{ |
| 35 |
public: |
| 36 |
// returns a unique identifier of the shape type |
| 37 |
virtual size_t Identifier() const = 0; |
| 38 |
// returns the number of point samples required to uniquely determine a shape |
| 39 |
virtual unsigned int RequiredSamples() const = 0; |
| 40 |
virtual PrimitiveShape *Clone() const = 0; |
| 41 |
virtual float Distance(const Vec3f &p) const = 0; |
| 42 |
virtual float SignedDistance(const Vec3f &p) const = 0; |
| 43 |
virtual float NormalDeviation(const Vec3f &p, |
| 44 |
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( |
| 48 |
const Vec3f &p, 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, float epsilon, |
| 59 |
MiscLib::Vector< size_t > *indices, bool doFiltering = true, float* borderRatio = 0 ) = 0; |
| 60 |
virtual unsigned int ConfidenceTests(unsigned int numTests, |
| 61 |
float epsilon, float normalThresh, float rms, const PointCloud &pc, |
| 62 |
const MiscLib::Vector< size_t > &indices) const = 0; |
| 63 |
// returns descriptive string |
| 64 |
virtual void Description(std::string *s) const = 0; |
| 65 |
// refitting |
| 66 |
virtual bool Fit(const PointCloud &pc, float epsilon, |
| 67 |
float normalThresh, |
| 68 |
MiscLib::Vector< size_t >::const_iterator begin, |
| 69 |
MiscLib::Vector< size_t >::const_iterator end) = 0; |
| 70 |
virtual PrimitiveShape *LSFit(const PointCloud &pc, float epsilon, |
| 71 |
float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, |
| 72 |
MiscLib::Vector< size_t >::const_iterator end, |
| 73 |
std::pair< size_t, float > *score) const = 0; |
| 74 |
virtual LevMarFunc< float > *SignedDistanceFunc() const = 0; |
| 75 |
typedef MiscLib::Vector< GfxTL::VectorXD< 2, size_t > > BitmapPolygon; |
| 76 |
typedef MiscLib::Vector< BitmapPolygon > ComponentPolygons; |
| 77 |
virtual void TrimmingPolygons(const PointCloud &pc, float epsilon, |
| 78 |
size_t begin, size_t end, |
| 79 |
std::deque< ComponentPolygons > *polys) const = 0; |
| 80 |
// generates points on the shape from the primitive's bitmap i.e. where the bitmap is set |
| 81 |
virtual void GenerateBitmapPoints(const PointCloud &pc, float epsilon, |
| 82 |
size_t begin, size_t end, PointCloud *bmpPc) const = 0; |
| 83 |
/** This is the one and only serialization function |
| 84 |
It stores all the parameters of the shape as well as the parametrization. |
| 85 |
The first byte written (in both, binary and ascii mode) is the shape identifier */ |
| 86 |
virtual void Serialize(std::ostream *o, bool binary = true) const = 0; |
| 87 |
virtual size_t SerializedSize() const = 0; |
| 88 |
// Serialize parameters to float array |
| 89 |
virtual void Serialize(float* array) const = 0; |
| 90 |
virtual size_t SerializedFloatSize() const = 0; |
| 91 |
virtual void Transform(float scale, const Vec3f &translate) = 0; |
| 92 |
virtual void Visit(PrimitiveShapeVisitor *visitor) const = 0; |
| 93 |
virtual void SuggestSimplifications(const PointCloud &pc, |
| 94 |
MiscLib::Vector< size_t >::const_iterator begin, |
| 95 |
MiscLib::Vector< size_t >::const_iterator end, float distThresh, |
| 96 |
MiscLib::Vector< MiscLib::RefCountPtr< PrimitiveShape > > *suggestions) const {} |
| 97 |
virtual void OptimizeParametrization(const PointCloud &pc, |
| 98 |
size_t begin, size_t end, float epsilon) {} |
| 99 |
// gets the 2D parametrization coordinates of a point p in 3-space (it is projected first) |
| 100 |
virtual void Parameters(const Vec3f &p, |
| 101 |
std::pair< float, float > *param) const = 0; |
| 102 |
// computes the point and normal in 3-space from coordinates in the parametrization |
| 103 |
virtual bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const = 0; |
| 104 |
virtual bool CheckGeneratedShapeWithinLimits(const PointCloud& pc, |
| 105 |
MiscLib::Vector< size_t >::const_iterator begin, |
| 106 |
MiscLib::Vector< size_t >::const_iterator end) { return true; } |
| 107 |
}; |
| 108 |
|
| 109 |
#endif |