/
Equation.cc
65 lines (55 loc) · 1.96 KB
/
Equation.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// __BEGIN_LICENSE__
// Copyright (C) 2006-2011 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__
#include <asp/IsisIO/Equation.h>
using namespace vw;
using namespace asp;
// Useful tools
//-------------------------------------------------------
// Debugging output of coefficients (constants)
std::ostream& asp::operator<<( std::ostream& os,
boost::shared_ptr<BaseEquation> eq ) {
os << "Vector Equation-----------------------------\n";
os << " " << eq->type() << std::endl;
os << " Time Offset: " << eq->get_time_offset() << "\n";
os << " Eq Coeff: " << "\n";
unsigned working_idx = 0;
while ( working_idx != eq->size() ) {
os << " ";
for ( int i = 0; i < 4; i++ )
if ( working_idx != eq->size() ) {
os << (*eq)[working_idx] << " ";
working_idx++;
}
os << "\n";
}
os << "--------------------------------------------\n";
return os;
}
// Determines equation type and write appropriate
void asp::write_equation( std::ofstream& f, boost::shared_ptr<BaseEquation> eq ) {
f << eq->type() << "\n";
eq->write( f );
}
// Determines equation type from file and return appropriate
boost::shared_ptr<BaseEquation> asp::read_equation( std::ifstream& f) {
if ( !f.is_open() )
vw_throw( IOErr() << "Unable to open equation file\n" );
boost::shared_ptr<BaseEquation> eq;
std::string buffer = "";
std::getline( f, buffer );
if ( buffer == "PolyEquation" ) {
boost::shared_ptr<PolyEquation> eqn_new( new PolyEquation() );
eq = boost::shared_dynamic_cast<BaseEquation>( eqn_new );
eq->read( f );
} else if ( buffer == "RPNEquation" ) {
boost::shared_ptr<RPNEquation> eqn_new( new RPNEquation() );
eq = boost::shared_dynamic_cast<BaseEquation>( eqn_new );
eq->read( f );
} else {
vw_throw( IOErr() << "Unknown equation type: " << buffer << "\n" );
}
return eq;
}