Blob 1.0
BlobTree Class Reference

The BlobTree model. More...

#include <blobtree.h>

Inheritance diagram for BlobTree:
AnalyticScalarField

Public Member Functions

 BlobTree (TreeNode *=nullptr, const double &=0.5)
 Creates a BlobTree.
 
virtual ~BlobTree ()
 Destroys the BlobTree structure, recursively exploring the nodes of the BlobTree.
 
 BlobTree (const BlobTree &)
 Overloaded.
 
BlobTreeoperator= (const BlobTree &)
 Overloaded.
 
double GetThreshold () const
 Returns the threshold value.
 
virtual double Value (const Vector &) const
 Computes the field function value at a point.
 
virtual Vector Gradient (const Vector &) const
 Computes the gradient of the field function at a point.
 
virtual void IntensityGradient (const Vector &, double &, Vector &) const
 Overloaded to minimize function calls.
 
virtual BlobTreeCopy () const
 Deep copy.
 
virtual double K () const
 Computes the Lipschitz constant over the whole domain.
 
virtual double K (int) const
 Computes the Lipschitz constant.
 
virtual double K (const Box &) const
 Computes the Lipschitz constant of the field function in a limited region of space.
 
virtual double K (const Ray &) const
 Computes the Lipschitz constant of the function along a ray.
 
virtual double K (const Segment &) const
 Computes the Lipschitz constant along a segment.
 
virtual double K (const RayStep &) const
 Computes the Lipschitz constant along an optimized ray-stepping segment.
 
virtual double K (const Sphere &) const
 Computes the Lipschitz constant in a sphere.
 
virtual bool SphereTrace (const Ray &, const double &, const double &, const double &, double &, int &, const double &=1e-4) const
 Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.
 
virtual bool SphereTrace (const Ray &, const double &, const double &, const double &, const double &, double &, int &, const double &=1e-4) const
 Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.
 
virtual bool SphereBoxTrace (const Ray &, const double &, const double &, const double &, double &, int &, const double &=1e-4) const
 Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.
 
virtual bool SphereSegmentTrace (const Ray &, const double &, const double &, const double &, double &, int &, const double &=1e-4) const
 Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.
 
virtual bool RayStepSegmentTrace (const Ray &, const double &, const double &, const double &, double &, int &, const double &=1e-4) const
 Find the first intersection between a ray and the implicit surface.
 
virtual bool BinarySearch (const Ray &ray, const double &a, const double &b, double &t, int &x, const double &=1e-4, bool=false) const
 Compute the intersection with a ray, using binary search.
 
virtual bool BinarySearch (const Ray &ray, const double &a, const double &b, const Vector &pa, const Vector &pb, const double &va, const double &vb, double &t, int &, const double &=1e-4, bool=false) const
 Compute the intersection with a ray, using binary search.
 
virtual Box GetBox () const
 Return the bounding box of the BlobTree structure.
 
virtual double Omega (const Vector &) const
 Return the squared distance to the compact support of the BlobTree.
 
virtual Voxel EmptyVoxels (int) const
 Compute a voxel whose cells are defined as empty if the statisfy the Lipschitz condition, or (possibly) non empty otherwise.
 
virtual Color GetMaterial (const Vector &, const Vector &=Vector::Null) const
 Computes the surface parameters at a point.
 
BlobTreeCut (const Box &) const
 Cuts the BlobTree to simplify its structure inside a box.
 
void Rotate (const Matrix &)
 Creates a union node at the top node of the BlobTree.
 
void Translate (const Vector &)
 Creates a union node at the top node of the BlobTree.
 
void Scale (const Vector &)
 Creates a union node at the top node of the BlobTree.
 
void Blend (TreeNode *)
 Creates a blending node at the top node of the BlobTree.
 
void Difference (TreeNode *)
 Creates a difference node at the top node of the BlobTree.
 
void Intersection (TreeNode *)
 Creates an intersection node at the top node of the BlobTree.
 
void Union (TreeNode *)
 Creates a union node at the top node of the BlobTree.
 
BlobTreeCenterBox ()
 Centers the BlobTree at the origin.
 
BlobTreeScaleBox ()
 Scales the BlobTree to a unit bounding box.
 
int Memory () const
 Compute the size of the BlobTree.
 
int Nodes () const
 Compute the number of nodes of the BlobTree.
 
int Depth () const
 Compute the depth of the BlobTree.
 

Static Public Member Functions

static void ResetCalls ()
 Reset the number of function calls.
 
