mercator
0.4.0
A terrain generation library for the Worldforge system.
|
5 #include "ThresholdShader.h"
25 auto Iend = params.end();
27 m_threshold = I->second;
31 HighShader::~HighShader() =
default;
35 if (s.
getMax() > m_threshold) {
46 unsigned int colors = channels - 1;
49 if (height_data == 0) {
50 std::cerr <<
"WARNING: Mercator: Attempting to shade empty segment."
51 << std::endl << std::flush;
56 unsigned int count = size * size;
58 for (
unsigned int i = 0; i < count; ++i) {
59 for (
unsigned int k = 0; k < colors; ++k) {
62 data[++j] = ((height_data[i] > m_threshold) ? colorMax : colorMin);
77 auto Iend = params.end();
79 m_threshold = I->second;
83 LowShader::~LowShader() =
default;
87 if (s.
getMin() < m_threshold) {
98 unsigned int colors = channels - 1;
101 if (height_data == 0) {
102 std::cerr <<
"WARNING: Mercator: Attempting to shade empty segment."
103 << std::endl << std::flush;
108 unsigned int count = size * size;
110 for (
unsigned int i = 0; i < count; ++i) {
111 for (
unsigned int k = 0; k < colors; ++k) {
112 data[++j] = colorMax;
114 data[++j] = ((height_data[i] < m_threshold) ? colorMax : colorMin);
125 m_lowThreshold(low_threshold), m_highThreshold(high_threshold)
130 m_lowThreshold(default_lowThreshold), m_highThreshold(default_highThreshold)
133 auto Iend = params.end();
135 m_lowThreshold = I->second;
139 m_highThreshold = I->second;
143 BandShader::~BandShader() =
default;
147 if ((s.
getMin() < m_highThreshold) &&
148 (s.
getMax() > m_lowThreshold)) {
158 assert(channels > 0);
159 unsigned int colors = channels - 1;
162 if (height_data ==
nullptr) {
163 std::cerr <<
"WARNING: Mercator: Attempting to shade empty segment."
164 << std::endl << std::flush;
169 unsigned int count = size * size;
171 for (
unsigned int i = 0; i < count; ++i) {
172 for (
unsigned int k = 0; k < colors; ++k) {
173 data[++j] = colorMax;
175 data[++j] = (((height_data[i] > m_lowThreshold) &&
176 (height_data[i] < m_highThreshold)) ? colorMax : colorMin);
static const float default_lowThreshold
Default level above which the shader renders.
float getMin() const
Accessor for the minimum height value in this Segment.
const Segment & getSegment() const
Accessor for the terrain height segment this surface is associated with.
void shade(Surface &) const override
Populate a Surface with data.
unsigned int getChannels() const
Accessor for the number of data values per height point.
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Data store for terrain surface data.
static const std::string key_highThreshold
Key string used when specifying the high threshold parameter.
static const float default_threshold
Default level above which the shader renders.
void shade(Surface &) const override
Populate a Surface with data.
static const float default_threshold
Default level below which the shader renders.
int getSize() const
Accessor for array size of this segment.
static const float default_highThreshold
Default level below which the shader renders.
static const std::string key_threshold
Key string used when specifying the threshold parameter.
bool checkIntersect(const Segment &) const override
Check whether this Shader has any effect on the given Segment.
LowShader(float threshold=default_threshold)
Constructor.
DataType * getData()
Accessor for a pointer to buffer containing data values.
bool checkIntersect(const Segment &) const override
Check whether this Shader has any effect on the given Segment.
static const std::string key_lowThreshold
Key string used when specifying the low threshold parameter.
bool checkIntersect(const Segment &) const override
Check whether this Shader has any effect on the given Segment.
HighShader(float threshold=default_threshold)
Constructor.
BandShader(float low_threshold=default_lowThreshold, float high_threshold=default_highThreshold)
Constructor.
std::map< std::string, float > Parameters
STL map of parameter values for a shader constructor.
static const std::string key_threshold
Key string used when specifying the threshold parameter.
const float * getPoints() const
Accessor for buffer containing height points.
float getMax() const
Accessor for the maximum height value in this Segment.
void shade(Surface &) const override
Populate a Surface with data.