3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
ValuesField Class Reference

The class to operate over the 2D fields. More...

#include <ValuesField.h>

Public Member Functions

 ValuesField (const ValuesField &vf, int x=0, int y=0, int w=0, int h=0)
 construct the field from the other cropped field
 
void create (int SizeX, int SiezY, int depth=1, FieldClamp clampmode=fcWrap)
 Create the field.
 
void createMips ()
 create the mipmaps, decreasing twice with each level until it is possible
 
void setClampMode (FieldClamp cl)
 set the field clamp mode - how it acts beyond the boundaries
 
int width () const
 get width
 
int height () const
 get height
 
int depth () const
 Get amount of channels.
 
void createFromImage (const comms::cImage &im)
 create the field form the image
 
void createFromImageMono (const comms::cImage &im, Vector3D mask=Vector3D::Zero)
 create the monochromatic field from the image (1 channel)
 
void toImage (comms::cImage &im)
 convert the field to the image
 
void loadImage (const char *name)
 read the image directly from the file
 
void saveImage (const char *name)
 save the field directly to file
 
void clear ()
 clear rthe field
 
bool torange (int &x, int &y) const
 converts the (x,y) to range [0..Lx-1, 0..Ly-1]
 
void set (float value, int x, int y, int channel=0)
 set teh value to the field
 
void add (float value, int x, int y, int channel=0)
 add the value to the field
 
float get (int x, int y, int channel=0) const
 get the value of the field by the integer coordinates
 
float & value (int x, int y, int channel=0)
 get the value reference of the field by the integer coordinates
 
Vector3D & getV3 (int x, int y)
 get the reference to the values as 3d - vector. It has sense only if there are at least 3 channels
 
Vector3D getV3 (int x, int y) const
 
Vector4D & getV4 (int x, int y)
 get the reference to the values as 4d - vector. It has sense only if there are at least 4 channels
 
Vector4D getV4 (int x, int y) const
 
cVec2getV2 (int x, int y)
 get the reference to the values as 2d - vector. It has sense only if there are at least 2 channels
 
cVec2 getV2 (int x, int y) const
 
float get_linear (float x, float y, int channel=0) const
 get the linearly interpolated value
 
float get_linear_mip (float x, float y, int channel, float mip_level) const
 get the linearly interpolated value using the mipmaps
 
cVec2 get_linearV2 (float x, float y) const
 get the linearly interpolated value as 2d-vector
 
cVec2 get_linearV2_mip (float x, float y, float mip_level) const
 get the linearly interpolated value as 2d-vector using the mipmaps
 
cVec3 get_linearV3 (float x, float y) const
 get the linearly interpolated value as 3d-vector
 
cVec3 get_linearV3_mip (float x, float y, float mip_level) const
 get the linearly interpolated value as 3d-vector using the mipmaps
 
cVec4 get_linearV4 (float x, float y) const
 get the linearly interpolated value as 4d-vector
 
cVec4 get_linearV4_mip (float x, float y, float mip_level) const
 get the linearly interpolated value as 4d-vector using the mipmaps
 
float get_bicubic (float x, float y, int channel=0) const
 get the bicubic interpolated value
 
float get_bicubic_mip (float x, float y, int channel, float mip_level) const
 get the bicubic interpolated value using the mipmaps
 
cVec2 get_bicubicV2 (float x, float y) const
 get the bicubic interpolated value as the 2d-vector
 
cVec2 get_bicubicV2_mip (float x, float y, float mip_level) const
 get the bicubic interpolated value as the 2d-vector using the mipmaps
 
cVec3 get_bicubicV3 (float x, float y) const
 get the bicubic interpolated value as the 3d-vector
 
cVec3 get_bicubicV3_mip (float x, float y, float mip_level) const
 get the bicubic interpolated value as the 3d-vector using the mipmaps
 
cVec4 get_bicubicV4 (float x, float y) const
 get the bicubic interpolated value as the 4d-vector
 
cVec4 get_bicubicV4_mip (float x, float y, float mip_level) const
 get the bicubic interpolated value as the 4d-vector using the mipmaps
 
void resizeTo (ValuesField &dest)
 resize the field to other size using the bicubic interpolation
 
void sharp2X (ValuesField &dest)
 Experimental: Increase the image 2X and sharpen.
 
void sharpEdges2X (ValuesField &dest)
 Experimental: Increase the image 2X and sharpen (sharpening edges so that edge width will be kept despite on the image size increasing)
 
void sharpEdges2X1 (ValuesField &dest)
 Experimental, variation of the previous function: Increase the image 2X and sharpen (sharpening edges so that edge width will be kept despite on the image size increasing)
 
void sharpResize (ValuesField &dest, float scale)
 resize to bigger size keeping the edges sharpness
 
void relax (ValuesField &destination, float degree, float radius)
 relax the field
 
void relax (ValuesField &destination, float degree, float radius, int x0, int y0, int x1, int y1)
 
void sharpen (ValuesField &destination, float degree, float radius)
 sharpen the field
 
void monoTo (ValuesField &dest)
 convert multiple channels to one as an average-arithmetic
 
void curvature (ValuesField &dest)
 calculate the curvature of the 2d-field
 
void curvatureDir (ValuesField &dest)
 calculate the curvature principal directions
 
void normalmap (ValuesField &dest, int byChannel=0)
 calculate the normalmap
 
void normalmap3 (ValuesField &dest, float heightmod=1.0, int channel=0)
 calculate the normalmap as the 3d-vectors set
 
void gradientValue (ValuesField &dest)
 calculate the gradient length
 
void perlinMap (ValuesField &dest)
 
void detectAnisotropy (ValuesField &dest)
 
float detectPerlin (int x, int y, int channel)
 
void operator-= (const ValuesField &field)
 subtract field from the current
 
void operator+= (const ValuesField &field)
 add field to the current
 
void operator+= (float value)
 add the constant value to the field
 
void operator-= (float value)
 subtract the value from the field
 
void operator*= (float value)
 multiply on the constant
 
void operator/= (float value)
 divide on the constant
 
void operate (const std::function< void(int, int) > &f, bool multithread=true)
 operate over the field with the lambda
 
void max (ValuesField &other)
 calculated the maximum of two fields into hte current
 
void swap (ValuesField &dest)
 swap two fields (dimensions may be different)
 
void LaplacianInterpolate (const cList< Vector3D > &lines)
 Interpolates the whole field so that it is maximally smooth (laplacian value minimized) and gets the given values at the each line provided, so that field_value(point.x,point.y) = point.z. This is heavy function, be careful with the timing. But it produces absolutely clean and smooth field.
 
void LaplacianInterpolate (const UnlimitedBitset &fixed)
 Interpolates the whole field so that it is maximally smooth (laplacian value minimized) and keeps the grid value at each locked point. This is heavy function, be careful with the timing. But it produces absolutely clean and smooth field.
 
void NormalizeColors (bool monochromatic=false, int mipsize=64)
 Normalize the texture to be (128, 128, 128) in average using the mip-mapping algorithm.
 
comms::cVec3 averageColor (int x=0, int y=0, int w=0, int h=0, float alpha_threshold=200) const
 get the average color of the texture piece
 
void Decrease2X (ValuesField &dest)
 Decrease the field 2X times.
 
void toPower2 (ValuesField &dest)
 resize to the closest power of 2 (may increase, may decrease the size, we choose what is arithmetically closer)
 
void recoverBump (ValuesField &dest)
 recover the bump from the color/greyscale (heuristic)
 
comms::cBounds blendImage (const ValuesField &other, const cMat3 &transform, const cVec4 &modulator=cVec4::One)
 blend the image with the other image
 
comms::cBounds blendImageM4 (const ValuesField &other, const comms::cMat4 &transform, const cVec4 &modulator=cVec4::One)
 blend the image with the other image using the 4x4 matrix transformation
 
void rect (int x0, int y0, int x1, int y1, const cVec4 &color)
 draw the filled rectangle
 
void calc_featuremap (ValuesField &dest, int radius)
 
void local_normalisation (ValuesField &dest, int size)
 
void find_local_minmax (std::vector< comms::cVec2 > &minmax)
 
void getEllipse (int x, int y, cVec2 &center, cVec2 &longer_axis, float &relation)
 

Detailed Description

The class to operate over the 2D fields.

Constructor & Destructor Documentation

◆ ValuesField()

ValuesField::ValuesField ( const ValuesField & vf,
int x = 0,
int y = 0,
int w = 0,
int h = 0 )

construct the field from the other cropped field

Parameters
vfthe field to copy
xthe x-coordinate of the left-top corner (of the vf)
ythe y-coordinate of the left-top corner (of the vf)
wthe width of the field, if zero the whole field will be copied (shifted on x)
hthe height of the field, if zero the whole field will be copied (shifted on y)

Member Function Documentation

◆ add()

void ValuesField::add ( float value,
int x,
int y,
int channel = 0 )

add the value to the field

Parameters
valuethe value to add
xx-coordinate
yy-coordinate
channelthe channel

◆ averageColor()

comms::cVec3 ValuesField::averageColor ( int x = 0,
int y = 0,
int w = 0,
int h = 0,
float alpha_threshold = 200 ) const

get the average color of the texture piece

Parameters
xthe x-coordinate of the piece
ythe y-coordinate of the piece
wthe width of the piece, iw w == 0, the whole texture width is taken
hthe height of the piece, if h == 0, the whole texture height is taken
alpha_thresholdthe threshold for the alpha channel (if exists)
Returns
the average color, taken only the color of pixels with alpha > alpha_threshold

◆ blendImage()

comms::cBounds ValuesField::blendImage ( const ValuesField & other,
const cMat3 & transform,
const cVec4 & modulator = cVec4::One )

blend the image with the other image

Parameters
otherthe other image to blend with this image, it should be of the 4-channels in depth (color + alpha)
transformthe transformation matrix applied to the other image
modulatorthe color/alpha modulator

◆ blendImageM4()

comms::cBounds ValuesField::blendImageM4 ( const ValuesField & other,
const comms::cMat4 & transform,
const cVec4 & modulator = cVec4::One )

blend the image with the other image using the 4x4 matrix transformation

Parameters
otherthe other image to blend with this image, it should be of the 4-channels in depth (color + alpha)
transformthe transformation matrix applied to the other image
modulatorthe color/alpha modulator
Returns
the bounds of the blended image

◆ create()

void ValuesField::create ( int SizeX,
int SiezY,
int depth = 1,
FieldClamp clampmode = fcWrap )

Create the field.

Parameters
SizeXwidth
SiezYheight
depthchannels count
clampmodeclamp mode

◆ createFromImage()

void ValuesField::createFromImage ( const comms::cImage & im)

create the field form the image

Parameters
imthe image to be converted to the float field

◆ createFromImageMono()

void ValuesField::createFromImageMono ( const comms::cImage & im,
Vector3D mask = Vector3D::Zero )

create the monochromatic field from the image (1 channel)

Parameters
imthe image, if it is RGB, the channels will be merged to greyscale
maskthe mask to blend rgb - channels, if zero - the default rgb mask will be used

◆ curvature()

void ValuesField::curvature ( ValuesField & dest)

calculate the curvature of the 2d-field

Parameters
destthe destination field (1 channel)

◆ curvatureDir()

void ValuesField::curvatureDir ( ValuesField & dest)

calculate the curvature principal directions

Parameters
destthe destination field (3channels)

◆ Decrease2X()

void ValuesField::Decrease2X ( ValuesField & dest)

Decrease the field 2X times.

Parameters
destthe destination field

◆ depth()

int ValuesField::depth ( ) const
inline

Get amount of channels.

Returns
channels count

◆ get()

float ValuesField::get ( int x,
int y,
int channel = 0 ) const

get the value of the field by the integer coordinates

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the value of the field

◆ get_bicubic()

float ValuesField::get_bicubic ( float x,
float y,
int channel = 0 ) const

get the bicubic interpolated value

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated value

◆ get_bicubic_mip()

float ValuesField::get_bicubic_mip ( float x,
float y,
int channel,
float mip_level ) const

get the bicubic interpolated value using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
channelthe channel
mip_levelthe mip level
Returns
the interpolated value

◆ get_bicubicV2()

cVec2 ValuesField::get_bicubicV2 ( float x,
float y ) const

get the bicubic interpolated value as the 2d-vector

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated value

◆ get_bicubicV2_mip()

cVec2 ValuesField::get_bicubicV2_mip ( float x,
float y,
float mip_level ) const

get the bicubic interpolated value as the 2d-vector using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
mip_levelthe mip level
Returns
the interpolated value

◆ get_bicubicV3()

cVec3 ValuesField::get_bicubicV3 ( float x,
float y ) const

get the bicubic interpolated value as the 3d-vector

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated value

◆ get_bicubicV3_mip()

cVec3 ValuesField::get_bicubicV3_mip ( float x,
float y,
float mip_level ) const

get the bicubic interpolated value as the 3d-vector using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
mip_levelthe mip level
Returns
the interpolated value

◆ get_bicubicV4()

cVec4 ValuesField::get_bicubicV4 ( float x,
float y ) const

get the bicubic interpolated value as the 4d-vector

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated value

◆ get_bicubicV4_mip()

cVec4 ValuesField::get_bicubicV4_mip ( float x,
float y,
float mip_level ) const

get the bicubic interpolated value as the 4d-vector using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
mip_levelthe mip level
Returns
the interpolated value

◆ get_linear()

float ValuesField::get_linear ( float x,
float y,
int channel = 0 ) const

get the linearly interpolated value

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated value reference

◆ get_linear_mip()

float ValuesField::get_linear_mip ( float x,
float y,
int channel,
float mip_level ) const

get the linearly interpolated value using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
channelthe channel
mip_levelthe mip level
Returns
the interpolated value

◆ get_linearV2()

cVec2 ValuesField::get_linearV2 ( float x,
float y ) const

get the linearly interpolated value as 2d-vector

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated 2d-value

◆ get_linearV2_mip()

cVec2 ValuesField::get_linearV2_mip ( float x,
float y,
float mip_level ) const

get the linearly interpolated value as 2d-vector using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
mip_levelthe mip level
Returns
the interpolated value

◆ get_linearV3()

cVec3 ValuesField::get_linearV3 ( float x,
float y ) const

get the linearly interpolated value as 3d-vector

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated 2d-value

◆ get_linearV3_mip()

cVec3 ValuesField::get_linearV3_mip ( float x,
float y,
float mip_level ) const

get the linearly interpolated value as 3d-vector using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
mip_levelthe mip level
Returns
the interpolated value

◆ get_linearV4()

cVec4 ValuesField::get_linearV4 ( float x,
float y ) const

get the linearly interpolated value as 4d-vector

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the interpolated 2d-value

◆ get_linearV4_mip()

cVec4 ValuesField::get_linearV4_mip ( float x,
float y,
float mip_level ) const

get the linearly interpolated value as 4d-vector using the mipmaps

Parameters
xthe x-coordinate
ythe y-coordinate
mip_levelthe mip level
Returns
the interpolated value (assuming that w is the alpha channel)

◆ getV2()

cVec2 & ValuesField::getV2 ( int x,
int y )

get the reference to the values as 2d - vector. It has sense only if there are at least 2 channels

