Fermat
bbox.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2018, NVIDIA Corporation
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  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
32 #pragma once
33 
34 #ifdef min
35 #undef min
36 #endif
37 #ifdef max
38 #unded max
39 #endif
40 
41 #include <cugar/basic/numbers.h>
42 #include <cugar/linalg/vector.h>
43 #include <limits>
44 #include <algorithm>
45 
46 namespace cugar {
47 
50 
54 
58 template <typename Vector_t>
59 struct Bbox
60 {
61  typedef typename Vector_t::value_type value_type;
62  typedef typename Vector_t vector_type;
63 
66  CUGAR_HOST CUGAR_DEVICE Bbox();
67 
71  CUGAR_HOST CUGAR_DEVICE Bbox(
72  const Vector_t& v);
73 
78  CUGAR_HOST CUGAR_DEVICE Bbox(
79  const Vector_t& v1,
80  const Vector_t& v2);
81 
86  CUGAR_HOST CUGAR_DEVICE Bbox(
87  const Bbox<Vector_t>& bb1,
88  const Bbox<Vector_t>& bb2);
89 
93  CUGAR_HOST CUGAR_DEVICE Bbox(
94  const Bbox<Vector_t>& bb);
95 
99  CUGAR_HOST CUGAR_DEVICE void insert(const Vector_t& v);
100 
104  CUGAR_HOST CUGAR_DEVICE void insert(const Bbox& v);
105 
108  CUGAR_HOST CUGAR_DEVICE void clear();
109 
113  CUGAR_HOST CUGAR_DEVICE const Vector_t& operator[](const size_t i) const { return (&m_min)[i]; }
114 
118  CUGAR_HOST CUGAR_DEVICE Vector_t& operator[](const size_t i) { return (&m_min)[i]; }
119 
123  CUGAR_HOST CUGAR_DEVICE Bbox<Vector_t>& operator=(const Bbox<Vector_t>& bb);
124 
125  Vector_t m_min;
126  Vector_t m_max;
127 };
128 
129 typedef Bbox<Vector2f> Bbox2f;
130 typedef Bbox<Vector3f> Bbox3f;
131 typedef Bbox<Vector4f> Bbox4f;
132 typedef Bbox<Vector2d> Bbox2d;
133 typedef Bbox<Vector3d> Bbox3d;
134 typedef Bbox<Vector4d> Bbox4d;
135 typedef Bbox<Vector2i> Bbox2i;
136 typedef Bbox<Vector3i> Bbox3i;
137 typedef Bbox<Vector4i> Bbox4i;
138 typedef Bbox<Vector2u> Bbox2u;
139 typedef Bbox<Vector3u> Bbox3u;
140 typedef Bbox<Vector4u> Bbox4u;
141 
145 inline CUGAR_HOST_DEVICE float area(const Bbox2f& bbox);
146 
150 inline CUGAR_HOST_DEVICE float area(const Bbox3f& bbox);
151 
156 template <typename Vector_t>
157 inline CUGAR_HOST_DEVICE bool contains(const Bbox<Vector_t>& bbox, const Vector_t& p);
158 
163 template <typename Vector_t>
164 inline CUGAR_HOST_DEVICE bool contains(const Bbox<Vector_t>& bbox, const Bbox<Vector_t>& candidate);
165 
170 template <typename Vector_t>
171 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE float sq_distance(const Bbox<Vector_t>& bbox, const Vector_t& p);
172 
176 template <typename Vector_t>
177 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE size_t largest_axis(const Bbox<Vector_t>& bbox);
178 
182 template <typename Vector_t>
183 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector_t extents(const Bbox<Vector_t>& bbox);
184 
187 template <uint32 DIM>
189 {
192  typedef bbox_type argument_type;
193  typedef float result_type;
194 
195  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
196  result_type operator() (const bbox_type& bbox) const { return area(bbox); }
197 };
198 
201 
202 } // namespace cugar
203 
204 #include <cugar/linalg/bbox_inline.h>
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE float sq_distance(const Bbox< Vector_t > &bbox, const Vector_t &p)
Definition: bbox_inline.h:186
Vector_t m_max
max corner
Definition: bbox.h:126
CUGAR_HOST CUGAR_DEVICE void clear()
Definition: bbox_inline.h:85
CUGAR_HOST_DEVICE bool contains(const Bbox< Vector_t > &bbox, const Vector_t &p)
Definition: bbox_inline.h:154
CUGAR_HOST CUGAR_DEVICE Vector_t & operator[](const size_t i)
Definition: bbox.h:118
CUGAR_HOST CUGAR_DEVICE Bbox< Vector_t > & operator=(const Bbox< Vector_t > &bb)
Definition: bbox_inline.h:95
Definition: bbox.h:59
CUGAR_HOST CUGAR_DEVICE const Vector_t & operator[](const size_t i) const
Definition: bbox.h:113
Definition: vector.h:54
Vector_t m_min
min corner
Definition: bbox.h:125
Definition: bbox.h:188
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE size_t largest_axis(const Bbox< Vector_t > &bbox)
Definition: bbox_inline.h:103
CUGAR_HOST_DEVICE float area(const Bbox2f &bbox)
Definition: bbox_inline.h:134
CUGAR_HOST CUGAR_DEVICE Bbox()
Definition: bbox_inline.h:31
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector_t extents(const Bbox< Vector_t > &bbox)
Definition: bbox_inline.h:126
CUGAR_HOST CUGAR_DEVICE void insert(const Vector_t &v)
Definition: bbox_inline.h:65