$darkmode
VCG Library
Classes | Public Types | Static Public Member Functions | List of all members
vcg::tri::SurfaceSampling< MeshType, VertexSampler > Class Template Reference

Main Class of the Sampling framework. More...

#include <point_sampling.h>

Classes

class  MarsenneTwisterURBG
 
struct  PoissonDiskParam
 
class  RRParam
 

Public Types

enum  EdgeSamplingStrategy { Floor = 0 , Round , Ceil }
 The EdgeSamplingStrategy enum determines the sampling strategy for edge meshes. Given a sampling radius 'r', and the total length of the edge mesh 'L', the number of generated samples is: op(L/r) (+ 1 if the mesh is not a loop) where op is (floor | round | ceil)
 
typedef GridStaticPtr< FaceType, ScalarType > TriMeshGrid
 

Static Public Member Functions

static math::MarsenneTwisterRNG & SamplingRandomGenerator ()
 
static unsigned int RandomInt (unsigned int i)
 
static double RandomDouble01 ()
 
static double LnFac (int n)
 
static int PoissonRatioUniforms (double L)
 
static int Poisson (double lambda)
 
static void AllVertex (MeshType &m, VertexSampler &ps)
 
static void AllVertex (MeshType &m, VertexSampler &ps, bool onlySelected)
 
static void VertexWeighted (MeshType &m, VertexSampler &ps, int sampleNum)
 
static void VertexAreaUniform (MeshType &m, VertexSampler &ps, int sampleNum)
 
static void FillAndShuffleFacePointerVector (MeshType &m, std::vector< FacePointer > &faceVec)
 
static void FillAndShuffleVertexPointerVector (MeshType &m, std::vector< VertexPointer > &vertVec)
 
static void VertexUniform (MeshType &m, VertexSampler &ps, int sampleNum, bool onlySelected)
 Sample the vertices in a uniform way. Each vertex has the same probabiltiy of being chosen.
 
static void VertexUniform (MeshType &m, VertexSampler &ps, int sampleNum)
 
static void EdgeMeshUniform (MeshType &m, VertexSampler &ps, float radius, EdgeSamplingStrategy strategy=Floor)
 
static void VertexBorderCorner (MeshType &m, VertexSampler &ps, ScalarType angleRad)
 Sample all the border corner vertices. More...
 
static void VertexBorder (MeshType &m, VertexSampler &ps)
 Sample all the border vertices. More...
 
static void VertexCrease (MeshType &m, VertexSampler &ps)
 
static void FaceUniform (MeshType &m, VertexSampler &ps, int sampleNum)
 
static void AllFace (MeshType &m, VertexSampler &ps)
 
static void AllEdge (MeshType &m, VertexSampler &ps)
 
static void EdgeUniform (MeshType &m, VertexSampler &ps, int sampleNum, bool sampleFauxEdge=true)
 
static CoordType RandomBarycentric ()
 
static CoordType RandomPointInTriangle (const FaceType &f)
 
static void StratifiedMontecarlo (MeshType &m, VertexSampler &ps, int sampleNum)
 
static void MontecarloPoisson (MeshType &m, VertexSampler &ps, int sampleNum)
 
static void EdgeMontecarlo (MeshType &m, VertexSampler &ps, int sampleNum, bool sampleAllEdges)
 
static void Montecarlo (MeshType &m, VertexSampler &ps, int sampleNum)
 
static ScalarType WeightedArea (FaceType &f, PerVertexFloatAttribute &wH)
 
static void WeightedMontecarlo (MeshType &m, VertexSampler &ps, int sampleNum, float variance)
 
static int SingleFaceSubdivision (int sampleNum, const CoordType &v0, const CoordType &v1, const CoordType &v2, VertexSampler &ps, FacePointer fp, bool randSample)
 
static void FaceSubdivision (MeshType &m, VertexSampler &ps, int sampleNum, bool randSample)
 Compute a sampling of the surface where the points are regularly scattered over the face surface using a recursive longest-edge subdivision rule.
 
static int SingleFaceSubdivisionOld (int sampleNum, const CoordType &v0, const CoordType &v1, const CoordType &v2, VertexSampler &ps, FacePointer fp, bool randSample)
 
static void FaceSubdivisionOld (MeshType &m, VertexSampler &ps, int sampleNum, bool randSample)
 Compute a sampling of the surface where the points are regularly scattered over the face surface using a recursive longest-edge subdivision rule.
 
static int SingleFaceSimilar (FacePointer fp, VertexSampler &ps, int n_samples_per_edge)
 
static int SingleFaceSimilarDual (FacePointer fp, VertexSampler &ps, int n_samples_per_edge, bool randomFlag)
 
static void FaceSimilar (MeshType &m, VertexSampler &ps, int sampleNum, bool dualFlag, bool randomFlag)
 
static void SingleFaceRaster (typename MeshType::FaceType &f, VertexSampler &ps, const Point2< typename MeshType::ScalarType > &v0, const Point2< typename MeshType::ScalarType > &v1, const Point2< typename MeshType::ScalarType > &v2, bool correctSafePointsBaryCoords=true)
 
static bool checkPoissonDisk (SampleSHT &sht, const Point3< ScalarType > &p, ScalarType radius)
 
static VertexPointer getSampleFromCell (Point3i &cell, MontecarloSHT &samplepool)
 
static VertexPointer getBestPrecomputedMontecarloSample (Point3i &cell, MontecarloSHT &samplepool, ScalarType diskRadius, const PoissonDiskParam &pp)
 
static ScalarType ComputePoissonDiskRadius (MeshType &origMesh, int sampleNum)
 Estimate the radius r that you should give to get a certain number of samples in a Poissson Disk Distribution of radius r.
 
static int ComputePoissonSampleNum (MeshType &origMesh, ScalarType diskRadius)
 
static void InitRadiusHandleFromQuality (MeshType &sampleMesh, PerVertexFloatAttribute &rH, ScalarType diskRadius, ScalarType radiusVariance, bool invert)
 
static void InitSpatialHashTable (MeshType &montecarloMesh, MontecarloSHT &montecarloSHT, ScalarType diskRadius, struct PoissonDiskParam pp=PoissonDiskParam())
 
static void PoissonDiskPruningByNumber (VertexSampler &ps, MeshType &m, size_t sampleNum, ScalarType &diskRadius, PoissonDiskParam &pp, float tolerance=0.04, int maxIter=20)
 
static void PoissonDiskPruning (VertexSampler &ps, MeshType &montecarloMesh, ScalarType diskRadius, PoissonDiskParam &pp)
 
static void HierarchicalPoissonDisk (MeshType &origMesh, VertexSampler &ps, MeshType &montecarloMesh, ScalarType diskRadius, const struct PoissonDiskParam pp=PoissonDiskParam())
 
static void Texture (MeshType &m, VertexSampler &ps, int textureWidth, int textureHeight, bool correctSafePointsBaryCoords=true)
 
static void RegularRecursiveOffset (MeshType &m, std::vector< CoordType > &pvec, ScalarType offset, float minDiag)
 
static void SubdivideAndSample (MeshType &m, std::vector< CoordType > &pvec, const Box3< ScalarType > bb, RRParam &rrp, float curDiag)
 

Detailed Description

template<class MeshType, class VertexSampler = TrivialSampler< MeshType>>
class vcg::tri::SurfaceSampling< MeshType, VertexSampler >

Main Class of the Sampling framework.

This class allows you to perform various kind of random/procedural point sampling over a triangulated surface. The class is templated over the PointSampler object that allows to customize the use of the generated samples.

Member Function Documentation

◆ EdgeMeshUniform()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::EdgeMeshUniform ( MeshType &  m,
VertexSampler &  ps,
float  radius,
EdgeSamplingStrategy  strategy = Floor 
)
inlinestatic

Perform an uniform sampling over an EdgeMesh.

It assumes that the mesh is 1-manifold. each connected component is sampled in a independent way. For each component of length <L> we place on it floor(L/radius)+1 samples. (if conservative argument is false we place ceil(L/radius)+1 samples)

◆ EdgeMontecarlo()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::EdgeMontecarlo ( MeshType &  m,
VertexSampler &  ps,
int  sampleNum,
bool  sampleAllEdges 
)
inlinestatic

This function computes a montecarlo distribution with an EXACT number of samples. it works by generating a sequence of consecutive segments proportional to the triangle areas and actually shooting sample over this line

◆ HierarchicalPoissonDisk()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::HierarchicalPoissonDisk ( MeshType &  origMesh,
VertexSampler &  ps,
MeshType &  montecarloMesh,
ScalarType  diskRadius,
const struct PoissonDiskParam  pp = PoissonDiskParam() 
)
inlinestatic

Compute a Poisson-disk sampling of the surface. The radius of the disk is computed according to the estimated sampling density.

This algorithm is an adaptation of the algorithm of White et al. :

"Poisson Disk Point Set by Hierarchical Dart Throwing" K. B. White, D. Cline, P. K. Egbert, IEEE Symposium on Interactive Ray Tracing, 2007, 10-12 Sept. 2007, pp. 129-132.

◆ InitRadiusHandleFromQuality()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::InitRadiusHandleFromQuality ( MeshType &  sampleMesh,
PerVertexFloatAttribute &  rH,
ScalarType  diskRadius,
ScalarType  radiusVariance,
bool  invert 
)
inlinestatic

When performing an adptive pruning for each sample we expect a varying radius to be removed. The radius is a PerVertex attribute that we compute from the current quality

the expected radius of the sample is computed so that it linearly maps the quality between diskradius and diskradius*variance in other words the radius

◆ Montecarlo()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::Montecarlo ( MeshType &  m,
VertexSampler &  ps,
int  sampleNum 
)
inlinestatic

This function computes a montecarlo distribution with an EXACT number of samples. it works by generating a sequence of consecutive segments proportional to the triangle areas and actually shooting sample over this line

◆ MontecarloPoisson()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::MontecarloPoisson ( MeshType &  m,
VertexSampler &  ps,
int  sampleNum 
)
inlinestatic

This function compute montecarlo distribution with an approximate number of samples exploiting the poisson distribution approximation of the binomial distribution.

For a given triangle t of area a_t, in a Mesh of area A, if we take n_s sample over the mesh, the number of samples that falls in t follows the poisson distribution of P(lambda ) with lambda = n_s * (a_t/A).

To approximate the Binomial we use a Poisson distribution with parameter \lambda = np can be used as an approximation to B(n,p) (it works if n is sufficiently large and p is sufficiently small).

◆ Poisson()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static int vcg::tri::SurfaceSampling< MeshType, VertexSampler >::Poisson ( double  lambda)
inlinestatic

algorithm poisson random number (Knuth): init: Let L ← e^−λ, k ← 0 and p ← 1. do: k ← k + 1. Generate uniform random number u in [0,1] and let p ← p × u. while p > L. return k − 1.

◆ PoissonDiskPruning()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::PoissonDiskPruning ( VertexSampler &  ps,
MeshType &  montecarloMesh,
ScalarType  diskRadius,
PoissonDiskParam pp 
)
inlinestatic

This is the main function that is used to build a poisson distribuition starting from a dense sample cloud (the montecarloMesh) by 'pruning' it. it puts all the samples in a hashed UG and randomly choose a sample and remove all the points in the sphere centered on the chosen sample

You can impose some constraint: all the vertices in the montecarloMesh that are marked with a bool attribute called "fixed" are surely chosen (if you also set the preGenFlag option)

◆ VertexAreaUniform()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::VertexAreaUniform ( MeshType &  m,
VertexSampler &  ps,
int  sampleNum 
)
inlinestatic

Sample the vertices in a uniform way. Each vertex has a probability of being chosen that is proportional to the area it represent.

◆ VertexBorder()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::VertexBorder ( MeshType &  m,
VertexSampler &  ps 
)
inlinestatic

Sample all the border vertices.

It assumes that the border flag have been set over the mesh. All the vertices on the border are sampled.

◆ VertexBorderCorner()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::VertexBorderCorner ( MeshType &  m,
VertexSampler &  ps,
ScalarType  angleRad 
)
inlinestatic

Sample all the border corner vertices.

It assumes that the border flag have been set over the mesh both for vertex and for faces. All the vertices on the border where the edges of the boundary of the surface forms an angle smaller than the given threshold are sampled. It assumes that the Per-Vertex border Flag has been set.

◆ VertexCrease()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::VertexCrease ( MeshType &  m,
VertexSampler &  ps 
)
inlinestatic

Sample all the crease vertices. It assumes that the crease edges had been marked as non-faux edges for example by using tri::UpdateFlags<MeshType>::FaceFauxCrease(mesh,creaseAngleRad); Then it chooses all the vertices where there are at least three non faux edges.

◆ VertexWeighted()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::VertexWeighted ( MeshType &  m,
VertexSampler &  ps,
int  sampleNum 
)
inlinestatic

Sample the vertices in a weighted way. Each vertex has a probability of being chosen that is proportional to its quality. It assumes that you are asking a number of vertices smaller than nv; Algorithm: 1) normalize quality so that sum q == 1; 2) shuffle vertices. 3) for each vertices choose it if rand > thr;

◆ WeightedMontecarlo()

template<class MeshType , class VertexSampler = TrivialSampler< MeshType>>
static void vcg::tri::SurfaceSampling< MeshType, VertexSampler >::WeightedMontecarlo ( MeshType &  m,
VertexSampler &  ps,
int  sampleNum,
float  variance 
)
inlinestatic

Compute a sampling of the surface that is weighted by the quality and a variance

We use the quality as linear distortion of density. We consider each triangle as scaled between 1 and 1/variance linearly according quality.

In practice with variance 2 the average distance between sample will double where the quality is maxima. If you have two same area region A with q==-1 and B with q==1, if variance==2 the A will have 4 times more samples than B


The documentation for this class was generated from the following file: