Isis 3 Programmer Reference
EmbreeTargetShape.h
1 #ifndef EmbreeTargetShape_h
2 #define EmbreeTargetShape_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 #include <QString>
11 
12 // Embree includes
13 #include <embree2/rtcore.h>
14 #include <embree2/rtcore_ray.h>
15 
16 // PointCloudLibrary includes
17 #include <pcl/io/auto_io.h>
18 #include <pcl/point_types.h>
19 #include <pcl/PolygonMesh.h>
20 
21 // WARNING
22 // The following undefes macros set in pcl. They conflict with ISIS's macros.
23 // If pcl tries to use these macros you will get compilation errors.
24 // - JAM
25 #undef DEG2RAD
26 #undef RAD2DEG
27 
28 #include "FileName.h"
29 #include "LinearAlgebra.h"
30 
31 namespace Isis {
32 
33 
34  class Pvl;
35 
46  RTCMultiHitRay(const std::vector<double> &origin,
47  const std::vector<double> &direction);
49  LinearAlgebra::Vector direction);
50 
51 // These are the inheritted members from RTCRay
52 // float org; //!< Ray origin
53 // float dir; //!< Ray direction
54 // float tnear; //!< Start of ray segment
55 // float tfar; //!< End of ray segment
56 // float time; //!< Time of this ray for motion blur.
57 // unsigned mask; //!< used to mask out objects during traversal
58 // float Ng; //!< Geometric normal.
59 // float u; //!< Barycentric u coordinate of hit
60 // float v; //!< Barycentric v coordinate of hit
61 // unsigned geomID; //!< geometry ID
62 // unsigned primID; //!< primitive ID
63 // unsigned instID; //!< instance ID
64 
65  // ray extensions
66  // we remember up to 16 hits to ignore duplicate hits
67  unsigned hitGeomIDs[16];
68  unsigned hitPrimIDs[16];
69  float hitUs[16];
70  float hitVs[16];
71  int lastHit;
72  };
73 
74 
85  RTCOcclusionRay(const std::vector<double> &origin,
86  const std::vector<double> &direction);
88  LinearAlgebra::Vector direction);
89 
90 // These are the inheritted members from RTCRay
91 // float org; //!< Ray origin
92 // float dir; //!< Ray direction
93 // float tnear; //!< Start of ray segment
94 // float tfar; //!< End of ray segment
95 // float time; //!< Time of this ray for motion blur.
96 // unsigned mask; //!< used to mask out objects during traversal
97 // float Ng; //!< Geometric normal.
98 // float u; //!< Barycentric u coordinate of hit
99 // float v; //!< Barycentric v coordinate of hit
100 // unsigned geomID; //!< geometry ID
101 // unsigned primID; //!< primitive ID
102 // unsigned instID; //!< instance ID
103 
104  // ray extensions
105  int lastHit;
106  unsigned ignorePrimID;
107  };
108 
109 
121 
124  int primID;
125  };
126 
127 
140  public:
141 
143  EmbreeTargetShape(pcl::PolygonMesh::Ptr mesh, const QString &name = "");
144  EmbreeTargetShape(const QString &dem, const Pvl *conf = 0);
145  virtual ~EmbreeTargetShape();
146 
147  QString name() const;
148  bool isValid() const;
149 
150  int numberOfPolygons() const;
151  int numberOfVertices() const;
152  RTCBounds sceneBounds() const;
153  double maximumSceneDistance() const;
154 
155  void intersectRay(RTCMultiHitRay &ray);
156  bool isOccluded(RTCOcclusionRay &ray);
157 
159 
160  static void multiHitFilter(void* userDataPtr, RTCMultiHitRay& ray);
161  static void occlusionFilter(void* userDataPtr, RTCOcclusionRay& ray);
162 
163  protected:
164  pcl::PolygonMesh::Ptr readDSK(FileName file);
165  pcl::PolygonMesh::Ptr readPC(FileName file);
166  void initMesh(pcl::PolygonMesh::Ptr mesh);
167  void addVertices(int geomID);
168  void addIndices(int geomID);
169 
170  private:
178  struct Vertex {
179  float x;
180  float y;
181  float z;
182  float a;
183  };
184 
193  struct Triangle {
194  int v0;
195  int v1;
196  int v2;
197  };
198 
199  QString m_name;
200  pcl::PolygonMesh::Ptr m_mesh;
203  pcl::PointCloud<pcl::PointXYZ> m_cloud;
208  RTCDevice m_device;
210  RTCScene m_scene;
216  };
217 
218 } // namespace Isis
219 
220 #endif
221 
Isis::EmbreeTargetShape::multiHitFilter
static void multiHitFilter(void *userDataPtr, RTCMultiHitRay &ray)
Filter function for collecting multiple hits during ray intersection.
Definition: EmbreeTargetShape.cpp:754
Isis::EmbreeTargetShape::m_device
RTCDevice m_device
!< The point cloud representation of the target.
Definition: EmbreeTargetShape.h:208
Isis::EmbreeTargetShape::m_cloud
pcl::PointCloud< pcl::PointXYZ > m_cloud
!< A boost shared pointer to the polygon mesh representation of the target.
Definition: EmbreeTargetShape.h:203
Isis::RTCMultiHitRay::lastHit
int lastHit
Index of the last hit in the hit containers.
Definition: EmbreeTargetShape.h:71
Isis::EmbreeTargetShape::numberOfVertices
int numberOfVertices() const
Return the number of vertices in the target shape.
Definition: EmbreeTargetShape.cpp:559
Isis::RayHitInformation::RayHitInformation
RayHitInformation()
Default constructor for RayHitInformation.
Definition: EmbreeTargetShape.cpp:196
Isis::EmbreeTargetShape::Triangle::v0
int v0
The index of the first vertex in the tin.
Definition: EmbreeTargetShape.h:194
Isis::RayHitInformation::primID
int primID
The primitive ID of the hit.
Definition: EmbreeTargetShape.h:124
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::RTCOcclusionRay::RTCOcclusionRay
RTCOcclusionRay()
Default constructor for RTCOcclussionRay.
Definition: EmbreeTargetShape.cpp:112
Isis::EmbreeTargetShape::Vertex
Container for a vertex.
Definition: EmbreeTargetShape.h:178
Isis::EmbreeTargetShape::Vertex::a
float a
Extra float for aligning memory.
Definition: EmbreeTargetShape.h:182
Isis::EmbreeTargetShape::Vertex::y
float y
Vertex y position.
Definition: EmbreeTargetShape.h:180
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::EmbreeTargetShape::maximumSceneDistance
double maximumSceneDistance() const
Return the maximum distance within the scene.
Definition: EmbreeTargetShape.cpp:600
Isis::EmbreeTargetShape::~EmbreeTargetShape
virtual ~EmbreeTargetShape()
Desctructor.
Definition: EmbreeTargetShape.cpp:533
Isis::EmbreeTargetShape::numberOfPolygons
int numberOfPolygons() const
Return the number of polygons in the target shape.
Definition: EmbreeTargetShape.cpp:545
Isis::RTCMultiHitRay::hitGeomIDs
unsigned hitGeomIDs[16]
IDs of the geometries (bodies) hit.
Definition: EmbreeTargetShape.h:67
Isis::RayHitInformation
Container that holds the body fixed intersection point and unit surface normal for a hit.
Definition: EmbreeTargetShape.h:118
Isis::RTCOcclusionRay::lastHit
int lastHit
Index of the last hit in the hit containers.
Definition: EmbreeTargetShape.h:105
Isis::RTCMultiHitRay::hitPrimIDs
unsigned hitPrimIDs[16]
IDs of the primitives (trinagles) hit.
Definition: EmbreeTargetShape.h:68
Isis::RTCOcclusionRay
Struct for capturing occluded plates when using embree::rtcintersectscene.
Definition: EmbreeTargetShape.h:83
Isis::RTCMultiHitRay::hitUs
float hitUs[16]
Barycentric u coordinate of the hits.
Definition: EmbreeTargetShape.h:69
Isis::EmbreeTargetShape::addIndices
void addIndices(int geomID)
Adds the polygon vertex indices from the internalized polygon mesh to the Embree scene.
Definition: EmbreeTargetShape.cpp:513
Isis::EmbreeTargetShape::readPC
pcl::PolygonMesh::Ptr readPC(FileName file)
Read a PointCloudLibrary file into a PointCloudLibrary polygon mesh.
Definition: EmbreeTargetShape.cpp:420
RTCRay
Isis::LinearAlgebra::Vector
boost::numeric::ublas::vector< double > Vector
Definition for an Isis::LinearAlgebra::Vector of doubles.
Definition: LinearAlgebra.h:120
Isis::EmbreeTargetShape::initMesh
void initMesh(pcl::PolygonMesh::Ptr mesh)
Internalize a PointCloudLibrary polygon mesh in the target shape.
Definition: EmbreeTargetShape.cpp:449
Isis::RTCMultiHitRay
Struct for capturing multiple intersections when using embree::rtcintersectscene.
Definition: EmbreeTargetShape.h:44
Isis::EmbreeTargetShape::Triangle::v2
int v2
The index of the third vertex in the tin.
Definition: EmbreeTargetShape.h:196
Isis::EmbreeTargetShape::sceneBounds
RTCBounds sceneBounds() const
Returns the bounds of the Embree scene.
Definition: EmbreeTargetShape.cpp:577
Isis::EmbreeTargetShape::m_scene
RTCScene m_scene
!< The Embree device for rendering the scene.
Definition: EmbreeTargetShape.h:210
Isis::EmbreeTargetShape::addVertices
void addVertices(int geomID)
Adds the vertices from the internalized vertex point cloud to the Embree scene.
Definition: EmbreeTargetShape.cpp:488
Isis::EmbreeTargetShape
Embree Target Shape for planetary bodies.
Definition: EmbreeTargetShape.h:139
Isis::EmbreeTargetShape::getHitInformation
RayHitInformation getHitInformation(RTCMultiHitRay &ray, int hitIndex)
Extract the intersection point and unit surface normal from an RTCMultiHitRay that has been intersect...
Definition: EmbreeTargetShape.cpp:683
Isis::EmbreeTargetShape::Vertex::z
float z
Vertex z position.
Definition: EmbreeTargetShape.h:181
Isis::RTCOcclusionRay::ignorePrimID
unsigned ignorePrimID
IDs of the primitives (trinagles) which should be ignored.
Definition: EmbreeTargetShape.h:106
Isis::EmbreeTargetShape::isOccluded
bool isOccluded(RTCOcclusionRay &ray)
Check if a ray intersects the target body.
Definition: EmbreeTargetShape.cpp:653
Isis::EmbreeTargetShape::intersectRay
void intersectRay(RTCMultiHitRay &ray)
Intersect a ray with the target shape.
Definition: EmbreeTargetShape.cpp:639
Isis::EmbreeTargetShape::Vertex::x
float x
Vertex x position.
Definition: EmbreeTargetShape.h:179
Isis::EmbreeTargetShape::m_mesh
pcl::PolygonMesh::Ptr m_mesh
!< The name of the target.
Definition: EmbreeTargetShape.h:200
Isis::RayHitInformation::surfaceNormal
LinearAlgebra::Vector surfaceNormal
The unit surface normal vector at the intersection.
Definition: EmbreeTargetShape.h:123
Isis::EmbreeTargetShape::EmbreeTargetShape
EmbreeTargetShape()
Default empty constructor.
Definition: EmbreeTargetShape.cpp:225
Isis::RTCMultiHitRay::RTCMultiHitRay
RTCMultiHitRay()
Default constructor for RTCMultiHitRay.
Definition: EmbreeTargetShape.cpp:28
Isis::EmbreeTargetShape::Triangle
Container for a tin, or triangular polygon.
Definition: EmbreeTargetShape.h:193
Isis::EmbreeTargetShape::occlusionFilter
static void occlusionFilter(void *userDataPtr, RTCOcclusionRay &ray)
Filter function for collecting multiple primitiveIDs This function is called by the Embree library du...
Definition: EmbreeTargetShape.cpp:779
Isis::EmbreeTargetShape::Triangle::v1
int v1
The index of the second vertex in the tin.
Definition: EmbreeTargetShape.h:195
Isis::RTCMultiHitRay::hitVs
float hitVs[16]
Barycentric v coordinate of the hits.
Definition: EmbreeTargetShape.h:70
Isis::EmbreeTargetShape::name
QString name() const
Return the name of the target shape.
Definition: EmbreeTargetShape.cpp:730
Isis::EmbreeTargetShape::isValid
bool isValid() const
Return if a valid mesh is internalized and ready for use.
Definition: EmbreeTargetShape.cpp:740
Isis::EmbreeTargetShape::readDSK
pcl::PolygonMesh::Ptr readDSK(FileName file)
Read a NAIF type 2 DSK file into a PointCloudLibrary polygon mesh.
Definition: EmbreeTargetShape.cpp:310
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::RayHitInformation::intersection
LinearAlgebra::Vector intersection
The (x, y, z) intersection location.
Definition: EmbreeTargetShape.h:122