47 tfar = std::numeric_limits<float>::infinity();
52 geomID = RTC_INVALID_GEOMETRY_ID;
53 primID = RTC_INVALID_GEOMETRY_ID;
54 instID = RTC_INVALID_GEOMETRY_ID;
74 const std::vector<double> &direction) {
76 tfar = std::numeric_limits<float>::infinity();
81 geomID = RTC_INVALID_GEOMETRY_ID;
82 primID = RTC_INVALID_GEOMETRY_ID;
83 instID = RTC_INVALID_GEOMETRY_ID;
87 dir[0] = direction[0];
88 dir[1] = direction[1];
89 dir[2] = direction[2];
106 tfar = std::numeric_limits<float>::infinity();
111 geomID = RTC_INVALID_GEOMETRY_ID;
112 primID = RTC_INVALID_GEOMETRY_ID;
113 instID = RTC_INVALID_GEOMETRY_ID;
117 dir[0] = direction[0];
118 dir[1] = direction[1];
119 dir[2] = direction[2];
131 tfar = std::numeric_limits<float>::infinity();
137 geomID = RTC_INVALID_GEOMETRY_ID;
138 primID = RTC_INVALID_GEOMETRY_ID;
139 instID = RTC_INVALID_GEOMETRY_ID;
159 const std::vector<double> &direction) {
161 tfar = std::numeric_limits<float>::infinity();
166 geomID = RTC_INVALID_GEOMETRY_ID;
168 instID = RTC_INVALID_GEOMETRY_ID;
172 dir[0] = direction[0];
173 dir[1] = direction[1];
174 dir[2] = direction[2];
190 tfar = std::numeric_limits<float>::infinity();
195 geomID = RTC_INVALID_GEOMETRY_ID;
197 instID = RTC_INVALID_GEOMETRY_ID;
201 dir[0] = direction[0];
202 dir[1] = direction[1];
203 dir[2] = direction[2];
231 : intersection(location),
232 surfaceNormal(normal) ,
246 m_device(rtcNewDevice(NULL)),
247 m_scene(rtcDeviceNewScene(m_device,
248 RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY | RTC_SCENE_ROBUST,
262 m_device(rtcNewDevice(NULL)),
263 m_scene(rtcDeviceNewScene(m_device,
264 RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY | RTC_SCENE_ROBUST,
284 m_device(rtcNewDevice(NULL)),
285 m_scene(rtcDeviceNewScene(m_device,
286 RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY | RTC_SCENE_ROBUST,
289 pcl::PolygonMesh::Ptr mesh;
295 QString msg =
"DEMs cannot be used to create an EmbreeTargetShape.";
308 QString msg =
"Failed creating an EmbreeTargetShape from [" 331 SpiceDLADescr dlaDescriptor;
333 SpiceDSKDescr dskDescriptor;
335 SpiceInt numVertices;
339 QString mess =
"NAIF DSK file [" + file.
expanded() +
"] does not exist.";
344 dasopr_c( file.
expanded().toLatin1().data(), &dskHandle );
349 dlabfs_c( dskHandle, &dlaDescriptor, &found );
352 QString mess =
"No segments found in DSK file [" + file.
expanded() +
"]";
356 dskgd_c( dskHandle, &dlaDescriptor, &dskDescriptor );
360 dskz02_c( dskHandle, &dlaDescriptor, &numVertices, &numPlates );
367 double *verticesArray =
new double[numVertices * 3];
368 int *polygonsArray =
new int[numPlates * 3];
371 SpiceInt numRead = 0;
372 dskv02_c(dskHandle, &dlaDescriptor, 1, numVertices,
373 &numRead, ( SpiceDouble(*)[3] )(verticesArray) );
375 if ( numRead != numVertices ) {
376 QString msg =
"Failed reading all vertices from the DSK file, [" 378 +
toString(numVertices) +
"] vertices read.";
384 dskp02_c(dskHandle, &dlaDescriptor, 1, numPlates,
385 &numRead, ( SpiceInt(*)[3] )(polygonsArray) );
387 if ( numRead != numPlates ) {
388 QString msg =
"Failed reading all polygons from the DSK file, [" 390 +
toString(numPlates) +
"] polygons read.";
395 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
396 for (
int vertexIndex = 0; vertexIndex < numVertices; ++vertexIndex) {
397 cloud->push_back(pcl::PointXYZ(verticesArray[vertexIndex * 3],
398 verticesArray[vertexIndex * 3 + 1],
399 verticesArray[vertexIndex * 3 + 2]));
403 std::vector<pcl::Vertices> polygons;
404 for (
int plateIndex = 0; plateIndex < numPlates; ++plateIndex) {
405 pcl::Vertices vertexIndices;
407 vertexIndices.vertices.push_back(polygonsArray[plateIndex * 3] - 1);
408 vertexIndices.vertices.push_back(polygonsArray[plateIndex * 3 + 1] - 1);
409 vertexIndices.vertices.push_back(polygonsArray[plateIndex * 3 + 2] - 1);
410 polygons.push_back(vertexIndices);
414 pcl::PolygonMesh::Ptr mesh(
new pcl::PolygonMesh);
415 mesh->polygons = polygons;
416 pcl::PCLPointCloud2::Ptr cloudBlob(
new pcl::PCLPointCloud2);
417 pcl::toPCLPointCloud2(*cloud, *cloudBlob);
418 mesh->cloud = *cloudBlob;
421 delete [] verticesArray;
422 delete [] polygonsArray;
438 pcl::PolygonMesh::Ptr mesh(
new pcl::PolygonMesh );
440 int loadStatus = pcl::io::load(file.
expanded().toStdString(), *mesh);
441 if (loadStatus == -1) {
442 QString msg =
"Failed loading target shape file [" + file.
expanded() +
"]";
471 pcl::fromPCLPointCloud2(mesh->cloud,
m_cloud);
474 unsigned geomID = rtcNewTriangleMesh(
m_scene,
484 rtcSetIntersectionFilterFunction(
m_scene, geomID,
488 rtcSetOcclusionFilterFunction(
m_scene, geomID,
512 vertices[v].
x =
m_cloud.points[v].x;
513 vertices[v].
y =
m_cloud.points[v].y;
514 vertices[v].
z =
m_cloud.points[v].z;
517 rtcUnmapBuffer(
m_scene, geomID, RTC_VERTEX_BUFFER);
537 triangles[t].
v0 =
m_mesh->polygons[t].vertices[0];
538 triangles[t].
v1 =
m_mesh->polygons[t].vertices[1];
539 triangles[t].
v2 =
m_mesh->polygons[t].vertices[2];
542 rtcUnmapBuffer(
m_scene, geomID, RTC_INDEX_BUFFER);
564 return m_mesh->polygons.size();
620 diagonal[0] = sceneBoundary.upper_x - sceneBoundary.lower_x;
621 diagonal[1] = sceneBoundary.upper_y - sceneBoundary.lower_y;
622 diagonal[2] = sceneBoundary.upper_z - sceneBoundary.lower_z;
674 if (ray.geomID == 0) {
701 if (hitIndex > ray.
lastHit || hitIndex < 0) {
702 QString msg =
"Hit index [" +
toString(hitIndex) +
"] is out of bounds.";
715 float u = ray.
hitUs[hitIndex];
716 float v = ray.
hitVs[hitIndex];
717 float w = 1.0 - u - v;
720 intersection[0] = w*v0.x + v*v1.x + u*v2.x;
721 intersection[1] = w*v0.y + v*v1.y + u*v2.y;
722 intersection[2] = w*v0.z + v*v1.z + u*v2.z;
729 surfaceNormal[0] = (v1.y - v0.y) * (v2.z - v0.z)
730 - (v1.z - v0.z) * (v2.y - v0.y);
731 surfaceNormal[1] = (v1.z - v0.z) * (v2.x - v0.x)
732 - (v1.x - v0.x) * (v2.z - v0.z);
733 surfaceNormal[2] = (v1.x - v0.x) * (v2.y - v0.y)
734 - (v1.y - v0.y) * (v2.x - v0.x);
783 ray.geomID = RTC_INVALID_GEOMETRY_ID;
801 ray.geomID = RTC_INVALID_GEOMETRY_ID;
static Vector vector(double v0, double v1, double v2)
Constructs a 3 dimensional vector with the given component values.
unsigned hitGeomIDs[16]
IDs of the geometries (bodies) hit.
int numberOfVertices() const
Return the number of vertices in the target shape.
File name manipulation and expansion.
RTCMultiHitRay()
Default constructor for RTCMultiHitRay.
RTCOcclusionRay()
Default constructor for RTCOcclussionRay.
int numberOfPolygons() const
Return the number of polygons in the target shape.
int lastHit
Index of the last hit in the hit containers.
static double magnitude(const Vector &vector)
Computes the magnitude (i.e., the length) of the given vector using the Euclidean norm (L2 norm)...
double maximumSceneDistance() const
Return the maximum distance within the scene.
Struct for capturing multiple intersections when using embree::rtcintersectscene. ...
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
static Vector normalize(const Vector &vector)
Returns a unit vector that is codirectional with the given vector by dividing each component of the v...
pcl::PolygonMesh::Ptr readPC(FileName file)
Read a PointCloudLibrary file into a PointCloudLibrary polygon mesh.
This error is for when a programmer made an API call that was illegal.
A type of error that occurred when performing an actual I/O operation.
unsigned hitPrimIDs[16]
IDs of the primitives (trinagles) hit.
virtual ~EmbreeTargetShape()
Desctructor.
float hitUs[16]
Barycentric u coordinate of the hits.
void addIndices(int geomID)
Adds the polygon vertex indices from the internalized polygon mesh to the Embree scene.
Container for a tin, or triangular polygon.
int v1
The index of the second vertex in the tin.
boost::numeric::ublas::vector< double > Vector
Definition for an Isis::LinearAlgebra::Vector of doubles.
void initMesh(pcl::PolygonMesh::Ptr mesh)
Internalize a PointCloudLibrary polygon mesh in the target shape.
float y
Vertex y position.
RTCScene m_scene
!< The Embree device for rendering the scene.
#define _FILEINFO_
Macro for the filename and line number.
unsigned ignorePrimID
IDs of the primitives (trinagles) which should be ignored.
A type of error that could only have occurred due to a mistake on the user's part (e...
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
int v0
The index of the first vertex in the tin.
float x
Vertex x position.
void addVertices(int geomID)
Adds the vertices from the internalized vertex point cloud to the Embree scene.
void intersectRay(RTCMultiHitRay &ray)
Intersect a ray with the target shape.
pcl::PolygonMesh::Ptr m_mesh
!< The name of the target.
RTCBounds sceneBounds() const
Returns the bounds of the Embree scene.
Container for cube-like labels.
float hitVs[16]
Barycentric v coordinate of the hits.
QString baseName() const
Returns the name of the file without the path and without extensions.
RayHitInformation getHitInformation(RTCMultiHitRay &ray, int hitIndex)
Extract the intersection point and unit surface normal from an RTCMultiHitRay that has been intersect...
QString name() const
Return the name of the target shape.
Struct for capturing occluded plates when using embree::rtcintersectscene.
bool isValid() const
Return if a valid mesh is internalized and ready for use.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Namespace for ISIS/Bullet specific routines.
QString extension() const
Returns the last extension of the file name.
EmbreeTargetShape()
Default empty constructor.
int lastHit
Index of the last hit in the hit containers.
bool isOccluded(RTCOcclusionRay &ray)
Check if a ray intersects the target body.
RTCDevice m_device
!< The point cloud representation of the target.
pcl::PointCloud< pcl::PointXYZ > m_cloud
!< A boost shared pointer to the polygon mesh representation of the target.
static void occlusionFilter(void *userDataPtr, RTCOcclusionRay &ray)
Filter function for collecting multiple primitiveIDs This function is called by the Embree library du...
bool fileExists() const
Returns true if the file exists; false otherwise.
int v2
The index of the third vertex in the tin.
float z
Vertex z position.
static void multiHitFilter(void *userDataPtr, RTCMultiHitRay &ray)
Filter function for collecting multiple hits during ray intersection.
pcl::PolygonMesh::Ptr readDSK(FileName file)
Read a NAIF type 2 DSK file into a PointCloudLibrary polygon mesh.