FDM supports gizmo uses neighbor data from stl_file

This commit is contained in:
Lukas Matena 2020-05-20 11:58:00 +02:00
parent 8afd273c4b
commit 581892cb0d
2 changed files with 8 additions and 37 deletions

View file

@ -205,7 +205,6 @@ void GLGizmoFdmSupports::update_from_model_object()
if (mv->is_model_part())
++num_of_volumes;
m_selected_facets.resize(num_of_volumes);
m_neighbors.resize(num_of_volumes);
m_ivas.clear();
m_ivas.resize(num_of_volumes);
@ -235,17 +234,6 @@ void GLGizmoFdmSupports::update_from_model_object()
}
update_vertex_buffers(mesh, volume_id, FacetSupportType::ENFORCER);
update_vertex_buffers(mesh, volume_id, FacetSupportType::BLOCKER);
m_neighbors[volume_id].resize(3 * mesh->its.indices.size());
// Prepare vector of vertex_index - facet_index pairs to quickly find adjacent facets
for (size_t i=0; i<mesh->its.indices.size(); ++i) {
const stl_triangle_vertex_indices& ind = mesh->its.indices[i];
m_neighbors[volume_id][3*i] = std::make_pair(ind(0), i);
m_neighbors[volume_id][3*i+1] = std::make_pair(ind(1), i);
m_neighbors[volume_id][3*i+2] = std::make_pair(ind(2), i);
}
std::sort(m_neighbors[volume_id].begin(), m_neighbors[volume_id].end());
}
}
@ -267,11 +255,6 @@ bool GLGizmoFdmSupports::is_mesh_point_clipped(const Vec3d& point) const
}
bool operator<(const GLGizmoFdmSupports::NeighborData& a, const GLGizmoFdmSupports::NeighborData& b) {
return a.first < b.first;
}
// Following function is called from GLCanvas3D to inform the gizmo about a mouse/keyboard event.
// The gizmo has an opportunity to react - if it does, it should return true so that the Canvas3D is
// aware that the event was reacted to and stops trying to make different sense of it. If the gizmo
@ -404,8 +387,6 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
const std::pair<Vec3f, size_t>& hit_and_facet = { closest_hit, closest_facet };
const std::vector<NeighborData>& neighbors = m_neighbors[mesh_id];
// Calculate direction from camera to the hit (in mesh coords):
Vec3f dir = ((trafo_matrix.inverse() * camera.get_position()).cast<float>() - hit_and_facet.first).normalized();
@ -419,28 +400,22 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
auto faces_camera = [&dir, &mesh](const size_t& facet) -> bool {
return (mesh->stl.facet_start[facet].normal.dot(dir) > 0.);
};
// Now start with the facet the pointer points to and check all adjacent facets. neighbors vector stores
// pairs of vertex_idx - facet_idx and is sorted with respect to the former. Neighboring facet index can be
// quickly found by finding a vertex in the list and read the respective facet ids.
// Now start with the facet the pointer points to and check all adjacent facets.
std::vector<size_t> facets_to_select{hit_and_facet.second};
NeighborData vertex = std::make_pair(0, 0);
std::vector<bool> visited(m_selected_facets[mesh_id].size(), false); // keep track of facets we already processed
size_t facet_idx = 0; // index into facets_to_select
auto it = neighbors.end();
while (facet_idx < facets_to_select.size()) {
size_t facet = facets_to_select[facet_idx];
if (! visited[facet]) {
// check all three vertices and in case they're close enough, find the remaining facets
// and add them to the list to be proccessed later
// check all three vertices and in case they're close enough,
// add neighboring facets to be proccessed later
for (size_t i=0; i<3; ++i) {
vertex.first = mesh->its.indices[facet](i); // vertex index
float dist = squared_distance_from_line(mesh->its.vertices[vertex.first]);
float dist = squared_distance_from_line(
mesh->its.vertices[mesh->its.indices[facet](i)]);
if (dist < limit) {
it = std::lower_bound(neighbors.begin(), neighbors.end(), vertex);
while (it != neighbors.end() && it->first == vertex.first) {
if (it->second != facet && faces_camera(it->second))
facets_to_select.push_back(it->second);
++it;
for (int n=0; n<3; ++n) {
if (faces_camera(mesh->stl.neighbors_start[facet].neighbor[n]))
facets_to_select.push_back(mesh->stl.neighbors_start[facet].neighbor[n]);
}
}
}
@ -809,7 +784,6 @@ void GLGizmoFdmSupports::on_set_state()
}
m_old_mo_id = -1;
m_ivas.clear();
m_neighbors.clear();
m_selected_facets.clear();
}
m_old_state = m_state;

View file

@ -49,7 +49,6 @@ public:
~GLGizmoFdmSupports() override;
void set_fdm_support_data(ModelObject* model_object, const Selection& selection);
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
using NeighborData = std::pair<size_t, size_t>;
private:
@ -86,8 +85,6 @@ private:
Button m_button_down = Button::None;
EState m_old_state = Off; // to be able to see that the gizmo has just been closed (see on_set_state)
std::vector<std::vector<NeighborData>> m_neighbors; // pairs of vertex_index - facet_index for each mesh
protected:
void on_set_state() override;
void on_start_dragging() override;