Point metadata #6940
-
Hi, I am a first time user of CGAL. It's already speeding up some important calculations, so I'm excited to keep using it! What I need to do is to add some metadata (fields that don't affect geometric computations) to my Simple_cartesian::Point_2 objects. Is there an easy way to do this? Thanks! Ilya |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
You can create a map from some kernel objects to your data, or do something like: #include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/Color.h>
using K = CGAL::Simple_cartesian<double>;
using Point_2 = K::Point_2;
struct Point_with_color
{
Point_with_color(const Point_2& p) : p(p), c(CGAL::IO::white()) { }
Point_with_color(const Point_2& p, const CGAL::IO::Color& c) : p(p), c(c) { }
// Conversion to Point_2
operator const Point_2&() const { return p; }
Point_2 p;
CGAL::IO::Color c;
};
int main()
{
K k;
Point_2 bp0(0,0), bp1(1,0), bp2(1,1);
Point_with_color p0(bp0, CGAL::IO::red());
Point_with_color p1(bp1, CGAL::IO::green());
Point_with_color p2(bp2, CGAL::IO::blue());
std::cout << "Are these points collinear? " << k.collinear_2_object()(p0, p1, p2) << std::endl;
Point_with_color cc = k.construct_circumcenter_2_object()(p0, p1, p2);
std::cout << "Circumcenter at pos: " << cc.p << " and color " << cc.c << std::endl;
return 0;
} Also, if you are using some specific data structures, there might also be more natural ways to associate extra information to your elements (such as Triangulation_vertex_base_with_info_2). |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestion @MaelRL! I intend to use these modified Point objects in a kd tree and then perform a range search with a fuzzy_sphere object. The code below seems to be convert the Point_with_index object back into a Point_2 object during the search, removing the additional meta data from the point. Do you have a suggestion for how to define fuzzy_sphere in a way that keeps the Point_with_index object intact?
|
Beta Was this translation helpful? Give feedback.
-
@MaelRL, I also tried out the solution with mapping from Kernel objects to my data. If I understand correctly, the idea is to map from each Point_2 object's memory address to my data. Here, I'm having trouble because the Point_2 object seems to get copied (rather than assigned by reference) during node insertion into the tree and into the output iterator during each search through the tree. Is this copying something that can be easily avoided? I really appreciate your help with this! |
Beta Was this translation helpful? Give feedback.
-
You can use something like this example: https://doc.cgal.org/latest/Spatial_searching/Spatial_searching_2searching_with_point_with_info_inplace_8cpp-example.html |
Beta Was this translation helpful? Give feedback.
-
Perfect, thank you! |
Beta Was this translation helpful? Give feedback.
You can use something like this example: https://doc.cgal.org/latest/Spatial_searching/Spatial_searching_2searching_with_point_with_info_inplace_8cpp-example.html