Signed Distance Fields 1.0
SDFTree Class Reference

Signed distance field construction tree. More...

#include <sdf.h>

Inheritance diagram for SDFTree:
AnalyticScalarField

Public Member Functions

 SDFTree (SDFNode *)
 Constructor.
 
 ~SDFTree ()
 Destructor.
 
void ComputeCost (const Vector &) const
 Computes the signed distance to the surface.
 
double Value (const Vector &) const
 Computes the signed distance to the surface.
 
Vector Gradient (const Vector &) const
 Compute the gradient of the field.
 
Vector Normal (const Vector &) const
 Compute the normal of the field.
 
bool Inside (const Vector &) const
 Check if a point is inside or outside.
 
Color GetColor (const Vector &) const
 Compute the color.
 
void setUseBID (bool)
 Set the value of useBID so that the function value use or not the BID method.
 
double K () const
 Computes the Lipschitz constant of the construction tree.
 
Box GetBox () const
 Get the bounding box of the construction tree.
 
void Union (SDFNode *)
 Apply an union operator between the root and paremeter.
 
void Intersection (SDFNode *)
 Apply an intersection operator between the root and paremeter.
 
void Difference (SDFNode *)
 Apply a difference operator between the root and paremeter.
 
void SmoothDifference (SDFNode *, double)
 Apply a smooth difference operator between the root and paremeter.
 
void SmoothUnion (SDFNode *, double)
 Apply a smooth union operator between the root and paremeter.
 
void AddSphere (const Vector &, double, double)
 Adds a sphere.
 
bool SphereTrace (const Ray &, const double &, const double &, const double &, double &, int &, const double &=0.001) const
 Find the first intersection between a ray and the object.
 
bool Intersect (const Ray &, Vector &) const
 Intersection with the construction tree, using sphere tracing.
 
void PolygonizeMultithreadSplit (int, int, QVector< Mesh > &, const Box &) const
 Polygonization into multiple mesh to virtually increase maximum resolution.
 
virtual int Memory () const
 Computes the memory used by the construction tree.
 
int Nodes () const
 Returns the number of nodes in the tree.
 
SDFNodeRoot () const
 Returns the root of the tree.
 
QString TimingsGradientAnalytic (int) const
 Computes the timings (in ms) for the analytic (if available) gradient function of the construction tree.
 
QString TimingsGradientNumerical (int) const
 Computes the timings (in ms) for the numerical gradient function of the construction tree.
 
QString Timings (int) const
 Computes the timings (in ms) for the field function of the construction tree.
 
QString GetShader (bool materialShader=true, bool costShader=true, bool gradShader=true) const
 create the GLSL code to render the SDF using sphereTracing.glsl
 
QString GetShaderIndented (bool materialShader=true, bool costShader=true, bool gradShader=true) const
 create the GLSL code to render the SDF using sphereTracing.glsl
 

Static Public Member Functions

static void ResetCalls ()
 Reset the call property of the tree.
 
static int Calls ()
 Returns the number of calls to Value().
 
static void ResetReccursiveCalls ()
 Reset the reccursive call property of the tree.
 
static int ReccursiveCalls ()
 Returns the number of reccursive calls to Value() and BID().
 
static void setComputeNbReccursiveCalls (bool computeRecCalls)
 Set the static boolean computeNbReccursiveCalls to allow computation of nb of reccursive call in the function Value.
 

Protected Attributes

SDFNoderoot = nullptr
 Root node.
 

Static Protected Attributes

static int calls = 0
 Number of call to SDFTree::Value(). <FONT COLOR="AA2222"><B>Warning</B></FONT> this will not give the correct number when used in a multi-threaded context (for example when raytracing the tree).
 

Detailed Description

Signed distance field construction tree.

Constructor & Destructor Documentation

◆ SDFTree()

SDFTree::SDFTree ( SDFNode * r)
explicit

Constructor.

Parameters
rRoot node.

Member Function Documentation

◆ AddSphere()

void SDFTree::AddSphere ( const Vector & c,
double r,
double e )

Adds a sphere.

