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