static int Calls ()
 Get the number of function calls.
 
static int Oversteps ()
 Return the number of overstep fails.
 
static BlobTreeCreateCandlestick ()
 Create a candlestick.
 
static BlobTreeCreateAmphora (const double &=0.02)
 Creates an amphora.
 
static BlobTreeCreateVase ()
 Creates a vase.
 
static BlobTreeCreateBear (bool=false)
 Creates a soft-toy like bear.
 
static BlobTreeCreateBird ()
 Creates a soft-toy like bird.
 
static BlobTreeCreateElk ()
 Creates a soft-toy like elk.
 
static BlobTreeCreateFlask ()
 Create a liquor flask.
 
static BlobTreeCreateFlaskGlass (bool=false, bool=false)
 Creates a flask.
 
static BlobTreeChessRook ()
 Creates a rook.
 
static BlobTreeChessQueen ()
 Creates a queen.
 
static BlobTreeChessKing ()
 Creates a king.
 
static BlobTreeCreateCube ()
 Sphere pierced by three boxes.
 
static BlobTreeColumn (bool=false)
 Create a colum.
 
static BlobTreeCreateCandle ()
 Candle.
 
static BlobTreeScotchGlass ()
 A simple glass.
 
static BlobTreeWaterGlass ()
 Creates a simple water glass.
 
static BlobTreeMechanic ()
 Create a mechanical shape.
 
static BlobTreeCandelabra ()
 Creates the candelabra.
 
static BlobTreeChandelier3 ()
 Create a candlestick.
 
static BlobTreeChampagneGlass ()
 Create a simple twisted shape.
 
static TreeNodeStalactite (const Vector &, const double &, const double &)
 Create a stalactite.
 

Protected Attributes

double T = 0.5
 Threshold value.
 
TreeNoderoot = nullptr
 Root node.
 

Static Protected Attributes

static int calls = 0
 Number of calls to Value().
 
static int oversteps = 0
 Number of oversteps failed in ray marching.
 

Detailed Description

The BlobTree model.

Constructor & Destructor Documentation

◆ BlobTree()

BlobTree::BlobTree ( TreeNode * node = nullptr,
const double & T = 0.5 )
explicit

Creates a BlobTree.

Parameters
nodeRoot node.
TThreshold.

Member Function Documentation

◆ GetThreshold()

double BlobTree::GetThreshold ( ) const

Returns the threshold value.

Returns
Threshold value.

◆ Value()

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

Computes the field function value at a point.

If the root of the BlobTree is empty, this function returns -T.

Parameters
pPoint.
Returns
Intensity.

Reimplemented from AnalyticScalarField.

◆ Gradient()

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

Computes the gradient of the field function at a point.

Parameters
pPoint.
Returns
Gradient.
See also
TreeNode::Gradient()

Reimplemented from AnalyticScalarField.

◆ IntensityGradient()

void BlobTree::IntensityGradient ( const Vector & p,
double & intensity,
Vector & normal ) const
virtual

Overloaded to minimize function calls.

Parameters
pPoint.
intensityReturned field value.
normalReturned gradient.

◆ Copy()

BlobTree * BlobTree::Copy ( ) const
virtual

Deep copy.

Returns
Copy of the BlobTree.

◆ K() [1/7]

double BlobTree::K ( ) const
virtual

Computes the Lipschitz constant over the whole domain.

See also
BlobTree::K(int)
Returns
Lipschitz constant.

Reimplemented from AnalyticScalarField.

◆ K() [2/7]

double BlobTree::K ( int n) const
virtual

Computes the Lipschitz constant.

Divides the domain into a grid, and compute the maximum of the local constants.

Returns
Lipschitz constant.

◆ K() [3/7]

double BlobTree::K ( const Box & b) const
virtual

Computes the Lipschitz constant of the field function in a limited region of space.

The implementation prunes the whole tree data structure, combining the Lipschitz constants of the nodes as needed if the bounding box of the node intersects the argument box.

Parameters
bThe box.
Returns
Lipschitz constant.

Reimplemented from AnalyticScalarField.

◆ K() [4/7]

double BlobTree::K ( const Ray & ray) const
virtual

Computes the Lipschitz constant of the function along a ray.

The implementation prunes the whole tree data structure, combining the Lipschitz constants of the nodes on the fly as needed.

Parameters
rayThe ray.
Returns
Lipschitz constant.

◆ K() [5/7]

double BlobTree::K ( const Segment & s) const
virtual

Computes the Lipschitz constant along a segment.

