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 <embree4/rtcore.h>
24#include <embree4/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 typedef Eigen::RowVector3f OriginType;
41 typedef Eigen::RowVector3f DirectionType;
42 public:
44 private:
45 // Copying and assignment are not allowed.
47 EmbreeIntersector & operator=(const EmbreeIntersector &);
48 public:
50
58 void init(
59 const PointMatrixType& V,
60 const FaceMatrixType& F,
61 bool isStatic = false);
62
72 void init(
73 const std::vector<const PointMatrixType*>& V,
74 const std::vector<const FaceMatrixType*>& F,
75 const std::vector<int>& masks,
76 bool isStatic = false);
77
81 void deinit();
82
93 const Eigen::RowVector3f& origin,
94 const Eigen::RowVector3f& direction,
95 Hit<float>& hit,
96 float tnear = 0,
97 float tfar = std::numeric_limits<float>::infinity(),
98 int mask = 0xFFFFFFFF) const;
99
114 const Eigen::RowVector3f& origin,
115 const Eigen::RowVector3f& direction,
116 Hit<float>& hit,
117 float tnear = 0,
118 float tfar = std::numeric_limits<float>::infinity(),
119 int mask = 0xFFFFFFFF,
120 int geoId = -1,
121 bool closestHit = true,
122 unsigned int samples = 4) const;
123
135 const Eigen::RowVector3f& origin,
136 const Eigen::RowVector3f& direction,
137 std::vector<Hit<float>> &hits,
138 int& num_rays,
139 float tnear = 0,
140 float tfar = std::numeric_limits<float>::infinity(),
141 int mask = 0xFFFFFFFF) const;
142
150 const Eigen::RowVector3f& a,
151 const Eigen::RowVector3f& ab,
152 Hit<float> &hit,
153 int mask = 0xFFFFFFFF) const;
154
166 const OriginType & origin,
167 const DirectionType& direction,
168 float tnear = 0.0f,
169 float tfar = std::numeric_limits<float>::infinity(),
170 int mask = 0xFFFFFFFF) const;
171
172 private:
173
174 struct Vertex {float x,y,z,a;};
175 struct Triangle {int v0, v1, v2;};
176
177 RTCScene scene;
178 unsigned geomID;
179 Vertex* vertices;
180 Triangle* triangles;
181 bool initialized;
182
183 RTCDevice device;
184
185 void createRay(
186 RTCRayHit& ray,
187 const Eigen::RowVector3f& origin,
188 const Eigen::RowVector3f& direction,
189 float tnear,
190 float tfar,
191 int mask) const;
192 };
193 }
194}
195
196#ifndef IGL_STATIC_LIBRARY
197# include "EmbreeIntersector.cpp"
198#endif
199
200#endif //EMBREE_INTERSECTOR_H
int signedIntersectionsRay(const OriginType &origin, const DirectionType &direction, float tnear=0.0f, float tfar=std::numeric_limits< float >::infinity(), int mask=0xFFFFFFFF) const
Signed ray-mesh crossing count along (origin, direction).
bool intersectRay(const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, Hit< float > &hit, float tnear=0, float tfar=std::numeric_limits< float >::infinity(), int mask=0xFFFFFFFF) const
Given a ray find the first hit.
Eigen::RowVector3f DirectionType
Definition EmbreeIntersector.h:41
void deinit()
Deinitialize embree datasctructures for current mesh.
Eigen::Matrix< float, Eigen::Dynamic, 3 > PointMatrixType
Definition EmbreeIntersector.h:38
bool intersectRay(const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, std::vector< Hit< float > > &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.
bool intersectSegment(const Eigen::RowVector3f &a, const Eigen::RowVector3f &ab, Hit< float > &hit, int mask=0xFFFFFFFF) const
Given a ray find the first hit.
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.
bool intersectBeam(const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, Hit< float > &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 init(const PointMatrixType &V, const FaceMatrixType &F, bool isStatic=false)
Initialize with a given mesh.
Eigen::RowVector3f OriginType
Definition EmbreeIntersector.h:40
Eigen::Matrix< int, Eigen::Dynamic, 3 > FaceMatrixType
Definition EmbreeIntersector.h:39
Definition ambient_occlusion.h:15
Definition AABB.h:18
Reimplementation of the embree::Hit struct from embree1.0.
Definition Hit.h:18