diff options
author | glisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-12-12 05:43:06 +0000 |
---|---|---|
committer | glisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-12-12 05:43:06 +0000 |
commit | ad6a64ad5a4f4121410250021eda0904eb9c718c (patch) | |
tree | fdad2e783a79b388cde1826e3b344d8977d1183a /src/GudhUI | |
parent | f9a32a464156dd61b444f0e70c8342642363e8ea (diff) | |
parent | f0e5330a88f9e89a887769ab79f6db6dd4e1c35a (diff) |
Merge from trunk.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/qt5@1848 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: c8e1376894207c8c08896f750f71c115e07f6d95
Diffstat (limited to 'src/GudhUI')
-rw-r--r-- | src/GudhUI/CMakeLists.txt | 24 | ||||
-rw-r--r-- | src/GudhUI/gui/MainWindow.h | 3 | ||||
-rw-r--r-- | src/GudhUI/gui/MenuEdgeContraction.ui | 236 | ||||
-rw-r--r-- | src/GudhUI/gui/gudhui.cpp | 76 | ||||
-rw-r--r-- | src/GudhUI/model/Complex_typedefs.h | 2 | ||||
-rw-r--r-- | src/GudhUI/model/Model.h | 18 | ||||
-rw-r--r-- | src/GudhUI/utils/Bar_code_persistence.h | 90 | ||||
-rw-r--r-- | src/GudhUI/utils/Edge_contractor.h | 2 | ||||
-rw-r--r-- | src/GudhUI/utils/Furthest_point_epsilon_net.h | 2 | ||||
-rw-r--r-- | src/GudhUI/utils/Is_manifold.h | 2 | ||||
-rw-r--r-- | src/GudhUI/utils/K_nearest_builder.h | 10 | ||||
-rw-r--r-- | src/GudhUI/utils/Persistence_compute.h | 14 | ||||
-rw-r--r-- | src/GudhUI/view/FirstCoordProjector.h | 8 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer.h | 234 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer_instructor.cpp | 2 | ||||
-rw-r--r-- | src/GudhUI/view/Viewer_instructor.h | 228 |
16 files changed, 513 insertions, 438 deletions
diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index c852c43f..d3a52b60 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -33,25 +33,6 @@ if ( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) SET(Boost_USE_STATIC_LIBS ON) SET(Boost_USE_MULTITHREAD OFF) - INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) - LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) - - include(${CGAL_USE_FILE}) - # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. - # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 - # A workaround is to add "-std=c++11" again. - # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html - # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html - # but it implies to use cmake version 3.1 at least. - if(NOT MSVC) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) - if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - endif() - # - End of workaround - include_directories (${QGLVIEWER_INCLUDE_DIR}) ##################################################################### @@ -69,6 +50,11 @@ if ( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) target_link_libraries( GudhUI Qt5::Widgets Qt5::Xml Qt5::OpenGL ) target_link_libraries( GudhUI ${QGLVIEWER_LIBRARIES} ) target_link_libraries( GudhUI ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) +if (TBB_FOUND) + target_link_libraries( GudhUI ${TBB_LIBRARIES}) +endif() + +############################################################################### else() message(STATUS "NOTICE: GudhUI requires CGAL, the QGLViewer, OpenGL and Qt5, and will not be compiled.") diff --git a/src/GudhUI/gui/MainWindow.h b/src/GudhUI/gui/MainWindow.h index 7e11ddd6..15664dcb 100644 --- a/src/GudhUI/gui/MainWindow.h +++ b/src/GudhUI/gui/MainWindow.h @@ -23,6 +23,9 @@ #ifndef GUI_MAINWINDOW_H_ #define GUI_MAINWINDOW_H_ +// Workaround https://svn.boost.org/trac/boost/ticket/12534 +#include <boost/container/flat_map.hpp> + #include <QMainWindow> #include "ui_main_window.h" #include "model/Model.h" diff --git a/src/GudhUI/gui/MenuEdgeContraction.ui b/src/GudhUI/gui/MenuEdgeContraction.ui index da2e5c82..b1696431 100644 --- a/src/GudhUI/gui/MenuEdgeContraction.ui +++ b/src/GudhUI/gui/MenuEdgeContraction.ui @@ -1,118 +1,118 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>MenuEdgeContraction</class>
- <widget class="QDialog" name="MenuEdgeContraction">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>362</width>
- <height>209</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Edge contraction</string>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="5" column="2">
- <widget class="QSpinBox" name="spinBox_nb_remaining_vertices">
- <property name="minimum">
- <number>1</number>
- </property>
- <property name="maximum">
- <number>999999999</number>
- </property>
- <property name="value">
- <number>1</number>
- </property>
- </widget>
- </item>
- <item row="7" column="2">
- <widget class="QCheckBox" name="checkBox_link_condition">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Link condition</string>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="3" column="2" alignment="Qt::AlignRight">
- <widget class="QLabel" name="txt_nb_collapses">
- <property name="text">
- <string>1</string>
- </property>
- </widget>
- </item>
- <item row="6" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Policy</string>
- </property>
- </widget>
- </item>
- <item row="6" column="2">
- <widget class="QComboBox" name="m_simplificationMethod">
- <item>
- <property name="text">
- <string>Length_midpoint</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="2" column="2" alignment="Qt::AlignRight">
- <widget class="QLabel" name="txt_nb_vertices">
- <property name="text">
- <string>0</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Number of vertices</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0" colspan="2">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Number of contractions</string>
- </property>
- </widget>
- </item>
- <item row="5" column="0" colspan="2">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>Number of vertices after </string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QSlider" name="horizontalSlider">
- <property name="minimum">
- <number>0</number>
- </property>
- <property name="maximum">
- <number>100</number>
- </property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QPushButton" name="pushButton_collapse">
- <property name="text">
- <string>Perform collapse</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MenuEdgeContraction</class> + <widget class="QDialog" name="MenuEdgeContraction"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>362</width> + <height>209</height> + </rect> + </property> + <property name="windowTitle"> + <string>Edge contraction</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="5" column="2"> + <widget class="QSpinBox" name="spinBox_nb_remaining_vertices"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>999999999</number> + </property> + <property name="value"> + <number>1</number> + </property> + </widget> + </item> + <item row="7" column="2"> + <widget class="QCheckBox" name="checkBox_link_condition"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Link condition</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="3" column="2" alignment="Qt::AlignRight"> + <widget class="QLabel" name="txt_nb_collapses"> + <property name="text"> + <string>1</string> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Policy</string> + </property> + </widget> + </item> + <item row="6" column="2"> + <widget class="QComboBox" name="m_simplificationMethod"> + <item> + <property name="text"> + <string>Length_midpoint</string> + </property> + </item> + </widget> + </item> + <item row="2" column="2" alignment="Qt::AlignRight"> + <widget class="QLabel" name="txt_nb_vertices"> + <property name="text"> + <string>0</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Number of vertices</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Number of contractions</string> + </property> + </widget> + </item> + <item row="5" column="0" colspan="2"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Number of vertices after </string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QSlider" name="horizontalSlider"> + <property name="minimum"> + <number>0</number> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="pushButton_collapse"> + <property name="text"> + <string>Perform collapse</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/GudhUI/gui/gudhui.cpp b/src/GudhUI/gui/gudhui.cpp index 377cd2f2..276c4a5f 100644 --- a/src/GudhUI/gui/gudhui.cpp +++ b/src/GudhUI/gui/gudhui.cpp @@ -1,38 +1,38 @@ -/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): David Salinas
- *
- * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "MainWindow.h"
-#include <QApplication>
-#include <CGAL/Qt/resources.h>
-
-int main(int argc, char** argv) {
- QApplication application(argc, argv);
- application.setOrganizationDomain("inria.fr");
- application.setOrganizationName("INRIA");
- application.setApplicationName("GudhUI");
-
- MainWindow mw;
- application.setQuitOnLastWindowClosed(false);
- mw.show();
- return application.exec();
-}
+/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "MainWindow.h" +#include <QApplication> +#include <CGAL/Qt/resources.h> + +int main(int argc, char** argv) { + QApplication application(argc, argv); + application.setOrganizationDomain("inria.fr"); + application.setOrganizationName("INRIA"); + application.setApplicationName("GudhUI"); + + MainWindow mw; + application.setQuitOnLastWindowClosed(false); + mw.show(); + return application.exec(); +} diff --git a/src/GudhUI/model/Complex_typedefs.h b/src/GudhUI/model/Complex_typedefs.h index c310d4a6..a4df2c94 100644 --- a/src/GudhUI/model/Complex_typedefs.h +++ b/src/GudhUI/model/Complex_typedefs.h @@ -41,7 +41,7 @@ struct Geometry_trait : public CGAL::Cartesian_d<double> { typedef Geometry_trait::Point Point; using namespace Gudhi; -using namespace Gudhi::skbl; +using namespace Gudhi::skeleton_blocker; typedef Skeleton_blocker_simple_geometric_traits<Geometry_trait> Complex_geometric_traits; typedef Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex; diff --git a/src/GudhUI/model/Model.h b/src/GudhUI/model/Model.h index d78cbad9..fc284cc6 100644 --- a/src/GudhUI/model/Model.h +++ b/src/GudhUI/model/Model.h @@ -71,9 +71,9 @@ class CGAL_geometric_flag_complex_wrapper { void maximal_face(std::vector<int> vertices) { if (!load_only_points_) { - std::cout << "size:" << vertices.size() << std::endl; - for (int i = 0; i < vertices.size(); ++i) - for (int j = i + 1; j < vertices.size(); ++j) + // std::cout << "size:" << vertices.size() << std::endl; + for (std::size_t i = 0; i < vertices.size(); ++i) + for (std::size_t j = i + 1; j < vertices.size(); ++j) complex_.add_edge(Vertex_handle(vertices[i]), Vertex_handle(vertices[j])); } } @@ -187,7 +187,7 @@ class Model { } void contract_edges(unsigned num_contractions) { - Clock c; + Gudhi::Clock c; Edge_contractor<Complex> contractor(complex_, num_contractions); std::cout << "Time to simplify: " << c.num_seconds() << "s" << std::endl; } @@ -248,8 +248,8 @@ class Model { unsigned num_simplices = 0; int euler = 0; int dimension = 0; - Clock clock; - for (const auto &s : complex_.simplex_range()) { + Gudhi::Clock clock; + for (const auto &s : complex_.complex_simplex_range()) { num_simplices++; dimension = (std::max)(s.dimension(), dimension); if (s.dimension() % 2 == 0) @@ -271,7 +271,7 @@ class Model { #ifdef _WIN32 std::cout << "Works only on linux x64 for the moment\n"; #else - Clock clock; + Gudhi::Clock clock; run_chomp(); clock.end(); #endif @@ -281,7 +281,7 @@ class Model { unsigned num_simplices = 0; int euler = 0; int dimension = 0; - for (const auto &s : complex_.simplex_range()) { + for (const auto &s : complex_.complex_simplex_range()) { num_simplices++; dimension = (std::max)(s.dimension(), dimension); if (s.dimension() % 2 == 0) @@ -328,7 +328,7 @@ class Model { void save_complex_in_file_for_chomp() { std::ofstream file; file.open("chomp.sim"); - for (const auto &s : complex_.simplex_range()) { + for (const auto &s : complex_.complex_simplex_range()) { bool first = true; file << "("; for (auto x : s) { diff --git a/src/GudhUI/utils/Bar_code_persistence.h b/src/GudhUI/utils/Bar_code_persistence.h new file mode 100644 index 00000000..b527d684 --- /dev/null +++ b/src/GudhUI/utils/Bar_code_persistence.h @@ -0,0 +1,90 @@ +#include <math.h> // isfinite + +#include <QtGui/QApplication> + +#include <QGraphicsView> +#include <QGraphicsScene> +#include <QPointF> +#include <QVector> +#include <QGraphicsTextItem> + +#include <iostream> +#include <vector> +#include <limits> // NaN, infinity +#include <utility> // for pair +#include <string> + +#ifndef UTILS_BAR_CODE_PERSISTENCE_H_ +#define UTILS_BAR_CODE_PERSISTENCE_H_ + +class Bar_code_persistence { + private: + typedef std::vector<std::pair<double, double>> Persistence; + Persistence persistence_vector; + double min_birth; + double max_death; + + public: + Bar_code_persistence() + : min_birth(std::numeric_limits<double>::quiet_NaN()), + max_death(std::numeric_limits<double>::quiet_NaN()) { } + + void insert(double birth, double death) { + persistence_vector.push_back(std::make_pair(birth, death)); + if (std::isfinite(birth)) { + if ((birth < min_birth) || (std::isnan(min_birth))) + min_birth = birth; + if ((birth > max_death) || (std::isnan(max_death))) + max_death = birth; + } + if (std::isfinite(death)) + if ((death > max_death) || (std::isnan(max_death))) + max_death = death; + } + + void show(const std::string& window_title) { + // Create a view, put a scene in it + QGraphicsView * view = new QGraphicsView(); + QGraphicsScene * scene = new QGraphicsScene(); + view->setScene(scene); + double ratio = 600.0 / (max_death - min_birth); + // std::cout << "min_birth=" << min_birth << " - max_death=" << max_death << " - ratio=" << ratio << std::endl; + + double height = 0.0, birth = 0.0, death = 0.0; + int pers_num = 1; + for (auto& persistence : persistence_vector) { + height = 5.0 * pers_num; + // std::cout << "[" << pers_num << "] birth=" << persistence.first << " - death=" << persistence.second << std::endl; + if (std::isfinite(persistence.first)) + birth = ((persistence.first - min_birth) * ratio) + 50.0; + else + birth = 0.0; + + if (std::isfinite(persistence.second)) + death = ((persistence.second - min_birth) * ratio) + 50.0; + else + death = 700.0; + + scene->addLine(birth, height, death, height, QPen(Qt::blue, 2)); + pers_num++; + } + height += 10.0; + // scale line + scene->addLine(0, height, 700.0, height, QPen(Qt::black, 1)); + int modulo = 0; + for (double scale = 50.0; scale < 700.0; scale += 50.0) { + modulo++; + // scale small dash + scene->addLine(scale, height - 3.0, scale, height + 3.0, QPen(Qt::black, 1)); + // scale text + QString scale_value = QString::number(((scale - 50.0) / ratio) + min_birth); + QGraphicsTextItem* dimText = scene->addText(scale_value, QFont("Helvetica", 8)); + dimText->setPos(scale - (3.0 * scale_value.size()), height + 9.0 * (modulo % 2)); + } + view->setWindowTitle(window_title.c_str()); + // Show the view + view->show(); + } +}; + +#endif // UTILS_BAR_CODE_PERSISTENCE_H_ diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h index 45079a40..8a29ff4b 100644 --- a/src/GudhUI/utils/Edge_contractor.h +++ b/src/GudhUI/utils/Edge_contractor.h @@ -65,7 +65,7 @@ template<typename SkBlComplex> class Edge_contractor { Placement_type operator()(const EdgeProfile& profile) const override { std::vector<double> mid_coords(profile.p0().dimension(), 0); - for (size_t i = 0; i < profile.p0().dimension(); ++i) { + for (int i = 0; i < profile.p0().dimension(); ++i) { mid_coords[i] = (profile.p0()[i] + profile.p1()[i]) / 2.; } return Point(profile.p0().dimension(), mid_coords.begin(), mid_coords.end()); diff --git a/src/GudhUI/utils/Furthest_point_epsilon_net.h b/src/GudhUI/utils/Furthest_point_epsilon_net.h index f2a216f6..98346daa 100644 --- a/src/GudhUI/utils/Furthest_point_epsilon_net.h +++ b/src/GudhUI/utils/Furthest_point_epsilon_net.h @@ -73,7 +73,7 @@ template<typename SkBlComplex> class Furthest_point_epsilon_net { complex_(complex) { if (!complex.empty()) { init_filtration(); - for (int k = 2; k < net_filtration_.size(); ++k) { + for (std::size_t k = 2; k < net_filtration_.size(); ++k) { update_radius_value(k); } } diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index b6b19ee0..0640ea47 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -69,7 +69,7 @@ template<typename SkBlComplex> class Is_manifold { private: unsigned local_dimension(Vertex_handle v) { unsigned dim = 0; - for (const auto& s : input_complex_.simplex_range(v)) + for (const auto& s : input_complex_.star_simplex_range(v)) dim = (std::max)(dim, (unsigned) s.dimension()); return dim; } diff --git a/src/GudhUI/utils/K_nearest_builder.h b/src/GudhUI/utils/K_nearest_builder.h index cab24b7c..7be0a4f4 100644 --- a/src/GudhUI/utils/K_nearest_builder.h +++ b/src/GudhUI/utils/K_nearest_builder.h @@ -29,12 +29,10 @@ #include <CGAL/Search_traits_d.h> #include <CGAL/Search_traits_adapter.h> #include <CGAL/property_map.h> -#include <boost/iterator/iterator_facade.hpp> -#include <boost/iterator/zip_iterator.hpp> #include <unordered_map> -#include <tuple> #include <list> +#include <utility> #include "utils/UI_utils.h" #include "model/Complex_typedefs.h" @@ -43,9 +41,9 @@ template<typename SkBlComplex> class K_nearest_builder { private: typedef Geometry_trait Kernel; typedef Point Point_d; - typedef boost::tuple<Point_d, unsigned> Point_d_with_id; + typedef std::pair<Point_d, unsigned> Point_d_with_id; typedef CGAL::Search_traits_d<Kernel> Traits_base; - typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::Nth_of_tuple_property_map<0, Point_d_with_id>, + typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::First_of_pair_property_map<Point_d_with_id>, Traits_base> Traits; typedef CGAL::Orthogonal_k_neighbor_search<Traits> Neighbor_search; typedef Neighbor_search::Tree Tree; @@ -81,7 +79,7 @@ template<typename SkBlComplex> class K_nearest_builder { for (auto p : complex_.vertex_range()) { Neighbor_search search(tree, complex_.point(p), k + 1); for (auto it = ++search.begin(); it != search.end(); ++it) { - Vertex_handle q(boost::get<1>(it->first)); + Vertex_handle q(std::get<1>(it->first)); if (p != q && complex_.contains_vertex(p) && complex_.contains_vertex(q)) complex_.add_edge(p, q); } diff --git a/src/GudhUI/utils/Persistence_compute.h b/src/GudhUI/utils/Persistence_compute.h index 0b9961d3..97165490 100644 --- a/src/GudhUI/utils/Persistence_compute.h +++ b/src/GudhUI/utils/Persistence_compute.h @@ -46,10 +46,6 @@ struct Persistence_params { * Show persistence into output stream */ template<typename SkBlComplex> class Persistence_compute { - private: - SkBlComplex& complex_; - std::ostream& stream_; - public: typedef typename SkBlComplex::Vertex_handle Vertex_handle; typedef typename SkBlComplex::Edge_handle Edge_handle; @@ -61,9 +57,7 @@ template<typename SkBlComplex> class Persistence_compute { * double threshold * int p for coefficient Z_p */ - Persistence_compute(SkBlComplex& complex, std::ostream& stream, const Persistence_params& params) : - // double threshold = 0.5,unsigned dim_max = 8): - complex_(complex), stream_(stream) { + Persistence_compute(SkBlComplex& complex, std::ostream& stream, const Persistence_params& params) { // for now everything is copied, todo boost adapt iterators to points of SkBlComplex instead of copying to an // initial vector typedef std::vector<double> Point_t; @@ -87,10 +81,10 @@ template<typename SkBlComplex> class Persistence_compute { pcoh.init_coefficients(params.p); // put params.min_pers pcoh.compute_persistent_cohomology(params.min_pers); - stream_ << "persistence: \n"; - stream_ << "p dimension birth death: \n"; + stream << "persistence: \n"; + stream << "p dimension birth death: \n"; - pcoh.output_diagram(stream_); + pcoh.output_diagram(stream); } }; diff --git a/src/GudhUI/view/FirstCoordProjector.h b/src/GudhUI/view/FirstCoordProjector.h index 529d2d42..1333f5d3 100644 --- a/src/GudhUI/view/FirstCoordProjector.h +++ b/src/GudhUI/view/FirstCoordProjector.h @@ -32,8 +32,12 @@ class FirstCoordProjector3D : public Projector3D { typedef Projector3D::Point_3 Point_3; Point_3 operator()(const Point& p) const { - assert(p.dimension() >= 3); - return Point_3(p.x(), p.y(), p.z()); + if (p.dimension() >= 3) + return Point_3(p.x(), p.y(), p.z()); + else if (p.dimension() >= 2) + return Point_3(p.x(), p.y(), 0.0); + else + return Point_3(0.0, 0.0, 0.0); } }; diff --git a/src/GudhUI/view/Viewer.h b/src/GudhUI/view/Viewer.h index 48427099..797ddc53 100644 --- a/src/GudhUI/view/Viewer.h +++ b/src/GudhUI/view/Viewer.h @@ -1,117 +1,117 @@ -/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): David Salinas
- *
- * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef VIEW_VIEWER_H_
-#define VIEW_VIEWER_H_
-
-#include <QGLViewer/qglviewer.h>
-
-#include <vector>
-
-#include "View_parameter.h"
-#include "model/Complex_typedefs.h"
-#include "Color.h"
-#include "Viewer_instructor.h"
-
-class Viewer_instructor;
-
-class Viewer : public QGLViewer {
- Q_OBJECT
-
- Viewer_instructor * instructor;
-
- /**
- * light angles
- */
- double theta, phi;
- typedef Complex::GT Gudhi_kernel;
- typedef Gudhi_kernel::Point_3 Point_3;
-
- public:
- Viewer(QWidget* parent);
-
- void set_instructor(Viewer_instructor* instructor_);
-
- void show_entire_scene();
-
- void draw();
-
- void set_bounding_box(const Point_3 & lower_left, const Point_3 & upper_right);
-
- void update_GL();
-
- void init_scene();
-
- void init_light();
-
- void set_light();
-
- void set_light_direction(double theta, double phi);
-
- /**
- * set the light in the direction of the observer
- */
- void set_light_direction();
-
- protected:
- virtual void postSelection(const QPoint& point);
-
- public:
- ////////////////////////
- // draw
- ////////////////////////
- void set_size_point(double size_points);
-
- void set_color(const Color& color);
-
- void draw_point(const Point_3& p, const Color& color, double size_points);
-
- void begin_draw_points(double size, bool light = false);
-
- void draw_points(const Point_3 & point);
-
- void end_draw_points();
-
- void draw_edge(const Point_3 &a, const Point_3 &b, const Color& color, double size);
-
- void begin_draw_edges(double size, bool light = false);
-
- void draw_edges(const Point_3 &a, const Point_3 &b);
-
- void end_draw_edges();
-
- void begin_draw_triangles(double size, bool light, bool transparent = false);
-
- void draw_triangles(const Point_3& p1, const Point_3& p2, const Point_3& p3);
-
- // todo remove
- void draw_triangles(const std::vector<Point_3*>& points);
-
- void end_draw_triangles();
-
-
- signals:
- void click(const Point_3& position);
-};
-
-#endif // VIEW_VIEWER_H_
+/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef VIEW_VIEWER_H_ +#define VIEW_VIEWER_H_ + +#include <QGLViewer/qglviewer.h> + +#include <vector> + +#include "View_parameter.h" +#include "model/Complex_typedefs.h" +#include "Color.h" +#include "Viewer_instructor.h" + +class Viewer_instructor; + +class Viewer : public QGLViewer { + Q_OBJECT + + Viewer_instructor * instructor; + + /** + * light angles + */ + double theta, phi; + typedef Complex::GT Gudhi_kernel; + typedef Gudhi_kernel::Point_3 Point_3; + + public: + Viewer(QWidget* parent); + + void set_instructor(Viewer_instructor* instructor_); + + void show_entire_scene(); + + void draw(); + + void set_bounding_box(const Point_3 & lower_left, const Point_3 & upper_right); + + void update_GL(); + + void init_scene(); + + void init_light(); + + void set_light(); + + void set_light_direction(double theta, double phi); + + /** + * set the light in the direction of the observer + */ + void set_light_direction(); + + protected: + virtual void postSelection(const QPoint& point); + + public: + //////////////////////// + // draw + //////////////////////// + void set_size_point(double size_points); + + void set_color(const Color& color); + + void draw_point(const Point_3& p, const Color& color, double size_points); + + void begin_draw_points(double size, bool light = false); + + void draw_points(const Point_3 & point); + + void end_draw_points(); + + void draw_edge(const Point_3 &a, const Point_3 &b, const Color& color, double size); + + void begin_draw_edges(double size, bool light = false); + + void draw_edges(const Point_3 &a, const Point_3 &b); + + void end_draw_edges(); + + void begin_draw_triangles(double size, bool light, bool transparent = false); + + void draw_triangles(const Point_3& p1, const Point_3& p2, const Point_3& p3); + + // todo remove + void draw_triangles(const std::vector<Point_3*>& points); + + void end_draw_triangles(); + + + signals: + void click(const Point_3& position); +}; + +#endif // VIEW_VIEWER_H_ diff --git a/src/GudhUI/view/Viewer_instructor.cpp b/src/GudhUI/view/Viewer_instructor.cpp index 4446d209..1ddd4d8b 100644 --- a/src/GudhUI/view/Viewer_instructor.cpp +++ b/src/GudhUI/view/Viewer_instructor.cpp @@ -159,7 +159,7 @@ void Viewer_instructor::set_color_edge(Edge_handle eh) { viewer_->set_color(Color(view_params_.light_edges, view_params_.light_edges, view_params_.light_edges)); } -void Viewer_instructor::set_color_triangle(const Simplex_handle& triangle) { +void Viewer_instructor::set_color_triangle(const Simplex& triangle) { viewer_->set_color(Color(view_params_.light_triangles, view_params_.light_triangles, view_params_.light_triangles)); } diff --git a/src/GudhUI/view/Viewer_instructor.h b/src/GudhUI/view/Viewer_instructor.h index 96b25c77..05c5c1fc 100644 --- a/src/GudhUI/view/Viewer_instructor.h +++ b/src/GudhUI/view/Viewer_instructor.h @@ -1,114 +1,114 @@ -/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): David Salinas
- *
- * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef VIEW_VIEWER_INSTRUCTOR_H_
-#define VIEW_VIEWER_INSTRUCTOR_H_
-
-// todo do a viewer instructor that have directely a pointer to a QGLviewer and buffer ot not triangles
-
-#include <QFileDialog>
-#include <QKeyEvent>
-#include <QGLViewer/camera.h>
-
-#include <memory>
-#include <utility> // for pair<>
-
-#include "model/Complex_typedefs.h"
-
-#include "Projector3D.h"
-#include "View_parameter.h"
-#include "Viewer.h"
-
-class Viewer;
-class Viewer_parameter;
-
-class Viewer_instructor : public QWidget {
- Q_OBJECT
-
- typedef Geometry_trait::Point_3 Point_3;
- typedef Complex::Point Point;
- typedef Complex::Vertex_handle Vertex_handle;
- typedef Complex::Edge_handle Edge_handle;
- typedef Complex::Simplex_handle Simplex_handle;
-
- Viewer* viewer_;
- View_parameter view_params_;
- const Complex& mesh_;
- std::unique_ptr<Projector3D> projector_;
-
- public:
- Viewer_instructor(QWidget* parent, Viewer* viewer, const Complex& mesh);
-
- void initialize_bounding_box();
-
- std::pair<Point, Point> compute_bounding_box_corners();
-
- void show_entire_scene();
-
- const qglviewer::Camera* camera() const;
-
- int width() const;
- int height() const;
-
- /**
- * to change display parameters
- */
- View_parameter& view_params();
-
- public:
- /**
- * gives instructions to the viewer
- */
- void give_instructions();
-
- void draw_edges();
- void draw_triangles();
- void draw_points();
-
- void draw_edge(const Point&, const Point&);
-
- void draw_point(const Point&);
-
- /**
- * set the right color of vertex/edge/triangle considering the view_params choice
- */
- void set_color_vertex(Vertex_handle vh);
- void set_color_edge(Edge_handle eh);
-
- void set_color_triangle(const Simplex_handle& triangle);
-
- private:
- /**
- * Projection to 3D needed for the viewer.
- */
- Point_3 proj(const Point& p) const;
-
- public slots:
- void sceneChanged();
- void change_draw_vertices();
- void change_draw_edges();
- void change_draw_triangles();
- void change_light();
-};
-
-#endif // VIEW_VIEWER_INSTRUCTOR_H_
+/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef VIEW_VIEWER_INSTRUCTOR_H_ +#define VIEW_VIEWER_INSTRUCTOR_H_ + +// todo do a viewer instructor that have directely a pointer to a QGLviewer and buffer ot not triangles + +#include <QFileDialog> +#include <QKeyEvent> +#include <QGLViewer/camera.h> + +#include <memory> +#include <utility> // for pair<> + +#include "model/Complex_typedefs.h" + +#include "Projector3D.h" +#include "View_parameter.h" +#include "Viewer.h" + +class Viewer; +class Viewer_parameter; + +class Viewer_instructor : public QWidget { + Q_OBJECT + + typedef Geometry_trait::Point_3 Point_3; + typedef Complex::Point Point; + typedef Complex::Vertex_handle Vertex_handle; + typedef Complex::Edge_handle Edge_handle; + typedef Complex::Simplex Simplex; + + Viewer* viewer_; + View_parameter view_params_; + const Complex& mesh_; + std::unique_ptr<Projector3D> projector_; + + public: + Viewer_instructor(QWidget* parent, Viewer* viewer, const Complex& mesh); + + void initialize_bounding_box(); + + std::pair<Point, Point> compute_bounding_box_corners(); + + void show_entire_scene(); + + const qglviewer::Camera* camera() const; + + int width() const; + int height() const; + + /** + * to change display parameters + */ + View_parameter& view_params(); + + public: + /** + * gives instructions to the viewer + */ + void give_instructions(); + + void draw_edges(); + void draw_triangles(); + void draw_points(); + + void draw_edge(const Point&, const Point&); + + void draw_point(const Point&); + + /** + * set the right color of vertex/edge/triangle considering the view_params choice + */ + void set_color_vertex(Vertex_handle vh); + void set_color_edge(Edge_handle eh); + + void set_color_triangle(const Simplex& triangle); + + private: + /** + * Projection to 3D needed for the viewer. + */ + Point_3 proj(const Point& p) const; + + public slots: + void sceneChanged(); + void change_draw_vertices(); + void change_draw_edges(); + void change_draw_triangles(); + void change_light(); +}; + +#endif // VIEW_VIEWER_INSTRUCTOR_H_ |