Core 1.0
Public Member Functions | Protected Attributes | List of all members
ScalarHexagonField2 Class Reference

A base two-dimensional field of real values on a hexagonal grid. More...

#include <hexagonscalarfield.h>

Inheritance diagram for ScalarHexagonField2:
HexagonArray2 Hexagon2

Public Member Functions

 ScalarHexagonField2 ()
 Empty.
 
 ScalarHexagonField2 (const ScalarField2 &)
 Create the hexagonal field. More...
 
 ScalarHexagonField2 (const ScalarField2 &, const double &)
 Create the hexagonal field. More...
 
 ScalarHexagonField2 (const Vector2 &, const double &, int, int, const double &=0.0)
 Create the field structure. More...
 
 ScalarHexagonField2 (const Vector2 &, const double &, int, int, const QVector< double > &)
 Create the field structure. More...
 
 ~ScalarHexagonField2 ()
 Empty.
 
void GetRange (double &, double &) const
 Get the range of the field. More...
 
double Integral () const
 Get the integral of the scalar field. More...
 
virtual Vector2 Gradient (int, int) const
 Compute the gradient at a given sample. More...
 
virtual double Value (int, int) const
 Return the field gradient at a given array vertex. More...
 
virtual double K () const
 Compute the Lipschitz constant of the field. More...
 
void CutEpsilon (const double &=1e-6)
 Set all values in the field that are lower than epsilon to true zero. More...
 
double at (int, int) const
 Return the field value at a given array vertex. More...
 
double at (const QPoint &) const
 Return the field value at a given array vertex. More...
 
double & operator() (int, int)
 Return the field value at a given array vertex. More...
 
double & operator() (const QPoint &)
 Return the field value at a given array vertex. More...
 
double at (int) const
 Return the data in the field. More...
 
double & operator[] (int)
 Return the data in the field. More...
 
ScalarField2 CreateScalarField () const
 Create a ScalarField2 from the hexagonal field. More...
 
ScalarField2 CreateScalarField (const Box2 &, int, int) const
 Create a ScalarField2 from the hexagonal field. More...
 
virtual double Value (const Vector2 &) const
 Get the field value with world coordinate system. More...
 
virtual double BiCubic (const Vector2 &) const
 Get the field value with world coordinate system. More...
 
void Fill (const double &)
 Sets the entire field with a constant value. More...
 
void Smooth (const Vector2 &, const double &)
 Smooth the scalar field within a given region. More...
 
void Flatten (const Vector2 &, const double &, const double &=0.25)
 Flatten the scalar field. More...
 
void Gaussian (const Vector2 &, const double &, const double &)
 Add material with gaussian distribution. More...
 
void Smooth ()
 Smooth the scalar field using a discrete gaussian kernel. More...
 
void Smooth (int)
 Applies several smoothing steps to the scalar field. More...
 
void Blur ()
 Blurs the scalar field. More...
 
void Translate (const Vector2 &)
 Translate the domain of the scalar field. More...
 
void Scale (const double &)
 Scale the domain of the scalar field. More...
 
void Normalize ()
 Normalize the values of a scalar field to unit interval. More...
 
void Clamp (const double &, const double &)
 Clamp the values of a scalar field. More...
 
void Add (const double &)
 Add a constant to the values the scalar field. More...
 
void Step (const double &, const double &)
 Perform a linear step over the values of a scalar field. More...
 
void SmoothStep (const double &, const double &, bool=false)
 Perform a smooth step over the values of a scalar field. More...
 
ScalarHexagonField2 GradientNorm () const
 Compute the gradient norm scalar field.
 
- Public Member Functions inherited from HexagonArray2
 HexagonArray2 (const Vector2 &, const double &, int, int)
 Create and array of hexagons. More...
 
 HexagonArray2 (const Box2 &, const double &)
 Create and array of hexagons embedded in a box. More...
 
bool IsEmpty () const
 Detect if the array is empty, i.e., any dimension equal to zero.
 
int GetSizeX () const
 Get the vertex size of the array for x axis.
 
int GetSizeY () const
 Get the vertex size of the array for y axis.
 
int VertexSize () const
 Return the size of the vertex array.
 
Box2 GetBox () const
 Compute the bounding box of the centroids of the hexagons. More...
 
Box2 GetHexagonBox () const
 Compute the bounding box of all the hexagons. More...
 
Vector2 CellCenter (int, int) const
 Compute the center of the hexagonal cell. More...
 
void Translate (const Vector2 &)
 Translate the array. More...
 
Vector2 ArrayVertex (int, int) const
 Compute the coordinates of a point on the grid. More...
 
constexpr bool InsideVertexIndex (int, int) const
 Check if the indexes are within range. More...
 
bool Inside (const Vector2 &) const
 Check if a point is in the rectangular domain. More...
 
Hexagon2 UnitCell () const
 Return the geometry of a generic cell. More...
 
double CellArea () const
 Return the area of a cell. More...
 
QPoint Next (int, int, int) const
 Compute the index of the neighboring hexagon. More...
 
QPoint Next (const QPoint &, int) const
 Compute the index of the neighboring hexagon. More...
 
void TriangleInteger (const Vector2 &, int &, int &, double &, double &) const
 Compute the coordinates of a vertex inside a triangle of the hexagonal grid. More...
 
QPoint TriangleInteger (const Vector2 &) const
 Compute the coordinates of a vertex inside a triangle of the hexagonal grid. More...
 
QRect VertexIntegerArea (const Box2 &) const
 Compute the integer coordinates of the vertices embedding a box. More...
 
QRect VertexIntegerArea (const Circle2 &) const
 Compute the integer coordinates of the vertices embedding a circle. More...
 
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draws the hexagon array. More...
 
void DrawCenters (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draws the centers of the hexagon grid. More...
 

Protected Attributes

QVector< double > field
 Samples.
 
- Protected Attributes inherited from HexagonArray2
int ny = 0
 Number of hexagons.
 
- Protected Attributes inherited from Hexagon2
Vector2 c = Vector2::Null
 Center.
 
double r = 1.0
 Radius.
 

Additional Inherited Members

- Protected Member Functions inherited from HexagonArray2
constexpr int VertexIndex (int, int) const
 Compute the index of a given cell. More...
 
void InverseVertexIndex (int, int &, int &) const
 Compute the coordinates of a given cell. More...
 
QPoint InverseVertexIndex (int) const
 Compute the coordinates of a given cell. More...
 
bool InsideCellIndex (int, int) const
 Check if the indexes are within range. More...
 
- Protected Member Functions inherited from Hexagon2
 Hexagon2 ()
 Empty.
 
 Hexagon2 (const Vector2 &, const double &)
 Create an hexagon. More...
 
 Hexagon2 (const double &)
 Create an hexagon. More...
 
void Translate (const Vector2 &)
 Translate a hexagon. More...
 
void Scale (const double &)
 Scale a hexagon. More...
 
double Width () const
 Width of the hexagon.
 
double Height () const
 Height of the hexagon.
 
bool Inside (const Vector2 &) const
 Test if a point is inside. More...
 
bool Intersect (const Hexagon2 &) const
 Check if two hexagons intersect. More...
 
double R (const Vector2 &) const
 Compute the squared Euclidean distance to the hexagon. More...
 
double Signed (const Vector2 &) const
 Compute the signed Euclidean distance to the hexagon. More...
 
Vector2 Normal (const Vector2 &) const
 Computes the distance vector between a hexagon and a point. More...
 
Vector2 Center () const
 Return the center of the hexagonal cell.
 
double Radius () const
 Return the radius of the hexagonal cell.
 
Vector2 Radial (int) const
 Return the radial vector of the k-th vertex. More...
 
Vector2 Edge (int) const
 Return the edge vector connecting vertexes k and k+1. More...
 
Vector2 Vertex (int) const
 Return the coordinates of the k-th vertex. More...
 
Box2 GetBox () const
 Compute the bounding box of a hexagon.
 
double Area () const
 Area of the hexagon.
 
double Perimeter () const
 Perimeter of the hexagon.
 
bool Intersect (const Circle2 &) const
 Check the intersection with a circle. More...
 
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draws an hexagon. More...
 
- Static Protected Member Functions inherited from Hexagon2
static int Sector (const Vector2 &)
 Compute the sector given an input direction. More...
 
- Static Protected Attributes inherited from HexagonArray2
static int next [6][2] = { {1,0}, {0,1}, {-1,0 }, {-1,-1}, {0,-1}, {1,-1 } }
 Array of offsets for computing neighbor indexes.
 
- Static Protected Attributes inherited from Hexagon2
static const Vector2 vertex [6]
 Array of vertices.
 
static const Vector2 normal [6]
 Array of normal vectors to the edges.
 
static const Vector2 edge [6]
 Unit edge vectors.
 
static const double Alpha = sqrt(3.0) / 2.0
 Constant sin(π/6)=√3/2.
 

Detailed Description

A base two-dimensional field of real values on a hexagonal grid.

Constructor & Destructor Documentation

◆ ScalarHexagonField2() [1/4]

ScalarHexagonField2::ScalarHexagonField2 ( const ScalarField2 s)
explicit

Create the hexagonal field.

Parameters
sScalar field.

◆ ScalarHexagonField2() [2/4]

ScalarHexagonField2::ScalarHexagonField2 ( const ScalarField2 s,
const double &  r 
)
explicit

Create the hexagonal field.

Parameters
sScalar field.
rSampling distance.

◆ ScalarHexagonField2() [3/4]

ScalarHexagonField2::ScalarHexagonField2 ( const Vector2 c,
const double &  r,
int  x,
int  y,
const double &  v = 0.0 
)
explicit

Create the field structure.

Parameters
cOrigin.
rRadius.
x,ySize of the array.
vDefault value of field.

◆ ScalarHexagonField2() [4/4]

ScalarHexagonField2::ScalarHexagonField2 ( const Vector2 c,
const double &  r,
int  x,
int  y,
const QVector< double > &  v 
)
explicit

Create the field structure.

Parameters
cOrigin.
rRadius.
x,ySize of the array.
vArray of scalar values.

Member Function Documentation

◆ Add()

void ScalarHexagonField2::Add ( const double &  c)

Add a constant to the values the scalar field.

Parameters
cConstant.

◆ at() [1/3]

double ScalarHexagonField2::at ( const QPoint &  q) const
inline

Return the field value at a given array vertex.

Parameters
qPoint.

◆ at() [2/3]

double ScalarHexagonField2::at ( int  c) const
inline

Return the data in the field.

Parameters
cIndex.

◆ at() [3/3]

double ScalarHexagonField2::at ( int  i,
int  j 
) const
inline

Return the field value at a given array vertex.

Parameters
i,jInteger coordinates of the vertex.

◆ BiCubic()

double ScalarHexagonField2::BiCubic ( const Vector2 p) const
virtual

Get the field value with world coordinate system.

This function computes a bicubic interpolation of the values, with null derivatives.

See also
Math::BiCubic
Parameters
pPoint (should be strictly within bounding box of the domain).

◆ Blur()

void ScalarHexagonField2::Blur ( )

Blurs the scalar field.

The function uses a 32 blur kernel.

◆ Clamp()

void ScalarHexagonField2::Clamp ( const double &  a,
const double &  b 
)

Clamp the values of a scalar field.

Parameters
a,bInterval.

◆ CreateScalarField() [1/2]

ScalarField2 ScalarHexagonField2::CreateScalarField ( ) const

Create a ScalarField2 from the hexagonal field.

This function comptes a rectangular domain inside the hexagonal field, sets grid size equal to the distance between the samples of the hexagonal field, and computes values at the grid points.

◆ CreateScalarField() [2/2]

ScalarField2 ScalarHexagonField2::CreateScalarField ( const Box2 box,
int  nx,
int  ny 
) const

Create a ScalarField2 from the hexagonal field.

Parameters
boxBox.
nx,nyDiscretization.

◆ CutEpsilon()

void ScalarHexagonField2::CutEpsilon ( const double &  e = 1e-6)

Set all values in the field that are lower than epsilon to true zero.

Parameters
eEpsilon coefficient.

◆ Fill()

void ScalarHexagonField2::Fill ( const double &  s)

Sets the entire field with a constant value.

Parameters
sScalar.

◆ Flatten()

void ScalarHexagonField2::Flatten ( const Vector2 center,
const double &  radius,
const double &  scaling = 0.25 
)

Flatten the scalar field.

Parameters
centerCenter.
radiusRadius.
scalingScaling of the effect.

◆ Gaussian()

void ScalarHexagonField2::Gaussian ( const Vector2 center,
const double &  radius,
const double &  height 
)

Add material with gaussian distribution.

Parameters
centerCenter of the distribution.
radiusRadius
heightMaximum height of the distribution.

◆ GetRange()

void ScalarHexagonField2::GetRange ( double &  a,
double &  b 
) const

Get the range of the field.

Parameters
a,bReturned minimum and maximum.

◆ Gradient()

Vector2 ScalarHexagonField2::Gradient ( int  i,
int  j 
) const
virtual

Compute the gradient at a given sample.

Parameters
i,jInteger coordinates of the sample.

◆ Integral()

double ScalarHexagonField2::Integral ( ) const

Get the integral of the scalar field.

Simply compute the sum of all the elements and make the product by the area of small cell element.

◆ K()

double ScalarHexagonField2::K ( ) const
virtual

Compute the Lipschitz constant of the field.

Note that this is equivalent to the following code, with the difference that this function does not store the norm of the gradient in memory.

double k=0.0;
for (int i=0;i<f.VertexSize();i++)
{
k=Math::Max(k,f.at(i));
}
static double Max(const double &, const double &)
Maximum of two reals.
Definition: mathematics.h:630
A base two-dimensional field of real values on a hexagonal grid.
Definition: hexagonscalarfield.h:12
ScalarHexagonField2 GradientNorm() const
Compute the gradient norm scalar field.
Definition: hexagonscalarfield2.cpp:525

◆ Normalize()

void ScalarHexagonField2::Normalize ( )

Normalize the values of a scalar field to unit interval.

Compute range and apply transformation.

◆ operator()() [1/2]

double & ScalarHexagonField2::operator() ( const QPoint &  q)
inline

Return the field value at a given array vertex.

Parameters
qPoint.

◆ operator()() [2/2]

double & ScalarHexagonField2::operator() ( int  i,
int  j 
)
inline

Return the field value at a given array vertex.

Parameters
i,jInteger coordinates of the vertex.

◆ operator[]()

double & ScalarHexagonField2::operator[] ( int  c)
inline

Return the data in the field.

Parameters
cIndex.

◆ Scale()

void ScalarHexagonField2::Scale ( const double &  s)

Scale the domain of the scalar field.

Parameters
sScaling factor.

◆ Smooth() [1/3]

void ScalarHexagonField2::Smooth ( )

Smooth the scalar field using a discrete gaussian kernel.

The function uses a 32 approximation of the Gaussian kernel.

◆ Smooth() [2/3]

void ScalarHexagonField2::Smooth ( const Vector2 center,
const double &  r 
)

Smooth the scalar field within a given region.

The smoothing is performed with the cubic falloff function Cubic::Smooth(const double&,const double&)

Parameters
centerCenter.
rRadius.

◆ Smooth() [3/3]

void ScalarHexagonField2::Smooth ( int  n)

Applies several smoothing steps to the scalar field.

See also
Smooth()
Parameters
nNumber of smoothing steps.

◆ SmoothStep()

void ScalarHexagonField2::SmoothStep ( const double &  a,
const double &  b,
bool  s = false 
)

Perform a smooth step over the values of a scalar field.

Either the function Cubic::Step() or Quintic::Step() is applied to all the values of the field.

See also
Linear::Step(), Quintic::Step()
Parameters
a,bInterval.
sSmoothing boolean value, apply a quintic smoothing kernel if set to true.

◆ Step()

void ScalarHexagonField2::Step ( const double &  a,
const double &  b 
)

Perform a linear step over the values of a scalar field.

The function Linear::Step() is applied to all the values of the field.

See also
Linear::Step
Parameters
a,bInterval.

◆ Translate()

void ScalarHexagonField2::Translate ( const Vector2 t)

Translate the domain of the scalar field.

Parameters
tTranslation vector.

◆ Value() [1/2]

double ScalarHexagonField2::Value ( const Vector2 p) const
virtual

Get the field value with world coordinate system.

This function computes a triangle interpolation of the values.

Parameters
pPoint position (should be strictly inside the box domain).

◆ Value() [2/2]

double ScalarHexagonField2::Value ( int  i,
int  j 
) const
virtual

Return the field gradient at a given array vertex.

Parameters
i,jInteger coordinates of the vertex.
See also
at(int,int)