Skip to content

Commit

Permalink
Fix badly designed fields
Browse files Browse the repository at this point in the history
* Average R is not used anymore
* Init RidgePolyhederon via ctor
  • Loading branch information
ardazishvili committed Oct 2, 2024
1 parent 797f347 commit abe7d91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
31 changes: 13 additions & 18 deletions src/polyhedron/polyhedron_ridge_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

namespace sota {

PolyhedronRidgeProcessor::PolyhedronRidgeProcessor() {
PolyhedronRidgeProcessor::PolyhedronRidgeProcessor(RidgePolyhedron& ridge_polyhedron)
: _ridge_polyhedron(ridge_polyhedron) {
_ridge_config = RidgeConfig{
.variation_min_bound = 0.0,
.variation_max_bound = 0.02,
Expand Down Expand Up @@ -89,7 +90,7 @@ void PolyhedronRidgeProcessor::configure_pentagon(PolygonWrapper& wrapper, Biome

void PolyhedronRidgeProcessor::set_neighbours() {
int pentagon_cnt = 0;
for (auto& p : _polyhedron_mesh->_neighbours_map) {
for (auto& p : _ridge_polyhedron._neighbours_map) {
int cur_id = p.first;
std::set<int> neighbours_ids = p.second;
auto cur_it = std::find_if(_meshes_wrapped.begin(), _meshes_wrapped.end(),
Expand Down Expand Up @@ -202,11 +203,11 @@ void PolyhedronRidgeProcessor::process_meshes() {
// print_biomes();

for (RidgeGroup& group : _mountain_groups) {
group.init_ridges(_distance_map, _ridge_config.top_ridge_offset, _polyhedron_mesh->_divisions);
group.init_ridges(_distance_map, _ridge_config.top_ridge_offset, _ridge_polyhedron._divisions);
}

for (RidgeGroup& group : _water_groups) {
group.init_ridges(_distance_map, _ridge_config.bottom_ridge_offset, _polyhedron_mesh->_divisions);
group.init_ridges(_distance_map, _ridge_config.bottom_ridge_offset, _ridge_polyhedron._divisions);
}

// initial heights calculation
Expand All @@ -223,7 +224,7 @@ void PolyhedronRidgeProcessor::process_meshes() {
}

float amplitude = global_max_y - global_min_y;
float compress = _polyhedron_mesh->_compression_factor / amplitude;
float compress = _ridge_polyhedron._compression_factor / amplitude;
for (PolygonWrapper* wrapper : _meshes_wrapped) {
RidgeMesh* ridge_mesh = dynamic_cast<RidgeMesh*>(wrapper->mesh().ptr());
ridge_mesh->set_shift_compress(-global_min_y, compress);
Expand All @@ -234,28 +235,22 @@ void PolyhedronRidgeProcessor::process_meshes() {
RidgeMesh* ridge_mesh = dynamic_cast<RidgeMesh*>(wrapper->mesh().ptr());

float approx_diameter = _meshes_wrapped[0]->mesh()->inner_mesh()->get_R() * 2;
ridge_mesh->calculate_final_heights(_distance_map, approx_diameter, _polyhedron_mesh->_divisions);
ridge_mesh->calculate_final_heights(_distance_map, approx_diameter, _ridge_polyhedron._divisions);
ridge_mesh->recalculate_all_except_vertices();
ridge_mesh->update();
}
}

void PolyhedronRidgeProcessor::init(Polyhedron* polyhedron) {
void PolyhedronRidgeProcessor::init() {
_meshes_wrapped.clear();
_polyhedron_mesh = dynamic_cast<RidgePolyhedron*>(polyhedron);
std::transform(polyhedron->_hexagons.begin(), polyhedron->_hexagons.end(), std::back_inserter(_meshes_wrapped),
[](PolygonWrapper& wrapper) { return &wrapper; });
std::transform(polyhedron->_pentagons.begin(), polyhedron->_pentagons.end(), std::back_inserter(_meshes_wrapped),
[](PolygonWrapper& wrapper) { return &wrapper; });

float all_r =
std::accumulate(_meshes_wrapped.begin(), _meshes_wrapped.end(), 0.0f,
[](float acc, PolygonWrapper* wrapper) { return acc + wrapper->mesh()->inner_mesh()->get_R(); });
_R_average = all_r / _meshes_wrapped.size();
std::transform(_ridge_polyhedron._hexagons.begin(), _ridge_polyhedron._hexagons.end(),
std::back_inserter(_meshes_wrapped), [](PolygonWrapper& wrapper) { return &wrapper; });
std::transform(_ridge_polyhedron._pentagons.begin(), _ridge_polyhedron._pentagons.end(),
std::back_inserter(_meshes_wrapped), [](PolygonWrapper& wrapper) { return &wrapper; });
}

void PolyhedronRidgeProcessor::process(Polyhedron& polyhedron_mesh) {
init(&polyhedron_mesh);
init();

process_meshes();
}
Expand Down
12 changes: 4 additions & 8 deletions src/polyhedron/polyhedron_ridge_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class RidgePolyhedron;

class PolyhedronRidgeProcessor : public PolyhedronProcessor, public RidgeBased {
public:
PolyhedronRidgeProcessor();
PolyhedronRidgeProcessor(RidgePolyhedron &ridge_polyhedron);
PolyhedronRidgeProcessor(const PolyhedronRidgeProcessor &other) = delete;
PolyhedronRidgeProcessor(PolyhedronRidgeProcessor &&other) = default;
PolyhedronRidgeProcessor &operator=(const PolyhedronRidgeProcessor &other) = delete;
PolyhedronRidgeProcessor &operator=(PolyhedronRidgeProcessor &&other) = default;
PolyhedronRidgeProcessor &operator=(PolyhedronRidgeProcessor &&other) = delete;

void configure_hexagon(PolygonWrapper &wrapper, Biome biome, int &id, Ref<ShaderMaterial> mat,
Polyhedron &polyhedron_mesh) override;
Expand All @@ -44,17 +44,13 @@ class PolyhedronRidgeProcessor : public PolyhedronProcessor, public RidgeBased {
float get_bottom_offset() const { return _ridge_config.bottom_ridge_offset; }

private:
// TODO fix possibility of zero
RidgePolyhedron *_polyhedron_mesh;
RidgePolyhedron &_ridge_polyhedron;

std::vector<PolygonWrapper *> _meshes_wrapped;

DiscreteVertexToDistance _distance_map;

// TODO fix possibility of zero
float _R_average{0};

void init(Polyhedron *polyhedron_mesh);
void init();

void process_meshes();
void set_neighbours();
Expand Down
2 changes: 1 addition & 1 deletion src/polyhedron/ridge_polyhedron.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RidgePolyhedron : public RidgeBasedPolyhedron {
GDCLASS(RidgePolyhedron, RidgeBasedPolyhedron)
public:
protected:
RidgePolyhedron() = default;
RidgePolyhedron() : _ridge_processor(*this) {}
RidgePolyhedron(const RidgePolyhedron& other) = delete;
RidgePolyhedron(RidgePolyhedron&& other) = delete;
// copying operator= defined inside GDCLASS
Expand Down

0 comments on commit abe7d91

Please # to comment.