25#include "BulletShapeModel.h"
32#include "IException.h"
37#include "NaifStatus.h"
39#include "ShapeModel.h"
40#include "SpecialPixel.h"
41#include "Statistics.h"
42#include "SurfacePoint.h"
54 m_intercept(btVector3(0,0,0), btVector3(0,0,0)) {
79 ShapeModel(target), m_model(), m_tolerance(DBL_MAX),
80 m_intercept(btVector3(0,0,0), btVector3(0,0,0)) {
96 shapefile = (QString) kernels[
"ElevationModel"];
99 shapefile = (QString) kernels[
"ShapeModel"];
103 if (v_shape.isNull() ) {
104 QString mess =
"Cannot create a BulletShape from " + shapefile;
111 m_model->addTarget( v_shape.take() );
125 ShapeModel(target), m_model(), m_tolerance(DBL_MAX),
126 m_intercept(btVector3(0,0,0), btVector3(0,0,0)) {
129 btAssert ( shape != 0 );
131 m_model->addTarget( shape );
146 ShapeModel(target), m_model(model), m_tolerance(DBL_MAX),
147 m_intercept(btVector3(0,0,0), btVector3(0,0,0)) {
194 std::vector<double> lookDirection) {
197 btVector3 observer(observerPos[0], observerPos[1], observerPos[2]);
198 btVector3 lookdir(lookDirection[0], lookDirection[1], lookDirection[2]);
201 bool success = m_model->raycast(observer, rayEnd, result);
225 const std::vector<double> &observerPos,
226 const bool &checkOcclusion) {
230 btVector3 origin(0.0, 0.0, 0.0);
236 if ( !m_model->raycast(origin, rayEnd, results) ) {
241 btVector3 observer(observerPos[0], observerPos[1], observerPos[2]);
242 QVector<BulletClosestRayCallback> points =
sortHits(results, observer);
245 if ( checkOcclusion ) {
246 for (
int i = 0 ; i < points.size() ; i++) {
288 const std::vector<double> &observerPos,
289 const bool &checkOcclusion) {
293 btVector3 origin(0.0, 0.0, 0.0);
295 btVector3 rayEnd =
castLookDir(origin, surfPointVec);
300 if ( !m_model->raycast(origin, rayEnd, results) ) {
305 QVector<BulletClosestRayCallback> points =
sortHits(results, surfPointVec);
308 if ( checkOcclusion ) {
309 btVector3 observer(observerPos[0], observerPos[1], observerPos[2]);
310 for (
int i = 0 ; i < points.size() ; i++) {
343 const btVector3 &observer)
const {
351 btVector3 psB = (observer - hit.
point()).normalized();
352 btScalar angle = std::acos( hit.
normal().dot( psB ) ) *
RAD2DEG;
353 if ( std::fabs( angle ) > 90.0 - DBL_MIN) {
360 if ( !m_model->raycast(observer, hit.
point(), results) ) {
380 std::vector<double> fakepos(3, 0.0);
414 btVector3 origin(0.0, 0.0, 0.0);
419 if ( m_model->raycast(origin, rayEnd, result) ) {
440 QString mess =
"Intercept point does not exist - cannot provide normal vector";
471 const std::vector<double> lookDirection) {
477 btVector3 observer(observerPos[0], observerPos[1], observerPos[2]);
480 if ( std::fabs( angle ) > 90.0 - DBL_MIN) {
484 btVector3 rayEnd =
castLookDir( observer, btVector3(lookDirection[0], lookDirection[1], lookDirection[2]) );
486 (void) m_model->raycast(observer, rayEnd, results);
520 QString mess =
"Intercept point does not exist - cannot provide normal vector";
542 setNormal(std::vector<double>(norm.begin(), norm.end()));
564 QString msg =
"An intersection must be defined before computing the surface normal.";
569 QString msg =
"The surface point intersection must be valid to compute the surface normal.";
574 QString msg =
"A valid target must be defined before computing the surface normal.";
583 QVector<double> norm(3);
586 QVector<Distance> radii = QVector<Distance>(stdRadii.begin(), stdRadii.end());
588 surfnm_c(radii[0].kilometers(), radii[1].kilometers(), radii[2].kilometers(),
613 return m_model->getTarget()->maximumDistance();
629 const btVector3 &lookdir)
const {
630 btScalar lookScale = observer.length() +
maxDistance();
631 return ( observer + lookdir.normalized() * lookScale );
647 double latAngle = lat.radians();
648 double lonAngle = lon.radians();
649 btVector3 lookDir( cos(latAngle) * cos(lonAngle),
650 cos(latAngle) * sin(lonAngle),
665 surfpt.ToNaifArray( &point[0] );
695 const btVector3 &sortPoint)
const {
696 QMap<btScalar, BulletClosestRayCallback> sortMap;
697 for (
int i = 0 ; i < hits.size() ; i++) {
699 sortMap.insert( hit.
distance(sortPoint), hit );
Bullet ray tracing callback to return all intersections along a ray's path.
const BulletClosestRayCallback & hit(const int &index=0) const
Return a callback for the intersection at a given index.
Bullet ray tracing callback for closest hit on target surface.
btScalar distance() const
Returns the distance from the intersection point to the beginning of the ray.
bool isValid() const
Checks if the callback is valid/has a valid intersection.
btVector3 point() const
Return the intersection point, if one exists.
bool isVisible(const BulletClosestRayCallback &other, const btScalar tolerance=DBL_MAX) const
Check if the intersection in this is visible based on another callback.
btVector3 normal() const
Return the local surface normal at the intersection, if an intersection exists.
const BulletWorldManager & model() const
Returns a direct reference to the Bullet world that contains the target shape and can perform ray cas...
BulletClosestRayCallback m_intercept
! Tolerance of occlusion check in kilometers.
void calculateSurfaceNormal()
compute the ellipsoid surface normal of the target
void updateShapeModel(const BulletClosestRayCallback &result)
Update shape model - carefully!!
void calculateLocalNormal(QVector< double * > cornerNeighborPoints)
Compute the normal for a local region of surface points.
Distance localRadius(const Latitude &lat, const Longitude &lon)
Compute the radius of the body at a lat/lon point.
SurfacePoint makeSurfacePoint(const btVector3 &point) const
Convert a vector into a surface point.
btVector3 latlonToVector(const Latitude &lat, const Longitude &lon) const
Convert a pair of latitude and longitude values into a unit vector pointing from the origin of the bo...
QVector< double > ellipsoidNormal()
Compute the true surface normal vector of an ellipsoid.
double getTolerance() const
Returns the occlusion tolerance in kilometers.
virtual bool isVisibleFrom(const std::vector< double > observerPos, const std::vector< double > lookDirection)
Check if the saved intercept is visible from a observer with a given look direction.
BulletShapeModel()
Default constructor that creates a shape model without any internal model.
void calculateDefaultNormal()
Calculate the surface normal of the ellipsoid as the default.
btVector3 castLookDir(const btVector3 &observer, const btVector3 &lookdir) const
Compute the end point of a ray based on an observer and look direction.
QVector< BulletClosestRayCallback > sortHits(const BulletAllHitsRayCallback &hits, const btVector3 &sortPoint) const
Sort the hits in an AllHitsRayCallback based on distance to a point.
~BulletShapeModel()
Destructor.
virtual void clearSurfacePoint()
Clear the saved surface point and reset the saved intersection.
double m_tolerance
! Bullet collision world that contains the representation of the body.
void setLocalNormalFromIntercept()
Set the normal vector to the intercept point normal.
btScalar maxDistance() const
! The results of the last ray cast.
bool isDEM() const
Indicates that this shape model is not from a DEM.
bool isOccluded(const BulletClosestRayCallback &hit, const btVector3 &observer) const
Check if an intersection is occluded from an observer.
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
This method computes a DEM intercept point given an observer location and look direction using the Bu...
virtual void setSurfacePoint(const SurfacePoint &surfacePoint)
Set the internal surface point.
btVector3 pointToVector(const SurfacePoint &point) const
Convert a surface point into a vector.
void setTolerance(const double &tolerance)
Sets the occlusion tolerance.
Bullet Target Shape for planetary bodies.
static BulletTargetShape * load(const QString &dem, const Pvl *conf=0)
Load a DEM file into the target shape.
QString name() const
Return name of the target shape.
Bullet World manager maintains a proper state for target bodies.
Distance measurement, usually in meters.
@ Kilometers
The distance is being specified in kilometers.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
This class is designed to encapsulate the concept of a Latitude.
This class is designed to encapsulate the concept of a Longitude.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Contains multiple PvlContainers.
Container for cube-like labels.
@ Traverse
Search child objects.
Define shapes and provide utilities for Isis targets.
virtual void clearSurfacePoint()
Clears or resets the current surface point.
bool hasIntersection()
Returns intersection status.
void setNormal(const std::vector< double >)
Sets the surface normal for the currect intersection point.
void setLocalNormal(const std::vector< double >)
Sets the local normal for the currect intersection point.
virtual SurfacePoint * surfaceIntersection() const
Returns the surface intersection for this ShapeModel.
bool hasValidTarget() const
Returns the status of the target.
virtual void setSurfacePoint(const SurfacePoint &surfacePoint)
Set surface intersection point.
virtual std::vector< double > normal()
Returns the surface normal at the current intersection point.
std::vector< Distance > targetRadii() const
Returns the radii of the body in km.
void setHasLocalNormal(bool status)
Sets the flag to indicate whether this ShapeModel has a local normal.
void setName(QString name)
Sets the shape name.
This class defines a body-fixed surface point.
void FromNaifArray(const double naifValues[3])
A naif array is a c-style array of size 3.
This class is used to create and store valid Isis targets.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
const double RAD2DEG
Multiplier for converting from radians to degrees.
Namespace for the standard library.