EMODnet Quantized Mesh Generator for Cesium
tin_creation_utils.h
1 // Copyright (c) 2018 Coronis Computing S.L. (Spain)
2 // All rights reserved.
3 //
4 // This file is part of EMODnet Quantized Mesh Generator for Cesium.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 //
19 // Author: Ricard Campos (ricardcd@gmail.com)
20 
21 #ifndef EMODNET_QMGC_TIN_CREATION_UTILS_H
22 #define EMODNET_QMGC_TIN_CREATION_UTILS_H
23 
24 #include <vector>
25 #include <cmath>
26 
27 namespace TinCreation {
28 
42 template <class T>
43 T standardHandlingOfThresholdPerZoom(const std::vector<T>& thresholdsPerZoom,
44  const unsigned int& zoom,
45  const bool& downScale = true)
46 {
47  T thres;
48  if (thresholdsPerZoom.size() == 1) {
49  // This means that only the root tolerance was specified, we will infer the tolerance at the desired zoom level by dividing by two the root number for each level
50  if (zoom == 0)
51  thres = thresholdsPerZoom[0];
52  else {
53  if (downScale)
54  thres = thresholdsPerZoom[0] / pow(2.0, zoom);
55  else
56  thres = thresholdsPerZoom[0] * pow(2.0, zoom);
57  }
58  } else if (zoom < thresholdsPerZoom.size()) {
59  // Use the approximation tolerance corresponding to the zoom in the vector
60  thres = thresholdsPerZoom[zoom];
61  } else {
62  // Use the approximation tolerance corresponding to the last zoom specified in the vector
63  thres = thresholdsPerZoom.back();
64  }
65 
66  return thres;
67 }
68 
69 
70 } // End namespace TinCreation
71 
72 #endif //EMODNET_QMGC_TIN_CREATION_UTILS_H
T standardHandlingOfThresholdPerZoom(const std::vector< T > &thresholdsPerZoom, const unsigned int &zoom, const bool &downScale=true)
Definition: tin_creation_utils.h:43
This namespace contains all the types/classes/functions required to create a TIN out of a regularly g...