World Ocean Simulation System (WOSS) library
time-arrival-definitions.h
Go to the documentation of this file.
1/* WOSS - World Ocean Simulation System -
2 *
3 * Copyright (C) 2009 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - federico@guerra-tlc.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/*
23 * This software has been developed by Federico Guerra and SIGNET lab,
24 * University of Padova, in collaboration with the NATO Centre for
25 * Maritime Research and Experimentation (http://www.cmre.nato.int ;
26 * E-mail: pao@cmre.nato.int), whose support is gratefully acknowledged.
27 */
28
29
40#ifndef TIME_ARRIVAL_DEFINITIONS_H
41#define TIME_ARRIVAL_DEFINITIONS_H
42
43
44#include <cassert>
45#include <climits>
46#include <map>
49
50
51namespace woss {
52
53
57 typedef std::map < PDouble , std::complex<double> > TimeArrMap;
58 typedef TimeArrMap::iterator TimeArrIt;
59 typedef TimeArrMap::const_iterator TimeArrCIt;
60 typedef TimeArrMap::reverse_iterator TimeArrRIt;
61 typedef TimeArrMap::const_reverse_iterator TimeArrCRIt;
62
63
67 #define TIMEARR_CUSTOM_DELAY_PRECISION (1.0e-7)
68
69
73 #define TIMEARR_PRESSURE_CONVERSION_DELAY (-INT_MAX)
74
75
82 class TimeArr {
83
84
85 public:
86
87
92 TimeArr( long double custom_delay_prec = TIMEARR_CUSTOM_DELAY_PRECISION );
93
99 TimeArr( TimeArrMap& map, long double custom_delay_prec = TIMEARR_CUSTOM_DELAY_PRECISION );
100
107 TimeArr( const Pressure& pressure, double delay = TIMEARR_PRESSURE_CONVERSION_DELAY, long double custom_delay_prec = TIMEARR_CUSTOM_DELAY_PRECISION );
108
113 TimeArr( const TimeArr& copy );
114
115 virtual ~TimeArr() { }
116
117
122 virtual operator std::complex<double>() const;
123
124
130 virtual TimeArr* create( long double custom_delay_prec = TIMEARR_CUSTOM_DELAY_PRECISION ) const { return new TimeArr(custom_delay_prec); }
131
138 virtual TimeArr* create( TimeArrMap& map, long double custom_delay_prec = TIMEARR_CUSTOM_DELAY_PRECISION ) const {
139 return new TimeArr( map, custom_delay_prec); }
140
148 virtual TimeArr* create( const Pressure& pressure, double delay = TIMEARR_PRESSURE_CONVERSION_DELAY, long double custom_delay_prec = TIMEARR_CUSTOM_DELAY_PRECISION ) const {
149 return new TimeArr(pressure, delay, custom_delay_prec ); }
150
156 virtual TimeArr* create( const TimeArr& copy ) const { return new TimeArr( copy ); }
157
162 virtual TimeArr* clone() const { return new TimeArr(*this); }
163
169 virtual TimeArr* createArray( unsigned int array_size ) const { return new TimeArr[array_size]; }
170
175 static TimeArrMap& createNotValid();
176
181 static TimeArrMap& createImpulse();
182
183
190 TimeArr& insertValue( double delay, const Pressure& pressure );
191
197 void sumValue( double delay, const Pressure& pressure );
198
199
205 TimeArrCIt findValue( double delay ) const { return( time_arr_map.find(delay) ); }
206
207
213 TimeArr& eraseValue( double delay ) { time_arr_map.erase(delay); return *this; }
214
215
222 virtual TimeArr* coherentSumSample( double time_delay );
223
230 virtual TimeArr* incoherentSumSample( double time_delay );
231
239 virtual TimeArr* crop( double time_start, double time_end );
240
248 virtual bool checkPressureAttenuation( double distance, double frequency );
249
250
255 TimeArrCIt begin() const { return time_arr_map.begin(); }
256
261 TimeArrCIt end() const { return time_arr_map.end(); }
262
267 TimeArrCRIt rbegin() const { return time_arr_map.rbegin(); }
268
273 TimeArrCRIt rend() const { return time_arr_map.rend(); }
274
280 TimeArrCIt at( const int i ) const ;
281
287 TimeArrCIt lowerBoundTxLoss( double threshold_db ) const;
288
293 int size() const { return time_arr_map.size(); }
294
299 bool empty() const { return time_arr_map.empty(); }
300
301
305 void clear() { time_arr_map.clear(); }
306
307
314 TimeArr& setDelayPrecision( long double precision );
315
316
321 static void setDebug( bool flag ) { debug = flag; }
322
323
328 double getMaxDelayValue() const { return( time_arr_map.rbegin()->first ); }
329
334 double getMinDelayValue() const { return( time_arr_map.begin()->first ); }
335
340 long double getDelayPrecision() const { return delay_precision; }
341
342
347 virtual bool isValid() const;
348
349
354 virtual bool isConvertedFromPressure() const { return( time_arr_map.size() == 1 && ( time_arr_map.begin()->first == PDouble(TIMEARR_PRESSURE_CONVERSION_DELAY) ) ); }
355
356
362 TimeArr& operator=( const TimeArr& copy ) ;
363
364
371 friend bool operator==( const TimeArr& left, const TimeArr& right ) ;
372
379 friend bool operator!=( const TimeArr& left, const TimeArr& right );
380
381
388 friend const TimeArr operator+( const TimeArr& left, const TimeArr& right );
389
396 friend const TimeArr operator-( const TimeArr& left, const TimeArr& right );
397
398
405 friend const TimeArr operator+( const TimeArr& left, const double right );
406
413 friend const TimeArr operator-( const TimeArr& left, const double right );
414
421 friend const TimeArr operator/( const TimeArr& left, const double right );
422
429 friend const TimeArr operator*( const TimeArr& left, const double right );
430
431
438 friend const TimeArr operator+( const double left, const TimeArr& right );
439
446 friend const TimeArr operator-( const double left, const TimeArr& right );
447
454 friend const TimeArr operator/( const double left, const TimeArr& right );
455
462 friend const TimeArr operator*( const double left, const TimeArr& right );
463
464
471 friend TimeArr& operator+=( TimeArr& left, const TimeArr& right );
472
479 friend TimeArr& operator-=( TimeArr& left, const TimeArr& right );
480
481
488 friend TimeArr& operator+=( TimeArr& left, double right );
489
496 friend TimeArr& operator-=( TimeArr& left, double right );
497
504 friend TimeArr& operator/=( TimeArr& left, double right );
505
512 friend TimeArr& operator*=( TimeArr& left, double right );
513
514
521 friend std::ostream& operator<<( std::ostream& os, const TimeArr& instance );
522
523
524 protected:
525
526
530 static bool debug;
531
532
536 long double delay_precision;
537
538
543
544
545 };
546
547 //non-inline operator declarations
549 const TimeArr operator+( const TimeArr& left, const TimeArr& right );
550
551 const TimeArr operator-( const TimeArr& left, const TimeArr& right );
552
553
554 const TimeArr operator+( const TimeArr& left, const double right );
555
556 const TimeArr operator-( const TimeArr& left, const double right );
557
558 const TimeArr operator/( const TimeArr& left, const double right );
559
560 const TimeArr operator*( const TimeArr& left, const double right );
561
562
563 const TimeArr operator+( const double left, const TimeArr& right );
564
565 const TimeArr operator-( const double left, const TimeArr& right );
566
567 const TimeArr operator/( const double left, const TimeArr& right );
568
569 const TimeArr operator*( const double left, const TimeArr& right );
570
571
572 TimeArr& operator+=( TimeArr& left, const TimeArr& right );
573
574 TimeArr& operator-=( TimeArr& left, const TimeArr& right );
575
576
577 TimeArr& operator+=( TimeArr& left, double right );
578
579 TimeArr& operator-=( TimeArr& left, double right );
580
581 TimeArr& operator/=( TimeArr& left, double right );
582
583 TimeArr& operator*=( TimeArr& left, double right );
584
585
587 //inline functions
594
595
598 time_arr_map.clear();
599 time_arr_map[0.0] = std::complex<double> (1.0 , 0.0);
600 return time_arr_map;
601 }
602
603
604 inline TimeArr& TimeArr::insertValue( double delay, const Pressure& pressure ) {
605 assert( pressure.isValid() );
606 assert( delay >= 0.0 );
607
608 time_arr_map.insert( std::make_pair( delay, pressure ) );
609
610 return *this;
611 }
612
613
614 inline void TimeArr::sumValue( double delay, const Pressure& pressure ) {
615 assert( pressure.isValid() );
616 assert( delay >= 0.0 );
617
618 TimeArrIt it = time_arr_map.find( delay );
619 if ( it == time_arr_map.end() ) time_arr_map.insert( std::make_pair( delay, pressure ) );
620 else it->second += std::complex<double>( pressure );
621 }
622
623
624 inline std::ostream& operator<<( std::ostream& os, const TimeArr& instance ) {
625 os << "size = " << instance.time_arr_map.size() << "; min time_arr = " << instance.time_arr_map.begin()->first
626 << "; pressure db = " << Pressure::getTxLossDb(instance.begin()->second)
627 << "; max time_arr = " << instance.time_arr_map.rbegin()->first
628 << "; pressure db = " << Pressure::getTxLossDb(instance.time_arr_map.rbegin()->second);
629 return os;
630 }
631
632
633 inline bool operator==( const TimeArr& left, const TimeArr& right ) {
634 if ( &left == &right ) return true;
635 return( left.time_arr_map == right.time_arr_map );
636 }
637
638
639 inline bool operator!=( const TimeArr& left, const TimeArr& right ) {
640 if ( &left == &right ) return false;
641 return( left.time_arr_map != right.time_arr_map );
642 }
643
644}
645
646
647#endif /* TIME_ARRIVAL_DEFINITIONS_H */
648
649
650
bool operator!=(const Altimetry &left, const Altimetry &right)
Definition altimetry-definitions.h:846
std::ostream & operator<<(std::ostream &os, const Altimetry &instance)
Definition altimetry-definitions.h:826
Altimetry & operator*=(Altimetry &left, double right)
Definition altimetry-definitions.cpp:367
const Altimetry operator/(const Altimetry &left, const double right)
Definition altimetry-definitions.cpp:285
bool operator==(const Altimetry &left, const Altimetry &right)
Definition altimetry-definitions.h:840
Altimetry & operator+=(Altimetry &left, const Altimetry &right)
Definition altimetry-definitions.cpp:327
const Altimetry operator+(const Altimetry &left, const Altimetry &right)
Definition altimetry-definitions.cpp:257
const Altimetry operator*(const Altimetry &left, const double right)
Definition altimetry-definitions.cpp:292
Altimetry & operator-=(Altimetry &left, const Altimetry &right)
Definition altimetry-definitions.cpp:335
const Altimetry operator-(const Altimetry &left, const Altimetry &right)
Definition altimetry-definitions.cpp:264
Altimetry & operator/=(Altimetry &left, double right)
Definition altimetry-definitions.cpp:359
Custom precision long double class.
Definition custom-precision-double.h:67
Complex attenuated pressure class.
Definition pressure-definitions.h:59
virtual bool isValid() const
Definition pressure-definitions.h:187
static const ::std::complex< double > createNotValid()
Definition pressure-definitions.h:148
double getTxLossDb() const
Definition pressure-definitions.h:202
Channel power delay profile class.
Definition time-arrival-definitions.h:82
friend const TimeArr operator-(const double left, const TimeArr &right)
friend const TimeArr operator+(const TimeArr &left, const TimeArr &right)
virtual TimeArr * create(const TimeArr &copy) const
Definition time-arrival-definitions.h:156
TimeArrCIt findValue(double delay) const
Definition time-arrival-definitions.h:205
virtual TimeArr * incoherentSumSample(double time_delay)
Definition time-arrival-definitions.cpp:172
TimeArrCIt begin() const
Definition time-arrival-definitions.h:255
TimeArrCIt end() const
Definition time-arrival-definitions.h:261
TimeArr & operator=(const TimeArr &copy)
Definition time-arrival-definitions.cpp:97
TimeArrCIt lowerBoundTxLoss(double threshold_db) const
Definition time-arrival-definitions.cpp:116
virtual TimeArr * create(long double custom_delay_prec=TIMEARR_CUSTOM_DELAY_PRECISION) const
Definition time-arrival-definitions.h:130
virtual TimeArr * create(const Pressure &pressure, double delay=TIMEARR_PRESSURE_CONVERSION_DELAY, long double custom_delay_prec=TIMEARR_CUSTOM_DELAY_PRECISION) const
Definition time-arrival-definitions.h:148
TimeArr & insertValue(double delay, const Pressure &pressure)
Definition time-arrival-definitions.h:604
friend TimeArr & operator+=(TimeArr &left, const TimeArr &right)
friend const TimeArr operator*(const double left, const TimeArr &right)
TimeArrCRIt rend() const
Definition time-arrival-definitions.h:273
friend const TimeArr operator+(const TimeArr &left, const double right)
double getMaxDelayValue() const
Definition time-arrival-definitions.h:328
friend TimeArr & operator-=(TimeArr &left, double right)
TimeArrCIt at(const int i) const
Definition time-arrival-definitions.cpp:105
friend const TimeArr operator-(const TimeArr &left, const TimeArr &right)
static TimeArrMap & createNotValid()
Definition time-arrival-definitions.h:588
friend TimeArr & operator/=(TimeArr &left, double right)
TimeArr & setDelayPrecision(long double precision)
Definition time-arrival-definitions.cpp:135
virtual bool isConvertedFromPressure() const
Definition time-arrival-definitions.h:354
friend const TimeArr operator-(const TimeArr &left, const double right)
double getMinDelayValue() const
Definition time-arrival-definitions.h:334
virtual TimeArr * coherentSumSample(double time_delay)
Definition time-arrival-definitions.cpp:160
TimeArr & eraseValue(double delay)
Definition time-arrival-definitions.h:213
virtual TimeArr * crop(double time_start, double time_end)
Definition time-arrival-definitions.cpp:188
friend TimeArr & operator+=(TimeArr &left, double right)
virtual bool isValid() const
Definition time-arrival-definitions.cpp:90
friend const TimeArr operator/(const double left, const TimeArr &right)
static void setDebug(bool flag)
Definition time-arrival-definitions.h:321
friend bool operator!=(const TimeArr &left, const TimeArr &right)
Definition time-arrival-definitions.h:639
static bool debug
Definition time-arrival-definitions.h:530
long double delay_precision
Definition time-arrival-definitions.h:536
friend const TimeArr operator*(const TimeArr &left, const double right)
virtual TimeArr * create(TimeArrMap &map, long double custom_delay_prec=TIMEARR_CUSTOM_DELAY_PRECISION) const
Definition time-arrival-definitions.h:138
friend TimeArr & operator-=(TimeArr &left, const TimeArr &right)
friend const TimeArr operator+(const double left, const TimeArr &right)
friend std::ostream & operator<<(std::ostream &os, const TimeArr &instance)
Definition time-arrival-definitions.h:624
static TimeArrMap & createImpulse()
Definition time-arrival-definitions.h:596
friend const TimeArr operator/(const TimeArr &left, const double right)
TimeArrCRIt rbegin() const
Definition time-arrival-definitions.h:267
friend TimeArr & operator*=(TimeArr &left, double right)
virtual bool checkPressureAttenuation(double distance, double frequency)
Definition time-arrival-definitions.cpp:147
virtual TimeArr * clone() const
Definition time-arrival-definitions.h:162
bool empty() const
Definition time-arrival-definitions.h:299
int size() const
Definition time-arrival-definitions.h:293
void clear()
Definition time-arrival-definitions.h:305
long double getDelayPrecision() const
Definition time-arrival-definitions.h:340
friend bool operator==(const TimeArr &left, const TimeArr &right)
Definition time-arrival-definitions.h:633
virtual TimeArr * createArray(unsigned int array_size) const
Definition time-arrival-definitions.h:169
TimeArrMap time_arr_map
Definition time-arrival-definitions.h:542
void sumValue(double delay, const Pressure &pressure)
Definition time-arrival-definitions.h:614
Provides the interface for the woss::PDouble class.
Definitions and library for woss::Pressure class.
std::map< PDouble, std::complex< double > > TimeArrMap
Definition time-arrival-definitions.h:57