USGS

Isis 3.0 Application Source Code Reference

Home

SpiceSegment.h

Go to the documentation of this file.
00001 #if !defined(SpiceSegment_h)
00002 #define SpiceSegment_h
00003 /**                                                                       
00004  * @file                                                                  
00005  * $Revision$ 
00006  * $Date$
00007  *                                                                        
00008  *   Unless noted otherwise, the portions of Isis written by the USGS are 
00009  *   public domain. See individual third-party library and package descriptions 
00010  *   for intellectual property information, user agreements, and related  
00011  *   information.                                                         
00012  *                                                                        
00013  *   Although Isis has been used by the USGS, no warranty, expressed or   
00014  *   implied, is made by the USGS as to the accuracy and functioning of such 
00015  *   software and related material nor shall the fact of distribution     
00016  *   constitute any such warranty, and no responsibility is assumed by the
00017  *   USGS in connection therewith.                                        
00018  *                                                                        
00019  *   For additional information, launch                                   
00020  *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html                
00021  *   in a browser or see the Privacy & Disclaimers page on the Isis website,
00022  *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
00023  *   http://www.usgs.gov/privacy.html.
00024  *  
00025  *   $Id$
00026  */                                                                       
00027 
00028 #include <cmath>
00029 #include <string>
00030 #include <vector>
00031 #include <iostream>
00032 #include <sstream>
00033 
00034 #include "naif/SpiceZdf.h"
00035 #include "tnt/tnt_array1d.h"
00036 #include "tnt/tnt_array1d_utils.h"
00037 #include "tnt/tnt_array2d.h"
00038 #include "tnt/tnt_array2d_utils.h"
00039 
00040 #include "Kernels.h"
00041 #include "iString.h"
00042 #include "iException.h"
00043 
00044 
00045 namespace Isis {
00046 
00047 class Cube;
00048 class Camera;
00049 class Table;
00050 class PvlObject;
00051 
00052 /**
00053  * @brief Maintain a SPICE kernel segment for conversions and export
00054  * 
00055  * This class is designed to read SPICE data from ISIS cube blobs and convert
00056  * them to proper formats for export to NAIF formatted SPICE kernel files.  This
00057  * particular implementation supports NAIF CK kernel types 1, 2 and 3.
00058  *  
00059  * @author 2010-11-10 Kris Becker 
00060  * @internal 
00061  * @history 2010-12-09 Kris Becker Added more documentation
00062  * @history 2011-05-04 Kris Becker Added pad time. 
00063  * @history 2011-05-29 Debbie A. Cook Changed name of local Kernels class to
00064  *                                    LocalKernels to avoid confusion
00065  * @history 2011-06-15 Kris Becker Removed use of LocalKernels and use version 
00066  *                                  in system; added loading of IAK kernel
00067  *                                  specifically for Cassini support; removed
00068  *                                  conditionalized obsolete code.
00069  * @history 2011-09-19 Debbie A. Cook Added section of code to ignore
00070  *                                  Instrument group and use OriginalInstrument
00071  *                                  group in the case of the IdealCamera.  The
00072  *                                  output kernel will be based on the original
00073  *                                  instrument code since the IdealCamera has
00074  *                                  no code.  This is safe to do since the
00075  *                                  camera is not being used to manipulate
00076  *                                  pixels. 
00077  * 
00078  */
00079 class SpiceSegment {
00080   public:
00081     typedef TNT::Array1D<SpiceDouble> SVector;       //!<  1-D Buffer
00082     typedef TNT::Array2D<SpiceDouble> SMatrix;       //!<  2-D buffer
00083 
00084     SpiceSegment();
00085     SpiceSegment(const std::string &fname);
00086     SpiceSegment(Cube &cube, const std::string &tblname = "SpiceSegment");
00087     virtual ~SpiceSegment() { }
00088     
00089     /** Returns the number of elements in the quaternions */
00090     int size() const { return (size(_quats)); }
00091 
00092     /** Returns the name of the segment, typically the ProductId */
00093     std::string Id() const { return (_name); }
00094     void setId(const std::string &id);
00095 
00096     /** Start time of segment in ET */
00097     double startTime() const { return (_startTime); }
00098     /** End time of segment in ET */
00099     double endTime() const { return (_endTime); }
00100 
00101     bool operator<(const SpiceSegment &segment) const {
00102       return (startTime() < segment.startTime());
00103     }
00104 
00105     // Elements for writing NAIF SPICE kernels
00106     int FurnshKernelType(const std::string &ktypes) const;
00107     int UnloadKernelType(const std::string &ktypes = "") const;
00108 
00109     /** Returns CK segment reference frame */
00110     std::string ReferenceFrame() const { return (_refFrame); }
00111     /** NAIF SPICE instrument code */
00112     int InstCode() const { return (_instCode); }
00113     /** Returns instance of quaternions */
00114     const SMatrix &Quaternions() const { return (_quats); }
00115     /** Determines if angular velocites exist */
00116     bool hasAngularVelocities() const { return ((size(_avvs) > 0)); }
00117     /** Returns instance of angular velocity vectors */
00118     const SMatrix &AngularVelocities() const { return (_avvs); }
00119 
00120     /** Returns times in units of SCLK */
00121     const SVector &SCLKTimes() const { return (_times); }
00122 
00123     /** Returns a comment summarizing the segment */
00124     std::string getComment() const;
00125 
00126     // Mostly type 2 needs but can be used for type 3 (start times anyway)
00127     virtual SVector SCLKStartIntervals() const;
00128     virtual SVector SCLKStopIntervals() const;
00129     virtual SVector TickRate() const;
00130 
00131   private:
00132     typedef TNT::Array1D<SMatrix>     SMatSeq;       //!<  Time ordered matrices
00133 
00134     // Mutable for full loading/unloading of kernels w/o restrictions
00135     mutable Kernels  _kernels;
00136     int         _camVersion;
00137     std::string _name;
00138     std::string _fname;
00139     double      _startTime;
00140     double      _endTime;
00141     std::string _utcStartTime; //  Need to store these as conversion from ET
00142     std::string _utcEndTime;   //  requires leap seconds kernel
00143     std::string _instId;       //  Instrument ID
00144     std::string _target;       //  Target name
00145     int         _instCode;     //  NAIF instrument code of the SPICE segment
00146     std::string _instFrame;    //  NAIF instrument frame
00147     std::string _refFrame;     //  NAIF reference frame
00148     SMatrix     _quats;
00149     SMatrix     _avvs;
00150     SVector     _times;
00151     double      _tickRate;     // Number of seconds per tick for s/c
00152 
00153 
00154     // Internal processing methods
00155     void init();
00156     template <class TNTSTORE> int size(const TNTSTORE &t) const { return (t.dim1()); }
00157 
00158     std::string getKeyValue(PvlObject &label, const std::string &keyword);
00159     void import(Cube &cube, const std::string &tblname = "SpiceSegment");
00160     SMatrix load(Table &cache);
00161     SMatrix getQuaternions(const SMatrix &spice) const;
00162     SMatrix getAngularVelocities(const SMatrix &spice) const;
00163     SVector getTimes(const SMatrix &spice) const;
00164 
00165     bool getTimeDependentFrameIds(Table &table, int &toId, int &fromId) const;
00166     std::string getFrameName(int frameid) const;
00167     SMatrix getConstantRotation(Table &table) const;
00168     SMatrix getIdentityRotation(const int &nelements = 3) const;
00169     SMatrix computeStateRotation(const std::string &frame1, 
00170                                  const std::string &frame2, 
00171                                  double etTime) const;
00172     void getRotationMatrices(Cube &cube, Camera &camera, Table &table,
00173                              SMatSeq &lmats, SMatSeq &rmat, SVector &sclks);
00174     SVector convertTimes(int scCode, const SVector &etTimes);
00175     void convert(const SMatrix &quats, const SMatrix &avvs,
00176                  const SMatSeq &lmats, const SMatSeq &rmats, 
00177                  SMatrix &ckQuats, SMatrix &ckAvvs) const;
00178     const SMatrix &getMatrix(const SMatSeq &seq, const int &nth) const;
00179 
00180     SMatrix expand(int ntop, int nbot, const SMatrix &matrix) const;
00181     SVector expand(int ntop, int nbot, const SVector &vec) const;
00182 
00183     double SCLKtoET(SpiceInt scCode, double sclk) const;
00184     double ETtoSCLK(SpiceInt scCode, double et) const;
00185 
00186     std::string toUTC(const double &et) const;
00187 
00188 };
00189 
00190 };     // namespace Isis
00191 #endif
00192