From 539625fe0a686b26c2c078138442eb0dbac50c65 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 27 Apr 2015 14:33:43 +0200 Subject: [PATCH 01/24] Modification of save/load function to use the last api of cmap. Replace the specialization on Point and Info by the use of has_xxx functions. --- .../examples/Combinatorial_map/map_3_load.cpp | 402 +++++++++ .../examples/Combinatorial_map/map_3_save.cpp | 430 ++++++++++ .../include/CGAL/Combinatorial_map.h | 13 +- .../include/CGAL/Combinatorial_map_functors.h | 36 + .../CGAL/Combinatorial_map_save_load.h | 800 ++++++++++++++++++ .../Combinatorial_map_copy_functors.h | 12 +- .../Combinatorial_map_group_functors.h | 1 - .../Combinatorial_map_internal_functors.h | 40 +- .../include/CGAL/Cell_attribute_with_point.h | 1 + 9 files changed, 1692 insertions(+), 43 deletions(-) create mode 100644 Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp create mode 100644 Combinatorial_map/examples/Combinatorial_map/map_3_save.cpp create mode 100644 Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h diff --git a/Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp b/Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp new file mode 100644 index 00000000000..22e4f67f518 --- /dev/null +++ b/Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp @@ -0,0 +1,402 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//****************************************************************************** +// Functor used to display all the attributes of a given dimension. +template +struct My_functor_display_attrib +{ + template + static void run(const CMap& amap) + { + std::cout<::type::const_iterator + it_attrib = amap.template attributes().begin(), + itend_attrib = amap.template attributes().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<info()<<" "; + } + std::cout< +void display_map(const CMap& amap) +{ + amap.display_characteristics(std::cout) + <<", valid="< >::run(amap); +} +//****************************************************************************** +// Functor used to display all the attributes of a given dimension. +template::type::Info> +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<::type::const_iterator + it_attrib = amap.template attributes().begin(), + itend_attrib = amap.template attributes().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<info()<<" "; + } + std::cout< +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<().size()<<" attributes without info." + < +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<<"0-attributes: "; + + typename CMap::template Attribute_range<0>::type::const_iterator + it_attrib = amap.template attributes<0>().begin(), + itend_attrib = amap.template attributes<0>().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<<"("<point()<<") "; + } + std::cout< +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<<"0-attributes: "; + + typename CMap::template Attribute_range<0>::type::const_iterator + it_attrib = amap.template attributes<0>().begin(), + itend_attrib = amap.template attributes<0>().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<<"("<point()<<" "<info()<<") "; + } + std::cout< +struct My_functor_display_attrib_lcc +{ + template + static void run(const CMap& amap) + { My_functor_display_one_attrib_lcc::run(amap); } +}; + +// Display the map, i.e. all its characteristics, then all its attributes. +template < class CMap > +void display_lcc(const CMap& amap) +{ + amap.display_characteristics(std::cout) + <<", valid="< >::run(amap); +} + +//****************************************************************************** +/* Configuration example 1 + Map containing attributes defined with basic types. */ +struct MesAttributs1 +{ + template < class CMap> + struct Dart_wrapper + { + typedef CGAL::Dart<3, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<3, MesAttributs1> CMap_3a; + +bool example1(const char* filename) +{ + std::cout<<"************** example 1 **************"<>cm; + display_map(cm); + return true; +} + +//****************************************************************************** +/* Configuration example 2 + Map containing custom attributes, without overload read_cmap_attribute_node. + In this case, custom attributes are not loaded. Use custom load dart. */ +struct ACustomType +{ + int anint; + float afloat; + ACustomType(int ai=0, float af=0.0) : anint(ai), afloat(af) + {} + friend std::ostream& operator<<(std::ostream& os, const ACustomType& a) + { return os<<"["< + struct Dart_wrapper + { + typedef CGAL::Dart<3, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<3, MesAttributs2> CMap_3b; + +namespace CGAL +{ +// Definition of function allowing to same custom darts. +template<> +void read_cmap_dart_node +(const boost::property_tree::ptree::value_type & v, + CMap_3b::Dart_handle dh) +{ + std::cout<<"Read dart "<("myn")<>cm; + display_map(cm); + return true; +} + +//****************************************************************************** +/* Configuration example 3 + Map containing custom attributes, and overloading read_cmap_attribute_node. + Here custom attributes are also loaded. */ +struct ACustomType2 +{ + int anint; + float afloat; + ACustomType2(int ai=0, float af=0.0) : anint(ai), afloat(af) + {} + friend std::ostream& operator<<(std::ostream& os, const ACustomType2& a) + { return os<<"["< +void read_cmap_attribute_node +(const boost::property_tree::ptree::value_type &v,ACustomType2 &val) +{ + val.anint = v.second.get("v1"); + val.afloat = v.second.get("v2"); + + /* Example showing how to iterate through all the son of the node v. + BOOST_FOREACH( const boost::property_tree::ptree::value_type &v2, v.second) + { + if(v2.first=="v1") + { + val.anint=boost::lexical_cast< int >(v2.second.data()); + } + else if (v2.first=="v2") + { + val.afloat=boost::lexical_cast< float >(v2.second.data()); + } + } + */ +} + +} + +struct MesAttributs3 +{ + template < class CMap> + struct Dart_wrapper + { + typedef CGAL::Dart<3, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<3, MesAttributs3> CMap_3c; + +bool example3(const char* filename) +{ + std::cout<<"************** example 3 **************"<>cm; + display_map(cm); + return true; +} + +//****************************************************************************** +/* Configuration example 4 + Map containing custom attributes, and overloading read_cmap_attribute_node. + But dimension of the map is 2 (instead of 3 in previous examples). */ +struct MesAttributs4 +{ + template < class CMap> + struct Dart_wrapper + { + typedef CGAL::Dart<2, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<2, MesAttributs4> CMap_2; + +bool example4(const char* filename) +{ + std::cout<<"************** example 4 **************"<>cm; + display_map(cm); + return true; +} + +//****************************************************************************** +/* Configuration example 5 + Map containing custom attributes, and overloading read_cmap_attribute_node. + But dimension of the map is 5. */ +struct MesAttributs5 +{ + template < class CMap> + struct Dart_wrapper + { + typedef CGAL::Dart<5, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<5, MesAttributs5> CMap_5; + +bool example5(const char* filename) +{ + std::cout<<"************** example 5 **************"<>cm; + display_map(cm); + return true; +} + +//****************************************************************************** +/* Configuration example 6 + Linear cell complex without attributes*/ +typedef CGAL::Linear_cell_complex<3> LCC_1; + +bool example6(const char* filename) +{ + std::cout<<"************** example 6 **************"<>cm; + display_lcc(cm); + return true; +} + +//****************************************************************************** +/* Configuration example 7 + Linear cell complex with attributes*/ +struct Myitem7 +{ + template + struct Dart_wrapper + { + typedef CGAL::Dart<3, Refs > Dart; + typedef CGAL::Cell_attribute_with_point< Refs, int, CGAL::Tag_true> + Vertex_attribute; + typedef CGAL::Cell_attribute T1; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; +typedef CGAL::Linear_cell_complex_traits +<3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits; +typedef CGAL::Linear_cell_complex<3,3,Traits,Myitem7> LCC_2; + +bool example7(const char* filename) +{ + std::cout<<"************** example 7 **************"<>cm; + display_lcc(cm); + return true; +} + +//****************************************************************************** +//==================================== main ==================================== +int main(int argc, char* argv[]) +{ + if(argc!=2) + { + std::cout<<"Usage: a.out filename"< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//****************************************************************************** +// Functor used to display all the attributes of a given dimension. +template +struct My_functor_display_attrib +{ + template + static void run(const CMap& amap) + { + std::cout<::type::const_iterator + it_attrib = amap.template attributes().begin(), + itend_attrib = amap.template attributes().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<info()<<" "; + } + std::cout< +void display_map(const CMap& amap) +{ + amap.display_characteristics(std::cout) + <<", valid="< >::run(amap); +} + +//****************************************************************************** +// Functor used to display all the attributes of a given dimension. +template::type::Info> +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<::type::const_iterator + it_attrib = amap.template attributes().begin(), + itend_attrib = amap.template attributes().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<info()<<" "; + } + std::cout< +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<().size()<<" attributes without info." + < +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<<"0-attributes: "; + + typename CMap::template Attribute_range<0>::type::const_iterator + it_attrib = amap.template attributes<0>().begin(), + itend_attrib = amap.template attributes<0>().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<<"("<point()<<") "; + } + std::cout< +struct My_functor_display_one_attrib_lcc +{ + static void run(const CMap& amap) + { + std::cout<<"0-attributes: "; + + typename CMap::template Attribute_range<0>::type::const_iterator + it_attrib = amap.template attributes<0>().begin(), + itend_attrib = amap.template attributes<0>().end(); + + for (; it_attrib!=itend_attrib; ++it_attrib) + { + std::cout<<"("<point()<<" "<info()<<") "; + } + std::cout< +struct My_functor_display_attrib_lcc +{ + template + static void run(const CMap& amap) + { My_functor_display_one_attrib_lcc::run(amap); } +}; + +// Display the map, i.e. all its characteristics, then all its attributes. +template < class CMap > +void display_lcc(const CMap& amap) +{ + amap.display_characteristics(std::cout) + <<", valid="< >::run(amap); +} + +//****************************************************************************** +/* Configuration example 1 + Map containing attributes defined with basic types. */ +struct MesAttributs1 +{ + template < class CMap> + struct Dart_wrapper + { + typedef CGAL::Dart<3, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<3, MesAttributs1> CMap_3a; +typedef CMap_3a::Dart_handle Dart_handle_a; + +void example1() +{ + CMap_3a cm; + + // 1) create two tetrahedra 3-sewn + Dart_handle_a dh1 = CGAL::make_combinatorial_tetrahedron(cm); + Dart_handle_a dh2 = CGAL::make_combinatorial_tetrahedron(cm); + cm.sew<3>(dh1,dh2); + + // 2) make attributes + for (CMap_3a::Dart_range::iterator it(cm.darts().begin()), + itend(cm.darts().end()); it!=itend; ++it) + { + if ( it->attribute<1>()==NULL ) + { + cm.set_attribute<1>(it, cm.create_attribute<1>()); + it->attribute<1>()->info()=cm.number_of_attributes<1>(); + } + if( it->attribute<2>()==NULL) + { + cm.set_attribute<2>(it, cm.create_attribute<2>()); + it->attribute<2>()->info()=(cm.number_of_attributes<2>()/2.0); + } + } + + std::cout<<"************** example 1 **************"< + struct Dart_wrapper + { + typedef CGAL::Dart<3, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<3, MesAttributs2> CMap_3b; +typedef CMap_3b::Dart_handle Dart_handle_b; + +void example2() +{ + CMap_3b cm; + + // 1) create two tetrahedra 3-sewn + Dart_handle_b dh1 = CGAL::make_combinatorial_tetrahedron(cm); + Dart_handle_b dh2 = CGAL::make_combinatorial_tetrahedron(cm); + cm.sew<3>(dh1,dh2); + + // 2) make attributes + for (CMap_3b::Dart_range::iterator it(cm.darts().begin()), + itend(cm.darts().end()); it!=itend; ++it) + { + if ( it->attribute<1>()==NULL ) + { + cm.set_attribute<1>(it, cm.create_attribute<1>()); + it->attribute<1>()->info()=cm.number_of_attributes<1>(); + } + if( it->attribute<2>()==NULL) + { + cm.set_attribute<2>(it, cm.create_attribute<2>()); + it->attribute<2>()->info()=ACustomType((int)cm.number_of_attributes<2>(), + cm.number_of_attributes<2>()/2.0); + } + } + + std::cout<<"************** example 2 **************"< +void write_cmap_attribute_node(boost::property_tree::ptree & node, + const ACustomType2& arg) +{ + boost::property_tree::ptree & nValue = node.add("v",""); + nValue.add("v1",arg.anint); + nValue.add("v2",arg.afloat); +} + +} + +struct MesAttributs3 +{ + template < class CMap> + struct Dart_wrapper + { + typedef CGAL::Dart<3, CMap> Dart; + typedef CGAL::Cell_attribute T1; + typedef CGAL::Cell_attribute T2; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; + +typedef CGAL::Combinatorial_map<3, MesAttributs3> CMap_3c; +typedef CMap_3c::Dart_handle Dart_handle_c; +typedef CMap_3c::Dart_const_handle Dart_const_handle_c; + +namespace CGAL +{ +// Definition of function allowing to same custom darts. +template<> +void write_cmap_dart_node(boost::property_tree::ptree & node, + Dart_const_handle_c dh) +{ + static int i=0; + boost::property_tree::ptree & nValue = node.add("v",""); + nValue.add("myn",i++); +} + +} + + +void example3() +{ + CMap_3c cm; + + // 1) create two tetrahedra 3-sewn + Dart_handle_c dh1 = CGAL::make_combinatorial_tetrahedron(cm); + Dart_handle_c dh2 = CGAL::make_combinatorial_tetrahedron(cm); + cm.sew<3>(dh1,dh2); + + // 2) make attributes + for (CMap_3c::Dart_range::iterator it(cm.darts().begin()), + itend(cm.darts().end()); it!=itend; ++it) + { + if ( it->attribute<1>()==NULL ) + { + cm.set_attribute<1>(it, cm.create_attribute<1>()); + it->attribute<1>()->info()=cm.number_of_attributes<1>(); + } + if( it->attribute<2>()==NULL) + { + cm.set_attribute<2>(it, cm.create_attribute<2>()); + it->attribute<2>()->info()=ACustomType2(cm.number_of_attributes<2>(), + cm.number_of_attributes<2>()/2.0); + } + } + + std::cout<<"************** example 3 **************"< LCC_1; + +void example4() +{ + LCC_1 lcc; + LCC_1::Dart_handle d1 = lcc.make_tetrahedron(LCC_1::Point(-1, 0, 0), + LCC_1::Point(0, 2, 0), + LCC_1::Point(1, 0, 0), + LCC_1::Point(1, 1, 2)); + LCC_1::Dart_handle d2 = lcc.make_tetrahedron(LCC_1::Point(0, 2, -1), + LCC_1::Point(-1, 0, -1), + LCC_1::Point(1, 0, -1), + LCC_1::Point(1, 1, -3)); + lcc.sew<3>(d1, d2); + + std::cout<<"************** example 4 **************"< + struct Dart_wrapper + { + typedef CGAL::Dart<3, Refs > Dart; + typedef CGAL::Cell_attribute_with_point< Refs, int, CGAL::Tag_true> + Vertex_attribute; + typedef CGAL::Cell_attribute T1; + typedef CGAL::cpp0x::tuple Attributes; + }; +}; +typedef CGAL::Linear_cell_complex_traits +<3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits; +typedef CGAL::Linear_cell_complex<3,3,Traits,Myitem7> LCC_2; + +void example5() +{ + LCC_2 lcc; + LCC_2::Dart_handle d1 = lcc.make_tetrahedron(LCC_2::Point(-1, 0, 0), + LCC_2::Point(0, 2, 0), + LCC_2::Point(1, 0, 0), + LCC_2::Point(1, 1, 2)); + LCC_2::Dart_handle d2 = lcc.make_tetrahedron(LCC_2::Point(0, 2, -1), + LCC_2::Point(-1, 0, -1), + LCC_2::Point(1, 0, -1), + LCC_2::Point(1, 1, -3)); + lcc.sew<3>(d1, d2); + + // 2) make attributes + for (LCC_2::Dart_range::iterator it(lcc.darts().begin()), + itend(lcc.darts().end()); it!=itend; ++it) + { + it->attribute<0>()->info()=rand()%10; + if ( it->attribute<1>()==NULL ) + { + lcc.set_attribute<1>(it, lcc.create_attribute<1>()); + it->attribute<1>()->info()=lcc.number_of_attributes<1>(); + } + } + + std::cout<<"************** example 5 **************"< #include -#include #include #include #include @@ -350,6 +349,18 @@ namespace CGAL { bool is_empty() const { return mdarts.empty(); } + friend std::ostream& operator<< (std::ostream& os, const Self& amap) + { + save_combinatorial_map(amap, os); + return os; + } + + friend std::ifstream& operator>> (std::ifstream& is, Self& amap) + { + load_combinatorial_map(is, amap); + return is; + } + /** Create a new dart and add it to the map. * The marks of the darts are initialised with mmask_marks, i.e. the dart * is unmarked for all the marks. diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h index cbdef1f5945..f87aab4d186 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h @@ -24,6 +24,7 @@ #include #include #include +#include /* Definition of functors used to manage attributes (we need functors as * attributes are stored in tuple, thus all the access must be done at @@ -44,6 +45,13 @@ * * Test_is_valid_attribute_functor to test if an attribute is valid * (used with Foreach_enabled_attributes) + * + * Is_attribute_has_non_void_info to test if the attribute + * Attr is non Void and has an non void Info as inner type + * + * Is_attribute_has_point to test if the attribute + * Attr is non Void and has a Point inner type + * */ namespace CGAL @@ -127,6 +135,34 @@ struct Set_i_attribute_functor {} }; // **************************************************************************** +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_point,Point,false) + +template +struct Is_nonvoid_attribute_has_non_void_info +{ + static const bool value=true; +}; +template +struct Is_nonvoid_attribute_has_non_void_info +{ + static const bool value=false; +}; + +template +struct Is_attribute_has_non_void_info +{ + static const bool value=Is_nonvoid_attribute_has_non_void_info::value; +}; +template<> +struct Is_attribute_has_non_void_info +{ + static const bool value=false; +}; +// **************************************************************************** +template +struct Is_attribute_has_point +{ static const bool value=Has_point::value; }; +// **************************************************************************** } // namespace CGAL #endif // CGAL_COMBINATORIAL_MAP_FUNCTORS_H // diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h new file mode 100644 index 00000000000..5446c343e63 --- /dev/null +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -0,0 +1,800 @@ +// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// Guillaume Castano +// Pascal Khieu +// +#ifndef CGAL_COMBINATORIAL_MAP_SAVE_LOAD_H +#define CGAL_COMBINATORIAL_MAP_SAVE_LOAD_H + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace CGAL { + + typedef Exact_predicates_inexact_constructions_kernel::Point_3 RPoint_3; + typedef Exact_predicates_exact_constructions_kernel::Point_3 EPoint_3; + + // Tags used in xml tree: + // For darts: + // + // // new dart + // neighbor dart index for beta1 + // ... + // value of dart (optional) + // + // ... + // + // For attributes: + // + // // new type of non void attribute + // type of the info associated + // // new attribute + // dart index + // value of attribute + // + // ... + // + + // Here T is a Dart_const_handle so we don't need & + template + void write_cmap_dart_node(boost::property_tree::ptree & node, T) + {} + + template + void write_cmap_attribute_node(boost::property_tree::ptree & node, const T&) + {} + + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + char val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + unsigned char val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + short int val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + unsigned short int val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + int val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + unsigned int val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + long int val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + unsigned long int val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + float val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + double val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + long double val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + bool val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + const std::string& val) + {node.add("v",val);} + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + const RPoint_3& val) + { + node.add("p.x",val.x()); + node.add("p.y",val.y()); + node.add("p.z",val.z()); + } + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + const EPoint_3& val) + { + node.add("p.x",CGAL::to_double(val.x())); + node.add("p.y",CGAL::to_double(val.y())); + node.add("p.z",CGAL::to_double(val.z())); + } + + template::type>::value, + bool WithPoint=CGAL::Is_attribute_has_point + ::type >::value > + struct My_functor_cmap_save_one_attrib; + + // An attrib with point and with info + template + struct My_functor_cmap_save_one_attrib + { + static void run(const CMap* amap, boost::property_tree::ptree* ptree, + std::map* myDarts) + { + // to check all i-cells of the map + typename CMap::template Attribute_range::type::const_iterator + it_attrib, itend_attrib; + it_attrib=amap->template attributes().begin(); + itend_attrib=amap->template attributes().end(); + + // add dimension & type + boost::property_tree::ptree & ndim = ptree->add("dimension", ""); + ndim.put(".index", i); + ndim.add("type", typeid(typename CMap::template Attribute_type::type::Info).name()); + ndim.add("type_point", typeid(RPoint_3).name()); + + // for every attribute of the dimension + for (; it_attrib!=itend_attrib; ++it_attrib) + { + // make composant, dart and property node + boost::property_tree::ptree & nattr = ndim.add("a", ""); + boost::property_tree::ptree & ndarts = + nattr.add("d", (*myDarts)[it_attrib->dart()]); + + // update property node to add a value node (from basic or custom type + write_cmap_attribute_node(nattr, it_attrib->info()); + write_cmap_attribute_node(nattr, it_attrib->point()); + } + } + }; + + // An attribute with point and without info + template + struct My_functor_cmap_save_one_attrib + { + static void run(const CMap* amap, boost::property_tree::ptree* ptree, + std::map* myDarts) + { + // to check all i-cells of the map + typename CMap::template Attribute_range::type::const_iterator + it_attrib, itend_attrib; + it_attrib=amap->template attributes().begin(); + itend_attrib=amap->template attributes().end(); + + // add dimension & type + boost::property_tree::ptree & ndim = ptree->add("dimension", ""); + ndim.put(".index", i); + ndim.add("type", "void"); + ndim.add("type_point", typeid(RPoint_3).name()); + + // for every attribute of the dimension + for (; it_attrib!=itend_attrib; ++it_attrib) + { + // make composant, dart and property node + boost::property_tree::ptree & nattr = ndim.add("a", ""); + boost::property_tree::ptree & ndarts = + nattr.add("d", (*myDarts)[it_attrib->dart()]); + + // update property node to add a value node (from basic or custom type + write_cmap_attribute_node(nattr, it_attrib->point()); + } + } + }; + + // An attribute without point and with info + template + struct My_functor_cmap_save_one_attrib + { + static void run(const CMap* amap, boost::property_tree::ptree* ptree, + std::map* myDarts) + { + // to check all i-cells of the map + typename CMap::template Attribute_range::type::const_iterator + it_attrib, itend_attrib; + it_attrib=amap->template attributes().begin(); + itend_attrib=amap->template attributes().end(); + + // add dimension & type + boost::property_tree::ptree & ndim = ptree->add("dimension", ""); + ndim.put(".index", i); + ndim.add("type", typeid(typename CMap::template Attribute_type::type::Info).name()); + ndim.add("type_point", "void"); + + // for every attribute of the dimension + for (; it_attrib!=itend_attrib; ++it_attrib) + { + // make composant, dart and property node + boost::property_tree::ptree & nattr = ndim.add("a", ""); + boost::property_tree::ptree & ndarts = + nattr.add("d", (*myDarts)[it_attrib->dart()]); + + // update property node to add a value node (from basic or custom type + write_cmap_attribute_node(nattr, it_attrib->info()); + } + } + }; + + // An attrib without point and without info + template + struct My_functor_cmap_save_one_attrib + { + static void run(const CMap* amap, boost::property_tree::ptree* ptree, + std::map* myDarts) + { + // to check all i-cells of the map + typename CMap::template Attribute_range::type::const_iterator + it_attrib, itend_attrib; + it_attrib=amap->template attributes().begin(); + itend_attrib=amap->template attributes().end(); + + // add dimension & type + boost::property_tree::ptree & ndim = ptree->add("dimension", ""); + ndim.put(".index", i); + ndim.add("type", "void"); + ndim.add("type_point", "void"); + + // for every attribute of the dimension + for (; it_attrib!=itend_attrib; ++it_attrib) + { + // make composant, dart and property node + boost::property_tree::ptree & nattr = ndim.add("a", ""); + boost::property_tree::ptree & ndarts = + nattr.add("d", (*myDarts)[it_attrib->dart()]); + } + } + }; + + template + struct My_functor_cmap_save_attrib + { + template + static void run(const CMap* amap, boost::property_tree::ptree* ptree, + std::map* myDarts) + { + My_functor_cmap_save_one_attrib::run(amap, ptree, myDarts); + } + }; + + template < class CMap > + boost::property_tree::ptree cmap_save_darts + (const CMap& amap, std::map& myDarts) + { + assert( myDarts.empty() ); + + // First we numbered each dart by using the std::map. + typename CMap::Dart_range::const_iterator it(amap.darts().begin()); + for(typename CMap::size_type num=1; num<=amap.number_of_darts(); + ++num, ++it) + { + myDarts[it] = num; + } + + // make a tree + using boost::property_tree::ptree; + ptree pt; + + // Now we save each dart, and its neighbors. + it=amap.darts().begin(); + for(typename CMap::size_type num=0; num.i", dim); + } + } + + // update property node to add a value node (if user defined its own + // function) + write_cmap_dart_node(ndart, it); + } + + return pt; + } + + template < class CMap > + boost::property_tree::ptree cmap_save_attributes + (const CMap& amap, std::map& myDarts) + { + using boost::property_tree::ptree; + ptree pt; + + // update pt adding nodes containing attributes informations + CMap::Helper::template Foreach_enabled_attributes + >::run(&amap, &pt, &myDarts); + + return pt; + } + + template < class CMap > + bool save_combinatorial_map(const CMap& amap, std::ostream & output) + { + using boost::property_tree::ptree; + ptree data; + + // map dart => number + std::map myDarts; + + // Get darts + ptree pt_darts; + pt_darts = cmap_save_darts(amap, myDarts); + data.add_child("data.darts",pt_darts); + + // Get attributes + ptree pt_attr; + pt_attr = cmap_save_attributes(amap, myDarts); + data.add_child("data.attributes", pt_attr); + + // save data in output + write_xml(output, data); + + return true; + } + + template < class CMap > + bool save_combinatorial_map(const CMap& amap, const char* filename) + { + std::ofstream output(filename); + if (!output) return false; + save_combinatorial_map(amap, filename); + } + + // Here T is a Dart_handle so no need of & + template + void read_cmap_dart_node + (const boost::property_tree::ptree::value_type &v, T val) + {} + template + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v, T &val) + {} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,char &val) + {val=boost::lexical_cast< char >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,unsigned char &val) + {val=boost::lexical_cast< unsigned char >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,short int &val) + {val=boost::lexical_cast< short int >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,unsigned short int &val) + {val=boost::lexical_cast< unsigned short int >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,int &val) + {val=boost::lexical_cast< int >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,unsigned int &val) + {val=boost::lexical_cast< unsigned int >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,long int &val) + {val=boost::lexical_cast< long int >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,unsigned long int &val) + {val=boost::lexical_cast< unsigned long int >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,float &val) + {val=boost::lexical_cast< float >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,double &val) + {val=boost::lexical_cast< double >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,long double &val) + {val=boost::lexical_cast< long double >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,bool &val) + {val=boost::lexical_cast< bool >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,std::string &val) + {val=boost::lexical_cast< std::string >(v.second.data());} + template<> inline + void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,RPoint_3 &val) + { + double x=v.second.get("x"); + double y=v.second.get("y"); + double z=v.second.get("z"); + val = RPoint_3(x,y,z); + } + + template::type>::value, + bool WithPoint=CGAL::Is_attribute_has_point + ::type >::value > + struct My_functor_cmap_load_one_attrib; + + // An attrib with point and with info + template + struct My_functor_cmap_load_one_attrib + { + static void run(const boost::property_tree::ptree& pt, CMap* amap, + const std::vector& myDarts) + { + BOOST_FOREACH( const boost::property_tree::ptree::value_type &v0, + pt.get_child("data.attributes") ) + { + // + if (v0.first == "dimension") + { + int dimension=v0.second.get(".index", -1); + + // if map.dimension == dimension saved in the xml file + if (dimension==i) + { + unsigned int id_dart_cellule=0; + std::string type = v0.second.get("type"); + std::string type_map=std::string + (typeid(typename CMap::template Attribute_type::type::Info).name()); + + std::string ptype = v0.second.get("type_point"); + std::string ptype_map= std::string + (typeid(typename CMap::template Attribute_type::type::Point).name()); + + // std::cout<<"ptype="<("d")-1; + + BOOST_FOREACH(const boost::property_tree::ptree::value_type &v2, + v1.second ) + { + if( type==type_map && v2.first == "v" ) + { + if (myDarts[id_dart_cellule]-> + template attribute()==NULL ) + amap->template set_attribute + (myDarts[id_dart_cellule], + amap->template create_attribute()); + read_cmap_attribute_node + (v2, + myDarts[id_dart_cellule]-> + template attribute()->info()); + } + if( ptype==ptype_map && v2.first == "p" ) + { + if (myDarts[id_dart_cellule]-> + template attribute()==NULL ) + amap->template set_attribute + (myDarts[id_dart_cellule], + amap->template create_attribute()); + read_cmap_attribute_node + (v2, + myDarts[id_dart_cellule]-> + template attribute()->point()); + } + } + } + } + } + } + } + } + }; + + // An attribute with point and without info + template + struct My_functor_cmap_load_one_attrib + { + static void run(const boost::property_tree::ptree& pt, CMap* amap, + const std::vector& myDarts) + { + BOOST_FOREACH( const boost::property_tree::ptree::value_type &v0, + pt.get_child("data.attributes") ) + { + // + if (v0.first == "dimension") + { + int dimension=v0.second.get(".index", -1); + + // if map.dimension == dimension saved in the xml file + if (dimension==i) + { + unsigned int id_dart_cellule=0; + std::string ptype = v0.second.get("type_point"); + std::string type_map= typeid + (typename CMap::template Attribute_type::type::Point).name(); + // std::cout<<"ptype="<("d")-1; + + BOOST_FOREACH(const boost::property_tree::ptree::value_type &v2, + v1.second ) + { + if( v2.first == "p" ) + { + if (myDarts[id_dart_cellule]-> + template attribute()==NULL ) + amap->template set_attribute + (myDarts[id_dart_cellule], + amap->template create_attribute()); + + read_cmap_attribute_node + (v2, + myDarts[id_dart_cellule]-> + template attribute()->point()); + } + } + } + } + } + } + } + } + }; + + // An attribute without point and with info + template + struct My_functor_cmap_load_one_attrib + { + static void run(const boost::property_tree::ptree& pt, CMap* amap, + const std::vector& myDarts) + { + BOOST_FOREACH( const boost::property_tree::ptree::value_type &v0, + pt.get_child("data.attributes") ) + { + // + if (v0.first == "dimension") + { + int dimension=v0.second.get(".index", -1); + + // if map.dimension == dimension saved in the xml file + if (dimension==i) + { + unsigned int id_dart_cellule=0; + std::string ptype = v0.second.get("type"); + std::string type_map= typeid + (typename CMap::template Attribute_type::type::Info).name(); + // std::cout<<"ptype="<("d")-1; + + BOOST_FOREACH(const boost::property_tree::ptree::value_type &v2, + v1.second ) + { + if( v2.first == "v" ) + { + if (myDarts[id_dart_cellule]-> + template attribute()==NULL ) + amap->template set_attribute + (myDarts[id_dart_cellule], + amap->template create_attribute()); + read_cmap_attribute_node + (v2, + myDarts[id_dart_cellule]-> + template attribute()->info()); + } + } + } + } + } + } + } + } + }; + + // An attribute without point and without info + template + struct My_functor_cmap_load_one_attrib + { + static void run(const boost::property_tree::ptree& pt, CMap* amap, + const std::vector& myDarts) + { + BOOST_FOREACH( const boost::property_tree::ptree::value_type &v0, + pt.get_child("data.attributes") ) + { + // + if (v0.first == "dimension") + { + int dimension=v0.second.get(".index", -1); + + // if map.dimension == dimension saved in the xml file + if (dimension==i) + { + unsigned int id_dart_cellule=0; + + BOOST_FOREACH(const boost::property_tree::ptree::value_type &v1, + v0.second ) + { + if( v1.first == "a" ) + { + id_dart_cellule=v1.second.get("d")-1; + + if (myDarts[id_dart_cellule]-> + template attribute()==NULL ) + amap->template set_attribute + (myDarts[id_dart_cellule], + amap->template create_attribute()); + } + } + } + } + } + } + }; + + /** Functor called to load i-attributes. + * @param pt a boost::property_tree::ptree load from an xml file + * @param amap a pointer to the map to load into + * @param myDarts an array of Dart_handle st myDarts[i] is the ith dart. + */ + template + struct My_functor_cmap_load_attrib + { + template + static void run(const boost::property_tree::ptree& pt, CMap* amap, + const std::vector& myDarts) + { + My_functor_cmap_load_one_attrib::run(pt, amap, myDarts); + } + }; + + template < class CMap > + bool cmap_load_darts(boost::property_tree::ptree &pt, CMap& amap, + std::vector& myDarts) + { + // use a boost::property_tree + using boost::property_tree::ptree; + + // make darts + BOOST_FOREACH( const ptree::value_type &v, pt.get_child("data.darts") ) + { + if( v.first == "d" ) + myDarts.push_back(amap.create_dart()); + } + + // update beta links + int index; + unsigned int currentDartInt = 0; + unsigned int nextDartInt; + + BOOST_FOREACH( const ptree::value_type &v, pt.get_child("data.darts") ) + { + if( v.first == "d" ) + { + BOOST_FOREACH( const ptree::value_type &v2, v.second ) + { + if (v2.first == "b") + { + index = v2.second.get(".i", 0); + nextDartInt = boost::lexical_cast< int >(v2.second.data())-1; + + if ( index<=amap.dimension ) + { + // A->B + amap.basic_link_beta(myDarts[currentDartInt], + myDarts[nextDartInt], + index); + + //B->A + amap.basic_link_beta(myDarts[nextDartInt], + myDarts[currentDartInt], + CGAL_BETAINV(index)); + } + } + else if (v2.first=="v") + read_cmap_dart_node(v2,myDarts[currentDartInt]); + } + } + ++currentDartInt; + } + + return true; + } + + template < class CMap > + void cmap_load_attributes(const boost::property_tree::ptree& pt, CMap& amap, + const std::vector& myDarts) + { + CMap::Helper::template Foreach_enabled_attributes + >::run(pt,&amap,myDarts); + } + + template < class CMap > + bool load_combinatorial_map(std::ifstream & input, CMap& amap) + { + using boost::property_tree::ptree; + ptree pt; + read_xml(input, pt); + std::vector myDarts; + cmap_load_darts(pt,amap,myDarts); + cmap_load_attributes(pt,amap,myDarts); + return true; + } + + template < class CMap > + bool load_combinatorial_map(const char* filename, CMap& amap) + { + std::ifstream input(filename); + if (!input) return false; + return load_combinatorial_map(input, amap); + } + +} // namespace CGAL + +#endif // CGAL_COMBINATORIAL_MAP_SAVE_LOAD_H // +// EOF // diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h index fc856440d16..7fbee1c0ec2 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -21,7 +21,7 @@ #define CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H #include -#include +#include #include #include #include @@ -162,10 +162,10 @@ struct Get_convert_attribute_functor // Call a given functor if both i-attribute have an non void info template< typename Map1, typename Map2, unsigned int i, typename Converters, - bool Withinfo1=CGAL::internal::template + bool Withinfo1=CGAL::template Is_attribute_has_non_void_info ::type>::value, - bool Withinfo2=CGAL::internal::template + bool Withinfo2=CGAL::template Is_attribute_has_non_void_info ::type>::value > struct Call_functor_if_both_attributes_have_info @@ -199,9 +199,9 @@ struct Call_functor_if_both_attributes_have_info::type>::value, - bool Withpoint2=CGAL::internal::template Is_attribute_has_point + bool Withpoint2=CGAL::template Is_attribute_has_point ::type>::value > struct Call_functor_if_both_attributes_have_point { @@ -288,7 +288,7 @@ struct Copy_attribute_functor_if_nonvoidtemplate attribute<0>(dh2)!=Map2::null_handle ) return; // Create the point if 0-attributes has Point. - if ( CGAL::internal::template Is_attribute_has_point + if ( CGAL::template Is_attribute_has_point ::type>::value ) cmap2->template set_attribute<0>(dh2, cmap2->template create_attribute<0>()); diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h index 2a408a948fd..e6dc19c79a7 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h @@ -21,7 +21,6 @@ #define CGAL_COMBINATORIAL_MAP_GROUP_FUNCTORS_H #include -#include #include /* Definition of functors used to group/ungroup attributes (we need functors diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h index bcf4b0c4d00..a0ea69faf74 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -25,7 +25,6 @@ #include #include #include -#include /* Definition of functors used internally to manage attributes (we need * functors as attributes are stored in tuple, thus all the access must be @@ -65,12 +64,6 @@ * internal::Test_is_same_attribute_functor to test if two * i-attributes of two darts are isomorphic. * - * internal::Is_attribute_has_non_void_info to test if the attribute - * Attr is non Void and has an non void Info as inner type - * - * internal::Is_attribute_has_point to test if the attribute - * Attr is non Void and has a Point inner type - * * internal::Reverse_orientation_of_map_functor to reverse the * orientation of a whole combinatorial map * @@ -83,6 +76,11 @@ namespace CGAL { +//----------------------------------------------------------------------------- +template +struct Is_attribute_has_non_void_info; +template +struct Is_attribute_has_point; // **************************************************************************** namespace internal { @@ -638,34 +636,6 @@ struct Is_same_attribute_point_functor { return true; } }; // **************************************************************************** -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_point,Point,false) - -template -struct Is_nonvoid_attribute_has_non_void_info -{ - static const bool value=true; -}; -template -struct Is_nonvoid_attribute_has_non_void_info -{ - static const bool value=false; -}; - -template -struct Is_attribute_has_non_void_info -{ - static const bool value=Is_nonvoid_attribute_has_non_void_info::value; -}; -template<> -struct Is_attribute_has_non_void_info -{ - static const bool value=false; -}; -// **************************************************************************** -template -struct Is_attribute_has_point -{ static const bool value=Has_point::value; }; -// **************************************************************************** /// Test if the two darts are associated with the same attribute. template struct Test_is_same_attribute_functor diff --git a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h index 95193df77dc..ede3dd331d8 100644 --- a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h +++ b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h @@ -129,6 +129,7 @@ namespace CGAL { Functor_on_merge_, Functor_on_split_> Base1; typedef Point_for_cell Base2; + typedef void Info; typedef typename LCC::Point Point; typedef typename LCC::Dart_handle Dart_handle; typedef typename LCC::Dart_const_handle Dart_const_handle; From 1609fbe902674b120a84ae9e947189ef1cf39321 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 11 Jun 2015 11:34:24 +0200 Subject: [PATCH 02/24] Bug fix --- Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h index 5446c343e63..1eb4d658119 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -378,7 +378,7 @@ namespace CGAL { { std::ofstream output(filename); if (!output) return false; - save_combinatorial_map(amap, filename); + save_combinatorial_map(amap, output); } // Here T is a Dart_handle so no need of & From 1867f5b09630c002c6d0d795360ae41a63358076 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 15 Jun 2015 14:53:00 +0200 Subject: [PATCH 03/24] Add save/load in the demo. --- .../examples/Combinatorial_map/map_3_load.cpp | 402 ---------------- .../examples/Combinatorial_map/map_3_save.cpp | 430 ------------------ .../include/CGAL/Combinatorial_map.h | 4 +- .../demo/Linear_cell_complex/MainWindow.cpp | 98 +++- .../demo/Linear_cell_complex/MainWindow.h | 5 + .../demo/Linear_cell_complex/MainWindow.ui | 15 +- .../demo/Linear_cell_complex/typedefs.h | 36 +- 7 files changed, 153 insertions(+), 837 deletions(-) delete mode 100644 Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp delete mode 100644 Combinatorial_map/examples/Combinatorial_map/map_3_save.cpp diff --git a/Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp b/Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp deleted file mode 100644 index 22e4f67f518..00000000000 --- a/Combinatorial_map/examples/Combinatorial_map/map_3_load.cpp +++ /dev/null @@ -1,402 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//****************************************************************************** -// Functor used to display all the attributes of a given dimension. -template -struct My_functor_display_attrib -{ - template - static void run(const CMap& amap) - { - std::cout<::type::const_iterator - it_attrib = amap.template attributes().begin(), - itend_attrib = amap.template attributes().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<info()<<" "; - } - std::cout< -void display_map(const CMap& amap) -{ - amap.display_characteristics(std::cout) - <<", valid="< >::run(amap); -} -//****************************************************************************** -// Functor used to display all the attributes of a given dimension. -template::type::Info> -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<::type::const_iterator - it_attrib = amap.template attributes().begin(), - itend_attrib = amap.template attributes().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<info()<<" "; - } - std::cout< -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<().size()<<" attributes without info." - < -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<<"0-attributes: "; - - typename CMap::template Attribute_range<0>::type::const_iterator - it_attrib = amap.template attributes<0>().begin(), - itend_attrib = amap.template attributes<0>().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<<"("<point()<<") "; - } - std::cout< -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<<"0-attributes: "; - - typename CMap::template Attribute_range<0>::type::const_iterator - it_attrib = amap.template attributes<0>().begin(), - itend_attrib = amap.template attributes<0>().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<<"("<point()<<" "<info()<<") "; - } - std::cout< -struct My_functor_display_attrib_lcc -{ - template - static void run(const CMap& amap) - { My_functor_display_one_attrib_lcc::run(amap); } -}; - -// Display the map, i.e. all its characteristics, then all its attributes. -template < class CMap > -void display_lcc(const CMap& amap) -{ - amap.display_characteristics(std::cout) - <<", valid="< >::run(amap); -} - -//****************************************************************************** -/* Configuration example 1 - Map containing attributes defined with basic types. */ -struct MesAttributs1 -{ - template < class CMap> - struct Dart_wrapper - { - typedef CGAL::Dart<3, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<3, MesAttributs1> CMap_3a; - -bool example1(const char* filename) -{ - std::cout<<"************** example 1 **************"<>cm; - display_map(cm); - return true; -} - -//****************************************************************************** -/* Configuration example 2 - Map containing custom attributes, without overload read_cmap_attribute_node. - In this case, custom attributes are not loaded. Use custom load dart. */ -struct ACustomType -{ - int anint; - float afloat; - ACustomType(int ai=0, float af=0.0) : anint(ai), afloat(af) - {} - friend std::ostream& operator<<(std::ostream& os, const ACustomType& a) - { return os<<"["< - struct Dart_wrapper - { - typedef CGAL::Dart<3, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<3, MesAttributs2> CMap_3b; - -namespace CGAL -{ -// Definition of function allowing to same custom darts. -template<> -void read_cmap_dart_node -(const boost::property_tree::ptree::value_type & v, - CMap_3b::Dart_handle dh) -{ - std::cout<<"Read dart "<("myn")<>cm; - display_map(cm); - return true; -} - -//****************************************************************************** -/* Configuration example 3 - Map containing custom attributes, and overloading read_cmap_attribute_node. - Here custom attributes are also loaded. */ -struct ACustomType2 -{ - int anint; - float afloat; - ACustomType2(int ai=0, float af=0.0) : anint(ai), afloat(af) - {} - friend std::ostream& operator<<(std::ostream& os, const ACustomType2& a) - { return os<<"["< -void read_cmap_attribute_node -(const boost::property_tree::ptree::value_type &v,ACustomType2 &val) -{ - val.anint = v.second.get("v1"); - val.afloat = v.second.get("v2"); - - /* Example showing how to iterate through all the son of the node v. - BOOST_FOREACH( const boost::property_tree::ptree::value_type &v2, v.second) - { - if(v2.first=="v1") - { - val.anint=boost::lexical_cast< int >(v2.second.data()); - } - else if (v2.first=="v2") - { - val.afloat=boost::lexical_cast< float >(v2.second.data()); - } - } - */ -} - -} - -struct MesAttributs3 -{ - template < class CMap> - struct Dart_wrapper - { - typedef CGAL::Dart<3, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<3, MesAttributs3> CMap_3c; - -bool example3(const char* filename) -{ - std::cout<<"************** example 3 **************"<>cm; - display_map(cm); - return true; -} - -//****************************************************************************** -/* Configuration example 4 - Map containing custom attributes, and overloading read_cmap_attribute_node. - But dimension of the map is 2 (instead of 3 in previous examples). */ -struct MesAttributs4 -{ - template < class CMap> - struct Dart_wrapper - { - typedef CGAL::Dart<2, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<2, MesAttributs4> CMap_2; - -bool example4(const char* filename) -{ - std::cout<<"************** example 4 **************"<>cm; - display_map(cm); - return true; -} - -//****************************************************************************** -/* Configuration example 5 - Map containing custom attributes, and overloading read_cmap_attribute_node. - But dimension of the map is 5. */ -struct MesAttributs5 -{ - template < class CMap> - struct Dart_wrapper - { - typedef CGAL::Dart<5, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<5, MesAttributs5> CMap_5; - -bool example5(const char* filename) -{ - std::cout<<"************** example 5 **************"<>cm; - display_map(cm); - return true; -} - -//****************************************************************************** -/* Configuration example 6 - Linear cell complex without attributes*/ -typedef CGAL::Linear_cell_complex<3> LCC_1; - -bool example6(const char* filename) -{ - std::cout<<"************** example 6 **************"<>cm; - display_lcc(cm); - return true; -} - -//****************************************************************************** -/* Configuration example 7 - Linear cell complex with attributes*/ -struct Myitem7 -{ - template - struct Dart_wrapper - { - typedef CGAL::Dart<3, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int, CGAL::Tag_true> - Vertex_attribute; - typedef CGAL::Cell_attribute T1; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; -typedef CGAL::Linear_cell_complex_traits -<3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits; -typedef CGAL::Linear_cell_complex<3,3,Traits,Myitem7> LCC_2; - -bool example7(const char* filename) -{ - std::cout<<"************** example 7 **************"<>cm; - display_lcc(cm); - return true; -} - -//****************************************************************************** -//==================================== main ==================================== -int main(int argc, char* argv[]) -{ - if(argc!=2) - { - std::cout<<"Usage: a.out filename"< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//****************************************************************************** -// Functor used to display all the attributes of a given dimension. -template -struct My_functor_display_attrib -{ - template - static void run(const CMap& amap) - { - std::cout<::type::const_iterator - it_attrib = amap.template attributes().begin(), - itend_attrib = amap.template attributes().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<info()<<" "; - } - std::cout< -void display_map(const CMap& amap) -{ - amap.display_characteristics(std::cout) - <<", valid="< >::run(amap); -} - -//****************************************************************************** -// Functor used to display all the attributes of a given dimension. -template::type::Info> -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<::type::const_iterator - it_attrib = amap.template attributes().begin(), - itend_attrib = amap.template attributes().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<info()<<" "; - } - std::cout< -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<().size()<<" attributes without info." - < -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<<"0-attributes: "; - - typename CMap::template Attribute_range<0>::type::const_iterator - it_attrib = amap.template attributes<0>().begin(), - itend_attrib = amap.template attributes<0>().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<<"("<point()<<") "; - } - std::cout< -struct My_functor_display_one_attrib_lcc -{ - static void run(const CMap& amap) - { - std::cout<<"0-attributes: "; - - typename CMap::template Attribute_range<0>::type::const_iterator - it_attrib = amap.template attributes<0>().begin(), - itend_attrib = amap.template attributes<0>().end(); - - for (; it_attrib!=itend_attrib; ++it_attrib) - { - std::cout<<"("<point()<<" "<info()<<") "; - } - std::cout< -struct My_functor_display_attrib_lcc -{ - template - static void run(const CMap& amap) - { My_functor_display_one_attrib_lcc::run(amap); } -}; - -// Display the map, i.e. all its characteristics, then all its attributes. -template < class CMap > -void display_lcc(const CMap& amap) -{ - amap.display_characteristics(std::cout) - <<", valid="< >::run(amap); -} - -//****************************************************************************** -/* Configuration example 1 - Map containing attributes defined with basic types. */ -struct MesAttributs1 -{ - template < class CMap> - struct Dart_wrapper - { - typedef CGAL::Dart<3, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<3, MesAttributs1> CMap_3a; -typedef CMap_3a::Dart_handle Dart_handle_a; - -void example1() -{ - CMap_3a cm; - - // 1) create two tetrahedra 3-sewn - Dart_handle_a dh1 = CGAL::make_combinatorial_tetrahedron(cm); - Dart_handle_a dh2 = CGAL::make_combinatorial_tetrahedron(cm); - cm.sew<3>(dh1,dh2); - - // 2) make attributes - for (CMap_3a::Dart_range::iterator it(cm.darts().begin()), - itend(cm.darts().end()); it!=itend; ++it) - { - if ( it->attribute<1>()==NULL ) - { - cm.set_attribute<1>(it, cm.create_attribute<1>()); - it->attribute<1>()->info()=cm.number_of_attributes<1>(); - } - if( it->attribute<2>()==NULL) - { - cm.set_attribute<2>(it, cm.create_attribute<2>()); - it->attribute<2>()->info()=(cm.number_of_attributes<2>()/2.0); - } - } - - std::cout<<"************** example 1 **************"< - struct Dart_wrapper - { - typedef CGAL::Dart<3, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<3, MesAttributs2> CMap_3b; -typedef CMap_3b::Dart_handle Dart_handle_b; - -void example2() -{ - CMap_3b cm; - - // 1) create two tetrahedra 3-sewn - Dart_handle_b dh1 = CGAL::make_combinatorial_tetrahedron(cm); - Dart_handle_b dh2 = CGAL::make_combinatorial_tetrahedron(cm); - cm.sew<3>(dh1,dh2); - - // 2) make attributes - for (CMap_3b::Dart_range::iterator it(cm.darts().begin()), - itend(cm.darts().end()); it!=itend; ++it) - { - if ( it->attribute<1>()==NULL ) - { - cm.set_attribute<1>(it, cm.create_attribute<1>()); - it->attribute<1>()->info()=cm.number_of_attributes<1>(); - } - if( it->attribute<2>()==NULL) - { - cm.set_attribute<2>(it, cm.create_attribute<2>()); - it->attribute<2>()->info()=ACustomType((int)cm.number_of_attributes<2>(), - cm.number_of_attributes<2>()/2.0); - } - } - - std::cout<<"************** example 2 **************"< -void write_cmap_attribute_node(boost::property_tree::ptree & node, - const ACustomType2& arg) -{ - boost::property_tree::ptree & nValue = node.add("v",""); - nValue.add("v1",arg.anint); - nValue.add("v2",arg.afloat); -} - -} - -struct MesAttributs3 -{ - template < class CMap> - struct Dart_wrapper - { - typedef CGAL::Dart<3, CMap> Dart; - typedef CGAL::Cell_attribute T1; - typedef CGAL::Cell_attribute T2; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; - -typedef CGAL::Combinatorial_map<3, MesAttributs3> CMap_3c; -typedef CMap_3c::Dart_handle Dart_handle_c; -typedef CMap_3c::Dart_const_handle Dart_const_handle_c; - -namespace CGAL -{ -// Definition of function allowing to same custom darts. -template<> -void write_cmap_dart_node(boost::property_tree::ptree & node, - Dart_const_handle_c dh) -{ - static int i=0; - boost::property_tree::ptree & nValue = node.add("v",""); - nValue.add("myn",i++); -} - -} - - -void example3() -{ - CMap_3c cm; - - // 1) create two tetrahedra 3-sewn - Dart_handle_c dh1 = CGAL::make_combinatorial_tetrahedron(cm); - Dart_handle_c dh2 = CGAL::make_combinatorial_tetrahedron(cm); - cm.sew<3>(dh1,dh2); - - // 2) make attributes - for (CMap_3c::Dart_range::iterator it(cm.darts().begin()), - itend(cm.darts().end()); it!=itend; ++it) - { - if ( it->attribute<1>()==NULL ) - { - cm.set_attribute<1>(it, cm.create_attribute<1>()); - it->attribute<1>()->info()=cm.number_of_attributes<1>(); - } - if( it->attribute<2>()==NULL) - { - cm.set_attribute<2>(it, cm.create_attribute<2>()); - it->attribute<2>()->info()=ACustomType2(cm.number_of_attributes<2>(), - cm.number_of_attributes<2>()/2.0); - } - } - - std::cout<<"************** example 3 **************"< LCC_1; - -void example4() -{ - LCC_1 lcc; - LCC_1::Dart_handle d1 = lcc.make_tetrahedron(LCC_1::Point(-1, 0, 0), - LCC_1::Point(0, 2, 0), - LCC_1::Point(1, 0, 0), - LCC_1::Point(1, 1, 2)); - LCC_1::Dart_handle d2 = lcc.make_tetrahedron(LCC_1::Point(0, 2, -1), - LCC_1::Point(-1, 0, -1), - LCC_1::Point(1, 0, -1), - LCC_1::Point(1, 1, -3)); - lcc.sew<3>(d1, d2); - - std::cout<<"************** example 4 **************"< - struct Dart_wrapper - { - typedef CGAL::Dart<3, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int, CGAL::Tag_true> - Vertex_attribute; - typedef CGAL::Cell_attribute T1; - typedef CGAL::cpp0x::tuple Attributes; - }; -}; -typedef CGAL::Linear_cell_complex_traits -<3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits; -typedef CGAL::Linear_cell_complex<3,3,Traits,Myitem7> LCC_2; - -void example5() -{ - LCC_2 lcc; - LCC_2::Dart_handle d1 = lcc.make_tetrahedron(LCC_2::Point(-1, 0, 0), - LCC_2::Point(0, 2, 0), - LCC_2::Point(1, 0, 0), - LCC_2::Point(1, 1, 2)); - LCC_2::Dart_handle d2 = lcc.make_tetrahedron(LCC_2::Point(0, 2, -1), - LCC_2::Point(-1, 0, -1), - LCC_2::Point(1, 0, -1), - LCC_2::Point(1, 1, -3)); - lcc.sew<3>(d1, d2); - - // 2) make attributes - for (LCC_2::Dart_range::iterator it(lcc.darts().begin()), - itend(lcc.darts().end()); it!=itend; ++it) - { - it->attribute<0>()->info()=rand()%10; - if ( it->attribute<1>()==NULL ) - { - lcc.set_attribute<1>(it, lcc.create_attribute<1>()); - it->attribute<1>()->info()=lcc.number_of_attributes<1>(); - } - } - - std::cout<<"************** example 5 **************"<> (std::ifstream& is, Self& amap) { load_combinatorial_map(is, amap); return is; } - + /** Create a new dart and add it to the map. * The marks of the darts are initialised with mmask_marks, i.e. the dart * is unmarked for all the marks. diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 85a65cb06cc..65c1f835731 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -81,7 +81,7 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), this->addRecentFiles (this->menuFile, this->actionQuit); connect (this, SIGNAL (openRecentFile (QString)), - this, SLOT (load_off (QString))); + this, SLOT (load_depend_on_extension(QString))); statusMessage = new QLabel ("Darts: 0, Vertices: 0 (Points: 0), Edges: 0, Facets: 0," @@ -222,6 +222,32 @@ void MainWindow::init_all_new_volumes() { on_new_volume(it); } } +void MainWindow::on_actionSave_triggered () +{ + QString fileName = QFileDialog::getSaveFileName (this, + tr ("Save"), + "save.3map", + tr ("3-map files (*.3map)")); + + if (!fileName.isEmpty ()) + { + save(fileName); + } +} + +void MainWindow::on_actionLoad_triggered () +{ + QString fileName = QFileDialog::getOpenFileName (this, + tr ("Load"), + "./3map", + tr ("3-map files (*.3map)")); + + if (!fileName.isEmpty ()) + { + load(fileName, true); + } +} + void MainWindow::on_actionImportOFF_triggered () { QString fileName = QFileDialog::getOpenFileName (this, @@ -263,6 +289,76 @@ void MainWindow::on_actionAddOFF_triggered() } } +void MainWindow::load_depend_on_extension(const QString & fileName, bool clear) +{ + QString ext = QFileInfo(fileName).suffix(); + if ( ext=="3map") + load(fileName, clear); + else if (ext=="off") + load_off(fileName, clear); + else + { + std::cout<<"Extension not considered."<clear_all(); + +#ifdef CGAL_PROFILE_LCC_DEMO + CGAL::Timer timer; + timer.start(); +#endif + + bool res = load_combinatorial_map(fileName.toStdString().c_str(), *(scene.lcc)); + +#ifdef CGAL_PROFILE_LCC_DEMO + timer.stop(); + std::cout<<"Time to load 3-map "<addToRecentFiles(fileName); + QApplication::restoreOverrideCursor (); + + if (res) + statusBar ()->showMessage (QString ("3-map loaded ") + fileName, + DELAY_STATUSMSG); + else + statusBar ()->showMessage (QString ("Problem: 3-map not loaded ") + fileName, + DELAY_STATUSMSG); + Q_EMIT (sceneChanged ()); +} + +void MainWindow::save(const QString & fileName) +{ + QApplication::setOverrideCursor (Qt::WaitCursor); + +#ifdef CGAL_PROFILE_LCC_DEMO + CGAL::Timer timer; + timer.start(); +#endif + + if ( save_combinatorial_map(*(scene.lcc), fileName.toStdString().c_str()) ) + statusBar ()->showMessage (QString ("3-map saved ") + fileName, + DELAY_STATUSMSG); + else + statusBar ()->showMessage (QString ("Problem: 3-map not saved ") + fileName, + DELAY_STATUSMSG); + QApplication::restoreOverrideCursor (); + +#ifdef CGAL_PROFILE_LCC_DEMO + timer.stop(); + std::cout<<"Time to save 3-map "<0 0 635 - 22 + 25 &File + + + @@ -221,6 +224,16 @@ Create Sierpinski Triangle + + + &Load + + + + + &Save + + diff --git a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h index d31132c1de3..61ba838b8ca 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,11 @@ extern CGAL::Random myrandom; class Volume_info { + friend void CGAL::read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,Volume_info &val); + + friend void CGAL::write_cmap_attribute_node(boost::property_tree::ptree & node, + const Volume_info& arg); public: Volume_info() : m_color(CGAL::Color(myrandom.get_int(0,256), myrandom.get_int(0,256), @@ -91,11 +97,39 @@ public: void negate_filled() { set_filled(!is_filled()); } - private: +private: CGAL::Color m_color; char m_status; }; +namespace CGAL +{ + +template<> +inline void read_cmap_attribute_node +(const boost::property_tree::ptree::value_type &v,Volume_info &val) +{ + val.m_status = v.second.get("status"); + char r = v.second.get("color-r"); + char g = v.second.get("color-g"); + char b = v.second.get("color-b"); + val.m_color = CGAL::Color(r,g,b); +} + +// Definition of function allowing to save custon information. +template<> +inline void write_cmap_attribute_node(boost::property_tree::ptree & node, + const Volume_info& arg) +{ + boost::property_tree::ptree & nValue = node.add("v",""); + nValue.add("status",(int)arg.m_status); + nValue.add("color-r",(int)arg.m_color.r()); + nValue.add("color-g",(int)arg.m_color.g()); + nValue.add("color-b",(int)arg.m_color.b()); +} + +} + class Myitems { public: From 1797dc57e07a17df902b53c396f7c97d004dd241 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 15 Jun 2015 16:18:05 +0200 Subject: [PATCH 04/24] * add one more import * bugfix in drawing fuction (to draw a volume in wireframe) --- .../demo/Linear_cell_complex/MainWindow.cpp | 54 ++++- .../demo/Linear_cell_complex/MainWindow.h | 2 + .../demo/Linear_cell_complex/MainWindow.ui | 6 + .../demo/Linear_cell_complex/Viewer.cpp | 55 ++--- .../demo/Linear_cell_complex/import_moka.h | 192 ++++++++++++++++++ 5 files changed, 283 insertions(+), 26 deletions(-) create mode 100644 Linear_cell_complex/demo/Linear_cell_complex/import_moka.h diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 65c1f835731..610dfdfe557 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -22,9 +22,10 @@ #include "MainWindow.h" #include #include -#include "MainWindow.moc" #include #include +#include "MainWindow.moc" +#include "import_moka.h" // Function defined in Linear_cell_complex_3_subivision.cpp void subdivide_lcc_3 (LCC & m); @@ -261,6 +262,19 @@ void MainWindow::on_actionImportOFF_triggered () } } +void MainWindow::on_actionImportMoka_triggered() +{ + QString fileName = QFileDialog::getOpenFileName (this, + tr ("Import Moka"), + "./moka", + tr ("Moka files (*.moka)")); + + if (!fileName.isEmpty ()) + { + load_moka(fileName, true); + } +} + void MainWindow::on_actionImport3DTDS_triggered () { QString fileName = QFileDialog::getOpenFileName (this, @@ -296,6 +310,8 @@ void MainWindow::load_depend_on_extension(const QString & fileName, bool clear) load(fileName, clear); else if (ext=="off") load_off(fileName, clear); + else if (ext=="moka") + load_moka(fileName, clear); else { std::cout<<"Extension not considered."<addToRecentFiles(fileName); QApplication::restoreOverrideCursor (); @@ -428,6 +444,40 @@ void MainWindow::load_3DTDS (const QString & fileName, bool clear) Q_EMIT (sceneChanged ()); } +void MainWindow::load_moka(const QString & fileName, bool clear) +{ + QApplication::setOverrideCursor (Qt::WaitCursor); + + if (clear) this->clear_all(); + +#ifdef CGAL_PROFILE_LCC_DEMO + CGAL::Timer timer; + timer.start(); +#endif + + CGAL::import_from_moka < LCC > (*scene.lcc, qPrintable (fileName)); + +#ifdef CGAL_PROFILE_LCC_DEMO + timer.stop(); + std::cout<<"Time to load off "<addToRecentFiles (fileName); + QApplication::restoreOverrideCursor (); + + if (clear) + statusBar ()->showMessage (QString ("Load off file") + fileName, + DELAY_STATUSMSG); + else + statusBar ()->showMessage (QString ("Add off file") + fileName, + DELAY_STATUSMSG); + Q_EMIT (sceneChanged ()); +} + Dart_handle MainWindow::make_iso_cuboid(const Point_3 basepoint, LCC::FT lg) { return scene.lcc->make_hexahedron(basepoint, diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h index 3dd455935e0..94ece0289c1 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h @@ -115,6 +115,7 @@ public Q_SLOTS: void on_actionImportOFF_triggered(); void on_actionAddOFF_triggered(); void on_actionImport3DTDS_triggered(); + void on_actionImportMoka_triggered(); void on_actionCompute_Voronoi_3D_triggered(); void on_actionClear_triggered(); @@ -148,6 +149,7 @@ public Q_SLOTS: void save(const QString& fileName); void load_off(const QString& fileName, bool clear=true); void load_3DTDS(const QString& fileName, bool clear=true); + void load_moka(const QString& fileName, bool clear=true); void onSceneChanged(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui index 356593a38ba..33291ca159e 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui @@ -45,6 +45,7 @@ + @@ -234,6 +235,11 @@ &Save + + + Import Moka + + diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index 2840bb5b4f9..ab5d6aa9051 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -30,11 +30,11 @@ Viewer::sceneChanged() this->initDraw(); this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(), - bb.ymin(), - bb.zmin()), - qglviewer::Vec(bb.xmax(), - bb.ymax(), - bb.zmax())); + bb.ymin(), + bb.zmin()), + qglviewer::Vec(bb.xmax(), + bb.ymax(), + bb.zmax())); this->showEntireScene(); } @@ -53,34 +53,41 @@ void Viewer::drawAllFaces(bool flat) (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) { // We draw the polygon - ::glBegin(GL_POLYGON); - - // double r = (double)dartIter->attribute<3>()->info().r()/255.0; - double r = (double)lcc.info<3>(dartIter).color().r()/255.0; - double g = (double)lcc.info<3>(dartIter).color().g()/255.0; - double b = (double)lcc.info<3>(dartIter).color().b()/255.0; - if ( !lcc.is_free(dartIter, 3) ) + if ( it->info().is_filled() ) { - r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; - g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; - b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; - r /= 2; g /= 2; b /= 2; + ::glBegin(GL_POLYGON); + // double r = (double)dartIter->attribute<3>()->info().r()/255.0; + double r = (double)lcc.info<3>(dartIter).color().r()/255.0; + double g = (double)lcc.info<3>(dartIter).color().g()/255.0; + double b = (double)lcc.info<3>(dartIter).color().b()/255.0; + if ( !lcc.is_free(dartIter, 3) ) + { + r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; + g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; + b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; + r /= 2; g /= 2; b /= 2; + } + + ::glColor3f(r,g,b); + + if(flat) + { + LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); + normal = normal/(CGAL::sqrt(normal*normal)); + ::glNormal3d(normal.x(), normal.y(), normal.z()); + } } - - ::glColor3f(r,g,b); - - if(flat) + else { - LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); - normal = normal/(CGAL::sqrt(normal*normal)); - ::glNormal3d(normal.x(), normal.y(), normal.z()); + ::glBegin(GL_LINE_STRIP); + ::glColor3f(.2f,.2f,.6f); } for (LCC::Dart_of_orbit_range<1>::const_iterator orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); orbitIter.cont(); ++orbitIter) { - if(!flat) + if(!flat && it->info().is_filled()) { // If Gouraud shading: 1 normal per vertex LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h b/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h new file mode 100644 index 00000000000..83791442bff --- /dev/null +++ b/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h @@ -0,0 +1,192 @@ +// Copyright (c) 2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// +#ifndef IMPORT_MOKA_H +#define IMPORT_MOKA_H + +namespace CGAL +{ +struct GDart +{ + unsigned int alpha[4]; + Dart_handle dh; + LCC::Vertex_attribute_handle vh; + + GDart() : dh(NULL), vh(NULL) + {} + + GDart(const GDart& adart) : dh(adart.dh), + vh(adart.vh) + { + for (unsigned int i=0; i<4; ++i) + alpha[i]=adart.alpha[i]; + } +}; + +template +bool import_from_moka(LCC& lcc, const char* filename) +{ + typedef typename LCC::Point Point; + + std::ifstream ifile(filename); + if (!ifile) + { + std::cout<<"Error opening file "< gdarts; + int nbLoaded = 0; + unsigned int number; + double x,y,z; + + // First load all the gdarts, and create vertex attributes + while(ifile) + { + GDart agdart; + ifile>>agdart.alpha[0]>>agdart.alpha[1] + >>agdart.alpha[2]>>agdart.alpha[3]; // the 4 alpha + ifile>>number>>number>>number>>number; // to skip the 4*8 marks + if ( agdart.alpha[0]==nbLoaded ) + { + std::cout<<"Impossible to load a moka file with 0-free darts.\n"; + return false; + } + if ( ifile ) + { + ifile>>number; // bool to know if dart has a vertex of not. + if (number) + { + ifile>>x>>y>>z; + agdart.vh = lcc.create_vertex_attribute(Point(x, y, z)); + } + + gdarts.push_back(agdart); + ++nbLoaded; + } + } + ifile.close(); + + // Second orient the gmap, and create oriented darts. + std::stack totreat; + for (int startingdart = 0; startingdartattribute<3>() == NULL ) + { + lcc.template set_attribute<3>(gdarts[i].dh, lcc.template create_attribute<3>()); + } + } + if (gdarts[i].vh!=NULL) + { + lcc.set_vertex_attribute(gdarts[i].dh, gdarts[i].vh); + } + } + + return true; +} + +} + +#endif From 4bae2612d8b1b1c14316c5144969e26d3c554924 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 15 Jun 2015 21:14:02 +0200 Subject: [PATCH 05/24] * Modify load to not take into account the typeid of attributes * Update the demo to draw non convex faces --- .../CGAL/Combinatorial_map_save_load.h | 12 +- .../demo/Linear_cell_complex/Viewer.cpp | 140 ++++++++++++------ .../demo/Linear_cell_complex/Viewer.h | 25 +++- .../demo/Linear_cell_complex/typedefs.h | 29 ++-- 4 files changed, 147 insertions(+), 59 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h index 1eb4d658119..2ac5328f8c1 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -487,11 +487,11 @@ namespace CGAL { (typeid(typename CMap::template Attribute_type::type::Point).name()); // std::cout<<"ptype="<::type::Point).name(); // std::cout<<"ptype="<::type::Info).name(); // std::cout<<"ptype="<showEntireScene(); } +void Viewer::drawOneFaceWireframe(Dart_handle dh) +{ + ::glColor3f(.2f,.2f,.6f); + + ::glBegin(GL_LINE_STRIP); + + for (LCC::Dart_of_orbit_range<1>::const_iterator + orbitIter = scene->lcc->darts_of_orbit<1>(dh).begin(); + orbitIter.cont(); ++orbitIter) + { + const LCC::Point& p = scene->lcc->point(orbitIter); + ::glVertex3d(p.x(),p.y(),p.z()); + } + + ::glEnd(); +} + +void Viewer::drawOneFilledFace(Dart_handle dh) +{ + LCC &lcc = *scene->lcc; + + // double r = (double)dartIter->attribute<3>()->info().r()/255.0; + double r = (double)lcc.info<3>(dh).color().r()/255.0; + double g = (double)lcc.info<3>(dh).color().g()/255.0; + double b = (double)lcc.info<3>(dh).color().b()/255.0; + if ( !lcc.is_free(dh, 3) ) + { + r += (double)lcc.info<3>(lcc.beta(dh,3)).color().r()/255.0; + g += (double)lcc.info<3>(lcc.beta(dh,3)).color().g()/255.0; + b += (double)lcc.info<3>(lcc.beta(dh,3)).color().b()/255.0; + r /= 2; g /= 2; b /= 2; + } + + ::glColor3f(r,g,b); + + if(flatShading) + { + LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dh); + normal = normal/(CGAL::sqrt(normal*normal)); + ::glNormal3d(normal.x(), normal.y(), normal.z()); + } + + // array of vertices of the face + std::size_t nb=0; + for (LCC::Dart_of_orbit_range<1>::const_iterator it(lcc, dh); it.cont(); ++it, ++nb); + ++nb; // the last vertex of the array is the first vertex + + gluTessBeginPolygon(FTess, NULL); + gluTessBeginContour(FTess); + + GLdouble* data = new GLdouble[3*nb]; + std::size_t i=0; + for (LCC::Dart_of_orbit_range<1>::const_iterator it(lcc, dh); it.cont(); ++it, ++i) + { + const LCC::Point& p = lcc.point(it); + data[ (i*3)] = p.x(); + data[1+(i*3)] = p.y(); + data[2+(i*3)] = p.z(); + + if(!flatShading) + { + // If Gouraud shading: 1 normal per vertex + LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,it); + normal = normal/(CGAL::sqrt(normal*normal)); + ::glNormal3d(normal.x(), normal.y(), normal.z()); + } + + gluTessVertex(FTess, &data[i*3], &data[i*3]); + } + + const LCC::Point& p = lcc.point(dh); + data[ (i*3)] = p.x(); + data[1+(i*3)] = p.y(); + data[2+(i*3)] = p.z(); + + // If Gouraud shading: 1 normal per vertex + if(!flatShading) + { + LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,dh); + normal = normal/(CGAL::sqrt(normal*normal)); + ::glNormal3d(normal.x(), normal.y(), normal.z()); + } + + gluTessVertex(FTess, &data[i*3], &data[i*3]); + + gluTessEndContour(FTess); + gluTessEndPolygon(FTess); + + delete [] data; +} + void Viewer::drawAllFaces(bool flat) { LCC &lcc = *scene->lcc; @@ -55,51 +146,12 @@ void Viewer::drawAllFaces(bool flat) // We draw the polygon if ( it->info().is_filled() ) { - ::glBegin(GL_POLYGON); - // double r = (double)dartIter->attribute<3>()->info().r()/255.0; - double r = (double)lcc.info<3>(dartIter).color().r()/255.0; - double g = (double)lcc.info<3>(dartIter).color().g()/255.0; - double b = (double)lcc.info<3>(dartIter).color().b()/255.0; - if ( !lcc.is_free(dartIter, 3) ) - { - r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; - g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; - b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; - r /= 2; g /= 2; b /= 2; - } - - ::glColor3f(r,g,b); - - if(flat) - { - LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); - normal = normal/(CGAL::sqrt(normal*normal)); - ::glNormal3d(normal.x(), normal.y(), normal.z()); - } + drawOneFilledFace(dartIter); } else { - ::glBegin(GL_LINE_STRIP); - ::glColor3f(.2f,.2f,.6f); + drawOneFaceWireframe(dartIter); } - - for (LCC::Dart_of_orbit_range<1>::const_iterator - orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); - orbitIter.cont(); ++orbitIter) - { - if(!flat && it->info().is_filled()) - { - // If Gouraud shading: 1 normal per vertex - LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); - normal = normal/(CGAL::sqrt(normal*normal)); - ::glNormal3d(normal.x(), normal.y(), normal.z()); - } - - const LCC::Point& p = lcc.point(orbitIter); - ::glVertex3d(p.x(),p.y(),p.z()); - } - - ::glEnd(); } } } @@ -112,10 +164,11 @@ void Viewer::drawAllEdges() if ( lcc.is_empty() ) return; // ::glDepthRange(0.0, 1.0-0.005); - ::glBegin(GL_LINES); //::glColor3f(0.0f, 0.0f, 0.0f); ::glColor3f(.2f,.2f,.6f); + ::glBegin(GL_LINES); + for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), itend=lcc.attributes<3>().end(); it!=itend; ++it ) @@ -154,9 +207,10 @@ void Viewer::drawAllVertices() // ::glDepthRange(0.0, 1.0-0.005); ::glPointSize(7.0); - ::glBegin(GL_POINTS); ::glColor3f(0.2f, 0.2f, 0.7f); + ::glBegin(GL_POINTS); + bool empty = true; for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index c8daaa5c117..5c7cbfd4d80 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -25,6 +25,15 @@ #include #include +static void monCombine(GLdouble c[3], void *d[4], GLfloat w[4], void **out) +{ + GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble)*3); + nv[0] = c[0]; + nv[1] = c[1]; + nv[2] = c[2]; + *out = nv; +} + class Viewer : public QGLViewer { Q_OBJECT @@ -43,10 +52,11 @@ class Viewer : public QGLViewer GLuint m_dlVertices; bool m_displayListCreated; + GLUtesselator* FTess; + typedef LCC::Dart_handle Dart_handle; typedef LCC::Dart_const_handle Dart_const_handle; - public: Viewer(QWidget* parent) : QGLViewer(parent), wireframe(false), flatShading(true), @@ -56,6 +66,17 @@ public: newFormat.setSampleBuffers(true); newFormat.setSamples(16); this->setFormat(newFormat); + + FTess = gluNewTess(); + gluTessCallback(FTess, GLU_TESS_BEGIN, (GLvoid (*) ( )) & glBegin); + gluTessCallback(FTess, GLU_TESS_END, (GLvoid (*) ( )) & glEnd); + gluTessCallback(FTess, GLU_TESS_VERTEX, (GLvoid (*) ( )) & glVertex3dv); + gluTessCallback(FTess, GLU_TESS_COMBINE, (GLvoid (*) ( )) & monCombine ); + } + + ~Viewer() + { + gluDeleteTess(FTess); } void setScene(Scene* scene_) @@ -81,6 +102,8 @@ protected: void drawAllFaces(bool flat); void drawAllEdges(); void drawAllVertices(); + void drawOneFaceWireframe(Dart_handle); + void drawOneFilledFace(Dart_handle); }; #endif diff --git a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h index 61ba838b8ca..2c4f8cbdffa 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h @@ -50,7 +50,7 @@ class Volume_info (const boost::property_tree::ptree::value_type &v,Volume_info &val); friend void CGAL::write_cmap_attribute_node(boost::property_tree::ptree & node, - const Volume_info& arg); + const Volume_info& arg); public: Volume_info() : m_color(CGAL::Color(myrandom.get_int(0,256), myrandom.get_int(0,256), @@ -109,11 +109,22 @@ template<> inline void read_cmap_attribute_node (const boost::property_tree::ptree::value_type &v,Volume_info &val) { - val.m_status = v.second.get("status"); - char r = v.second.get("color-r"); - char g = v.second.get("color-g"); - char b = v.second.get("color-b"); - val.m_color = CGAL::Color(r,g,b); + try + { + val.m_status = v.second.get("status"); + } + catch(const std::exception & ) + {} + + try + { + char r = v.second.get("color-r"); + char g = v.second.get("color-g"); + char b = v.second.get("color-b"); + val.m_color = CGAL::Color(r,g,b); + } + catch(const std::exception & ) + {} } // Definition of function allowing to save custon information. @@ -134,13 +145,13 @@ class Myitems { public: template < class Refs > - struct Dart_wrapper + struct Dart_wrapper { typedef CGAL::Dart<3, Refs > Dart; - + typedef CGAL::Cell_attribute_with_point< Refs > Vertex_attrib; typedef CGAL::Cell_attribute< Refs, Volume_info> Volume_attrib; - + typedef CGAL::cpp11::tuple Attributes; }; From 50fabbec8d3a87bd4123c3c84813c0ce8cda505e Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 15 Jun 2015 22:59:00 +0200 Subject: [PATCH 06/24] Add delaunay triangulation of faces --- .../demo/Linear_cell_complex/MainWindow.cpp | 264 +++++++++++++++++- .../demo/Linear_cell_complex/MainWindow.h | 4 +- .../demo/Linear_cell_complex/MainWindow.ui | 17 +- 3 files changed, 279 insertions(+), 6 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 610dfdfe557..97ed18e2d49 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -27,6 +27,11 @@ #include "MainWindow.moc" #include "import_moka.h" +#include +#include +#include +#include + // Function defined in Linear_cell_complex_3_subivision.cpp void subdivide_lcc_3 (LCC & m); @@ -928,7 +933,7 @@ void MainWindow::on_actionRemove_filled_volumes_triggered() DELAY_STATUSMSG); } -void MainWindow::on_actionTriangulate_all_facets_triggered() +void MainWindow::on_actionInsert_center_vertices_triggered() { QApplication::setOverrideCursor (Qt::WaitCursor); @@ -950,17 +955,83 @@ void MainWindow::on_actionTriangulate_all_facets_triggered() #ifdef CGAL_PROFILE_LCC_DEMO timer.stop(); - std::cout<<"Time to triangulate all filled faces: " + std::cout<<"Time to insert center vertices in all filled faces: " <showMessage - (QString ("Facets of visible and filled volume(s) triangulated"), + (QString ("Vertices are inserted in center of facets of visible and filled volume(s)"), DELAY_STATUSMSG); } +double compute_angle3d(const Vector_3& v1, const Vector_3& v2) +{ + double a = CGAL::to_double( (v1*v2) / + ( sqrt(v1.squared_length()) * sqrt(v2.squared_length()) ) ) ; + + if (a < -1.0) return acos(-1.0)/M_PI*180.0; + else if (a > 1.0) return acos(1.0)/M_PI*180.0; + else return acos(a)/M_PI*180.0; +} + +void MainWindow::on_actionMerge_coplanar_faces_triggered() +{ + QApplication::setOverrideCursor (Qt::WaitCursor); + +#ifdef CGAL_PROFILE_LCC_DEMO + CGAL::Timer timer; + timer.start(); +#endif + + std::vector edges; + int treated = scene.lcc->get_new_mark(); + + for ( typename LCC::Dart_range::iterator it= scene.lcc->darts().begin(), + itend = scene.lcc->darts().end(); it!=itend; ++it ) + { + if (!scene.lcc->is_marked(it, treated) && + CGAL::is_removable(*scene.lcc, it) ) + { + LCC::Vector normal1 = CGAL::compute_normal_of_cell_2(*scene.lcc,it); + LCC::Vector normal2 = CGAL::compute_normal_of_cell_2(*scene.lcc, scene.lcc->beta<2>(it) ); + double angle = compute_angle3d(normal1, normal2); + + if ( ((angle<5.0 or angle>355.0) or (angle<185.0 and angle>175.0)) ) + { + CGAL::mark_cell(*scene.lcc, it, treated); + edges.push_back(it); + } + } + } + + for (std::vector::iterator it=edges.begin(), + itend=edges.end(); it!=itend; ++it) + { + if ( !CGAL::belong_to_same_cell(*scene.lcc, *it, scene.lcc->beta<2>(*it)) ) + CGAL::remove_cell(*scene.lcc, *it); + else + CGAL::unmark_cell(*scene.lcc, *it, treated); + } + + assert(scene.lcc->is_whole_map_unmarked(treated)); + scene.lcc->free_mark(treated); + +#ifdef CGAL_PROFILE_LCC_DEMO + timer.stop(); + std::cout<<"Time to merge all coplanar faces: " + <showMessage + (QString ("Coplanar face(s) merged"), DELAY_STATUSMSG); +} + void MainWindow::on_actionMerge_all_volumes_triggered() { QApplication::setOverrideCursor (Qt::WaitCursor); @@ -1006,6 +1077,193 @@ void MainWindow::on_actionMerge_all_volumes_triggered() (QString ("Visible and filled volume(s) merged"), DELAY_STATUSMSG); } +typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; + +struct Face_info { + bool exist_edge[3]; + bool is_external; +}; + +typedef CGAL::Triangulation_face_base_with_info_2 Fb1; + +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::No_intersection_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; + +bool is_external(CDT::Face_handle fh) +{ + return fh->info().is_external; +} + +int number_of_existing_edge(CDT::Face_handle fh) +{ + unsigned res=0; + for (int i=0; i<3; ++i) + if (fh->info().exist_edge[i]) ++res; + return res; +} + +int get_free_edge(CDT::Face_handle fh) +{ + CGAL_assertion( number_of_existing_edge(fh)==2 ); + for (int i=0; i<3; ++i) + if (!fh->info().exist_edge[i]) return i; + + CGAL_assertion(false); + return -1; +} + +void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) +{ + Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc,d1); + P_traits cdt_traits(normal); + CDT cdt(cdt_traits); + + //inserting the constraints edge by edge + LCC::Dart_of_orbit_range<1>::iterator + it(lcc.darts_of_orbit<1>(d1).begin()); + + CDT::Vertex_handle previous=LCC::null_handle, first=LCC::null_handle, + vh=LCC::null_handle; + + for (LCC::Dart_of_orbit_range<1>::iterator + itend(lcc.darts_of_orbit<1>(d1).end()); it!=itend; ++it) + { + vh = cdt.insert(lcc.point(it)); + vh->info()=it; + if( first==NULL ) + { + first=vh; + } + if( previous!=NULL) + { + CGAL_assertion( previous !=vh ); + cdt.insert_constraint(previous,vh); + } + + previous=vh; + } + cdt.insert_constraint(previous,first); + CGAL_assertion(cdt.is_valid()); + + // sets mark is_external + for( CDT::All_faces_iterator fit = cdt.all_faces_begin(), + fitend = cdt.all_faces_end(); fit != fitend; ++fit) + { + fit->info().is_external = false; + fit->info().exist_edge[0]=false; + fit->info().exist_edge[1]=false; + fit->info().exist_edge[2]=false; + } + + std::queue face_queue; + + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) + { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(!fh->info().is_external) + { + fh->info().is_external = true; + for(int i = 0; i <3; ++i) + { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + face_queue.push(fh->neighbor(i)); + } + } + } + } + for( CDT::Finite_edges_iterator eit = cdt.finite_edges_begin(), + eitend = cdt.finite_edges_end(); eit != eitend; ++eit) + { + CDT::Face_handle fh = eit->first; + int index = eit->second; + CDT::Face_handle opposite_fh = fh->neighbor(index); + if(cdt.is_constrained(std::make_pair(fh, index))) + { + fh->info().exist_edge[index]=true; + opposite_fh->info().exist_edge[cdt.mirror_index(fh,index)]=true; + + if ( !fh->info().is_external && number_of_existing_edge(fh)==2 ) + face_queue.push(fh); + if ( !opposite_fh->info().is_external && + number_of_existing_edge(opposite_fh)==2 ) + face_queue.push(opposite_fh); + } + } + + while( !face_queue.empty() ) + { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + CGAL_assertion( number_of_existing_edge(fh)>=2 ); // i.e. ==2 or ==3 + CGAL_assertion( !fh->info().is_external ); + + if (number_of_existing_edge(fh)==2) + { + int index = get_free_edge(fh); + CDT::Face_handle opposite_fh = fh->neighbor(index); + + CGAL_assertion( !fh->info().exist_edge[index] ); + CGAL_assertion( !opposite_fh->info(). + exist_edge[cdt.mirror_index(fh,index)] ); + const CDT::Vertex_handle va = fh->vertex(cdt. cw(index)); + const CDT::Vertex_handle vb = fh->vertex(cdt.ccw(index)); + + Dart_handle ndart= + CGAL::insert_cell_1_in_cell_2(lcc,va->info(),vb->info()); + va->info()=lcc.beta<2>(ndart); + + fh->info().exist_edge[index]=true; + opposite_fh->info().exist_edge[cdt.mirror_index(fh,index)]=true; + + if ( !opposite_fh->info().is_external && + number_of_existing_edge(opposite_fh)==2 ) + face_queue.push(opposite_fh); + } + } +} + +void MainWindow::on_actionTriangulate_all_facets_triggered() +{ + QApplication::setOverrideCursor (Qt::WaitCursor); + +#ifdef CGAL_PROFILE_LCC_DEMO + CGAL::Timer timer; + timer.start(); +#endif + + std::vector v; + for (LCC::One_dart_per_cell_range<2>::iterator + it(scene.lcc->one_dart_per_cell<2>().begin()); it.cont(); ++it) + { + if ( scene.lcc->info<3>(it).is_filled_and_visible() ) + v.push_back(it); + } + + for (std::vector::iterator itv(v.begin()); + itv!=v.end(); ++itv) + constrained_delaunay_triangulation(*scene.lcc, *itv); + +#ifdef CGAL_PROFILE_LCC_DEMO + timer.stop(); + std::cout<<"Time to triangulate all filled faces: " + <showMessage + (QString ("All visible and filled faces were triangulated"), DELAY_STATUSMSG); +} + bool MainWindow::is_volume_in_list(LCC::Attribute_handle<3>::type ah) { for(int row=0; row < volumeList->rowCount(); ++row) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h index 94ece0289c1..2e58379a474 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h @@ -133,11 +133,13 @@ public Q_SLOTS: void on_actionSubdivide_pqq_triggered(); void on_actionDual_3_triggered(); void on_actionClose_volume_triggered(); - void on_actionTriangulate_all_facets_triggered(); void on_actionSew3_same_facets_triggered(); void on_actionUnsew3_all_triggered(); + void on_actionMerge_coplanar_faces_triggered(); void on_actionMerge_all_volumes_triggered(); void on_actionRemove_filled_volumes_triggered(); + void on_actionInsert_center_vertices_triggered(); + void on_actionTriangulate_all_facets_triggered(); // View menu void on_actionExtend_filled_volumes_triggered(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui index 33291ca159e..321dc4f3bc1 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui @@ -58,12 +58,15 @@ &Operations + - - + + + + @@ -240,6 +243,16 @@ Import Moka + + + Merge coplanar faces + + + + + Insert center vertices in faces + + From d0cb5d35f5aaf1855e72f6798a0e2ed5cb90048f Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 16 Jun 2015 07:57:45 +0200 Subject: [PATCH 07/24] Bug fix when changing the visible property of a volume. --- Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 97ed18e2d49..cf82a286840 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -1378,6 +1378,8 @@ void MainWindow::recreate_whole_volume_list() void MainWindow::onCellChanged(int row, int col) { + volumeList->disconnect(this); + LCC::Attribute_type<3>::type* ptr= reinterpret_cast::type*> ( volumeList->item(row,3)->data(Qt::UserRole).value() ); @@ -1397,6 +1399,7 @@ void MainWindow::onCellChanged(int row, int col) (volumeList->item(row,1)->flags()|Qt::ItemIsEnabled); } + connectVolumeListHandlers(); Q_EMIT( sceneChanged()); } From c0741ed4202d9bedf8baab9a2568813827b954c2 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 16 Jun 2015 07:58:02 +0200 Subject: [PATCH 08/24] Remove warnings --- .../CGAL/Combinatorial_map_save_load.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h index 2ac5328f8c1..bf4ed3aba21 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -155,7 +155,7 @@ namespace CGAL { struct My_functor_cmap_save_one_attrib { static void run(const CMap* amap, boost::property_tree::ptree* ptree, - std::map* myDarts) + std::map* myDarts) { // to check all i-cells of the map typename CMap::template Attribute_range::type::const_iterator @@ -174,7 +174,7 @@ namespace CGAL { { // make composant, dart and property node boost::property_tree::ptree & nattr = ndim.add("a", ""); - boost::property_tree::ptree & ndarts = + /* boost::property_tree::ptree & ndarts = */ nattr.add("d", (*myDarts)[it_attrib->dart()]); // update property node to add a value node (from basic or custom type @@ -189,7 +189,7 @@ namespace CGAL { struct My_functor_cmap_save_one_attrib { static void run(const CMap* amap, boost::property_tree::ptree* ptree, - std::map* myDarts) + std::map* myDarts) { // to check all i-cells of the map typename CMap::template Attribute_range::type::const_iterator @@ -208,7 +208,7 @@ namespace CGAL { { // make composant, dart and property node boost::property_tree::ptree & nattr = ndim.add("a", ""); - boost::property_tree::ptree & ndarts = + /* boost::property_tree::ptree & ndarts = */ nattr.add("d", (*myDarts)[it_attrib->dart()]); // update property node to add a value node (from basic or custom type @@ -222,7 +222,7 @@ namespace CGAL { struct My_functor_cmap_save_one_attrib { static void run(const CMap* amap, boost::property_tree::ptree* ptree, - std::map* myDarts) + std::map* myDarts) { // to check all i-cells of the map typename CMap::template Attribute_range::type::const_iterator @@ -241,7 +241,7 @@ namespace CGAL { { // make composant, dart and property node boost::property_tree::ptree & nattr = ndim.add("a", ""); - boost::property_tree::ptree & ndarts = + /* boost::property_tree::ptree & ndarts = */ nattr.add("d", (*myDarts)[it_attrib->dart()]); // update property node to add a value node (from basic or custom type @@ -255,7 +255,7 @@ namespace CGAL { struct My_functor_cmap_save_one_attrib { static void run(const CMap* amap, boost::property_tree::ptree* ptree, - std::map* myDarts) + std::map* myDarts) { // to check all i-cells of the map typename CMap::template Attribute_range::type::const_iterator @@ -274,7 +274,7 @@ namespace CGAL { { // make composant, dart and property node boost::property_tree::ptree & nattr = ndim.add("a", ""); - boost::property_tree::ptree & ndarts = + /* boost::property_tree::ptree & ndarts = */ nattr.add("d", (*myDarts)[it_attrib->dart()]); } } @@ -285,7 +285,7 @@ namespace CGAL { { template static void run(const CMap* amap, boost::property_tree::ptree* ptree, - std::map* myDarts) + std::map* myDarts) { My_functor_cmap_save_one_attrib::run(amap, ptree, myDarts); } @@ -293,7 +293,7 @@ namespace CGAL { template < class CMap > boost::property_tree::ptree cmap_save_darts - (const CMap& amap, std::map& myDarts) + (const CMap& amap, std::map& myDarts) { assert( myDarts.empty() ); @@ -336,7 +336,7 @@ namespace CGAL { template < class CMap > boost::property_tree::ptree cmap_save_attributes - (const CMap& amap, std::map& myDarts) + (const CMap& amap, std::map& myDarts) { using boost::property_tree::ptree; ptree pt; @@ -355,7 +355,7 @@ namespace CGAL { ptree data; // map dart => number - std::map myDarts; + std::map myDarts; // Get darts ptree pt_darts; @@ -378,7 +378,7 @@ namespace CGAL { { std::ofstream output(filename); if (!output) return false; - save_combinatorial_map(amap, output); + return save_combinatorial_map(amap, output); } // Here T is a Dart_handle so no need of & From da8fbde03c54806c2eeb215a45ec786de0f8b057 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 16 Jun 2015 08:39:00 +0200 Subject: [PATCH 09/24] Bug fix in merge coplanar faces --- .../demo/Linear_cell_complex/MainWindow.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index cf82a286840..0dc81488073 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -1009,7 +1009,22 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() for (std::vector::iterator it=edges.begin(), itend=edges.end(); it!=itend; ++it) { - if ( !CGAL::belong_to_same_cell(*scene.lcc, *it, scene.lcc->beta<2>(*it)) ) + if ( scene.lcc->beta<0, 2>(*it)==*it || scene.lcc->beta<1, 2>(*it)==*it) + { // To process dangling edges + + Dart_handle actu = *it, prev=NULL; + do + { + if ( scene.lcc->beta<0, 2>(actu)==actu ) prev = scene.lcc->beta<1>(actu); + else if prev = scene.lcc->beta<0>(actu); + + CGAL::remove_cell(*scene.lcc, actu); + actu = prev; + } + while (scene.lcc->beta<0, 2>(actu)==actu || scene.lcc->beta<1, 2>(actu)==actu); + } + else if ( !CGAL::belong_to_same_cell(*scene.lcc, *it, + scene.lcc->beta<2>(*it)) ) CGAL::remove_cell(*scene.lcc, *it); else CGAL::unmark_cell(*scene.lcc, *it, treated); From 0a92fae044addce3dfd9781e37cd1dc2a9e8e9ba Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 16 Jun 2015 08:53:45 +0200 Subject: [PATCH 10/24] Do not modify the user point of view after each operation. --- .../demo/Linear_cell_complex/MainWindow.cpp | 16 +++++++++++++++- .../demo/Linear_cell_complex/Viewer.cpp | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 0dc81488073..bd152fc1a12 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -251,6 +251,7 @@ void MainWindow::on_actionLoad_triggered () if (!fileName.isEmpty ()) { load(fileName, true); + viewer->showEntireScene(); } } @@ -264,6 +265,7 @@ void MainWindow::on_actionImportOFF_triggered () if (!fileName.isEmpty ()) { load_off (fileName, true); + viewer->showEntireScene(); } } @@ -277,6 +279,7 @@ void MainWindow::on_actionImportMoka_triggered() if (!fileName.isEmpty ()) { load_moka(fileName, true); + viewer->showEntireScene(); } } @@ -290,6 +293,7 @@ void MainWindow::on_actionImport3DTDS_triggered () if (!fileName.isEmpty ()) { load_3DTDS (fileName, true); + viewer->showEntireScene(); statusBar ()->showMessage (QString ("Import 3DTDS file") + fileName, DELAY_STATUSMSG); } @@ -305,6 +309,7 @@ void MainWindow::on_actionAddOFF_triggered() if (!fileName.isEmpty ()) { load_off (fileName, false); + viewer->showEntireScene(); } } @@ -312,11 +317,20 @@ void MainWindow::load_depend_on_extension(const QString & fileName, bool clear) { QString ext = QFileInfo(fileName).suffix(); if ( ext=="3map") + { load(fileName, clear); + viewer->showEntireScene(); + } else if (ext=="off") + { load_off(fileName, clear); + viewer->showEntireScene(); + } else if (ext=="moka") + { load_moka(fileName, clear); + viewer->showEntireScene(); + } else { std::cout<<"Extension not considered."<beta<0, 2>(actu)==actu ) prev = scene.lcc->beta<1>(actu); - else if prev = scene.lcc->beta<0>(actu); + else prev = scene.lcc->beta<0>(actu); CGAL::remove_cell(*scene.lcc, actu); actu = prev; diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index 309e93b80a3..f493e9a79af 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -35,8 +35,8 @@ Viewer::sceneChanged() qglviewer::Vec(bb.xmax(), bb.ymax(), bb.zmax())); - this->showEntireScene(); -} + // this->showEntireScene(); + this->updateGL();} void Viewer::drawOneFaceWireframe(Dart_handle dh) { From af01f3820c9e88abfe33c241b465949489205e98 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 16 Jun 2015 12:14:23 +0200 Subject: [PATCH 11/24] Remove a warning --- .../include/CGAL/Combinatorial_map_save_load.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h index bf4ed3aba21..e83c6d255f4 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -67,11 +67,11 @@ namespace CGAL { // Here T is a Dart_const_handle so we don't need & template - void write_cmap_dart_node(boost::property_tree::ptree & node, T) + void write_cmap_dart_node(boost::property_tree::ptree & /*node*/, T) {} template - void write_cmap_attribute_node(boost::property_tree::ptree & node, const T&) + void write_cmap_attribute_node(boost::property_tree::ptree & /*node*/, const T&) {} inline @@ -384,11 +384,11 @@ namespace CGAL { // Here T is a Dart_handle so no need of & template void read_cmap_dart_node - (const boost::property_tree::ptree::value_type &v, T val) + (const boost::property_tree::ptree::value_type &/*v*/, T /*val*/) {} template void read_cmap_attribute_node - (const boost::property_tree::ptree::value_type &v, T &val) + (const boost::property_tree::ptree::value_type &/*v*/, T &/*val*/) {} template<> inline void read_cmap_attribute_node From 37b0d2256c8608a6f90ac9e8f54575a6320ef87f Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 16 Jun 2015 12:14:47 +0200 Subject: [PATCH 12/24] * Better drawing when scene was empty. * Bug fix in triangulate all faces --- .../demo/Linear_cell_complex/MainWindow.cpp | 42 +++++++++---------- .../demo/Linear_cell_complex/Viewer.cpp | 26 ++++++------ .../demo/Linear_cell_complex/Viewer.h | 10 +++-- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index bd152fc1a12..717698e7c46 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -251,7 +251,6 @@ void MainWindow::on_actionLoad_triggered () if (!fileName.isEmpty ()) { load(fileName, true); - viewer->showEntireScene(); } } @@ -265,7 +264,6 @@ void MainWindow::on_actionImportOFF_triggered () if (!fileName.isEmpty ()) { load_off (fileName, true); - viewer->showEntireScene(); } } @@ -279,7 +277,6 @@ void MainWindow::on_actionImportMoka_triggered() if (!fileName.isEmpty ()) { load_moka(fileName, true); - viewer->showEntireScene(); } } @@ -293,7 +290,6 @@ void MainWindow::on_actionImport3DTDS_triggered () if (!fileName.isEmpty ()) { load_3DTDS (fileName, true); - viewer->showEntireScene(); statusBar ()->showMessage (QString ("Import 3DTDS file") + fileName, DELAY_STATUSMSG); } @@ -309,7 +305,6 @@ void MainWindow::on_actionAddOFF_triggered() if (!fileName.isEmpty ()) { load_off (fileName, false); - viewer->showEntireScene(); } } @@ -319,17 +314,14 @@ void MainWindow::load_depend_on_extension(const QString & fileName, bool clear) if ( ext=="3map") { load(fileName, clear); - viewer->showEntireScene(); } else if (ext=="off") { load_off(fileName, clear); - viewer->showEntireScene(); } else if (ext=="moka") { load_moka(fileName, clear); - viewer->showEntireScene(); } else { @@ -998,6 +990,8 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() CGAL::Timer timer; timer.start(); #endif + + scene.lcc->set_update_attributes(false); std::vector edges; int treated = scene.lcc->get_new_mark(); @@ -1005,21 +999,24 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() for ( typename LCC::Dart_range::iterator it= scene.lcc->darts().begin(), itend = scene.lcc->darts().end(); it!=itend; ++it ) { - if (!scene.lcc->is_marked(it, treated) && - CGAL::is_removable(*scene.lcc, it) ) + if (!scene.lcc->is_marked(it, treated) ) { - LCC::Vector normal1 = CGAL::compute_normal_of_cell_2(*scene.lcc,it); - LCC::Vector normal2 = CGAL::compute_normal_of_cell_2(*scene.lcc, scene.lcc->beta<2>(it) ); - double angle = compute_angle3d(normal1, normal2); - - if ( ((angle<5.0 or angle>355.0) or (angle<185.0 and angle>175.0)) ) + if ( CGAL::is_removable(*scene.lcc, it) ) { - CGAL::mark_cell(*scene.lcc, it, treated); - edges.push_back(it); + LCC::Vector normal1 = CGAL::compute_normal_of_cell_2(*scene.lcc,it); + LCC::Vector normal2 = CGAL::compute_normal_of_cell_2(*scene.lcc, scene.lcc->beta<2>(it) ); + double angle = compute_angle3d(normal1, normal2); + + if ( ((angle<5.0 or angle>355.0) or (angle<185.0 and angle>175.0)) ) + { + edges.push_back(it); + } } + CGAL::mark_cell(*scene.lcc, it, treated); } } + for (std::vector::iterator it=edges.begin(), itend=edges.end(); it!=itend; ++it) { @@ -1034,19 +1031,20 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() CGAL::remove_cell(*scene.lcc, actu); actu = prev; + std::cout<<&(*actu)<beta<0, 2>(actu)==actu || scene.lcc->beta<1, 2>(actu)==actu); } else if ( !CGAL::belong_to_same_cell(*scene.lcc, *it, scene.lcc->beta<2>(*it)) ) CGAL::remove_cell(*scene.lcc, *it); - else - CGAL::unmark_cell(*scene.lcc, *it, treated); } - assert(scene.lcc->is_whole_map_unmarked(treated)); + assert(scene.lcc->is_whole_map_marked(treated)); scene.lcc->free_mark(treated); + scene.lcc->set_update_attributes(true); + #ifdef CGAL_PROFILE_LCC_DEMO timer.stop(); std::cout<<"Time to merge all coplanar faces: " @@ -1271,7 +1269,9 @@ void MainWindow::on_actionTriangulate_all_facets_triggered() for (LCC::One_dart_per_cell_range<2>::iterator it(scene.lcc->one_dart_per_cell<2>().begin()); it.cont(); ++it) { - if ( scene.lcc->info<3>(it).is_filled_and_visible() ) + if ( scene.lcc->info<3>(it).is_filled_and_visible() || + (!scene.lcc->is_free<3>(it) && + scene.lcc->info<3>(scene.lcc->beta<3>(it)).is_filled_and_visible()) ) v.push_back(it); } diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index f493e9a79af..de31eadf103 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -35,8 +35,14 @@ Viewer::sceneChanged() qglviewer::Vec(bb.xmax(), bb.ymax(), bb.zmax())); - // this->showEntireScene(); - this->updateGL();} + + if (m_previous_scene_empty) + this->showEntireScene(); + else + this->updateGL(); + + m_previous_scene_empty = scene->lcc->is_empty(); // for the next call to sceneChanged +} void Viewer::drawOneFaceWireframe(Dart_handle dh) { @@ -55,7 +61,7 @@ void Viewer::drawOneFaceWireframe(Dart_handle dh) ::glEnd(); } -void Viewer::drawOneFilledFace(Dart_handle dh) +void Viewer::drawOneFilledFace(Dart_handle dh, bool flat) { LCC &lcc = *scene->lcc; @@ -73,7 +79,7 @@ void Viewer::drawOneFilledFace(Dart_handle dh) ::glColor3f(r,g,b); - if(flatShading) + if(flat) { LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dh); normal = normal/(CGAL::sqrt(normal*normal)); @@ -97,7 +103,7 @@ void Viewer::drawOneFilledFace(Dart_handle dh) data[1+(i*3)] = p.y(); data[2+(i*3)] = p.z(); - if(!flatShading) + if(!flat) { // If Gouraud shading: 1 normal per vertex LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,it); @@ -114,7 +120,7 @@ void Viewer::drawOneFilledFace(Dart_handle dh) data[2+(i*3)] = p.z(); // If Gouraud shading: 1 normal per vertex - if(!flatShading) + if(!flat) { LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,dh); normal = normal/(CGAL::sqrt(normal*normal)); @@ -146,7 +152,7 @@ void Viewer::drawAllFaces(bool flat) // We draw the polygon if ( it->info().is_filled() ) { - drawOneFilledFace(dartIter); + drawOneFilledFace(dartIter, flat); } else { @@ -238,12 +244,6 @@ void Viewer::drawAllVertices() } ::glEnd(); - - if ( lcc.is_empty() ) - { - bb = LCC::Point(CGAL::ORIGIN).bbox(); - bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer - } } void Viewer::initDraw() diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index 5c7cbfd4d80..1087f027efd 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -25,7 +25,7 @@ #include #include -static void monCombine(GLdouble c[3], void *d[4], GLfloat w[4], void **out) +static void monCombine(GLdouble c[3], void */*d*/[4], GLfloat /*w*/[4], void **out) { GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble)*3); nv[0] = c[0]; @@ -51,7 +51,8 @@ class Viewer : public QGLViewer GLuint m_dlEdges; GLuint m_dlVertices; bool m_displayListCreated; - + bool m_previous_scene_empty; + GLUtesselator* FTess; typedef LCC::Dart_handle Dart_handle; @@ -60,7 +61,8 @@ class Viewer : public QGLViewer public: Viewer(QWidget* parent) : QGLViewer(parent), wireframe(false), flatShading(true), - edges(true), vertices(true), m_displayListCreated(false) + edges(true), vertices(true), m_displayListCreated(false), + m_previous_scene_empty(true) { QGLFormat newFormat = this->format(); newFormat.setSampleBuffers(true); @@ -103,7 +105,7 @@ protected: void drawAllEdges(); void drawAllVertices(); void drawOneFaceWireframe(Dart_handle); - void drawOneFilledFace(Dart_handle); + void drawOneFilledFace(Dart_handle, bool flat); }; #endif From a57e1274129aedf780ef39d6e205cf5a7904baf5 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 17 Jun 2015 09:45:59 +0200 Subject: [PATCH 13/24] Remove warnings --- .../include/CGAL/Combinatorial_map_save_load.h | 4 ++-- .../demo/Linear_cell_complex/CMakeLists.txt | 1 + .../demo/Linear_cell_complex/MainWindow.cpp | 4 ++-- Linear_cell_complex/demo/Linear_cell_complex/Viewer.h | 8 ++++---- .../demo/Linear_cell_complex/import_moka.h | 10 +++++----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h index e83c6d255f4..debd26b66e8 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -317,7 +317,7 @@ namespace CGAL { ptree & ndart = pt.add("d", ""); // the beta, only for non free sews - for(int dim=1; dim<=amap.dimension; dim++) + for(unsigned int dim=1; dim<=amap.dimension; dim++) { if(!amap.is_free(it, dim)) { @@ -728,7 +728,7 @@ namespace CGAL { } // update beta links - int index; + unsigned int index; unsigned int currentDartInt = 0; unsigned int nextDartInt; diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index 0e631ae48d5..ade157a45bc 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -16,6 +16,7 @@ endif() ## For profilling with gprof # add_definitions("-pg") +add_definitions("-Wall -Wextra") # SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") ## To add an is_valid test after each operation (only in debug mode) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 717698e7c46..3bc191c39d6 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -996,7 +996,7 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() std::vector edges; int treated = scene.lcc->get_new_mark(); - for ( typename LCC::Dart_range::iterator it= scene.lcc->darts().begin(), + for ( LCC::Dart_range::iterator it= scene.lcc->darts().begin(), itend = scene.lcc->darts().end(); it!=itend; ++it ) { if (!scene.lcc->is_marked(it, treated) ) @@ -1007,7 +1007,7 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() LCC::Vector normal2 = CGAL::compute_normal_of_cell_2(*scene.lcc, scene.lcc->beta<2>(it) ); double angle = compute_angle3d(normal1, normal2); - if ( ((angle<5.0 or angle>355.0) or (angle<185.0 and angle>175.0)) ) + if ( ((angle<5.0 || angle>355.0) || (angle<185.0 && angle>175.0)) ) { edges.push_back(it); } diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index 1087f027efd..8013b04fd06 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -70,10 +70,10 @@ public: this->setFormat(newFormat); FTess = gluNewTess(); - gluTessCallback(FTess, GLU_TESS_BEGIN, (GLvoid (*) ( )) & glBegin); - gluTessCallback(FTess, GLU_TESS_END, (GLvoid (*) ( )) & glEnd); - gluTessCallback(FTess, GLU_TESS_VERTEX, (GLvoid (*) ( )) & glVertex3dv); - gluTessCallback(FTess, GLU_TESS_COMBINE, (GLvoid (*) ( )) & monCombine ); + gluTessCallback(FTess, GLU_TESS_BEGIN,(void (*) ( )) & glBegin); + gluTessCallback(FTess, GLU_TESS_END, (void (*) ( )) & glEnd); + gluTessCallback(FTess, GLU_TESS_VERTEX, (void (*) ( )) & glVertex3dv); + gluTessCallback(FTess, GLU_TESS_COMBINE, (void (*) ( )) & monCombine ); } ~Viewer() diff --git a/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h b/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h index 83791442bff..f0a62a6609e 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/import_moka.h @@ -70,7 +70,7 @@ bool import_from_moka(LCC& lcc, const char* filename) std::getline(ifile, line); std::vector gdarts; - int nbLoaded = 0; + unsigned int nbLoaded = 0; unsigned int number; double x,y,z; @@ -102,8 +102,8 @@ bool import_from_moka(LCC& lcc, const char* filename) ifile.close(); // Second orient the gmap, and create oriented darts. - std::stack totreat; - for (int startingdart = 0; startingdart totreat; + for (unsigned int startingdart = 0; startingdart Date: Thu, 18 Jun 2015 09:55:35 +0200 Subject: [PATCH 14/24] Increase the size of the first column. --- Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 3bc191c39d6..1ed3427f67c 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -65,7 +65,7 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), labels.append(QString(tr("Hidden"))); volumeList->setHorizontalHeaderLabels(labels); //volumeList->resizeColumnsToContents(); - volumeList->setFixedWidth(200); + volumeList->setFixedWidth(220); /* volumeList->setColumnWidth(0,85); volumeList->setColumnWidth(1,35); volumeList->setColumnWidth(2,35);*/ From ff154680793b67c01ef18ef8109d05cc20d40d7b Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 22 Jun 2015 16:02:32 +0200 Subject: [PATCH 15/24] Remove flag in cmake, pushed by error --- Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index ade157a45bc..03096460f21 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -13,10 +13,10 @@ endif() ## To add expensive tests # add_definitions("-DCGAL_CHECK_EXPENSIVE") +# add_definitions("-Wall -Wextra") ## For profilling with gprof # add_definitions("-pg") -add_definitions("-Wall -Wextra") # SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") ## To add an is_valid test after each operation (only in debug mode) From cf563fa834221f4ca3671a13021c1951401dd7e9 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 25 Jun 2015 16:09:51 +0200 Subject: [PATCH 16/24] Disable non flat rendering; add casts to solve problem of gluTessCallback on win32. --- .../demo/Linear_cell_complex/Viewer.cpp | 23 +++++++++++-------- .../demo/Linear_cell_complex/Viewer.h | 22 +++++++++++------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index de31eadf103..b8b3ff7c2f8 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -250,10 +250,11 @@ void Viewer::initDraw() { //Compile drawFacet // std::cout << "Compile Display Lists : Faces, " << std::flush; - m_dlFaces = ::glGenLists(1); + /* Non flat shading does not work with tesselator. TODO + m_dlFaces = ::glGenLists(1); ::glNewList(m_dlFaces, GL_COMPILE); drawAllFaces(false); - ::glEndList(); + ::glEndList(); */ //Compile drawFacet with flat shading // std::cout << "Faces (flat shading), " << std::flush; @@ -286,8 +287,10 @@ void Viewer::draw() if ( !wireframe ) { - if(flatShading) ::glCallList(m_dlFacesFlat); - else ::glCallList(m_dlFaces); + //if(flatShading) + ::glCallList(m_dlFacesFlat); + // Non flat shading does not work with tesselator TODO + // else ::glCallList(m_dlFaces); } if(edges) ::glCallList(m_dlEdges); @@ -305,7 +308,7 @@ void Viewer::init() // Add custom key description (see keyPressEvent). setKeyDescription(Qt::Key_W, "Toggles wire frame display"); - setKeyDescription(Qt::Key_F, "Toggles flat shading display"); + // setKeyDescription(Qt::Key_F, "Toggles flat shading display"); setKeyDescription(Qt::Key_E, "Toggles edges display"); setKeyDescription(Qt::Key_V, "Toggles vertices display"); @@ -322,7 +325,7 @@ void Viewer::init() ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - if (flatShading) + // if (flatShading) { ::glShadeModel(GL_FLAT); ::glDisable(GL_BLEND); @@ -331,14 +334,14 @@ void Viewer::init() ::glBlendFunc(GL_ONE, GL_ZERO); ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } - else + /* else { ::glShadeModel(GL_SMOOTH); ::glEnable(GL_BLEND); ::glEnable(GL_LINE_SMOOTH); ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } + }*/ } void Viewer::keyPressEvent(QKeyEvent *e) @@ -356,7 +359,7 @@ void Viewer::keyPressEvent(QKeyEvent *e) handled = true; updateGL(); } - else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) + /* else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) { flatShading = !flatShading; if (flatShading) @@ -378,7 +381,7 @@ void Viewer::keyPressEvent(QKeyEvent *e) } handled = true; updateGL(); - } + }*/ else if ((e->key()==Qt::Key_E) && (modifiers==Qt::NoButton)) { edges = !edges; diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index 8013b04fd06..59f49faf356 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -23,9 +23,15 @@ #include "typedefs.h" #include +#include +#include #include -static void monCombine(GLdouble c[3], void */*d*/[4], GLfloat /*w*/[4], void **out) +#ifndef CALLBACK +#define CALLBACK +#endif + +static void CALLBACK monCombine(GLdouble c[3], void * /*d*/ [4], GLfloat /*w*/ [4], void **out) { GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble)*3); nv[0] = c[0]; @@ -41,12 +47,12 @@ class Viewer : public QGLViewer CGAL::Timer timer; Scene* scene; bool wireframe; - bool flatShading; + // bool flatShading; bool edges; bool vertices; CGAL::Bbox_3 bb; - GLuint m_dlFaces; + // GLuint m_dlFaces; GLuint m_dlFacesFlat; GLuint m_dlEdges; GLuint m_dlVertices; @@ -60,7 +66,7 @@ class Viewer : public QGLViewer public: Viewer(QWidget* parent) - : QGLViewer(parent), wireframe(false), flatShading(true), + : QGLViewer(parent), wireframe(false), // flatShading(true), edges(true), vertices(true), m_displayListCreated(false), m_previous_scene_empty(true) { @@ -70,10 +76,10 @@ public: this->setFormat(newFormat); FTess = gluNewTess(); - gluTessCallback(FTess, GLU_TESS_BEGIN,(void (*) ( )) & glBegin); - gluTessCallback(FTess, GLU_TESS_END, (void (*) ( )) & glEnd); - gluTessCallback(FTess, GLU_TESS_VERTEX, (void (*) ( )) & glVertex3dv); - gluTessCallback(FTess, GLU_TESS_COMBINE, (void (*) ( )) & monCombine ); + gluTessCallback(FTess, GLU_TESS_BEGIN, (void (CALLBACK*)()) &glBegin); + gluTessCallback(FTess, GLU_TESS_END, (void (CALLBACK*)()) &glEnd); + gluTessCallback(FTess, GLU_TESS_VERTEX, (void (CALLBACK*)()) &glVertex3dv); + gluTessCallback(FTess, GLU_TESS_COMBINE, (void (CALLBACK*)()) &monCombine); } ~Viewer() From fbfd47896b0b3dc310cb9eb6aa679b85306c8c08 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 30 Jun 2015 14:22:53 +0200 Subject: [PATCH 17/24] Remove the use of glu tesselator to draw non convex faces. --- .../demo/Linear_cell_complex/Viewer.cpp | 47 ++++++++++++++----- .../demo/Linear_cell_complex/Viewer.h | 31 ++++++------ 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index b8b3ff7c2f8..82bfde06c24 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -86,6 +86,29 @@ void Viewer::drawOneFilledFace(Dart_handle dh, bool flat) ::glNormal3d(normal.x(), normal.y(), normal.z()); } + ::glBegin(GL_POLYGON); + + for (typename LCC::template Dart_of_orbit_range<1>::const_iterator + orbitIter = lcc.template darts_of_orbit<1>(dh).begin(); + orbitIter.cont(); ++orbitIter) + { + if(!flat) + { + // If Gouraud shading: 1 normal per vertex + LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc, orbitIter); + normal = normal/(CGAL::sqrt(normal*normal)); + ::glNormal3d(normal.x(), normal.y(), normal.z()); + } + + const LCC::Point& p = lcc.point(orbitIter); + ::glVertex3d(p.x(), p.y(), p.z()); + } + + ::glEnd(); + + /* Old version to draw non convex face, but which uses glu tesselator which is not + deprecated + // array of vertices of the face std::size_t nb=0; for (LCC::Dart_of_orbit_range<1>::const_iterator it(lcc, dh); it.cont(); ++it, ++nb); @@ -133,6 +156,7 @@ void Viewer::drawOneFilledFace(Dart_handle dh, bool flat) gluTessEndPolygon(FTess); delete [] data; + */ } void Viewer::drawAllFaces(bool flat) @@ -250,11 +274,10 @@ void Viewer::initDraw() { //Compile drawFacet // std::cout << "Compile Display Lists : Faces, " << std::flush; - /* Non flat shading does not work with tesselator. TODO - m_dlFaces = ::glGenLists(1); + m_dlFaces = ::glGenLists(1); ::glNewList(m_dlFaces, GL_COMPILE); drawAllFaces(false); - ::glEndList(); */ + ::glEndList(); //Compile drawFacet with flat shading // std::cout << "Faces (flat shading), " << std::flush; @@ -287,10 +310,10 @@ void Viewer::draw() if ( !wireframe ) { - //if(flatShading) + if(flatShading) ::glCallList(m_dlFacesFlat); - // Non flat shading does not work with tesselator TODO - // else ::glCallList(m_dlFaces); + else + ::glCallList(m_dlFaces); } if(edges) ::glCallList(m_dlEdges); @@ -308,7 +331,7 @@ void Viewer::init() // Add custom key description (see keyPressEvent). setKeyDescription(Qt::Key_W, "Toggles wire frame display"); - // setKeyDescription(Qt::Key_F, "Toggles flat shading display"); + setKeyDescription(Qt::Key_F, "Toggles flat shading display"); setKeyDescription(Qt::Key_E, "Toggles edges display"); setKeyDescription(Qt::Key_V, "Toggles vertices display"); @@ -325,7 +348,7 @@ void Viewer::init() ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - // if (flatShading) + if (flatShading) { ::glShadeModel(GL_FLAT); ::glDisable(GL_BLEND); @@ -334,14 +357,14 @@ void Viewer::init() ::glBlendFunc(GL_ONE, GL_ZERO); ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } - /* else + else { ::glShadeModel(GL_SMOOTH); ::glEnable(GL_BLEND); ::glEnable(GL_LINE_SMOOTH); ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - }*/ + } } void Viewer::keyPressEvent(QKeyEvent *e) @@ -359,7 +382,7 @@ void Viewer::keyPressEvent(QKeyEvent *e) handled = true; updateGL(); } - /* else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) + else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) { flatShading = !flatShading; if (flatShading) @@ -381,7 +404,7 @@ void Viewer::keyPressEvent(QKeyEvent *e) } handled = true; updateGL(); - }*/ + } else if ((e->key()==Qt::Key_E) && (modifiers==Qt::NoButton)) { edges = !edges; diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index 59f49faf356..5fd50510270 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -23,15 +23,17 @@ #include "typedefs.h" #include -#include -#include #include -#ifndef CALLBACK -#define CALLBACK -#endif +/* TODO: code to draw non convex faces (since glu tesselator is now deprecated) -static void CALLBACK monCombine(GLdouble c[3], void * /*d*/ [4], GLfloat /*w*/ [4], void **out) + #include + #include + #ifndef CALLBACK + #define CALLBACK + #endif + +static void CALLBACK monCombine(GLdouble c[3], void * d [4], GLfloat w [4], void **out) { GLdouble *nv = (GLdouble *) malloc(sizeof(GLdouble)*3); nv[0] = c[0]; @@ -39,6 +41,7 @@ static void CALLBACK monCombine(GLdouble c[3], void * /*d*/ [4], GLfloat /*w*/ [ nv[2] = c[2]; *out = nv; } +*/ class Viewer : public QGLViewer { @@ -47,26 +50,26 @@ class Viewer : public QGLViewer CGAL::Timer timer; Scene* scene; bool wireframe; - // bool flatShading; + bool flatShading; bool edges; bool vertices; CGAL::Bbox_3 bb; - // GLuint m_dlFaces; + GLuint m_dlFaces; GLuint m_dlFacesFlat; GLuint m_dlEdges; GLuint m_dlVertices; bool m_displayListCreated; bool m_previous_scene_empty; - - GLUtesselator* FTess; + + // GLUtesselator* FTess; typedef LCC::Dart_handle Dart_handle; typedef LCC::Dart_const_handle Dart_const_handle; public: Viewer(QWidget* parent) - : QGLViewer(parent), wireframe(false), // flatShading(true), + : QGLViewer(parent), wireframe(false), flatShading(true), edges(true), vertices(true), m_displayListCreated(false), m_previous_scene_empty(true) { @@ -75,16 +78,16 @@ public: newFormat.setSamples(16); this->setFormat(newFormat); - FTess = gluNewTess(); + /* FTess = gluNewTess(); gluTessCallback(FTess, GLU_TESS_BEGIN, (void (CALLBACK*)()) &glBegin); gluTessCallback(FTess, GLU_TESS_END, (void (CALLBACK*)()) &glEnd); gluTessCallback(FTess, GLU_TESS_VERTEX, (void (CALLBACK*)()) &glVertex3dv); - gluTessCallback(FTess, GLU_TESS_COMBINE, (void (CALLBACK*)()) &monCombine); + gluTessCallback(FTess, GLU_TESS_COMBINE, (void (CALLBACK*)()) &monCombine); */ } ~Viewer() { - gluDeleteTess(FTess); + // gluDeleteTess(FTess); } void setScene(Scene* scene_) From 7f0b73634afa836bcae962718f21118f161bfab3 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 1 Jul 2015 07:28:37 +0200 Subject: [PATCH 18/24] Remove typename outside templace class --- Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index 82bfde06c24..097602488ea 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -88,8 +88,8 @@ void Viewer::drawOneFilledFace(Dart_handle dh, bool flat) ::glBegin(GL_POLYGON); - for (typename LCC::template Dart_of_orbit_range<1>::const_iterator - orbitIter = lcc.template darts_of_orbit<1>(dh).begin(); + for (LCC::Dart_of_orbit_range<1>::const_iterator + orbitIter = lcc.darts_of_orbit<1>(dh).begin(); orbitIter.cont(); ++orbitIter) { if(!flat) From 662408b2f8568b9193045e2453223687a485f398 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 1 Jul 2015 15:21:35 +0200 Subject: [PATCH 19/24] Improve merge coplanar faces method. --- .../demo/Linear_cell_complex/MainWindow.cpp | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 1ed3427f67c..642a8996fef 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -976,7 +976,7 @@ double compute_angle3d(const Vector_3& v1, const Vector_3& v2) { double a = CGAL::to_double( (v1*v2) / ( sqrt(v1.squared_length()) * sqrt(v2.squared_length()) ) ) ; - + if (a < -1.0) return acos(-1.0)/M_PI*180.0; else if (a > 1.0) return acos(1.0)/M_PI*180.0; else return acos(a)/M_PI*180.0; @@ -992,10 +992,11 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() #endif scene.lcc->set_update_attributes(false); - + std::vector edges; int treated = scene.lcc->get_new_mark(); - + int treated2 = scene.lcc->get_new_mark(); + for ( LCC::Dart_range::iterator it= scene.lcc->darts().begin(), itend = scene.lcc->darts().end(); it!=itend; ++it ) { @@ -1006,7 +1007,7 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() LCC::Vector normal1 = CGAL::compute_normal_of_cell_2(*scene.lcc,it); LCC::Vector normal2 = CGAL::compute_normal_of_cell_2(*scene.lcc, scene.lcc->beta<2>(it) ); double angle = compute_angle3d(normal1, normal2); - + if ( ((angle<5.0 || angle>355.0) || (angle<185.0 && angle>175.0)) ) { edges.push_back(it); @@ -1015,11 +1016,13 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() CGAL::mark_cell(*scene.lcc, it, treated); } } - - + + for (std::vector::iterator it=edges.begin(), itend=edges.end(); it!=itend; ++it) { + CGAL::mark_cell(*scene.lcc, *it, treated2); + if ( scene.lcc->beta<0, 2>(*it)==*it || scene.lcc->beta<1, 2>(*it)==*it) { // To process dangling edges @@ -1028,12 +1031,17 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() { if ( scene.lcc->beta<0, 2>(actu)==actu ) prev = scene.lcc->beta<1>(actu); else prev = scene.lcc->beta<0>(actu); - - CGAL::remove_cell(*scene.lcc, actu); - actu = prev; - std::cout<<&(*actu)<is_marked(actu, treated2) && + (scene.lcc->beta<0, 2>(actu)!=actu || scene.lcc->beta<1, 2>(actu)!=actu) ) + { + CGAL::remove_cell(*scene.lcc, actu); + actu = prev; + } + else + actu = NULL; } - while (scene.lcc->beta<0, 2>(actu)==actu || scene.lcc->beta<1, 2>(actu)==actu); + while (actu!=NULL && (scene.lcc->beta<0, 2>(actu)==actu || scene.lcc->beta<1, 2>(actu)==actu)); } else if ( !CGAL::belong_to_same_cell(*scene.lcc, *it, scene.lcc->beta<2>(*it)) ) @@ -1042,6 +1050,7 @@ void MainWindow::on_actionMerge_coplanar_faces_triggered() assert(scene.lcc->is_whole_map_marked(treated)); scene.lcc->free_mark(treated); + scene.lcc->free_mark(treated2); scene.lcc->set_update_attributes(true); @@ -1138,7 +1147,7 @@ int get_free_edge(CDT::Face_handle fh) CGAL_assertion( number_of_existing_edge(fh)==2 ); for (int i=0; i<3; ++i) if (!fh->info().exist_edge[i]) return i; - + CGAL_assertion(false); return -1; } @@ -1147,8 +1156,8 @@ void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) { Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc,d1); P_traits cdt_traits(normal); - CDT cdt(cdt_traits); - + CDT cdt(cdt_traits); + //inserting the constraints edge by edge LCC::Dart_of_orbit_range<1>::iterator it(lcc.darts_of_orbit<1>(d1).begin()); @@ -1158,7 +1167,7 @@ void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) for (LCC::Dart_of_orbit_range<1>::iterator itend(lcc.darts_of_orbit<1>(d1).end()); it!=itend; ++it) - { + { vh = cdt.insert(lcc.point(it)); vh->info()=it; if( first==NULL ) @@ -1185,9 +1194,9 @@ void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) fit->info().exist_edge[1]=false; fit->info().exist_edge[2]=false; } - + std::queue face_queue; - + face_queue.push(cdt.infinite_vertex()->face()); while(! face_queue.empty() ) { @@ -1215,7 +1224,7 @@ void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) { fh->info().exist_edge[index]=true; opposite_fh->info().exist_edge[cdt.mirror_index(fh,index)]=true; - + if ( !fh->info().is_external && number_of_existing_edge(fh)==2 ) face_queue.push(fh); if ( !opposite_fh->info().is_external && @@ -1223,14 +1232,14 @@ void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) face_queue.push(opposite_fh); } } - + while( !face_queue.empty() ) { CDT::Face_handle fh = face_queue.front(); face_queue.pop(); CGAL_assertion( number_of_existing_edge(fh)>=2 ); // i.e. ==2 or ==3 CGAL_assertion( !fh->info().is_external ); - + if (number_of_existing_edge(fh)==2) { int index = get_free_edge(fh); @@ -1241,19 +1250,19 @@ void constrained_delaunay_triangulation(LCC &lcc, Dart_handle d1) exist_edge[cdt.mirror_index(fh,index)] ); const CDT::Vertex_handle va = fh->vertex(cdt. cw(index)); const CDT::Vertex_handle vb = fh->vertex(cdt.ccw(index)); - + Dart_handle ndart= - CGAL::insert_cell_1_in_cell_2(lcc,va->info(),vb->info()); + CGAL::insert_cell_1_in_cell_2(lcc,va->info(),vb->info()); va->info()=lcc.beta<2>(ndart); fh->info().exist_edge[index]=true; opposite_fh->info().exist_edge[cdt.mirror_index(fh,index)]=true; - + if ( !opposite_fh->info().is_external && number_of_existing_edge(opposite_fh)==2 ) face_queue.push(opposite_fh); } - } + } } void MainWindow::on_actionTriangulate_all_facets_triggered() @@ -1264,7 +1273,7 @@ void MainWindow::on_actionTriangulate_all_facets_triggered() CGAL::Timer timer; timer.start(); #endif - + std::vector v; for (LCC::One_dart_per_cell_range<2>::iterator it(scene.lcc->one_dart_per_cell<2>().begin()); it.cont(); ++it) @@ -1274,7 +1283,7 @@ void MainWindow::on_actionTriangulate_all_facets_triggered() scene.lcc->info<3>(scene.lcc->beta<3>(it)).is_filled_and_visible()) ) v.push_back(it); } - + for (std::vector::iterator itv(v.begin()); itv!=v.end(); ++itv) constrained_delaunay_triangulation(*scene.lcc, *itv); From 921416603fde863689f7b2f8f2b4ed933d26f933 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 28 Aug 2015 14:43:07 +0200 Subject: [PATCH 20/24] Reintegrate LCC demo save/load in the new qt5 version ok. --- .../demo/Linear_cell_complex/MainWindow.cpp | 79 ---------- .../demo/Linear_cell_complex/Viewer.cpp | 140 +++++++----------- .../demo/Linear_cell_complex/typedefs.h | 22 +++ 3 files changed, 74 insertions(+), 167 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 13ec7efb720..34b0fb2a1cf 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -27,11 +27,6 @@ #include "MainWindow.moc" #include "import_moka.h" -#include -#include -#include -#include - // Function defined in Linear_cell_complex_3_subivision.cpp void subdivide_lcc_3 (LCC & m); @@ -1115,22 +1110,6 @@ void MainWindow::on_actionMerge_all_volumes_triggered() (QString ("Visible and filled volume(s) merged"), DELAY_STATUSMSG); } -typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; -typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; - -struct Face_info { - bool exist_edge[3]; - bool is_external; -}; - -typedef CGAL::Triangulation_face_base_with_info_2 Fb1; - -typedef CGAL::Constrained_triangulation_face_base_2 Fb; -typedef CGAL::Triangulation_data_structure_2 TDS; -typedef CGAL::No_intersection_tag Itag; -typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; - bool is_external(CDT::Face_handle fh) { return fh->info().is_external; @@ -2321,64 +2300,6 @@ void MainWindow::onSierpinskiCarpetUpdateAttributes(bool newValue) sierpinskiCarpetUpdateAttributes = newValue; } -/*void MainWindow::onSierpinskiCarpetNeverUpdateAttributes(bool newValue) -{ - if (afterConstructionUpdateAttributes) - { - dialogsierpinskicarpet.groupBox2->setEnabled(false); - } - - neverUpdateAttributes = true; - duringConstructionUpdateAttributes = false; - afterConstructionUpdateAttributes = false; -} - -void MainWindow::onSierpinskiCarpetDuringConstructionUpdateAttributes(bool newValue) -{ - if (afterConstructionUpdateAttributes) - { - dialogsierpinskicarpet.groupBox2->setEnabled(false); - } - - neverUpdateAttributes = false; - duringConstructionUpdateAttributes = true; - afterConstructionUpdateAttributes = false; -} - -void MainWindow::onSierpinskiCarpetAfterConstructionUpdateAttributes(bool newValue) -{ - if (!afterConstructionUpdateAttributes) - { - dialogsierpinskicarpet.groupBox2->setEnabled(true); - } - - neverUpdateAttributes = false; - duringConstructionUpdateAttributes = false; - afterConstructionUpdateAttributes = true; -} - -void MainWindow::onSierpinskiCarpetUpdateAttributesMethodStdMap(bool newValue) -{ - updateAttributesMethodStdMap = true; - updateAttributesMethodTraversal = false; -} - -void MainWindow::onSierpinskiCarpetUpdateAttributesMethodTraversal(bool newValue) -{ - updateAttributesMethodStdMap = false; - updateAttributesMethodTraversal = true; -} - -void MainWindow::onSierpinskiCarpetComputeGeometry(bool newValue) -{ - sierpinski_carpet_compute_geometry(); - - computeGeometry = false; - dialogsierpinskicarpet.computeGeometry->setEnabled(false); - - Q_EMIT( sceneChanged()); -}*/ - void MainWindow::onSierpinskiCarpetInc() { QApplication::setOverrideCursor (Qt::WaitCursor); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index 862094505a0..fe1f18f7c58 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -21,35 +21,12 @@ #include "Viewer.h" #include -#include -#include -#include -#include -#include #include #include #include #include -typedef LCC::Traits Traits; -typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; -struct Face_info { - LCC::Dart_handle e[3]; - bool is_external; -}; -typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; -typedef CGAL::Triangulation_face_base_with_info_2 Fb1; -typedef CGAL::Constrained_triangulation_face_base_2 Fb; -typedef CGAL::Triangulation_data_structure_2 TDS; -typedef CGAL::No_intersection_tag Itag; -typedef CGAL::Constrained_Delaunay_triangulation_2 CDTbase; -typedef CGAL::Constrained_triangulation_plus_2 CDT; - Viewer::Viewer(QWidget* parent) : QGLViewer(CGAL::Qt::createOpenGLContext(),parent), wireframe(false), flatShading(true), edges(true), vertices(true), m_displayListCreated(false) @@ -109,34 +86,28 @@ void Viewer::triangulate_facet() (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) { //Computes the normal of the facet - Traits::Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc, dartIter); + Mytraits::Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc, dartIter); normal = normal/(CGAL::sqrt(normal*normal)); P_traits cdt_traits(normal); CDT cdt(cdt_traits); // Iterates on the vector of facet handles - std::cout<<"New face: "; CDT::Vertex_handle previous = NULL, first = NULL; for (LCC::Dart_of_orbit_range<1>::const_iterator he_circ = lcc.darts_of_orbit<1>(dartIter).begin(), he_circ_end = lcc.darts_of_orbit<1>(dartIter).end(); he_circ!=he_circ_end; ++he_circ) { - std::cout<info() = he_circ; if(previous!=NULL && previous != vh) - { cdt.insert_constraint(previous, vh); - std::cout<<"Constraint: "<<*previous<<" -> "<<*vh< "<<*first<info().is_external) + if(!ffit->info().is_external) { - std::cout<<"external"<vertex(0)->point().x()); + pos_facets.push_back(ffit->vertex(0)->point().y()); + pos_facets.push_back(ffit->vertex(0)->point().z()); + + pos_facets.push_back(ffit->vertex(1)->point().x()); + pos_facets.push_back(ffit->vertex(1)->point().y()); + pos_facets.push_back(ffit->vertex(1)->point().z()); + + pos_facets.push_back(ffit->vertex(2)->point().x()); + pos_facets.push_back(ffit->vertex(2)->point().y()); + pos_facets.push_back(ffit->vertex(2)->point().z()); + + double r = (double)lcc.info<3>(dartIter).color().r()/255.0; + double g = (double)lcc.info<3>(dartIter).color().g()/255.0; + double b = (double)lcc.info<3>(dartIter).color().b()/255.0; + if ( !lcc.is_free(dartIter, 3) ) + { + r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; + g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; + b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; + r /= 2; g /= 2; b /= 2; + } + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); } - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - pos_facets.push_back(ffit->vertex(0)->point().x()); - pos_facets.push_back(ffit->vertex(0)->point().y()); - pos_facets.push_back(ffit->vertex(0)->point().z()); - - pos_facets.push_back(ffit->vertex(1)->point().x()); - pos_facets.push_back(ffit->vertex(1)->point().y()); - pos_facets.push_back(ffit->vertex(1)->point().z()); - - pos_facets.push_back(ffit->vertex(2)->point().x()); - pos_facets.push_back(ffit->vertex(2)->point().y()); - pos_facets.push_back(ffit->vertex(2)->point().z()); - - std::cout<<"Triangle: "<vertex(0)->point()<<" " - <vertex(1)->point()<<" " - <vertex(2)->point()<(dartIter).color().r()/255.0; - double g = (double)lcc.info<3>(dartIter).color().g()/255.0; - double b = (double)lcc.info<3>(dartIter).color().b()/255.0; - if ( !lcc.is_free(dartIter, 3) ) - { - r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; - g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; - b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; - r /= 2; g /= 2; b /= 2; - } - colors.push_back(r);colors.push_back(g);colors.push_back(b); - colors.push_back(r);colors.push_back(g);colors.push_back(b); - colors.push_back(r);colors.push_back(g);colors.push_back(b); } } } diff --git a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h index 2c4f8cbdffa..3609e6665cf 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h @@ -26,6 +26,12 @@ #include #include +#include +#include +#include +#include +#include + #include #include #include @@ -169,6 +175,22 @@ typedef LCC::Vector Vector_3; typedef CGAL::Timer Timer; +typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; + +struct Face_info { + bool exist_edge[3]; + bool is_external; +}; + +typedef CGAL::Triangulation_face_base_with_info_2 Fb1; + +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::No_intersection_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; + struct Scene { LCC* lcc; }; From 24840dbd5c6e1d76da7bc6cc5714777745df9abb Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Sat, 29 Aug 2015 14:43:52 +0200 Subject: [PATCH 21/24] Improve drawing code in LCC demo. --- .../demo/Linear_cell_complex/Viewer.cpp | 528 ++++++++---------- .../demo/Linear_cell_complex/Viewer.h | 10 +- 2 files changed, 231 insertions(+), 307 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index fe1f18f7c58..e465cb8a0ca 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -38,166 +38,6 @@ Viewer::Viewer(QWidget* parent) are_buffers_initialized = false; } -//Make sure all the facets are triangles -bool Viewer::is_Triangulated() -{ - LCC &lcc = *scene->lcc; - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) - { - for(LCC::One_dart_per_incident_cell_range<2,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<2,3> - (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) - { - int nb_points_per_facet =0; - for (LCC::Dart_of_orbit_range<1>::const_iterator - orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); - orbitIter.cont(); ++orbitIter) - { - nb_points_per_facet++; - } - if(nb_points_per_facet != 3) - { - return false; - } - } - } - return true; -} - -void Viewer::triangulate_facet() -{ - pos_facets.clear(); - flat_normals.clear(); - smooth_normals.clear(); - colors.clear(); - - LCC &lcc = *scene->lcc; - - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) - { - if ( it->info().is_visible() ) - { - for(LCC::One_dart_per_incident_cell_range<2,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<2,3> - (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) - { - //Computes the normal of the facet - Mytraits::Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc, dartIter); - normal = normal/(CGAL::sqrt(normal*normal)); - - P_traits cdt_traits(normal); - CDT cdt(cdt_traits); - - // Iterates on the vector of facet handles - CDT::Vertex_handle previous = NULL, first = NULL; - for (LCC::Dart_of_orbit_range<1>::const_iterator - he_circ = lcc.darts_of_orbit<1>(dartIter).begin(), - he_circ_end = lcc.darts_of_orbit<1>(dartIter).end(); - he_circ!=he_circ_end; ++he_circ) - { - CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ)); - if(first == NULL) - { first = vh; } - //vh->info() = he_circ; - if(previous!=NULL && previous != vh) - { cdt.insert_constraint(previous, vh); } - previous = vh; - } - cdt.insert_constraint(previous, first); - - // sets mark is_external - for(CDT::All_faces_iterator fit = cdt.all_faces_begin(), - fitend = cdt.all_faces_end(); fit!=fitend; ++fit) - { - fit->info().is_external = false; - } - //check if the facet is external or internal - std::queue face_queue; - face_queue.push(cdt.infinite_vertex()->face()); - while(! face_queue.empty() ) - { - CDT::Face_handle fh = face_queue.front(); - face_queue.pop(); - if(!fh->info().is_external) - { - fh->info().is_external = true; - for(int i = 0; i <3; ++i) - { - if(!cdt.is_constrained(std::make_pair(fh, i))) - { - face_queue.push(fh->neighbor(i)); - } - } - } - } - - //iterates on the internal faces to add the vertices to the positions - //and the normals to the appropriate vectors - for(CDT::Finite_faces_iterator ffit = cdt.finite_faces_begin(), - ffitend = cdt.finite_faces_end(); ffit != ffitend; ++ffit) - { - if(!ffit->info().is_external) - { - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - pos_facets.push_back(ffit->vertex(0)->point().x()); - pos_facets.push_back(ffit->vertex(0)->point().y()); - pos_facets.push_back(ffit->vertex(0)->point().z()); - - pos_facets.push_back(ffit->vertex(1)->point().x()); - pos_facets.push_back(ffit->vertex(1)->point().y()); - pos_facets.push_back(ffit->vertex(1)->point().z()); - - pos_facets.push_back(ffit->vertex(2)->point().x()); - pos_facets.push_back(ffit->vertex(2)->point().y()); - pos_facets.push_back(ffit->vertex(2)->point().z()); - - double r = (double)lcc.info<3>(dartIter).color().r()/255.0; - double g = (double)lcc.info<3>(dartIter).color().g()/255.0; - double b = (double)lcc.info<3>(dartIter).color().b()/255.0; - if ( !lcc.is_free(dartIter, 3) ) - { - r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; - g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; - b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; - r /= 2; g /= 2; b /= 2; - } - colors.push_back(r);colors.push_back(g);colors.push_back(b); - colors.push_back(r);colors.push_back(g);colors.push_back(b); - colors.push_back(r);colors.push_back(g);colors.push_back(b); - } - } - } - } - } -} - void Viewer::compile_shaders() { if(!buffers[0].create() || !buffers[1].create() || !buffers[2].create() || @@ -439,167 +279,249 @@ void Viewer::initialize_buffers() are_buffers_initialized = true; } -void Viewer::compute_elements() +void Viewer::compute_faces(Dart_handle dh) { LCC &lcc = *scene->lcc; - - //Facets - if(is_Triangulated()) + for(LCC::One_dart_per_incident_cell_range<2,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<2,3>(dh).begin(); + dartIter.cont(); ++dartIter) { - pos_facets.resize(0); - flat_normals.resize(0); - smooth_normals.resize(0); - colors.resize(0); - - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) + double r = (double)lcc.info<3>(dartIter).color().r()/255.0; + double g = (double)lcc.info<3>(dartIter).color().g()/255.0; + double b = (double)lcc.info<3>(dartIter).color().b()/255.0; + if ( !lcc.is_free(dartIter, 3) ) { - if ( it->info().is_visible() ) - { - for(LCC::One_dart_per_incident_cell_range<2,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<2,3> - (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) - { - // We draw the polygon - - // double r = (double)dartIter->attribute<3>()->info().r()/255.0; - float r = (float)lcc.info<3>(dartIter).color().r()/255.0; - float g = (float)lcc.info<3>(dartIter).color().g()/255.0; - float b = (float)lcc.info<3>(dartIter).color().b()/255.0; - if ( !lcc.is_free(dartIter, 3) ) - { - r += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; - g += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; - b += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; - r /= 2; g /= 2; b /= 2; - } - - colors.push_back(r);colors.push_back(g);colors.push_back(b); - colors.push_back(r);colors.push_back(g);colors.push_back(b); - colors.push_back(r);colors.push_back(g);colors.push_back(b); - //compute flat normals - LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); - normal = normal/(CGAL::sqrt(normal*normal)); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); - - for (LCC::Dart_of_orbit_range<1>::const_iterator - orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); - orbitIter.cont(); ++orbitIter) - { - //compute Smooth normals - LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); - normal = normal/(CGAL::sqrt(normal*normal)); - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - const LCC::Point& p = lcc.point(orbitIter); - pos_facets.push_back(p.x()); - pos_facets.push_back(p.y()); - pos_facets.push_back(p.z()); - } - } - } + r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; + g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; + b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; + r /= 2; g /= 2; b /= 2; } - } - else - triangulate_facet(); - - //Edges - { - pos_lines.resize(0); - if ( !lcc.is_empty() ) - { - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) + //compute flat normals + LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); + normal = normal/(CGAL::sqrt(normal*normal)); + + if (lcc.beta<1,1,1>(dartIter)!=dartIter) + { + P_traits cdt_traits(normal); + CDT cdt(cdt_traits); + + // Iterates on the vector of facet handles + CDT::Vertex_handle previous = NULL, first = NULL; + for (LCC::Dart_of_orbit_range<1>::const_iterator + he_circ = lcc.darts_of_orbit<1>(dartIter).begin(), + he_circ_end = lcc.darts_of_orbit<1>(dartIter).end(); + he_circ!=he_circ_end; ++he_circ) { - if ( it->info().is_visible() ) + CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ)); + if(first == NULL) + { first = vh; } + //vh->info() = he_circ; + if(previous!=NULL && previous != vh) + { cdt.insert_constraint(previous, vh); } + previous = vh; + } + cdt.insert_constraint(previous, first); + + // sets mark is_external + for(CDT::All_faces_iterator fit = cdt.all_faces_begin(), + fitend = cdt.all_faces_end(); fit!=fitend; ++fit) + { + fit->info().is_external = false; + } + //check if the facet is external or internal + std::queue face_queue; + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) + { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(!fh->info().is_external) { - for(LCC::One_dart_per_incident_cell_range<1,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<1,3> - (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) + fh->info().is_external = true; + for(int i = 0; i <3; ++i) { - const LCC::Point& p = lcc.point(dartIter); - Dart_handle d2 = lcc.other_extremity(dartIter); - if ( d2!=NULL ) + if(!cdt.is_constrained(std::make_pair(fh, i))) { - const LCC::Point& p2 = lcc.point(d2); - pos_lines.push_back(p.x()); - pos_lines.push_back(p.y()); - pos_lines.push_back(p.z()); - - pos_lines.push_back(p2.x()); - pos_lines.push_back(p2.y()); - pos_lines.push_back(p2.z()); + face_queue.push(fh->neighbor(i)); } } } } - } - } - - //Points - { - pos_points.resize(0); - - if ( lcc.is_empty() ) - { - bb = LCC::Point(CGAL::ORIGIN).bbox(); - bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer - return; - } - - bool empty = true; - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) - { - if ( it->info().is_visible() ) + + //iterates on the internal faces to add the vertices to the positions + //and the normals to the appropriate vectors + for(CDT::Finite_faces_iterator ffit = cdt.finite_faces_begin(), + ffitend = cdt.finite_faces_end(); ffit != ffitend; ++ffit) { - for(LCC::One_dart_per_incident_cell_range<0,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<0,3> - (lcc.dart_of_attribute<3>(it)).begin(); - dartIter.cont(); ++dartIter) + if(!ffit->info().is_external) { - const LCC::Point& p = lcc.point(dartIter); - pos_points.push_back(p.x()); - pos_points.push_back(p.y()); - pos_points.push_back(p.z()); + smooth_normals.push_back(normal.x()); + smooth_normals.push_back(normal.y()); + smooth_normals.push_back(normal.z()); - if ( empty ) - { - bb = p.bbox(); - empty = false; - } - else - bb = bb + p.bbox(); + smooth_normals.push_back(normal.x()); + smooth_normals.push_back(normal.y()); + smooth_normals.push_back(normal.z()); + + smooth_normals.push_back(normal.x()); + smooth_normals.push_back(normal.y()); + smooth_normals.push_back(normal.z()); + + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + pos_facets.push_back(ffit->vertex(0)->point().x()); + pos_facets.push_back(ffit->vertex(0)->point().y()); + pos_facets.push_back(ffit->vertex(0)->point().z()); + + pos_facets.push_back(ffit->vertex(1)->point().x()); + pos_facets.push_back(ffit->vertex(1)->point().y()); + pos_facets.push_back(ffit->vertex(1)->point().z()); + + pos_facets.push_back(ffit->vertex(2)->point().x()); + pos_facets.push_back(ffit->vertex(2)->point().y()); + pos_facets.push_back(ffit->vertex(2)->point().z()); + + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); } } } - - if ( lcc.is_empty() ) - { - bb = LCC::Point(CGAL::ORIGIN).bbox(); - bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer + else + { + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + for (LCC::Dart_of_orbit_range<1>::const_iterator + orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); + orbitIter.cont(); ++orbitIter) + { + //compute Smooth normals + LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); + normal = normal/(CGAL::sqrt(normal*normal)); + + smooth_normals.push_back(normal.x()); + smooth_normals.push_back(normal.y()); + smooth_normals.push_back(normal.z()); + + const LCC::Point& p = lcc.point(orbitIter); + pos_facets.push_back(p.x()); + pos_facets.push_back(p.y()); + pos_facets.push_back(p.z()); + } } } } +void Viewer::compute_edges(Dart_handle dh) +{ + LCC &lcc = *scene->lcc; + for(LCC::One_dart_per_incident_cell_range<1,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<1,3>(dh).begin(); + dartIter.cont(); ++dartIter) + { + const LCC::Point& p = lcc.point(dartIter); + Dart_handle d2 = lcc.other_extremity(dartIter); + if ( d2!=NULL ) + { + const LCC::Point& p2 = lcc.point(d2); + pos_lines.push_back(p.x()); + pos_lines.push_back(p.y()); + pos_lines.push_back(p.z()); + + pos_lines.push_back(p2.x()); + pos_lines.push_back(p2.y()); + pos_lines.push_back(p2.z()); + } + } +} + +void Viewer::compute_vertices(Dart_handle dh, bool empty) +{ + LCC &lcc = *scene->lcc; + for(LCC::One_dart_per_incident_cell_range<0,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<0,3>(dh).begin(); + dartIter.cont(); ++dartIter) + { + const LCC::Point& p = lcc.point(dartIter); + pos_points.push_back(p.x()); + pos_points.push_back(p.y()); + pos_points.push_back(p.z()); + + if ( empty ) + { + bb = p.bbox(); + empty = false; + } + else + bb = bb + p.bbox(); + } +} + +void Viewer::compute_elements() +{ + LCC &lcc = *scene->lcc; + + pos_facets.clear(); + flat_normals.clear(); + smooth_normals.clear(); + colors.clear(); + pos_lines.clear(); + pos_points.clear(); + + if ( lcc.is_empty() ) + { + bb = LCC::Point(CGAL::ORIGIN).bbox(); + bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer + return; + } + + bool empty = true; + for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), + itend=lcc.attributes<3>().end(); it!=itend; ++it ) + { + if ( it->info().is_visible() ) + { + if (it->info().is_filled()) + compute_faces(lcc.dart_of_attribute<3>(it)); + + compute_edges(lcc.dart_of_attribute<3>(it)); + compute_vertices(lcc.dart_of_attribute<3>(it), empty); + empty = false; + } + } + + if ( empty ) + { + bb = LCC::Point(CGAL::ORIGIN).bbox(); + bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer + } +} + void Viewer::attrib_buffers(QGLViewer* viewer) { QMatrix4x4 mvpMatrix; @@ -800,12 +722,12 @@ void Viewer::keyPressEvent(QKeyEvent *e) } else { - ::glShadeModel(GL_FLAT); - ::glDisable(GL_BLEND); - ::glDisable(GL_LINE_SMOOTH); - ::glDisable(GL_POLYGON_SMOOTH_HINT); - ::glBlendFunc(GL_ONE, GL_ZERO); - ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); + ::glShadeModel(GL_FLAT); + ::glDisable(GL_BLEND); + ::glDisable(GL_LINE_SMOOTH); + ::glDisable(GL_POLYGON_SMOOTH_HINT); + ::glBlendFunc(GL_ONE, GL_ZERO); + ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } handled = true; updateGL(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index fb241cdd7dd..37e9fb4a230 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -90,8 +90,8 @@ public Q_SLOTS: private: bool are_buffers_initialized; - //Shaders elements + //Shaders elements int vertexLocation[3]; int normalsLocation; int mvpLocation[2]; @@ -113,11 +113,13 @@ private: QOpenGLShaderProgram rendering_program_p_l; void initialize_buffers(); - void compute_elements(); void attrib_buffers(QGLViewer*); void compile_shaders(); - void triangulate_facet(); - bool is_Triangulated(); + + void compute_elements(); + void compute_faces(Dart_handle dh); + void compute_edges(Dart_handle dh); + void compute_vertices(Dart_handle dh, bool empty); }; #endif From 98b36b260e472f968ff9e33c59fc6cac3d6ade5f Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 31 Aug 2015 08:18:04 +0200 Subject: [PATCH 22/24] Update light parameters --- .../demo/Linear_cell_complex/Viewer.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index e465cb8a0ca..db8e6c4823e 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -538,18 +538,18 @@ void Viewer::attrib_buffers(QGLViewer* viewer) mvMatrix.data()[i] = (float)mat[i]; } // define material - QVector4D ambient(0.1f, 0.1f, 0.1f, 1.0f); + QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f); QVector4D diffuse( 0.9f, 0.9f, 0.9f, - 0.0f ); + 0.9f ); QVector4D specular( 0.0f, 0.0f, 0.0f, - 0.0f ); + 1.0f ); - QVector4D position( 0.0f, -10.0f, -10.0f, 0.0f ); + QVector4D position( 10.0f, 10.0f, 10.0f, 0.0f ); GLfloat shininess = 1.0f; rendering_program.bind(); @@ -669,7 +669,6 @@ void Viewer::init() ::glEnable(GL_LIGHTING); ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - // ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); if (flatShading) { @@ -697,7 +696,6 @@ void Viewer::keyPressEvent(QKeyEvent *e) { const Qt::KeyboardModifiers modifiers = e->modifiers(); - bool handled = false; if ((e->key()==Qt::Key_W) && (modifiers==Qt::NoButton)) { wireframe = !wireframe; @@ -705,7 +703,6 @@ void Viewer::keyPressEvent(QKeyEvent *e) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - handled = true; updateGL(); } else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) @@ -729,23 +726,19 @@ void Viewer::keyPressEvent(QKeyEvent *e) ::glBlendFunc(GL_ONE, GL_ZERO); ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } - handled = true; updateGL(); } else if ((e->key()==Qt::Key_E) && (modifiers==Qt::NoButton)) { edges = !edges; - handled = true; updateGL(); } else if ((e->key()==Qt::Key_V) && (modifiers==Qt::NoButton)) { vertices = !vertices; - handled = true; updateGL(); } - - if (!handled) + else QGLViewer::keyPressEvent(e); } From 9b4b3ee846de8f2f61b70fddca3ab220d978218c Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 3 Sep 2015 12:32:20 +0200 Subject: [PATCH 23/24] More cleanup plus do not recenter the scene at each modification. --- .../demo/Linear_cell_complex/Viewer.cpp | 130 ++++++++++-------- .../demo/Linear_cell_complex/Viewer.h | 63 +++------ 2 files changed, 97 insertions(+), 96 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index db8e6c4823e..d1ad8b71ebf 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -16,7 +16,7 @@ // $Id$ // // Author(s) : Guillaume Damiand -// Kumar Snehasish +// Contributor(s): Kumar Snehasish // #include "Viewer.h" @@ -29,13 +29,30 @@ Viewer::Viewer(QWidget* parent) : QGLViewer(CGAL::Qt::createOpenGLContext(),parent), wireframe(false), - flatShading(true), edges(true), vertices(true), m_displayListCreated(false) + flatShading(true), edges(true), vertices(true), + m_previous_scene_empty(true), are_buffers_initialized(false) + { QGLFormat newFormat = this->format(); newFormat.setSampleBuffers(true); newFormat.setSamples(16); this->setFormat(newFormat); - are_buffers_initialized = false; +} + +Viewer::~Viewer() +{ + buffers[0].destroy(); + buffers[1].destroy(); + buffers[2].destroy(); + buffers[3].destroy(); + buffers[4].destroy(); + buffers[5].destroy(); + buffers[6].destroy(); + buffers[7].destroy(); + vao[0].destroy(); + vao[1].destroy(); + vao[2].destroy(); + vao[3].destroy(); } void Viewer::compile_shaders() @@ -53,7 +70,7 @@ void Viewer::compile_shaders() } //The Facets - + //Vertex source code const char vertex_source[] = { @@ -61,10 +78,10 @@ void Viewer::compile_shaders() "attribute highp vec4 vertex;\n" "attribute highp vec3 normal;\n" "attribute highp vec3 color;\n" - + "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - + "varying highp vec4 fP; \n" "varying highp vec3 fN; \n" "varying highp vec4 fColor; \n" @@ -88,20 +105,20 @@ void Viewer::compile_shaders() "uniform vec4 light_spec; \n" "uniform vec4 light_amb; \n" "uniform float spec_power ; \n" - + "void main(void) { \n" - + " vec3 L = light_pos.xyz - fP.xyz; \n" " vec3 V = -fP.xyz; \n" - + " vec3 N = normalize(fN); \n" " L = normalize(L); \n" " V = normalize(V); \n" - + " vec3 R = reflect(-L, N); \n" " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - + "gl_FragColor = light_amb*fColor + diffuse ; \n" "} \n" "\n" @@ -122,7 +139,7 @@ void Viewer::compile_shaders() if(!rendering_program.addShader(vertex_shader)) { std::cerr<<"adding vertex shader FAILED"<compileSourceCode(vertex_source_p_l)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_p_l)) { std::cerr<<"Compiling fragmentsource FAILED"<(pos_facets.size()*sizeof(float))); @@ -239,7 +256,7 @@ void Viewer::initialize_buffers() rendering_program.enableAttributeArray(normalsLocation); rendering_program.setAttributeBuffer(normalsLocation,GL_FLOAT,0,3); buffers[4].release(); - + //colors of the facets buffers[5].bind(); buffers[5].allocate(colors.data(), static_cast(colors.size()*sizeof(float))); @@ -296,16 +313,16 @@ void Viewer::compute_faces(Dart_handle dh) b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; r /= 2; g /= 2; b /= 2; } - + //compute flat normals LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); normal = normal/(CGAL::sqrt(normal*normal)); - + if (lcc.beta<1,1,1>(dartIter)!=dartIter) { P_traits cdt_traits(normal); - CDT cdt(cdt_traits); - + CDT cdt(cdt_traits); + // Iterates on the vector of facet handles CDT::Vertex_handle previous = NULL, first = NULL; for (LCC::Dart_of_orbit_range<1>::const_iterator @@ -322,7 +339,7 @@ void Viewer::compute_faces(Dart_handle dh) previous = vh; } cdt.insert_constraint(previous, first); - + // sets mark is_external for(CDT::All_faces_iterator fit = cdt.all_faces_begin(), fitend = cdt.all_faces_end(); fit!=fitend; ++fit) @@ -348,7 +365,7 @@ void Viewer::compute_faces(Dart_handle dh) } } } - + //iterates on the internal faces to add the vertices to the positions //and the normals to the appropriate vectors for(CDT::Finite_faces_iterator ffit = cdt.finite_faces_begin(), @@ -359,39 +376,39 @@ void Viewer::compute_faces(Dart_handle dh) smooth_normals.push_back(normal.x()); smooth_normals.push_back(normal.y()); smooth_normals.push_back(normal.z()); - + smooth_normals.push_back(normal.x()); smooth_normals.push_back(normal.y()); smooth_normals.push_back(normal.z()); - + smooth_normals.push_back(normal.x()); smooth_normals.push_back(normal.y()); smooth_normals.push_back(normal.z()); - + flat_normals.push_back(normal.x()); flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - + flat_normals.push_back(normal.x()); flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - + flat_normals.push_back(normal.x()); flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - + pos_facets.push_back(ffit->vertex(0)->point().x()); pos_facets.push_back(ffit->vertex(0)->point().y()); pos_facets.push_back(ffit->vertex(0)->point().z()); - + pos_facets.push_back(ffit->vertex(1)->point().x()); pos_facets.push_back(ffit->vertex(1)->point().y()); pos_facets.push_back(ffit->vertex(1)->point().z()); - + pos_facets.push_back(ffit->vertex(2)->point().x()); pos_facets.push_back(ffit->vertex(2)->point().y()); pos_facets.push_back(ffit->vertex(2)->point().z()); - + colors.push_back(r);colors.push_back(g);colors.push_back(b); colors.push_back(r);colors.push_back(g);colors.push_back(b); colors.push_back(r);colors.push_back(g);colors.push_back(b); @@ -399,23 +416,23 @@ void Viewer::compute_faces(Dart_handle dh) } } else - { + { colors.push_back(r);colors.push_back(g);colors.push_back(b); colors.push_back(r);colors.push_back(g);colors.push_back(b); colors.push_back(r);colors.push_back(g);colors.push_back(b); - + flat_normals.push_back(normal.x()); flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - + flat_normals.push_back(normal.x()); flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - + flat_normals.push_back(normal.x()); flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - + for (LCC::Dart_of_orbit_range<1>::const_iterator orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); orbitIter.cont(); ++orbitIter) @@ -423,11 +440,11 @@ void Viewer::compute_faces(Dart_handle dh) //compute Smooth normals LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); normal = normal/(CGAL::sqrt(normal*normal)); - + smooth_normals.push_back(normal.x()); smooth_normals.push_back(normal.y()); smooth_normals.push_back(normal.z()); - + const LCC::Point& p = lcc.point(orbitIter); pos_facets.push_back(p.x()); pos_facets.push_back(p.y()); @@ -452,7 +469,7 @@ void Viewer::compute_edges(Dart_handle dh) pos_lines.push_back(p.x()); pos_lines.push_back(p.y()); pos_lines.push_back(p.z()); - + pos_lines.push_back(p2.x()); pos_lines.push_back(p2.y()); pos_lines.push_back(p2.z()); @@ -471,7 +488,7 @@ void Viewer::compute_vertices(Dart_handle dh, bool empty) pos_points.push_back(p.x()); pos_points.push_back(p.y()); pos_points.push_back(p.z()); - + if ( empty ) { bb = p.bbox(); @@ -492,14 +509,14 @@ void Viewer::compute_elements() colors.clear(); pos_lines.clear(); pos_points.clear(); - + if ( lcc.is_empty() ) { bb = LCC::Point(CGAL::ORIGIN).bbox(); bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer return; } - + bool empty = true; for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), itend=lcc.attributes<3>().end(); it!=itend; ++it ) @@ -508,13 +525,13 @@ void Viewer::compute_elements() { if (it->info().is_filled()) compute_faces(lcc.dart_of_attribute<3>(it)); - + compute_edges(lcc.dart_of_attribute<3>(it)); compute_vertices(lcc.dart_of_attribute<3>(it), empty); empty = false; } } - + if ( empty ) { bb = LCC::Point(CGAL::ORIGIN).bbox(); @@ -543,15 +560,15 @@ void Viewer::attrib_buffers(QGLViewer* viewer) 0.9f, 0.9f, 0.9f ); - + QVector4D specular( 0.0f, 0.0f, 0.0f, 1.0f ); - + QVector4D position( 10.0f, 10.0f, 10.0f, 0.0f ); GLfloat shininess = 1.0f; - + rendering_program.bind(); mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); mvLocation = rendering_program.uniformLocation("mv_matrix"); @@ -560,7 +577,7 @@ void Viewer::attrib_buffers(QGLViewer* viewer) lightLocation[2] = rendering_program.uniformLocation("light_spec"); lightLocation[3] = rendering_program.uniformLocation("light_amb"); lightLocation[4] = rendering_program.uniformLocation("spec_power"); - + rendering_program.setUniformValue(lightLocation[0], position); rendering_program.setUniformValue(lightLocation[1], diffuse); rendering_program.setUniformValue(lightLocation[2], specular); @@ -575,7 +592,6 @@ void Viewer::attrib_buffers(QGLViewer* viewer) colorLocation = rendering_program_p_l.uniformLocation("color"); rendering_program.setUniformValue(mvpLocation[1], mvpMatrix); rendering_program_p_l.release(); - are_buffers_initialized = true; } void Viewer::sceneChanged() @@ -588,7 +604,13 @@ void Viewer::sceneChanged() bb.ymax(), bb.zmax())); are_buffers_initialized = false; - this->showEntireScene(); + + if (m_previous_scene_empty) + this->showEntireScene(); + else + this->updateGL(); + + m_previous_scene_empty = scene->lcc->is_empty(); // for the next call to sceneChanged } void Viewer::draw() @@ -596,12 +618,12 @@ void Viewer::draw() glEnable(GL_DEPTH_TEST); if(!are_buffers_initialized) initialize_buffers(); - + QColor color; if ( !wireframe ) { if(flatShading) - { + { vao[0].bind(); attrib_buffers(this); rendering_program.bind(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index 37e9fb4a230..450cea1da1a 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -31,47 +31,18 @@ #include #include -class Viewer : public QGLViewer, QOpenGLFunctions_2_1 +class Viewer : public QGLViewer, public QOpenGLFunctions_2_1 { Q_OBJECT - CGAL::Timer timer; - Scene* scene; - bool wireframe; - bool flatShading; - bool edges; - bool vertices; - CGAL::Bbox_3 bb; - - GLuint m_dlFaces; - GLuint m_dlFacesFlat; - GLuint m_dlEdges; - GLuint m_dlVertices; - bool m_displayListCreated; - bool m_previous_scene_empty; - typedef LCC::Dart_handle Dart_handle; typedef LCC::Dart_const_handle Dart_const_handle; public: Viewer(QWidget* parent); - - ~Viewer() - { - buffers[0].destroy(); - buffers[1].destroy(); - buffers[2].destroy(); - buffers[3].destroy(); - buffers[4].destroy(); - buffers[5].destroy(); - buffers[6].destroy(); - buffers[7].destroy(); - vao[0].destroy(); - vao[1].destroy(); - vao[2].destroy(); - vao[3].destroy(); - } - + + ~Viewer(); + void setScene(Scene* scene_) { scene = scene_; } @@ -89,6 +60,23 @@ public Q_SLOTS: void sceneChanged(); private: + void initialize_buffers(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); + + void compute_elements(); + void compute_faces(Dart_handle dh); + void compute_edges(Dart_handle dh); + void compute_vertices(Dart_handle dh, bool empty); + +private: + Scene* scene; + bool wireframe; + bool flatShading; + bool edges; + bool vertices; + CGAL::Bbox_3 bb; + bool m_previous_scene_empty; bool are_buffers_initialized; //Shaders elements @@ -111,15 +99,6 @@ private: QOpenGLVertexArrayObject vao[10]; QOpenGLShaderProgram rendering_program; QOpenGLShaderProgram rendering_program_p_l; - - void initialize_buffers(); - void attrib_buffers(QGLViewer*); - void compile_shaders(); - - void compute_elements(); - void compute_faces(Dart_handle dh); - void compute_edges(Dart_handle dh); - void compute_vertices(Dart_handle dh, bool empty); }; #endif From e2656f9600ba11b7d4c6be09fbaf91c2a4dc96e2 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 3 Sep 2015 12:35:42 +0200 Subject: [PATCH 24/24] Remove glu link in cmake --- Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index 3540c646cc9..763c25d968e 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -73,7 +73,6 @@ target_link_libraries(Linear_cell_complex_3_demo ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) target_link_libraries(Linear_cell_complex_3_demo ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ) -target_link_libraries(Linear_cell_complex_3_demo ${OPENGL_gl_LIBRARY} - ${OPENGL_glu_LIBRARY} ) +target_link_libraries(Linear_cell_complex_3_demo ${OPENGL_gl_LIBRARY} ) endif()