#include <CGAL/Generalized_map.h>
#include <CGAL/Cell_attribute.h>
#include <iostream>
#include <cstdlib>
struct Myitem
{
template<class GMap>
struct Dart_wrapper
{
typedef std::tuple<void,void,Face_attribute> Attributes;
};
};
typedef GMap_3::Dart_descriptor Dart_descriptor;
typedef GMap_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(GMap_3& amap) : mmap(amap)
{}
void operator()(Face_attribute& ca1, Face_attribute& ca2)
{
GMap_3::size_type nb1=mmap.darts_of_cell<2>(ca1.dart()).size();
GMap_3::size_type nb2=mmap.darts_of_cell<2>(ca2.dart()).size();
mmap.info<2>(ca1.dart())*=(double(nb1)/(nb1+nb2));
mmap.info<2>(ca2.dart())*=(double(nb2)/(nb1+nb2));
std::cout<<"After on split faces: info of face1="<<ca1.info()
<<", info of face2="<<ca2.info()<<std::endl;
}
private:
GMap_3& mmap;
};
void display_map_and_2attributes(GMap_3& gm)
{
for (GMap_3::Attribute_range<2>::type::iterator
it=gm.attributes<2>().begin(), itend=gm.attributes<2>().end();
it!=itend; ++it)
{ std::cout<<gm.info_of_attribute<2>(it)<<"; "; }
std::cout<<std::endl;
gm.display_characteristics(std::cout);
std::cout<<", valid="<<gm.is_valid()<<std::endl;
}
int main()
{
GMap_3 gm;
Dart_descriptor d1 = gm.make_combinatorial_hexahedron();
Dart_descriptor d2 = gm.make_combinatorial_hexahedron();
for (GMap_3::One_dart_per_cell_range<2>::iterator
it=gm.one_dart_per_cell<2>().begin(),
itend=gm.one_dart_per_cell<2>().end(); it!=itend; ++it)
{
gm.set_attribute<2>(it, gm.create_attribute<2>(1));
}
gm.onsplit_functor<2>()=Split_functor(gm);
gm.onmerge_functor<2>()=Merge_functor();
gm.sew<3>(d1, d2);
display_map_and_2attributes(gm);
Dart_descriptor resdart=gm.insert_cell_0_in_cell_2(d2);
display_map_and_2attributes(gm);
gm.onmerge_functor<2>()=boost::function<void(Face_attribute&,
Face_attribute&)>();
gm.remove_cell<1>(resdart);
display_map_and_2attributes(gm);
return EXIT_SUCCESS;
}