TriangleSelector: even more progress

This commit is contained in:
Lukas Matena 2020-06-22 11:45:51 +02:00
parent c3db84e382
commit bed28bb2ff
2 changed files with 27 additions and 16 deletions

View file

@ -859,6 +859,7 @@ void TriangleSelector::select_patch(const Vec3f& hit, int facet_start,
float radius_sqr, FacetSupportType new_state) float radius_sqr, FacetSupportType new_state)
{ {
assert(facet_start < m_orig_size_indices); assert(facet_start < m_orig_size_indices);
assert(is_approx(dir.norm(), 1.f));
// Save current cursor center, squared radius and camera direction, // Save current cursor center, squared radius and camera direction,
// so we don't have to pass it around. // so we don't have to pass it around.
@ -892,7 +893,6 @@ void TriangleSelector::select_patch(const Vec3f& hit, int facet_start,
// outside the cursor. // outside the cursor.
bool TriangleSelector::select_triangle(int facet_idx, FacetSupportType type, bool cursor_inside) bool TriangleSelector::select_triangle(int facet_idx, FacetSupportType type, bool cursor_inside)
{ {
bool out = false;
assert(facet_idx < int(m_triangles.size())); assert(facet_idx < int(m_triangles.size()));
Triangle& tr = m_triangles[facet_idx]; Triangle& tr = m_triangles[facet_idx];
@ -903,10 +903,12 @@ bool TriangleSelector::select_triangle(int facet_idx, FacetSupportType type, boo
int num_of_inside_vertices = vertices_inside(facet_idx); int num_of_inside_vertices = vertices_inside(facet_idx);
if (num_of_inside_vertices == 0 && ! cursor_inside) if (num_of_inside_vertices == 0
return out; // FIXME: just an edge can be inside && ! cursor_inside
&& ! is_edge_inside_cursor(facet_idx))
return false;
if (num_of_inside_vertices == 3) { if (vertices_inside(facet_idx) == 3) {
// dump any subdivision and select whole triangle // dump any subdivision and select whole triangle
undivide_triangle(facet_idx); undivide_triangle(facet_idx);
tr.set_state(type); tr.set_state(type);
@ -914,7 +916,6 @@ bool TriangleSelector::select_triangle(int facet_idx, FacetSupportType type, boo
// the triangle is partially inside, let's recursively divide it // the triangle is partially inside, let's recursively divide it
// (if not already) and try selecting its children. // (if not already) and try selecting its children.
if (! tr.is_split() && tr.get_state() == type) { if (! tr.is_split() && tr.get_state() == type) {
// This is leaf triangle that is already of correct type as a whole. // This is leaf triangle that is already of correct type as a whole.
// No need to split, all children would end up selected anyway. // No need to split, all children would end up selected anyway.
@ -1065,11 +1066,10 @@ bool TriangleSelector::faces_camera(int facet) const
{ {
assert(facet < m_orig_size_indices); assert(facet < m_orig_size_indices);
// The normal is cached in mesh->stl, use it. // The normal is cached in mesh->stl, use it.
return (m_mesh->stl.facet_start[facet].normal.dot(m_cursor.dir) > 0.); return (m_mesh->stl.facet_start[facet].normal.dot(m_cursor.dir) < 0.);
} }
// How many vertices of a triangle are inside the circle? // How many vertices of a triangle are inside the circle?
int TriangleSelector::vertices_inside(int facet_idx) const int TriangleSelector::vertices_inside(int facet_idx) const
{ {
@ -1082,11 +1082,27 @@ int TriangleSelector::vertices_inside(int facet_idx) const
} }
// Is mouse pointer inside a triangle? // Is edge inside cursor?
/*bool TriangleSelector::is_pointer_inside_triangle(int facet_idx) const bool TriangleSelector::is_edge_inside_cursor(int facet_idx) const
{ {
Vec3f pts[3];
for (int i=0; i<3; ++i)
pts[i] = m_vertices[m_triangles[facet_idx].verts_idxs[i]];
}*/ const Vec3f& p = m_cursor.center;
for (int side = 0; side < 3; ++side) {
const Vec3f& a = pts[side];
const Vec3f& b = pts[side<2 ? side+1 : 0];
Vec3f s = (b-a).normalized();
float t = (p-a).dot(s);
Vec3f vector = a+t*s - p;
float dist_sqr = vector.squaredNorm();
if (dist_sqr < m_cursor.radius_sqr && t>=0.f && t<=(b-a).norm())
return true;
}
return false;
}

View file

@ -113,19 +113,14 @@ private:
// Private functions: // Private functions:
bool select_triangle(int facet_idx, FacetSupportType type, bool select_triangle(int facet_idx, FacetSupportType type,
bool cursor_inside = false); bool cursor_inside = false);
bool is_point_inside_cursor(const Vec3f& point) const; bool is_point_inside_cursor(const Vec3f& point) const;
int vertices_inside(int facet_idx) const; int vertices_inside(int facet_idx) const;
bool faces_camera(int facet) const; bool faces_camera(int facet) const;
void undivide_triangle(int facet_idx); void undivide_triangle(int facet_idx);
bool split_triangle(int facet_idx); bool split_triangle(int facet_idx);
void remove_if_needless(int child_facet); void remove_if_needless(int child_facet);
bool is_pointer_in_triangle(int facet_idx) const; bool is_pointer_in_triangle(int facet_idx) const;
bool is_edge_inside_cursor(int facet_idx) const;
}; };