RINGMesh  Version 5.0.0
A programming library for geological model meshes
types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #pragma once
37 
38 #include <geogram/basic/geometry.h>
39 #include <geogram/basic/numeric.h>
40 
45 namespace RINGMesh
46 {
47  /* If you need interger of 8bits of any other one
48  * it is sufficient to write using GEO::Numeric::uint8 in your file.
49  *
50  * Dummy variables were removed, the pollute the namespace and
51  * it is quite easy to do without them.
52  */
53 
54  // Basic types used in RINGMesh
55  // Using definitions of Geogram/basic/numeric.h
56  using GEO::Numeric::float32;
57  using GEO::Numeric::float64;
58 
59  using GEO::Numeric::max_float32;
60  using GEO::Numeric::min_float32;
61  using GEO::Numeric::max_float64;
62  using GEO::Numeric::min_float64;
63 
64  static const double global_epsilon = 1E-8;
65  static const double global_epsilon_sq = global_epsilon * global_epsilon;
66  static const double global_epsilon_3 = global_epsilon_sq * global_epsilon;
67 
68  // This is an unsigned int
69  using GEO::index_t;
70  // This is an int
71  using GEO::signed_index_t;
72  // This is an array template of doubles
73  template < index_t DIMENSION >
74  using vecn = GEO::vecng< DIMENSION, double >;
75  // This is an array of 3 doubles
76  using vec3 = vecn< 3 >;
77  // This is an array of 3 doubles
78  using vec2 = vecn< 2 >;
79 
80  // This is the value used in RINGMesh for a invalid index
81  static const index_t NO_ID = index_t( -1 );
82 
89  enum struct CellType : index_t
90  {
91  TETRAHEDRON = 0,
92  HEXAHEDRON = 1,
93  PRISM = 2,
94  PYRAMID = 3,
95  UNCLASSIFIED = 4,
96  UNDEFINED = 5
97  };
98 
105  enum struct PolygonType : index_t
106  {
107  TRIANGLE = 0,
108  QUAD = 1,
109  UNCLASSIFIED = 2,
110  UNDEFINED = 3
111  };
112 
113  template < typename Enum >
114  auto to_underlying_type( Enum e ) ->
115  typename std::underlying_type< Enum >::type
116  {
117  return static_cast< typename std::underlying_type< Enum >::type >( e );
118  }
119 
120  template < typename Enum >
122  {
123  static const bool enable = false;
124  };
125 
126  template < typename Enum >
127  typename std::enable_if< EnableBitMaskOperators< Enum >::enable,
128  Enum >::type
129  operator|( Enum lhs, Enum rhs )
130  {
131  using underlying = typename std::underlying_type< Enum >::type;
132  return static_cast< Enum >( static_cast< underlying >( lhs )
133  | static_cast< underlying >( rhs ) );
134  }
135 
136  template < typename Enum >
137  typename std::enable_if< EnableBitMaskOperators< Enum >::enable,
138  Enum >::type
139  operator&( Enum lhs, Enum rhs )
140  {
141  using underlying = typename std::underlying_type< Enum >::type;
142  return static_cast< Enum >( static_cast< underlying >( lhs )
143  & static_cast< underlying >( rhs ) );
144  }
145 
146  template < typename Enum >
147  typename std::enable_if< EnableBitMaskOperators< Enum >::enable,
148  Enum >::type
149  operator^( Enum lhs, Enum rhs )
150  {
151  using underlying = typename std::underlying_type< Enum >::type;
152  return static_cast< Enum >( static_cast< underlying >( lhs )
153  ^ static_cast< underlying >( rhs ) );
154  }
155 
156  template < typename Enum >
157  bool enum_contains( Enum lhs, Enum rhs )
158  {
159  return ( lhs & rhs ) != Enum::EMPTY;
160  }
161 
162 #define ENABLE_BITMASK_OPERATORS( Enum ) \
163  template <> \
164  struct EnableBitMaskOperators< Enum > \
165  { \
166  static const bool enable = true; \
167  }
168 } // namespace RINGMesh
GEO::vecng< DIMENSION, double > vecn
Definition: types.h:74
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator^(Enum lhs, Enum rhs)
Definition: types.h:149
vecn< 3 > vec3
Definition: types.h:76
auto to_underlying_type(Enum e) -> typename std::underlying_type< Enum >::type
Definition: types.h:114
vecn< 2 > vec2
Definition: types.h:78
bool enum_contains(Enum lhs, Enum rhs)
Definition: types.h:157
CellType
Definition: types.h:89
PolygonType
Definition: types.h:105
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator|(Enum lhs, Enum rhs)
Definition: types.h:129
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator &(Enum lhs, Enum rhs)
Definition: types.h:139