Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
index.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * 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  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef GEOGRAM_MESH_INDEX
41 #define GEOGRAM_MESH_INDEX
42 
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/numeric.h>
45 #include <geogram/basic/argused.h>
47 #include <iostream>
48 
54 namespace GEO {
55 
56  /************************************************************************/
57 
65  template <class IndexType>
66  struct basic_bindex {
67 
71  IndexType indices[2];
72 
80  };
81 
86  }
87 
95  IndexType i,
96  IndexType j
97  ) {
98  if(i < j) {
99  indices[0] = i;
100  indices[1] = j;
101  } else {
102  indices[0] = j;
103  indices[1] = i;
104  }
105  }
106 
118  IndexType i,
119  IndexType j,
120  KeepOrderType order
121  ) {
122  geo_argused(order);
123  indices[0] = i;
124  indices[1] = j;
125  }
126 
133  bool operator< (const basic_bindex<IndexType>& rhs) const {
134  if(indices[0] < rhs.indices[0]) {
135  return true;
136  }
137  if(indices[0] > rhs.indices[0]) {
138  return false;
139  }
140  if(indices[1] < rhs.indices[1]) {
141  return true;
142  }
143  return false;
144  }
145 
152  bool operator== (const basic_bindex<IndexType>& rhs) const {
153  return
154  (indices[0] == rhs.indices[0]) &&
155  (indices[1] == rhs.indices[1]);
156  }
157 
165  bool operator!= (const basic_bindex<IndexType>& rhs) const {
166  return
167  (indices[0] != rhs.indices[0]) ||
168  (indices[1] != rhs.indices[1]);
169  }
170 
176  basic_bindex(const basic_bindex<IndexType>& rhs) = default;
177 
185  const basic_bindex<IndexType>& rhs
186  ) = default;
187 
197  return basic_bindex(b.indices[1], b.indices[0], KEEP_ORDER);
198  }
199  };
200 
205  typedef basic_bindex<index_t> bindex;
206 
211  typedef basic_bindex<signed_index_t> signed_bindex;
212 
222  template <class IndexType>
223  inline std::ostream& operator<< (
224  std::ostream& out, const basic_bindex<IndexType>& B
225  ) {
226  return out << B.indices[0] << " " << B.indices[1];
227  }
228 
229  /************************************************************************/
230 
238  template <class IndexType>
239  struct basic_trindex {
240 
244  IndexType indices[3];
245 
252  KEEP_ORDER
253  };
254 
259  }
260 
269  IndexType i,
270  IndexType j,
271  IndexType k
272  ) {
273  indices[0] = i;
274  indices[1] = j;
275  indices[2] = k;
277  }
278 
291  IndexType i,
292  IndexType j,
293  IndexType k,
294  KeepOrderType order
295  ) {
296  geo_argused(order);
297  indices[0] = i;
298  indices[1] = j;
299  indices[2] = k;
300  }
301 
308  bool operator< (const basic_trindex<IndexType>& rhs) const {
309  for(index_t i = 0; i < 3; i++) {
310  if(indices[i] < rhs.indices[i]) {
311  return true;
312  }
313  if(indices[i] > rhs.indices[i]) {
314  return false;
315  }
316  }
317  return false;
318  }
319 
326  bool operator== (const basic_trindex<IndexType>& rhs) const {
327  return
328  (indices[0] == rhs.indices[0]) &&
329  (indices[1] == rhs.indices[1]) &&
330  (indices[2] == rhs.indices[2]);
331  }
332 
340  bool operator!= (const basic_trindex<IndexType>& rhs) const {
341  return
342  (indices[0] != rhs.indices[0]) ||
343  (indices[1] != rhs.indices[1]) ||
344  (indices[2] != rhs.indices[2]);
345  }
346 
353 
361  const basic_trindex<IndexType>& rhs
362  ) = default;
363 
376  static bool same_orientation(
377  const basic_trindex<IndexType>& t,
378  IndexType i, IndexType j, IndexType k
379  ) {
380  return
381  (t.indices[0] == i && t.indices[1] == j && t.indices[2] == k) ||
382  (t.indices[1] == i && t.indices[2] == j && t.indices[0] == k) ||
383  (t.indices[2] == i && t.indices[0] == j && t.indices[1] == k);
384  }
385 
395  static bool same_orientation(
396  const basic_trindex<IndexType>& t1,
397  const basic_trindex<IndexType>& t2
398  ) {
399  return same_orientation(
400  t1, t2.indices[0], t2.indices[1], t2.indices[2]
401  );
402  }
403 
413  return basic_trindex(
414  t.indices[2], t.indices[1], t.indices[0], KEEP_ORDER
415  );
416  }
417  };
418 
423  typedef basic_trindex<index_t> trindex;
424 
429  typedef basic_trindex<signed_index_t> signed_trindex;
430 
440  template <class IndexType>
441  inline std::ostream& operator<< (
442  std::ostream& out, const basic_trindex<IndexType>& T
443  ) {
444  return out
445  << T.indices[0] << " " << T.indices[1] << " " << T.indices[2];
446  }
447 
448  /************************************************************************/
449 
457  template <class IndexType>
462  IndexType indices[4];
463 
471  KEEP_ORDER
472  };
473 
478  }
479 
489  IndexType i,
490  IndexType j,
491  IndexType k,
492  IndexType l
493  ) {
494  indices[0] = i;
495  indices[1] = j;
496  indices[2] = k;
497  indices[3] = l;
499  }
500 
514  IndexType i,
515  IndexType j,
516  IndexType k,
517  IndexType l,
518  KeepOrderType order
519  ) {
520  geo_argused(order);
521  indices[0] = i;
522  indices[1] = j;
523  indices[2] = k;
524  indices[3] = l;
525  }
526 
534  bool operator< (const basic_quadindex<IndexType>& rhs) const {
535  for(index_t i = 0; i < 4; i++) {
536  if(indices[i] < rhs.indices[i]) {
537  return true;
538  }
539  if(indices[i] > rhs.indices[i]) {
540  return false;
541  }
542  }
543  return false;
544  }
545 
553  bool operator== (const basic_quadindex<IndexType>& rhs) const {
554  return
555  (indices[0] == rhs.indices[0]) &&
556  (indices[1] == rhs.indices[1]) &&
557  (indices[2] == rhs.indices[2]) &&
558  (indices[3] == rhs.indices[3]);
559  }
560 
569  bool operator!= (const basic_quadindex<IndexType>& rhs) const {
570  return
571  (indices[0] != rhs.indices[0]) ||
572  (indices[1] != rhs.indices[1]) ||
573  (indices[2] != rhs.indices[2]) ||
574  (indices[3] != rhs.indices[3]);
575  }
576 
583 
591  const basic_quadindex<IndexType>& rhs
592  ) = default;
593  };
594 
599  typedef basic_quadindex<index_t> quadindex;
600 
605  typedef basic_quadindex<signed_index_t> signed_quadindex;
606 
616  template <class IndexType>
617  inline std::ostream& operator<< (
618  std::ostream& out, const basic_quadindex<IndexType>& Q
619  ) {
620  return out
621  << Q.indices[0] << " " << Q.indices[1] << " "
622  << Q.indices[2] << " " << Q.indices[3];
623  }
624 
625  /************************************************************************/
626 }
627 
628 #endif
Wrappers around parallel implementation of STL.
A function to suppress unused parameters compilation warnings.
Common include file, providing basic definitions. Should be included before anything else by all head...
basic_quadindex< signed_index_t > signed_quadindex
A basic_quadindex made of 4 signed integers.
Definition: index.h:605
basic_bindex< index_t > bindex
A basic_bindex made of 2 unsigned integers.
Definition: index.h:205
basic_quadindex< index_t > quadindex
A basic_quadindex made of 4 unsigned integers.
Definition: index.h:599
basic_trindex< index_t > trindex
A basic_trindex made of 3 unsigned integers.
Definition: index.h:423
basic_bindex< signed_index_t > signed_bindex
A basic_bindex made of 2 signed integers.
Definition: index.h:211
basic_trindex< signed_index_t > signed_trindex
A basic_trindex made of 3 signed integers.
Definition: index.h:429
Global Vorpaline namespace.
Definition: basic.h:55
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
Definition: argused.h:60
void sort_4(ITERATOR items)
Specialized sort routine for 4 elements.
Definition: algorithm.h:181
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
void sort_3(ITERATOR items)
Specialized sort routine for 3 elements.
Definition: algorithm.h:163
Types and functions for numbers manipulation.
A couple of two indices.
Definition: index.h:66
basic_bindex(IndexType i, IndexType j)
Creates a basic_bindex from two integers.
Definition: index.h:94
bool operator!=(const basic_bindex< IndexType > &rhs) const
Compares two basic_bindex.
Definition: index.h:165
basic_bindex(const basic_bindex< IndexType > &rhs)=default
Constructs a basic_bindex from another one.
bool operator<(const basic_bindex< IndexType > &rhs) const
Compares two basic_bindex.
Definition: index.h:133
basic_bindex< IndexType > & operator=(const basic_bindex< IndexType > &rhs)=default
Assigns a basic_bindex to this one.
bool operator==(const basic_bindex< IndexType > &rhs) const
Compares two basic_bindex.
Definition: index.h:152
basic_bindex(IndexType i, IndexType j, KeepOrderType order)
Creates a basic_bindex from two integers and keeps their order.
Definition: index.h:117
KeepOrderType
This type is used to overload basic_bindex constructors with versions that keep the order of the stor...
Definition: index.h:77
IndexType indices[2]
The array of 2 indices.
Definition: index.h:71
static basic_bindex inverse(const basic_bindex< IndexType > &b)
Computes the inverse of a basic_bindex.
Definition: index.h:196
basic_bindex()
Creates an uninitialized basic_bindex.
Definition: index.h:85
A tuple of four indices.
Definition: index.h:458
basic_quadindex< IndexType > & operator=(const basic_quadindex< IndexType > &rhs)=default
Assigns a basic_quadindex to this one.
bool operator==(const basic_quadindex< IndexType > &rhs) const
Compares two basic_quadindex.
Definition: index.h:553
IndexType indices[4]
The array of 4 indices.
Definition: index.h:462
basic_quadindex(const basic_quadindex< IndexType > &rhs)=default
Constructs a basic_quadindex from another one.
bool operator<(const basic_quadindex< IndexType > &rhs) const
Compares two basic_quadindex.
Definition: index.h:534
basic_quadindex()
Constructs a new uninitialized basic_quadindex.
Definition: index.h:477
basic_quadindex(IndexType i, IndexType j, IndexType k, IndexType l, KeepOrderType order)
Creates a basic_quadindex from four integers and keeps their order.
Definition: index.h:513
bool operator!=(const basic_quadindex< IndexType > &rhs) const
Compares two basic_quadindex.
Definition: index.h:569
basic_quadindex(IndexType i, IndexType j, IndexType k, IndexType l)
Creates a basic_quadindex from four integers.
Definition: index.h:488
KeepOrderType
This type is used to overload basic_quadindex constructors with versions that keep the order of the s...
Definition: index.h:469
A triple of three indices.
Definition: index.h:239
static basic_trindex inverse(const basic_trindex< IndexType > &t)
Computes the inverse of a basic_trindex.
Definition: index.h:412
bool operator!=(const basic_trindex< IndexType > &rhs) const
Compares two basic_trindex.
Definition: index.h:340
static bool same_orientation(const basic_trindex< IndexType > &t1, const basic_trindex< IndexType > &t2)
Tests whether two basic_trindex have the same orientation.
Definition: index.h:395
basic_trindex(const basic_trindex< IndexType > &rhs)=default
Constructs a basic_trindex from another one.
basic_trindex(IndexType i, IndexType j, IndexType k, KeepOrderType order)
Creates a basic_trindex from three integers and keeps their order.
Definition: index.h:290
static bool same_orientation(const basic_trindex< IndexType > &t, IndexType i, IndexType j, IndexType k)
Tests whether a basic_trindex has the same orientation as a triple of integers.
Definition: index.h:376
bool operator==(const basic_trindex< IndexType > &rhs) const
Compares two basic_trindex.
Definition: index.h:326
bool operator<(const basic_trindex< IndexType > &rhs) const
Compares two basic_trindex.
Definition: index.h:308
KeepOrderType
This type is used to overload basic_trindex constructors with versions that keep the order of the sto...
Definition: index.h:250
basic_trindex< IndexType > & operator=(const basic_trindex< IndexType > &rhs)=default
Assigns a basic_trindex to this one.
basic_trindex(IndexType i, IndexType j, IndexType k)
Creates a basic_trindex from three integers.
Definition: index.h:268
basic_trindex()
Creates an uninitialized basic_trindex.
Definition: index.h:258
IndexType indices[3]
The array of 3 indices.
Definition: index.h:244