Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
igl::embree::EmbreeIntersector Class Reference

#include <src/libigl/igl/embree/EmbreeIntersector.h>

+ Collaboration diagram for igl::embree::EmbreeIntersector:

Classes

struct  Triangle
 
struct  Vertex
 

Public Types

typedef Eigen::Matrix< float, Eigen::Dynamic, 3 > PointMatrixType
 
typedef Eigen::Matrix< int, Eigen::Dynamic, 3 > FaceMatrixType
 

Public Member Functions

 EmbreeIntersector ()
 
virtual ~EmbreeIntersector ()
 
void init (const PointMatrixType &V, const FaceMatrixType &F, bool isStatic=false)
 
void init (const std::vector< const PointMatrixType * > &V, const std::vector< const FaceMatrixType * > &F, const std::vector< int > &masks, bool isStatic=false)
 
void deinit ()
 
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
 
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
 
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
 
bool intersectSegment (const Eigen::RowVector3f &a, const Eigen::RowVector3f &ab, Hit &hit, int mask=0xFFFFFFFF) const
 

Static Public Member Functions

static void global_init ()
 

Private Member Functions

 EmbreeIntersector (const EmbreeIntersector &that)
 
EmbreeIntersectoroperator= (const EmbreeIntersector &)
 
void createRay (RTCRay &ray, const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, float tnear, float tfar, int mask) const
 

Static Private Member Functions

static void global_deinit ()
 

Private Attributes

RTCScene scene
 
unsigned geomID
 
Vertexvertices
 
Triangletriangles
 
bool initialized
 

Detailed Description


Class Documentation

◆ igl::embree::EmbreeIntersector::Triangle

struct igl::embree::EmbreeIntersector::Triangle
Class Members
int v0
int v1
int v2

◆ igl::embree::EmbreeIntersector::Vertex

struct igl::embree::EmbreeIntersector::Vertex
Class Members
float a
float x
float y
float z

Member Typedef Documentation

◆ FaceMatrixType

◆ PointMatrixType

Constructor & Destructor Documentation

◆ EmbreeIntersector() [1/2]

igl::embree::EmbreeIntersector::EmbreeIntersector ( )
inline
228 :
229 //scene(NULL),
230 geomID(0),
231 vertices(NULL),
232 triangles(NULL),
233 initialized(false)
234{
235}
Triangle * triangles
Definition EmbreeIntersector.h:176
unsigned geomID
Definition EmbreeIntersector.h:174
bool initialized
Definition EmbreeIntersector.h:177
Vertex * vertices
Definition EmbreeIntersector.h:175

◆ EmbreeIntersector() [2/2]

igl::embree::EmbreeIntersector::EmbreeIntersector ( const EmbreeIntersector that)
inlineprivate
239 :// To make -Weffc++ happy
240 //scene(NULL),
241 geomID(0),
242 vertices(NULL),
243 triangles(NULL),
244 initialized(false)
245{
246 assert(false && "Embree: Copying EmbreeIntersector is not allowed");
247}

◆ ~EmbreeIntersector()

igl::embree::EmbreeIntersector::~EmbreeIntersector ( )
inlinevirtual
338{
339 if(initialized)
340 deinit();
341}
void deinit()
Definition EmbreeIntersector.h:343

References initialized.

Member Function Documentation

◆ createRay()

void igl::embree::EmbreeIntersector::createRay ( RTCRay &  ray,
const Eigen::RowVector3f &  origin,
const Eigen::RowVector3f &  direction,
float  tnear,
float  tfar,
int  mask 
) const
inlineprivate
568{
569 ray.org[0] = origin[0];
570 ray.org[1] = origin[1];
571 ray.org[2] = origin[2];
572 ray.dir[0] = direction[0];
573 ray.dir[1] = direction[1];
574 ray.dir[2] = direction[2];
575 ray.tnear = tnear;
576 ray.tfar = tfar;
577 ray.geomID = RTC_INVALID_GEOMETRY_ID;
578 ray.primID = RTC_INVALID_GEOMETRY_ID;
579 ray.instID = RTC_INVALID_GEOMETRY_ID;
580 ray.mask = mask;
581 ray.time = 0.0f;
582}
#define RTC_INVALID_GEOMETRY_ID
Definition rtcore_geometry.h:24

References RTC_INVALID_GEOMETRY_ID.

◆ deinit()

void igl::embree::EmbreeIntersector::deinit ( )
inline
344{
346 {
348
350 {
351 std::cerr << "Embree: An error occurred while resetting!" << std::endl;
352 }
353#ifdef IGL_VERBOSE
354 else
355 {
356 std::cerr << "Embree: geometry removed." << std::endl;
357 }
358#endif
359 }
360}
RTCScene scene
Definition EmbreeIntersector.h:173
static bool EmbreeIntersector_inited
Definition EmbreeIntersector.h:202
RTCORE_API RTCORE_DEPRECATED RTCError rtcGetError()
Returns the value of the per-thread error flag.
@ RTC_NO_ERROR
No error has been recorded.
Definition rtcore.h:179
RTCORE_API void rtcDeleteScene(RTCScene scene)

References igl::embree::EmbreeIntersector_inited, RTC_NO_ERROR, rtcDeleteScene(), and rtcGetError().

+ Here is the call graph for this function:

◆ global_deinit()

void igl::embree::EmbreeIntersector::global_deinit ( )
inlinestaticprivate
222{
224 rtcExit();
225}
RTCORE_API RTCORE_DEPRECATED void rtcExit()
Shuts down Embree.

References igl::embree::EmbreeIntersector_inited, and rtcExit().

+ Here is the call graph for this function:

◆ global_init()

void igl::embree::EmbreeIntersector::global_init ( )
inlinestatic
207{
209 {
210 rtcInit();
212 std::cerr << "Embree: An error occurred while initializing embree core!" << std::endl;
213#ifdef IGL_VERBOSE
214 else
215 std::cerr << "Embree: core initialized." << std::endl;
216#endif
218 }
219}
RTCORE_API RTCORE_DEPRECATED void rtcInit(const char *cfg=NULL)
Initializes the Embree ray tracing core.

References igl::embree::EmbreeIntersector_inited, RTC_NO_ERROR, rtcGetError(), and rtcInit().

+ Here is the call graph for this function:

◆ init() [1/2]

void igl::embree::EmbreeIntersector::init ( const PointMatrixType V,
const FaceMatrixType F,
bool  isStatic = false 
)
inline
261{
262 std::vector<const PointMatrixType*> Vtemp;
263 std::vector<const FaceMatrixType*> Ftemp;
264 std::vector<int> masks;
265 Vtemp.push_back(&V);
266 Ftemp.push_back(&F);
267 masks.push_back(0xFFFFFFFF);
268 init(Vtemp,Ftemp,masks,isStatic);
269}
void init(const PointMatrixType &V, const FaceMatrixType &F, bool isStatic=false)
Definition EmbreeIntersector.h:257

Referenced by igl::embree::ambient_occlusion(), igl::embree::bone_heat(), igl::embree::bone_visible(), igl::embree::line_mesh_intersection(), igl::embree::reorient_facets_raycast(), and igl::embree::shape_diameter_function().

+ Here is the caller graph for this function:

◆ init() [2/2]

