Added seed fill for MMU segmentation

This commit is contained in:
Lukáš Hejl 2021-04-27 06:48:09 +02:00
parent be1b4ce18c
commit 576c5b78e9
8 changed files with 228 additions and 174 deletions

View file

@ -29,13 +29,18 @@ public:
explicit TriangleSelector(const TriangleMesh& mesh);
// Select all triangles fully inside the circle, subdivide where needed.
void select_patch(const Vec3f& hit, // point where to start
int facet_start, // facet that point belongs to
const Vec3f& source, // camera position (mesh coords)
float radius, // radius of the cursor
CursorType type, // current type of cursor
void select_patch(const Vec3f &hit, // point where to start
int facet_start, // facet that point belongs to
const Vec3f &source, // camera position (mesh coords)
float radius, // radius of the cursor
CursorType type, // current type of cursor
EnforcerBlockerType new_state, // enforcer or blocker?
const Transform3d& trafo); // matrix to get from mesh to world
const Transform3d &trafo, // matrix to get from mesh to world
bool triangle_splitting); // If triangles will be split base on the cursor or not
void seed_fill_select_triangles(const Vec3f &hit, // point where to start
int facet_start, // facet that point belongs to
float seed_fill_angle); // the maximal angle between two facets to be painted by the same color
// Get facets currently in the given state.
indexed_triangle_set get_facets(EnforcerBlockerType state) const;
@ -56,6 +61,11 @@ public:
// Load serialized data. Assumes that correct mesh is loaded.
void deserialize(const std::map<int, std::vector<bool>> data);
// For all triangles, remove the flag indicating that the triangle was selected by seed fill.
void seed_fill_unselect_all_triangles();
// For all triangles selected by seed fill, set new EnforcerBlockerType and remove flag indicating that triangle was selected by seed fill.
void seed_fill_apply_on_triangles(EnforcerBlockerType new_state);
protected:
// Triangle and info about how it's split.
@ -90,6 +100,12 @@ protected:
void set_state(EnforcerBlockerType type) { assert(! is_split()); state = type; }
EnforcerBlockerType get_state() const { assert(! is_split()); return state; }
// Set if the triangle has been selected or unselected by seed fill.
void select_by_seed_fill() { assert(! is_split()); m_selected_by_seed_fill = true; }
void unselect_by_seed_fill() { assert(! is_split()); m_selected_by_seed_fill = false; }
// Get if the triangle has been selected or not by seed fill.
bool is_selected_by_seed_fill() const { assert(! is_split()); return m_selected_by_seed_fill; }
// Get info on how it's split.
bool is_split() const { return number_of_split_sides() != 0; }
int number_of_split_sides() const { return number_of_splits; }
@ -101,6 +117,7 @@ protected:
int number_of_splits;
int special_side_idx;
EnforcerBlockerType state;
bool m_selected_by_seed_fill = false;
// How many children were spawned during last split?
// Is not reset on remerging the triangle.
@ -153,8 +170,7 @@ protected:
float m_old_cursor_radius_sqr;
// Private functions:
bool select_triangle(int facet_idx, EnforcerBlockerType type,
bool recursive_call = false);
bool select_triangle(int facet_idx, EnforcerBlockerType type, bool recursive_call = false, bool triangle_splitting = true);
int vertices_inside(int facet_idx) const;
bool faces_camera(int facet) const;
void undivide_triangle(int facet_idx);