mirror of https://github.com/CGAL/cgal
Add a test for copy attributes for cmap/gmap, with and without indices.
This commit is contained in:
parent
52d78763d6
commit
46a35ff642
|
|
@ -1,67 +0,0 @@
|
|||
#include <CGAL/Combinatorial_map.h>
|
||||
#include <CGAL/Cell_attribute.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
struct MyInfo
|
||||
{
|
||||
MyInfo() :data(1)
|
||||
{}
|
||||
|
||||
MyInfo(int i) :data(i)
|
||||
{}
|
||||
|
||||
int data;
|
||||
};
|
||||
|
||||
struct Myitem1
|
||||
{
|
||||
using Use_index=CGAL::Tag_true; // use indices
|
||||
using Index_type=std::uint16_t; // 16 bits
|
||||
template<class CMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Cell_attribute<CMap, MyInfo> attrib;
|
||||
typedef std::tuple<attrib> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
struct Myitem2
|
||||
{
|
||||
template<class CMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Cell_attribute<CMap, MyInfo> attrib;
|
||||
typedef std::tuple<attrib> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
using CMap1=CGAL::Combinatorial_map<3,Myitem1>;
|
||||
using CMap2=CGAL::Combinatorial_map<3,Myitem2>;
|
||||
|
||||
#define NB 100
|
||||
int main()
|
||||
{
|
||||
CMap1 cm1;
|
||||
CMap2 cm2;
|
||||
|
||||
CMap1::Attribute_descriptor<0>::type a1=cm1.create_attribute<0>(2);
|
||||
for(std::size_t i=0; i<NB; ++i)
|
||||
{
|
||||
CMap1::Attribute_descriptor<0>::type a2=cm1.create_attribute<0>(cm1.info_of_attribute<0>(a1));
|
||||
if(cm1.info_of_attribute<0>(a1).data!=cm1.info_of_attribute<0>(a2).data)
|
||||
{ std::cout<<"ERROR1: "<<cm1.info_of_attribute<0>(a1).data<<" and "<<cm1.info_of_attribute<0>(a2).data<<" ("<<i<<")"<<std::endl; }
|
||||
}
|
||||
|
||||
CMap2::Attribute_descriptor<0>::type a3=cm2.create_attribute<0>(3);
|
||||
for(std::size_t i=0; i<NB; ++i)
|
||||
{
|
||||
CMap2::Attribute_descriptor<0>::type a4=cm2.create_attribute<0>(cm2.info_of_attribute<0>(a3));
|
||||
if(cm2.info_of_attribute<0>(a3).data!=cm2.info_of_attribute<0>(a4).data)
|
||||
{ std::cout<<"ERROR2: "<<cm2.info_of_attribute<0>(a3).data<<" and "<<cm2.info_of_attribute<0>(a4).data<<" ("<<i<<")"<<std::endl; }
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -24,6 +24,8 @@ target_compile_definitions(Combinatorial_map_copy_test_index PUBLIC USE_COMPACT_
|
|||
target_link_libraries(Combinatorial_map_copy_test_index PUBLIC CGAL CGAL::Data)
|
||||
cgal_add_compilation_test(Combinatorial_map_copy_test_index)
|
||||
|
||||
create_single_source_cgal_program(cmap_test_split_attribute.cpp)
|
||||
|
||||
# Link with OpenMesh if possible
|
||||
find_package(OpenMesh QUIET)
|
||||
if(TARGET OpenMesh::OpenMesh)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
#include <CGAL/Combinatorial_map.h>
|
||||
#include <CGAL/Cell_attribute.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
struct MyInfo
|
||||
{
|
||||
MyInfo() :data(1)
|
||||
{}
|
||||
|
||||
MyInfo(int i) :data(i)
|
||||
{}
|
||||
|
||||
int data;
|
||||
};
|
||||
|
||||
struct Myitem1
|
||||
{
|
||||
using Use_index=CGAL::Tag_true; // use indices
|
||||
using Index_type=std::uint16_t; // 16 bits
|
||||
template<class CMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Cell_attribute<CMap, MyInfo> attrib;
|
||||
typedef std::tuple<void, void, attrib> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
struct Myitem2
|
||||
{
|
||||
template<class CMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Cell_attribute<CMap, MyInfo> attrib;
|
||||
typedef std::tuple<void, void, attrib> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
using CMap1=CGAL::Combinatorial_map<3,Myitem1>;
|
||||
using CMap2=CGAL::Combinatorial_map<3,Myitem2>;
|
||||
|
||||
#define NB 1000
|
||||
template<typename CMap>
|
||||
bool test(const std::string& s)
|
||||
{
|
||||
bool res=true;
|
||||
CMap m;
|
||||
// 1) create a face and one attribute.
|
||||
typename CMap::Dart_descriptor dd=m.make_combinatorial_polygon(4);
|
||||
m.template set_attribute<2>(dd, m.template create_attribute<2>(2));
|
||||
// 2) Split this face NB times => will create new 2-attributes for new faces
|
||||
for(std::size_t i=0; i<NB; ++i)
|
||||
{
|
||||
typename CMap::Dart_descriptor
|
||||
newd=m.insert_cell_1_in_cell_2(dd, m.next(m.next(dd)));
|
||||
if(m.template attribute<2>(newd)==CMap::null_descriptor)
|
||||
{
|
||||
std::cout<<"ERROR1: "<<s<<": "
|
||||
<<"attribute<2>(newd)==CMap::null_descriptor"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
else if(m.template info<2>(newd).data!=2)
|
||||
{
|
||||
std::cout<<"ERROR2: "<<s<<": "<<m.template info<2>(newd).data<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
|
||||
newd=m.template opposite<2>(newd);
|
||||
if(m.template attribute<2>(newd)==CMap::null_descriptor)
|
||||
{
|
||||
std::cout<<"ERROR3: "<<s<<": "
|
||||
<<"attribute<2>(newd)==CMap::null_descriptor"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
else if(m.template info<2>(newd).data!=2)
|
||||
{
|
||||
std::cout<<"ERROR4: "<<s<<": "<<m.template info<2>(newd).data<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if(!test<CMap1>("CMap1") || !test<CMap2>("CMap2"))
|
||||
{ return EXIT_FAILURE; }
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -18,3 +18,5 @@ add_executable(Generalized_map_test_index Generalized_map_test.cpp ${hfiles})
|
|||
target_compile_definitions(Generalized_map_test_index PUBLIC USE_COMPACT_CONTAINER_WITH_INDEX)
|
||||
target_link_libraries(Generalized_map_test_index PUBLIC CGAL CGAL::Data)
|
||||
cgal_add_compilation_test(Generalized_map_test_index)
|
||||
|
||||
create_single_source_cgal_program("gmap_test_split_attribute.cpp")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
#include <CGAL/Generalized_map.h>
|
||||
#include <CGAL/Cell_attribute.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
struct MyInfo
|
||||
{
|
||||
MyInfo() :data(1)
|
||||
{}
|
||||
|
||||
MyInfo(int i) :data(i)
|
||||
{}
|
||||
|
||||
int data;
|
||||
};
|
||||
|
||||
struct Myitem1
|
||||
{
|
||||
using Use_index=CGAL::Tag_true; // use indices
|
||||
using Index_type=std::uint16_t; // 16 bits
|
||||
template<class GMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Cell_attribute<GMap, MyInfo> attrib;
|
||||
typedef std::tuple<void, void, attrib> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
struct Myitem2
|
||||
{
|
||||
template<class GMap>
|
||||
struct Dart_wrapper
|
||||
{
|
||||
typedef CGAL::Cell_attribute<GMap, MyInfo> attrib;
|
||||
typedef std::tuple<void, void, attrib> Attributes;
|
||||
};
|
||||
};
|
||||
|
||||
using GMap1=CGAL::Generalized_map<3,Myitem1>;
|
||||
using GMap2=CGAL::Generalized_map<3,Myitem2>;
|
||||
|
||||
#define NB 1000
|
||||
template<typename GMap>
|
||||
bool test(const std::string& s)
|
||||
{
|
||||
bool res=true;
|
||||
GMap m;
|
||||
// 1) create a face and one attribute.
|
||||
typename GMap::Dart_descriptor dd=m.make_combinatorial_polygon(4);
|
||||
m.template set_attribute<2>(dd, m.template create_attribute<2>(2));
|
||||
// 2) Split this face NB times => will create new 2-attributes for new faces
|
||||
for(std::size_t i=0; i<NB; ++i)
|
||||
{
|
||||
typename GMap::Dart_descriptor
|
||||
newd=m.insert_cell_1_in_cell_2(dd, m.template alpha<0,1,0>(dd));
|
||||
if(m.template attribute<2>(newd)==GMap::null_descriptor)
|
||||
{
|
||||
std::cout<<"ERROR1: "<<s<<": "
|
||||
<<"attribute<2>(newd)==GMap::null_descriptor"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
else if(m.template info<2>(newd).data!=2)
|
||||
{
|
||||
std::cout<<"ERROR2: "<<s<<": "<<m.template info<2>(newd).data<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
|
||||
newd=m.template opposite<2>(newd);
|
||||
if(m.template attribute<2>(newd)==GMap::null_descriptor)
|
||||
{
|
||||
std::cout<<"ERROR3: "<<s<<": "
|
||||
<<"attribute<2>(newd)==GMap::null_descriptor"<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
else if(m.template info<2>(newd).data!=2)
|
||||
{
|
||||
std::cout<<"ERROR4: "<<s<<": "<<m.template info<2>(newd).data<<std::endl;
|
||||
res=false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if(!test<GMap1>("GMap1") || !test<GMap2>("GMap2"))
|
||||
{ return EXIT_FAILURE; }
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Reference in New Issue