Parameters
sThe segment.
Returns
Lipschitz constant.

Reimplemented from AnalyticScalarField.

◆ K() [6/7]

double BlobTree::K ( const RayStep & s) const
virtual

Computes the Lipschitz constant along an optimized ray-stepping segment.

Parameters
sThe ray-stepping segment.
Returns
Lipschitz constant.

◆ K() [7/7]

double BlobTree::K ( const Sphere & s) const
virtual

Computes the Lipschitz constant in a sphere.

Parameters
sThe sphere.
Returns
Lipschitz constant.

Reimplemented from AnalyticScalarField.

◆ SphereTrace() [1/2]

bool BlobTree::SphereTrace ( const Ray & ray,
const double & k,
const double & a,
const double & b,
double & t,
int & s,
const double & epsilon = 1e-4 ) const
virtual

Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.

Parameters
rayThe ray
kLipschitz constant.
a,bInterval where intersection is tracked.
sReturn number of steps.
tNearest root, if exists
epsilonPrecision for detecting ray-surface intersection.

Simply march along the ray using adaptive steps depending on the magnitude of the field function at point samples. Intersection occurs if the absolute value of the field function gets lower than epsilon.

In practice, if the Lipschitz constant is unknown, it may be accurately defined with the member function BlobTree::K(const Ray&). Thus, the code could be as follows:

double t;
double a,b;
int s;
if (blobtree->GetBox().Intersect(ray,a,b))
{
bool r=blobtree->SphereTrace(ray,blobtree->K(ray),a,b,t,s,1.0e-6);
}

Reimplemented from AnalyticScalarField.

◆ SphereTrace() [2/2]

bool BlobTree::SphereTrace ( const Ray & ray,
const double & k,
const double & a,
const double & b,
const double & e,
double & t,
int & s,
const double & epsilon = 1e-4 ) const
virtual

Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.

Parameters
rayThe ray
kLipschitz constant.
a,bInterval where intersection is tracked.
eOverstep factor, should be within interval [1.0,2.0], using 1.25 is fine.
sReturned number of steps.
tNearest root, if exists
epsilonPrecision for detecting ray-surface intersection.

The function is almost the same as normal sphere-tracing. Instead of marching along the ray with valid steps, the magnitude of the step is slighly over estimated by a factor e.

See also
BlobTree::SphereTrace(const Ray&, const double&, const double& , const double& , double&, int& ,const double& ) const

◆ SphereBoxTrace()

bool BlobTree::SphereBoxTrace ( const Ray & ray,
const double & a,
const double & b,
const double & c,
double & t,
int & s,
const double & epsilon = 1e-4 ) const
virtual

Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.

Parameters
rayThe ray
a,bInterval where intersection is tracked.
cAcceleration factor defining the stepping distance increase factor [1.0,100.0], using 1.5 is fine.
sReturned number of steps.
tNearest root, if exists
epsilonPrecision for detecting ray-surface intersection.

The function is almost the same as normal sphere-tracing. Instead of marching along the ray with valid steps, the magnitude of the step is slighly over estimated by a factor e.

See also
BlobTree::SphereTrace(const Ray&, const double&, const double& , const double& , double&, int& ,const double& ) const

◆ SphereSegmentTrace()

bool BlobTree::SphereSegmentTrace ( const Ray & ray,
const double & a,
const double & b,
const double & c,
double & t,
int & s,
const double & epsilon = 1e-4 ) const
virtual

Find the first intersection between a ray and an implicit surface on a given interval, using sphere tracing.

Parameters
rayThe ray
a,bInterval where intersection is tracked.
cAcceleration factor defining the stepping distance increase factor [1.0,100.0], using 1.5 is fine.
sReturned number of steps.
tNearest root, if exists
epsilonPrecision for detecting ray-surface intersection.

The function is almost the same as normal sphere-tracing. Instead of marching along the ray with valid steps, the magnitude of the step is slighly over estimated by a factor e.

See also
BlobTree::SphereTrace(const Ray&, const double&, const double& , const double& , double&, int& ,const double& ) const

◆ BinarySearch() [1/2]

bool BlobTree::BinarySearch ( const Ray & ray,
const double & a,
const double & b,
double & t,
int & x,
const double & e = 1e-4,
bool uk = false ) const
virtual

Compute the intersection with a ray, using binary search.

Parameters
rayThe ray.
a,bInterval.
tIntersection depth.
xReturned number of steps.
eEpsilon value.
ukBoolean, local segment Lipschitz bound if true, global Lipschitz bound otherwise.

