#include <CGAL/Combinatorial_map.h>
#include <CGAL/Combinatorial_map_constructors.h>
#include <CGAL/Combinatorial_map_operations.h>
#include <CGAL/Cell_attribute.h>
#include <iostream>
#include <cstdlib>
struct Myitem
{
template<class CMap>
struct Dart_wrapper
{
};
};
typedef CMap_3::Dart_handle Dart_handle;
typedef CMap_3::Attribute_type<2>::type Face_attribute;
struct Merge_functor
{
void operator()(Face_attribute& ca1, Face_attribute& ca2)
{
ca1.info()=ca1.info()+ca2.info();
std::cout<<"After on merge faces: info of face1="<<ca1.info()
<<", info of face2="<<ca2.info()<<std::endl;
}
};
struct Split_functor
{
Split_functor(CMap_3& amap) : mmap(amap)
{}
void operator()(Face_attribute& ca1, Face_attribute& ca2)
{
set_color_of_face(ca1.dart());
set_color_of_face(ca2.dart());
std::cout<<"After on split faces: info of face1="<<ca1.info()
<<", info of face2="<<ca2.info()<<std::endl;
}
private:
void set_color_of_face(CMap_3::Dart_handle dh)
{
int nb=0;
int sum=0;
for (CMap_3::Dart_of_orbit_range<1>::iterator
it=mmap.darts_of_orbit<1>(dh).begin(),
itend=mmap.darts_of_orbit<1>(dh).end();
it!=itend; ++it, ++nb)
{ sum+=mmap.info<2>(mmap.beta<2>(it)); }
mmap.info<2>(dh)=(sum/nb);
}
CMap_3& mmap;
};
void display_map_and_2attributes(CMap_3& cm)
{
for (CMap_3::Attribute_range<2>::type::iterator
it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end();
it!=itend; ++it)
{
std::cout<<cm.info_of_attribute<2>(it)<<"; ";
}
std::cout<<std::endl;
cm.display_characteristics(std::cout);
std::cout<<", valid="<<cm.is_valid()<<std::endl;
}
int main()
{
CMap_3 cm;
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator
it=cm.one_dart_per_incident_cell<2,3>(dh1).begin(),
itend=cm.one_dart_per_incident_cell<2,3>(dh1).end(); it!=itend; ++it)
{ cm.set_attribute<2>(it, cm.create_attribute<2>(7)); }
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator it=
cm.one_dart_per_incident_cell<2,3>(dh2).begin(),
itend=cm.one_dart_per_incident_cell<2,3>(dh2).end(); it!=itend; ++it)
{ cm.set_attribute<2>(it, cm.create_attribute<2>(13)); }
cm.onsplit_functor<2>()=Split_functor(cm);
cm.onmerge_functor<2>()=Merge_functor();
cm.sew<3>(dh1, dh2);
display_map_and_2attributes(cm);
display_map_and_2attributes(cm);
cm.onmerge_functor<2>()=boost::function<void(Face_attribute&,
Face_attribute&)>();
CGAL::remove_cell<CMap_3, 1>(cm, resdart);
display_map_and_2attributes(cm);
return EXIT_SUCCESS;
}