MeshLib Documentation
Loading...
Searching...
No Matches
MRUnorientedTriangle.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRId.h"
4#include <cassert>
5#include <utility>
6
7namespace MR
8{
9
13{
15
17 bool * outFlipped = nullptr )
18 : verts( inVs )
19 {
20 bool flipped = false;
21 auto checkSwap = [this, &flipped]( int i, int j )
22 {
23 assert( i < j );
24 assert( verts[i] != verts[j] );
25 if ( verts[i] > verts[j] )
26 {
27 flipped = !flipped;
28 std::swap( verts[i], verts[j] );
29 }
30 };
31 checkSwap( 0, 1 );
32 checkSwap( 0, 2 );
33 checkSwap( 1, 2 );
34 if ( outFlipped )
35 *outFlipped = flipped;
36 }
37
39 ThreeVertIds getFlipped() const { return { verts[0], verts[2], verts[1] }; } // id #0 remains the lowest
40
41 operator ThreeVertIds &() { return verts; }
42 operator const ThreeVertIds &() const { return verts; }
43
44 VertId &operator[]( std::size_t i ) { return verts[i]; }
45 const VertId &operator[]( std::size_t i ) const { return verts[i]; }
46
47 friend bool operator==( const UnorientedTriangle& a, const UnorientedTriangle& b ) = default;
48};
49
50} //namespace MR
51
52namespace std
53{
54
55template <>
56struct hash<MR::UnorientedTriangle>
57{
58 size_t operator() ( const MR::UnorientedTriangle& triplet ) const noexcept
59 {
60 return
61 2 * size_t( triplet.verts[0] ) +
62 3 * size_t( triplet.verts[1] ) +
63 5 * size_t( triplet.verts[2] );
64 }
65};
66
67} //namespace std
Definition MRCameraOrientationPlugin.h:8
std::array< VertId, 3 > ThreeVertIds
three vertex ids describing a triangle topology
Definition MRMesh/MRMeshFwd.h:383
Definition MRUnorientedTriangle.h:13
const VertId & operator[](std::size_t i) const
Definition MRUnorientedTriangle.h:45
VertId & operator[](std::size_t i)
Definition MRUnorientedTriangle.h:44
friend bool operator==(const UnorientedTriangle &a, const UnorientedTriangle &b)=default
ThreeVertIds verts
Definition MRUnorientedTriangle.h:14
ThreeVertIds getFlipped() const
returns this triangle with the opposite orientation
Definition MRUnorientedTriangle.h:39
UnorientedTriangle(const ThreeVertIds &inVs, bool *outFlipped=nullptr)
Definition MRUnorientedTriangle.h:16