LCOV - code coverage report
Current view: top level - ugbase/lib_grid/algorithms - heightfield_util.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 17 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 4 0

            Line data    Source code
       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"
      38              : #include "common/boost_serialization.h"
      39              : 
      40              : namespace ug{
      41              : 
      42              : ////////////////////////////////////////////////////////////////////////////////
      43              : ///     A heightfield represents a grid of number-values together with descriptors for
      44              : ///     the cell dimensions and the total offset.
      45              : /** You can manually create heightfields or load them from a file. Given a heightfield
      46              :  * you may create a quad/tri grid or extract the heightfields boundary into a grid.
      47              :  * Have a look at field_util.h, too, which declares some useful functions (e.g. blurring).
      48              :  * \sa LoadHeightfieldFromASC, CreateGridFromField, CreateGridFromFieldBoundary
      49              :  */
      50            0 : UG_API class Heightfield{
      51              :         public:
      52              :                 Heightfield();
      53              :                 
      54              :         ///     returns the interpolated value at the given location.
      55              :         /** returns the interpolated value at the given location. Through 'interpOrder'
      56              :          * one may specify the order of interpolation:
      57              :          *      - 0: piecewise constant (nearest entry)
      58              :          *      - 1: linear
      59              :          *
      60              :          * \todo: add a method 'set_interpolation_method' to also support
      61              :          * bilinear- or spline-interpolation
      62              :          * \{ */
      63              : 
      64              :                 number  interpolate (number x, number y, int interpOrder) const;
      65              :                 
      66              :                 number  interpolate (const vector2& c, int interpOrder) const
      67              :                 {
      68            0 :                         return interpolate(c.x(), c.y(), interpOrder);
      69              :                 }
      70              : 
      71            0 :                 number  interpolate (number x, number y) const
      72              :                 {
      73            0 :                         return interpolate(x, y, 0);
      74              :                 }
      75              : 
      76              :                 number  interpolate (const vector2& c) const
      77              :                 {
      78            0 :                         return interpolate(c.x(), c.y(), 0);
      79              :                 }
      80              :         /** \} */
      81              : 
      82              : 
      83              : 
      84              :         ///     returns the index-tuple of the closest field-entry
      85              :                 std::pair<int, int> coordinate_to_index(number x, number y) const;
      86              : 
      87              :         ///     returns the coordinate of the given cell (specified through an index-tuple)
      88              :                 vector2 index_to_coordinate(int ix, int iy) const;
      89              : 
      90              :         ///     returns the x- and y-extent of the heightfield
      91              :                 vector2 extent() const;
      92              : 
      93            0 :                 Field<number>& field()                                        {return m_field;}
      94            0 :                 const Field<number>& field() const            {return m_field;}
      95              : 
      96            0 :                 const vector2& cell_size() const            {return m_cellSize;}
      97              :                 void set_cell_size(const vector2& s)        {m_cellSize = s;}
      98              : 
      99            0 :                 const vector2& offset() const                       {return m_offset;}
     100              :                 void set_offset(const vector2& o)           {m_offset = o;}
     101              : 
     102            0 :                 number no_data_value() const                    {return m_noDataValue;}
     103            0 :                 void set_no_data_value(number val)              {m_noDataValue = val;}
     104              : 
     105              :         //      moves the heightfield by altering it's offset
     106              :                 void move(const vector2& v)                         {m_offset += v;}
     107              : 
     108              :         ///     Smoothens the field by adjusting the value of each pixel towards the average of its neighbours
     109              :                 void blur(number alpha, size_t numIterations);
     110              : 
     111              :         ///     eliminates invalid cells by repeatedly filling those cells with averages of neighboring cells
     112              :         /** The field has to contain at least one valid cell. If it doesn't, false is returned.*/
     113              :                 bool eliminate_invalid_cells();
     114              :         
     115              :         private:
     116              :         //      BEGIN SERIALIZATION
     117              :                 friend class boost::serialization::access;
     118              : 
     119              :                 template <class Archive>
     120            0 :                 void serialize( Archive& ar, const unsigned int version)
     121              :                 {
     122            0 :                         ar & m_cellSize;
     123            0 :                         ar & m_offset;
     124            0 :                         ar & m_noDataValue;
     125            0 :                         ar & m_field;
     126            0 :                 }
     127              :         //      END SERIALIZATION
     128              : 
     129              : 
     130              :                 Field<number>     m_field;
     131              :                 vector2                 m_cellSize;
     132              :                 vector2                 m_offset;
     133              :                 number                  m_noDataValue;
     134              : };
     135              : 
     136              : 
     137              : ////////////////////////////////////////////////////////////////////////////////
     138              : void UG_API
     139              : LoadHeightfieldFromASC(Heightfield& field, const char* filename);
     140              : 
     141              : ////////////////////////////////////////////////////////////////////////////////
     142              : void UG_API
     143              : CreateGridFromField(Grid& grid,
     144              :                                         const Heightfield& hfield,
     145              :                                         Grid::VertexAttachmentAccessor<APosition> aaPos);
     146              : 
     147              : ////////////////////////////////////////////////////////////////////////////////
     148              : void UG_API
     149              : CreateGridFromFieldBoundary(Grid& grid,
     150              :                                                         const Heightfield& hfield,
     151              :                                                         Grid::VertexAttachmentAccessor<APosition> aaPos);
     152              : 
     153              : }//     end of namespace
     154              : 
     155              : #endif  //__H__UG_heightfield_util
        

Generated by: LCOV version 2.0-1