15 #include <BoundingBox.hpp>
18 #include <cuda/CudaGlobal.hpp>
33 typedef unsigned char ubyte;
34 typedef unsigned int uint;
35 typedef unsigned short ushort;
36 typedef unsigned long ulong;
38 typedef util::Vector<2, float> Point2f;
39 typedef util::Vector<3, float> Point3f;
40 typedef util::Vector<4, float> Point4f;
41 typedef util::Vector<5, float> Point5f;
42 typedef util::Vector<6, float> Point6f;
43 typedef util::Vector<12, float> Point12f;
45 typedef util::Vector<2, double> Point2d;
46 typedef util::Vector<3, double> Point3d;
47 typedef util::Vector<4, double> Point4d;
48 typedef util::Vector<5, double> Point5d;
49 typedef util::Vector<6, double> Point6d;
50 typedef util::Vector<16, double> Point16d;
52 typedef util::Vector<2, int> Point2i;
53 typedef util::Vector<3, int> Point3i;
54 typedef util::Vector<4, int> Point4i;
55 typedef util::Vector<5, int> Point5i;
56 typedef util::Vector<6, int> Point6i;
58 typedef util::Vector<2, uint> Point2u;
59 typedef util::Vector<3, uint> Point3u;
60 typedef util::Vector<4, uint> Point4u;
61 typedef util::Vector<5, uint> Point5u;
62 typedef util::Vector<6, uint> Point6u;
64 typedef util::Vector<2, size_t> Point2s;
65 typedef util::Vector<3, size_t> Point3s;
66 typedef util::Vector<4, size_t> Point4s;
67 typedef util::Vector<5, size_t> Point5s;
68 typedef util::Vector<6, size_t> Point6s;
70 typedef util::Vector<3, ushort> Point3us;
72 typedef util::Matrix<2, 2, float> Matrix2f;
73 typedef util::Matrix<3, 3, float> Matrix3f;
74 typedef util::Matrix<4, 4, float> Matrix4f;
76 typedef util::Matrix<2, 2, double> Matrix2d;
77 typedef util::Matrix<3, 3, double> Matrix3d;
78 typedef util::Matrix<4, 4, double> Matrix4d;
80 typedef util::BoundingBox<3, uint> BoundingBox3u;
81 typedef util::BoundingBox<3, int> BoundingBox3i;
82 typedef util::BoundingBox<3, float> BoundingBox3f;
85 Point3u toVoxelsCeil(
const Point3f& p,
const Point3f& step)
88 if(p.x() > 0 and step.x() > 0)
89 r.x() = uint(ceil(p.x() / step.x()));
90 if(p.y() > 0 and step.y() > 0)
91 r.y() = uint(ceil(p.y() / step.y()));
92 if(p.z() > 0 and step.z() > 0)
93 r.z() = uint(ceil(p.z() / step.z()));
99 CU_HOST_DEVICE util::Vector<3, T> multMatrix4Point3(
const util::Matrix<4, 4, T>& m,
const util::Vector<3, T>& p)
101 util::Vector<4, T> t(p.x(), p.y(), p.z(), T(1.0));
103 util::Vector<3, T> res(t.x() / t.t(), t.y() / t.t(), t.z() / t.t());
107 template <
typename T> T CU_HOST_DEVICE interpolate(
const T a,
const T b,
const T s)
109 T t = trim(s, (T)0.0, (T)1.0);
110 return ((1.0 - t) * a + t * b);
128 bool planeLineIntersect(Point3f p, Point3f n, Point3f u1, Point3f u2,
float& s, Point3f& u)
131 Point3f u1u2 = u2 - u1;
136 s = n * (p - u1) / t;
143 float triangleArea(Point3f a, Point3f b, Point3f c) {
144 return ((a - b).cross(a - c).norm() / 2.0);
149 float signedTetraVolume(Point3f a, Point3f b, Point3f c)
151 return ((-c.x() * b.y() * a.z() + b.x() * c.y() * a.z() + c.x() * a.y() * b.z() - a.x() * c.y() * b.z()
152 - b.x() * a.y() * c.z() + a.x() * b.y() * c.z()) / 6.0f);
157 void getBasisFromPlane(
const Point3f& nrml, Point3f& x, Point3f& y, Point3f& z)
161 x = Point3f(1, 0, 0);
162 y = Point3f(0, 1, 0);
163 z = Point3f(0, 0, 1);
164 if(z.cross(n).norm() != 0) {
182 int rayTriangleIntersect(
const Point3f& r0,
const Point3f& r1,
const Point3f& t0,
const Point3f& t1,
const Point3f& t2,
188 Point3f n = u.
cross(v);
189 if(n.x() == 0 && n.y() == 0 && n.z() == 0)
192 Point3f dir = r1 - r0;
193 Point3f w0 = r0 - t0;
212 float uu, uv, vv, wu, wv, d;
216 Point3f w = intp - t0;
219 d = uv * uv - uu * vv;
223 s = (uv * wv - vv * wu) / d;
224 if(s < 0.0f || s > 1.0f)
226 t = (uv * wu - uu * wv) / d;
227 if(t < 0.0f || (s + t) > 1.0f)
235 float distLinePoint(Point3f v1, Point3f v2, Point3f p,
bool segment)
245 Point3f q = vn * (p * vn);
246 float dist = norm(p - q);
252 if(qn >= 0 and qn <= n)
257 float d = norm(p - v2);
CU_HOST_DEVICE Vector cross(const Vector &other) const
Compute the cross product as this x other.
Definition: Vector.hpp:641
CU_HOST_DEVICE Vector & normalize(void)
Normalize the vector.
Definition: Vector.hpp:548
Common definitions and utilities This file is shared by cuda, do not include headers that nvcc can't ...
Defines the Matrix class template This file is shared by cuda, do not include headers that nvcc can't...
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can't...