mirror of https://github.com/CGAL/cgal
Updated plugin
This commit is contained in:
parent
f3a703ba2c
commit
e8e8a4755d
|
|
@ -140,8 +140,8 @@ public:
|
|||
connect(ui_widget.number_of_trials, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(on_update_number_of_trials()));
|
||||
|
||||
connect(ui_widget.add_new_class, SIGNAL(clicked()), this,
|
||||
SLOT(on_add_new_class_clicked()));
|
||||
connect(ui_widget.add_new_label, SIGNAL(clicked()), this,
|
||||
SLOT(on_add_new_label_clicked()));
|
||||
connect(ui_widget.reset_training_sets, SIGNAL(clicked()), this,
|
||||
SLOT(on_reset_training_sets_clicked()));
|
||||
connect(ui_widget.validate_selection, SIGNAL(clicked()), this,
|
||||
|
|
@ -149,10 +149,10 @@ public:
|
|||
connect(ui_widget.train, SIGNAL(clicked()), this,
|
||||
SLOT(on_train_clicked()));
|
||||
|
||||
connect(ui_widget.selected_attribute, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(on_selected_attribute_changed(int)));
|
||||
connect(ui_widget.attribute_weight, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(on_attribute_weight_changed(int)));
|
||||
connect(ui_widget.selected_feature, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(on_selected_feature_changed(int)));
|
||||
connect(ui_widget.feature_weight, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(on_feature_weight_changed(int)));
|
||||
|
||||
QObject* scene_obj = dynamic_cast<QObject*>(scene_interface);
|
||||
if(scene_obj)
|
||||
|
|
@ -258,7 +258,7 @@ public Q_SLOTS:
|
|||
ui_widget.number_of_trials->setValue((int)(item->number_of_trials()));
|
||||
ui_widget.smoothingDoubleSpinBox->setValue((int)(item->smoothing()));
|
||||
|
||||
// Clear class types
|
||||
// Clear class labels
|
||||
for (std::size_t i = 0; i < class_rows.size(); ++ i)
|
||||
{
|
||||
|
||||
|
|
@ -277,10 +277,10 @@ public Q_SLOTS:
|
|||
}
|
||||
class_rows.clear();
|
||||
|
||||
// Add types
|
||||
for (std::size_t i = 0; i < item->types().size(); ++ i)
|
||||
add_new_class (ClassRow (dock_widget, item->types()[i].first->name().c_str(),
|
||||
item->types()[i].second));
|
||||
// Add labels
|
||||
for (std::size_t i = 0; i < item->labels().size(); ++ i)
|
||||
add_new_label (ClassRow (dock_widget, item->labels()[i].first->name().c_str(),
|
||||
item->labels()[i].second));
|
||||
|
||||
// Enabled classif if features computed
|
||||
if (!(item->features_computed()))
|
||||
|
|
@ -293,13 +293,13 @@ public Q_SLOTS:
|
|||
ui_widget.display->addItem("Real colors");
|
||||
ui_widget.display->addItem("Classification");
|
||||
ui_widget.display->addItem("Training sets");
|
||||
ui_widget.selected_attribute->clear();
|
||||
item->fill_display_combo_box(ui_widget.display, ui_widget.selected_attribute);
|
||||
ui_widget.selected_feature->clear();
|
||||
item->fill_display_combo_box(ui_widget.display, ui_widget.selected_feature);
|
||||
if (index >= ui_widget.display->count())
|
||||
ui_widget.display->setCurrentIndex(1);
|
||||
else
|
||||
ui_widget.display->setCurrentIndex(index);
|
||||
ui_widget.selected_attribute->setCurrentIndex(0);
|
||||
ui_widget.selected_feature->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -574,7 +574,7 @@ public Q_SLOTS:
|
|||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void on_add_new_class_clicked()
|
||||
void on_add_new_label_clicked()
|
||||
{
|
||||
Scene_point_set_classification_item* classification_item
|
||||
= get_classification_item();
|
||||
|
|
@ -587,19 +587,19 @@ public Q_SLOTS:
|
|||
bool ok;
|
||||
QString name =
|
||||
QInputDialog::getText((QWidget*)mw,
|
||||
tr("Add new classification type"), // dialog title
|
||||
tr("Add new label"), // dialog title
|
||||
tr("Name:"), // field label
|
||||
QLineEdit::Normal,
|
||||
tr("type%1").arg(class_rows.size() + 1),
|
||||
tr("label%1").arg(class_rows.size() + 1),
|
||||
&ok);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
add_new_class (ClassRow (dock_widget, name.toStdString().c_str(),
|
||||
add_new_label (ClassRow (dock_widget, name.toStdString().c_str(),
|
||||
QColor (192 + rand() % 60,
|
||||
192 + rand() % 60,
|
||||
192 + rand() % 60)));
|
||||
classification_item->add_new_type (class_rows.back().label->text().toStdString().c_str(),
|
||||
classification_item->add_new_label (class_rows.back().label->text().toStdString().c_str(),
|
||||
class_rows.back().color);
|
||||
|
||||
|
||||
|
|
@ -655,7 +655,7 @@ public Q_SLOTS:
|
|||
update_plugin_from_item(classification_item);
|
||||
}
|
||||
|
||||
void add_new_class (const ClassRow& class_row)
|
||||
void add_new_label (const ClassRow& class_row)
|
||||
{
|
||||
class_rows.push_back (class_row);
|
||||
int position = static_cast<int>(class_rows.size());
|
||||
|
|
@ -696,7 +696,7 @@ public Q_SLOTS:
|
|||
ui_widget.gridLayout_3->getItemPosition(index, &row_index, &column_index, &row_span, &column_span);
|
||||
--row_index;
|
||||
|
||||
classification_item->remove_type (class_rows[row_index].label->text().toStdString().c_str());
|
||||
classification_item->remove_label (class_rows[row_index].label->text().toStdString().c_str());
|
||||
|
||||
ui_widget.gridLayout_3->removeWidget (class_rows[row_index].label);
|
||||
delete class_rows[row_index].label;
|
||||
|
|
@ -745,9 +745,9 @@ public Q_SLOTS:
|
|||
-- row_index;
|
||||
|
||||
QColor color = class_rows[row_index].color;
|
||||
color = QColorDialog::getColor(color, (QWidget*)mw, "Change of color of classification type");
|
||||
color = QColorDialog::getColor(color, (QWidget*)mw, "Change of color of label");
|
||||
class_rows[row_index].change_color (color);
|
||||
classification_item->change_type_color (class_rows[row_index].label->text().toStdString().c_str(),
|
||||
classification_item->change_label_color (class_rows[row_index].label->text().toStdString().c_str(),
|
||||
color);
|
||||
|
||||
scene->itemChanged(classification_item);
|
||||
|
|
@ -772,7 +772,7 @@ public Q_SLOTS:
|
|||
(class_rows[row_index].label->text().toStdString().c_str());
|
||||
}
|
||||
|
||||
void on_selected_attribute_changed(int v)
|
||||
void on_selected_feature_changed(int v)
|
||||
{
|
||||
Scene_point_set_classification_item* classification_item
|
||||
= get_classification_item();
|
||||
|
|
@ -782,26 +782,26 @@ public Q_SLOTS:
|
|||
return;
|
||||
}
|
||||
|
||||
if (classification_item->number_of_attributes() <= (std::size_t)v)
|
||||
if (classification_item->number_of_features() <= (std::size_t)v)
|
||||
return;
|
||||
|
||||
Scene_point_set_classification_item::Attribute_handle
|
||||
att = classification_item->attribute(v);
|
||||
Scene_point_set_classification_item::Feature_handle
|
||||
att = classification_item->feature(v);
|
||||
|
||||
if (att == Scene_point_set_classification_item::Attribute_handle())
|
||||
if (att == Scene_point_set_classification_item::Feature_handle())
|
||||
return;
|
||||
|
||||
// std::cerr << att->weight
|
||||
// << " " << (int)(1001. * 2. * std::atan(att->weight) / CGAL_PI) << std::endl;
|
||||
ui_widget.attribute_weight->setValue ((int)(1001. * 2. * std::atan(att->weight()) / CGAL_PI));
|
||||
ui_widget.feature_weight->setValue ((int)(1001. * 2. * std::atan(att->weight()) / CGAL_PI));
|
||||
|
||||
for (std::size_t i = 0; i < classification_item->types().size(); ++ i)
|
||||
for (std::size_t i = 0; i < classification_item->labels().size(); ++ i)
|
||||
{
|
||||
CGAL::Classification::Attribute::Effect
|
||||
eff = classification_item->types()[i].first->attribute_effect(att);
|
||||
if (eff == CGAL::Classification::Attribute::PENALIZING)
|
||||
CGAL::Classification::Feature::Effect
|
||||
eff = classification_item->labels()[i].first->feature_effect(att);
|
||||
if (eff == CGAL::Classification::Feature::PENALIZING)
|
||||
class_rows[i].effect->setCurrentIndex(0);
|
||||
else if (eff == CGAL::Classification::Attribute::NEUTRAL)
|
||||
else if (eff == CGAL::Classification::Feature::NEUTRAL)
|
||||
class_rows[i].effect->setCurrentIndex(1);
|
||||
else
|
||||
class_rows[i].effect->setCurrentIndex(2);
|
||||
|
|
@ -809,7 +809,7 @@ public Q_SLOTS:
|
|||
}
|
||||
|
||||
|
||||
void on_attribute_weight_changed(int v)
|
||||
void on_feature_weight_changed(int v)
|
||||
{
|
||||
Scene_point_set_classification_item* classification_item
|
||||
= get_classification_item();
|
||||
|
|
@ -818,10 +818,10 @@ public Q_SLOTS:
|
|||
print_message("Error: there is no point set classification item!");
|
||||
return;
|
||||
}
|
||||
Scene_point_set_classification_item::Attribute_handle
|
||||
att = classification_item->attribute(ui_widget.selected_attribute->currentIndex());
|
||||
Scene_point_set_classification_item::Feature_handle
|
||||
att = classification_item->feature(ui_widget.selected_feature->currentIndex());
|
||||
|
||||
if (att == Scene_point_set_classification_item::Attribute_handle())
|
||||
if (att == Scene_point_set_classification_item::Feature_handle())
|
||||
return;
|
||||
|
||||
att->set_weight(std::tan ((CGAL_PI/2.) * v / 1001.));
|
||||
|
|
@ -840,10 +840,10 @@ public Q_SLOTS:
|
|||
print_message("Error: there is no point set classification item!");
|
||||
return;
|
||||
}
|
||||
Scene_point_set_classification_item::Attribute_handle
|
||||
att = classification_item->attribute(ui_widget.selected_attribute->currentIndex());
|
||||
Scene_point_set_classification_item::Feature_handle
|
||||
att = classification_item->feature(ui_widget.selected_feature->currentIndex());
|
||||
|
||||
if (att == Scene_point_set_classification_item::Attribute_handle())
|
||||
if (att == Scene_point_set_classification_item::Feature_handle())
|
||||
return;
|
||||
|
||||
QComboBox* combo = qobject_cast<QComboBox*>(QObject::sender());
|
||||
|
|
@ -853,23 +853,23 @@ public Q_SLOTS:
|
|||
// std::cerr << att->id() << " is ";
|
||||
if (v == 0)
|
||||
{
|
||||
classification_item->types()[i].first->set_attribute_effect
|
||||
(att, CGAL::Classification::Attribute::PENALIZING);
|
||||
classification_item->labels()[i].first->set_feature_effect
|
||||
(att, CGAL::Classification::Feature::PENALIZING);
|
||||
// std::cerr << " penalized for ";
|
||||
}
|
||||
else if (v == 1)
|
||||
{
|
||||
classification_item->types()[i].first->set_attribute_effect
|
||||
(att, CGAL::Classification::Attribute::NEUTRAL);
|
||||
classification_item->labels()[i].first->set_feature_effect
|
||||
(att, CGAL::Classification::Feature::NEUTRAL);
|
||||
// std::cerr << " neutral for ";
|
||||
}
|
||||
else
|
||||
{
|
||||
classification_item->types()[i].first->set_attribute_effect
|
||||
(att, CGAL::Classification::Attribute::FAVORING);
|
||||
classification_item->labels()[i].first->set_feature_effect
|
||||
(att, CGAL::Classification::Feature::FAVORING);
|
||||
// std::cerr << " favored for ";
|
||||
}
|
||||
// std::cerr << classification_item->types()[i].first->id() << std::endl;
|
||||
// std::cerr << classification_item->labels()[i].first->id() << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Classes</string>
|
||||
<string>Labels</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -266,7 +266,7 @@
|
|||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<widget class="QPushButton" name="add_new_class">
|
||||
<widget class="QPushButton" name="add_new_label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
@ -434,12 +434,12 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Attribute:</string>
|
||||
<string>Features:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="selected_attribute">
|
||||
<widget class="QComboBox" name="selected_feature">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
@ -464,7 +464,7 @@
|
|||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="attribute_weight">
|
||||
<widget class="QSlider" name="feature_weight">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
@ -531,7 +531,7 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Class type</string>
|
||||
<string>Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
Scene_point_set_classification_item::Scene_point_set_classification_item(PSC* psc)
|
||||
: Scene_item(NbOfVbos,NbOfVaos),
|
||||
m_points (NULL),
|
||||
m_psc (psc)
|
||||
m_psc (psc),
|
||||
m_trainer (new Trainer(*m_psc))
|
||||
{
|
||||
setRenderingMode(PointsPlusNormals);
|
||||
m_nb_scales = 5;
|
||||
|
|
@ -33,7 +34,8 @@ Scene_point_set_classification_item::Scene_point_set_classification_item(PSC* ps
|
|||
Scene_point_set_classification_item::Scene_point_set_classification_item(Scene_points_with_normal_item* points)
|
||||
: Scene_item(NbOfVbos,NbOfVaos),
|
||||
m_points (points),
|
||||
m_psc (NULL)
|
||||
m_psc (NULL),
|
||||
m_trainer (NULL)
|
||||
{
|
||||
setRenderingMode(PointsPlusNormals);
|
||||
m_nb_scales = 5;
|
||||
|
|
@ -44,15 +46,16 @@ Scene_point_set_classification_item::Scene_point_set_classification_item(Scene_p
|
|||
reset_indices();
|
||||
|
||||
m_psc = new PSC(*(m_points->point_set()), m_points->point_set()->point_map());
|
||||
m_trainer = new Trainer(*m_psc);
|
||||
|
||||
Type_handle ground = m_psc->add_classification_type("ground");
|
||||
Type_handle vegetation = m_psc->add_classification_type("vegetation");
|
||||
Type_handle roof = m_psc->add_classification_type("roof");
|
||||
Type_handle facade = m_psc->add_classification_type("facade");
|
||||
m_types.push_back (std::make_pair(ground, QColor(245, 180, 0)));
|
||||
m_types.push_back (std::make_pair(vegetation, QColor(0, 255, 27)));
|
||||
m_types.push_back (std::make_pair(roof, QColor(255, 0, 170)));
|
||||
m_types.push_back (std::make_pair(facade, QColor(100, 0, 255)));
|
||||
Label_handle ground = m_psc->add_label("ground");
|
||||
Label_handle vegetation = m_psc->add_label("vegetation");
|
||||
Label_handle roof = m_psc->add_label("roof");
|
||||
Label_handle facade = m_psc->add_label("facade");
|
||||
m_labels.push_back (std::make_pair(ground, QColor(245, 180, 0)));
|
||||
m_labels.push_back (std::make_pair(vegetation, QColor(0, 255, 27)));
|
||||
m_labels.push_back (std::make_pair(roof, QColor(255, 0, 170)));
|
||||
m_labels.push_back (std::make_pair(facade, QColor(100, 0, 255)));
|
||||
|
||||
is_selected = true;
|
||||
nb_points = 0;
|
||||
|
|
@ -64,7 +67,8 @@ Scene_point_set_classification_item::Scene_point_set_classification_item(Scene_p
|
|||
Scene_point_set_classification_item::Scene_point_set_classification_item(const Scene_point_set_classification_item&)
|
||||
:Scene_item(NbOfVbos,NbOfVaos), // do not call superclass' copy constructor
|
||||
m_points (NULL),
|
||||
m_psc (NULL)
|
||||
m_psc (NULL),
|
||||
m_trainer (NULL)
|
||||
{
|
||||
setRenderingMode(PointsPlusNormals);
|
||||
m_nb_scales = 5;
|
||||
|
|
@ -80,6 +84,8 @@ Scene_point_set_classification_item::~Scene_point_set_classification_item()
|
|||
{
|
||||
if (m_psc != NULL)
|
||||
delete m_psc;
|
||||
if (m_trainer != NULL)
|
||||
delete m_trainer;
|
||||
}
|
||||
|
||||
void Scene_point_set_classification_item::initializeBuffers(CGAL::Three::Viewer_interface *viewer) const
|
||||
|
|
@ -212,17 +218,17 @@ void Scene_point_set_classification_item::compute_normals_and_vertices() const
|
|||
}
|
||||
else if (index_color == 1) // classif
|
||||
{
|
||||
std::map<Type_handle, QColor> map_colors;
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
map_colors.insert (m_types[i]);
|
||||
std::map<Label_handle, QColor> map_colors;
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
map_colors.insert (m_labels[i]);
|
||||
|
||||
for (Point_set::const_iterator it = m_points->point_set()->begin();
|
||||
it != m_points->point_set()->first_selected(); ++ it)
|
||||
{
|
||||
QColor color (0, 0, 0);
|
||||
Type_handle c = m_psc->classification_type_of(*it);
|
||||
Label_handle c = m_psc->label_of(*it);
|
||||
|
||||
if (c != Type_handle())
|
||||
if (c != Label_handle())
|
||||
color = map_colors[c];
|
||||
|
||||
colors_points.push_back ((double)(color.red()) / 255.);
|
||||
|
|
@ -232,18 +238,18 @@ void Scene_point_set_classification_item::compute_normals_and_vertices() const
|
|||
}
|
||||
else if (index_color == 2) // training
|
||||
{
|
||||
std::map<Type_handle, QColor> map_colors;
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
map_colors.insert (m_types[i]);
|
||||
std::map<Label_handle, QColor> map_colors;
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
map_colors.insert (m_labels[i]);
|
||||
|
||||
for (Point_set::const_iterator it = m_points->point_set()->begin();
|
||||
it != m_points->point_set()->first_selected(); ++ it)
|
||||
{
|
||||
QColor color (0, 0, 0);
|
||||
Type_handle c = m_psc->training_type_of(*it);
|
||||
Type_handle c2 = m_psc->classification_type_of(*it);
|
||||
Label_handle c = m_trainer->training_label_of(*it);
|
||||
Label_handle c2 = m_psc->label_of(*it);
|
||||
|
||||
if (c != Type_handle())
|
||||
if (c != Label_handle())
|
||||
color = map_colors[c];
|
||||
double div = 255.;
|
||||
if (c != c2)
|
||||
|
|
@ -256,7 +262,7 @@ void Scene_point_set_classification_item::compute_normals_and_vertices() const
|
|||
}
|
||||
else
|
||||
{
|
||||
Attribute_handle att = m_psc->get_attribute(index_color - 3);
|
||||
Feature_handle att = m_psc->feature(index_color - 3);
|
||||
double weight = att->weight();
|
||||
att->set_weight(att->max);
|
||||
for (Point_set::const_iterator it = m_points->point_set()->begin();
|
||||
|
|
@ -289,7 +295,7 @@ Scene_point_set_classification_item::clone() const
|
|||
// Write point set to .PLY file
|
||||
bool Scene_point_set_classification_item::write_ply_point_set(std::ostream& stream)
|
||||
{
|
||||
if (m_psc->number_of_attributes() == 0)
|
||||
if (m_psc->number_of_features() == 0)
|
||||
return false;
|
||||
|
||||
stream.precision (std::numeric_limits<double>::digits10 + 2);
|
||||
|
|
@ -297,11 +303,11 @@ bool Scene_point_set_classification_item::write_ply_point_set(std::ostream& stre
|
|||
reset_indices();
|
||||
|
||||
std::vector<Color> colors;
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
{
|
||||
Color c = {{ (unsigned char)(m_types[i].second.red()),
|
||||
(unsigned char)(m_types[i].second.green()),
|
||||
(unsigned char)(m_types[i].second.blue()) }};
|
||||
Color c = {{ (unsigned char)(m_labels[i].second.red()),
|
||||
(unsigned char)(m_labels[i].second.green()),
|
||||
(unsigned char)(m_labels[i].second.blue()) }};
|
||||
colors.push_back (c);
|
||||
}
|
||||
|
||||
|
|
@ -452,11 +458,11 @@ void Scene_point_set_classification_item::compute_features ()
|
|||
{
|
||||
Q_ASSERT (!(m_points->point_set()->empty()));
|
||||
Q_ASSERT (m_psc != NULL);
|
||||
m_psc->clear_attributes();
|
||||
m_psc->clear_features();
|
||||
reset_indices();
|
||||
|
||||
std::cerr << "Computing features with " << m_nb_scales << " scale(s)" << std::endl;
|
||||
if (m_psc->number_of_attributes() != 0)
|
||||
if (m_psc->number_of_features() != 0)
|
||||
m_psc->clear();
|
||||
compute_bbox();
|
||||
|
||||
|
|
@ -467,21 +473,21 @@ void Scene_point_set_classification_item::compute_features ()
|
|||
boost::tie (echo_map, echo) = m_points->point_set()->template property_map<boost::uint8_t>("echo");
|
||||
|
||||
if (!normals && !colors && !echo)
|
||||
m_psc->generate_attributes (m_nb_scales);
|
||||
m_psc->generate_features (m_nb_scales);
|
||||
else if (!normals && !colors && echo)
|
||||
m_psc->generate_attributes (m_nb_scales, CGAL::Default(), CGAL::Default(), echo_map);
|
||||
m_psc->generate_features (m_nb_scales, CGAL::Default(), CGAL::Default(), echo_map);
|
||||
else if (!normals && colors && !echo)
|
||||
m_psc->generate_attributes (m_nb_scales, CGAL::Default(), Color_map(m_points->point_set()));
|
||||
m_psc->generate_features (m_nb_scales, CGAL::Default(), Color_map(m_points->point_set()));
|
||||
else if (!normals && colors && echo)
|
||||
m_psc->generate_attributes (m_nb_scales, CGAL::Default(), Color_map(m_points->point_set()), echo_map);
|
||||
m_psc->generate_features (m_nb_scales, CGAL::Default(), Color_map(m_points->point_set()), echo_map);
|
||||
else if (normals && !colors && !echo)
|
||||
m_psc->generate_attributes (m_nb_scales, m_points->point_set()->normal_map());
|
||||
m_psc->generate_features (m_nb_scales, m_points->point_set()->normal_map());
|
||||
else if (normals && !colors && echo)
|
||||
m_psc->generate_attributes (m_nb_scales, m_points->point_set()->normal_map(), CGAL::Default(), echo_map);
|
||||
m_psc->generate_features (m_nb_scales, m_points->point_set()->normal_map(), CGAL::Default(), echo_map);
|
||||
else if (normals && colors && !echo)
|
||||
m_psc->generate_attributes (m_nb_scales, m_points->point_set()->normal_map(), Color_map(m_points->point_set()));
|
||||
m_psc->generate_features (m_nb_scales, m_points->point_set()->normal_map(), Color_map(m_points->point_set()));
|
||||
else
|
||||
m_psc->generate_attributes (m_nb_scales, m_points->point_set()->normal_map(), Color_map(m_points->point_set()), echo_map);
|
||||
m_psc->generate_features (m_nb_scales, m_points->point_set()->normal_map(), Color_map(m_points->point_set()), echo_map);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -489,20 +495,20 @@ void Scene_point_set_classification_item::compute_features ()
|
|||
|
||||
void Scene_point_set_classification_item::train()
|
||||
{
|
||||
if (m_psc->number_of_attributes() == 0)
|
||||
if (m_psc->number_of_features() == 0)
|
||||
{
|
||||
std::cerr << "Error: features not computed" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
m_psc->train(m_nb_trials);
|
||||
m_trainer->train(m_nb_trials);
|
||||
m_psc->run();
|
||||
m_psc->info();
|
||||
}
|
||||
|
||||
bool Scene_point_set_classification_item::run (int method)
|
||||
{
|
||||
if (m_psc->number_of_attributes() == 0)
|
||||
if (m_psc->number_of_features() == 0)
|
||||
{
|
||||
std::cerr << "Error: features not computed" << std::endl;
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,15 @@
|
|||
|
||||
#include <CGAL/Three/Scene_item.h>
|
||||
#include <CGAL/Point_set_classifier.h>
|
||||
#include <CGAL/Classification/Attribute_base.h>
|
||||
#include <CGAL/Classification/Attribute/Vertical_dispersion.h>
|
||||
#include <CGAL/Classification/Attribute/Elevation.h>
|
||||
#include <CGAL/Classification/Attribute/Verticality.h>
|
||||
#include <CGAL/Classification/Attribute/Distance_to_plane.h>
|
||||
#include <CGAL/Classification/Attribute/Hsv.h>
|
||||
#include <CGAL/Classification/Attribute/Echo_scatter.h>
|
||||
#include <CGAL/Classification/Attribute/Eigen.h>
|
||||
#include <CGAL/Classification/Trainer.h>
|
||||
#include <CGAL/Classification/Feature_base.h>
|
||||
#include <CGAL/Classification/Feature/Vertical_dispersion.h>
|
||||
#include <CGAL/Classification/Feature/Elevation.h>
|
||||
#include <CGAL/Classification/Feature/Verticality.h>
|
||||
#include <CGAL/Classification/Feature/Distance_to_plane.h>
|
||||
#include <CGAL/Classification/Feature/Hsv.h>
|
||||
#include <CGAL/Classification/Feature/Echo_scatter.h>
|
||||
#include <CGAL/Classification/Feature/Eigen.h>
|
||||
|
||||
|
||||
#include "Scene_point_set_classification_item_config.h"
|
||||
|
|
@ -69,13 +70,14 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
typedef Point_set::Vector_map Vector_map;
|
||||
typedef Point_set_color_map<Point_set> Color_map;
|
||||
|
||||
typedef CGAL::Point_set_classifier<Kernel, Point_set, Point_map> PSC;
|
||||
typedef CGAL::Classification::Type_handle Type_handle;
|
||||
typedef CGAL::Classification::Attribute_handle Attribute_handle;
|
||||
typedef CGAL::Classification::Attribute::Vertical_dispersion<Kernel, Point_set, Point_map> Dispersion;
|
||||
typedef CGAL::Classification::Attribute::Elevation<Kernel, Point_set, Point_map> Elevation;
|
||||
typedef CGAL::Classification::Attribute::Verticality<Kernel, Point_set, Point_map> Verticality;
|
||||
typedef CGAL::Classification::Attribute::Distance_to_plane<Kernel, Point_set, Point_map> Distance_to_plane;
|
||||
typedef CGAL::Point_set_classifier<Kernel, Point_set, Point_map> PSC;
|
||||
typedef CGAL::Classification::Trainer<Point_set, Point_map> Trainer;
|
||||
typedef CGAL::Classification::Label_handle Label_handle;
|
||||
typedef CGAL::Classification::Feature_handle Feature_handle;
|
||||
typedef CGAL::Classification::Feature::Vertical_dispersion<Kernel, Point_set, Point_map> Dispersion;
|
||||
typedef CGAL::Classification::Feature::Elevation<Kernel, Point_set, Point_map> Elevation;
|
||||
typedef CGAL::Classification::Feature::Verticality<Kernel, Point_set, Point_map> Verticality;
|
||||
typedef CGAL::Classification::Feature::Distance_to_plane<Kernel, Point_set, Point_map> Distance_to_plane;
|
||||
|
||||
|
||||
public:
|
||||
|
|
@ -123,21 +125,21 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
void generate_point_set_items(std::vector<Item*>& items,
|
||||
const char* name)
|
||||
{
|
||||
std::map<Type_handle, std::size_t> map_types;
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
std::map<Label_handle, std::size_t> map_labels;
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
{
|
||||
items.push_back (new Item);
|
||||
items.back()->setName (QString("%1 (%2)").arg(name).arg(m_types[i].first->name().c_str()));
|
||||
items.back()->setColor (m_types[i].second);
|
||||
map_types[m_types[i].first] = i;
|
||||
items.back()->setName (QString("%1 (%2)").arg(name).arg(m_labels[i].first->name().c_str()));
|
||||
items.back()->setColor (m_labels[i].second);
|
||||
map_labels[m_labels[i].first] = i;
|
||||
}
|
||||
|
||||
for (Point_set::const_iterator it = m_points->point_set()->begin();
|
||||
it != m_points->point_set()->end(); ++ it)
|
||||
{
|
||||
Type_handle c = m_psc->classification_type_of(*it);
|
||||
if (c != Type_handle())
|
||||
items[map_types[c]]->point_set()->insert (m_points->point_set()->point(*it));
|
||||
Label_handle c = m_psc->label_of(*it);
|
||||
if (c != Label_handle())
|
||||
items[map_labels[c]]->point_set()->insert (m_points->point_set()->point(*it));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,8 +147,7 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
|
||||
void reset_training_sets()
|
||||
{
|
||||
m_psc->prepare_classification();
|
||||
m_psc->reset_inlier_sets();
|
||||
m_trainer->reset_inlier_sets();
|
||||
invalidateOpenGLBuffers();
|
||||
Q_EMIT itemChanged();
|
||||
}
|
||||
|
|
@ -160,41 +161,36 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
}
|
||||
|
||||
|
||||
Type_handle get_classification_type (const char* name)
|
||||
Label_handle get_label (const char* name)
|
||||
{
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
if (m_types[i].first->name() == name)
|
||||
return m_types[i].first;
|
||||
return Type_handle();
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
if (m_labels[i].first->name() == name)
|
||||
return m_labels[i].first;
|
||||
return Label_handle();
|
||||
}
|
||||
|
||||
void add_selection_to_training_set (const char* name)
|
||||
{
|
||||
Type_handle class_type = get_classification_type (name);
|
||||
|
||||
if (!(m_psc->classification_prepared()))
|
||||
m_psc->prepare_classification();
|
||||
Label_handle label = get_label (name);
|
||||
|
||||
for (Point_set::const_iterator it = m_points->point_set()->first_selected();
|
||||
it != m_points->point_set()->end(); ++ it)
|
||||
m_psc->set_classification_type_of(*it, class_type);
|
||||
m_psc->set_label_of(*it, label);
|
||||
|
||||
m_trainer->set_inliers(label,
|
||||
boost::make_iterator_range(m_points->point_set()->first_selected(),
|
||||
m_points->point_set()->end()));
|
||||
|
||||
m_psc->set_inliers(class_type,
|
||||
boost::make_iterator_range(m_points->point_set()->first_selected(),
|
||||
m_points->point_set()->end()));
|
||||
m_points->resetSelection();
|
||||
}
|
||||
|
||||
void validate_selection ()
|
||||
{
|
||||
if (!(m_psc->classification_prepared()))
|
||||
m_psc->prepare_classification();
|
||||
|
||||
for (Point_set::const_iterator it = m_points->point_set()->first_selected();
|
||||
it != m_points->point_set()->end(); ++ it)
|
||||
{
|
||||
Type_handle t = m_psc->classification_type_of(*it);
|
||||
m_psc->set_inlier (t, *it);
|
||||
Label_handle t = m_psc->label_of(*it);
|
||||
m_trainer->set_inlier (t, *it);
|
||||
}
|
||||
|
||||
m_points->resetSelection();
|
||||
|
|
@ -203,36 +199,36 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
double& smoothing() { return m_smoothing; }
|
||||
std::size_t& nb_scales() { return m_nb_scales; }
|
||||
std::size_t& number_of_trials() { return m_nb_trials; }
|
||||
bool features_computed() const { return (m_psc->number_of_attributes() != 0); }
|
||||
bool features_computed() const { return (m_psc->number_of_features() != 0); }
|
||||
|
||||
std::vector<std::pair<Type_handle, QColor> >& types() { return m_types; }
|
||||
std::size_t number_of_attributes() const { return m_psc->number_of_attributes(); }
|
||||
Attribute_handle attribute(std::size_t i) { return m_psc->get_attribute(i); }
|
||||
void add_new_type (const char* name, const QColor& color)
|
||||
std::vector<std::pair<Label_handle, QColor> >& labels() { return m_labels; }
|
||||
std::size_t number_of_features() const { return m_psc->number_of_features(); }
|
||||
Feature_handle feature(std::size_t i) { return m_psc->feature(i); }
|
||||
void add_new_label (const char* name, const QColor& color)
|
||||
{
|
||||
m_types.push_back (std::make_pair (m_psc->add_classification_type(name),
|
||||
m_labels.push_back (std::make_pair (m_psc->add_label(name),
|
||||
color));
|
||||
}
|
||||
|
||||
void remove_type (const char* name)
|
||||
void remove_label (const char* name)
|
||||
{
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
if (m_types[i].first->name() == name)
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
if (m_labels[i].first->name() == name)
|
||||
{
|
||||
m_psc->remove_classification_type (m_types[i].first);
|
||||
m_types.erase (m_types.begin() + i);
|
||||
m_psc->remove_label (m_labels[i].first);
|
||||
m_labels.erase (m_labels.begin() + i);
|
||||
break;
|
||||
}
|
||||
invalidateOpenGLBuffers();
|
||||
Q_EMIT itemChanged();
|
||||
}
|
||||
|
||||
void change_type_color (const char* name, const QColor& color)
|
||||
void change_label_color (const char* name, const QColor& color)
|
||||
{
|
||||
for (std::size_t i = 0; i < m_types.size(); ++ i)
|
||||
if (m_types[i].first->name() == name)
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
if (m_labels[i].first->name() == name)
|
||||
{
|
||||
m_types[i].second = color;
|
||||
m_labels[i].second = color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -240,11 +236,11 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
template <typename ComboBox>
|
||||
void fill_display_combo_box (ComboBox* cb, ComboBox* cb1)
|
||||
{
|
||||
for (std::size_t i = 0; i < m_psc->number_of_attributes(); ++ i)
|
||||
for (std::size_t i = 0; i < m_psc->number_of_features(); ++ i)
|
||||
{
|
||||
std::size_t scale = m_psc->scale_of_attribute(m_psc->get_attribute(i));
|
||||
std::size_t scale = m_psc->scale_of_feature(m_psc->feature(i));
|
||||
std::ostringstream oss;
|
||||
oss << "Attribute " << m_psc->get_attribute(i)->name() << "_" << scale;
|
||||
oss << "Feature " << m_psc->feature(i)->name() << "_" << scale;
|
||||
cb->addItem (oss.str().c_str());
|
||||
cb1->addItem (oss.str().c_str());
|
||||
}
|
||||
|
|
@ -252,7 +248,7 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
|
||||
void save_config(const char* filename)
|
||||
{
|
||||
if (m_psc->number_of_attributes() == 0)
|
||||
if (m_psc->number_of_features() == 0)
|
||||
{
|
||||
std::cerr << "Error: features not computed" << std::endl;
|
||||
return;
|
||||
|
|
@ -264,7 +260,7 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
|
||||
void load_config(const char* filename)
|
||||
{
|
||||
if (m_psc->number_of_attributes() != 0)
|
||||
if (m_psc->number_of_features() != 0)
|
||||
m_psc->clear();
|
||||
|
||||
reset_indices();
|
||||
|
|
@ -293,24 +289,24 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
else
|
||||
m_psc->load_configuration (f, m_points->point_set()->normal_map(), Color_map(m_points->point_set()), echo_map);
|
||||
|
||||
std::vector<std::pair<Type_handle, QColor> > new_types;
|
||||
for (std::size_t i = 0; i < m_psc->number_of_classification_types(); ++ i)
|
||||
std::vector<std::pair<Label_handle, QColor> > new_labels;
|
||||
for (std::size_t i = 0; i < m_psc->number_of_labels(); ++ i)
|
||||
{
|
||||
Type_handle t = m_psc->get_classification_type(i);
|
||||
Label_handle t = m_psc->label(i);
|
||||
QColor color (192 + rand() % 60,
|
||||
192 + rand() % 60,
|
||||
192 + rand() % 60);
|
||||
|
||||
for (std::size_t j = 0; j < m_types.size(); ++ j)
|
||||
if (t->name() == m_types[j].first->name())
|
||||
for (std::size_t j = 0; j < m_labels.size(); ++ j)
|
||||
if (t->name() == m_labels[j].first->name())
|
||||
{
|
||||
color = m_types[j].second;
|
||||
color = m_labels[j].second;
|
||||
break;
|
||||
}
|
||||
|
||||
new_types.push_back (std::make_pair (t, color));
|
||||
new_labels.push_back (std::make_pair (t, color));
|
||||
}
|
||||
m_types.swap (new_types);
|
||||
m_labels.swap (new_labels);
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
|
|
@ -320,10 +316,11 @@ class SCENE_POINT_SET_CLASSIFICATION_ITEM_EXPORT Scene_point_set_classification_
|
|||
|
||||
Scene_points_with_normal_item* m_points;
|
||||
PSC* m_psc;
|
||||
Trainer* m_trainer;
|
||||
|
||||
std::size_t m_nb_scales;
|
||||
|
||||
std::vector<std::pair<Type_handle, QColor> > m_types;
|
||||
std::vector<std::pair<Label_handle, QColor> > m_labels;
|
||||
std::size_t m_nb_trials;
|
||||
double m_smoothing;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue