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"
92 PvlGroup &kernels = pvl.findGroup(
"Kernels", Pvl::Traverse);
95 if (kernels.hasKeyword(
"ElevationModel")) {
96 shapefile = (QString) kernels[
"ElevationModel"];
99 shapefile = (QString) kernels[
"ShapeModel"];
103 if (v_shape.isNull() ) {
104 QString mess =
"Cannot create a BulletShape from " + shapefile;
105 throw IException(IException::User, mess, _FILEINFO_);
111 m_model->addTarget( v_shape.take() );
129 btAssert ( shape != 0 );
131 m_model->addTarget( shape );
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]);
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) ) {
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";
441 throw IException(IException::Programmer, mess, _FILEINFO_);
471 const std::vector<double> lookDirection) {
477 btVector3 observer(observerPos[0], observerPos[1], observerPos[2]);
478 btVector3 psB = (observer -
m_intercept.point()).normalized();
479 btScalar angle = std::acos(
m_intercept.normal().dot( psB ) ) * RAD2DEG;
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";
521 throw IException(IException::Programmer, mess, _FILEINFO_);
545 return m_model->getTarget()->maximumDistance();
561 const btVector3 &lookdir)
const {
562 btScalar lookScale = observer.length() +
maxDistance();
563 return ( observer + lookdir.normalized() * lookScale );
579 double latAngle = lat.
radians();
580 double lonAngle = lon.
radians();
581 btVector3 lookDir( cos(latAngle) * cos(lonAngle),
582 cos(latAngle) * sin(lonAngle),
627 const btVector3 &sortPoint)
const {
629 for (
int i = 0 ; i < hits.
size() ; i++) {
631 sortMap.insert( hit.
distance(sortPoint), hit );
double radians() const
Convert an angle to a double.
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.
int size() const
Returns the number of intersections found.
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
!
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...
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.
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.
void setLocalNormalFromIntercept()
Set the normal vector to the intercept point normal.
btScalar maxDistance() const
!
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.
This class is designed to encapsulate the concept of a Latitude.
This class is designed to encapsulate the concept of a Longitude.
virtual void clearSurfacePoint()
Clears or resets the current surface point.
bool hasIntersection()
Returns intersection status.
void setLocalNormal(const std::vector< double >)
Sets the local normal for the currect intersection point.
virtual void setSurfacePoint(const SurfacePoint &surfacePoint)
Set surface intersection point.
virtual std::vector< double > normal()
Returns the surface normal at the current intersection point.
void setHasLocalNormal(bool status)
Sets the flag to indicate whether this ShapeModel has a local normal.
ShapeModel()
Default constructor creates ShapeModel object, initializing name to an empty string,...
void setName(QString name)
Sets the shape name.
This class defines a body-fixed surface point.
void ToNaifArray(double naifOutput[3]) const
A naif array is a c-style array of size 3.
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.
Namespace for the standard library.