surface.hpp
Go to the documentation of this file.
1// $Id: surface.hpp 882 2011-09-23 13:10:16Z perroe $
2
3// Copyright (c) 2011, Norwegian Computing Center
4// All rights reserved.
5// Redistribution and use in source and binary forms, with or without modification,
6// are permitted provided that the following conditions are met:
7// • Redistributions of source code must retain the above copyright notice, this
8// list of conditions and the following disclaimer.
9// • Redistributions in binary form must reproduce the above copyright notice, this list of
10// conditions and the following disclaimer in the documentation and/or other materials
11// provided with the distribution.
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
13// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
15// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
17// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
20// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
22#ifndef NRLIB_SURFACE_HPP
23#define NRLIB_SURFACE_HPP
24
25#include <limits>
26
27namespace NRLib {
28 template <class A>
29 class Surface {
30 public:
31 virtual ~Surface();
32
34 virtual Surface * Clone() const = 0;
35
36 virtual A GetZ(double x, double y) const = 0;
37
38 virtual bool EnclosesRectangle(double x_min, double x_max,
39 double y_min, double y_max) const = 0;
40
41 virtual bool IsMissing(A) const { return(false) ;}
42
43 virtual bool IsInsideSurface(double /*x*/, double /*y*/) const = 0;
44
45 virtual void Add(A c) = 0;
46
47 virtual void Multiply(A c) = 0;
48
49 virtual A Min() const = 0;
50 virtual A Max() const = 0;
51
52 virtual double GetXMin() const = 0;
53 virtual double GetYMin() const = 0;
54 virtual double GetXMax() const = 0;
55 virtual double GetYMax() const = 0;
56
57 };
58
59 template <class A>
60 class ConstantSurface : public Surface<A> {
61 public:
63
65 { return new ConstantSurface(*this); }
66
67 A GetZ() const {
68 return z_;
69 }
70
71 bool IsInsideSurface(double /*x*/, double /*y*/) const {return(true);}
72 A GetZ(double /*x*/, double /*y*/) const
73 { return z_; }
74
75 bool EnclosesRectangle(double /*x_min*/, double /*x_max*/,
76 double /*y_min*/, double /*y_max*/) const
77 { return true; }
78
79 void Add(A c) {
80 z_ += c;
81 }
82
83 void Multiply(A c) {
84 z_ *= c;
85 }
86
87 A Min() const {return(z_);}
88 A Max() const {return(z_);}
89
90 double GetXMin() const
91 {
92 if ( std::numeric_limits<double>::has_infinity )
93 return -std::numeric_limits<double>::infinity();
94 else
96 }
97
98 double GetYMin() const
99 {
100 if ( std::numeric_limits<double>::has_infinity )
101 return -std::numeric_limits<double>::infinity();
102 else
104 }
105
106 double GetXMax() const
107 {
108 if ( std::numeric_limits<double>::has_infinity )
109 return(std::numeric_limits<double>::infinity());
110 else
112 }
113
114 double GetYMax() const
115 {
116 if ( std::numeric_limits<double>::has_infinity )
117 return(std::numeric_limits<double>::infinity());
118 else
120 }
121
122 private:
123 A z_;
124 };
125
126 template <class A>
128 {}
129
130 template <class A>
132 : z_(z)
133 {}
134} // namespace NRLib
135
136#endif // NRLIB_SURFACE_HPP
Definition: surface.hpp:60
A GetZ() const
Definition: surface.hpp:67
Surface< A > * Clone() const
Generate a copy of the underlying object.
Definition: surface.hpp:64
A GetZ(double, double) const
Definition: surface.hpp:72
double GetYMax() const
Definition: surface.hpp:114
bool EnclosesRectangle(double, double, double, double) const
Definition: surface.hpp:75
double GetXMin() const
Definition: surface.hpp:90
void Add(A c)
Definition: surface.hpp:79
A Max() const
Definition: surface.hpp:88
A Min() const
Definition: surface.hpp:87
void Multiply(A c)
Definition: surface.hpp:83
ConstantSurface(A z)
Definition: surface.hpp:131
double GetXMax() const
Definition: surface.hpp:106
bool IsInsideSurface(double, double) const
Definition: surface.hpp:71
double GetYMin() const
Definition: surface.hpp:98
Definition: surface.hpp:29
virtual bool IsInsideSurface(double, double) const =0
virtual ~Surface()
Definition: surface.hpp:127
virtual bool IsMissing(A) const
Definition: surface.hpp:41
virtual double GetXMax() const =0
virtual double GetYMax() const =0
virtual Surface * Clone() const =0
Generate a copy of the underlying object.
virtual double GetXMin() const =0
virtual bool EnclosesRectangle(double x_min, double x_max, double y_min, double y_max) const =0
virtual A GetZ(double x, double y) const =0
virtual void Add(A c)=0
virtual void Multiply(A c)=0
virtual A Max() const =0
virtual double GetYMin() const =0
virtual A Min() const =0
Definition: exception.hpp:31
T max(const T v0, const T v1)
Definition: exprtk.hpp:1407
x y * z
Definition: exprtk.hpp:9663
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)