pktools 2.6.7
Processing Kernel for geospatial data
Public Member Functions | Friends | List of all members
Vector2d< T > Class Template Reference
Inheritance diagram for Vector2d< T >:
Inheritance graph
[legend]
Collaboration diagram for Vector2d< T >:
Collaboration graph
[legend]

Public Member Functions

 Vector2d (const Vector2d< T > &v1)
 
 Vector2d (int nrow)
 
 Vector2d (int nrow, int ncol)
 
 Vector2d (int nrow, int ncol, const T &value)
 
 Vector2d (const gsl_matrix *gsl_m)
 
void resize (int nrow)
 
void resize (int nrow, int ncol)
 
int nRows () const
 
int nCols () const
 
void selectCol (int col, std::vector< T > &output) const
 
void selectCol (int col, T *output) const
 
std::vector< T > selectCol (int col)
 
void selectCols (const std::list< int > &cols, Vector2d< T > &output) const
 
void setMask (const Vector2d< T > &mask, T msknodata, T nodata=0)
 
void transpose (Vector2d< T > &output) const
 
void selectCols (const std::list< int > &cols)
 
void sort (Vector2d< T > &output)
 
void scale (const std::vector< double > &scaleVector, const std::vector< double > &offsetVector, Vector2d< T > &scaledOutput)
 
void scale (const T lbound, const T ubound, std::vector< double > &scaleVector, std::vector< double > &offsetVector, Vector2d< T > &scaledOutput)
 
Vector2d< T > operator= (const Vector2d< T > &v1)
 
Vector2d< T > operator+= (const Vector2d< T > &v1)
 
Vector2d< T > sum (const Vector2d< T > &v1, const Vector2d< T > &v2) const
 
mymax (int &x, int &y, double maxValue) const
 
sum () const
 

Friends

template<class T1 >
std::ostream & operator<< (std::ostream &os, const Vector2d< T1 > &v)
 

Detailed Description

template<class T>
class Vector2d< T >

Definition at line 31 of file Vector2d.h.

Constructor & Destructor Documentation

◆ Vector2d() [1/6]

template<class T >
Vector2d< T >::Vector2d

Definition at line 76 of file Vector2d.h.

77 : std::vector< std::vector<T> >()
78{
79}

◆ Vector2d() [2/6]

template<class T >
Vector2d< T >::Vector2d ( const Vector2d< T > &  v1)

Definition at line 86 of file Vector2d.h.

86 {
87 this->resize(v1.size());
88 for(int irow=0;irow<v1.size();++irow)
89 this->at(irow)=v1[irow];
90}

◆ ~Vector2d()

template<class T >
Vector2d< T >::~Vector2d

Definition at line 81 of file Vector2d.h.

82{
83}

◆ Vector2d() [3/6]

template<class T >
Vector2d< T >::Vector2d ( int  nrow)

Definition at line 113 of file Vector2d.h.

114 : std::vector< std::vector<T> >(nrow)
115{
116}

◆ Vector2d() [4/6]

template<class T >
Vector2d< T >::Vector2d ( int  nrow,
int  ncol 
)

Definition at line 118 of file Vector2d.h.

120{
121 this->resize(nrow);
122 for(int irow=0;irow<nrow;++irow){
123 (this->operator[](irow)).resize(ncol);
124// (*this)[irow].resize(ncol);
125 }
126}

◆ Vector2d() [5/6]

template<class T >
Vector2d< T >::Vector2d ( int  nrow,
int  ncol,
const T &  value 
)

Definition at line 128 of file Vector2d.h.

129{
130 this->resize(nrow);
131 for(int irow=0;irow<nrow;++irow){
132 (this->operator[](irow)).resize(ncol);
133 for(int icol=0;icol<ncol;++icol)
134 (this->operator[](irow))[icol]=value;
135 }
136}

◆ Vector2d() [6/6]

template<class T >
Vector2d< T >::Vector2d ( const gsl_matrix *  gsl_m)

Definition at line 138 of file Vector2d.h.

139{
140 this->resize(gsl_m->size1);
141 for(int irow=0;irow<this->size();++irow){
142 (this->operator[](irow)).resize(gsl_m->size2);
143 for(int icol=0;icol<this->operator[](irow).size();++icol)
144 (this->operator[](irow))[icol]=gsl_matrix_get(gsl_m,irow,icol);
145 }
146}

Member Function Documentation

◆ mymax()

template<class T >
T Vector2d< T >::mymax ( int &  x,
int &  y,
double  maxValue 
) const

Definition at line 309 of file Vector2d.h.

309 {
310 //todo: what if this->operator[](0)[0] >=maxValue?
311 // double theMax=(this->operator[](0))[0];
312 double theMax=0;
313 for(int irow=0;irow<this->size();++irow){
314 for(int icol=0;icol<(this->operator[](irow)).size();++icol){
315 double currentValue=(this->operator[](irow))[icol];
316 if(currentValue<maxValue&&currentValue>theMax){
317 assert(theMax<maxValue);
318 y=irow;
319 x=icol;
320 theMax=currentValue;
321 }
322 }
323 }
324 assert(theMax<maxValue);
325 return theMax;
326}

◆ nCols()

template<class T >
int Vector2d< T >::nCols ( ) const
inline

Definition at line 47 of file Vector2d.h.

47{if(this->size()) return this->begin()->size(); else return 0;};

◆ nRows()

template<class T >
int Vector2d< T >::nRows ( ) const
inline

Definition at line 46 of file Vector2d.h.

46{return this->size();};

◆ operator+=()

template<class T >
Vector2d< T > Vector2d< T >::operator+= ( const Vector2d< T > &  v1)

Definition at line 104 of file Vector2d.h.

104 {
105 assert(v1.nRows()==nRows());
106 assert(v1.nCols()==nCols());
107 for(int irow=0;irow<nRows();++irow)
108 for(int icol=0;icol<nCols();++icol)
109 (*this)[irow][icol]+=v1[irow][icol];
110 return *this;
111}

◆ operator=()

template<class T >
Vector2d< T > Vector2d< T >::operator= ( const Vector2d< T > &  v1)

Definition at line 92 of file Vector2d.h.

92 {
93 //check for assignment to self (of the form v=v)
94 if(this==&v1)
95 return *this;
96 else{
97 this->resize(v1.size());
98 for(int irow=0;irow<v1.size();++irow)
99 this->at(irow)=v1[irow];
100 return *this;
101 }
102}

◆ resize() [1/2]

template<class T >
void Vector2d< T >::resize ( int  nrow)
inline

Definition at line 41 of file Vector2d.h.

42 {
43 std::vector< std::vector<T> >::resize(nrow);
44 };

◆ resize() [2/2]

template<class T >
void Vector2d< T >::resize ( int  nrow,
int  ncol 
)

Definition at line 149 of file Vector2d.h.

150{
151 this->std::vector< std::vector<T> >::resize(nrow);
152 for(int irow=0;irow<nrow;++irow){
153 (this->operator[](irow)).resize(ncol);
154 }
155}

◆ scale() [1/2]

template<class T >
void Vector2d< T >::scale ( const std::vector< double > &  scaleVector,
const std::vector< double > &  offsetVector,
Vector2d< T > &  scaledOutput 
)

Definition at line 253 of file Vector2d.h.

254{
255 int nsample=this->size();//including first sample (ex. wavelength)
256 int nband=(*this)[0].size();
257 assert(scaleVector.size()==nband);
258 assert(offsetVector.size()==nband);
259 std::vector<T> pixel(nband);
260 scaledOutput.resize(nsample,nband);
261 for(int isample=0;isample<nsample;++isample)
262 for(int iband=0;iband<nband;++iband)
263 scaledOutput[isample][iband]=((*this)[isample][iband])*scaleVector[iband]+offsetVector[iband];
264}

◆ scale() [2/2]

template<class T >
void Vector2d< T >::scale ( const T  lbound,
const T  ubound,
std::vector< double > &  scaleVector,
std::vector< double > &  offsetVector,
Vector2d< T > &  scaledOutput 
)

Definition at line 266 of file Vector2d.h.

267{
268 //scale to lbound and ubound
269 int nsample=this->size();//including first sample (ex. wavelength)
270 int nband=(*this)[0].size();
271 scaleVector.resize(nband);
272 offsetVector.resize(nband);
273 std::vector<T> pixel(nsample);
274 T theMin;
275 T theMax;
277 scaledOutput.resize(nsample,nband);
278 for(int iband=0;iband<nband;++iband){
279 pixel=selectCol(iband);
280 stat.minmax(pixel, pixel.begin(), pixel.end(), theMin, theMax);
281 scaleVector[iband]=static_cast<double>(ubound-lbound)/(theMax-theMin);
282 offsetVector[iband]=static_cast<double>(-theMin*scaleVector[iband])-lbound;
283 for(int isample=0;isample<pixel.size();++isample)
284 scaledOutput[isample][iband]=((*this)[isample][iband])*scaleVector[iband]+offsetVector[iband];
285 }
286}

◆ selectCol() [1/3]

template<class T >
std::vector< T > Vector2d< T >::selectCol ( int  col)

Definition at line 179 of file Vector2d.h.

180{
181 assert(col>=0);
182 assert(col<(*this)[0].size());
183 std::vector<T> output(this->size());
184 for(int irow=0;irow<this->size();++irow)
185 output[irow]=(*this)[irow][col];
186 return(output);
187}

◆ selectCol() [2/3]

template<class T >
void Vector2d< T >::selectCol ( int  col,
std::vector< T > &  output 
) const

Definition at line 169 of file Vector2d.h.

170{
171 assert(col>=0);
172 assert(col<(*this)[0].size());
173 output.resize(this->size());
174 for(int irow=0;irow<this->size();++irow){
175 output[irow]=(*this)[irow][col];
176 }
177}

◆ selectCol() [3/3]

template<class T >
void Vector2d< T >::selectCol ( int  col,
T *  output 
) const

Definition at line 189 of file Vector2d.h.

190{
191 assert(col>=0);
192 assert(col<(*this)[0].size());
193 for(int irow=0;irow<this->size();++irow){
194 output[irow]=(*this)[irow][col];
195 }
196}

◆ selectCols() [1/2]

template<class T >
void Vector2d< T >::selectCols ( const std::list< int > &  cols)

Definition at line 198 of file Vector2d.h.

199{
200 for(int irow=0;irow<this->size();++irow)
201 for(int icol=((*this)[irow]).size()-1;icol>=0;--icol)
202 if(find(cols.begin(),cols.end(),icol)==cols.end())
203 (*this)[irow].erase(((*this)[irow]).begin()+icol);
204}

◆ selectCols() [2/2]

template<class T >
void Vector2d< T >::selectCols ( const std::list< int > &  cols,
Vector2d< T > &  output 
) const

Definition at line 157 of file Vector2d.h.

158{
159 output.resize(this->size());
160 std::list<int>::const_iterator it;
161 for(int irow=0;irow<this->size();++irow){
162 output[irow].resize(cols.size());
163 it=cols.begin();
164 for(int icol=0;icol<cols.size();++icol)
165 output[irow][icol]=(*this)[irow][*(it++)];
166 }
167}

◆ setMask()

template<class T >
void Vector2d< T >::setMask ( const Vector2d< T > &  mask,
msknodata,
nodata = 0 
)

Definition at line 206 of file Vector2d.h.

207{
208 assert(mask.nRows()==nRows());
209 assert(mask.nCols()==nCols());
210 for(int irow=0;irow<this->size();++irow)
211 for(int icol=0;icol<((*this)[irow]).size()-1;++icol)
212 if(mask[irow][icol]==msknodata)
213 (*this)[irow][icol]=nodata;
214}

◆ sort()

template<class T >
void Vector2d< T >::sort ( Vector2d< T > &  output)

Definition at line 232 of file Vector2d.h.

233{
234 //sort according to first sample (ex. wavelength)
235 int nsample=this->size();//including first sample (ex. wavelength)
236 int nband=(*this)[0].size();
237 std::vector<IndexValue> sortW(nband);
238 for(int ilevel=0;ilevel<nband;++ilevel){
239 IndexValue pv;
240 pv.position=ilevel;
241 pv.value=(*this)[0][ilevel];
242 sortW[ilevel]=pv;
243 }
244 std::sort(sortW.begin(),sortW.end(),Increase_IndexValue());
245 output.resize(nsample);
246 for(int isample=0;isample<nsample;++isample){
247 output[isample].resize(nband);
248 for(int iband=0;iband<nband;++iband)
249 output[isample][iband]=(*this)[isample][sortW[iband].position];
250 }
251}

◆ sum() [1/2]

template<class T >
T Vector2d< T >::sum

Definition at line 300 of file Vector2d.h.

300 {
301 double theSum=0;
302 for(int irow=0;irow<this->size();++irow){
303 for(int icol=0;icol<this->operator[](irow).size();++icol)
304 theSum+=(this->operator[](irow))[icol];
305 }
306 return theSum;
307}

◆ sum() [2/2]

template<class T >
Vector2d< T > Vector2d< T >::sum ( const Vector2d< T > &  v1,
const Vector2d< T > &  v2 
) const

Definition at line 288 of file Vector2d.h.

288 {
289 Vector2d<T> vsum(v1.size());
290 assert(v1.size()==v2.size());
291 for(int irow=0;irow<v1.size();++irow){
292 assert(v1[irow].size()==v2[irow].size());
293 vsum[irow].resize(v1[irow].size());
294 for(int icol=0;icol<v1.size();++icol)
295 vsum[irow][icol]=v1[irow][icol]+v2[irow][icol];
296 }
297 return vsum;
298}

◆ transpose()

template<class T >
void Vector2d< T >::transpose ( Vector2d< T > &  output) const
inline

Definition at line 53 of file Vector2d.h.

53 {
54 output.resize(nCols(),nRows());
55 for(int irow=0;irow<nRows();++irow){
56 for(int icol=0;icol<nCols();++icol){
57 output[icol][irow]=(*this)[irow][icol];
58 }
59 }
60 };

Friends And Related Function Documentation

◆ operator<<

template<class T >
template<class T1 >
std::ostream & operator<< ( std::ostream &  os,
const Vector2d< T1 > &  v 
)
friend

Definition at line 216 of file Vector2d.h.

217{
218 for(int irow=0;irow<v.size();++irow){
219 for(int icol=0;icol<v[irow].size();++icol){
220 os << v[irow][icol] << "\t";
221 }
222 os << std::endl;
223 }
224 return os;
225 // os << theOption.getLongName() << ": ";
226 // for(int index=0;index<theOption.size();++index)
227 // os << type2string<T>(theOption[index]) << " ";
228 // os << std::endl;
229 // return os;
230}

The documentation for this class was generated from the following file: