Blob 1.0
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
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. More...
 
virtual ~BlobTree ()
 Destroys the BlobTree structure, recursively exploring the nodes of the BlobTree.
 
 BlobTree (const BlobTree &)
 Overloaded.
 
BlobTreeoperator= (const BlobTree &)
 Overloaded.
 
TreeNodeGetRoot () const
 Returns the root. More...
 
double GetThreshold () const
 Returns the threshold value. More...
 
virtual double Value (const Vector &) const
 Computes the field function value at a point. More...
 
virtual Vector Gradient (const Vector &) const
 Computes the gradient of the field function at a point. More...
 
virtual void IntensityGradient (const Vector &, double &, Vector &) const
 Overloaded to minimize function calls. More...
 
virtual double Volume (int=5) const
 Computes the volume of the BlobTree. More...
 
virtual double Volume (const Box &, int) const
 Compute the volume of a BlobTree object. More...
 
virtual double Volume (const Box &, int, double &) const
 Compute the volume of a BlobTree object. More...
 
virtual Sphere Center (int) const
 Computes the gravity center of the BlobTree. More...
 
virtual Sphere Center (const Box &, int) const
 Compute the center of gravity of the BlobTree. More...
 
virtual BlobTreeCopy () const
 Deep copy. More...
 
virtual double K () const
 Computes the Lipschitz constant over the whole domain. More...
 
virtual double K (int) const
 Computes the Lipschitz constant. More...
 
virtual double K (const Box &) const
 Computes the Lipschitz constant of the field function in a limited region of space. More...
 
virtual double K (const Ray &) const
 Computes the Lipschitz constant of the function along a ray. More...
 
virtual double K (const Segment &) const
 Computes the Lipschitz constant along a segment. More...
 
virtual double K (const RayStep &) const
 Computes the Lipschitz constant along an optimized ray-stepping segment. More...
 
virtual double K (const Sphere &) const
 Computes the Lipschitz constant in a sphere. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual Box GetBox () const
 Return the bounding box of the BlobTree structure. More...
 
virtual Voxel EmptyVoxels (int) const
 Step along the ray. More...
 
virtual Color GetMaterial (const Vector &, const Vector &=Vector::Null) const
 Computes the surface parameters at a point. More...
 
BlobTreeCut (const Box &) const
 Cuts the BlobTree to simplify its structure inside a box. More...
 
void Rotate (const Matrix &)
 Creates a union node at the top node of the BlobTree. More...
 
void Translate (const Vector &)
 Creates a union node at the top node of the BlobTree. More...
 
void Scale (const Vector &)
 Creates a union node at the top node of the BlobTree. More...
 
void Blend (TreeNode *)
 Creates a union node at the top node of the BlobTree. More...
 
void Difference (TreeNode *)
 Creates a difference node at the top node of the BlobTree. More...
 
void Intersection (TreeNode *)
 Creates an intersection node at the top node of the BlobTree. More...
 
void Union (TreeNode *)
 Creates a union node at the top node of the BlobTree. More...
 
BlobTreeCenterBox ()
 Centers the BlobTree at the origin.
 
BlobTreeScaleBox ()
 Scales the BlobTree to a unit bounding box. More...
 
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. More...
 
static int Oversteps ()
 Return the number of overstep fails.
 
static TreeNodeSplineVertex (const Vector &, const double &, const Vector &, const double &, const Vector &, const double &, const Vector &, const double &, const double &, int)
 Create a spline of TreeVertex primitives. More...
 
static BlobTreeCreateCandlestick ()
 Create a candlestick.
 
static BlobTreeCreateAmphora (const double &=0.02)
 Creates an amphora. More...
 
static BlobTreeCreateVase ()
 Creates a vase.
 
static BlobTreeCreateBear ()
 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. More...
 
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. More...
 
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 BlobTreeStalactite (const Vector &, const double &, const double &)
 Create a stalactite. More...
 

Protected Attributes

double T
 Threshold value.
 
TreeNoderoot
 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

◆ BinarySearch() [1/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.

◆ BinarySearch() [2/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.

◆ Blend()

void BlobTree::Blend ( TreeNode node)

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

Parameters
nodeSub-tree 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().

◆ Center() [1/2]

Sphere BlobTree::Center ( const Box box,
int  depth 
) const
virtual

Compute the center of gravity of the BlobTree.

Parameters
boxInitial box.
depthRecursion depth.
See also
BlobTree::Center(int)

◆ Center() [2/2]

Sphere BlobTree::Center ( int  depth) const
virtual

Computes the gravity center of the BlobTree.

This function returns a sphere, the center is the center of gravity, and the radius is the volume.

Parameters
depthRecursion depth.

◆ Column()

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

Create a colum.

Parameters
typeCarvings, set to true if carvings are wanted.

◆ Copy()

BlobTree * BlobTree::Copy ( ) const
virtual

Deep copy.

Returns
Copy of the BlobTree.

◆ CreateAmphora()

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

Creates an amphora.

Parameters
thicknessThe thickness of the amphora.

◆ 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.

◆ Cut()

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

Cuts the BlobTree to simplify its structure inside a box.

Parameters
bBox.

◆ Difference()

void BlobTree::Difference ( TreeNode node)

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

Parameters
nodeSub-tree node.

◆ EmptyVoxels()

Voxel BlobTree::EmptyVoxels ( int  n) const
virtual

Step along the ray.

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

Parameters
nMaximum subdivision.

◆ GetBox()

Box BlobTree::GetBox ( ) const
virtual

Return the bounding box of the BlobTree structure.

Returns
The box.

Reimplemented from AnalyticScalarField.

◆ 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.

◆ GetRoot()

TreeNode * BlobTree::GetRoot ( ) const

Returns the root.

Returns
Root node.

◆ GetThreshold()

double BlobTree::GetThreshold ( ) const

Returns the threshold value.

Returns
Threshold value.

◆ 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.

◆ Intersection()

void BlobTree::Intersection ( TreeNode node)

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

Parameters
nodeSub-tree node.

◆ 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 ( 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() [3/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() [4/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() [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 Sphere s) const
virtual

Computes the Lipschitz constant in a sphere.

Parameters
sThe sphere.
Returns
Lipschitz constant.

Reimplemented from AnalyticScalarField.

◆ K() [7/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.

◆ Rotate()

void BlobTree::Rotate ( const Matrix r)

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

Parameters
rRotation matrix.

◆ Scale()

void BlobTree::Scale ( const Vector s)

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

Parameters
sScaling vector.

◆ 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.

◆ 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

◆ SphereTrace() [1/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

◆ SphereTrace() [2/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.

◆ SplineVertex()

TreeNode * BlobTree::SplineVertex ( const Vector a,
const double &  ra,
const Vector na,
const double &  fa,
const Vector b,
const double &  rb,
const Vector nb,
const double &  fb,
const double &  It,
int  n 
)
static

Create a spline of TreeVertex primitives.

Parameters
a,bControl points.
na,nbControl directions.
ra,rbControl radii.
fa,fbControl length of directions.
ItIntensity.
nNumber of elements.

◆ Stalactite()

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

Create a stalactite.

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

◆ Translate()

void BlobTree::Translate ( const Vector t)

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

Parameters
tTranslation vector.

◆ Union()

void BlobTree::Union ( TreeNode node)

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

Parameters
nodeSub-tree node.

◆ 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.

◆ Volume() [1/3]

double BlobTree::Volume ( const Box box,
int  depth 
) const
virtual

Compute the volume of a BlobTree object.

Parameters
boxCube where volume computations will be performed.
depthRecursion depth.

◆ Volume() [2/3]

double BlobTree::Volume ( const Box box,
int  depth,
double &  e 
) const
virtual

Compute the volume of a BlobTree object.

Parameters
boxCube where volume computations will be performed.
depthRecursion depth.
eError, i.e., amount of volume that could not be classified as inside or outside.
See also
BlobTree::Volume(const Box&,int) const

◆ Volume() [3/3]

double BlobTree::Volume ( int  depth = 5) const
virtual

Computes the volume of the BlobTree.

Create an octree subdivision of space and check the differents cells of the octree using a Lipschitz criterion to determine whether cells are inside, outside or straddling the object.

Parameters
depthRecursion depth in the creation of the octree.