3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
ValuesField.h
1#pragma once
2enum FieldClamp {
3 fcWrap = 0,
4 fcClamp=1,
5 fcZero=2
6};
7
11class APICALL ValuesField {
12 int Lx, Ly, Depth;
13 cList<float> values;
14 FieldClamp clamp;
16public:
19
28 ValuesField(const ValuesField& vf, int x = 0, int y = 0, int w = 0, int h = 0);
29
37 void create(int SizeX, int SiezY, int depth = 1, FieldClamp clampmode = fcWrap);
38
42 void createMips();
43
48 void setClampMode(FieldClamp cl);
49
54 int width() const ;
55
60 int height() const ;
61
66 int depth() const ;
67
72 void createFromImage(const comms::cImage& im);
73
79 void createFromImageMono(const comms::cImage& im, Vector3D mask = Vector3D::Zero);
80
85 void toImage(comms::cImage& im);
86
91 void loadImage(const char* name);
92
97 void saveImage(const char* name);
98
102 void clear();
103
110 bool torange(int& x, int& y) const;
111
119 void set(float value, int x, int y, int channel = 0);
120
128 void add(float value, int x, int y, int channel = 0);
129
137 float get(int x, int y, int channel = 0) const ;
138
146 float& value(int x, int y, int channel = 0);
147
154 Vector3D& getV3(int x, int y);
155 Vector3D getV3(int x, int y) const;
156
163 Vector4D& getV4(int x, int y);
164 Vector4D getV4(int x, int y) const;
165
172 cVec2& getV2(int x, int y);
173 cVec2 getV2(int x, int y) const;
174
182 float get_linear(float x, float y, int channel = 0) const ;
183
192 float get_linear_mip(float x, float y, int channel, float mip_level) const;
193
201 cVec2 get_linearV2(float x, float y) const;
202
210 cVec2 get_linearV2_mip(float x, float y, float mip_level) const;
211
219 cVec3 get_linearV3(float x, float y) const;
220
228 cVec3 get_linearV3_mip(float x, float y, float mip_level) const;
229
237 cVec4 get_linearV4(float x, float y) const;
238
246 cVec4 get_linearV4_mip(float x, float y, float mip_level) const;
247
255 float get_bicubic(float x, float y, int channel = 0) const ;
256
265 float get_bicubic_mip(float x, float y, int channel, float mip_level) const;
266
274 cVec2 get_bicubicV2(float x, float y) const;
275
283 cVec2 get_bicubicV2_mip(float x, float y, float mip_level) const;
284
292 cVec3 get_bicubicV3(float x, float y) const;
293
301 cVec3 get_bicubicV3_mip(float x, float y, float mip_level) const;
302
310 cVec4 get_bicubicV4(float x, float y) const;
311
319 cVec4 get_bicubicV4_mip(float x, float y, float mip_level) const;
320
326
331 void sharp2X(ValuesField& dest);
332
338
344
350 void sharpResize(ValuesField& dest, float scale);
351
358 void relax(ValuesField& destination, float degree, float radius);
359 void relax(ValuesField& destination, float degree, float radius, int x0, int y0, int x1, int y1);
360
361
368 void sharpen(ValuesField& destination, float degree, float radius);
369
374 void monoTo(ValuesField& dest);
375
381
387
393 void normalmap(ValuesField& dest, int byChannel = 0);
394
401 void normalmap3(ValuesField& dest, float heightmod = 1.0, int channel = 0);
402
408
409 //experimental functions...
410 void perlinMap(ValuesField& dest);
411 void detectAnisotropy(ValuesField& dest);
412 float detectPerlin(int x, int y, int channel);
413
418 void operator -= (const ValuesField& field);
419
424 void operator += (const ValuesField& field);
425
430 void operator += (float value);
431
436 void operator -= (float value);
437
442 void operator *= (float value);
443
448 void operator /= (float value);
449
454 void operate(const std::function<void(int, int) >& f, bool multithread = true);
455
460 void max(ValuesField& other);
461
466 void swap(ValuesField& dest);
467
474
480 void LaplacianInterpolate(const UnlimitedBitset& fixed);
481
487 void NormalizeColors(bool monochromatic = false, int mipsize = 64);
488
498 comms::cVec3 averageColor(int x = 0, int y = 0, int w = 0, int h = 0, float alpha_threshold = 200) const;
499
505
511
517
524 comms::cBounds blendImage(const ValuesField& other, const cMat3& transform, const cVec4& modulator = cVec4::One);
525
533 comms::cBounds blendImageM4(const ValuesField& other, const comms::cMat4& transform, const cVec4& modulator = cVec4::One);
534
543 void rect(int x0, int y0, int x1, int y1, const cVec4& color);
544
545 void calc_featuremap(ValuesField& dest, int radius);
546
547 void local_normalisation(ValuesField& dest, int size);
548
549 void find_local_minmax(std::vector<comms::cVec2>& minmax);
550
551 void getEllipse(int x, int y, cVec2& center, cVec2& longer_axis, float& relation);
552};
553
554inline int ValuesField::width() const {
555 return Lx;
556}
557
558inline int ValuesField::height() const {
559 return Ly;
560}
561
562inline int ValuesField::depth() const {
563 return Depth;
564}
565
The class to operate over the 2D fields.
Definition ValuesField.h:11
void relax(ValuesField &destination, float degree, float radius)
relax the field
float get_bicubic(float x, float y, int channel=0) const
get the bicubic interpolated value
cVec2 get_linearV2(float x, float y) const
get the linearly interpolated value as 2d-vector
comms::cBounds blendImage(const ValuesField &other, const cMat3 &transform, const cVec4 &modulator=cVec4::One)
blend the image with the other image
void sharpen(ValuesField &destination, float degree, float radius)
sharpen the field
void sharp2X(ValuesField &dest)
Experimental: Increase the image 2X and sharpen.
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 toImage(comms::cImage &im)
convert the field to the image
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
void LaplacianInterpolate(const cList< Vector3D > &lines)
Interpolates the whole field so that it is maximally smooth (laplacian value minimized) and gets the ...
float get(int x, int y, int channel=0) const
get the value of the field by the integer coordinates
void swap(ValuesField &dest)
swap two fields (dimensions may be different)
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
cVec4 get_linearV4(float x, float y) const
get the linearly interpolated value as 4d-vector
void sharpResize(ValuesField &dest, float scale)
resize to bigger size keeping the edges sharpness
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_mip(float x, float y, float mip_level) const
get the linearly interpolated value as 3d-vector using the mipmaps
void clear()
clear rthe field
void rect(int x0, int y0, int x1, int y1, const cVec4 &color)
draw the filled rectangle
void LaplacianInterpolate(const UnlimitedBitset &fixed)
Interpolates the whole field so that it is maximally smooth (laplacian value minimized) and keeps the...
void sharpEdges2X1(ValuesField &dest)
Experimental, variation of the previous function: Increase the image 2X and sharpen (sharpening edges...
void create(int SizeX, int SiezY, int depth=1, FieldClamp clampmode=fcWrap)
Create the field.
void setClampMode(FieldClamp cl)
set the field clamp mode - how it acts beyond the boundaries
void NormalizeColors(bool monochromatic=false, int mipsize=64)
Normalize the texture to be (128, 128, 128) in average using the mip-mapping algorithm.
cVec4 get_linearV4_mip(float x, float y, float mip_level) const
get the linearly interpolated value as 4d-vector using the mipmaps
void normalmap(ValuesField &dest, int byChannel=0)
calculate the normalmap
void toPower2(ValuesField &dest)
resize to the closest power of 2 (may increase, may decrease the size, we choose what is arithmetical...
void createFromImageMono(const comms::cImage &im, Vector3D mask=Vector3D::Zero)
create the monochromatic field from the image (1 channel)
void createMips()
create the mipmaps, decreasing twice with each level until it is possible
void recoverBump(ValuesField &dest)
recover the bump from the color/greyscale (heuristic)
int depth() const
Get amount of channels.
Definition ValuesField.h:562
int height() const
get height
Definition ValuesField.h:558
cVec4 get_bicubicV4(float x, float y) const
get the bicubic interpolated value as the 4d-vector
float get_linear(float x, float y, int channel=0) const
get the linearly interpolated value
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 set(float value, int x, int y, int channel=0)
set teh value to the field
cVec2 & 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
void normalmap3(ValuesField &dest, float heightmod=1.0, int channel=0)
calculate the normalmap as the 3d-vectors set
void curvature(ValuesField &dest)
calculate the curvature of the 2d-field
float & value(int x, int y, int channel=0)
get the value reference of the field by the integer coordinates
void saveImage(const char *name)
save the field directly to file
cVec3 get_bicubicV3_mip(float x, float y, float mip_level) const
get the bicubic interpolated value as the 3d-vector using the mipmaps
void curvatureDir(ValuesField &dest)
calculate the curvature principal directions
void sharpEdges2X(ValuesField &dest)
Experimental: Increase the image 2X and sharpen (sharpening edges so that edge width will be kept des...
bool torange(int &x, int &y) const
converts the (x,y) to range [0..Lx-1, 0..Ly-1]
void createFromImage(const comms::cImage &im)
create the field form the image
cVec3 get_linearV3(float x, float y) const
get the linearly interpolated value as 3d-vector
void gradientValue(ValuesField &dest)
calculate the gradient length
void add(float value, int x, int y, int channel=0)
add the value to the field
void operate(const std::function< void(int, int) > &f, bool multithread=true)
operate over the field with the lambda
void monoTo(ValuesField &dest)
convert multiple channels to one as an average-arithmetic
int width() const
get width
Definition ValuesField.h:554
cVec2 get_bicubicV2_mip(float x, float y, float mip_level) const
get the bicubic interpolated value as the 2d-vector using the mipmaps
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
cVec3 get_bicubicV3(float x, float y) const
get the bicubic interpolated value as the 3d-vector
void resizeTo(ValuesField &dest)
resize the field to other size using the bicubic interpolation
float get_linear_mip(float x, float y, int channel, float mip_level) const
get the linearly interpolated value using the mipmaps
void Decrease2X(ValuesField &dest)
Decrease the field 2X times.
void max(ValuesField &other)
calculated the maximum of two fields into hte current
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
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
void loadImage(const char *name)
read the image directly from the file
The array template, refer it as coat::list <...> if you are using the Core API.
Definition cList.h:133
The 3D-matrix, refer it as coat::mat3 in the Core API.
Definition cMat3.h:6
The 2D-vector, refer it as coat::vec2 in the Core API.
Definition cVec2.h:9
The 3D-vector, refer it as coat::vec3 in the Core API.
Definition cVec3.h:10
The 4D-vector, refer it as coat::vec4 in the Core API.
Definition cVec4.h:9