void igl::embree::EmbreeIntersector::init ( const std::vector< const PointMatrixType * > &  V,
const std::vector< const FaceMatrixType * > &  F,
const std::vector< int > &  masks,
bool  isStatic = false 
)
inline
276{
277
278 if(initialized)
279 deinit();
280
281 using namespace std;
282 global_init();
283
284 if(V.size() == 0 || F.size() == 0)
285 {
286 std::cerr << "Embree: No geometry specified!";
287 return;
288 }
289
290 // create a scene
292 if(isStatic)
293 flags = flags | RTC_SCENE_STATIC;
295
296 for(int g=0;g<(int)V.size();g++)
297 {
298 // create triangle mesh geometry in that scene
300
301 // fill vertex buffer
303 for(int i=0;i<(int)V[g]->rows();i++)
304 {
305 vertices[i].x = (float)V[g]->coeff(i,0);
306 vertices[i].y = (float)V[g]->coeff(i,1);
307 vertices[i].z = (float)V[g]->coeff(i,2);
308 }
310
311 // fill triangle buffer
313 for(int i=0;i<(int)F[g]->rows();i++)
314 {
315 triangles[i].v0 = (int)F[g]->coeff(i,0);
316 triangles[i].v1 = (int)F[g]->coeff(i,1);
317 triangles[i].v2 = (int)F[g]->coeff(i,2);
318 }
320
321 rtcSetMask(scene,geomID,masks[g]);
322 }
323
325
327 std::cerr << "Embree: An error occurred while initializing the provided geometry!" << endl;
328#ifdef IGL_VERBOSE
329 else
330 std::cerr << "Embree: geometry added." << endl;
331#endif
332
333 initialized = true;
334}
static void global_init()
Definition EmbreeIntersector.h:206
float z
Definition EmbreeIntersector.h:170
int v1
Definition EmbreeIntersector.h:171
float y
Definition EmbreeIntersector.h:170
int v2
Definition EmbreeIntersector.h:171
int v0
Definition EmbreeIntersector.h:171
float x
Definition EmbreeIntersector.h:170
@ F
Definition libslic3r.h:102
Kernel::Triangle_3 Triangle
Definition points_inside_component.cpp:33
size_t rows(const T &raster)
Definition MarchingSquares.hpp:55
STL namespace.
@ RTC_GEOMETRY_STATIC
specifies static geometry that will change rarely
Definition rtcore_geometry.h:60
RTCORE_API void rtcUnmapBuffer(RTCScene scene, unsigned geomID, RTCBufferType type)
Unmaps specified buffer.
RTCORE_API void * rtcMapBuffer(RTCScene scene, unsigned geomID, RTCBufferType type)
Maps specified buffer. This function can be used to set index and vertex buffers of geometries.
RTCORE_API unsigned rtcNewTriangleMesh(RTCScene scene, RTCGeometryFlags flags, size_t numTriangles, size_t numVertices, size_t numTimeSteps=1)
Creates a new triangle mesh. The number of triangles (numTriangles), number of vertices (numVertices)...
@ RTC_INDEX_BUFFER
Definition rtcore_geometry.h:28
@ RTC_VERTEX_BUFFER
Definition rtcore_geometry.h:30
RTCORE_API void rtcSetMask(RTCScene scene, unsigned geomID, int mask)
Sets 32 bit ray mask.
RTCORE_API void rtcCommit(RTCScene scene)
@ RTC_INTERSECT1
enables the rtcIntersect1 and rtcOccluded1 functions for this scene
Definition rtcore_scene.h:50
RTCSceneFlags
Definition rtcore_scene.h:32
@ RTC_SCENE_ROBUST
use more robust traversal algorithms
Definition rtcore_scene.h:44
@ RTC_SCENE_HIGH_QUALITY
create higher quality data structures
Definition rtcore_scene.h:41
@ RTC_SCENE_STATIC
specifies static scene
Definition rtcore_scene.h:34
RTCORE_API RTCORE_DEPRECATED RTCScene rtcNewScene(RTCSceneFlags flags, RTCAlgorithmFlags aflags)

References initialized, RTC_GEOMETRY_STATIC, RTC_INDEX_BUFFER, RTC_INTERSECT1, RTC_NO_ERROR, RTC_SCENE_HIGH_QUALITY, RTC_SCENE_ROBUST, RTC_SCENE_STATIC, RTC_VERTEX_BUFFER, rtcCommit(), rtcGetError(), rtcMapBuffer(), rtcNewScene(), rtcNewTriangleMesh(), rtcSetMask(), and rtcUnmapBuffer().

+ Here is the call graph for this function:

◆ intersectBeam()

bool igl::embree::EmbreeIntersector::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
inline
403{
404 bool hasHit = false;
405 Hit bestHit;
406
407 if(closestHit)
408 bestHit.t = std::numeric_limits<float>::max();
409 else
410 bestHit.t = 0;
411
412 if((intersectRay(origin,direction,hit,tnear,tfar,mask) && (hit.gid == geoId || geoId == -1)))
413 {
414 bestHit = hit;
415 hasHit = true;
416 }
417
418 // sample points around actual ray (conservative hitcheck)
419 const float eps= 1e-5;
420
421 Eigen::RowVector3f up(0,1,0);
422 Eigen::RowVector3f offset = direction.cross(up).normalized();
423
424 Eigen::Matrix3f rot = Eigen::AngleAxis<float>(2*3.14159265358979/samples,direction).toRotationMatrix();
425
426 for(int r=0;r<(int)samples;r++)
427 {
428 if(intersectRay(origin+offset*eps,direction,hit,tnear,tfar,mask) &&
429 ((closestHit && (hit.t < bestHit.t)) ||
430 (!closestHit && (hit.t > bestHit.t))) &&
431 (hit.gid == geoId || geoId == -1))
432 {
433 bestHit = hit;
434 hasHit = true;
435 }
436 offset = rot*offset.transpose();
437 }
438
439 hit = bestHit;
440 return hasHit;
441}
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
Definition EmbreeIntersector.h:362
EIGEN_DEVICE_FUNC Matrix3 toRotationMatrix(void) const
Definition AngleAxis.h:218
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition AngleAxis.h:50
AABBMesh::hit_result Hit
Definition SupportTreeUtils.hpp:95
void offset(Slic3r::ExPolygon &sh, coord_t distance, const PolygonTag &)
Definition geometries.hpp:132

References igl::Hit::gid, igl::Hit::t, and Eigen::AngleAxis< _Scalar >::toRotationMatrix().

Referenced by igl::embree::line_mesh_intersection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ intersectRay() [1/2]

bool igl::embree::EmbreeIntersector::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
inline
369{
370 RTCRay ray;
371 createRay(ray, origin,direction,tnear,tfar,mask);
372
373 // shot ray
374 rtcIntersect(scene,ray);
375#ifdef IGL_VERBOSE
377 std::cerr << "Embree: An error occurred while resetting!" << std::endl;
378#endif
379
380 if((unsigned)ray.geomID != RTC_INVALID_GEOMETRY_ID)
381 {
382 hit.id = ray.primID;
383 hit.gid = ray.geomID;
384 hit.u = ray.u;
385 hit.v = ray.v;
386 hit.t = ray.tfar;
387 return true;
388 }
389
390 return false;
391}
void createRay(RTCRay &ray, const Eigen::RowVector3f &origin, const Eigen::RowVector3f &direction, float tnear, float tfar, int mask) const
Definition EmbreeIntersector.h:567
RTCORE_API void rtcIntersect(RTCScene scene, RTCRay &ray)

References igl::Hit::gid, igl::Hit::id, RTC_INVALID_GEOMETRY_ID, RTC_NO_ERROR, rtcGetError(), rtcIntersect(), igl::Hit::t, igl::Hit::u, and igl::Hit::v.

Referenced by igl::embree::ambient_occlusion(), igl::embree::reorient_facets_raycast(), igl::embree::shape_diameter_function(), igl::embree::unproject_in_mesh(), and igl::embree::unproject_onto_mesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ intersectRay() [2/2]

