Skip to content

Commit

Permalink
ShapeModel Normal State Fix (#5345)
Browse files Browse the repository at this point in the history
* Adds local normal member variable to shapemodel

* Fixes variable initialization and sets local normal properly in bullet

* Update tests and truth data

* Fixed up documentation in ShapeModel.h

* Handled cases where the hasLocalNormal flag should be set to false

* Fixed tests

* Fixed gtests

* Addressed PR feedback

* Fixed more typos

* Further adjusted truth data for test

* Added changelog

---------

Co-authored-by: Kelvin Rodriguez <krodriguez@usgs.gov>
  • Loading branch information
acpaquette and Kelvinrr authored Mar 18, 2024
1 parent c603772 commit c70dd7c
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ release.
outputsuffix, both, or neither for naming convention purposes. [#5162](https://github.com/DOI-USGS/ISIS3/pull/5162)
- Changed the default PCK load behavior to try and load mission specific PCKs, if that fails we default to the base PCKs [#5335](https://github.com/DOI-USGS/ISIS3/pull/5335)
- Disabled option to use web=true when running spiceinit with HRSC images. [#5223](https://github.com/DOI-USGS/ISIS3/issues/5223)
- Seperated `normal` and `localNormal` in ISIS shapemodels, now the local normal is stored in its own member variable with setters and getters. [#5345](https://github.com/DOI-USGS/ISIS3/pull/5345)
- Set build option `pybindings=ON` in `build.sh` to turn on python bindings. [#5389](https://github.com/DOI-USGS/ISIS3/pull/5389)
- Updated Ale to version 0.10.0 [#5399](https://github.com/DOI-USGS/ISIS3/pull/5399)

Expand Down
6 changes: 3 additions & 3 deletions isis/src/base/objs/BulletShapeModel/BulletShapeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ namespace Isis {
}

btVector3 normal = m_intercept.normal();
setNormal(normal[0], normal[1], normal[2]);
setLocalNormal(normal[0], normal[1], normal[2]);
}


Expand Down Expand Up @@ -719,11 +719,11 @@ namespace Isis {
ShapeModel::setSurfacePoint( makeSurfacePoint(m_intercept.point()) ); // sets ShapeModel::m_hasIntersection=t, ShapeModel::m_hasNormal=f

btVector3 normal = m_intercept.normal();
setNormal(normal[0], normal[1], normal[2]);
setLocalNormal(normal[0], normal[1], normal[2]);
}
else {
ShapeModel::clearSurfacePoint();
setHasNormal(false);
setHasLocalNormal(false);
}

return;
Expand Down
8 changes: 4 additions & 4 deletions isis/src/base/objs/BulletShapeModel/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ void outputModelStatus(BulletShapeModel &bulletModel) {
<< intersection->GetY().kilometers() << ", "
<< intersection->GetZ().kilometers() << ")";
}
qDebug() << "Model has normal? " << bulletModel.hasNormal();
qDebug() << "Model has normal? " << bulletModel.hasLocalNormal();
std::vector<double> normal;
if ( bulletModel.hasNormal() ) {
normal = bulletModel.normal();
if ( bulletModel.hasLocalNormal() ) {
normal = bulletModel.localNormal();
qDebug() << " Local Normal: ("
<< normal[0] << ", "
<< normal[1] << ", "
Expand All @@ -238,7 +238,7 @@ void outputModelStatus(BulletShapeModel &bulletModel) {
<< normal[1] << ", "
<< normal[2] << ")";
bulletModel.setLocalNormalFromIntercept();
normal = bulletModel.normal();
normal = bulletModel.localNormal();
qDebug() << " Recalculated Local Normal: ("
<< normal[0] << ", "
<< normal[1] << ", "
Expand Down
4 changes: 2 additions & 2 deletions isis/src/base/objs/Camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ namespace Isis {
}

// restore input state if calculation failed and clean up.
if (!shapeModel->hasNormal()) {
if (!shapeModel->hasLocalNormal()) {
p_pointComputed = false;
return;
}
Expand All @@ -1634,7 +1634,7 @@ namespace Isis {

// Set the method normal values
std::vector<double> localNormal(3);
localNormal = shapeModel->normal();
localNormal = shapeModel->localNormal();
memcpy(normal, (double *) &localNormal[0], sizeof(double) * 3);
}

Expand Down
12 changes: 6 additions & 6 deletions isis/src/base/objs/DemShape/DemShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ namespace Isis {
std::vector<SpiceDouble> normal(3);
if (neighborPoints.isEmpty()) {
normal[0] = normal[1] = normal[2] = 0.0;
setNormal(normal);
setHasNormal(false);
setLocalNormal(normal);
setHasLocalNormal(false);
return;
}

Expand All @@ -389,12 +389,12 @@ namespace Isis {

if (mag == 0.0) {
normal[0] = normal[1] = normal[2] = 0.0;
setNormal(normal);
setHasNormal(false);
setLocalNormal(normal);
setHasLocalNormal(false);
return;
}
else {
setHasNormal(true);
setHasLocalNormal(true);
}

// Check to make sure that the normal is pointing outward from the planet
Expand All @@ -410,7 +410,7 @@ namespace Isis {
vminus_c((SpiceDouble *) &normal[0], (SpiceDouble *) &normal[0]);
}

setNormal(normal);
setLocalNormal(normal);
}


Expand Down
6 changes: 3 additions & 3 deletions isis/src/base/objs/DemShape/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int main() {

shape.calculateLocalNormal(neighborPoints);
vector<double> myNormal(3);
myNormal = shape.normal();
myNormal = shape.localNormal();
cout << " local normal = (" << myNormal[0] << ", " << myNormal[1] << ", " << myNormal[2] << endl;

cout << endl << " Testing class method calculateSurfaceNormal..." << endl;
Expand Down Expand Up @@ -212,7 +212,7 @@ int main() {
neighborPoints[3][2] = 1193.88;
cout << endl << " Testing method calculateLocalNormal with vector pointing outward" << endl;
shape.calculateLocalNormal(neighborPoints);
myNormal = shape.normal();
myNormal = shape.localNormal();
cout << " local normal = (" << myNormal[0] << ", " << myNormal[1] << ", " << myNormal[2] << endl;

// Test calculateLocalNormal with magnitude = 0
Expand All @@ -221,7 +221,7 @@ int main() {
neighborPoints[3][1] = -2380.59;
cout << endl << " Testing method calculateLocalNormal with magnitude = 0" << endl;
shape.calculateLocalNormal(neighborPoints);
myNormal = shape.normal();
myNormal = shape.localNormal();
cout << " local normal = (" << myNormal[0] << ", " << myNormal[1] << ", " << myNormal[2] << ")" << endl;
}
catch(Isis::IException &e) {
Expand Down
9 changes: 5 additions & 4 deletions isis/src/base/objs/EllipsoidShape/EllipsoidShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ namespace Isis {
*
*/
void EllipsoidShape::calculateDefaultNormal() {
QVector <double *> points;
calculateLocalNormal(points);
calculateSurfaceNormal();
}


Expand All @@ -71,6 +70,8 @@ namespace Isis {
void EllipsoidShape::calculateSurfaceNormal() {
QVector <double *> points;
calculateLocalNormal(points);

setNormal(localNormal());
}


Expand Down Expand Up @@ -129,8 +130,8 @@ namespace Isis {
surfnm_c(a, b, c, pB, (SpiceDouble *) &normal[0]);
NaifStatus::CheckErrors();

setNormal(normal);
setHasNormal(true);
setLocalNormal(normal);
setHasLocalNormal(true);
}


Expand Down
2 changes: 1 addition & 1 deletion isis/src/base/objs/EllipsoidShape/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int main() {

shape.calculateLocalNormal(notUsed);
vector<double> myNormal(3);
myNormal = shape.normal();
myNormal = shape.localNormal();

//Hand-calculated truth value: [-0.6196003462957385, -0.7004971412244801, 0.3541174466282787]

Expand Down
1 change: 1 addition & 0 deletions isis/src/base/objs/EmbreeShapeModel/EmbreeShapeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ namespace Isis {
void EmbreeShapeModel::clearSurfacePoint() {
ShapeModel::clearSurfacePoint();
setHasNormal(false);
setHasLocalNormal(false);
return;
}

Expand Down
6 changes: 3 additions & 3 deletions isis/src/base/objs/NaifDskShape/NaifDskShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace Isis {


/**
* @brief Set the normal vector to the intercept point normal
* @brief Set the local normal vector to the intercept point normal
*
* This method will reassign the ShapeModel normal to the current intecept point
* shape (which is a triangular plate) normal. If an intercept point is not
Expand All @@ -220,7 +220,7 @@ namespace Isis {

// Got it, use the existing intercept point (plate) normal
NaifVector norm(m_intercept->normal());
setNormal(norm[0], norm[1], norm[2]); // this also takes care of setHasNormal(true);
setLocalNormal(norm[0], norm[1], norm[2]); // this also takes care of setHasLocalNormal(true);
return;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ namespace Isis {
}


/** Return the surface normal of the ellipsi=oud */
/** Return the surface normal of the ellipsoid */
void NaifDskShape::calculateSurfaceNormal() {
// ShapeModel (parent class) throws error if no intersection
setNormal(ellipsoidNormal().toStdVector());// this takes care of setHasNormal(true);
Expand Down
8 changes: 4 additions & 4 deletions isis/src/base/objs/NaifDskShape/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ int main(int argc, char *argv[]) {

qDebug() << "Try to calculate norms using valid shape model...";
shapeModelFromPvlElevation.setLocalNormalFromIntercept();
qDebug() << "Has intercept normal? " << shapeModelFromPvlElevation.hasNormal();
qDebug() << "Has intercept normal? " << shapeModelFromPvlElevation.hasLocalNormal();
qDebug() << "Normal set from Intercept: "
<< QVector<double>::fromStdVector(shapeModelFromPvlElevation.normal());
<< QVector<double>::fromStdVector(shapeModelFromPvlElevation.localNormal());
// no need to call calculateSurfaceNormal() or ellipsoidNormal()
// directly. these methods are called by calculateDefaultNormal()
shapeModelFromPvlElevation.calculateDefaultNormal();
Expand All @@ -172,9 +172,9 @@ int main(int argc, char *argv[]) {
point[0] = 1.0; point[1] = 0.0; point[2] = 0.0;
cornerNeighborPoints.push_back(point);
shapeModelFromPvlElevation.calculateLocalNormal(cornerNeighborPoints);
qDebug() << "Has local normal? " << shapeModelFromPvlElevation.hasNormal();
qDebug() << "Has local normal? " << shapeModelFromPvlElevation.hasLocalNormal();
qDebug() << "Local normal from neighbor points: "
<< QVector<double>::fromStdVector(shapeModelFromPvlElevation.normal());
<< QVector<double>::fromStdVector(shapeModelFromPvlElevation.localNormal());
qDebug() << "";

qDebug() << "================================= Error Throws ==================================";
Expand Down
Loading

0 comments on commit c70dd7c

Please sign in to comment.