ug4
heightfield_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG_heightfield_util
34 #define __H__UG_heightfield_util
35 
36 #include "lib_grid/lg_base.h"
37 #include "common/util/field.h"
39 
40 namespace ug{
41 
45 
51  public:
52  Heightfield();
53 
55 
64  number interpolate (number x, number y, int interpOrder) const;
65 
66  number interpolate (const vector2& c, int interpOrder) const
67  {
68  return interpolate(c.x(), c.y(), interpOrder);
69  }
70 
72  {
73  return interpolate(x, y, 0);
74  }
75 
76  number interpolate (const vector2& c) const
77  {
78  return interpolate(c.x(), c.y(), 0);
79  }
85  std::pair<int, int> coordinate_to_index(number x, number y) const;
86 
88  vector2 index_to_coordinate(int ix, int iy) const;
89 
91  vector2 extent() const;
92 
94  const Field<number>& field() const {return m_field;}
95 
96  const vector2& cell_size() const {return m_cellSize;}
97  void set_cell_size(const vector2& s) {m_cellSize = s;}
98 
99  const vector2& offset() const {return m_offset;}
100  void set_offset(const vector2& o) {m_offset = o;}
101 
104 
105  // moves the heightfield by altering it's offset
106  void move(const vector2& v) {m_offset += v;}
107 
109  void blur(number alpha, size_t numIterations);
110 
112 
114 
115  private:
116  // BEGIN SERIALIZATION
118 
119  template <class Archive>
120  void serialize( Archive& ar, const unsigned int version)
121  {
122  ar & m_cellSize;
123  ar & m_offset;
124  ar & m_noDataValue;
125  ar & m_field;
126  }
127  // END SERIALIZATION
128 
129 
134 };
135 
136 
138 void UG_API
139 LoadHeightfieldFromASC(Heightfield& field, const char* filename);
140 
142 void UG_API
144  const Heightfield& hfield,
146 
148 void UG_API
150  const Heightfield& hfield,
152 
153 }// end of namespace
154 
155 #endif //__H__UG_heightfield_util
parameterString s
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
Definition: heightfield_util.h:50
number interpolate(const vector2 &c, int interpOrder) const
returns the interpolated value at the given location.
Definition: heightfield_util.h:66
const vector2 & cell_size() const
Definition: heightfield_util.h:96
std::pair< int, int > coordinate_to_index(number x, number y) const
returns the index-tuple of the closest field-entry
Definition: heightfield_util.cpp:106
Field< number > & field()
Definition: heightfield_util.h:93
bool eliminate_invalid_cells()
eliminates invalid cells by repeatedly filling those cells with averages of neighboring cells
Definition: heightfield_util.cpp:143
vector2 m_cellSize
Definition: heightfield_util.h:131
void set_offset(const vector2 &o)
Definition: heightfield_util.h:100
const vector2 & offset() const
Definition: heightfield_util.h:99
vector2 m_offset
Definition: heightfield_util.h:132
number m_noDataValue
Definition: heightfield_util.h:133
const Field< number > & field() const
Definition: heightfield_util.h:94
void move(const vector2 &v)
Definition: heightfield_util.h:106
void set_no_data_value(number val)
Definition: heightfield_util.h:103
number interpolate(const vector2 &c) const
returns the interpolated value at the given location.
Definition: heightfield_util.h:76
Field< number > m_field
Definition: heightfield_util.h:130
number interpolate(number x, number y) const
returns the interpolated value at the given location.
Definition: heightfield_util.h:71
Heightfield()
Definition: heightfield_util.cpp:43
number interpolate(number x, number y, int interpOrder) const
returns the interpolated value at the given location.
Definition: heightfield_util.cpp:51
vector2 index_to_coordinate(int ix, int iy) const
returns the coordinate of the given cell (specified through an index-tuple)
Definition: heightfield_util.cpp:125
void serialize(Archive &ar, const unsigned int version)
Definition: heightfield_util.h:120
number no_data_value() const
Definition: heightfield_util.h:102
friend class boost::serialization::access
Definition: heightfield_util.h:117
void blur(number alpha, size_t numIterations)
Smoothens the field by adjusting the value of each pixel towards the average of its neighbours.
Definition: heightfield_util.cpp:137
void set_cell_size(const vector2 &s)
Definition: heightfield_util.h:97
vector2 extent() const
returns the x- and y-extent of the heightfield
Definition: heightfield_util.cpp:131
number alpha
#define UG_API
Definition: ug_config.h:65
double number
Definition: types.h:124
the ug namespace
void LoadHeightfieldFromASC(Heightfield &hfield, const char *filename)
Definition: heightfield_util.cpp:170
void CreateGridFromField(Grid &grid, const Field< number > &field, const vector2 &cellSize, const vector2 &offset, number noDataValue, Grid::VertexAttachmentAccessor< APosition > aaPos)
Definition: field_util.cpp:41
void CreateGridFromFieldBoundary(Grid &grid, const Field< number > &field, const vector2 &cellSize, const vector2 &offset, number noDataValue, Grid::VertexAttachmentAccessor< APosition > aaPos)
Definition: field_util.cpp:117