mirror of https://github.com/CGAL/cgal
Example for map with index
This commit is contained in:
parent
9b44e0ae66
commit
f53c61a6e5
|
|
@ -1,7 +1,8 @@
|
|||
#include <CGAL/Combinatorial_map.h>
|
||||
#include <CGAL/Cell_attribute.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
struct Myitem
|
||||
|
|
@ -11,68 +12,43 @@ struct Myitem
|
|||
template<class CMap>
|
||||
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 CGAL::Combinatorial_map<3,Myitem> CMap_3;
|
||||
typedef CMap_3::Dart_descriptor Dart_descriptor;
|
||||
using CMap_3=CGAL::Combinatorial_map<3,Myitem>;
|
||||
using Dart_descriptor=CMap_3::Dart_descriptor;
|
||||
|
||||
int main()
|
||||
{
|
||||
CMap_3 cm;
|
||||
|
||||
// Create 2 hexahedra.
|
||||
Dart_descriptor d1 = cm.make_combinatorial_hexahedron();
|
||||
Dart_descriptor d2 = cm.make_combinatorial_hexahedron();
|
||||
Dart_descriptor d1=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.
|
||||
for (CMap_3::Dart_range::iterator
|
||||
it=cm.darts().begin(), itend=cm.darts().end();
|
||||
it!=itend; ++it)
|
||||
{
|
||||
if ( cm.attribute<2>(it)==CMap_3::null_descriptor )
|
||||
cm.set_attribute<2>(it, cm.create_attribute<2>());
|
||||
}
|
||||
// Create two 3-attributes and associated them to darts.
|
||||
cm.set_attribute<3>(d1, cm.create_attribute<3>());
|
||||
cm.set_attribute<3>(d2, cm.create_attribute<3>());
|
||||
|
||||
// 2) Set the color of all facets of the first hexahedron to 7.
|
||||
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator
|
||||
it=cm.one_dart_per_incident_cell<2,3>(d1).begin(),
|
||||
itend=cm.one_dart_per_incident_cell<2,3>(d1).end(); it!=itend; ++it)
|
||||
{ cm.info<2>(it)=7; }
|
||||
// Associate a vector of size_t to darts
|
||||
std::vector<std::size_t> array_for_darts(cm.upper_bound_on_dart_ids());
|
||||
std::generate(array_for_darts.begin(), array_for_darts.end(), std::rand);
|
||||
|
||||
// 3) Set the color of all facets of the second hexahedron to 13.
|
||||
for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator it=
|
||||
cm.one_dart_per_incident_cell<2,3>(d2).begin(),
|
||||
itend=cm.one_dart_per_incident_cell<2,3>(d2).end(); it!=itend; ++it)
|
||||
{ cm.info<2>(it)=13; }
|
||||
// Associate a vector of string to 3-attributes
|
||||
std::vector<std::string> array_for_vols(cm.upper_bound_on_attribute_ids<3>());
|
||||
std::size_t i=0;
|
||||
for(auto& e: array_for_vols)
|
||||
{ e="vol"+std::to_string(i++); }
|
||||
|
||||
// 4) 3-Sew the two hexahedra along one facet.
|
||||
cm.sew<3>(d1, d2);
|
||||
std::cout<<"Value in array for darts d1 and d2: "
|
||||
<<array_for_darts[d1]<<" and "<<array_for_darts[d2]<<std::endl;
|
||||
|
||||
// 5) 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;
|
||||
|
||||
// 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;
|
||||
std::cout<<"Value in array for volumes of dart d1 and d2: "
|
||||
<<array_for_vols[cm.attribute<3>(d1)]<<" and "
|
||||
<<array_for_vols[cm.attribute<3>(d2)]<<std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue