载入中...
搜索中...
未找到
TerrainDerivedMap.cpp
浏览该文件的文档.
10 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.heightmapSafeSample: finite data required"));
16 if (!raster_detail::validRaster(source) || !std::isfinite(x) || !std::isfinite(z) || x < 0 || x > 1 || z < 0 ||
22 const int x0 = std::min(int(px), source.getWidth() - 1), z0 = std::min(int(pz), source.getHeight() - 1);
32 if (source.getWidth() == 0 && source.getHeight() == 0 && source.data().empty()) return Result<bool>::success(false);
36 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.heightmapHasData: malformed storage"));
49 return raster_detail::validRaster(target) && raster_detail::validRaster(source) && source.getWidth() >= 2 &&
50 source.getHeight() >= 2 && target.getWidth() == source.getWidth() && target.getHeight() == source.getHeight();
60 return invalid("terrain.heightmapCurvature: matching finite 2D rasters and known mode required");
84 const double horizontal = normalized(-2 * (dy * dy * dxx + dx * dx * dyy - dx * dy * dxy) / denominator);
94Result<int> generateTerrainHeightmapAspect(Heightmap& target, const Heightmap& source, TerrainHeightmapAspect mode) {
96 if (!compatible(target, source) || mode < TerrainHeightmapAspect::Aspect || mode > TerrainHeightmapAspect::Easterness)
114 if (mode == TerrainHeightmapAspect::Northerness) aspect = std::cos(aspect * radians) * 0.5 + 0.5;
115 else if (mode == TerrainHeightmapAspect::Easterness) aspect = std::sin(aspect * radians) * 0.5 + 0.5;
117 if (!isRepresentable(aspect)) return invalid("terrain.heightmapAspect: derived value exceeds float range");
123Result<int> filterTerrainHeightmapNeighborhood(Heightmap& target, const Heightmap& source, int radius,
127 target.getHeight() != source.getHeight() || radius < 0 || radius > std::max(source.getWidth(), source.getHeight()) ||
129 mode < TerrainHeightmapNeighborhood::DeNoise || mode > TerrainHeightmapNeighborhood::ShrinkEdges)
130 return invalid("terrain.heightmapNeighborhood: matching finite rasters, valid radius and known mode required");
155 else if (mode == TerrainHeightmapNeighborhood::GrowEdges && maximum > value) value = (maximum + value) * 0.5F;
165 return invalid("terrain.heightmapSmooth: matching finite rasters and nonnegative iterations required");
181Result<int> smoothTerrainHeightmapRadius(Heightmap& target, const Heightmap& source, int radius) {
185 return invalid("terrain.heightmapSmoothRadius: matching finite rasters and nonnegative radius required");
211Result<int> convolveTerrainHeightmap(Heightmap& target, const Heightmap& source, const Heightmap& kernel) {
216 return invalid("terrain.heightmapConvolve: matching finite rasters and an odd square finite kernel required");
217 const int width = source.getWidth(), height = source.getHeight(), kernelSize = kernel.getWidth();
231 if (!isRepresentable(sum / divisor)) return invalid("terrain.heightmapConvolve: result exceeds float range");
241 return invalid("terrain.heightmapSlope: matching finite rasters with dimensions at least two required");
256 if (!isRepresentable(slope)) return invalid("terrain.heightmapSlope: derived value exceeds float range");
262Result<int> quantizeTerrainHeightmap(Heightmap& target, const Heightmap& source, float divisor) {
266 return invalid("terrain.heightmapQuantize: matching finite rasters and finite nonzero divisor required");
270 if (!isRepresentable(quantized)) return invalid("terrain.heightmapQuantize: result exceeds float range");
278 return operation >= TerrainHeightmapArithmetic::Add && operation <= TerrainHeightmapArithmetic::Divide;
287 if (raster.getWidth() == targetWidth && raster.getHeight() == targetHeight) return raster.height(x, y);
293Result<int> applyTerrainHeightmapScalarArithmetic(Heightmap& target, const Heightmap& source, float operand,
298 target.getHeight() != source.getHeight() || !std::isfinite(operand) || !knownArithmetic(operation) ||
301 return invalid("terrain.heightmapScalarArithmetic: finite matching inputs, valid operation and clamp required");
306 if (!isRepresentable(result)) return invalid("terrain.heightmapScalarArithmetic: result exceeds float range");
320 return invalid("terrain.heightmapRasterArithmetic: finite inputs, valid operation and clamp required");
330 if (!isRepresentable(result)) return invalid("terrain.heightmapRasterArithmetic: result exceeds float range");
336Result<int> lerpTerrainHeightmap(Heightmap& target, const Heightmap& source, const Heightmap& values,
339 if (!validRaster(target) || !validRaster(source) || !validRaster(values) || !validRaster(mask) ||
349 if (!isRepresentable(result)) return invalid("terrain.heightmapLerp: result exceeds float range");
361 ((transform == TerrainHeightmapTransform::Power || transform == TerrainHeightmapTransform::Contrast) &&
363 return invalid("terrain.heightmapTransform: matching finite rasters, known transform and parameter required");
374 else if (transform == TerrainHeightmapTransform::Normalise && range > 0.F) result = (value - minimum) / range;
375 else if (transform == TerrainHeightmapTransform::Power) result = std::pow(double(value), parameter);
376 else if (transform == TerrainHeightmapTransform::Contrast) result = (double(value) - 0.5) * parameter + 0.5;
377 if (!isRepresentable(result)) return invalid("terrain.heightmapTransform: result exceeds float range");
383Result<int> copyTerrainHeightmap(Heightmap& target, const Heightmap& source, TerrainHeightmapCopy mode) {
402Result<int> copyTerrainHeightmapClamped(Heightmap& target, const Heightmap& source, float minValue, float maxValue) {
404 if (!validRaster(target) || !validRaster(source) || !std::isfinite(minValue) || !std::isfinite(maxValue) ||
406 return invalid("terrain.heightmapCopyClamped: finite rasters and ordered finite bounds required");
434Result<double> measureTerrainHeightmap(const Heightmap& source, TerrainHeightmapMeasure measure) {
439 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.heightmapMeasure: finite raster and known measure required"));
447 for (int x = 0; x < width; ++x) level = std::max({level, source.height(x, 0), source.height(x, height - 1)});
448 for (int y = 0; y < height; ++y) level = std::max({level, source.height(0, y), source.height(width - 1, y)});
456 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.heightmapMeasure: float sum overflow"));
457 if (measure == TerrainHeightmapMeasure::Average) sum /= float(source.getWidth() * source.getHeight());
464 if (!validRaster(target) || !validRaster(source) || !validRaster(startHeights) || !validRaster(curves) ||
466 startHeights.getHeight() != 1 || curves.getHeight() != startHeights.getWidth() || curves.getWidth() < 2)
467 return invalid("terrain.heightmapTerraceQuantize: matching finite rasters, N-by-1 starts and curve rows required");
472 return invalid("terrain.heightmapTerraceQuantize: starts must be strictly increasing and at most one");
489 if (next <= start) return invalid("terrain.heightmapTerraceQuantize: final terrace must start below one");
493 const double shaped = std::lerp(double(curves.height(x0, terrace)), double(curves.height(x1, terrace)), x - x0);
495 if (!isRepresentable(result)) return invalid("terrain.heightmapTerraceQuantize: result exceeds float range");
504 if (!validRaster(source) || source.getWidth() < 2 || source.getHeight() < 2 || !std::isfinite(x) ||
508 DiagnosticCode::InvalidArgument, "terrain.heightmapSlopeQuery: finite 2D raster, coordinates and known mode required"));
511 if (x != ix || y != iy || ix < 0 || iy < 0 || ix >= source.getWidth() - 1 || iy >= source.getHeight() - 1)
513 DiagnosticCode::InvalidArgument, "terrain.heightmapSlopeQuery: forward mode requires an interior integer coordinate"));
520 DiagnosticCode::InvalidArgument, "terrain.heightmapSlopeQuery: normalized coordinates must be in [0,1]"));
559 return raster_detail::validRaster(values) && (values.getWidth() == 1 || values.getHeight() == 1) &&
566 if (!validRaster(target) || !validStrip(values, target.getHeight()) || rowX < 0 || rowX >= target.getWidth())
567 return invalid("terrain.heightmapSetRow: finite target, valid X and target-height strip required");
578 return invalid("terrain.heightmapSetColumn: finite target, valid Z and target-width strip required");
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
Definition Heightmap.h:21
Result< int > publish(Heightmap &target, std::vector< float > candidate)
Publish.
Definition TerrainRasterInternal.h:62
Definition EvpackPointGraphLoader.h:12
Result< int > resetTerrainHeightmap(Heightmap &target)
Reset a heightmap to Pcg's empty zero-by-zero state.
Definition TerrainDerivedMap.cpp:585
TerrainHeightmapNeighborhood
Pcg HeightMap neighborhood mutation modes.
Definition TerrainDerivedMap.h:36
Result< int > quantizeTerrainHeightmapTerraces(Heightmap &target, const Heightmap &source, const Heightmap &startHeights, const Heightmap &curves)
Apply Pcg's curve-driven Quantize overload using one sampled curve per raster row.
Definition TerrainDerivedMap.cpp:461
Result< int > generateTerrainHeightmapSlope(Heightmap &target, const Heightmap &source)
Generate Pcg HeightMap.SlopeMap's normalized gradient magnitude.
Definition TerrainDerivedMap.cpp:237
Result< int > setTerrainHeightmapRow(Heightmap &target, int rowX, const Heightmap &values)
Set Pcg's fixed-X row from a one-dimensional strip.
Definition TerrainDerivedMap.cpp:564
Result< int > copyTerrainHeightmapClamped(Heightmap &target, const Heightmap &source, float minValue, float maxValue)
Copy a Pcg heightmap with inclusive output clamping and normalized resampling.
Definition TerrainDerivedMap.cpp:402
Result< int > applyTerrainHeightmapRasterArithmetic(Heightmap &target, const Heightmap &source, const Heightmap &operand, TerrainHeightmapArithmetic operation, bool clampResult, float minValue, float maxValue)
Apply a raster Pcg HeightMap arithmetic operation, resampling a differently sized operand.
Definition TerrainDerivedMap.cpp:312
TerrainHeightmapCurvature
Pcg HeightMap.CurvatureMap modes in source enum order.
Definition TerrainDerivedMap.h:32
Result< int > flipTerrainHeightmap(Heightmap &target, const Heightmap &source)
Transpose a Pcg HeightMap exactly as HeightMap.Flip does.
Definition TerrainDerivedMap.cpp:416
Result< int > smoothTerrainHeightmap(Heightmap &target, const Heightmap &source, int iterations)
Apply Pcg HeightMap.Smooth's in-place four-neighbor passes.
Definition TerrainDerivedMap.cpp:161
TerrainHeightmapSlopeQuery
Pcg HeightMap point slope query variants.
Definition TerrainDerivedMap.h:46
@ NormalizedAverage
@ NormalizedCentral
Result< int > fillTerrainHeightmap(Heightmap &target, float value)
Fill a finite Pcg heightmap with one value clamped to [0,1].
Definition TerrainDerivedMap.cpp:538
Result< int > smoothTerrainHeightmapRadius(Heightmap &target, const Heightmap &source, int radius)
Apply Pcg HeightMap.SmoothRadius's scaled sliding-window filter, including its first-row omission.
Definition TerrainDerivedMap.cpp:181
Result< int > convolveTerrainHeightmap(Heightmap &target, const Heightmap &source, const Heightmap &kernel)
Apply Pcg HeightMap.Convolve with an odd square kernel and source-order in-place feedback.
Definition TerrainDerivedMap.cpp:211
Result< int > copyTerrainHeightmap(Heightmap &target, const Heightmap &source, TerrainHeightmapCopy mode)
Copy or conditionally merge a Pcg heightmap, resampling when dimensions differ.
Definition TerrainDerivedMap.cpp:383
Result< int > transformTerrainHeightmap(Heightmap &target, const Heightmap &source, TerrainHeightmapTransform transform, float parameter)
Apply Pcg Invert, Normalise, Power, or Contrast to a finite heightmap.
Definition TerrainDerivedMap.cpp:355
Result< int > setTerrainHeightmapColumn(Heightmap &target, int columnZ, const Heightmap &values)
Set Pcg's fixed-Z column from a one-dimensional strip.
Definition TerrainDerivedMap.cpp:574
Result< bool > terrainHeightmapHasData(const Heightmap &source)
Return whether a heightmap contains a valid positive-size sample array.
Definition TerrainDerivedMap.cpp:31
Result< float > sampleTerrainHeightmapSafe(const Heightmap &source, int x, int z)
Read a finite heightmap at an integer coordinate clamped to its nearest border.
Definition TerrainDerivedMap.cpp:7
TerrainHeightmapTransform
Pcg HeightMap whole-raster value transforms.
Definition TerrainDerivedMap.h:40
Result< int > quantizeTerrainHeightmap(Heightmap &target, const Heightmap &source, float divisor)
Quantize every sample using Pcg HeightMap.Quantize's Mathf.Round rule.
Definition TerrainDerivedMap.cpp:262
Result< bool > terrainHeightmapIsPowerOfTwo(const Heightmap &source)
Return whether both positive heightmap dimensions are powers of two; malformed storage fails.
Definition TerrainDerivedMap.cpp:40
TerrainHeightmapMeasure
Pcg HeightMap read-only scalar measurements.
Definition TerrainDerivedMap.h:44
Result< double > measureTerrainHeightmap(const Heightmap &source, TerrainHeightmapMeasure measure)
Measure Pcg height range, sum, average, or scanner base level from current samples.
Definition TerrainDerivedMap.cpp:434
Result< int > filterTerrainHeightmapNeighborhood(Heightmap &target, const Heightmap &source, int radius, TerrainHeightmapNeighborhood mode)
Apply Pcg HeightMap.DeNoise, GrowEdges, or ShrinkEdges in source traversal order.
Definition TerrainDerivedMap.cpp:123
TerrainHeightmapCopy
Pcg HeightMap.Copy conditional modes in source enum order.
Definition TerrainDerivedMap.h:42
Result< float > sampleTerrainHeightmapNormalized(const Heightmap &source, float x, float z)
Read Pcg HeightMap's normalized bilinear sample using x*width and z*depth coordinates.
Definition TerrainDerivedMap.cpp:15
Result< int > lerpTerrainHeightmap(Heightmap &target, const Heightmap &source, const Heightmap &values, const Heightmap &mask)
Lerp source toward values under a mask using Pcg's clamped Mathf.Lerp semantics.
Definition TerrainDerivedMap.cpp:336
TerrainHeightmapAspect
Pcg HeightMap.Aspect modes in source enum order.
Definition TerrainDerivedMap.h:34
@ Northerness
@ Easterness
Result< int > generateTerrainHeightmapAspect(Heightmap &target, const Heightmap &source, TerrainHeightmapAspect mode)
Derive Pcg HeightMap.Aspect's aspect, northerness, or easterness raster.
Definition TerrainDerivedMap.cpp:94
Result< int > setTerrainHeightmapSafe(Heightmap &target, int x, int y, float value)
Set one sample after clamping its coordinates to the nearest border.
Definition TerrainDerivedMap.cpp:546
Result< int > applyTerrainHeightmapScalarArithmetic(Heightmap &target, const Heightmap &source, float operand, TerrainHeightmapArithmetic operation, bool clampResult, float minValue, float maxValue)
Apply a scalar Pcg HeightMap arithmetic operation with optional clamping.
Definition TerrainDerivedMap.cpp:293
TerrainHeightmapArithmetic
Pcg HeightMap pointwise arithmetic operations.
Definition TerrainDerivedMap.h:38
Result< double > measureTerrainHeightmapSlope(const Heightmap &source, float x, float y, TerrainHeightmapSlopeQuery mode)
Evaluate one of Pcg HeightMap's three point-slope formulas.
Definition TerrainDerivedMap.cpp:501
Result< int > generateTerrainHeightmapCurvature(Heightmap &target, const Heightmap &source, TerrainHeightmapCurvature mode)
Derive Pcg HeightMap.CurvatureMap's normalized differential curvature.
Definition TerrainDerivedMap.cpp:55
@ InvalidArgument