Goosefoot Mesher - CGAL
implicit_zone_function.h
1 #ifndef IMPLICIT_ZONE_FUNCTION_H
2 #define IMPLICIT_ZONE_FUNCTION_H
3 
4 #include "mesher_cgal.h"
5 
6 #include <CGAL/Side_of_triangle_mesh.h>
7 typedef CGAL::Side_of_triangle_mesh<Polyhedron,K> Side_of_triangle_mesh;
8 
9 #include <CGAL/AABB_tree.h>
10 #include <CGAL/AABB_traits.h>
11 #include <CGAL/AABB_face_graph_triangle_primitive.h>
12 
13 typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
14 typedef CGAL::AABB_traits<K, Primitive> Traits;
15 typedef CGAL::AABB_tree<Traits> Tree;
16 
17 namespace mesherCGAL {
18  typedef std::vector< std::unique_ptr<Zone> > zones_vec;
19 
20  template<typename K >
22  {
23  public:
24  typedef int return_type;
25  typedef typename K::Point_3 Point_3;
26  typedef typename K::FT FT;
27  typedef typename std::vector< std::pair<int, Side_of_triangle_mesh*> > pip_vector;
28 
30  region_ip_map& region_ips,
31  const Point_3* centre,
32  float radius,
33  bool use_organ,
34  int organ_id,
35  bool use_extent,
36  int extent_id,
37  std::vector<int>& vessels,
38  std::vector<int>& needles,
39  zones_vec& zones,
40  int default_zone=1
41  ) : zones_(zones), default_zone_(default_zone), use_organ_(use_organ), organ_id_(organ_id), use_extent_(use_extent), extent_id_(extent_id)
42  {
43  Polyhedron* organ = NULL;
44  organ_pip_ = NULL;
45  radius_ = radius;
46  centre_ = centre;
47 
48  extent_tree_ = new Tree();
49 
50  if (use_organ) {
51  organ = new Polyhedron(*region_ips[organ_id]);
52  extent_tree_->insert(organ->facets_begin(), organ->facets_end(), *organ);
53  organ_pip_= new Side_of_triangle_mesh(*organ);
54  }
55 
56  extent_tree_->accelerate_distance_queries();
57 
58  BOOST_FOREACH(std::vector<int>::value_type& id, vessels) {
59  Tree* tree = new Tree(region_ips[id]->facets_begin(), region_ips[id]->facets_end(), *region_ips[id]);
60  tree->accelerate_distance_queries();
61  trees_.push_back(tree);
62  vessels_pip_.push_back(std::pair<int, Side_of_triangle_mesh*>(id, new Side_of_triangle_mesh(*region_ips[id])));
63  }
64 
65  BOOST_FOREACH(std::vector<int>::value_type& id, needles) {
66  Tree* tree = new Tree(region_ips[id]->facets_begin(), region_ips[id]->facets_end(), *region_ips[id]);
67  tree->accelerate_distance_queries();
68  trees_.push_back(tree);
69  needles_pip_.push_back(std::pair<int, Side_of_triangle_mesh*>(id, new Side_of_triangle_mesh(*region_ips[id])));
70  }
71  }
72 
74  {
75  }
76 
77  return_type signed_domain(const Point_3& p, const bool = true) const
78  {
79  int zone = default_zone_;
80 
81  if (CGAL::squared_distance(*centre_, p) > radius_ * radius_)
82  return extent_id_ == 0 ? 0 : -extent_id_;
83 
84  if (organ_pip_ != NULL) {
85  if ((*organ_pip_)(p) == CGAL::ON_UNBOUNDED_SIDE)
86  return organ_id_ == 0 ? -1000 : -organ_id_; //FIXME: replace with something sensible (for when default_zone==0)
87  else
88  zone = organ_id_;
89  }
90 
91  BOOST_FOREACH(const pip_vector::value_type& pip, vessels_pip_) {
92  if ((*pip.second)(p) == CGAL::ON_BOUNDED_SIDE)
93  return -pip.first;
94  }
95  BOOST_FOREACH(const pip_vector::value_type& pip, needles_pip_) {
96  if ((*pip.second)(p) == CGAL::ON_BOUNDED_SIDE)
97  return -pip.first;
98  }
99 
100  for (auto&& z : zones_) {
101  if (z->contains(p) != 0) {
102  zone = z->get_id();
103 
104  if (zone > 0 && default_zone_ == 0)
105  zone += 1;
106 
107  return zone;
108  }
109  }
110  if (default_zone_ == 0)
111  zone += 1;
112 
113  return zone;
114  }
115 
116  return_type operator()(const Point_3& p, const bool = true) const
117  {
118  return_type i = signed_domain(p);
119  return i;
120  //return i < 0 ? 0 : i;
121  }
122 
123  protected:
124  zones_vec& zones_;
125  int default_zone_;
126  bool use_organ_;
127  int organ_id_;
128  bool use_extent_;
129  int extent_id_;
130 
131  const Point_3* centre_;
132  float radius_;
133  Tree *extent_tree_;
134  std::vector<Tree*> trees_;
135  Side_of_triangle_mesh *extent_pip_, *organ_pip_;
136  pip_vector vessels_pip_, needles_pip_;
137  };
138 }
139 
140 #endif
Definition: implicit_zone_function.h:21
Definition: implicit_zone_function.h:17