Terra 1.0
TerraNode Class Reference

This class implements a generic node in the ArchesTree model. More...

#include <archestree.h>

Inheritance diagram for TerraNode:
TerraBinary TerraGrid TerraOperator TerraPrimitive TerraUnary Terra2015Replace Terra2015ReplaceAlpha Terra2015ReplaceMaxAlpha TerraAdd TerraBinaryBlend TerraHighest TerraLowest TerraReplace TerraSub TerraBlend TerraBox TerraCrater TerraCubic TerraCurveThick TerraDisc TerraDunes TerraField TerraOcean TerraQuadricCurveSet TerraVertex TerraAddNoise TerraCircleWarp TerraClampWeight TerraDiscCut TerraFrame TerraPlateau TerraScale TerraSmooth TerraTranslate TerraTwist TerraWarpNoise

Public Member Functions

 TerraNode (const Box2 &=Box2::Infinity)
 Create a node.
 
virtual Box2 GetBox () const
 Returns the bouding box of a node.
 
virtual ScalarAlpha ElevationAlpha (const Vector2 &) const
 Compute the elevation and weight.
 
virtual double Elevation (const Vector2 &) const
 Compute the elevation at a given position.
 
virtual double Alpha (const Vector2 &) const
 Compute the alpha mask at a given position.
 
virtual Vector2 Gradient (const Vector2 &) const
 Compute the gradient at a given position.
 
virtual Vector Normal (const Vector2 &) const
 Compute the normal at a given position.
 
virtual void writeJson (QJsonObject &)
 Compute the Json Document of the subtree.
 
virtual int Traversal (const Vector2 &) const
 Compute the number of nodes that are traversed when evaluating the tree.
 
virtual int Memory () const
 Compute the size of a node.
 
ScalarField2 Sample (const Array2 &) const
 Create a discrete scalar field by sampling the elevation over a given domain.
 
ScalarField2 Alpha (const Array2 &) const
 Create a discrete scalar field by sampling the elevation over a given domain.
 
void Blend (HeightField &) const
 Blend a given node with an existing terrain over an input heightfield.
 
void Add (HeightField &) const
 Add a given node with an existing heightfield.
 
virtual void Draw (QGraphicsScene &) const
 Renders the node into a QGraphicsScene.
 

Protected Attributes

Box2 box = Box2::Infinity
 Bounding box.
 

Static Protected Attributes

static const double epsilon = 1e-2
 Epsilon value for gradient computations.
 

Detailed Description

This class implements a generic node in the ArchesTree model.

The default elevation function is set to 0 and the weight to 1.

Constructor & Destructor Documentation

◆ TerraNode()

TerraNode::TerraNode ( const Box2 & box = Box2::Infinity)
explicit

Member Function Documentation

◆ Add()

void TerraNode::Add ( HeightField & h) const

Add a given node with an existing heightfield.

Parameters
hHeighfField.

References ScalarAlpha::Alpha(), box, ElevationAlpha(), and ScalarAlpha::Value().

◆ Alpha() [1/2]

ScalarField2 TerraNode::Alpha ( const Array2 & a) const

Create a discrete scalar field by sampling the elevation over a given domain.

Parameters
aDomain.

References Alpha(), Array2::ArrayVertex(), Array2::GetSizeX(), and Array2::GetSizeY().

◆ Alpha() [2/2]

double TerraNode::Alpha ( const Vector2 & p) const
virtual

Compute the alpha mask at a given position.

See also
Elevation
Parameters
pPoint.

References ScalarAlpha::Alpha(), and ElevationAlpha().

Referenced by Alpha().

◆ Blend()

void TerraNode::Blend ( HeightField & h) const

Blend a given node with an existing terrain over an input heightfield.

Let a the mask of the node, the mask of the heightfield is implicitly defined as (1-a).

Parameters
hHeighfField.

References ScalarAlpha::Alpha(), box, ElevationAlpha(), Math::Lerp(), ScalarAlpha::Value(), and Array2::VertexIntegerArea().

◆ Draw()

void TerraNode::Draw ( QGraphicsScene & scene) const
virtual

Renders the node into a QGraphicsScene.

Draws the box.

Parameters
sceneThe scene.

Reimplemented in TerraAddNoise, TerraBinary, TerraBlend, TerraCurveThick, TerraDisc, TerraOcean, TerraPlateau, and TerraVertex.

References box.

◆ Elevation()

double TerraNode::Elevation ( const Vector2 & p) const
virtual

Compute the elevation at a given position.

This is a shortcut for:

TerraNode* node; // Node
double e=node->ElevationAlpha(p).Value(); // Get elevation from ScalarAlpha
double Value() const
virtual ScalarAlpha ElevationAlpha(const Vector2 &) const
Compute the elevation and weight.
Definition terranode.cpp:83
TerraNode(const Box2 &=Box2::Infinity)
Create a node.
Definition terranode.cpp:23
Parameters
pPoint.

References ElevationAlpha(), and ScalarAlpha::Value().

Referenced by Gradient(), and Sample().

◆ ElevationAlpha()

◆ Gradient()

Vector2 TerraNode::Gradient ( const Vector2 & p) const
virtual

Compute the gradient at a given position.

Parameters
pPoint.

References Elevation(), and epsilon.

Referenced by Normal().

◆ Normal()

Vector TerraNode::Normal ( const Vector2 & p) const
virtual

Compute the normal at a given position.

See also
TerraNode::Gradient
Parameters
pPoint.

References Gradient().

◆ Sample()

ScalarField2 TerraNode::Sample ( const Array2 & a) const

Create a discrete scalar field by sampling the elevation over a given domain.

Parameters
aDomain.

References Array2::ArrayVertex(), Elevation(), Array2::GetSizeX(), and Array2::GetSizeY().

◆ Traversal()

int TerraNode::Traversal ( const Vector2 & p) const
virtual

Compute the number of nodes that are traversed when evaluating the tree.

Parameters
pPoint.

Reimplemented in TerraAddNoise, TerraBinary, TerraBlend, TerraPrimitive, and TerraUnary.