mirror of https://github.com/CGAL/cgal
Add a widget for filtering c3t3 subdomains
This commit is contained in:
parent
663ebce7bb
commit
ec41af7e33
|
|
@ -14,18 +14,34 @@
|
|||
<string>Filter Domain</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="test_label">
|
||||
<spacer name="horizontalSpacer">
|
||||
<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="resetButton">
|
||||
<property name="text">
|
||||
<string>plouf</string>
|
||||
<string>Reset Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
|
|||
|
|
@ -75,16 +75,60 @@ public Q_SLOTS:
|
|||
if(!c3t3_item)
|
||||
return;
|
||||
|
||||
|
||||
for (std::set<int>::iterator it = c3t3_item->subdomain_indices().begin(),
|
||||
end = c3t3_item->subdomain_indices().end(); it != end; ++it)
|
||||
{
|
||||
int index = *it;
|
||||
QPushButton* button = new QPushButton(tr("%1").arg(index));
|
||||
buttons.push_back(button);
|
||||
button->setCheckable(true);
|
||||
button->setChecked(true);
|
||||
QColor color = c3t3_item->getSubdomainIndexColor(index);
|
||||
QString s("QPushButton { font-weight: bold; background: #"
|
||||
+ QString::number(color.red(),16)
|
||||
+ QString::number(color.green(),16)
|
||||
+ QString::number(color.blue(),16)
|
||||
+ "; }");
|
||||
|
||||
button->setStyleSheet(s);
|
||||
connect(button, &QPushButton::toggled, [index, c3t3_item](bool){
|
||||
c3t3_item->switchVisibleSubdomain(index);
|
||||
});
|
||||
|
||||
dock_widget->horizontalLayout->addWidget(button);
|
||||
}
|
||||
|
||||
|
||||
auto cleanup = [this, c3t3_item](){
|
||||
while(!buttons.empty())
|
||||
{
|
||||
auto button = buttons.back();
|
||||
buttons.pop_back();
|
||||
dock_widget->horizontalLayout->removeWidget(button);
|
||||
buttons.removeAll(button);
|
||||
delete button;
|
||||
}
|
||||
dock_widget->hide();
|
||||
//todo : trouver comment disconnect clean-up, pour pas que ça se connect 36 fois qunad tu appuies sur reset.
|
||||
std::cout<<"cleaned."<<std::endl;
|
||||
};
|
||||
connect(c3t3_item, &Scene_c3t3_item::aboutToBeDestroyed, cleanup);
|
||||
//Is it safe ? Will they be called in that order ?
|
||||
connect(dock_widget->resetButton, &QPushButton::clicked, [this, cleanup](){
|
||||
cleanup();
|
||||
filter();
|
||||
});
|
||||
|
||||
dock_widget->show();
|
||||
dock_widget->raise();
|
||||
|
||||
dock_widget->test_label->setText(QString("This item has %1 subdomains.").arg(c3t3_item->subdomain_indices().size()));
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
QAction* actionFilter;
|
||||
DockWidget* dock_widget;
|
||||
QVector<QPushButton*> buttons;
|
||||
|
||||
};
|
||||
|
||||
#include "Mesh_3_filter_domain_plugin.moc"
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <CGAL/Qt/qglviewer.h>
|
||||
|
||||
#include <boost/iterator/function_output_iterator.hpp>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
#include <CGAL/AABB_tree.h>
|
||||
#include <CGAL/AABB_traits.h>
|
||||
|
|
@ -501,6 +502,8 @@ struct Scene_c3t3_item_priv {
|
|||
Tree tree;
|
||||
QVector<QColor> colors;
|
||||
QVector<QColor> colors_subdomains;
|
||||
boost::dynamic_bitset<> visible_subdomain;
|
||||
|
||||
bool show_tetrahedra;
|
||||
bool is_aabb_tree_built;
|
||||
bool cnc_are_shown;
|
||||
|
|
@ -659,6 +662,7 @@ Scene_c3t3_item::c3t3_changed()
|
|||
// Fill indices map and get max subdomain value
|
||||
d->surface_patch_indices_.clear();
|
||||
d->subdomain_indices_.clear();
|
||||
d->visible_subdomain.clear();
|
||||
|
||||
int max = 0;
|
||||
for (C3t3::Cells_in_complex_iterator cit = this->c3t3().cells_in_complex_begin(),
|
||||
|
|
@ -668,6 +672,7 @@ Scene_c3t3_item::c3t3_changed()
|
|||
d->subdomain_indices_.insert(cit->subdomain_index());
|
||||
}
|
||||
const int max_subdomain_index = max;
|
||||
d->visible_subdomain.resize(max_subdomain_index+1, true);
|
||||
for (C3t3::Facets_in_complex_iterator fit = this->c3t3().facets_in_complex_begin(),
|
||||
end = this->c3t3().facets_in_complex_end(); fit != end; ++fit)
|
||||
{
|
||||
|
|
@ -2130,10 +2135,30 @@ std::size_t Scene_c3t3_item::number_of_patches() const
|
|||
return d->surface_patch_indices_.size();
|
||||
}
|
||||
|
||||
std::set<int> Scene_c3t3_item::subdomain_indices() const
|
||||
const std::set<int>& Scene_c3t3_item::subdomain_indices() const
|
||||
{
|
||||
return d->subdomain_indices_;
|
||||
}
|
||||
|
||||
QColor Scene_c3t3_item::getSubdomainIndexColor(int i) const
|
||||
{
|
||||
return d->colors_subdomains[i];
|
||||
}
|
||||
|
||||
void Scene_c3t3_item::switchVisibleSubdomain(int i)
|
||||
{
|
||||
d->visible_subdomain[i] = !d->visible_subdomain[i];
|
||||
\
|
||||
//to remove
|
||||
if(d->visible_subdomain[i])
|
||||
{
|
||||
std::cout<<"Subdomain "<<i<<"is visible"<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"Subdomain "<<i<<"is hidden"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
#include "Scene_c3t3_item.moc"
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,8 @@ public:
|
|||
bool keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
|
||||
bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE;
|
||||
std::size_t number_of_patches() const;
|
||||
std::set<int> subdomain_indices() const;
|
||||
const std::set<int> &subdomain_indices() const;
|
||||
QColor getSubdomainIndexColor(int i) const;
|
||||
public Q_SLOTS:
|
||||
|
||||
void on_spheres_color_changed();
|
||||
|
|
@ -145,6 +146,7 @@ public:
|
|||
void show_grid(bool b);
|
||||
void show_cnc(bool b);
|
||||
|
||||
|
||||
virtual QPixmap graphicalToolTip() const Q_DECL_OVERRIDE;
|
||||
|
||||
void update_histogram();
|
||||
|
|
@ -163,6 +165,8 @@ public:
|
|||
void set_detect_borders(bool b);
|
||||
bool get_detect_borders();
|
||||
|
||||
void switchVisibleSubdomain(int);
|
||||
|
||||
void itemAboutToBeDestroyed(Scene_item *) Q_DECL_OVERRIDE;
|
||||
|
||||
void initializeBuffers(Viewer_interface *) const Q_DECL_OVERRIDE;
|
||||
|
|
|
|||
Loading…
Reference in New Issue