Loading...
Searching...
No Matches
vertex.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#include <limits>
26
27#include "bitpit_CG.hpp"
28#include "bitpit_common.hpp"
29
30#include "vertex.hpp"
31
32namespace bitpit {
33
42OBinaryStream& operator<<(OBinaryStream &out_stream, const Vertex &vertex)
43{
44 out_stream << vertex.m_id;
45 out_stream << vertex.m_coords;
46 out_stream << vertex.m_interior;
47
48 return out_stream;
49}
50
59IBinaryStream& operator>>(IBinaryStream &in_stream, Vertex &vertex)
60{
61 in_stream >> vertex.m_id;
62 in_stream >> vertex.m_coords;
63 in_stream >> vertex.m_interior;
64
65 return in_stream;
66}
67
77const long Vertex::NULL_ID = std::numeric_limits<long>::min();
78
83{
84 _initialize(NULL_ID, {{0., 0., 0.}}, true);
85}
86
93Vertex::Vertex(long id, bool interior)
94{
95 _initialize(id, {{0., 0., 0.}}, interior);
96}
97
105Vertex::Vertex(long id, const std::array<double, 3> &coords, bool interior)
106{
107 _initialize(id, coords, interior);
108}
109
117void Vertex::swap(Vertex &other) noexcept
118{
119 std::swap(other.m_id, m_id);
120 std::swap(other.m_coords, m_coords);
121 std::swap(other.m_interior, m_interior);
122}
123
131void Vertex::initialize(long id, const std::array<double, 3> &coords, bool interior)
132{
133 _initialize(id, coords, interior);
134}
135
143void Vertex::_initialize(long id, const std::array<double, 3> &coords, bool interior)
144{
145 setId(id);
146 setCoords(coords);
147 setInterior(interior);
148}
149
155void Vertex::setInterior(bool interior)
156{
157 m_interior = interior;
158}
159
167{
168 return m_interior;
169}
170
178bool Vertex::operator==(const Vertex &other) const
179{
180 for (int i = 0; i < 3; ++i) {
181 if (!utils::DoubleFloatingEqual()(m_coords[i], other.m_coords[i])) {
182 return false;
183 }
184 }
185
186 return true;
187}
188
195double & Vertex::operator[](int coord_id)
196{
197 return m_coords[coord_id];
198}
199
206const double & Vertex::operator[](int coord_id) const
207{
208 return m_coords[coord_id];
209}
210
216void Vertex::setId(long id)
217{
218 m_id = id;
219}
220
226long Vertex::getId() const
227{
228 return m_id;
229}
230
236void Vertex::setCoords(const std::array<double, 3> &coords)
237{
238 m_coords = coords;
239}
240
246std::array<double, 3> & Vertex::getCoords()
247{
248 return m_coords;
249}
250
256const std::array<double, 3> & Vertex::getCoords() const
257{
258 return m_coords;
259}
260
266void Vertex::translate(const std::array<double, 3> &translation)
267{
268 m_coords[0] += translation[0];
269 m_coords[1] += translation[1];
270 m_coords[2] += translation[2];
271}
272
280void Vertex::translate(double sx, double sy, double sz)
281{
282 translate({{sx, sy, sz}});
283}
284
293void Vertex::rotate(const std::array<double, 3> &n0, const std::array<double, 3> &n1, double angle)
294{
295 m_coords = CGElem::rotatePoint(m_coords, n0, n1, angle);
296}
297
310void Vertex::rotate(double n0x, double n0y, double n0z, double n1x, double n1y, double n1z, double angle)
311{
312 rotate({{n0x, n0y, n0z}}, {{n1x, n1y, n1z}}, angle);
313}
314
321void Vertex::scale(const std::array<double, 3> &scaling, const std::array<double, 3> &center)
322{
323 m_coords[0] = center[0] + scaling[0] * (m_coords[0] - center[0]);
324 m_coords[1] = center[1] + scaling[1] * (m_coords[1] - center[1]);
325 m_coords[2] = center[2] + scaling[2] * (m_coords[2] - center[2]);
326}
327
338void Vertex::scale(double sx, double sy, double sz,
339 double cx, double cy, double cz)
340{
341 scale({{sx, sy, sz}}, {{cx, cy, cz}});
342}
343
351void Vertex::display(std::ostream &out, unsigned short int indent) const
352{
353 std::string t_s = std::string(indent, ' ');
354
355 // General info ----------------------------------------------------- //
356 out << t_s << "ID: " << getId() << std::endl;
357
358 // Coordinates ------------------------------------------------------ //
359 out << t_s << "coordinates : (";
360 out << m_coords[0] << ", ";
361 out << m_coords[1] << ", ";
362 out << m_coords[2] << ")" << std::endl;
363}
364
370unsigned int Vertex::getBinarySize() const
371{
372 return (sizeof(m_id) + m_coords.size() * sizeof(double) + sizeof(m_interior));
373}
374
375// Explicit instantiation of the Vertex containers
376template class PiercedVector<Vertex>;
377
378}
Metafunction for generating a pierced vector.
The Vertex class defines the vertexs.
Definition vertex.hpp:42
bool operator==(const Vertex &other) const
Definition vertex.cpp:178
void setCoords(const std::array< double, 3 > &coords)
Definition vertex.cpp:236
void translate(const std::array< double, 3 > &translation)
Definition vertex.cpp:266
void display(std::ostream &out, unsigned short int indent) const
Definition vertex.cpp:351
unsigned int getBinarySize() const
Definition vertex.cpp:370
long getId() const
Definition vertex.cpp:226
void initialize(long id, const std::array< double, 3 > &coords, bool interior)
Definition vertex.cpp:131
void swap(Vertex &other) noexcept
Definition vertex.cpp:117
void scale(const std::array< double, 3 > &scaling, const std::array< double, 3 > &center)
Definition vertex.cpp:321
void setInterior(bool interior)
Definition vertex.cpp:155
void rotate(const std::array< double, 3 > &n0, const std::array< double, 3 > &n1, double angle)
Definition vertex.cpp:293
void setId(long id)
Definition vertex.cpp:216
std::array< double, 3 > & getCoords()
Definition vertex.cpp:246
bool isInterior() const
Definition vertex.cpp:166
double & operator[](int coord_id)
Definition vertex.cpp:195
array3D rotatePoint(const array3D &P, const array3D &n0, const array3D &n1, double angle)
Definition CG_elem.cpp:892
Logger & operator<<(Logger &logger, LoggerManipulator< T > &&m)
Definition logger.hpp:367
--- layout: doxygen_footer ---