40 #ifndef H_HEXDOM_ALGO_BASIC_H
41 #define H_HEXDOM_ALGO_BASIC_H
52 #define FOR(i,max) for (index_t i = 0; i<index_t(max); i++)
65 template<
class T>
void min_equal(T& A, T B) {
if (A > B) A = B; }
66 template<
class T>
void max_equal(T& A, T B) {
if (A < B) A = B; }
68 inline double nint(
double x) {
return floor(x + .5); }
71 return (i + 1) % imax;
75 return (i +
index_t(
int(imax) - 1)) % imax;
78 template <
class T> T clamp(T in, T vmin, T vmax) {
79 if (in<vmin)
return vmin;
80 if (in>vmax)
return vmax;
93 inline void show(
mat3 r) {
98 std::cerr <<
" " << r(i, j);
104 return vec3(M(0, j), M(1, j), M(2, j));
109 M(0, 0)*v[0] + M(0, 1)*v[1] + M(0, 2)*v[2],
110 M(1, 0)*v[0] + M(1, 1)*v[1] + M(1, 2)*v[2],
111 M(2, 0)*v[0] + M(2, 1)*v[1] + M(2, 2)*v[2]
117 int(M(0, 0)*v[0] + M(0, 1)*v[1] + M(0, 2)*v[2]),
118 int(M(1, 0)*v[0] + M(1, 1)*v[1] + M(1, 2)*v[2]),
119 int(M(2, 0)*v[0] + M(2, 1)*v[1] + M(2, 2)*v[2])
123 inline mat3 mat3_from_coeffs(
double a00,
double a01,
double a02,
double a10,
double a11,
double a12,
double a20,
double a21,
double a22) {
125 res(0, 0) = a00; res(0, 1) = a01; res(0, 2) = a02;
126 res(1, 0) = a10; res(1, 1) = a11; res(1, 2) = a12;
127 res(2, 0) = a20; res(2, 1) = a21; res(2, 2) = a22;
131 inline mat3 mat3_from_coeffs(
double* c) {
133 FOR(i, 9) res.data()[i] = c[i];
137 inline
double trace(const
mat3& m) {
return m(0, 0) + m(1, 1) + m(2, 2); }
139 inline double Frobenius_norm(
const mat3& m) {
return trace(m.transpose()*m);}
142 return vec2(M(0, 0)*v[0] + M(0, 1)*v[1], M(1, 0)*v[0] + M(1, 1)*v[1]) ;
146 inline vec3i snap_to_integer(
const vec3& f) {
150 inline bool is_integer(
double d) {
151 return d == floor(d);
156 template <
class T>
inline
157 T& aupp(
int id, vector<T>& data){
158 while (
id <0)
id += int(data.size());
159 while (
id >=
int(data.size()))
id -= int(data.size());
164 template <
class T>
inline
165 T& aupp(
index_t id, vector<T>& data){
166 while (
id >= data.size())
id -= data.size();
174 BBox1() { min = 1e20; max = -1e20; }
175 double length() {
return max - min; }
176 bool intersect(
const BBox1& b)
const {
return contains(b.min) || contains(b.max) || b.contains(min) || b.contains(max); }
177 bool contains(
const double& v)
const {
return v > min && v < max; }
178 bool is_null()
const;
179 void add(
const BBox1& b);
180 void add(
const double& P) { min_equal(min, P); max_equal(max, P);}
181 void dilate(
double eps) { min -= eps; max += eps; }
182 double bary()
const {
return (max + min) / 2.; }
194 #define reach(x){GEO::Logger::out("HexDom") <<"\n========= mark ===> "<<#x<<" =============\n"<< std::endl; }
197 #define check1 GEO::Logger::out("HexDom") <<"checkpoint 1 reached"<< std::endl;
198 #define check2 GEO::Logger::out("HexDom") <<"checkpoint 2 reached"<< std::endl;
199 #define check3 GEO::Logger::out("HexDom") <<"checkpoint 3 reached"<< std::endl;
204 template <
class T>
inline std::string plop_val(T val) {
205 return " => " + GEO::String::to_string(val);
208 template <>
inline std::string plop_val(
const char*) {
212 inline std::string plop_unquote(
const char* str) {
213 std::string result(str);
214 if(result.length() > 2 && result[0] ==
'\"' && result[result.length()-1] ==
'\"') {
215 result = result.substr(1, result.length()-2);
220 #define plop(x) GEO::Logger::out("HexDom") << " ->|plop|<- " << plop_file(__FILE__, __LINE__) << " : " << plop_unquote(#x) << plop_val(x) << std::endl
221 #define error(x) GEO::Logger::out("HexDom") << "ERROR " << plop_file(__FILE__, __LINE__) << " : " << plop_unquote(#x) << plop_val(x) << std::endl
226 #define get_thread_range(nb_tasks,istart,iend) \
229 {int thread_id = omp_get_thread_num(); \
230 int n_threads = omp_get_num_threads(); \
231 istart = index_t((thread_id*int(nb_tasks)) / n_threads); \
232 iend = index_t(((thread_id + 1)*int(nb_tasks)) / n_threads); \
233 if (thread_id == n_threads - 1) iend = nb_tasks; \
236 #define get_thread_range(nb_tasks,istart,iend) \
238 index_t iend=nb_tasks;
Assertion checking mechanism.
#define EXPLORAGRAM_API
Linkage declaration for exploragram symbols.
Included by all headers in exploragram.
Geometric functions in 2d and 3d.
Global Vorpaline namespace.
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
vecng< 3, Numeric::int32 > vec3i
Represents points and vectors in 3d with integer coordinates.
geo_index_t index_t
The type for storing and manipulating indices.
Matrix< 3, Numeric::float64 > mat3
Represents a 3x3 matrix.
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
Matrix< 2, Numeric::float64 > mat2
Represents a 2x2 matrix.
Functions for string manipulation.