Parameters
xx-coordinate
yy-coordinate
Returns
the reference to the vector

◆ getV3()

Vector3D & ValuesField::getV3 ( int x,
int y )

get the reference to the values as 3d - vector. It has sense only if there are at least 3 channels

Parameters
xx-coordinate
yy-coordinate
Returns
the reference to the vector

◆ getV4()

Vector4D & ValuesField::getV4 ( int x,
int y )

get the reference to the values as 4d - vector. It has sense only if there are at least 4 channels

Parameters
xx-coordinate
yy-coordinate
Returns
the reference to the 4d-vector

◆ gradientValue()

void ValuesField::gradientValue ( ValuesField & dest)

calculate the gradient length

Parameters
destthe 1d field

◆ height()

int ValuesField::height ( ) const
inline

get height

Returns
height of the field

◆ LaplacianInterpolate() [1/2]

void ValuesField::LaplacianInterpolate ( const cList< Vector3D > & lines)

Interpolates the whole field so that it is maximally smooth (laplacian value minimized) and gets the given values at the each line provided, so that field_value(point.x,point.y) = point.z. This is heavy function, be careful with the timing. But it produces absolutely clean and smooth field.

Parameters
linesthe pairs of points that define the field, x,y of each point may be not integer, the count of points should be even

◆ LaplacianInterpolate() [2/2]

void ValuesField::LaplacianInterpolate ( const UnlimitedBitset & fixed)

Interpolates the whole field so that it is maximally smooth (laplacian value minimized) and keeps the grid value at each locked point. This is heavy function, be careful with the timing. But it produces absolutely clean and smooth field.

Parameters
fixedThe fixel points falgs, fixed.get(x+y*width) == true means that point is fixed

◆ loadImage()

void ValuesField::loadImage ( const char * name)

read the image directly from the file

Parameters
namethe filename

◆ max()

void ValuesField::max ( ValuesField & other)

calculated the maximum of two fields into hte current

Parameters
otherthe other field

◆ monoTo()

void ValuesField::monoTo ( ValuesField & dest)

convert multiple channels to one as an average-arithmetic

Parameters
dest

◆ NormalizeColors()

void ValuesField::NormalizeColors ( bool monochromatic = false,
int mipsize = 64 )

Normalize the texture to be (128, 128, 128) in average using the mip-mapping algorithm.

Parameters
monochromaticset true to change the brightness only
mipsizethe mip-map size to be used to normalize the color

◆ normalmap()

void ValuesField::normalmap ( ValuesField & dest,
int byChannel = 0 )

calculate the normalmap

Parameters
destthe destination field (2 channels, only dx and dy will be written)
byChannelthe channel to be used as the depth source

◆ normalmap3()

void ValuesField::normalmap3 ( ValuesField & dest,
float heightmod = 1.0,
int channel = 0 )

calculate the normalmap as the 3d-vectors set

Parameters
destthe destination 3d-field
heightmodthe modulator for the heightmap
channelthe channel to be used as the depth source

◆ operate()

void ValuesField::operate ( const std::function< void(int, int) > & f,
bool multithread = true )

operate over the field with the lambda

Parameters
fthe lambda

◆ operator*=()

void ValuesField::operator*= ( float value)

multiply on the constant

Parameters
valuethe multiplicator

◆ operator+=() [1/2]

void ValuesField::operator+= ( const ValuesField & field)

add field to the current

Parameters
fieldthe field to add (same dimensions)

◆ operator+=() [2/2]

void ValuesField::operator+= ( float value)

add the constant value to the field

Parameters
valuethe value to add

◆ operator-=() [1/2]

void ValuesField::operator-= ( const ValuesField & field)

subtract field from the current

Parameters
fieldthe subtracted field, same dimensions required

◆ operator-=() [2/2]

void ValuesField::operator-= ( float value)

subtract the value from the field

Parameters
valuethe value to subtract

◆ operator/=()

void ValuesField::operator/= ( float value)

divide on the constant

Parameters
valuethe divider

◆ recoverBump()

void ValuesField::recoverBump ( ValuesField & dest)

recover the bump from the color/greyscale (heuristic)

Parameters
destthe destination depthmap

◆ rect()

void ValuesField::rect ( int x0,
int y0,
int x1,
int y1,
const cVec4 & color )

draw the filled rectangle

Parameters
x0the left-top corner x
y0the left-top corner y
x1the right-bottom corner x
y1the right-bottom corner y
colorthe color of the rectangle (r, g, b a), all values are in [0..255]

◆ relax()

void ValuesField::relax ( ValuesField & destination,
float degree,
float radius )

relax the field

Parameters
destinationthe destination field. It is recommended to use swap for multiple relax steps
degreethe degree of the relaxation
radiusthe radius of the kernel

◆ resizeTo()

void ValuesField::resizeTo ( ValuesField & dest)

resize the field to other size using the bicubic interpolation

Parameters
destthe destination field

◆ saveImage()

void ValuesField::saveImage ( const char * name)

save the field directly to file

Parameters
namethe filename

◆ set()

void ValuesField::set ( float value,
int x,
int y,
int channel = 0 )

set teh value to the field

Parameters
valuethe value to set
xx-coordinate
yy-coordinate
channelthe channel

◆ setClampMode()

void ValuesField::setClampMode ( FieldClamp cl)

set the field clamp mode - how it acts beyond the boundaries

Parameters
clthe clamp mode - fcWrap, fcClamp or fcZero

◆ sharp2X()

void ValuesField::sharp2X ( ValuesField & dest)

Experimental: Increase the image 2X and sharpen.

Parameters
destthe destination, should be empty

◆ sharpEdges2X()

void ValuesField::sharpEdges2X ( ValuesField & dest)

Experimental: Increase the image 2X and sharpen (sharpening edges so that edge width will be kept despite on the image size increasing)

Parameters
destthe destination, should be empty

◆ sharpEdges2X1()

void ValuesField::sharpEdges2X1 ( ValuesField & dest)

Experimental, variation of the previous function: Increase the image 2X and sharpen (sharpening edges so that edge width will be kept despite on the image size increasing)

Parameters
destthe destination, should be empty

◆ sharpen()

void ValuesField::sharpen ( ValuesField & destination,
float degree,
float radius )

sharpen the field

Parameters
destinationthe destination field. It is recommended to use swap for multiple relax steps
degreethe degree of the relaxation
radiusthe radius of the kernel

◆ sharpResize()

void ValuesField::sharpResize ( ValuesField & dest,
float scale )

resize to bigger size keeping the edges sharpness

Parameters
destdestination image
scalethe scale > 1

◆ swap()

void ValuesField::swap ( ValuesField & dest)

swap two fields (dimensions may be different)

Parameters
destthe other field

◆ toImage()

void ValuesField::toImage ( comms::cImage & im)

convert the field to the image

Parameters
imdestination image, values should be 0..255 fro 3 or 4 cannels field, if there is 1 channel, the values will be scaled from minimum to maximum in range 0..255

◆ toPower2()

void ValuesField::toPower2 ( ValuesField & dest)

resize to the closest power of 2 (may increase, may decrease the size, we choose what is arithmetically closer)

Parameters
destthe destination

◆ torange()

bool ValuesField::torange ( int & x,
int & y ) const

converts the (x,y) to range [0..Lx-1, 0..Ly-1]

Parameters
xx-coordinate
yy-coordinate
Returns
true if succeed and wrapping happened

◆ value()

float & ValuesField::value ( int x,
int y,
int channel = 0 )

get the value reference of the field by the integer coordinates

Parameters
xx-coordinate
yy-coordinate
channelthe channel
Returns
the value of the field

◆ width()

int ValuesField::width ( ) const
inline

get width

Returns
width of the field

The documentation for this class was generated from the following file: