Introducing override function.

This commit is contained in:
iyaz 2013-04-03 02:01:41 +03:00
parent abafa5efc1
commit 11b69e0104
5 changed files with 130 additions and 7 deletions

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>317</width>
<height>369</height>
<height>409</height>
</rect>
</property>
<property name="windowTitle">
@ -177,6 +177,43 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="OverridePushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Override</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
@ -236,6 +273,12 @@
</item>
<item>
<widget class="QPushButton" name="ApplyAndClosePushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Apply and Close</string>
</property>

View File

@ -50,6 +50,7 @@ public slots:
void on_ShowROICheckBox_stateChanged(int state);
void on_ShowAsSphereCheckBox_stateChanged(int state);
void on_ActivatePivotingCheckBox_stateChanged(int state);
void on_OverridePushButton_clicked();
void on_SaveROIPushButton_clicked();
void on_ReadROIPushButton_clicked();
void dock_widget_visibility_changed(bool visible);
@ -122,6 +123,8 @@ void Polyhedron_demo_edit_polyhedron_plugin::init(QMainWindow* mainWindow, Scene
connect(ui_widget->ShowROICheckBox, SIGNAL(stateChanged(int)), this, SLOT(on_ShowROICheckBox_stateChanged(int)));
connect(ui_widget->ShowAsSphereCheckBox, SIGNAL(stateChanged(int)), this, SLOT(on_ShowAsSphereCheckBox_stateChanged(int)));
connect(ui_widget->ActivatePivotingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(on_ActivatePivotingCheckBox_stateChanged(int)));
connect(ui_widget->OverridePushButton, SIGNAL(clicked()), this, SLOT(on_OverridePushButton_clicked()));
connect(ui_widget->SaveROIPushButton, SIGNAL(clicked()), this, SLOT(on_SaveROIPushButton_clicked()));
connect(ui_widget->ReadROIPushButton, SIGNAL(clicked()), this, SLOT(on_ReadROIPushButton_clicked()));
connect(dock_widget, SIGNAL(visibilityChanged(bool)), this, SLOT(dock_widget_visibility_changed(bool)) );
@ -234,6 +237,14 @@ void Polyhedron_demo_edit_polyhedron_plugin::on_ActivatePivotingCheckBox_stateCh
scene->itemChanged(edit_item);
}
}
void Polyhedron_demo_edit_polyhedron_plugin::on_OverridePushButton_clicked()
{
int item_id = scene->mainSelectionIndex();
Scene_edit_polyhedron_item* edit_item = qobject_cast<Scene_edit_polyhedron_item*>(scene->item(item_id));
if(!edit_item) return; // the selected item is not of the right type
edit_item->override_deform_object();
}
void Polyhedron_demo_edit_polyhedron_plugin::on_SaveROIPushButton_clicked()
{

View File

@ -190,8 +190,8 @@ bool Scene_edit_polyhedron_item::eventFilter(QObject *target, QEvent *event)
void Scene_edit_polyhedron_item::draw() const {
poly_item->direct_draw();
CGAL::GL::Color color;
//color.set_rgb_color(0.f, 0.f, 0.f);
//poly_item->direct_draw_edges();
color.set_rgb_color(0.f, 0.f, 0.f);
poly_item->direct_draw_edges();
CGAL::GL::Point_size point_size; point_size.set_point_size(5);
color.set_rgb_color(0, 1.f, 0);

View File

@ -402,6 +402,30 @@ public:
bool show_as_sphere() const
{ return ui_widget->ShowAsSphereCheckBox->isChecked(); }
void override_deform_object()
{
deform_mesh.override_halfedge_graph();
Deform_mesh::Roi_iterator rb, re;
for(boost::tie(rb, re) = deform_mesh.roi_vertices(); rb != re; ++rb)
{
original_positions[(*rb)->id()] = (*rb)->point();
}
for(Handle_group_data_list::iterator it = handle_frame_map.begin(); it != handle_frame_map.end(); ++it)
{
it->frame_initial_center = calculate_original_center(it->handle_group);
it->frame->blockSignals(true);
it->frame->setOrientation(qglviewer::Quaternion());
it->frame->setPosition(it->frame_initial_center);
it->frame->blockSignals(false);
it->bbox = calculate_bbox(it->handle_group);
}
}
protected:
// Deformation related functions //
void print_message(const QString& message)
@ -439,7 +463,7 @@ protected:
void process_selection(vertex_descriptor v, int k_ring, bool is_roi, bool is_insert, bool use_euclidean)
{
std::cout << "Process k-ring: " << k_ring << " roi: " << is_roi << " insert: " << is_insert << std::endl;
// std::cout << "Process k-ring: " << k_ring << " roi: " << is_roi << " insert: " << is_insert << std::endl;
std::map<vertex_descriptor, int> neighs = use_euclidean ?
extract_k_ring_with_distance(*polyhedron(), v, k_ring) :

View File

@ -165,6 +165,7 @@ private:
bool last_preprocess_successful; ///< stores the result of last call to preprocess()
Handle_group_container handle_group_list; ///< user specified handles
Weight_calculator weight_calculator;
private:
Deform_mesh(const Self& s) { }
@ -190,7 +191,8 @@ public:
double tolerance = 1e-4,
Weight_calculator weight_calculator = Weight_calculator())
: polyhedron(polyhedron), vertex_index_map(vertex_index_map), edge_index_map(edge_index_map),
iterations(iterations), tolerance(tolerance), need_preprocess(true), last_preprocess_successful(false),
iterations(iterations), tolerance(tolerance), weight_calculator(weight_calculator),
need_preprocess(true), last_preprocess_successful(false),
is_roi_map(std::vector<bool>(boost::num_vertices(polyhedron), false)),
is_hdl_map(std::vector<bool>(boost::num_vertices(polyhedron), false)),
ros_id_map(std::vector<std::size_t>(boost::num_vertices(polyhedron), -1))
@ -214,7 +216,7 @@ public:
edge_weight.reserve(boost::num_edges(polyhedron));
for(boost::tie(eb, ee) = boost::edges(polyhedron); eb != ee; ++eb)
{
edge_weight.push_back(weight_calculator(*eb, polyhedron));
edge_weight.push_back(this->weight_calculator(*eb, polyhedron));
}
}
@ -547,7 +549,6 @@ public:
*/
void deform(unsigned int iterations, double tolerance)
{
// CGAL_precondition(!need_preprocess || !"preprocess() need to be called before deforming!");
if(need_preprocess) { preprocess(); }
if(!last_preprocess_successful) {
@ -637,6 +638,50 @@ public:
*/
const Polyhedron& halfedge_graph() const
{ return polyhedron; }
/**
* Makes current positions as original positions. Effect of calling this funtion is equal to creating a new deformation
* object with current polyhedron and transfering region-of-interest and handles.
* \note There should not be any need for preprocess when this function is called, otherwise it just returns.
*/
void override_halfedge_graph()
{
if(roi.empty()) { return; } // no ROI to override
if(need_preprocess) { preprocess(); } // the roi should be preprocessed since we are using original_position vec
Roi_iterator rb, re;
for(boost::tie(rb, re) = roi_vertices(); rb != re; ++rb)
{
original[ros_id(*rb)] = (*rb)->point();
}
// now I need to compute weights for edges incident to roi vertices
std::vector<bool> is_weight_computed(boost::num_edges(polyhedron), false);
for(boost::tie(rb, re) = roi_vertices(); rb != re; ++rb)
{
in_edge_iterator e, e_end;
for (boost::tie(e,e_end) = boost::in_edges(*rb, polyhedron); e != e_end; e++)
{
std::size_t id_e = id(*e);
if(is_weight_computed[id_e]) { continue; }
edge_weight[id_e] = weight_calculator(*e, polyhedron);
is_weight_computed[id_e] = true;
edge_descriptor e_opp = CGAL::opposite_edge(*e, polyhedron);
std::size_t id_e_opp = id(e_opp);
edge_weight[id_e_opp] = weight_calculator(e_opp, polyhedron);
is_weight_computed[id_e_opp] = true;
}
}
// also set rotation matrix to identity
std::fill(rot_mtr.begin(), rot_mtr.end(), Eigen::Matrix3d().setIdentity());
need_preprocess = true; // now we need reprocess
}
/// @} Utilities