Example for map with index

This commit is contained in:
Guillaume Damiand 2022-06-27 14:22:07 +02:00
parent 9b44e0ae66
commit f53c61a6e5
1 changed files with 26 additions and 50 deletions

View File

@ -1,7 +1,8 @@
#include <CGAL/Combinatorial_map.h> #include <CGAL/Combinatorial_map.h>
#include <CGAL/Cell_attribute.h> #include <CGAL/Cell_attribute.h>
#include <iostream> #include <vector>
#include <algorithm> #include <algorithm>
#include <string>
#include <cstdlib> #include <cstdlib>
struct Myitem struct Myitem
@ -11,13 +12,13 @@ struct Myitem
template<class CMap> template<class CMap>
struct Dart_wrapper struct Dart_wrapper
{ {
typedef CGAL::Cell_attribute<CMap, int> Vol_attrib; typedef CGAL::Cell_attribute<CMap> Vol_attrib;
typedef std::tuple<void,void,void,Vol_attrib> Attributes; typedef std::tuple<void,void,void,Vol_attrib> Attributes;
}; };
}; };
typedef CGAL::Combinatorial_map<3,Myitem> CMap_3; using CMap_3=CGAL::Combinatorial_map<3,Myitem>;
typedef CMap_3::Dart_descriptor Dart_descriptor; using Dart_descriptor=CMap_3::Dart_descriptor;
int main() int main()
{ {
@ -26,53 +27,28 @@ int main()
// Create 2 hexahedra. // Create 2 hexahedra.
Dart_descriptor d1=cm.make_combinatorial_hexahedron(); Dart_descriptor d1=cm.make_combinatorial_hexahedron();
Dart_descriptor d2=cm.make_combinatorial_hexahedron(); Dart_descriptor d2=cm.make_combinatorial_hexahedron();
cm.sew<3>(d1, d2); // 3-Sew the two hexahedra along one facet.
// 1) Create all 2-attributes and associated them to darts. // Create two 3-attributes and associated them to darts.
for (CMap_3::Dart_range::iterator cm.set_attribute<3>(d1, cm.create_attribute<3>());
it=cm.darts().begin(), itend=cm.darts().end(); cm.set_attribute<3>(d2, cm.create_attribute<3>());
it!=itend; ++it)
{
if ( cm.attribute<2>(it)==CMap_3::null_descriptor )
cm.set_attribute<2>(it, cm.create_attribute<2>());
}
// 2) Set the color of all facets of the first hexahedron to 7. // Associate a vector of size_t to darts
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator std::vector<std::size_t> array_for_darts(cm.upper_bound_on_dart_ids());
it=cm.one_dart_per_incident_cell<2,3>(d1).begin(), std::generate(array_for_darts.begin(), array_for_darts.end(), std::rand);
itend=cm.one_dart_per_incident_cell<2,3>(d1).end(); it!=itend; ++it)
{ cm.info<2>(it)=7; }
// 3) Set the color of all facets of the second hexahedron to 13. // Associate a vector of string to 3-attributes
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator it= std::vector<std::string> array_for_vols(cm.upper_bound_on_attribute_ids<3>());
cm.one_dart_per_incident_cell<2,3>(d2).begin(), std::size_t i=0;
itend=cm.one_dart_per_incident_cell<2,3>(d2).end(); it!=itend; ++it) for(auto& e: array_for_vols)
{ cm.info<2>(it)=13; } { e="vol"+std::to_string(i++); }
// 4) 3-Sew the two hexahedra along one facet. std::cout<<"Value in array for darts d1 and d2: "
cm.sew<3>(d1, d2); <<array_for_darts[d1]<<" and "<<array_for_darts[d2]<<std::endl;
// 5) Display all the values of 2-attributes. std::cout<<"Value in array for volumes of dart d1 and d2: "
for (CMap_3::Attribute_range<2>::type::iterator <<array_for_vols[cm.attribute<3>(d1)]<<" and "
it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end(); <<array_for_vols[cm.attribute<3>(d2)]<<std::endl;
it!=itend; ++it)
{
std::cout<<cm.info_of_attribute<2>(it)<<"; ";
}
std::cout<<std::endl;
// 6) Insert a vertex in the facet between the two hexahedra.
cm.insert_cell_0_in_cell_2(d2);
// 7) Display all the values of 2-attributes.
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;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }