OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDoubleGridProperty.cpp
Go to the documentation of this file.
1 #include <sstream>
3 
4 RTTI_DEF1(ossimDoubleGridProperty, "ossimDoubleGridProperty", ossimProperty);
5 
7  int /* numberOfRows */,
8  int /* numberOfCols */,
9  const std::vector<double>& /* values*/ )
10  :ossimProperty(name),
11  theMinNumberOfCols(-1),
12  theMaxNumberOfCols(-1),
13  theMinNumberOfRows(-1),
14  theMaxNumberOfRows(-1)
15 {
16 
17 }
18 
20  :ossimProperty(rhs),
21  theMinNumberOfCols(rhs.theMinNumberOfCols),
22  theMaxNumberOfCols(rhs.theMaxNumberOfCols),
23  theMinNumberOfRows(rhs.theMinNumberOfRows),
24  theMaxNumberOfRows(rhs.theMaxNumberOfRows),
25  theValues(rhs.theValues)
26 {
27 }
28 
30 {
31 }
32 
34 {
35  return new ossimDoubleGridProperty(*this);
36 }
37 
39 {
41  const ossimDoubleGridProperty* rhsPtr = dynamic_cast<const ossimDoubleGridProperty*>(&rhs);
42  if(rhsPtr)
43  {
48  theValues = rhsPtr->theValues;
49  }
50  else
51  {
52  setValue(rhs.valueToString());
53  }
54 
55  return *this;
56 }
57 
58 
60 {
61  std::istringstream in(value.c_str());
62  ossimString nRows, nCols, v;
63  int numberOfRows=0;
64  int numberOfCols=0;
65  int rowIdx = 0;
66  int colIdx = 0;
67  in >> nRows >> nCols;
68  numberOfRows = nRows.toInt32();
69  numberOfCols = nCols.toInt32();
70  theValues.resize(numberOfRows);
71 
72  for(rowIdx = 0; rowIdx < numberOfRows; ++rowIdx)
73  {
74  theValues[rowIdx].resize(numberOfCols);
75  for(colIdx = 0; colIdx < numberOfCols; ++ colIdx)
76  {
77  in >> v;
78  theValues[rowIdx][colIdx] = v.toDouble();
79  }
80  }
81 
82  return true;
83 }
84 
86 {
88  int rowIdx = 0;
89  int colIdx = 0;
90  out << getNumberOfRows() << " " << getNumberOfCols() << " ";
91 
92  for(rowIdx = 0; rowIdx < (int)getNumberOfRows(); ++rowIdx)
93  {
94  for(colIdx = 0; colIdx < (int)getNumberOfCols(); ++colIdx)
95  {
96  out << ossimString::toString(getValue(rowIdx, colIdx)) << " ";
97  }
98  }
99  valueResult = out.str();
100 }
101 
103 {
104  theMinNumberOfCols = -1;
105  theMaxNumberOfCols = -1;
106  theMinNumberOfRows = -1;
107  theMaxNumberOfRows = -1;
108 }
109 
111  int maxNumberOfCols)
112 {
113  theMinNumberOfCols = minNumberOfCols;
114  theMaxNumberOfCols = maxNumberOfCols;
115 }
116 
118  int maxNumberOfRows)
119 {
120  theMinNumberOfRows = minNumberOfRows;
121  theMaxNumberOfRows = maxNumberOfRows;
122 }
123 
124 void ossimDoubleGridProperty::setContraints(int minNumberOfRows,
125  int maxNumberOfRows,
126  int minNumberOfCols,
127  int maxNumberOfCols)
128 {
129  theMinNumberOfRows = minNumberOfRows;
130  theMaxNumberOfRows = maxNumberOfRows;
131  theMinNumberOfCols = minNumberOfCols;
132  theMaxNumberOfCols = maxNumberOfCols;
133 }
134 
136 {
137  return ((int)theValues.size());
138 }
139 
141 {
142  if(getNumberOfRows())
143  {
144  return (ossim_uint32)theValues[0].size();
145  }
146  return 0;
147 }
148 
150  ossim_uint32 col)const
151 {
152  if((row < getNumberOfRows())&&
153  (col < getNumberOfCols()))
154  {
155  return theValues[(int)row][(int)col];
156  }
157 
158  return 0.0;
159 }
virtual void valueToString(ossimString &valueResult) const =0
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
void setColConstraints(int minNumberOfCols, int maxNumberOfCols)
RTTI_DEF1(ossimDoubleGridProperty, "ossimDoubleGridProperty", ossimProperty)
static ossimString toString(bool aValue)
Numeric to string methods.
virtual const ossimProperty & assign(const ossimProperty &rhs)
virtual ossimString valueToString() const
void setContraints(int minNumberOfRows, int maxNumberOfRows, int minNumberOfCols, int maxNumberOfCols)
ossim_int32 toInt32() const
virtual const ossimProperty & assign(const ossimProperty &rhs)
virtual bool setValue(const ossimString &value)
std::vector< std::vector< double > > theValues
unsigned int ossim_uint32
ossim_uint32 getNumberOfRows() const
void setRowConstraints(int minNumberOfRows, int maxNumberOfRows)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
double getValue(ossim_uint32 row, ossim_uint32 col) const
ossim_uint32 getNumberOfCols() const
ossimDoubleGridProperty(const ossimString &name=ossimString(""), int numberOfRows=0, int numberOfCols=0, const std::vector< double > &values=std::vector< double >())