bool igl::embree::EmbreeIntersector::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
inline
453{
454 using namespace std;
455 num_rays = 0;
456 hits.clear();
457 int last_id0 = -1;
458 double self_hits = 0;
459 // This epsilon is directly correleated to the number of missed hits, smaller
460 // means more accurate and slower
461 //const double eps = DOUBLE_EPS;
462 const double eps = FLOAT_EPS;
463 double min_t = tnear;
464 bool large_hits_warned = false;
465 RTCRay ray;
466 createRay(ray,origin,direction,tnear,tfar,mask);
467
468 while(true)
469 {
470 ray.tnear = min_t;
471 ray.tfar = tfar;
472 ray.geomID = RTC_INVALID_GEOMETRY_ID;
473 ray.primID = RTC_INVALID_GEOMETRY_ID;
474 ray.instID = RTC_INVALID_GEOMETRY_ID;
475 num_rays++;
476 rtcIntersect(scene,ray);
477 if((unsigned)ray.geomID != RTC_INVALID_GEOMETRY_ID)
478 {
479 // Hit self again, progressively advance
480 if(ray.primID == last_id0 || ray.tfar <= min_t)
481 {
482 // push min_t a bit more
483 //double t_push = pow(2.0,self_hits-4)*(hit.t<eps?eps:hit.t);
484 double t_push = pow(2.0,self_hits)*eps;
485 #ifdef IGL_VERBOSE
486 std::cerr<<" t_push: "<<t_push<<endl;
487 #endif
488 //o = o+t_push*d;
489 min_t += t_push;
490 self_hits++;
491 }
492 else
493 {
494 Hit hit;
495 hit.id = ray.primID;
496 hit.gid = ray.geomID;
497 hit.u = ray.u;
498 hit.v = ray.v;
499 hit.t = ray.tfar;
500 hits.push_back(hit);
501#ifdef IGL_VERBOSE
502 std::cerr<<" t: "<<hit.t<<endl;
503#endif
504 // Instead of moving origin, just change min_t. That way calculations
505 // all use exactly same origin values
506 min_t = ray.tfar;
507
508 // reset t_scale
509 self_hits = 0;
510 }
511 last_id0 = ray.primID;
512 }
513 else
514 break; // no more hits
515
516 if(hits.size()>1000 && !large_hits_warned)
517 {
518 std::cout<<"Warning: Large number of hits..."<<endl;
519 std::cout<<"[ ";
520 for(vector<Hit>::iterator hit = hits.begin(); hit != hits.end();hit++)
521 {
522 std::cout<<(hit->id+1)<<" ";
523 }
524
525 std::cout.precision(std::numeric_limits< double >::digits10);
526 std::cout<<"[ ";
527
528 for(vector<Hit>::iterator hit = hits.begin(); hit != hits.end(); hit++)
529 {
530 std::cout<<(hit->t)<<endl;;
531 }
532
533 std::cout<<"]"<<endl;
534 large_hits_warned = true;
535
536 return hits.empty();
537 }
538 }
539
540 return hits.empty();
541}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
Definition Half.h:477
const float FLOAT_EPS
Definition EPS.h:16

References igl::FLOAT_EPS, igl::Hit::gid, igl::Hit::id, RTC_INVALID_GEOMETRY_ID, rtcIntersect(), igl::Hit::t, igl::Hit::u, and igl::Hit::v.

+ Here is the call graph for this function:

◆ intersectSegment()

bool igl::embree::EmbreeIntersector::intersectSegment ( const Eigen::RowVector3f &  a,
const Eigen::RowVector3f &  ab,
Hit hit,
int  mask = 0xFFFFFFFF 
) const
inline
546{
547 RTCRay ray;
548 createRay(ray,a,ab,0,1.0,mask);
549
550 rtcIntersect(scene,ray);
551
552 if((unsigned)ray.geomID != RTC_INVALID_GEOMETRY_ID)
553 {
554 hit.id = ray.primID;
555 hit.gid = ray.geomID;
556 hit.u = ray.u;
557 hit.v = ray.v;
558 hit.t = ray.tfar;
559 return true;
560 }
561
562 return false;
563}

References igl::Hit::gid, igl::Hit::id, RTC_INVALID_GEOMETRY_ID, rtcIntersect(), igl::Hit::t, igl::Hit::u, and igl::Hit::v.

Referenced by igl::embree::bone_visible().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

igl::embree::EmbreeIntersector & igl::embree::EmbreeIntersector::operator= ( const EmbreeIntersector )
inlineprivate
251{
252 assert(false && "Embree: Assigning an EmbreeIntersector is not allowed");
253 return *this;
254}

Member Data Documentation

◆ geomID

unsigned igl::embree::EmbreeIntersector::geomID
private

◆ initialized

bool igl::embree::EmbreeIntersector::initialized
private

◆ scene

RTCScene igl::embree::EmbreeIntersector::scene
private

◆ triangles

Triangle* igl::embree::EmbreeIntersector::triangles
private

◆ vertices

Vertex* igl::embree::EmbreeIntersector::vertices
private

The documentation for this class was generated from the following file: