Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

surface_deformation: check that handle vertices are in the free vertices area #69

Merged
merged 1 commit into from
Dec 13, 2017
Merged
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
2 changes: 1 addition & 1 deletion schnapps/core/schnapps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Plugin* SCHNApps::enable_plugin(const QString& plugin_name)
// set the plugin with correct parameters (name, filepath, SCHNApps)
// plugin->set_name(plugin_name);
if (plugin_name != plugin->get_name())
cgogn_log_warning("SCHNApps::enable_plugin") << "plugin name incompatibility: "<< plugin_name.toStdString() << " != " << plugin->get_name().toStdString();
cgogn_log_warning("SCHNApps::enable_plugin") << "plugin name incompatibility: " << plugin_name.toStdString() << " != " << plugin->get_name().toStdString();
plugin->set_file_path(plugin_file_path);
plugin->set_schnapps(this);

Expand Down
26 changes: 24 additions & 2 deletions schnapps/plugins/surface_deformation/map_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct MapParameters
solver_ready_ = false;
}

void build_solver()
bool build_solver()
{
if (initialized_ && !solver_ready_ &&
free_vertex_set_ && free_vertex_set_->get_nb_cells() > 0 &&
Expand All @@ -213,12 +213,32 @@ struct MapParameters
CMap2* map2 = map_->get_map();
CMap2::CellMarkerStore<CMap2::Vertex::ORBIT> working_vertices_marker(*map2);

// check that handle vertices are surrounded only by handle or free vertices
bool handle_ok = true;
map2->foreach_cell([&] (CMap2::Vertex v) -> bool
{
if (handle_vertex_set_->is_selected(v))
{
map2->foreach_adjacent_vertex_through_edge(v, [&] (CMap2::Vertex av) -> bool
{
if (!handle_vertex_set_->is_selected(av) && !free_vertex_set_->is_selected(av))
handle_ok = false;
return handle_ok;
});
}
return handle_ok;
});
if (!handle_ok)
{
cgogn_log_warning("surface_deformation") << "Handle is not defined in the free area";
return false;
}

// build the cell cache of working area vertices (and mark them)
working_cells_->build<CMap2::Vertex>([&] (CMap2::Vertex v) -> bool
{
if (handle_vertex_set_->is_selected(v)) // handle vertices
{
// TODO: check that it is surrounded only by handle or free vertices
working_vertices_marker.mark(v);
return true;
}
Expand Down Expand Up @@ -335,6 +355,8 @@ struct MapParameters

solver_ready_ = true;
}

return solver_ready_;
}

private:
Expand Down
85 changes: 57 additions & 28 deletions schnapps/plugins/surface_deformation/surface_deformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,9 @@ bool Plugin_SurfaceDeformation::keyPress(View* view, QKeyEvent* event)
{
const MapParameters& p = get_parameters(mhg);
if (!dragging_ && p.get_handle_vertex_set() && p.get_handle_vertex_set()->get_nb_cells() > 0)
{
dragging_ = true;
drag_init_ = false;
view->setMouseTracking(true);
view->get_current_camera()->disable_views_bb_fitting();
}
start_dragging(view);
else
{
dragging_ = false;
drag_init_ = false;
view->setMouseTracking(false);
view->get_current_camera()->enable_views_bb_fitting();
}
stop_dragging(view);
}
break;
}
Expand Down Expand Up @@ -151,6 +141,22 @@ bool Plugin_SurfaceDeformation::keyPress(View* view, QKeyEvent* event)
return true;
}

void Plugin_SurfaceDeformation::start_dragging(View* view)
{
dragging_ = true;
drag_init_ = false;
view->setMouseTracking(true);
view->get_current_camera()->disable_views_bb_fitting();
}

void Plugin_SurfaceDeformation::stop_dragging(View* view)
{
dragging_ = false;
drag_init_ = false;
view->setMouseTracking(false);
view->get_current_camera()->enable_views_bb_fitting();
}

bool Plugin_SurfaceDeformation::mouseMove(View* view, QMouseEvent* event)
{
if (dragging_)
Expand All @@ -177,25 +183,37 @@ bool Plugin_SurfaceDeformation::mouseMove(View* view, QMouseEvent* event)
}
else
{
qoglviewer::Vec pp(event->x(), event->y(), drag_z_);
qoglviewer::Vec qq = view->camera()->unprojectedCoordinatesOf(pp);

qoglviewer::Vec vec = qq - drag_previous_;
VEC3 t(vec.x, vec.y, vec.z);
p.handle_vertex_set_->foreach_cell([&] (CMap2::Vertex v)
if (p.initialized_)
{
p.position_[v] += t;
});
qoglviewer::Vec pp(event->x(), event->y(), drag_z_);
qoglviewer::Vec qq = view->camera()->unprojectedCoordinatesOf(pp);

drag_previous_ = qq;
qoglviewer::Vec vec = qq - drag_previous_;
VEC3 t(vec.x, vec.y, vec.z);
p.handle_vertex_set_->foreach_cell([&] (CMap2::Vertex v)
{
p.position_[v] += t;
});

if (p.initialized_)
as_rigid_as_possible(mhg);
drag_previous_ = qq;

mhg->notify_attribute_change(CMap2::Vertex::ORBIT, p.get_position_attribute_name());
if (as_rigid_as_possible(mhg))
{
mhg->notify_attribute_change(CMap2::Vertex::ORBIT, p.get_position_attribute_name());

for (View* view : mhg->get_linked_views())
view->update();
for (View* view : mhg->get_linked_views())
view->update();
}
else
{
// undo handle displacement & stop dragging
p.handle_vertex_set_->foreach_cell([&] (CMap2::Vertex v)
{
p.position_[v] -= t;
});
stop_dragging(view);
}
}
}
}
}
Expand Down Expand Up @@ -401,15 +419,16 @@ void Plugin_SurfaceDeformation::stop(MapHandlerGen* map, bool update_dock_tab)
}
}

void Plugin_SurfaceDeformation::as_rigid_as_possible(MapHandlerGen* map)
bool Plugin_SurfaceDeformation::as_rigid_as_possible(MapHandlerGen* map)
{
if (map && map->dimension() == 2)
{
MapParameters& p = get_parameters(map);
if (p.initialized_)
{
if (!p.solver_ready_)
p.build_solver();
if (!p.build_solver())
return false;

CMap2* map2 = p.map_->get_map();

Expand Down Expand Up @@ -520,8 +539,18 @@ void Plugin_SurfaceDeformation::as_rigid_as_possible(MapHandlerGen* map)
},
*p.working_cells_
);

return true;
}
else
{
cgogn_log_warning("surface_deformation") << "initial state not initialized";
return false;
}
}

cgogn_log_warning("surface_deformation") << "wrong map dimension";
return false;
}

} // namespace plugin_surface_deformation
Expand Down
5 changes: 4 additions & 1 deletion schnapps/plugins/surface_deformation/surface_deformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class SCHNAPPS_PLUGIN_SURFACE_DEFORMATION_API Plugin_SurfaceDeformation : public

inline void resizeGL(View*, int, int) override {}

void start_dragging(View* view);
void stop_dragging(View* view);

void view_linked(View*) override;
void view_unlinked(View*) override;

Expand Down Expand Up @@ -102,7 +105,7 @@ public slots:
void initialize(MapHandlerGen* map, bool update_dock_tab);
void stop(MapHandlerGen* map, bool update_dock_tab);

void as_rigid_as_possible(MapHandlerGen* map);
bool as_rigid_as_possible(MapHandlerGen* map);

private:

Expand Down