Nektar++
BooleanOperators.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: BooleanOperators.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Boolean operators for comparison of mesh objects.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 namespace NekMeshUtils
43 {
44 
45 /**
46  * @brief Compares two element config structs
47  */
48 bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
49 {
50  return (c1.m_e == c2.m_e && c1.m_order == c2.m_order);
51 }
52 
53 /**
54  * @brief Compares two element shared pointers
55  */
56 bool operator==(ElementSharedPtr const &e1, ElementSharedPtr const &e2)
57 {
58  return e1->GetId() == e2->GetId();
59 }
60 
61 /**
62  * @brief Compares two %HOSurf objects referred to as shared pointers.
63  *
64  * Two %HOSurf objects are defined to be equal if they contain identical
65  * vertex ids contained in HOSurf::vertId.
66  */
67 bool operator==(HOSurfSharedPtr const &p1, HOSurfSharedPtr const &p2)
68 {
69  if (p1->vertId.size() != p2->vertId.size())
70  {
71  return false;
72  }
73 
74  vector<int> ids1 = p1->vertId;
75  vector<int> ids2 = p2->vertId;
76  sort(ids1.begin(), ids1.end());
77  sort(ids2.begin(), ids2.end());
78 
79  for (int i = 0; i < ids1.size(); ++i)
80  {
81  if (ids1[i] != ids2[i])
82  return false;
83  }
84 
85  return true;
86 }
87 
88 /**
89  * @brief Test equality of two conditions - i.e. compare types, fields
90  * and values but _not_ composite ids.
91  */
93 {
94  int i, n = c1->type.size();
95 
96  if (n != c2->type.size())
97  {
98  return false;
99  }
100 
101  for (i = 0; i < n; ++i)
102  {
103  if (c1->type[i] != c2->type[i])
104  {
105  return false;
106  }
107 
108  if (c1->field[i] != c2->field[i] || c1->value[i] != c2->value[i])
109  {
110  return false;
111  }
112  }
113 
114  return true;
115 }
116 
117 /**
118  * @brief Defines equality between two #NodeSharedPtr objects.
119  */
120 bool operator==(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
121 {
122  return *p1 == *p2;
123 }
124 
125 /**
126  * @brief Compares two nodes for inequality based on IDs
127  */
128 bool operator!=(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
129 {
130  if (p1->m_id != p2->m_id)
131  {
132  return true;
133  }
134  else
135  {
136  return false;
137  }
138 }
139 
140 /**
141  * @brief Defines ordering between two #NodeSharedPtr objects.
142  */
143 bool operator< (NodeSharedPtr const &p1, NodeSharedPtr const &p2)
144 {
145  return *p1 < *p2;
146 }
147 
148 /**
149  * @brief Print description of node to given ostream.
150  */
151 std::ostream &operator<<(std::ostream &os, const NodeSharedPtr &n)
152 {
153  os << n->m_x << " " << n->m_y << " " << n->m_z;
154  return os;
155 }
156 
157 /**
158  * @brief Defines equality of two edges (equal if IDs of end nodes
159  * match in either ordering).
160  */
161 bool operator==(EdgeSharedPtr const &p1, EdgeSharedPtr const &p2)
162 {
163  return ( ((*(p1->m_n1) == *(p2->m_n1)) && (*(p1->m_n2) == *(p2->m_n2)))
164  || ((*(p1->m_n2) == *(p2->m_n1)) && (*(p1->m_n1) == *(p2->m_n2))));
165 }
166 
167 /**
168  * @brief Defines ordering between two edges (based on ID of edges).
169  */
170 bool operator< (EdgeSharedPtr const &p1, EdgeSharedPtr const &p2)
171 {
172  return p1->m_id < p2->m_id;
173 }
174 
175 /**
176  * @brief Defines equality of two faces (equal if IDs of vertices are
177  * the same.)
178  */
179 bool operator==(FaceSharedPtr const &p1, FaceSharedPtr const &p2)
180 {
181  std::vector<NodeSharedPtr>::iterator it1;
182  for (it1 = p1->m_vertexList.begin(); it1 != p1->m_vertexList.end(); ++it1)
183  {
184  if (find(p2->m_vertexList.begin(), p2->m_vertexList.end(), *it1)
185  == p2->m_vertexList.end())
186  {
187  return false;
188  }
189  }
190  return true;
191 }
192 
193 /**
194  * @brief Defines ordering between two faces (depending on ID of
195  * faces).
196  */
197 bool operator< (FaceSharedPtr const &p1, FaceSharedPtr const &p2)
198 {
199  return p1->m_id < p2->m_id;
200 }
201 
202 }
203 }
Basic information about an element.
Definition: ElementConfig.h:49
std::ostream & operator<<(std::ostream &os, const NodeSharedPtr &n)
Print description of node to given ostream.
STL namespace.
bool operator<(FaceSharedPtr const &p1, FaceSharedPtr const &p2)
Defines ordering between two faces (depending on ID of faces).
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
std::shared_ptr< Node > NodeSharedPtr
Definition: CADVert.h:49
std::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:155
unsigned int m_order
Order of the element.
Definition: ElementConfig.h:88
bool operator!=(NodeSharedPtr const &p1, NodeSharedPtr const &p2)
Compares two nodes for inequality based on IDs.
std::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358
std::shared_ptr< HOSurf > HOSurfSharedPtr
Definition: HOAlignment.h:180
bool operator==(const VertexSharedPtr &v1, const VertexSharedPtr &v2)
Define comparison operator for the vertex struct.
Definition: VtkToFld.cpp:55
std::shared_ptr< Condition > ConditionSharedPtr
Definition: Mesh.h:85
LibUtilities::ShapeType m_e
Element type (e.g. triangle, quad, etc).
Definition: ElementConfig.h:78