◆ BinarySearch() [2/2]

bool BlobTree::BinarySearch ( const Ray & ray,
const double & a,
const double & b,
const Vector & pa,
const Vector & pb,
const double & va,
const double & vb,
double & t,
int & x,
const double & e = 1e-4,
bool uk = false ) const
virtual

Compute the intersection with a ray, using binary search.

Parameters
rayThe ray.
a,bInterval.
pa,pbPoints.
va,vbField function values.
tIntersection depth.
xReturned number of steps.
eEpsilon value.
ukBoolean, local segment Lipschitz bound if true, global Lipschitz bound otherwise.

◆ GetBox()

Box BlobTree::GetBox ( ) const
virtual

Return the bounding box of the BlobTree structure.

Returns
The box.

Reimplemented from AnalyticScalarField.

◆ Omega()

double BlobTree::Omega ( const Vector & p) const
virtual

Return the squared distance to the compact support of the BlobTree.

Some primitives such as TreeTwist return the squared distance to the bounding box as a default proxy.

Parameters
pPoint.

◆ EmptyVoxels()

Voxel BlobTree::EmptyVoxels ( int n) const
virtual

Compute a voxel whose cells are defined as empty if the statisfy the Lipschitz condition, or (possibly) non empty otherwise.

Parameters
nMaximum subdivision.

◆ GetMaterial()

Color BlobTree::GetMaterial ( const Vector & p,
const Vector & n = Vector::Null ) const
virtual

Computes the surface parameters at a point.

Parameters
pPoint.
nNormal.
Returns
Color.

Reimplemented from AnalyticScalarField.

◆ Cut()

BlobTree * BlobTree::Cut ( const Box & b) const

Cuts the BlobTree to simplify its structure inside a box.

Parameters
bBox.

◆ Rotate()

void BlobTree::Rotate ( const Matrix & r)

Creates a union node at the top node of the BlobTree.

Parameters
rRotation matrix.

◆ Translate()

void BlobTree::Translate ( const Vector & t)

Creates a union node at the top node of the BlobTree.

Parameters
tTranslation vector.

◆ Scale()

void BlobTree::Scale ( const Vector & s)

Creates a union node at the top node of the BlobTree.

Parameters
sScaling vector.

◆ Blend()

void BlobTree::Blend ( TreeNode * node)

Creates a blending node at the top node of the BlobTree.

Parameters
nodeSub-tree.

◆ Difference()

void BlobTree::Difference ( TreeNode * node)

Creates a difference node at the top node of the BlobTree.

Parameters
nodeSub-tree.

◆ Intersection()

void BlobTree::Intersection ( TreeNode * node)

Creates an intersection node at the top node of the BlobTree.

Parameters
nodeSub-tree.

◆ Union()

void BlobTree::Union ( TreeNode * node)

Creates a union node at the top node of the BlobTree.

Parameters
nodeSub-tree.

◆ ScaleBox()

BlobTree * BlobTree::ScaleBox ( )

Scales the BlobTree to a unit bounding box.

This is a convenience function, which simply computes the bounding box of the blobtree and inserts a new scaling node.

◆ Calls()

int BlobTree::Calls ( )
static

Get the number of function calls.

This function returns the number of calls to BlobTree::Value() since the creation of the BlobTree. It can be reset to using ResetCalls().

◆ CreateAmphora()

BlobTree * BlobTree::CreateAmphora ( const double & thickness = 0.02)
static

Creates an amphora.

Parameters
thicknessThe thickness of the amphora.

◆ CreateBear()

BlobTree * BlobTree::CreateBear ( bool symmetry = false)
static

Creates a soft-toy like bear.

Parameters
symmetryBoolean, set to false so avoid symmetry operator, true using a TreeCloneFrame

◆ CreateFlaskGlass()

BlobTree * BlobTree::CreateFlaskGlass ( bool type = false,
bool side = false )
static

Creates a flask.

Parameters
typeCreates a hole in the flask is set to true
sideAdds the handle.

◆ Column()

BlobTree * BlobTree::Column ( bool type = false)
static

Create a colum.

Parameters
typeCarvings, set to true if carvings are wanted.

◆ Stalactite()

TreeNode * BlobTree::Stalactite ( const Vector & a,
const double & length,
const double & r )
static

Create a stalactite.

Parameters
aStarting position.
lengthTarget length of the stalactite, the generated model may be slightly shorter.
rInitial radius.