diff --git a/isis/src/base/objs/SpicePosition/SpicePosition.cpp b/isis/src/base/objs/SpicePosition/SpicePosition.cpp index 0414ed0885..1cf7eda039 100644 --- a/isis/src/base/objs/SpicePosition/SpicePosition.cpp +++ b/isis/src/base/objs/SpicePosition/SpicePosition.cpp @@ -101,12 +101,11 @@ namespace Isis { p_timeBias = 0.0; p_timeScale = 1.; p_velocity.resize(3); - p_xhermite = NULL; - p_yhermite = NULL; - p_zhermite = NULL; + m_swapObserverTarget = swapObserverTarget; m_lt = 0.0; + m_state = NULL; // Determine observer/target ordering if ( m_swapObserverTarget ) { @@ -245,7 +244,10 @@ namespace Isis { NaifStatus::CheckErrors(); // Save the time - if(et == p_et) return p_coordinate; + if(et == p_et) { + return p_coordinate; + } + p_et = et; // Read from the cache @@ -310,13 +312,22 @@ namespace Isis { LoadTimeCache(); // Loop and load the cache + std::vector stateCache; for(int i = 0; i < size; i++) { double et = p_cacheTime[i]; SetEphemerisTime(et); - p_cache.push_back(p_coordinate); - if(p_hasVelocity) p_cacheVelocity.push_back(p_velocity); + ale::State currentState = ale::State(ale::Vec3d(p_coordinate)); + if (p_hasVelocity) { + currentState.velocity = ale::Vec3d(p_velocity); + } + stateCache.push_back(currentState); + } + + if (m_state != NULL) { + delete m_state; } + m_state = new ale::States(p_cacheTime, stateCache); p_source = Memcache; } @@ -359,25 +370,31 @@ namespace Isis { p_fullCacheSize = isdPos["spk_table_original_size"].get(); p_cacheTime = isdPos["ephemeris_times"].get>(); - for (auto it = isdPos["positions"].begin(); it != isdPos["positions"].end(); it++) { - std::vector pos = {it->at(0).get(), it->at(1).get(), it->at(2).get()}; - p_cache.push_back(pos); - } - - p_cacheVelocity.clear(); - - bool hasVelocityKey = isdPos.find("velocities") != isdPos.end(); + p_hasVelocity = isdPos.find("velocities") != isdPos.end(); - if (hasVelocityKey) { - for (auto it = isdPos["velocities"].begin(); it != isdPos["velocities"].end(); it++) { - std::vector vel = {it->at(0).get(), it->at(1).get(), it->at(2).get()}; - p_cacheVelocity.push_back(vel); + std::vector stateCache; + if (p_hasVelocity) { + for (auto it = isdPos["positions"].begin(); it != isdPos["positions"].end(); it++) { + int index = it - isdPos["positions"].begin(); + std::vector pos = it->get>(); + std::vector vel = isdPos["velocities"][index]; + stateCache.push_back(ale::State(ale::Vec3d(pos), ale::Vec3d(vel))); + } + } + else { + for (auto it = isdPos["positions"].begin(); it != isdPos["positions"].end(); it++) { + std::vector pos = {it->at(0).get(), it->at(1).get(), it->at(2).get()}; + stateCache.push_back(ale::State(ale::Vec3d(pos))); } } - p_hasVelocity = !p_cacheVelocity.empty(); - p_source = Memcache; + if (m_state != NULL) { + delete m_state; + } + m_state = new ale::States(p_cacheTime, stateCache); + + p_source = Memcache; SetEphemerisTime(p_cacheTime[0]); } @@ -445,6 +462,7 @@ namespace Isis { _FILEINFO_); } + std::vector stateCache; // Loop through and move the table to the cache if (p_source != PolyFunction) { for (int r = 0; r < table.Records(); r++) { @@ -460,24 +478,26 @@ namespace Isis { throw IException(IException::Programmer, msg, _FILEINFO_); } - std::vector j2000Coord; - j2000Coord.push_back((double)rec[0]); - j2000Coord.push_back((double)rec[1]); - j2000Coord.push_back((double)rec[2]); + ale::State currentState(ale::Vec3d((double)rec[0], + (double)rec[1], + (double)rec[2])); + int inext = 3; - p_cache.push_back(j2000Coord); if (p_hasVelocity) { - std::vector j2000Velocity; - j2000Velocity.push_back((double)rec[3]); - j2000Velocity.push_back((double)rec[4]); - j2000Velocity.push_back((double)rec[5]); + currentState.velocity = ale::Vec3d((double)rec[3], + (double)rec[4], + (double)rec[5]); inext = 6; - - p_cacheVelocity.push_back(j2000Velocity); } + stateCache.push_back(currentState); p_cacheTime.push_back((double)rec[inext]); } + + if (m_state != NULL) { + delete m_state; + } + m_state = new ale::States(p_cacheTime, stateCache); } else { // Coefficient table for postion coordinates x, y, and z @@ -502,7 +522,7 @@ namespace Isis { SetOverrideBaseTime(baseTime, timeScale); SetPolynomial(coeffX, coeffY, coeffZ); if (degree > 0) p_hasVelocity = true; - if(degree == 0 && p_cacheVelocity.size() > 0) p_hasVelocity = true; + if(degree == 0 && m_state->hasVelocity()) p_hasVelocity = true; } } @@ -525,9 +545,6 @@ namespace Isis { LineCache(tableName); // TODO Figure out how to get the tolerance -- for now hard code .01 Memcache2HermiteCache(0.01); - - //std::cout << "Cache size is " << p_cache.size(); - } // record to be added to table @@ -560,28 +577,30 @@ namespace Isis { int inext = 0; - for (int i = 0; i < (int)p_cache.size(); i++) { - record[inext++] = p_cache[i][0]; // record[0] - record[inext++] = p_cache[i][1]; // record[1] - record[inext++] = p_cache[i][2]; // record[2] + std::vector stateCache = m_state->getStates(); + for (int i = 0; i < (int)stateCache.size(); i++) { + record[inext++] = stateCache[i].position.x; // record[0] + record[inext++] = stateCache[i].position.y; // record[1] + record[inext++] = stateCache[i].position.z; // record[2] if (p_hasVelocity) { - record[inext++] = p_cacheVelocity[i][0]; // record[3] - record[inext++] = p_cacheVelocity[i][1]; // record[4] - record[inext++] = p_cacheVelocity[i][2]; // record[5] + record[inext++] = stateCache[i].velocity.x; // record[3] + record[inext++] = stateCache[i].velocity.y; // record[4] + record[inext++] = stateCache[i].velocity.z; // record[5] } record[inext] = p_cacheTime[i]; // record[6] table += record; inext = 0; } + CacheLabel(table); return table; } - else if(p_source == PolyFunction && p_degree == 0 && p_fullCacheSize == 1) + else if(p_source == PolyFunction && p_degree == 0 && p_fullCacheSize == 1){ // Just load the position for the single epoch return LineCache(tableName); - + } // Load the coefficients for the curves fit to the 3 camera angles else if (p_source == PolyFunction) { // PolyFunction case @@ -715,31 +734,35 @@ namespace Isis { // Clear existing positions from thecache p_cacheTime.clear(); - p_cache.clear(); - - // Clear the velocity cache if we can calculate it instead. It can't be calculated for - // functions of degree 0 (framing cameras), so keep the original velocity. It is better than nothing. - if (p_degree > 0 && p_cacheVelocity.size() > 1) p_cacheVelocity.clear(); // Load the time cache first LoadTimeCache(); if (p_fullCacheSize > 1) { - // Load the positions and velocity caches - p_et = -DBL_MAX; // Forces recalculation in SetEphemerisTime - + // Load the positions and velocity caches + p_et = -DBL_MAX; // Forces recalculation in SetEphemerisTime + std::vector stateCache; for (std::vector::size_type pos = 0; pos < p_cacheTime.size(); pos++) { - // p_et = p_cacheTime.at(pos); SetEphemerisTime(p_cacheTime.at(pos)); - p_cache.push_back(p_coordinate); - p_cacheVelocity.push_back(p_velocity); + stateCache.push_back(ale::State(ale::Vec3d(p_coordinate), ale::Vec3d(p_velocity))); } + if (m_state != NULL) { + delete m_state; + } + m_state = new ale::States(p_cacheTime, stateCache); } else { // Load the position for the single updated time instance p_et = p_cacheTime[0]; SetEphemerisTime(p_et); - p_cache.push_back(p_coordinate); + std::vector stateCache; + stateCache.push_back(p_coordinate); + std::vector timeCache; + timeCache.push_back(p_cacheTime[0]); + if (m_state != NULL) { + delete m_state; + } + m_state = new ale::States(timeCache, stateCache); } // Set source to cache and reset current et @@ -795,8 +818,6 @@ namespace Isis { // Set velocity vector to true since it is calculated p_hasVelocity = true; -// std::cout <<"time cache size is " << p_cacheTime.size() << std::endl; - // Calculate new postition coordinates from polynomials fit to coordinates & // fill cache // std::cout << "Before" << std::endl; @@ -865,6 +886,7 @@ namespace Isis { } // add positions and velocities for these times + std::vector stateCache; for(int i = 0; i < (int) p_cacheTime.size(); i++) { // x,y,z positions double time; @@ -872,14 +894,17 @@ namespace Isis { p_coordinate[0] = function1.Evaluate(time); p_coordinate[1] = function2.Evaluate(time); p_coordinate[2] = function3.Evaluate(time); - p_cache.push_back(p_coordinate); // x,y,z velocities p_velocity[0] = b1 + 2 * c1 * (p_cacheTime[i] - p_baseTime); p_velocity[1] = b2 + 2 * c2 * (p_cacheTime[i] - p_baseTime); p_velocity[2] = b3 + 2 * c3 * (p_cacheTime[i] - p_baseTime); - p_cacheVelocity.push_back(p_velocity); + stateCache.push_back(ale::State(p_coordinate, p_velocity)); + } + if (m_state != NULL) { + delete m_state; } + m_state = new ale::States(p_cacheTime, stateCache); p_source = HermiteCache; double et = p_et; @@ -904,14 +929,15 @@ namespace Isis { return; // Adjust the degree of the polynomial to the available data - if (p_cache.size() == 1) { + int size = m_state->getStates().size(); + if (size == 1) { p_degree = 0; } - else if (p_cache.size() == 2) { + else if (size == 2) { p_degree = 1; } - //Check for polynomial over Hermite constant and initialize coefficients + // Check for polynomial over Hermite constant and initialize coefficients if (type == PolyFunctionOverHermiteConstant) { XC.assign(p_degree + 1, 0.); YC.assign(p_degree + 1, 0.); @@ -928,15 +954,15 @@ namespace Isis { ComputeBaseTime(); std::vector time; - if(p_cache.size() == 1) { + if(size == 1) { double t = p_cacheTime.at(0); SetEphemerisTime(t); XC.push_back(p_coordinate[0]); YC.push_back(p_coordinate[1]); ZC.push_back(p_coordinate[2]); } - else if(p_cache.size() == 2) { -// Load the times and get the corresponding coordinates + else if(size == 2) { + // Load the times and get the corresponding coordinates double t1 = p_cacheTime.at(0); SetEphemerisTime(t1); std::vector coord1 = p_coordinate; @@ -948,7 +974,7 @@ namespace Isis { double slope[3]; double intercept[3]; -// Compute the linear equation for each coordinate and save them + // Compute the linear equation for each coordinate and save them for(int cIndex = 0; cIndex < 3; cIndex++) { Isis::LineEquation posline(t1, coord1[cIndex], t2, coord2[cIndex]); slope[cIndex] = posline.Slope(); @@ -978,7 +1004,7 @@ namespace Isis { fitZ->AddKnown(time, coord[2]); time.clear(); } - //Solve the equations for the coefficients + // Solve the equations for the coefficients fitX->Solve(); fitY->Solve(); fitZ->Solve(); @@ -1260,57 +1286,24 @@ namespace Isis { * method) */ void SpicePosition::SetEphemerisTimeMemcache() { - // If the cache has only one position return it - if(p_cache.size() == 1) { - p_coordinate[0] = p_cache[0][0]; - p_coordinate[1] = p_cache[0][1]; - p_coordinate[2] = p_cache[0][2]; - if(p_hasVelocity) { - p_velocity[0] = p_cacheVelocity[0][0]; - p_velocity[1] = p_cacheVelocity[0][1]; - p_velocity[2] = p_cacheVelocity[0][2]; - } + ale::State state; + if (p_cacheTime.size() == 1) { + state = m_state->getStates().front(); } - else { - // Otherwise determine the interval to interpolate - std::vector::iterator pos; - pos = upper_bound(p_cacheTime.begin(), p_cacheTime.end(), p_et); - - int cacheIndex; - if(pos != p_cacheTime.end()) { - cacheIndex = distance(p_cacheTime.begin(), pos); - cacheIndex--; - } - else { - cacheIndex = p_cacheTime.size() - 2; - } - - if(cacheIndex < 0) cacheIndex = 0; - - // Interpolate the coordinate - double mult = (p_et - p_cacheTime[cacheIndex]) / - (p_cacheTime[cacheIndex+1] - p_cacheTime[cacheIndex]); - std::vector p2 = p_cache[cacheIndex+1]; - std::vector p1 = p_cache[cacheIndex]; - - p_coordinate[0] = (p2[0] - p1[0]) * mult + p1[0]; - p_coordinate[1] = (p2[1] - p1[1]) * mult + p1[1]; - p_coordinate[2] = (p2[2] - p1[2]) * mult + p1[2]; - - if(p_hasVelocity) { - p2 = p_cacheVelocity[cacheIndex+1]; - p1 = p_cacheVelocity[cacheIndex]; - p_velocity[0] = (p2[0] - p1[0]) * mult + p1[0]; - p_velocity[1] = (p2[1] - p1[1]) * mult + p1[1]; - p_velocity[2] = (p2[2] - p1[2]) * mult + p1[2]; - } + state = m_state->getState(p_et, ale::LINEAR); + } + p_coordinate[0] = state.position.x; + p_coordinate[1] = state.position.y; + p_coordinate[2] = state.position.z; + if (p_hasVelocity){ + p_velocity[0] = state.velocity.x; + p_velocity[1] = state.velocity.y; + p_velocity[2] = state.velocity.z; } - } - /** * This is a protected method that is called by * SetEphemerisTime() when Source type is HermiteCache. It @@ -1323,78 +1316,21 @@ namespace Isis { * @history 2009-08-03 Jeannie Walldren - Original version */ void SpicePosition::SetEphemerisTimeHermiteCache() { + if (p_hasVelocity) { + ale::State state = m_state->getState(p_et, ale::SPLINE); - // what if framing camera??? - - // On the first SetEphemerisTime, create our splines. Later calls should - // reuse these splines. - if(p_xhermite == NULL) { - p_overrideTimeScale = 1.; - p_override = ScaleOnly; - ComputeBaseTime(); - - p_xhermite = new NumericalApproximation( - NumericalApproximation::CubicHermite); - p_yhermite = new NumericalApproximation( - NumericalApproximation::CubicHermite); - p_zhermite = new NumericalApproximation( - NumericalApproximation::CubicHermite); - - vector xvalues(p_cache.size()); - vector xhermiteYValues(p_cache.size()); - vector yhermiteYValues(p_cache.size()); - vector zhermiteYValues(p_cache.size()); - - vector xhermiteVelocities(p_cache.size()); - vector yhermiteVelocities(p_cache.size()); - vector zhermiteVelocities(p_cache.size()); - - for(unsigned int i = 0; i < p_cache.size(); i++) { - vector &cache = p_cache[i]; - double &cacheTime = p_cacheTime[i]; - xvalues[i] = (cacheTime - p_baseTime) / p_timeScale; - - xhermiteYValues[i] = cache[0]; - yhermiteYValues[i] = cache[1]; - zhermiteYValues[i] = cache[2]; - - if(p_hasVelocity) { // Line scan camera - vector &cacheVelocity = p_cacheVelocity[i]; - xhermiteVelocities[i] = cacheVelocity[0]; - yhermiteVelocities[i] = cacheVelocity[1]; - zhermiteVelocities[i] = cacheVelocity[2]; - } - else { // Not line scan camera - throw IException(IException::Io, "No velocities available.", - _FILEINFO_); - } - } - - p_xhermite->AddData(xvalues, xhermiteYValues); - p_xhermite->AddCubicHermiteDeriv(xhermiteVelocities); + p_coordinate[0] = state.position.x; + p_coordinate[1] = state.position.y; + p_coordinate[2] = state.position.z; - p_yhermite->AddData(xvalues, yhermiteYValues); - p_yhermite->AddCubicHermiteDeriv(yhermiteVelocities); - - p_zhermite->AddData(xvalues, zhermiteYValues); - p_zhermite->AddCubicHermiteDeriv(zhermiteVelocities); + p_velocity[0] = state.velocity.x; + p_velocity[1] = state.velocity.y; + p_velocity[2] = state.velocity.z; + } + else { + throw IException(IException::Io, "No velocities available. Cannot calculate Hermite Cache.", + _FILEINFO_); } - - // Next line added 07/13/2009 to prevent Camera unit test from bombing - // because time is outside domain. DAC Also added etype to Evaluate calls - NumericalApproximation::ExtrapType etype = - NumericalApproximation::Extrapolate; - - vector &coordinate = p_coordinate; - double sTime = (p_et - p_baseTime) / p_timeScale; - coordinate[0] = p_xhermite->Evaluate(sTime, etype); - coordinate[1] = p_yhermite->Evaluate(sTime, etype); - coordinate[2] = p_zhermite->Evaluate(sTime, etype); - - vector &velocity = p_velocity; - velocity[0] = p_xhermite->EvaluateCubicHermiteFirstDeriv(sTime); - velocity[1] = p_yhermite->EvaluateCubicHermiteFirstDeriv(sTime); - velocity[2] = p_zhermite->EvaluateCubicHermiteFirstDeriv(sTime); } @@ -1433,17 +1369,16 @@ namespace Isis { if(p_hasVelocity) { if( p_degree == 0) { - p_velocity = p_cacheVelocity[0]; + ale::Vec3d velocity = m_state->getVelocities()[0]; + p_velocity[0] = velocity.x; + p_velocity[1] = velocity.y; + p_velocity[2] = velocity.z; } else { p_velocity[0] = ComputeVelocityInTime(WRT_X); p_velocity[1] = ComputeVelocityInTime(WRT_Y); p_velocity[2] = ComputeVelocityInTime(WRT_Z); } - -// p_velocity[0] = functionX.DerivativeVar(rtime); -// p_velocity[1] = functionY.DerivativeVar(rtime); -// p_velocity[2] = functionZ.DerivativeVar(rtime); } } @@ -1463,8 +1398,6 @@ namespace Isis { SetEphemerisTimeHermiteCache(); std::vector hermiteCoordinate = p_coordinate; -// std::cout << hermiteCoordinate << std::endl; - std::vector hermiteVelocity = p_velocity; SetEphemerisTimePolyFunction(); @@ -1531,148 +1464,27 @@ namespace Isis { _FILEINFO_); } - // make sure base time is set before it is needed - p_overrideTimeScale = 1.; - p_override = ScaleOnly; - ComputeBaseTime(); - - // find current size of cache - int n = p_cacheTime.size() - 1; - - // create 3 starting values for the new table - vector inputIndices; - inputIndices.push_back(0); - inputIndices.push_back(n / 2); - inputIndices.push_back(n); - - // find all indices needed to make a hermite table within the appropriate tolerance - vector indexList = HermiteIndices(tolerance, inputIndices); - - // remove all lines from cache vectors that are not in the index list???? - for(int i = n; i >= 0; i--) { - if(!binary_search(indexList.begin(), indexList.end(), i)) { - p_cache.erase(p_cache.begin() + i); - p_cacheTime.erase(p_cacheTime.begin() + i); - p_cacheVelocity.erase(p_cacheVelocity.begin() + i); - } - } - + ale::States *tempStates = new ale::States(m_state->minimizeCache(tolerance)); + delete m_state; + m_state = tempStates; + p_cacheTime = m_state->getTimes(); p_source = HermiteCache; } - /** - * This method is called by Memcache2HermiteCache() to determine - * which indices from the orginal cache should be saved in the - * reduced cache. It is a recursive method that starts with an - * index list of 3 elements (first, center and last index - * values) and adds values to this list if the tolerance is not - * met. - * - * @param tolerance Maximum error allowed between NAIF kernel - * coordinate values and values interpolated by - * the Hermite spline. - * @param indexList Vector containing the list of indices to be - * kept in the cache. This list grows as the - * method is recursively called - * @return vector/ Vector containing final list - * of indices that will be kept for the Hermite cache. - * @internal - * @history 2009-08-03 Jeannie Walldren - Original version. - * @history 2009-08-14 Debbie A. Cook - Corrected indexing - * error in loop. - */ - std::vector SpicePosition::HermiteIndices(double tolerance, std::vector indexList) { - - unsigned int n = indexList.size(); - double sTime; - - NumericalApproximation xhermite(NumericalApproximation::CubicHermite); - NumericalApproximation yhermite(NumericalApproximation::CubicHermite); - NumericalApproximation zhermite(NumericalApproximation::CubicHermite); - for(unsigned int i = 0; i < indexList.size(); i++) { - sTime = (p_cacheTime[indexList[i]] - p_baseTime) / p_timeScale; - xhermite.AddData(sTime, p_cache[indexList[i]][0]); // add time, x-position to x spline - yhermite.AddData(sTime, p_cache[indexList[i]][1]); // add time, y-position to y spline - zhermite.AddData(sTime, p_cache[indexList[i]][2]); // add time, z-position to z spline - - if(p_hasVelocity) { // Line scan camera - xhermite.AddCubicHermiteDeriv(p_cacheVelocity[i][0]); // add x-velocity to x spline - yhermite.AddCubicHermiteDeriv(p_cacheVelocity[i][1]); // add y-velocity to y spline - zhermite.AddCubicHermiteDeriv(p_cacheVelocity[i][2]); // add z-velocity to z spline - } - else { // Not line scan camera - throw IException(IException::Io, "No velocities available.", _FILEINFO_); - // xhermite.AddCubicHermiteDeriv(0.0); // spacecraft didn't move => velocity = 0 - // yhermite.AddCubicHermiteDeriv(0.0); // spacecraft didn't move => velocity = 0 - // zhermite.AddCubicHermiteDeriv(0.0); // spacecraft didn't move => velocity = 0 - } - } - - // loop through the saved indices from the end - for(unsigned int i = indexList.size() - 1; i > 0; i--) { - double xerror = 0; - double yerror = 0; - double zerror = 0; - - // check every value of the original kernel values within interval - for(int line = indexList[i-1] + 1; line < indexList[i]; line++) { - sTime = (p_cacheTime[line] - p_baseTime) / p_timeScale; - - // find the errors at each value - xerror = fabs(xhermite.Evaluate(sTime) - p_cache[line][0]); - yerror = fabs(yhermite.Evaluate(sTime) - p_cache[line][1]); - zerror = fabs(zhermite.Evaluate(sTime) - p_cache[line][2]); - - if(xerror > tolerance || yerror > tolerance || zerror > tolerance) { - // if any error is greater than tolerance, no need to continue looking, break - break; - } - } - - if(xerror < tolerance && yerror < tolerance && zerror < tolerance) { - // if errors are less than tolerance after looping interval, no new point is necessary - continue; - } - else { - // if any error is greater than tolerance, add midpoint of interval to indexList vector - indexList.push_back((indexList[i] + indexList[i-1]) / 2); - } - } - - if(indexList.size() > n) { - sort(indexList.begin(), indexList.end()); - indexList = HermiteIndices(tolerance, indexList); - } - return indexList; - } - /** * Removes the entire cache from memory. */ void SpicePosition::ClearCache() { - p_cache.clear(); - p_cacheVelocity.clear(); - p_cacheTime.clear(); - - if(p_xhermite) { - delete p_xhermite; - p_xhermite = NULL; + if (m_state) { + delete m_state; + m_state = NULL; } - if(p_yhermite) { - delete p_xhermite; - p_xhermite = NULL; - } - - if(p_zhermite) { - delete p_xhermite; - p_xhermite = NULL; - } + p_cacheTime.clear(); } - /** Set the degree of the polynomials to be fit to the * three position coordinates for the time period covered by the * cache, coordinate = c0 + c1*t + c2*t**2 + ... + cn*t**n, @@ -1759,6 +1571,7 @@ namespace Isis { double et = p_fullCacheStartTime + (double) i * cacheSlope; p_cacheTime.push_back(et); } + } /** Compute and return the coordinate at the center time diff --git a/isis/src/base/objs/SpicePosition/SpicePosition.h b/isis/src/base/objs/SpicePosition/SpicePosition.h index f727d4553a..92cd592567 100644 --- a/isis/src/base/objs/SpicePosition/SpicePosition.h +++ b/isis/src/base/objs/SpicePosition/SpicePosition.h @@ -32,6 +32,9 @@ #include "Table.h" #include "PolynomialUnivariate.h" +// ale includes +#include "ale/States.h" + #include namespace Isis { @@ -181,6 +184,7 @@ namespace Isis { * @history 2017-08-18 Tyler Wilson, Summer Stapleton, Ian Humphrey - Added opening/closing brackets * to SetEphemerisTimePolyFunction() so this class compiles without warnings * under C++14. References #4809. + * @history 2020-07-01 Kristin Berry - Updated to use ale::States for internal state cache. */ class SpicePosition { public: @@ -247,12 +251,15 @@ namespace Isis { //! Is this position cached bool IsCached() const { - return (p_cache.size() > 0); + return (m_state != NULL); }; //! Get the size of the current cached positions int cacheSize() const { - return p_cache.size(); + if (m_state) { + return m_state->getStates().size(); + } + return 0; }; void SetPolynomial(const Source type = PolyFunction); @@ -304,8 +311,6 @@ namespace Isis { void SetEphemerisTimePolyFunction(); void SetEphemerisTimePolyFunctionOverHermiteConstant(); - std::vector HermiteIndices(double tol, std::vector indexList); - //====================================================================== // New methods support for light time correction and swap of observer/target SpicePosition(int targetCode, int observerCode, bool swapObserverTarget); @@ -339,17 +344,8 @@ namespace Isis { std::vector p_coordinate; //!< J2000 position at time et std::vector p_velocity; //!< J2000 velocity at time et - //! Hermite spline for x coordinate if Source == HermiteCache - NumericalApproximation *p_xhermite; - //! Hermite spline for y coordinate if Source == HermiteCache - NumericalApproximation *p_yhermite; - //! Hermite spline for z coordinate if Source == HermiteCache - NumericalApproximation *p_zhermite; - Source p_source; //!< Enumerated value for the location of the SPK information used std::vector p_cacheTime; //!< iTime for corresponding position - std::vector > p_cache; //!< Cached positions - std::vector > p_cacheVelocity; //!< Cached velocities std::vector p_coefficients[3]; //!< Coefficients of polynomials fit to 3 coordinates double p_baseTime; //!< Base time used in fit equations @@ -369,6 +365,8 @@ namespace Isis { // Variables support observer/target swap and light time correction bool m_swapObserverTarget; ///!< Swap traditional order double m_lt; ///!< Light time correction + + ale::States *m_state; ///!< State: stores times, positions, velocities; }; }; diff --git a/isis/src/control/apps/jigsaw/tsts/camsolveAll/Makefile b/isis/src/control/apps/jigsaw/tsts/camsolveAll/Makefile index f71d200e08..c3ff52e21d 100644 --- a/isis/src/control/apps/jigsaw/tsts/camsolveAll/Makefile +++ b/isis/src/control/apps/jigsaw/tsts/camsolveAll/Makefile @@ -23,7 +23,7 @@ commands: update=yes \ cksolvedegree=3 \ camsolve=all \ - bundleout_txt=no \ + bundleout_txt=yes \ twist=no > /dev/null; # The above command uses sed to do the following (in order): # 1. remove cube filename paths diff --git a/isis/tests/CubeTests.cpp b/isis/tests/CubeTests.cpp index c70b06c83d..7fa28a40bb 100644 --- a/isis/tests/CubeTests.cpp +++ b/isis/tests/CubeTests.cpp @@ -193,8 +193,7 @@ TEST(CubeTest, TestCubeAttachSpiceFromIsd) { "spk_table_end_time": 100.1, "spk_table_original_size": 2, "ephemeris_times": [ - 100, - 100.1 + 100 ], "positions": [ [0, 20, 0] diff --git a/isis/tests/SpiceTests.cpp b/isis/tests/SpiceTests.cpp index 43536e4964..6cfe5d781a 100644 --- a/isis/tests/SpiceTests.cpp +++ b/isis/tests/SpiceTests.cpp @@ -17,8 +17,8 @@ using namespace Isis; class ConstVelIsd : public ::testing::Test { protected: - json constVelIsdStr; - Pvl isisLabel; + json constVelIsdStr; + Pvl isisLabel; void SetUp() { constVelIsdStr = json::parse(R"( @@ -93,8 +93,7 @@ class ConstVelIsd : public ::testing::Test { "spk_table_end_time": 100.1, "spk_table_original_size": 2, "ephemeris_times": [ - 100, - 100.1 + 100 ], "positions": [ [0, 20, 0] @@ -112,7 +111,7 @@ class ConstVelIsd : public ::testing::Test { Format = Tile TileSamples = 128 TileLines = 128 - + Group = Dimensions Samples = 126 Lines = 126 @@ -133,8 +132,8 @@ class ConstVelIsd : public ::testing::Test { TargetAttitudeShape = NULL TargetPosition = NULL InstrumentPointing = NULL - Instrument = NULL - SpacecraftClock = NULL + Instrument = NULL + SpacecraftClock = NULL InstrumentPosition = NULL InstrumentAddendum = NULL ShapeModel = NULL @@ -144,9 +143,9 @@ class ConstVelIsd : public ::testing::Test { End_Group Group = Instrument - SpacecraftName = NULL - InstrumentId = NULL - TargetName = NULL + SpacecraftName = NULL + InstrumentId = NULL + TargetName = NULL End_Group End_Object @@ -160,35 +159,34 @@ class ConstVelIsd : public ::testing::Test { Bytes = 695 End_Object End - )"); - + )"); + isisLabelStr >> isisLabel; } }; TEST_F(ConstVelIsd, TestSpiceFromIsd) { - Spice testSpice(isisLabel, constVelIsdStr); - testSpice.setTime(100); - + Spice testSpice(isisLabel, constVelIsdStr); + testSpice.setTime(100); + EXPECT_DOUBLE_EQ(testSpice.time().Et(), 100); EXPECT_DOUBLE_EQ(testSpice.getDouble("INS-85600_FOCAL_LENGTH"), 699.62); EXPECT_STREQ(testSpice.getString("FRAME_-85600_NAME").toStdString().c_str(), "LRO_LROCNACL"); EXPECT_EQ(testSpice.getInteger("INS-85600_CK_FRAME_ID"), -85000); - + Distance radii[3]; testSpice.radii(radii); EXPECT_DOUBLE_EQ(radii[0].kilometers(), 1000); EXPECT_DOUBLE_EQ(radii[1].kilometers(), 2000); EXPECT_DOUBLE_EQ(radii[2].kilometers(), 3000); - + EXPECT_DOUBLE_EQ(testSpice.solarLongitude().positiveEast(), 3.1415926535897931); - + } -TEST_F(ConstVelIsd, SunToBodyDist) { - Spice testSpice(isisLabel, constVelIsdStr); +TEST_F(ConstVelIsd, SunToBodyDist) { + Spice testSpice(isisLabel, constVelIsdStr); EXPECT_DOUBLE_EQ(testSpice.sunToBodyDist(), 20); } -