Isis Developer Reference
EmbreeTargetShape.h
Go to the documentation of this file.
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
FileName.h
Isis::IException::Io
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:155
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
NaifDskApi.h
Isis::RayHitInformation::RayHitInformation
RayHitInformation()
Default constructor for RayHitInformation.
Definition: EmbreeTargetShape.cpp:196
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::FileName::fileExists
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:449
NaifStatus.h
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::LinearAlgebra::magnitude
static double magnitude(const Vector &vector)
Computes the magnitude (i.e., the length) of the given vector using the Euclidean norm (L2 norm).
Definition: LinearAlgebra.cpp:504
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::LinearAlgebra::vector
static Vector vector(double v0, double v1, double v2)
Constructs a 3 dimensional vector with the given component values.
Definition: LinearAlgebra.cpp:1714
Isis::NaifStatus::CheckErrors
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:28
Isis::RayHitInformation
Container that holds the body fixed intersection point and unit surface normal for a hit.
Definition: EmbreeTargetShape.h:118
EmbreeTargetShape.h
Isis::RTCOcclusionRay::lastHit
int lastHit
Index of the last hit in the hit containers.
Definition: EmbreeTargetShape.h:105
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::RTCMultiHitRay::hitPrimIDs
unsigned hitPrimIDs[16]
IDs of the primitives (trinagles) hit.
Definition: EmbreeTargetShape.h:68
IString.h
Isis::FileName::baseName
QString baseName() const
Returns the name of the file without the path and without extensions.
Definition: FileName.cpp:145
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
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
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
Pvl.h
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::RTCMultiHitRay
Struct for capturing multiple intersections when using embree::rtcintersectscene.
Definition: EmbreeTargetShape.h:44
Isis::EmbreeTargetShape::sceneBounds
RTCBounds sceneBounds() const
Returns the bounds of the Embree scene.
Definition: EmbreeTargetShape.cpp:577
Isis::LinearAlgebra::normalize
static Vector normalize(const Vector &vector)
Returns a unit vector that is codirectional with the given vector by dividing each component of the v...
Definition: LinearAlgebra.cpp:477
Isis::IException
Isis exception class.
Definition: IException.h:91
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::RTCOcclusionRay::ignorePrimID
unsigned ignorePrimID
IDs of the primitives (trinagles) which should be ignored.
Definition: EmbreeTargetShape.h:106
Isis::FileName::extension
QString extension() const
Returns the last extension of the file name.
Definition: FileName.cpp:178
IException.h
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
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
LinearAlgebra.h
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::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::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
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126