volume.hpp
Go to the documentation of this file.
1// $Id: volume.hpp 1061 2012-09-13 09:09:57Z georgsen $
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_VOLUME_HPP
23#define NRLIB_VOLUME_HPP
24
25#include <fstream>
26
27namespace NRLib {
28 template <class A>
29 class Surface;
30
31 class Volume {
32 public:
34 Volume(double x_min, double y_min, double z_min, double lx, double ly, double lz, double angle);
35
37 Volume(double x_min,
38 double y_min,
39 double lx,
40 double ly,
41 const Surface<double> & top,
42 const Surface<double> & bot,
43 double angle);
44
45 Volume(const Volume& volume);
46 virtual ~Volume();
47 Volume& operator=(const Volume& rhs);
48
49 void SetDimensions(double x_min, double y_min,
50 double lx, double ly);
51 void SetAngle(double angle);
52 void SetTolerance(double tolerance){tolerance_=tolerance;}
53 double GetTolerance(){return tolerance_;}
54
55 double GetXMin() const {return x_min_;}
56 double GetYMin() const {return y_min_;}
57
59 double GetZMin(size_t nx, size_t ny) const;
60 double GetZMax(size_t nx, size_t ny) const;
61
62 double GetLX() const {return lx_;}
63 double GetLY() const {return ly_;}
64 double GetAngle() const {return angle_;}
65
67 double GetLZ() const {return lz_;}
68
70 void GetXYFromRelative(double rel_x, double rel_y, double &x, double &y) const{
71 LocalToGlobalCoord(rel_x*lx_, rel_y*ly_, x, y);
72 }
73
75 double GetTopZMin(size_t nx, size_t ny) const; //Equal to GetZMin
76 double GetTopZMax(size_t nx, size_t ny) const;
77 double GetBotZMin(size_t nx, size_t ny) const;
78 double GetBotZMax(size_t nx, size_t ny) const; //Equal to GetZMax
79
81 void SetSurfaces(const Surface<double>& top_surf,
82 const Surface<double>& bot_surf,
83 bool skip_check = true); //Sometimes, we do not want an area cover check here.
84
85 /*
86 void SetSurfaces(const Surface<double>& top_surf,
87 const Surface<double>& bot_surf);
88 const Surface<double>& erosion_top,
89 const Surface<double>& erosion_bot);
90 */
91
92 const Surface<double> & GetTopSurface() const {return *z_top_;}
93 const Surface<double> & GetBotSurface() const {return *z_bot_;}
94 //const Surface<double>& GetErosionTop() const {return *erosion_top_;}
95 //const Surface<double>& GetErosionBot() const {return *erosion_bot_;}
96 Surface<double> & GetTopSurface() {return *z_top_;}
97 Surface<double> & GetBotSurface() {return *z_bot_;}
98
99 int IsInside(double x, double y) const;
100 bool IsInside(double x, double y, double z)const;
101 int IsInsideTolerance(double x, double y)const;
102 bool IsInsideZTolerance(double x, double y, double z, double tolerance) const;
103
104 void FindCenter(double & x, double & y, double & z) const;
105
107 bool CheckSurface(const Surface<double>& surface) const;
108
109 protected:
112 void WriteVolumeToFile(std::ofstream& file,
113 const std::string& filename,
114 bool remove_path = true) const;
115 void ReadVolumeFromFile(std::ifstream& file, int line, const std::string& path);
116
119 void GlobalToLocalCoord(double global_x, double global_y,
120 double& local_x, double& local_y) const;
121
122 void LocalToGlobalCoord(double local_x, double local_y,
123 double& global_x, double& global_y) const;
124
125 private:
126 virtual double RecalculateLZ();
128 bool CheckSurfaces() const;
130 double GetZExtreme(size_t nx, size_t ny, const Surface<double> * surf, bool getmin) const;
131
132 double x_min_;
133 double y_min_;
134 double lx_;
135 double ly_;
136 double lz_;
137 Surface<double>* z_top_;
138 Surface<double>* z_bot_;
139 //Surface<double>* erosion_top_;
140 //Surface<double>* erosion_bot_;
141 double angle_;
142 double tolerance_;
143 };
144} // namespace NRLib
145
146#endif // NRLIB_VOLUME_HPP
const char *const string
Definition: cJSON.h:170
Definition: volume.hpp:31
double GetLX() const
Definition: volume.hpp:62
double GetBotZMin(size_t nx, size_t ny) const
void SetAngle(double angle)
double GetLY() const
Definition: volume.hpp:63
double GetZMin(size_t nx, size_t ny) const
Get extreme values of z for volume, with nx, ny resolution.
Volume(const Volume &volume)
void LocalToGlobalCoord(double local_x, double local_y, double &global_x, double &global_y) const
double GetZMax(size_t nx, size_t ny) const
void WriteVolumeToFile(std::ofstream &file, const std::string &filename, bool remove_path=true) const
Reader and writer on storm-format.
double GetTopZMin(size_t nx, size_t ny) const
Get z-range for top and bottom surfaces, with nx, ny resolution.
double GetTolerance()
Definition: volume.hpp:53
void SetDimensions(double x_min, double y_min, double lx, double ly)
bool CheckSurface(const Surface< double > &surface) const
Checks if surface covers the whole volume.
const Surface< double > & GetBotSurface() const
Definition: volume.hpp:93
double GetBotZMax(size_t nx, size_t ny) const
Volume(double x_min, double y_min, double lx, double ly, const Surface< double > &top, const Surface< double > &bot, double angle)
Constructor with surfaces.
void GetXYFromRelative(double rel_x, double rel_y, double &x, double &y) const
rel_x and rel_y in [0,1].
Definition: volume.hpp:70
double GetXMin() const
Definition: volume.hpp:55
virtual ~Volume()
void SetSurfaces(const Surface< double > &top_surf, const Surface< double > &bot_surf, bool skip_check=true)
Set surfaces.
void ReadVolumeFromFile(std::ifstream &file, int line, const std::string &path)
bool IsInsideZTolerance(double x, double y, double z, double tolerance) const
void GlobalToLocalCoord(double global_x, double global_y, double &local_x, double &local_y) const
The local coorinates are (0,0) in (x_min, y_min), and have the same orientation as the volume.
Surface< double > & GetTopSurface()
Definition: volume.hpp:96
Surface< double > & GetBotSurface()
Definition: volume.hpp:97
double GetYMin() const
Definition: volume.hpp:56
const Surface< double > & GetTopSurface() const
Definition: volume.hpp:92
int IsInsideTolerance(double x, double y) const
void SetTolerance(double tolerance)
Definition: volume.hpp:52
double GetAngle() const
Definition: volume.hpp:64
double GetTopZMax(size_t nx, size_t ny) const
bool IsInside(double x, double y, double z) const
Volume(double x_min, double y_min, double z_min, double lx, double ly, double lz, double angle)
int IsInside(double x, double y) const
void FindCenter(double &x, double &y, double &z) const
Volume & operator=(const Volume &rhs)
double GetLZ() const
Maximum height of grid.
Definition: volume.hpp:67
Definition: exception.hpp:31
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)