Geogram  Version 1.9.1
A programming library of geometric algorithms
intersect_tools.h
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef H_HEXDOM_ALGO_INTERSECT_TOOLS_H
41 #define H_HEXDOM_ALGO_INTERSECT_TOOLS_H
42 
44 #include <exploragram/hexdom/basic.h>
45 #include <geogram/mesh/mesh.h>
46 namespace GEO {
47 
48  extern const index_t EXPLORAGRAM_API quad_rand_split[2][3];
49  extern const index_t EXPLORAGRAM_API quad_split[4][3];
50  extern const index_t EXPLORAGRAM_API diamon_split[12][3];
51  extern const index_t EXPLORAGRAM_API diamon_quad_split[16][3];
52 
53 
54 
56  BBox() {
57  min = vec3(1e20, 1e20, 1e20);
58  max = vec3(-1e20, -1e20, -1e20);
59  }
60 
61  bool intersect(const BBox& b) const;
62  bool contains(const vec3& v) const;
63  bool is_null() const;
64  void add(const BBox& b);
65  void add(const vec3& P);
66  void dilate(double eps) {
67  min -= vec3(eps, eps, eps);
68  max += vec3(eps, eps, eps);
69  }
70  vec3 bary() const;
71 
72  vec3 min;
73  vec3 max;
74  };
75 
77  HBoxes() {
78  }
79 
80  HBoxes(vector<BBox>& inboxes) {
81  init(inboxes);
82  }
83 
84  void init(vector<BBox>& inboxes);
85 
86  ~HBoxes() {
87  }
88 
89  void sort(vector<vec3> &G, index_t org, index_t dest);
90  void intersect(BBox& b, vector<index_t>& primitives, index_t node = 0);
91 
92  int STAT_nb_visits;
93  int STAT_nb_leafs;
94  int STAT_nb_requests;
95 
96  index_t offset;
97  vector<index_t> tree_pos_to_org;
98  vector<BBox> tree;
99  };
100 
101 
103  void init(vector<BBox>& inboxes);
104 
105  void intersect(BBox& b, vector<index_t>& primitives);
106 
107  void update_bbox(index_t id, BBox b = BBox());
108 
109  HBoxes hbox;
110  vector<index_t> moved;
111  vector<BBox> movedbbox;
112  };
113 
114 
115 
116  // double tetra_volume(vec3 A, vec3 B, vec3 C, vec3 D);
117  double tetra_volume_sign(vec3 A, vec3 B, vec3 C, vec3 D);
118  bool same_sign(double a, double b);
119 
120  //bool naive_tri_tri_intersect(vec3 v0, vec3 v1, vec3 v2, vec3 u0, vec3 u1, vec3 u2);
121 
122  vector<BBox> facets_bbox(Mesh* m);
123  struct FacetIntersect {
124  FacetIntersect(Mesh* p_m);
125  vector<index_t> get_intersections(vector<vec3>& P);
126  vector<index_t> get_intersections(index_t& f);
127  vector<BBox> inboxes;
128  DynamicHBoxes hb;
129  Mesh* m;
130  };
131 
132 
133  bool polyintersect(vector<vec3>& P, vector<vec3>& Q);
134  vector<index_t> get_intersecting_faces(Mesh* m);
135  void check_no_intersecting_faces(Mesh* m,bool allow_duplicated = false);
136 }
137 #endif
Represents a mesh.
Definition: mesh.h:2701
Vector with aligned memory allocation.
Definition: memory.h:635
#define EXPLORAGRAM_API
Linkage declaration for exploragram symbols.
Definition: defs.h:18
Included by all headers in exploragram.
The class that represents a mesh.
Global Vorpaline namespace.
Definition: basic.h:55
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition: geometry.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
void sort(const ITERATOR &begin, const ITERATOR &end)
Sorts elements in parallel.
Definition: algorithm.h:90