Signed Distance Fields 1.0

Union operator. More...

#include <sdf.h>

Inheritance diagram for SDFUnion:
SDFBinary SDFNode SDFSmoothUnion SDFSmoothUnionSphereLOD SDFUnionFrep SDFSmoothUnionExp

Public Member Functions

 SDFUnion (SDFNode *, SDFNode *)
 Create a union node.
 SDFUnion (SDFNode *, SDFNode *, SDFNode *)
 Create a union hierarchy ((A ∪ B) ∪ C).
 SDFUnion (SDFNode *, SDFNode *, SDFNode *, SDFNode *)
 Create a union hierarchy ((A ∪ B) ∪ (C ∪ D)).
 SDFUnion (const QVector< SDFNode * > &)
 Creates a union operator node given an array of nodes.
 SDFUnion (const QJsonValue &json)
QJsonValue ToJson () const
 Conversion to JavaScript Object Notation.
virtual ~SDFUnion ()
 Destructor.
double BID (const Vector &) const
 Compute a lower bound of the signed distance.
virtual double Signed (const Vector &) const
 Compute the signed distance.
virtual Vector Gradient (const Vector &) const
 Compute the gradient of the field.
virtual Color GetColor (const Vector &) const
 Compute the color.
QString GetShader (PrimitiveManager &, std::list< QString > &, bool &) const
 Compute the GLSL code to render the node.
QString GetCostShader (PrimitiveManager &, std::list< QString > &, bool &) const
 Compute the GLSL code to compute the cost of a call to sdf.
QString GetGradientShader (PrimitiveManager &, std::list< QString > &, bool &) const
 Compute the GLSL code to compute the gradient the sdf.
virtual int Memory () const
 Return the size of a sub-tree.
virtual SDFNode * Copy () const
 Deep copy.
Public Member Functions inherited from SDFBinary
 SDFBinary (SDFNode *, SDFNode *)
 Create a binary node.
virtual ~SDFBinary ()
 Recursively destroy the sub-trees.
virtual double K (const Box &) const
 Return the local Lipschitz constant.
virtual void SetShaderId (PrimitiveManager &)
 Set up an id for generating GLSL code.
virtual void ResetShaderId ()
 Reset the id for generating GLSL code.
virtual void ComputeCostSigned (const Vector &)
 Compute the number of recursive calls to Signed().
int Nodes () const
 Compute the number of nodes in the sub-tree.
virtual double Cost (const Vector &p) const
 Cost of the evaluation of the field at a point: the cost of the node plus the costs of the two sub-trees.
SDFNode * add_proxy ()
 Create a copy of the node where each sub-tree is replaced by its version with proxies, then bounded by the cheapest proxy, see SDFNode::add_proxy_root().
virtual SDFNode * extract_proxy (int=0)
 Replace each sub-tree by a copy of its proxy, see SDFNode::extract_proxy().
Public Member Functions inherited from SDFNode
 SDFNode ()
 Create a generic node.
virtual ~SDFNode ()
 Destructor.
virtual bool Inside (const Vector &) const
 Check if a point is inside or outside.
virtual double K () const
 Return the Lipschitz constant of the node.
Box GetBox () const
 Return the bounding box of the node.
virtual double Cost (int=10000) const
 Estimate the average cost of the evaluation of the field over the box of the node.
virtual double Cost (Box, int=10000) const
 Estimate the average cost of the evaluation of the field over a box.
SDFNode * add_proxy_root ()
 Create a copy of the node, bounded by the cheapest proxy if there is one.

Static Public Member Functions

static double Signed (const double &, const double &)
 Compute the union, i.e. the minimum of two distance field values.
static SDFNode * QuadricCurve (const double &, const QuadricCurveSet &)
 This function creates a quadric B�zier curve controled by an array of control knots.
static SDFNode * RevolutionQuadricTubeSet (const Vector &, const Vector &, const double &, const QuadricCurve2Set &)
 Creates a surface of revolution.
static SDFNode * RevolutionQuadricTubeSet (const double &, const QuadricCurve2Set &)
 Creates a surface of revolution.
Static Public Member Functions inherited from SDFNode
static SDFNode * FromJson (const QJsonValue &json)
 Conversion from JavaScript Object Notation.
static SDFNode * FromJson (const QByteArray &json)
 Create a node from its JSON description.
static void ResetrecursiveCalls ()
 Reset the recursive call property of the tree.
static int recursiveCalls ()
 Return the number of recursive calls counted by the ComputeCost*() functions since the last reset.
static void addrecursiveCalls (int)
 Add a number to the _recursiveCalls counter.
static SDFNode * Stalactite (const Vector &p, const double &h, const double &r, bool noise=true, Xoshiro256 &random=Xoshiro256::X512, const double &largeur=0.25, const double &espacement=0.61)
 Procedural parameterized stalactite.
static SDFNode * SpherePieces ()
 Sphere carved, placed on a cylinder. Nice scene for testing sharp features reconstruction.

Additional Inherited Members

Protected Attributes inherited from SDFBinary
SDFNode * e [2] = { nullptr,nullptr }
 Sub-trees.
Protected Attributes inherited from SDFNode
Box box = Box::Infinity
 Box bounding the surface.
double k = 1.0
 Lipschitz constant.
int cost = 1
 Relative computation cost.
int id = -1
 Id to optimize the glsl code generation (avoid repetition when looking twice the same node).
Static Protected Attributes inherited from SDFNode
static constexpr double Epsilon = 0.01
 Small constant used for bounding volumes and as finite-difference step in Gradient().
static int _recursiveCalls = 0
 Recursive calls counted by ComputeCost*().

Detailed Description

Union operator.

The union between two signed Euclidean distance functions yields another Euclidean signed distance function.

Constructor & Destructor Documentation

◆ SDFUnion() [1/5]

SDFUnion::SDFUnion ( SDFNode * a,
SDFNode * b )
explicit

Create a union node.

Parameters
a,bSub-trees.

◆ SDFUnion() [2/5]

SDFUnion::SDFUnion ( SDFNode * a,
SDFNode * b,
SDFNode * c )
explicit

Create a union hierarchy ((A ∪ B) ∪ C).

Parameters
a,b,cSub-trees.

◆ SDFUnion() [3/5]

SDFUnion::SDFUnion ( SDFNode * a,
SDFNode * b,
SDFNode * c,
SDFNode * d )
explicit

Create a union hierarchy ((A ∪ B) ∪ (C ∪ D)).

Parameters
a,b,c,dSub-trees.

◆ SDFUnion() [4/5]

SDFUnion::SDFUnion ( const QVector< SDFNode * > & a)
explicit

Creates a union operator node given an array of nodes.

Builds a left-nested chain in input order: Union(a[0], Union(Union(a[1], a[2]), ...)). The array must contain at least two elements.

Parameters
aSet of nodes (at least 2).

◆ SDFUnion() [5/5]

SDFUnion::SDFUnion ( const QJsonValue & json)
explicit

Member Function Documentation

◆ BID()

double SDFUnion::BID ( const Vector & p) const
virtual

Compute a lower bound of the signed distance.

The bound is not continuous, not even monotonous, but is faster to compute than the actual distance.

Author
Hubert-Brierre Pierre
Parameters
pPoint.

Reimplemented from SDFNode.

◆ GetColor()

Color SDFUnion::GetColor ( const Vector & p) const
virtual

Compute the color.

Parameters
pPoint.

Reimplemented from SDFNode.

Reimplemented in SDFSmoothUnion, and SDFSmoothUnionExp.

◆ GetCostShader()

QString SDFUnion::GetCostShader ( PrimitiveManager & primitives,
std::list< QString > & dependency,
bool & valid_glsl ) const
virtual

Compute the GLSL code to compute the cost of a call to sdf.

Author
Hubert-Brierre Pierre

Reimplemented from SDFBinary.

◆ GetGradientShader()

QString SDFUnion::GetGradientShader ( PrimitiveManager & primitives,
std::list< QString > & dependency,
bool & valid_glsl ) const
virtual

Compute the GLSL code to compute the gradient the sdf.

Author
Hubert-Brierre Pierre

Reimplemented from SDFNode.

◆ GetShader()

QString SDFUnion::GetShader ( PrimitiveManager & primitives,
std::list< QString > & dependency,
bool & valid_glsl ) const
virtual

Compute the GLSL code to render the node.

Author
Hubert-Brierre Pierre

Reimplemented from SDFNode.

Reimplemented in SDFUnionFrep.

◆ Gradient()

Vector SDFUnion::Gradient ( const Vector & p) const
virtual

Compute the gradient of the field.

Parameters
pPoint.

Reimplemented from SDFNode.

Reimplemented in SDFSmoothUnion, SDFSmoothUnionSphereLOD, and SDFUnionFrep.

◆ Memory()

int SDFUnion::Memory ( ) const
virtual

Return the size of a sub-tree.

Reimplemented from SDFNode.

Reimplemented in SDFSmoothUnion, SDFSmoothUnionExp, SDFSmoothUnionSphereLOD, and SDFUnionFrep.

◆ QuadricCurve()

SDFNode * SDFUnion::QuadricCurve ( const double & r,
const QuadricCurveSet & q )
static

This function creates a quadric B�zier curve controled by an array of control knots.

Parameters
rThe radius.
qThe set of quadrics.

◆ RevolutionQuadricTubeSet() [1/2]

SDFNode * SDFUnion::RevolutionQuadricTubeSet ( const double & r,
const QuadricCurve2Set & q )
static

Creates a surface of revolution.

The profile is a quadric B�zier curve controled by an array of control knots, using origin and z-axis.

Parameters
rOffset radius.
qSet of quadrics.

◆ RevolutionQuadricTubeSet() [2/2]

SDFNode * SDFUnion::RevolutionQuadricTubeSet ( const Vector & a,
const Vector & b,
const double & r,
const QuadricCurve2Set & q )
static

Creates a surface of revolution.

The profile is a quadric B�zier curve controled by an array of control knots.

Parameters
a,bThe vertices of the axis.
rThe offset radius.
qThe set of quadrics.

◆ Signed() [1/2]

double SDFUnion::Signed ( const double & x,
const double & y )
static

Compute the union, i.e. the minimum of two distance field values.

Parameters
x,yReals.

◆ Signed() [2/2]

double SDFUnion::Signed ( const Vector & p) const
virtual

Compute the signed distance.

Parameters
pPoint.

Reimplemented from SDFNode.

Reimplemented in SDFSmoothUnion, SDFSmoothUnionExp, SDFSmoothUnionSphereLOD, and SDFUnionFrep.

◆ ToJson()

QJsonValue SDFUnion::ToJson ( ) const
virtual

Conversion to JavaScript Object Notation.

Reimplemented from SDFNode.