Skip to content

Commit

Permalink
Add interpolation info to surface kdtree triangles.
Browse files Browse the repository at this point in the history
  • Loading branch information
MFraters committed Jan 29, 2023
1 parent 793a0b7 commit 1f9e88e
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 79 deletions.
33 changes: 30 additions & 3 deletions include/world_builder/objects/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,38 @@ This file is part of the World Builder.
#define WORLD_BUILDER_OBJECTSS_SURFACE_H

#include "world_builder/utilities.h"

#include "world_builder/kd_tree.h"

namespace WorldBuilder
{
namespace Objects
{
struct SurfaceValueInfo
{
size_t triangle_index;
double interpolated_value;
double interpolator_s;
double interpolator_t;

SurfaceValueInfo(
size_t triangle_index_,
double interpolated_value_,
double interpolator_s_,
double interpolator_t_)
:
triangle_index(triangle_index_),
interpolated_value(interpolated_value_),
interpolator_s(interpolator_s_),
interpolator_t(interpolator_t_) {};

SurfaceValueInfo(double interpolated_value_)
:
triangle_index(NaN::IQNAN),
interpolated_value(interpolated_value_),
interpolator_s(NaN::DQNAN),
interpolator_t(NaN::DQNAN) {};
};

class Surface
{
public:
Expand All @@ -46,7 +71,7 @@ namespace WorldBuilder
/**
* Returns the value of the surface at the check point.
*/
double local_value(const Point<2> check_point) const;
SurfaceValueInfo local_value(const Point<2> check_point) const;

/**
* Wether the surface is a constant value or not. This is used for optimalization.
Expand Down Expand Up @@ -87,7 +112,9 @@ namespace WorldBuilder
bool in_triangle(const std::array<std::array<double,3>,3> &points,
const std::array<double,8> &precomputed,
const Point<2> check_point,
double &interpolate_value) const;
double &interpolate_value,
double &interpolator_s,
double &interpolator_t) const;
};
}

Expand Down
4 changes: 2 additions & 2 deletions source/world_builder/features/continental_plate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ namespace WorldBuilder
WorldBuilder::Utilities::polygon_contains_point(coordinates, Point<2>(position_in_natural_coordinates.get_surface_coordinates(),
world->parameters.coordinate_system->natural_coordinate_system())))
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i_property = 0; i_property < properties.size(); ++i_property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ namespace WorldBuilder
double composition = composition_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ namespace WorldBuilder
WorldBuilder::grains grains_local = grains_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ namespace WorldBuilder
WorldBuilder::grains grains_local = grains_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ namespace WorldBuilder

if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
const double adabatic_temperature = potential_mantle_temperature *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace WorldBuilder
{
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
const double min_depth_local_local = std::max(feature_min_depth, min_depth_local);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ namespace WorldBuilder
const double /*feature_min_depth*/,
const double /*feature_max_depth*/) const
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
if (depth <= max_depth && depth >= min_depth)
Expand Down
4 changes: 2 additions & 2 deletions source/world_builder/features/mantle_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ namespace WorldBuilder
WorldBuilder::Utilities::polygon_contains_point(coordinates, Point<2>(position_in_natural_coordinates.get_surface_coordinates(),
world->parameters.coordinate_system->natural_coordinate_system())))
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i_property = 0; i_property < properties.size(); ++i_property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace WorldBuilder
double composition = composition_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ namespace WorldBuilder
WorldBuilder::grains grains_local = grains_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ namespace WorldBuilder
WorldBuilder::grains grains_local = grains_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ namespace WorldBuilder

if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
const double adabatic_temperature = potential_mantle_temperature *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ namespace WorldBuilder
{
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
const double min_depth_local_local = std::max(feature_min_depth, min_depth_local);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ namespace WorldBuilder

if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
return Utilities::apply_operation(operation,temperature_,temperature);
Expand Down
4 changes: 2 additions & 2 deletions source/world_builder/features/oceanic_plate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ namespace WorldBuilder
WorldBuilder::Utilities::polygon_contains_point(coordinates, Point<2>(position_in_natural_coordinates.get_surface_coordinates(),
world->parameters.coordinate_system->natural_coordinate_system())))
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i_property = 0; i_property < properties.size(); ++i_property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ namespace WorldBuilder
double composition = composition_;
if (depth <= max_depth && depth >= min_depth)
{
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point());
const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
if (depth <= max_depth_local && depth >= min_depth_local)
{
for (unsigned int i =0; i < compositions.size(); ++i)
Expand Down
Loading

0 comments on commit 1f9e88e

Please sign in to comment.