Terra 1.0
Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
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 TerraLowest TerraReplace TerraSub TerraBlend TerraUnion TerraCrater TerraCubic TerraCurveThick TerraDunes TerraImages TerraSkeleton TerraAddMusgrave TerraCircleWarp TerraClampWeight TerraDiscCut TerraPlateau TerraRotate TerraScale TerraSmooth TerraTransform TerraTranslate TerraTwist TerraWarpNoise

Public Member Functions

 TerraNode (const Box2 &=Box2::Infinity)
 Create a node. More...
 
virtual Box2 GetBox () const
 Returns the bouding box of a node.
 
virtual ScalarAlpha ElevationAlpha (const Vector2 &) const
 Compute the elevation and weight. More...
 
virtual double Elevation (const Vector2 &) const
 Compute the elevation at a given position. More...
 
virtual double Alpha (const Vector2 &) const
 Compute the alpha mask at a given position. More...
 
virtual Vector2 Gradient (const Vector2 &) const
 Compute the gradient at a given position. More...
 
virtual Vector Normal (const Vector2 &) const
 Compute the normal at a given position. More...
 
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. More...
 
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. More...
 
ScalarField2 Alpha (const Array2 &) const
 Create a discrete scalar field by sampling the elevation over a given domain. More...
 
void Blend (HeightField &) const
 Blend a given node with an existing terrain over an input heightfield. More...
 
void Add (HeightField &) const
 Add a given node with an existing heightfield. More...
 
virtual void Draw (QGraphicsScene &) const
 Renders the node into a QGraphicsScene. More...
 

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

Create a node.

Parameters
boxThe box.

Referenced by Memory().

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(), and ScalarAlpha::Value().

◆ Draw()

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

Renders the node into a QGraphicsScene.

Draws the box.

Parameters
sceneThe scene.

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

References box, and Box2::Draw().

Referenced by TerraBinary::Draw(), and TerraAddMusgrave::Draw().

◆ 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
This class implements a generic node in the ArchesTree model.
Definition: archestree.h:70
virtual ScalarAlpha ElevationAlpha(const Vector2 &) const
Compute the elevation and weight.
Definition: terranode.cpp:83
Parameters
pPoint.

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

Referenced by Gradient(), ArchesTree::Intersect(), and Sample().

◆ ElevationAlpha()

ScalarAlpha TerraNode::ElevationAlpha ( const Vector2 ) const
virtual

Compute the elevation and weight.

Parameters
pPoint.

Reimplemented in TerraRotate, TerraTransform, TerraDunes, TerraGrid, TerraBlend, TerraBlendGrid, TerraUnion, TerraLowest, TerraAdd, TerraSub, TerraReplace, TerraBinaryBlend, Terra2015Replace, TerraPlateau, TerraVertex, TerraDisc, TerraVertexSlope, Terra2013VertexSlopeNoise, TerraVertexNoise, TerraDiscNoise, TerraVertexNoiseRydge, TerraVertexFractal, TerraBox, TerraBoxImage, TerraVertexImage, TerraQuadrangleImage, TerraCubic, TerraCrater, TerraCubicImage, TerraScale, TerraDiscCut, TerraClampWeight, TerraTranslate, TerraWarpNoise, TerraTwist, TerraCircleWarp, Terra2015ReplaceAlpha, Terra2015ReplaceMaxAlpha, TerraSmooth, TerraCurveThick, TerraAddMusgrave, TerraOcean, TerraUnary, TerraOperator, and TerraImages.

Referenced by Add(), Alpha(), Blend(), ArchesTree::CreateLayerStack(), ArchesTree::dichotomie(), Elevation(), TerraRotate::ElevationAlpha(), TerraTransform::ElevationAlpha(), TerraGrid::ElevationAlpha(), TerraLowest::ElevationAlpha(), TerraAdd::ElevationAlpha(), TerraSub::ElevationAlpha(), TerraReplace::ElevationAlpha(), TerraBinaryBlend::ElevationAlpha(), Terra2015Replace::ElevationAlpha(), TerraPlateau::ElevationAlpha(), TerraScale::ElevationAlpha(), TerraDiscCut::ElevationAlpha(), TerraClampWeight::ElevationAlpha(), TerraTranslate::ElevationAlpha(), TerraWarpNoise::ElevationAlpha(), TerraTwist::ElevationAlpha(), TerraCircleWarp::ElevationAlpha(), Terra2015ReplaceAlpha::ElevationAlpha(), Terra2015ReplaceMaxAlpha::ElevationAlpha(), TerraSmooth::ElevationAlpha(), TerraAddMusgrave::ElevationAlpha(), ArchesTree::GetBedrock(), ArchesTree::GetFoam(), ArchesTree::GetSand(), ArchesTree::GetTriangles(), and ArchesTree::GetWater().

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

Referenced by ArchesTree::CreateMesh().

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

Referenced by ArchesTree::HeightFieldRock(), ArchesTree::HeightFieldSand(), and ArchesTree::HeightFieldWater().

◆ 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 TerraBinary, TerraUnary, TerraPrimitive, TerraBlend, and TerraAddMusgrave.

Referenced by ArchesTree::Traversal(), TerraBinary::Traversal(), TerraUnary::Traversal(), and TerraAddMusgrave::Traversal().