Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ target_sources( openemsh
"${CMAKE_CURRENT_SOURCE_DIR}/domain/mesh/interval.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/mesh/meshline.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/mesh/meshline_policy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/global.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/material.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/meshline_policy_manager.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/conflict_manager.cpp"
Expand Down Expand Up @@ -96,6 +97,7 @@ target_sources( openemsh_bin
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/utils/nodegraph/wire.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_delegate.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_dialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_dialog_per_axis_per_criteria.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model_global.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model_angle.cpp"
Expand All @@ -104,6 +106,7 @@ target_sources( openemsh_bin
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model_edge.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model_interval.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model_meshline_policy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/edit/edit_model_per_axis_per_criteria.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/processing_view/processing_axis.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/processing_view/processing_plane.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/processing_view/processing_style.cpp"
Expand Down
5 changes: 5 additions & 0 deletions src/app/openemsh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ optional<Step> next(Step step) {
case Step::DETECT_AND_SOLVE_TCMLP:
return Step::DETECT_INTERVALS;
case Step::DETECT_INTERVALS:
return Step::ADJUST_MESH_TO_MATERIAL;
case Step::ADJUST_MESH_TO_MATERIAL:
return Step::DETECT_INTERVALS_PER_DIAG_ZONES;
case Step::DETECT_INTERVALS_PER_DIAG_ZONES:
return Step::SOLVE_DIAG_ZONES_INTERVALS;
Expand Down Expand Up @@ -75,6 +77,7 @@ set<Step> that_and_after(Step step) {
case DETECT_INDIVIDUAL_EDGES: out.emplace(DETECT_INDIVIDUAL_EDGES); [[fallthrough]];
case DETECT_AND_SOLVE_TCMLP: out.emplace(DETECT_AND_SOLVE_TCMLP); [[fallthrough]];
case DETECT_INTERVALS: out.emplace(DETECT_INTERVALS); [[fallthrough]];
case ADJUST_MESH_TO_MATERIAL: out.emplace(ADJUST_MESH_TO_MATERIAL); [[fallthrough]];
case DETECT_INTERVALS_PER_DIAG_ZONES: out.emplace(DETECT_INTERVALS_PER_DIAG_ZONES); [[fallthrough]];
case SOLVE_DIAG_ZONES_INTERVALS: out.emplace(SOLVE_DIAG_ZONES_INTERVALS); [[fallthrough]];
case MESH: out.emplace(MESH); break;
Expand Down Expand Up @@ -178,6 +181,7 @@ void OpenEMSH::run(std::set<Step> const& steps) const {
handle(DETECT_INDIVIDUAL_EDGES, [&] { board->detect_individual_edges(); });
handle(DETECT_AND_SOLVE_TCMLP, [&] { board->detect_and_solve_too_close_meshline_policies(); });
handle(DETECT_INTERVALS, [&] { board->detect_intervals(); });
handle(ADJUST_MESH_TO_MATERIAL, [&] { board->adjust_mesh_to_materials(); });
handle(DETECT_INTERVALS_PER_DIAG_ZONES, [&] { board->detect_intervals_per_diagonal_zones(); });
handle(SOLVE_DIAG_ZONES_INTERVALS, [&] { board->solve_diagonal_zones_intervals(); });
handle(MESH, [&] { board->mesh(); });
Expand All @@ -200,6 +204,7 @@ void OpenEMSH::run_all_steps() const {
Step::DETECT_INDIVIDUAL_EDGES,
Step::DETECT_AND_SOLVE_TCMLP,
Step::DETECT_INTERVALS,
Step::ADJUST_MESH_TO_MATERIAL,
Step::DETECT_INTERVALS_PER_DIAG_ZONES,
Step::SOLVE_DIAG_ZONES_INTERVALS,
Step::MESH
Expand Down
8 changes: 5 additions & 3 deletions src/app/steps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class Step {
DETECT_INDIVIDUAL_EDGES,
DETECT_AND_SOLVE_TCMLP,
DETECT_INTERVALS,
ADJUST_MESH_TO_MATERIAL,
DETECT_INTERVALS_PER_DIAG_ZONES,
SOLVE_DIAG_ZONES_INTERVALS,
MESH
Expand All @@ -49,9 +50,10 @@ inline std::size_t index(std::optional<Step> step) {
case Step::DETECT_INDIVIDUAL_EDGES: return 10;
case Step::DETECT_AND_SOLVE_TCMLP: return 11;
case Step::DETECT_INTERVALS: return 12;
case Step::DETECT_INTERVALS_PER_DIAG_ZONES: return 13;
case Step::SOLVE_DIAG_ZONES_INTERVALS: return 14;
case Step::MESH: return 15;
case Step::ADJUST_MESH_TO_MATERIAL: return 13;
case Step::DETECT_INTERVALS_PER_DIAG_ZONES: return 14;
case Step::SOLVE_DIAG_ZONES_INTERVALS: return 15;
case Step::MESH: return 16;
default: ::unreachable();
}
}
Expand Down
74 changes: 68 additions & 6 deletions src/domain/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ shared_ptr<Board> Board::Builder::build(Params&& params) {
return make_shared<Board>(
std::move(polygons),
std::move(fixed_meshline_policy_creators),
std::move(material),
std::move(background_material),
std::move(params),
Caretaker::singleton().get_history_root());
}

//******************************************************************************
void Board::Builder::set_background_material(shared_ptr<Material> background) {
material = background;
void Board::Builder::set_background_material(shared_ptr<Material> material) {
background_material = material;
}

// TODO should be in meshline manager?
Expand Down Expand Up @@ -153,14 +153,14 @@ Board::Board(PlaneSpace<vector<shared_ptr<Polygon>>>&& polygons, Params&& params
Board::Board(
PlaneSpace<std::vector<std::shared_ptr<Polygon>>>&& polygons,
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>>&& fixed_meshline_policy_creators,
shared_ptr<Material>&& background,
shared_ptr<Material>&& background_material,
Params&& params,
Timepoint* t)
: Originator(t, BoardState(std::move(polygons)))
, global_params(make_shared<GlobalParams>(std::move(params), t))
, conflict_manager(make_shared<ConflictManager>(t))
, line_policy_manager(make_shared<MeshlinePolicyManager>(global_params.get(), t))
, material(background)
, background_material(background_material)
, fixed_meshline_policy_creators(std::move(fixed_meshline_policy_creators)) {

conflict_manager->init(line_policy_manager.get());
Expand All @@ -173,6 +173,33 @@ Board::Board(
get_caretaker().take_care_of(polygon);
}

//******************************************************************************
shared_ptr<Material> Board::find_ambient_material(Axis axis, Coord const& coord) const {
vector<pair<shared_ptr<Material>, remove_const_t<decltype(Polygon::priority)>>> materials;

for(ViewAxis view_axis : AllViewAxis) {
for(shared_ptr<Polygon> const& polygon : get_current_state().polygons[Planes[axis][view_axis]]) {
if(polygon->material
&& does_overlap(cast(view_axis, polygon->bounding), coord)) {
materials.emplace_back(shared_ptr<Material>(polygon->material), polygon->priority);
}
}
}

ranges::sort(materials, [](auto const& a, auto const& b) {
auto const& [material_a, priority_a] = a;
auto const& [material_b, priority_b] = b;
return priority_a != priority_b
? priority_a < priority_b
: *material_a < *material_b;
});

if(!materials.empty())
return materials.back().first;
else
return background_material;
}

//******************************************************************************
shared_ptr<Material> Board::find_ambient_material(Plane plane, Segment const& segment) const {
return find_ambient_material(plane, segment, nullptr).first;
Expand Down Expand Up @@ -205,7 +232,7 @@ pair<shared_ptr<Material>, remove_const_t<decltype(Polygon::priority)>> Board::f
if(!materials.empty())
return materials.back();
else
return { material, std::numeric_limits<remove_const_t<decltype(Polygon::priority)>>::min() };
return { background_material, std::numeric_limits<remove_const_t<decltype(Polygon::priority)>>::min() };
}

//******************************************************************************
Expand Down Expand Up @@ -619,6 +646,35 @@ void Board::add_fixed_meshline_policies(Axis axis) {
bar.complete();
}

//******************************************************************************
void Board::adjust_mesh_to_materials(Axis axis) {
auto [t, state_mlpm] = line_policy_manager->make_next_state();

auto [bar, i, _] = Progress::Bar::build(
state_mlpm.intervals[axis].size() + 1,
"["s + to_string(axis) + "] Adjusting mesh to Materials ");

for(auto const& interval : state_mlpm.intervals[axis]) {
auto const& params = global_params->get_current_state();
auto state_i = interval->get_current_state();
auto material = find_ambient_material(axis, interval->m);

auto const& lmin = global_params->get_lmin(axis, material.get(), params);
auto const& smoothness = global_params->get_smoothness(axis, material.get(), params);
state_i.main_material = material.get();
state_i.dmax = min(state_i.dmax, global_params->get_dmax(axis, material.get(), params));
state_i.before.lmin = lmin;
state_i.after.lmin = lmin;
state_i.before.smoothness = smoothness;
state_i.after.smoothness = smoothness;

interval->set_state(t, state_i);
bar.tick(++i);
}

bar.complete();
}

//******************************************************************************
void Board::adjust_edges_to_materials() {
for(auto const& plane : AllPlane)
Expand Down Expand Up @@ -673,6 +729,12 @@ void Board::add_fixed_meshline_policies() {
add_fixed_meshline_policies(axis);
}

//******************************************************************************
void Board::adjust_mesh_to_materials() {
for(auto const& axis : AllAxis)
adjust_mesh_to_materials(axis);
}

//******************************************************************************
void Board::auto_solve_all_edge_in_polygon() {
for(auto const& plane : AllPlane)
Expand Down
11 changes: 7 additions & 4 deletions src/domain/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Board
class Builder {
public:

void set_background_material(std::shared_ptr<Material> background);
void set_background_material(std::shared_ptr<Material> material);
void add_fixed_meshline_policy(Axis axis, Coord coord);
void add_polygon(Plane plane, std::shared_ptr<Material> const& material, std::string const& name, std::size_t priority, Polygon::RangeZ const& z_placement, std::initializer_list<Point> points);
void add_polygon(Plane plane, std::shared_ptr<Material> const& material, std::string const& name, std::size_t priority, Polygon::RangeZ const& z_placement, std::vector<std::unique_ptr<Point const>>&& points);
Expand All @@ -69,19 +69,19 @@ class Board
[[nodiscard]] std::shared_ptr<Board> build(Params&& params = Params());

private:
std::shared_ptr<Material> material;
std::shared_ptr<Material> background_material;
PlaneSpace<std::vector<std::shared_ptr<Polygon>>> polygons;
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>> fixed_meshline_policy_creators;
};

std::shared_ptr<Material> material;
std::shared_ptr<Material> background_material;
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>> const fixed_meshline_policy_creators; // Meant to delay MeshlinePolicies creation at Step time instead of Parse time.

Board(PlaneSpace<std::vector<std::shared_ptr<Polygon>>>&& polygons, Params&& params, Timepoint* t);
Board(
PlaneSpace<std::vector<std::shared_ptr<Polygon>>>&& polygons,
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>>&& fixed_meshline_policy_creators,
std::shared_ptr<Material>&& background,
std::shared_ptr<Material>&& background_material,
Params&& params,
Timepoint* t);

Expand All @@ -94,6 +94,7 @@ class Board
void detect_diagonal_angles(Plane plane);
void detect_diagonal_zones(Plane plane);
void add_fixed_meshline_policies(Axis axis);
void adjust_mesh_to_materials(Axis axis);

void adjust_edges_to_materials();
void detect_diagonal_angles();
Expand All @@ -104,6 +105,7 @@ class Board
void detect_colinear_edges();
void detect_individual_edges();
void add_fixed_meshline_policies();
void adjust_mesh_to_materials();

/// Mesh resolution dependant detection tasks
///*************************************************************************
Expand All @@ -127,6 +129,7 @@ class Board
std::size_t get_mesh_cell_number() const;

private:
std::shared_ptr<Material> find_ambient_material(Axis axis, Coord const& coord) const;
std::shared_ptr<Material> find_ambient_material(Plane plane, Segment const& segment) const;
std::pair<std::shared_ptr<Material>, std::remove_const_t<decltype(Polygon::priority)>> find_ambient_material(Plane plane, Segment const& segment, std::shared_ptr<Polygon> const& current_polygon) const;
};
Expand Down
8 changes: 5 additions & 3 deletions src/domain/conflicts/conflict_diagonal_or_circular_zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace std;
ConflictDiagonalOrCircularZone::ConflictDiagonalOrCircularZone(Axis axis, vector<Angle*> const& angles, GlobalParams* global_params, Timepoint* t)
: Originator(t, {
.dmax = global_params->get_current_state().diagonal_dmax,
.lmin = global_params->get_current_state().lmin,
.lmin = global_params->get_lmin(axis),
.minimal_angle = global_params->get_current_state().consecutive_diagonal_minimal_angle,
.angles = angles })
, Conflict(Kind::DIAGONAL_OR_CIRCULAR_ZONE)
Expand Down Expand Up @@ -89,8 +89,10 @@ void ConflictDiagonalOrCircularZone::solve_intervals() {

for(Interval* interval : state.intervals) {
auto state_i = interval->get_current_state();
state_i.dmax = state.dmax;
interval->set_state(t, state_i);
if(state.dmax < state_i.dmax) {
state_i.dmax = state.dmax;
interval->set_state(t, state_i);
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/domain/conflicts/conflict_diagonal_or_circular_zone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ class ConflictDiagonalOrCircularZone
: public Originator<ConflictDiagonalOrCircularZoneState const>
, public Visitable<ConflictDiagonalOrCircularZone, EntityVisitor>
, public Conflict {
private:
GlobalParams* global_params;

public:
GlobalParams* global_params;
Axis const axis;

ConflictDiagonalOrCircularZone(Axis axis, std::vector<Angle*> const& angles, GlobalParams* global_params, Timepoint* t);
Expand Down
8 changes: 8 additions & 0 deletions src/domain/geometrics/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ static_assert(Axes[ZX][V] == X);
static_assert(Axes[XY][H] == X);
static_assert(Axes[XY][V] == Y);

//******************************************************************************
static_assert(Planes[X][H] == XY);
static_assert(Planes[X][V] == ZX);
static_assert(Planes[Y][H] == YZ);
static_assert(Planes[Y][V] == XY);
static_assert(Planes[Z][H] == ZX);
static_assert(Planes[Z][V] == YZ);

//******************************************************************************
optional<ViewAxis> transpose(Plane const plane, Axis const axis) noexcept {
switch(plane) {
Expand Down
7 changes: 7 additions & 0 deletions src/domain/geometrics/space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ inline static PlaneSpace<ViewAxisSpace<Axis const>> constexpr Axes {{
{ X, Y }
}};

//******************************************************************************
inline static AxisSpace<ViewAxisSpace<Plane const>> constexpr Planes {{
{ XY, ZX },
{ YZ, XY },
{ ZX, YZ }
}};

/// ViewAxis describe the orientation of Axis itself.
///*****************************************************************************
std::optional<ViewAxis> transpose(Plane const plane, Axis const axis) noexcept;
Expand Down
Loading
Loading