ug4
raster_layer_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_raster_layer_util
34 #define __H__UG_raster_layer_util
35 
36 #include <utility>
37 #include <string>
38 #include <vector>
41 
42 namespace ug{
43 
45  RasterLayerDesc(const std::string& filename, number minHeight) :
46  m_filename(filename), m_minHeight(minHeight) {}
47 
48  const std::string& filename() const {return m_filename;}
49  number min_height() const {return m_minHeight;}
50 
51  private:
52  std::string m_filename;
54 };
55 
57 
58 
60  public:
61  struct layer_t{
63 
66 
67  private:
69  template <class Archive>
70  void serialize( Archive& ar, const unsigned int version)
71  {
72  ar & minHeight;
73  ar & heightfield;
74  }
75  };
76 
77 
80 
81 
83 
87  void load_from_files(const std::vector<LayerDesc>& layerDescs);
88 
89  void load_from_files(const std::vector<SPLayerDesc>& layerDescs);
93 
100  void load_from_files(const std::vector<std::string>& filenames,
101  number minLayerHeight);
102 
103  // void save_to_files(const char* filenamePrefix);
104  // void save_rel_to_glob_table_to_files(const char* filenamePrefix);
105 
106 
107  void resize(size_t newSize);
108 
109  size_t size() const {return m_layers.size();}
110  size_t num_layers() const {return m_layers.size();}
111  bool empty() const {return m_layers.empty();}
112 
113  layer_t& operator[] (size_t i) {return *m_layers[i];}
114  const layer_t& operator[] (size_t i) const {return *m_layers[i];}
115 
116  layer_t& layer (size_t i) {return *m_layers[i];}
117  const layer_t& layer (size_t i) const {return *m_layers[i];}
118 
119  const layer_t& top () const {return *m_layers.back();}
120 
121  Heightfield& heightfield (size_t i) {return layer(i).heightfield;}
122  const Heightfield& heightfield (size_t i) const {return layer(i).heightfield;}
123 
124  void set_min_height (size_t i, number h) {layer(i).minHeight = h;}
125  number min_height (size_t i) const {return layer(i).minHeight;}
126 
127 
129  void invalidate_flat_cells();
130 
132  void invalidate_small_lenses(number minArea);
133 
135  void remove_small_holes(number maxArea);
136 
138 
141 
144 
146  void blur_layers (number alpha, size_t numIterations);
147 
149 
152  std::pair<int, number> trace_line_down (const vector2& c, size_t firstLayer) const;
153 
155 
158  std::pair<int, number> trace_line_up (const vector2& c, size_t firstLayer) const;
159 
161 
163  std::pair<int, int> get_layer_indices (const vector3& c) const;
164 
166 
175  number relative_to_global_height (const vector2& c, number relHeight) const;
176 
178 
184  number relative_to_global_height_simple (const vector2& c, number relHeight) const;
185 
187 
198  void construct_relative_to_global_height_table (size_t iterations, number alpha);
199 
201 
204 
205  private:
207 
209  Field<number>& middle,
210  Field<number>& upper,
211  size_t ix,
212  size_t iy);
213 
214  // BEGIN SERIALIZATION
216 
217  template <class Archive>
218  void save( Archive& ar, const unsigned int version) const
219  {
220  size_t numLayers = m_layers.size();
221  ar & numLayers;
222  for(size_t i = 0; i < m_layers.size(); ++i){
223  ar & *m_layers[i];
224  }
225 
226  size_t numRelToGlob = m_relativeToGlobalHeights.size();
227  ar & numRelToGlob;
228  for(size_t i = 0; i < m_relativeToGlobalHeights.size(); ++i){
229  ar & *m_relativeToGlobalHeights[i];
230  }
231  }
232 
233  template <class Archive>
234  void load( Archive& ar, const unsigned int version)
235  {
236  size_t numLayers = 0;
237  ar & numLayers;
238  m_layers.resize(numLayers);
239  for(size_t i = 0; i < numLayers; ++i){
240  m_layers[i] = make_sp(new layer_t);
241  ar & *m_layers[i];
242  }
243 
244  size_t numRelToGlob = 0;
245  ar & numRelToGlob;
246  m_relativeToGlobalHeights.resize(numRelToGlob);
247  for(size_t i = 0; i < numRelToGlob; ++i){
249  ar & *m_relativeToGlobalHeights[i];
250  }
251  }
252 
253  BOOST_SERIALIZATION_SPLIT_MEMBER()
254  // END SERIALIZATION
255 
257 
264 };
265 
267 
268 }// end of namespace
269 
270 #endif //__H__UG_raster_layer_util
Definition: smart_pointer.h:108
Definition: heightfield_util.h:50
Definition: raster_layer_util.h:59
void load(Archive &ar, const unsigned int version)
Definition: raster_layer_util.h:234
void eliminate_invalid_cells()
eliminates invalid cells by filling those cells with averages of neighboring valid cells
Definition: raster_layer_util.cpp:283
const layer_t & layer(size_t i) const
Definition: raster_layer_util.h:117
std::pair< int, number > trace_line_down(const vector2 &c, size_t firstLayer) const
finds the first valid value at the given x-y-coordinate starting at the specified layer moving downwa...
Definition: raster_layer_util.cpp:301
number upper_lower_dist_relation(Field< number > &lower, Field< number > &middle, Field< number > &upper, size_t ix, size_t iy)
returns dist(middle, upper, ix, iy) / dist(lower, upper, ix, iy)
Definition: raster_layer_util.cpp:527
std::pair< int, number > trace_line_up(const vector2 &c, size_t firstLayer) const
finds the first valid value at the given x-y-coordinate starting at the specified layer moving downwa...
Definition: raster_layer_util.cpp:314
RasterLayerDesc LayerDesc
Definition: raster_layer_util.h:78
void invalidate_relative_to_global_height_table()
invalidates the table construced by 'construct_relative_to_global_height_table'
Definition: raster_layer_util.cpp:521
void construct_relative_to_global_height_table(size_t iterations, number alpha)
Prepares a table for better 'relative_to_global_height' values in invalid inner regions.
Definition: raster_layer_util.cpp:398
void save(Archive &ar, const unsigned int version) const
Definition: raster_layer_util.h:218
const Heightfield & heightfield(size_t i) const
Definition: raster_layer_util.h:122
size_t size() const
Definition: raster_layer_util.h:109
Heightfield & heightfield(size_t i)
Definition: raster_layer_util.h:121
number relative_to_global_height_simple(const vector2 &c, number relHeight) const
transforms a relative height to an absolute height for a given x-y-coordinate.
Definition: raster_layer_util.cpp:375
void remove_small_holes(number maxArea)
removes small holes by expanding the layer in those regions to the specified height
Definition: raster_layer_util.cpp:151
bool empty() const
Definition: raster_layer_util.h:111
void set_min_height(size_t i, number h)
Definition: raster_layer_util.h:124
void resize(size_t newSize)
Definition: raster_layer_util.cpp:83
void invalidate_flat_cells()
invalidates cells in lower levels which are too close to valid cells in higher levels
Definition: raster_layer_util.cpp:93
number relative_to_global_height(const vector2 &c, number relHeight) const
transforms a relative height to an absolute height for a given x-y-coordinate.
Definition: raster_layer_util.cpp:349
SPRasterLayerDesc SPLayerDesc
Definition: raster_layer_util.h:79
layer_t & layer(size_t i)
Definition: raster_layer_util.h:116
void load_from_files(const std::vector< LayerDesc > &layerDescs)
loads raster data from a list of .asc files.
Definition: raster_layer_util.cpp:51
void blur_layers(number alpha, size_t numIterations)
smoothens the values in each layer by averaging with neighboured values
Definition: raster_layer_util.cpp:293
void snap_cells_to_higher_layers()
sets invalid or flat cells to the value of the corresponding cell in the level above
Definition: raster_layer_util.cpp:252
std::vector< SmartPtr< layer_t > > m_layers
Definition: raster_layer_util.h:256
friend class boost::serialization::access
Definition: raster_layer_util.h:215
std::vector< SmartPtr< Heightfield > > m_relativeToGlobalHeights
Definition: raster_layer_util.h:263
void invalidate_small_lenses(number minArea)
invalidates cells that belong to a small lense regarding its horizontal area
Definition: raster_layer_util.cpp:138
size_t num_layers() const
Definition: raster_layer_util.h:110
const layer_t & top() const
Definition: raster_layer_util.h:119
number min_height(size_t i) const
Definition: raster_layer_util.h:125
layer_t & operator[](size_t i)
Definition: raster_layer_util.h:113
std::pair< int, int > get_layer_indices(const vector3 &c) const
returns an index-pair of the layers above and below the specified point
Definition: raster_layer_util.cpp:327
number alpha
double number
Definition: types.h:124
Definition: smart_pointer.h:814
the ug namespace
const number SMALL
Definition: math_constants.h:41
SmartPtr< RasterLayerDesc > SPRasterLayerDesc
Definition: raster_layer_util.h:56
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
Definition: raster_layer_util.h:44
RasterLayerDesc(const std::string &filename, number minHeight)
Definition: raster_layer_util.h:45
const std::string & filename() const
Definition: raster_layer_util.h:48
number min_height() const
Definition: raster_layer_util.h:49
std::string m_filename
Definition: raster_layer_util.h:52
number m_minHeight
Definition: raster_layer_util.h:53
Definition: raster_layer_util.h:61
layer_t()
Definition: raster_layer_util.h:62
void serialize(Archive &ar, const unsigned int version)
Definition: raster_layer_util.h:70
number minHeight
Definition: raster_layer_util.h:65
friend class boost::serialization::access
Definition: raster_layer_util.h:68
Heightfield heightfield
Definition: raster_layer_util.h:64