mirror of https://github.com/CGAL/cgal
Add save/load in the demo.
This commit is contained in:
parent
f680e36296
commit
1867f5b096
|
|
@ -1,402 +0,0 @@
|
|||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <CGAL/Combinatorial_map.h>
|
||||
#include <CGAL/Combinatorial_map_constructors.h>
|
||||
#include <CGAL/Combinatorial_map_operations.h>
|
||||
#include <CGAL/Combinatorial_map_save_load.h>
|
||||
#include <CGAL/Cell_attribute.h>
|
||||
#include <CGAL/Linear_cell_complex.h>
|
||||
#include <CGAL/Linear_cell_complex_constructors.h>
|
||||
#include <CGAL/Linear_cell_complex_operations.h>
|
||||
|
||||
//******************************************************************************
|
||||
// Functor used to display all the attributes of a given dimension.
|
||||
template<typename CMap>
|
||||
struct My_functor_display_attrib
|
||||
{
|
||||
template <unsigned int i>
|
||||
static void run(const CMap& amap)
|
||||
{
|
||||
std::cout<<i<<"-attributes: ";
|
||||
|
||||
typename CMap::template Attribute_range<i>::type::const_iterator
|
||||
it_attrib = amap.template attributes<i>().begin(),
|
||||
itend_attrib = amap.template attributes<i>().end();
|
||||
|
||||
for (; it_attrib!=itend_attrib; ++it_attrib)
|
||||
{
|
||||
std::cout<<it_attrib->info()<<" ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
// Display the map, i.e. all its characteristics, then all its attributes.
|
||||
template < class CMap >
|
||||
void display_map(const CMap& amap)
|
||||
{
|
||||
amap.display_characteristics(std::cout)
|
||||
<<", valid="<<amap.is_valid()<<std::endl;
|
||||
|
||||
CMap::Helper::template Foreach_enabled_attributes
|
||||
<My_functor_display_attrib<CMap> >::run(amap);
|
||||
}
|
||||
//******************************************************************************
|
||||
// Functor used to display all the attributes of a given dimension.
|
||||
template<typename CMap, unsigned int i, typename Info=typename CMap::template Attribute_type<i>::type::Info>
|
||||
struct My_functor_display_one_attrib_lcc
|
||||
{
|
||||
static void run(const CMap& amap)
|
||||
{
|
||||
std::cout<<i<<"-attributes: ";
|
||||
|
||||
typename CMap::template Attribute_range<i>::type::const_iterator
|
||||
it_attrib = amap.template attributes<i>().begin(),
|
||||
itend_attrib = amap.template attributes<i>().end();
|
||||
|
||||
for (; it_attrib!=itend_attrib; ++it_attrib)
|
||||
{
|
||||
std::cout<<it_attrib->info()<<" ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
template<typename CMap, unsigned int i>
|
||||
struct My_functor_display_one_attrib_lcc<CMap, i, void>
|
||||
{
|
||||
static void run(const CMap& amap)
|
||||
{
|
||||
std::cout<<i<<"-attributes: ";
|
||||
|
||||
std::cout<<amap.template attributes<i>().size()<<" attributes without info."
|
||||
<<std::endl;
|
||||
}
|
||||
};
|
||||
template<typename CMap>
|
||||
struct My_functor_display_one_attrib_lcc<CMap, 0, void>
|
||||
{
|
||||
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<<"("<<it_attrib->point()<<") ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
template<typename CMap, typename Info>
|
||||
struct My_functor_display_one_attrib_lcc<CMap, 0, Info>
|
||||
{
|
||||
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<<"("<<it_attrib->point()<<" "<<it_attrib->info()<<") ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename CMap>
|
||||
struct My_functor_display_attrib_lcc
|
||||
{
|
||||
template <unsigned int i>
|
||||
static void run(const CMap& amap)
|
||||
{ My_functor_display_one_attrib_lcc<CMap, i>::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="<<amap.is_valid()<<std::endl;
|
||||
|
||||
CMap::Helper::template Foreach_enabled_attributes
|
||||
<My_functor_display_attrib_lcc<CMap> >::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<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, float> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
typedef CGAL::Combinatorial_map<3, MesAttributs1> CMap_3a;
|
||||
|
||||
bool example1(const char* filename)
|
||||
{
|
||||
std::cout<<"************** example 1 **************"<<std::endl;
|
||||
CMap_3a cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>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<<"["<<a.anint<<", "<<a.afloat<<"]"; }
|
||||
};
|
||||
|
||||
struct MesAttributs2
|
||||
{
|
||||
template < class CMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Dart<3, CMap> Dart;
|
||||
typedef CGAL::Cell_attribute<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, ACustomType> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> 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<CMap_3b::Dart_handle>
|
||||
(const boost::property_tree::ptree::value_type & v,
|
||||
CMap_3b::Dart_handle dh)
|
||||
{
|
||||
std::cout<<"Read dart "<<v.second.get<int>("myn")<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool example2(const char* filename)
|
||||
{
|
||||
std::cout<<"************** example 2 **************"<<std::endl;
|
||||
CMap_3b cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>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<<"["<<a.anint<<", "<<a.afloat<<"]"; }
|
||||
};
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template<>
|
||||
void read_cmap_attribute_node
|
||||
(const boost::property_tree::ptree::value_type &v,ACustomType2 &val)
|
||||
{
|
||||
val.anint = v.second.get<int>("v1");
|
||||
val.afloat = v.second.get<float>("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<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, ACustomType2> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
typedef CGAL::Combinatorial_map<3, MesAttributs3> CMap_3c;
|
||||
|
||||
bool example3(const char* filename)
|
||||
{
|
||||
std::cout<<"************** example 3 **************"<<std::endl;
|
||||
CMap_3c cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>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<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, int> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
typedef CGAL::Combinatorial_map<2, MesAttributs4> CMap_2;
|
||||
|
||||
bool example4(const char* filename)
|
||||
{
|
||||
std::cout<<"************** example 4 **************"<<std::endl;
|
||||
CMap_2 cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>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<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, ACustomType2> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
typedef CGAL::Combinatorial_map<5, MesAttributs5> CMap_5;
|
||||
|
||||
bool example5(const char* filename)
|
||||
{
|
||||
std::cout<<"************** example 5 **************"<<std::endl;
|
||||
CMap_5 cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>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 **************"<<std::endl;
|
||||
LCC_1 cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>cm;
|
||||
display_lcc(cm);
|
||||
return true;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* Configuration example 7
|
||||
Linear cell complex with attributes*/
|
||||
struct Myitem7
|
||||
{
|
||||
template<class Refs>
|
||||
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<Refs, int> T1;
|
||||
typedef CGAL::cpp0x::tuple<Vertex_attribute, T1> 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 **************"<<std::endl;
|
||||
LCC_2 cm;
|
||||
std::ifstream input(filename);
|
||||
if (!input) return false;
|
||||
input>>cm;
|
||||
display_lcc(cm);
|
||||
return true;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//==================================== main ====================================
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc!=2)
|
||||
{
|
||||
std::cout<<"Usage: a.out filename"<<std::endl
|
||||
<<" filename being an xml combinatorial map file.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ( !example1(argv[1]) || !example2(argv[1]) || !example3(argv[1]) ||
|
||||
!example4(argv[1]) || !example5(argv[1]) || !example6(argv[1]) ||
|
||||
!example7(argv[1]))
|
||||
{
|
||||
std::cout<<"Error reading "<<argv[1]<<std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -1,430 +0,0 @@
|
|||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <CGAL/Combinatorial_map.h>
|
||||
#include <CGAL/Combinatorial_map_constructors.h>
|
||||
#include <CGAL/Combinatorial_map_operations.h>
|
||||
#include <CGAL/Combinatorial_map_save_load.h>
|
||||
#include <CGAL/Cell_attribute.h>
|
||||
#include <CGAL/Linear_cell_complex.h>
|
||||
#include <CGAL/Linear_cell_complex_constructors.h>
|
||||
#include <CGAL/Linear_cell_complex_operations.h>
|
||||
#include <cstdlib>
|
||||
//******************************************************************************
|
||||
// Functor used to display all the attributes of a given dimension.
|
||||
template<typename CMap>
|
||||
struct My_functor_display_attrib
|
||||
{
|
||||
template <unsigned int i>
|
||||
static void run(const CMap& amap)
|
||||
{
|
||||
std::cout<<i<<"-attributes: ";
|
||||
|
||||
typename CMap::template Attribute_range<i>::type::const_iterator
|
||||
it_attrib = amap.template attributes<i>().begin(),
|
||||
itend_attrib = amap.template attributes<i>().end();
|
||||
|
||||
for (; it_attrib!=itend_attrib; ++it_attrib)
|
||||
{
|
||||
std::cout<<it_attrib->info()<<" ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
// Display the map, i.e. all its characteristics, then all its attributes.
|
||||
template < class CMap >
|
||||
void display_map(const CMap& amap)
|
||||
{
|
||||
amap.display_characteristics(std::cout)
|
||||
<<", valid="<<amap.is_valid()<<std::endl;
|
||||
|
||||
CMap::Helper::template Foreach_enabled_attributes
|
||||
<My_functor_display_attrib<CMap> >::run(amap);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// Functor used to display all the attributes of a given dimension.
|
||||
template<typename CMap, unsigned int i, typename Info=typename CMap::template Attribute_type<i>::type::Info>
|
||||
struct My_functor_display_one_attrib_lcc
|
||||
{
|
||||
static void run(const CMap& amap)
|
||||
{
|
||||
std::cout<<i<<"-attributes: ";
|
||||
|
||||
typename CMap::template Attribute_range<i>::type::const_iterator
|
||||
it_attrib = amap.template attributes<i>().begin(),
|
||||
itend_attrib = amap.template attributes<i>().end();
|
||||
|
||||
for (; it_attrib!=itend_attrib; ++it_attrib)
|
||||
{
|
||||
std::cout<<it_attrib->info()<<" ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
template<typename CMap, unsigned int i>
|
||||
struct My_functor_display_one_attrib_lcc<CMap, i, void>
|
||||
{
|
||||
static void run(const CMap& amap)
|
||||
{
|
||||
std::cout<<i<<"-attributes: ";
|
||||
|
||||
std::cout<<amap.template attributes<i>().size()<<" attributes without info."
|
||||
<<std::endl;
|
||||
}
|
||||
};
|
||||
template<typename CMap>
|
||||
struct My_functor_display_one_attrib_lcc<CMap, 0, void>
|
||||
{
|
||||
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<<"("<<it_attrib->point()<<") ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
template<typename CMap, typename Info>
|
||||
struct My_functor_display_one_attrib_lcc<CMap, 0, Info>
|
||||
{
|
||||
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<<"("<<it_attrib->point()<<" "<<it_attrib->info()<<") ";
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename CMap>
|
||||
struct My_functor_display_attrib_lcc
|
||||
{
|
||||
template <unsigned int i>
|
||||
static void run(const CMap& amap)
|
||||
{ My_functor_display_one_attrib_lcc<CMap, i>::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="<<amap.is_valid()<<std::endl;
|
||||
|
||||
CMap::Helper::template Foreach_enabled_attributes
|
||||
<My_functor_display_attrib_lcc<CMap> >::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<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, float> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> 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 **************"<<std::endl;
|
||||
display_map(cm);
|
||||
|
||||
// 3) save
|
||||
std::ofstream output("output_example_1.xml");
|
||||
output<<cm;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* Configuration example 2
|
||||
Map containing custom attributes, without overload write_cmap_attribute_node.
|
||||
In this case, custom attributes are not saved. */
|
||||
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<<"["<<a.anint<<", "<<a.afloat<<"]"; }
|
||||
};
|
||||
|
||||
struct MesAttributs2
|
||||
{
|
||||
template < class CMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Dart<3, CMap> Dart;
|
||||
typedef CGAL::Cell_attribute<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, ACustomType> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> 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 **************"<<std::endl;
|
||||
display_map(cm);
|
||||
|
||||
// 3) save
|
||||
std::ofstream output("output_example_2.xml");
|
||||
output<<cm;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* Configuration example 3
|
||||
Map containing custom attributes, and overloading write_cmap_attribute_node.
|
||||
Here custom attributes are also saved. */
|
||||
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<<"["<<a.anint<<", "<<a.afloat<<"]"; }
|
||||
};
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
// Definition of function allowing to save custon information.
|
||||
template<>
|
||||
void write_cmap_attribute_node<ACustomType2>(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<CMap, int> T1;
|
||||
typedef CGAL::Cell_attribute<CMap, ACustomType2> T2;
|
||||
typedef CGAL::cpp0x::tuple<void,T1,T2> 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 **************"<<std::endl;
|
||||
display_map(cm);
|
||||
|
||||
// 3) save
|
||||
std::ofstream output("output_example_3.xml");
|
||||
output<<cm;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* Configuration example 4
|
||||
Linear cell complex without attributes*/
|
||||
typedef CGAL::Linear_cell_complex<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 **************"<<std::endl;
|
||||
display_lcc(lcc);
|
||||
|
||||
// 3) save
|
||||
std::ofstream output("output_example_4.xml");
|
||||
output<<lcc;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* Configuration example 5
|
||||
Linear cell complex with attributes*/
|
||||
struct Myitem7
|
||||
{
|
||||
template<class Refs>
|
||||
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<Refs, int> T1;
|
||||
typedef CGAL::cpp0x::tuple<Vertex_attribute, T1> 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::endl;
|
||||
display_lcc(lcc);
|
||||
|
||||
// 3) save
|
||||
std::ofstream output("output_example_5.xml");
|
||||
output<<lcc;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//==================================== main ====================================
|
||||
int main()
|
||||
{
|
||||
example1();
|
||||
example2();
|
||||
example3();
|
||||
example4();
|
||||
example5();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -354,13 +354,13 @@ namespace CGAL {
|
|||
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.
|
||||
|
|
|
|||
|
|
@ -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."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::load(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
|
||||
|
||||
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 "<<qPrintable(fileName)<<": "
|
||||
<<timer.time()<<" seconds."<<std::endl;
|
||||
#endif
|
||||
|
||||
init_all_new_volumes();
|
||||
|
||||
this->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 "<<qPrintable(fileName)<<": "
|
||||
<<timer.time()<<" seconds."<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::load_off (const QString & fileName, bool clear)
|
||||
{
|
||||
QApplication::setOverrideCursor (Qt::WaitCursor);
|
||||
|
|
|
|||
|
|
@ -110,6 +110,8 @@ public:
|
|||
|
||||
public Q_SLOTS:
|
||||
// File menu
|
||||
void on_actionSave_triggered();
|
||||
void on_actionLoad_triggered();
|
||||
void on_actionImportOFF_triggered();
|
||||
void on_actionAddOFF_triggered();
|
||||
void on_actionImport3DTDS_triggered();
|
||||
|
|
@ -141,6 +143,9 @@ public Q_SLOTS:
|
|||
void on_actionExtend_hidden_volumes_triggered();
|
||||
|
||||
// Other slots
|
||||
void load_depend_on_extension(const QString& fileName, bool clear=true);
|
||||
void load(const QString& fileName, bool clear=true);
|
||||
void save(const QString& fileName);
|
||||
void load_off(const QString& fileName, bool clear=true);
|
||||
void load_3DTDS(const QString& fileName, bool clear=true);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,13 +33,16 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>635</width>
|
||||
<height>22</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="actionLoad"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionImportOFF"/>
|
||||
<addaction name="actionAddOFF"/>
|
||||
<addaction name="separator"/>
|
||||
|
|
@ -221,6 +224,16 @@
|
|||
<string>Create Sierpinski Triangle</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoad">
|
||||
<property name="text">
|
||||
<string>&Load</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="text">
|
||||
<string>&Save</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <CGAL/Linear_cell_complex_constructors.h>
|
||||
#include <CGAL/Linear_cell_complex_operations.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Combinatorial_map_save_load.h>
|
||||
|
||||
#include <CGAL/IO/Color.h>
|
||||
#include <CGAL/Timer.h>
|
||||
|
|
@ -45,6 +46,11 @@ extern CGAL::Random myrandom;
|
|||
|
||||
class Volume_info
|
||||
{
|
||||
friend void CGAL::read_cmap_attribute_node<Volume_info>
|
||||
(const boost::property_tree::ptree::value_type &v,Volume_info &val);
|
||||
|
||||
friend void CGAL::write_cmap_attribute_node<Volume_info>(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<Volume_info>
|
||||
(const boost::property_tree::ptree::value_type &v,Volume_info &val)
|
||||
{
|
||||
val.m_status = v.second.get<int>("status");
|
||||
char r = v.second.get<int>("color-r");
|
||||
char g = v.second.get<int>("color-g");
|
||||
char b = v.second.get<int>("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<Volume_info>(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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue