regularsurface.hpp
Go to the documentation of this file.
1// $Id: regularsurface.hpp 1196 2013-09-09 12:01:04Z 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#ifndef NRLIB_REGULARSURFACE_HPP
22#define NRLIB_REGULARSURFACE_HPP
23
24#include <algorithm>
25#include <cmath>
26#include <iostream>
27
28#include "surface.hpp"
29#include "surfaceio.hpp"
30#include "../grid/grid2d.hpp"
31#include "../iotools/stringtools.hpp"
32
33namespace NRLib {
34
37
38template <class A>
39class RegularSurface : public Grid2D<A>, public Surface<A> {
40public:
42
43 RegularSurface(double x0, double y0, double lx, double ly, size_t nx, size_t ny,
44 const A& value = A());
45
46 RegularSurface(double x0, double y0, double lx, double ly, Grid2D<A> grid);
47
54 RegularSurface(const std::string & filename,
56
58 { return new RegularSurface<A>(*this); }
59
63 A GetZ(double x, double y) const;
64
67 A GetZInside(double x, double y) const;
68
70 bool IsInsideSurface(double x, double y) const;
71
72 bool EnclosesRectangle(double x_min, double x_max,
73 double y_min, double y_max) const;
74
76 void Assign(A c) {
77 typename Grid2D<A>::iterator i;
78 for (i=this->begin();i<this->end();i++)
79 *i = c;
80 }
81
82 void Add(A c) {
83 typename Grid2D<A>::iterator i;
84 for (i=this->begin();i<this->end();i++)
85 if (*i != missing_val_)
86 *i += c;
87 }
88
89 void Subtract(A c) {
90 typename Grid2D<A>::iterator i;
91 for (i=this->begin();i<this->end();i++)
92 if (*i != missing_val_)
93 *i -= c;
94 }
95
96 void Multiply(A c) {
97 typename Grid2D<A>::iterator i;
98 for (i=this->begin();i<this->end();i++)
99 if (*i != missing_val_)
100 *i *= c;
101 }
102
106 bool AddNonConform(const Surface<A> * s2);
107 bool SubtractNonConform(const Surface<A> * s2);
108 bool MultiplyNonConform(const Surface<A> * s2);
109 bool DivideNonConform(const Surface<A> *s2);
110
111 A Min() const;
112 A MinNode(size_t &i, size_t &j) const;
113 A Max() const;
114 A MaxNode(size_t &i, size_t &j) const;
115 A Avg() const;
116 // n_nodes is number of nodes with non-missing values.
117 A Avg(int& n_nodes) const;
118
124 inline void GetCorners(double x,
125 double y,
126 A corners[4]) const;
127
130 bool CreateNeighbourAvg(size_t i, size_t j);
131
134 inline size_t FindI(double x) const;
135
138 inline size_t FindJ(double y) const;
139
143 inline void FindIndex(double x, double y, size_t& i, size_t& j) const;
144
145 // Find continuous index
146 void FindContIndex(double x, double y, double& i, double& j) const;
147
153 inline void FindGeneralIndex(double x, double y, int& i, int& j) const;
154
157 inline void FindNearestNodeIndex(double x, double y, size_t& i, size_t& j) const;
158
159 double GetX(size_t i) const
160 { return x_min_ + i*dx_; }
161
162 double GetY(size_t j) const
163 { return y_min_ + j*dy_; }
164
165 void GetXY(size_t i, size_t j, double & x, double & y) const {
166 x = x_min_ + i*dx_;
167 y = y_min_ + j*dy_;
168 }
169
170 void GetXY(size_t index, double & x, double & y) const {
171 size_t j = index / this->GetNI();
172 size_t i = index - j*this->GetNI();
173 GetXY(i, j, x, y);
174 }
175
176 void GetNode(size_t index, double& x, double& y, double& z) const {
177 size_t i, j;
178 this->GetIJ(index, i, j);
179 GetNode(i, j, x, y, z);
180 }
181
182 void GetNode(size_t i, size_t j, double& x, double& y, double& z) const {
183 GetXY(i, j, x, y);
184 z = (*this)(i, j);
185 }
186
187 double GetXMin() const { return x_min_; }
188 double GetYMin() const { return y_min_; }
189 double GetXMax() const { return x_min_ + lx_; }
190 double GetYMax() const { return y_min_ + ly_; }
191 double GetDX() const { return dx_; }
192 double GetDY() const { return dy_; }
193 double GetLengthX() const { return lx_; }
194 double GetLengthY() const { return ly_; }
195
196 void SetDimensions(double x_min, double y_min,
197 double lx, double ly);
198
200 void Resize(size_t ni, size_t nj, const A& val = A());
201
203 bool IsMissing(A val) const {
204 return val == missing_val_;
205 }
206
207 // Change names:
208 // IsMissing(A) ==> EqualsMissingValue(A) ??
209 // IsMissingAt(i,j) ==> GetMissingAt(i,j)
210 // SetMissing(i,j) ==> SetMissingAt(i,j)
211
213 bool IsMissingAt(size_t i, size_t j) const {
214 return (*this)(i, j) == missing_val_;
215 }
216
218 void SetMissing(size_t i, size_t j) {
219 (*this)(i, j) = missing_val_;
220 }
221
222 A GetMissingValue() const { return missing_val_ ;}
223 void SetMissingValue(A missing_val) { missing_val_ = missing_val; }
224
225 const std::string& GetName() const { return name_; }
226 void SetName(const std::string& name) { name_ = name; }
227
234 void ReadFromFile(const std::string& filename,
236
237 void WriteToFile(const std::string& filename,
239
240 void Swap(RegularSurface<A>& other);
241
242private:
243 double CellRelX(double x) const;
244 double CellRelY(double y) const;
245
246 double x_min_;
247 double y_min_;
248 double lx_;
249 double ly_;
250 double dx_;
251 double dy_;
252 // double rotation_;
253
255 std::string name_;
256
258 A missing_val_;
259
260 inline static A GetBilinearZ(A corners[4], double u, double v);
262 inline A GetBilinearZMissingCorners(A corners[4], double u, double v) const;
263};
264
265// ==================== TEMPLATE IMPLEMENTATIONS ====================
266
267template <class A>
269 : Grid2D<A>(0, 0),
270 x_min_(0),
271 y_min_(0),
272 lx_(0),
273 ly_(0),
274 dx_(0),
275 dy_(0),
276 missing_val_(static_cast<A>(-999.0))
277{}
278
279
280template <class A>
281RegularSurface<A>::RegularSurface(double x_min, double y_min,
282 double lx, double ly,
283 size_t nx, size_t ny,
284 const A& value)
285 : Grid2D<A>(nx, ny, value),
286 x_min_(x_min),
287 y_min_(y_min),
288 lx_(lx),
289 ly_(ly),
290 missing_val_(static_cast<A>(-999.0))
291{
292 dx_ = (nx > 1) ? lx / (nx-1) : 1.0;
293 dy_ = (ny > 1) ? ly / (ny-1) : 1.0;
294}
295
296
297template <class A>
298RegularSurface<A>::RegularSurface(double x_min, double y_min,
299 double lx, double ly,
300 Grid2D<A> grid)
301 : Grid2D<A>(grid),
302 x_min_(x_min),
303 y_min_(y_min),
304 lx_(lx),
305 ly_(ly),
306 missing_val_(static_cast<A>(-999.0))
307{
308 size_t ni = grid.GetNI();
309 size_t nj = grid.GetNJ();
310 dx_ = (ni > 1) ? lx / (ni-1) : 1.0;
311 dy_ = (nj > 1) ? ly / (nj-1) : 1.0;
312}
313
314
315template <class A>
318 : lx_(0.0),
319 ly_(0.0),
320 missing_val_(static_cast<A>(-999.0))
321{
322 ReadFromFile(filename, format);
323}
324
325
327template <class A>
328A RegularSurface<A>::GetBilinearZ(A corners[4], double u, double v)
329{
330 A a = corners[0];
331 A b = corners[1] - a;
332 A c = corners[2] - a;
333 A d = corners[3] - a - b - c;
334
335 return static_cast<A>(a + b*u + c*v + d*u*v);
336}
337
338
339template <class A>
340A RegularSurface<A>::GetBilinearZMissingCorners(A corners[4], double u, double v) const
341{
342 double weights[4];
343
344 weights[0] = (1.0-u) * (1.0-v);
345 weights[1] = u * (1.0 - v);
346 weights[2] = (1.0-u) * v;
347 weights[3] = u * v;
348
349 double sum = 0.0;
350 double sum_weights = 0.0;
351
352 for (size_t i = 0; i < 4; ++i) {
353 if (!IsMissing(corners[i])) {
354 sum += weights[i] * corners[i];
355 sum_weights += weights[i];
356 }
357 }
358
359 if (sum_weights == 0.0) {
360 return GetMissingValue();
361 }
362 return static_cast<A>(sum / sum_weights);
363}
364
365
366template <class A>
367A RegularSurface<A>::GetZ(double x, double y) const
368{
369 A corner[4];
370 GetCorners(x, y, corner);
371
372 int n_missing = 0;
373
374 for (int pix = 0; pix < 4; pix++)
375 {
376 if (IsMissing(corner[pix]))
377 n_missing++;
378 }
379
380 if (n_missing == 4) {
381 return(missing_val_);
382 }
383 else {
384 double x1 = CellRelX(x);
385 double y1 = CellRelY(y);
386
387 if (n_missing == 0) {
388 return GetBilinearZ(corner, x1, y1);
389 }
390 else {
391 return GetBilinearZMissingCorners(corner, x1, y1);
392 }
393 }
394}
395
396
397template <class A>
398A RegularSurface<A>::GetZInside(double x, double y) const
399{
400 A corner[4];
401 GetCorners(x, y, corner);
402
403 bool missing = false;
404
405 int pix = 0;
406 while (pix < 4 && !missing) {
407 if (IsMissing(corner[pix]))
408 missing = true;
409 pix++;
410 }
411
412 if (missing)
413 return(missing_val_);
414 else {
415 double x1 = CellRelX(x);
416 double y1 = CellRelY(y);
417 return GetBilinearZ(corner, x1, y1);
418 }
419}
420
421
422template <class A>
423bool RegularSurface<A>::IsInsideSurface(double x, double y) const
424{
425 if (x < GetXMin() || x > GetXMax() || y < GetYMin() || y > GetYMax())
426 return false;
427 return true;
428}
429
430
431template <class A>
433{
434 for (size_t i = 0; i < this->GetN(); i++) {
435 if ((*this)(i) != missing_val_) {
436 double x, y, value;
437 GetXY(i, x, y);
438 value = s2->GetZ(x, y);
439 if (s2->IsMissing(value) == false)
440 (*this)(i) += value;
441 else
442 (*this)(i) = missing_val_;
443 }
444 }
445 return(true);
446}
447
448
449template <class A>
451{
452 for (size_t i = 0; i < this->GetN(); i++) {
453 if ((*this)(i) != missing_val_) {
454 double x, y, value;
455 GetXY(i, x, y);
456 value = s2->GetZ(x, y);
457 if (s2->IsMissing(value) == false)
458 (*this)(i) -= value;
459 else
460 (*this)(i) = missing_val_;
461 }
462 }
463 return(true);
464}
465
466template <class A>
468{
469 for (size_t i = 0; i < this->GetN(); i++) {
470 if ((*this)(i) != missing_val_) {
471 double x, y, value;
472 GetXY(i, x, y);
473 value = s2->GetZ(x, y);
474 if (s2->IsMissing(value) == false)
475 (*this)(i) *= value;
476 else
477 (*this)(i) = missing_val_;
478 }
479 }
480 return(true);
481}
482
483template <class A>
485{
486 for (size_t i = 0; i < this->GetN(); i++) {
487 if ((*this)(i) != missing_val_) {
488 double x, y, value;
489 GetXY(i, x, y);
490 value = s2->GetZ(x, y);
491 if (s2->IsMissing(value) == false)
492 (*this)(i) /= value;
493 else
494 (*this)(i) = missing_val_;
495 }
496 }
497 return(true);
498}
499
500
501template <class A>
503{
504 A minVal = (*this)(0);
505 typename std::vector<A>::const_iterator i;
506 for (i = this->begin(); i < this->end(); i++) {
507 if ((IsMissing(minVal) || (*i) < minVal) && IsMissing(*i) == false)
508 minVal = *i;
509 }
510 return minVal;
511}
512
513template <class A>
514A RegularSurface<A>::MinNode(size_t &i, size_t &j) const
515{
516 A minVal = (*this)(0);
517 typename std::vector<A>::const_iterator it;
518 size_t min_index = 0;
519 for (it = this->begin(); it < this->end(); it++) {
520 if ((IsMissing(minVal) || (*it) < minVal) && IsMissing(*it) == false) {
521 minVal = *it;
522 min_index = static_cast<size_t> (it - this->begin());
523 }
524 }
525 this->GetIJ(min_index, i, j);
526 return minVal;
527}
528
529template <class A>
531{
532 A maxVal = (*this)(0);
533 typename std::vector<A>::const_iterator i;
534 for (i = this->begin(); i < this->end(); i++) {
535 if ((IsMissing(maxVal) || (*i) > maxVal) && IsMissing(*i) == false)
536 maxVal = *i;
537 }
538 return maxVal;
539}
540
541template <class A>
542A RegularSurface<A>::MaxNode(size_t &i, size_t &j) const
543{
544 A maxVal = (*this)(0);
545 typename std::vector<A>::const_iterator it;
546 size_t max_index = 0;
547 for (it = this->begin(); it < this->end(); it++) {
548 if ((IsMissing(maxVal) || (*it) > maxVal) && IsMissing(*it) == false) {
549 maxVal = *it;
550 max_index = static_cast<size_t> (it - this->begin());
551 }
552 }
553 this->GetIJ(max_index, i, j);
554 return maxVal;
555}
556
557template <class A>
559{
560 int n;
561 return Avg(n);
562}
563
564
565template <class A>
566A RegularSurface<A>::Avg(int& n_nodes) const
567{
568 A sum = static_cast<A>(0);
569 int count = 0;
570 typename std::vector<A>::const_iterator i;
571 for (i = this->begin(); i < this->end(); i++) {
572 if (!IsMissing(*i)) {
573 sum += *i;
574 count++;
575 }
576 }
577 double avg;
578 if (count > 0)
579 avg = sum / count;
580 else
581 avg = missing_val_;
582
583 n_nodes = count;
584 return avg;
585}
586
587
588template <class A>
589bool RegularSurface<A>::EnclosesRectangle(double x_min, double x_max,
590 double y_min, double y_max) const
591{
592 if (x_min < GetXMin() || x_max > GetXMax() ||
593 y_min < GetYMin() || y_max > GetYMax()) {
594 return false;
595 }
596
597 return true;
598}
599
600
601template <class A>
602size_t RegularSurface<A>::FindI(double x) const
603{
604 assert (x >= GetXMin() && x <= GetXMax());
605 return static_cast<size_t>( (x-GetXMin()) / GetDX() );
606}
607
608
609template <class A>
610size_t RegularSurface<A>::FindJ(double y) const
611{
612 assert (y >= GetYMin() && y <= GetYMax());
613 return static_cast<size_t>( (y-GetYMin()) / GetDY() );
614}
615
616
617template <class A>
618void RegularSurface<A>::FindIndex(double x, double y, size_t& i, size_t& j) const
619{
620 assert(x >= GetXMin() && x <= GetXMax() &&
621 y >= GetYMin() && y <= GetYMax());
622
623 i = static_cast<size_t>( (x-GetXMin()) / GetDX() );
624 j = static_cast<size_t>( (y-GetYMin()) / GetDY() );
625}
626
627
628template <class A>
629void RegularSurface<A>::FindContIndex(double x, double y, double& i, double& j) const
630{
631 assert(x >= GetXMin() && x <= GetXMax() &&
632 y >= GetYMin() && y <= GetYMax());
633
634 i = (x-GetXMin()) / GetDX() ;
635 j = (y-GetYMin()) / GetDY() ;
636}
637
638
639template <class A>
640void RegularSurface<A>::FindGeneralIndex(double x, double y, int& i, int& j) const
641{
642 i = static_cast<int>(std::floor( (x-GetXMin()) / GetDX() ));
643 j = static_cast<int>(std::floor( (y-GetYMin()) / GetDY() ));
644}
645
646
647template <class A>
648void RegularSurface<A>::FindNearestNodeIndex(double x, double y, size_t& i, size_t& j) const
649{
650 int tmp_i, tmp_j;
651 int ni = static_cast<int>(this->GetNI());
652 int nj = static_cast<int>(this->GetNJ());
653 FindGeneralIndex(x + 0.5*dx_, y + 0.5*dy_, tmp_i, tmp_j);
654 if (tmp_i < 0)
655 tmp_i = 0;
656 else if (tmp_i >= ni)
657 tmp_i = ni - 1;
658
659 if (tmp_j < 0)
660 tmp_j = 0;
661 else if (tmp_j >= nj)
662 tmp_j = nj - 1;
663
664 i = static_cast<size_t>(tmp_i);
665 j = static_cast<size_t>(tmp_j);
666}
667
668
669template <class A>
671 double y,
672 A corners[4]) const
673{
674 int i, j;
675 int ni = static_cast<int>(this->GetNI());
676 int nj = static_cast<int>(this->GetNJ());
677 FindGeneralIndex(x, y, i , j);
678
679 if (i+1 >= 0 && i < ni && j+1 >= 0 && j < nj) {
680 if (i >= 0 && j >= 0)
681 corners[0] = (*this)(i, j);
682 else
683 corners[0] = missing_val_;
684 if (i+1 < ni && j >= 0)
685 corners[1] = (*this)(i+1, j);
686 else
687 corners[1] = missing_val_;
688 if (i >= 0 && j+1 < nj)
689 corners[2] = (*this)(i, j+1);
690 else
691 corners[2] = missing_val_;
692 if (i+1 < ni && j+1 < nj)
693 corners[3] = (*this)(i+1, j+1);
694 else
695 corners[3] = missing_val_;
696 }
697 else {
698 corners[0] = missing_val_;
699 corners[1] = missing_val_;
700 corners[2] = missing_val_;
701 corners[3] = missing_val_;
702 }
703}
704
705
706template <class A>
708{
709 double sum = 0.0;
710 int n = 0;
711 if (i > 0) {
712 if (j > 0) {
713 if (!IsMissingAt(i-1,j-1)) {
714 sum += (*this)(i-1,j-1);
715 n++;
716 }
717 }
718 if (j < this->GetNJ() - 1) {
719 if (!IsMissingAt(i-1,j+1)) {
720 sum += (*this)(i-1,j+1);
721 n++;
722 }
723 }
724 if (!IsMissingAt(i-1,j)) {
725 sum += (*this)(i-1,j);
726 n++;
727 }
728 }
729 if (i < this->GetNI() - 1) {
730 if (j > 0) {
731 if (!IsMissingAt(i+1,j-1)) {
732 sum += (*this)(i+1,j-1);
733 n++;
734 }
735 }
736 if (j < this->GetNJ() - 1) {
737 if (!IsMissingAt(i+1,j+1)) {
738 sum += (*this)(i+1,j+1);
739 n++;
740 }
741 }
742 if (!IsMissingAt(i+1,j)) {
743 sum += (*this)(i+1,j);
744 n++;
745 }
746 }
747
748 if (j > 0) {
749 if (!IsMissingAt(i,j-1)) {
750 sum += (*this)(i,j-1);
751 n++;
752 }
753 }
754 if (j < this->GetNJ() - 1) {
755 if (!IsMissingAt(i,j+1)) {
756 sum += (*this)(i,j+1);
757 n++;
758 }
759 }
760
761 double avg = missing_val_;
762 bool non_missing = false;
763 if (n > 0) {
764 avg = sum / n;
765 non_missing = true;
766 }
767
768 (*this)(i,j) = avg;
769 return (non_missing);
770}
771
772
773template <class A>
774void RegularSurface<A>::SetDimensions(double x_min, double y_min,
775 double lx, double ly)
776{
777 x_min_ = x_min;
778 y_min_ = y_min;
779 lx_ = lx;
780 ly_ = ly;
781 size_t ni = Grid2D<A>::GetNI();
782 size_t nj = Grid2D<A>::GetNJ();
783 dx_ = (ni > 1) ? lx / (ni - 1) : 1.0;
784 dy_ = (nj > 1) ? ly / (nj - 1) : 1.0;
785}
786
787
788template <class A>
789void RegularSurface<A>::Resize(size_t nx, size_t ny, const A& value)
790{
791 Grid2D<A>::Resize(nx, ny, value);
792 dx_ = (nx > 1) ? lx_ / (nx-1) : 1.0;
793 dy_ = (ny > 1) ? ly_ / (ny-1) : 1.0;
794}
795
796
797template <class A>
800{
801 if (format == SURF_UNKNOWN) {
802 format = FindSurfaceFileType(filename);
803 if (format == SURF_UNKNOWN) {
804 throw FileFormatError("Failed to determine file format for surface file: " + filename);
805 }
806 }
807
808 double angle = 0.0;
809
810 switch (format) {
812 ReadIrapClassicAsciiSurf(filename, *this, angle);
813 break;
815 ReadStormBinarySurf(filename, *this);
816 break;
817 case SURF_SGRI:
818 ReadSgriSurf(filename, *this, angle);
819 break;
820 default:
821 throw FileFormatError("Reading of file " + filename + " on format " + ToString(format)
822 + " as non-rotated grid is currently not supported.");
823 }
824
825 if (angle != 0.0) {
826 throw FileFormatError("Error reading regular surface: " + filename
827 + ". Rotated grids are not supported.");
828 }
829}
830
831
832template <class A>
835{
836 switch (format) {
838 WriteIrapClassicAsciiSurf(*this, 0.0, filename);
839 break;
841 WriteStormBinarySurf(*this, filename);
842 break;
843 default:
844 throw FileFormatError("Writing of surface to file " + filename + " on format "
845 + ToString(format) + " is currently not supported.");
846 }
847}
848
849
850template <class A>
851double RegularSurface<A>::CellRelX(double x) const
852{
853 double i;
854 return std::modf((x-GetXMin())/GetDX(), &i);
855}
856
857
858template <class A>
859double RegularSurface<A>::CellRelY(double y) const
860{
861 double j;
862 return std::modf((y-GetYMin())/GetDY(), &j);
863}
864
865
866template <class A>
868{
869 Grid2D<A>::Swap(other);
870 std::swap(x_min_, other.x_min_);
871 std::swap(y_min_, other.y_min_);
872 std::swap(lx_, other.lx_);
873 std::swap(ly_, other.ly_);
874 std::swap(dx_, other.dx_);
875 std::swap(dy_, other.dy_);
876 std::swap(name_, other.name_);
877 std::swap(missing_val_, other.missing_val_);
878}
879
880
881} // namespace NRLib
882
883#endif // NRLIB_REGULARSURFACE_HPP
const cJSON *const b
Definition: cJSON.h:251
const char *const name
Definition: cJSON.h:258
int index
Definition: cJSON.h:168
int count
Definition: cJSON.h:212
char const int const cJSON_bool format
Definition: cJSON.h:161
const char *const string
Definition: cJSON.h:170
Definition: exception.hpp:71
Definition: grid2d.hpp:32
virtual void Resize(size_t ni, size_t nj, const A &val=A())
Definition: grid2d.hpp:101
std::vector< A >::iterator iterator
Definition: grid2d.hpp:34
void Swap(Grid2D< A > &other)
Definition: grid2d.hpp:174
iterator end()
Definition: grid2d.hpp:56
void GetIJ(size_t index, size_t &i, size_t &j) const
Definition: grid2d.hpp:153
size_t GetNI() const
Definition: grid2d.hpp:61
iterator begin()
Definition: grid2d.hpp:55
size_t GetNJ() const
Definition: grid2d.hpp:62
Definition: regularsurface.hpp:39
A GetZInside(double x, double y) const
Definition: regularsurface.hpp:398
void GetXY(size_t i, size_t j, double &x, double &y) const
Definition: regularsurface.hpp:165
void FindContIndex(double x, double y, double &i, double &j) const
Definition: regularsurface.hpp:629
bool IsMissing(A val) const
Check if grid value is missing.
Definition: regularsurface.hpp:203
size_t FindJ(double y) const
Definition: regularsurface.hpp:610
bool MultiplyNonConform(const Surface< A > *s2)
Definition: regularsurface.hpp:467
bool IsInsideSurface(double x, double y) const
Checks if point is inside definition area for surface.
Definition: regularsurface.hpp:423
void Subtract(A c)
Definition: regularsurface.hpp:89
double GetDX() const
Definition: regularsurface.hpp:191
void SetDimensions(double x_min, double y_min, double lx, double ly)
Definition: regularsurface.hpp:774
double GetXMin() const
Definition: regularsurface.hpp:187
bool DivideNonConform(const Surface< A > *s2)
Definition: regularsurface.hpp:484
double GetYMin() const
Definition: regularsurface.hpp:188
Surface< A > * Clone() const
Generate a copy of the underlying object.
Definition: regularsurface.hpp:57
bool CreateNeighbourAvg(size_t i, size_t j)
Definition: regularsurface.hpp:707
double GetDY() const
Definition: regularsurface.hpp:192
size_t FindI(double x) const
Definition: regularsurface.hpp:602
void Add(A c)
Definition: regularsurface.hpp:82
bool EnclosesRectangle(double x_min, double x_max, double y_min, double y_max) const
Definition: regularsurface.hpp:589
A GetMissingValue() const
Definition: regularsurface.hpp:222
void SetMissingValue(A missing_val)
Definition: regularsurface.hpp:223
A Avg() const
Definition: regularsurface.hpp:558
void ReadFromFile(const std::string &filename, SurfaceFileFormat format=SURF_UNKNOWN)
Read surface file on given format.
Definition: regularsurface.hpp:798
A GetZ(double x, double y) const
Definition: regularsurface.hpp:367
void SetMissing(size_t i, size_t j)
Set missing.
Definition: regularsurface.hpp:218
double GetXMax() const
Definition: regularsurface.hpp:189
void Resize(size_t ni, size_t nj, const A &val=A())
Resize grid. Overrides Grid2D's resize.
Definition: regularsurface.hpp:789
void WriteToFile(const std::string &filename, SurfaceFileFormat format=SURF_STORM_BINARY) const
Definition: regularsurface.hpp:833
void GetCorners(double x, double y, A corners[4]) const
Definition: regularsurface.hpp:670
A Max() const
Definition: regularsurface.hpp:530
double GetYMax() const
Definition: regularsurface.hpp:190
bool AddNonConform(const Surface< A > *s2)
Definition: regularsurface.hpp:432
void FindNearestNodeIndex(double x, double y, size_t &i, size_t &j) const
Definition: regularsurface.hpp:648
double GetLengthY() const
Definition: regularsurface.hpp:194
double GetY(size_t j) const
Definition: regularsurface.hpp:162
RegularSurface()
Definition: regularsurface.hpp:268
void SetName(const std::string &name)
Definition: regularsurface.hpp:226
double GetLengthX() const
Definition: regularsurface.hpp:193
void FindGeneralIndex(double x, double y, int &i, int &j) const
Definition: regularsurface.hpp:640
void Swap(RegularSurface< A > &other)
Definition: regularsurface.hpp:867
void GetNode(size_t index, double &x, double &y, double &z) const
Definition: regularsurface.hpp:176
bool SubtractNonConform(const Surface< A > *s2)
Definition: regularsurface.hpp:450
A MinNode(size_t &i, size_t &j) const
Definition: regularsurface.hpp:514
void FindIndex(double x, double y, size_t &i, size_t &j) const
Definition: regularsurface.hpp:618
A Min() const
Definition: regularsurface.hpp:502
void Assign(A c)
Sets all values on the surface to a constant value.
Definition: regularsurface.hpp:76
A MaxNode(size_t &i, size_t &j) const
Definition: regularsurface.hpp:542
const std::string & GetName() const
Definition: regularsurface.hpp:225
double GetX(size_t i) const
Definition: regularsurface.hpp:159
bool IsMissingAt(size_t i, size_t j) const
Check if grid value is missing.
Definition: regularsurface.hpp:213
void Multiply(A c)
Definition: regularsurface.hpp:96
void GetNode(size_t i, size_t j, double &x, double &y, double &z) const
Definition: regularsurface.hpp:182
void GetXY(size_t index, double &x, double &y) const
Definition: regularsurface.hpp:170
Definition: surface.hpp:29
virtual bool IsMissing(A) const
Definition: surface.hpp:41
virtual A GetZ(double x, double y) const =0
not_this_one begin(...)
Definition: exception.hpp:31
void WriteIrapClassicAsciiSurf(const RegularSurface< A > &surf, double angle, const std::string &filename)
Definition: surfaceio.hpp:650
void ReadIrapClassicAsciiSurf(const std::string &filename, RegularSurface< A > &surface, double &angle)
Definition: surfaceio.hpp:180
void ReadSgriSurf(const std::string &filename, RegularSurface< A > &surface, double &angle)
Definition: surfaceio.hpp:262
SurfaceFileFormat FindSurfaceFileType(const std::string &filename)
Find type of file.
void WriteStormBinarySurf(const RegularSurface< A > &surf, const std::string &filename)
Definition: surfaceio.hpp:700
SurfaceFileFormat
Definition: surfaceio.hpp:38
@ SURF_STORM_BINARY
Definition: surfaceio.hpp:41
@ SURF_SGRI
Definition: surfaceio.hpp:42
@ SURF_UNKNOWN
Definition: surfaceio.hpp:39
@ SURF_IRAP_CLASSIC_ASCII
Definition: surfaceio.hpp:40
std::string ToString(const T obj, int precision=-99999)
Definition: stringtools.hpp:177
void ReadStormBinarySurf(const std::string &filename, RegularSurface< A > &surface)
Definition: surfaceio.hpp:119
x y * z
Definition: exprtk.hpp:9663
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
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)