Parameters
cCenter.
rRadius.
eEnergy.

◆ ComputeCost()

void SDFTree::ComputeCost ( const Vector & p) const

Computes the signed distance to the surface.

Parameters
pPoint.

◆ Difference()

void SDFTree::Difference ( SDFNode * n)

Apply a difference operator between the root and paremeter.

Parameters
nnode.

◆ GetColor()

Color SDFTree::GetColor ( const Vector & p) const

Compute the color.

Parameters
pPoint.

◆ GetShader()

QString SDFTree::GetShader ( bool materialShader = true,
bool costShader = true,
bool gradShader = true ) const

create the GLSL code to render the SDF using sphereTracing.glsl

Author
HUBERT-BRIERRE Pierre

◆ GetShaderIndented()

QString SDFTree::GetShaderIndented ( bool materialShader = true,
bool costShader = true,
bool gradShader = true ) const

create the GLSL code to render the SDF using sphereTracing.glsl

Author
HUBERT-BRIERRE Pierre

◆ Gradient()

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

Compute the gradient of the field.

Parameters
pPoint.

Reimplemented from AnalyticScalarField.

◆ Inside()

bool SDFTree::Inside ( const Vector & p) const

Check if a point is inside or outside.

Parameters
pPoint.

◆ Intersection()

void SDFTree::Intersection ( SDFNode * n)

Apply an intersection operator between the root and paremeter.

Parameters
nnode to be intersected with root.

◆ Normal()

Vector SDFTree::Normal ( const Vector & p) const
virtual

Compute the normal of the field.

Parameters
pPoint.

Reimplemented from AnalyticScalarField.

◆ PolygonizeMultithreadSplit()

void SDFTree::PolygonizeMultithreadSplit ( int nGlobal,
int nMesh,
QVector< Mesh > & meshes,
const Box & box ) const

Polygonization into multiple mesh to virtually increase maximum resolution.

See also
ScalarField::Polygonize
Parameters
nGlobalglobal grid resolution. n^2 meshes are created.
nMeshindividual grid resolution.
meshesMesh vector, should be empty.
boxThe box.

◆ SmoothDifference()

void SDFTree::SmoothDifference ( SDFNode * n,
double t )

Apply a smooth difference operator between the root and paremeter.

Parameters
nnode.
tSmoothing radius.

◆ SmoothUnion()

void SDFTree::SmoothUnion ( SDFNode * n,
double t )

Apply a smooth union operator between the root and paremeter.

Parameters
nnode.
tSmoothing radius.

◆ SphereTrace()

bool SDFTree::SphereTrace ( const Ray & ray,
const double & k,
const double & a,
const double & b,
double & t,
int & s,
const double & epsilon = 0.001 ) const
virtual

Find the first intersection between a ray and the object.

Parameters
rayThe ray
kLipschitz constant.
a,bSearching interval.
tReturned intersection depth.
sReturned step count.
epsilonMinimum stepping distance.

Reimplemented from AnalyticScalarField.

◆ Timings()

QString SDFTree::Timings ( int n) const

Computes the timings (in ms) for the field function of the construction tree.

Parameters
nNumber of calls
Returns
A string with the elapsed milliseconds for n calls.

◆ TimingsGradientAnalytic()

QString SDFTree::TimingsGradientAnalytic ( int n) const

Computes the timings (in ms) for the analytic (if available) gradient function of the construction tree.

Parameters
nNumber of calls
Returns
A string with the elapsed milliseconds for n calls.

◆ TimingsGradientNumerical()

QString SDFTree::TimingsGradientNumerical ( int n) const

Computes the timings (in ms) for the numerical gradient function of the construction tree.

Parameters
nNumber of calls
Returns
A string with the elapsed milliseconds for n calls.

◆ Union()

void SDFTree::Union ( SDFNode * n)

Apply an union operator between the root and paremeter.

Parameters
nnode to be unioned with root.

◆ Value()

double SDFTree::Value ( const Vector & p) const
virtual

Computes the signed distance to the surface.

Parameters
pPoint.

Reimplemented from AnalyticScalarField.