libigl v2.5.0
Loading...
Searching...
No Matches
EmbreeIntersector.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4// 2014 Christian Schüller <schuellchr@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla Public License
7// v. 2.0. If a copy of the MPL was not distributed with this file, You can
8// obtain one at http://mozilla.org/MPL/2.0/.
9// igl function interface for Embree2.2
10//
11// Necessary changes to switch from previous Embree versions:
12// * Use igl:Hit instead of embree:Hit (where id0 -> id)
13// * For Embree2.2
14// * Uncomment #define __USE_RAY_MASK__ in platform.h to enable masking
15
16#ifndef IGL_EMBREE_EMBREE_INTERSECTOR_H
17#define IGL_EMBREE_EMBREE_INTERSECTOR_H
18
19#include "../Hit.h"
20#include <Eigen/Geometry>
21#include <Eigen/Core>
22
23#include <embree3/rtcore.h>
24#include <embree3/rtcore_ray.h>
25#include <iostream>
26#include <vector>
27
28#include "EmbreeDevice.h"
29
30namespace igl
31{
32 namespace embree
33 {
36 {
37 public:
38 typedef Eigen::Matrix<float,Eigen::Dynamic,3> PointMatrixType;
39 typedef Eigen::Matrix<int,Eigen::Dynamic,3> FaceMatrixType;
40 public:
42 private:
43 // Copying and assignment are not allowed.
45 EmbreeIntersector & operator=(const EmbreeIntersector &);
46 public:
48
56 void init(
57 const PointMatrixType& V,
58 const FaceMatrixType& F,
59 bool isStatic = false);
60
70 void init(
71 const std::vector<const PointMatrixType*>& V,
72 const std::vector<const FaceMatrixType*>& F,
73 const std::vector<int>& masks,
74 bool isStatic = false);
75
79 void deinit();
80
91 const Eigen::RowVector3f& origin,
92 const Eigen::RowVector3f& direction,
93 Hit& hit,
94 float tnear = 0,
95 float tfar = std::numeric_limits<float>::infinity(),
96 int mask = 0xFFFFFFFF) const;
97
112 const Eigen::RowVector3f& origin,
113 const Eigen::RowVector3f& direction,
114 Hit& hit,
115 float tnear = 0,
116 float tfar = std::numeric_limits<float>::infinity(),
117 int mask = 0xFFFFFFFF,
118 int geoId = -1,
119 bool closestHit = true,
120 unsigned int samples = 4) const;
121
133 const Eigen::RowVector3f& origin,
134 const Eigen::RowVector3f& direction,
135 std::vector<Hit > &hits,
136 int& num_rays,
137 float tnear = 0,
138 float tfar = std::numeric_limits<float>::infinity(),
139 int mask = 0xFFFFFFFF) const;
140
148 const Eigen::RowVector3f& a,
149 const Eigen::RowVector3f& ab,
150 Hit &hit,
151 int mask = 0xFFFFFFFF) const;
152
153 private:
154
155 struct Vertex {float x,y,z,a;};
156 struct Triangle {int v0, v1, v2;};
157
158 RTCScene scene;
159 unsigned geomID;
160 Vertex* vertices;
161 Triangle* triangles;
162 bool initialized;
163
164 RTCDevice device;
165
166 void createRay(
167 RTCRayHit& ray,
168 const Eigen::RowVector3f& origin,
169 const Eigen::RowVector3f& direction,
170 float tnear,
171 float tfar,
172 int mask) const;
173 };
174 }
175}
176
177#ifndef IGL_STATIC_LIBRARY
178# include "EmbreeIntersector.cpp"
179#endif
180
181#endif //EMBREE_INTERSECTOR_H
Simple class to wrap Embree's ray tracing functionality.
Definition EmbreeIntersector.h:36
bool intersectSegment(const Eigen::RowVector3f &a, const Eigen::RowVector3f &ab, Hit &hit, int mask=0xFFFFFFFF) const
Given a ray find the first hit.
bool intersectBeam(const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, Hit &hit, float tnear=0, float tfar=std::numeric_limits< float >::infinity(), int mask=0xFFFFFFFF, int geoId=-1, bool closestHit=true, unsigned int samples=4) const
Given a ray find the first hit This is a conservative hit test where multiple rays within a small rad...
void deinit()
Deinitialize embree datasctructures for current mesh.
bool intersectRay(const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, Hit &hit, float tnear=0, float tfar=std::numeric_limits< float >::infinity(), int mask=0xFFFFFFFF) const
Given a ray find the first hit.
Eigen::Matrix< float, Eigen::Dynamic, 3 > PointMatrixType
Definition EmbreeIntersector.h:38
bool intersectRay(const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, std::vector< Hit > &hits, int &num_rays, float tnear=0, float tfar=std::numeric_limits< float >::infinity(), int mask=0xFFFFFFFF) const
Given a ray find all hits in order.
void init(const std::vector< const PointMatrixType * > &V, const std::vector< const FaceMatrixType * > &F, const std::vector< int > &masks, bool isStatic=false)
Initialize with a given mesh.
void init(const PointMatrixType &V, const FaceMatrixType &F, bool isStatic=false)
Initialize with a given mesh.
Eigen::Matrix< int, Eigen::Dynamic, 3 > FaceMatrixType
Definition EmbreeIntersector.h:39
Definition AABB.h:17
Reimplementation of the embree::Hit struct from embree1.0.
Definition Hit.h:18