mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: consistent member access for triFace / triangle etc.
- can access the vertices/points as a(), b(), c()
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -82,8 +82,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "hash-like functionality" << nl;
|
||||
|
||||
// doesn't work e4 = -1;
|
||||
e4.start() = e4.end() = -1;
|
||||
e4.clear();
|
||||
|
||||
printInfo(e4);
|
||||
for (label i : {2, -1, 2, 1, 4, 1, 2, 3})
|
||||
@ -93,24 +92,24 @@ int main(int argc, char *argv[])
|
||||
printInfo(e4);
|
||||
}
|
||||
|
||||
e4.start() = e4.end() = -1;
|
||||
e4.clear();
|
||||
Info<< "insert from list\n";
|
||||
labelHashSet newIndices({2, -1, 2, 1, 4, 1, 2, 3});
|
||||
e4.insert(newIndices.toc());
|
||||
printInfo(e4);
|
||||
|
||||
e4.start() = e4.end() = -1;
|
||||
e4.clear();
|
||||
Info<< "insert from list\n";
|
||||
e4.insert({0, 5, 2, -1, 2, 1, 4, 1, 2, 3});
|
||||
printInfo(e4);
|
||||
|
||||
FixedList<label, 8> otherIndices{12, 2, -1, 1, 4, 1, 2, 3};
|
||||
e4.start() = e4.end() = -1;
|
||||
e4.clear();
|
||||
Info<< "insert from list: " << otherIndices << nl;
|
||||
e4.insert(otherIndices);
|
||||
printInfo(e4);
|
||||
|
||||
e4.start() = e4.end();
|
||||
e4.a() = e4.b();
|
||||
Info<< "erase from list: " << otherIndices << nl;
|
||||
Info<< "removed " << e4.erase(otherIndices) << " values" << nl;
|
||||
printInfo(e4);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -107,27 +107,40 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- Return first vertex label
|
||||
//- The first vertex
|
||||
label a() const { return labelPair::first(); }
|
||||
|
||||
//- The second vertex
|
||||
label b() const { return labelPair::second(); }
|
||||
|
||||
//- The first vertex
|
||||
label& a() { return labelPair::first(); }
|
||||
|
||||
//- The second vertex
|
||||
label& b() { return labelPair::second(); }
|
||||
|
||||
|
||||
//- The first vertex label
|
||||
using labelPair::first;
|
||||
|
||||
//- Return last (second) vertex label
|
||||
using labelPair::last;
|
||||
|
||||
//- Return second (last) vertex label
|
||||
//- The second (last) vertex label
|
||||
using labelPair::second;
|
||||
|
||||
//- The last (second) vertex label
|
||||
using labelPair::last;
|
||||
|
||||
//- Return start (first) vertex label
|
||||
inline label start() const;
|
||||
//- The start (first) vertex label
|
||||
label start() const { return labelPair::first(); }
|
||||
|
||||
//- Return start (first) vertex label
|
||||
inline label& start();
|
||||
//- The end (last/second) vertex label
|
||||
label end() const { return labelPair::second(); }
|
||||
|
||||
//- Return end (last/second) vertex label
|
||||
inline label end() const;
|
||||
//- The start (first) vertex label
|
||||
label& start() { return labelPair::first(); }
|
||||
|
||||
//- The end (last/second) vertex label
|
||||
label& end() { return labelPair::second(); }
|
||||
|
||||
//- Return end (last/second) vertex label
|
||||
inline label& end();
|
||||
|
||||
//- Return reverse edge as copy.
|
||||
// No special handling of negative point labels.
|
||||
|
||||
@ -92,29 +92,6 @@ inline Foam::edge::edge(Istream& is)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::label Foam::edge::start() const
|
||||
{
|
||||
return first();
|
||||
}
|
||||
|
||||
inline Foam::label& Foam::edge::start()
|
||||
{
|
||||
return first();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::edge::end() const
|
||||
{
|
||||
return second();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label& Foam::edge::end()
|
||||
{
|
||||
return second();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::edge::minVertex() const
|
||||
{
|
||||
return (first() < second() ? first() : second());
|
||||
|
||||
@ -102,16 +102,35 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- Return first vertex label
|
||||
//- The first vertex
|
||||
label a() const { return operator[](0); }
|
||||
|
||||
//- The second vertex
|
||||
label b() const { return operator[](1); }
|
||||
|
||||
//- The third vertex
|
||||
label c() const { return operator[](2); }
|
||||
|
||||
//- The first vertex
|
||||
label& a() { return operator[](0); }
|
||||
|
||||
//- The second vertex
|
||||
label& b() { return operator[](1); }
|
||||
|
||||
//- The third vertex
|
||||
label& c() { return operator[](2); }
|
||||
|
||||
|
||||
//- The first vertex label
|
||||
using FixedList<label, 3>::first;
|
||||
|
||||
//- Return last (third) vertex label
|
||||
//- The last (third) vertex label
|
||||
using FixedList<label, 3>::last;
|
||||
|
||||
//- Return second vertex label
|
||||
//- The second vertex label
|
||||
label& second() { return operator[](1); }
|
||||
|
||||
//- Return second vertex label
|
||||
//- The second vertex label
|
||||
label second() const { return operator[](1); }
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,6 +43,7 @@ SourceFiles
|
||||
#include "vector.H"
|
||||
#include "PointHit.H"
|
||||
#include "FixedList.H"
|
||||
#include "Pair.H"
|
||||
#include "UList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -67,6 +68,55 @@ inline Ostream& operator<<(Ostream& os, const line<Point, PointRef>& l);
|
||||
typedef line<point, const point&> linePointRef;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class linePoints Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- Line point storage. Default constructable (line is not)
|
||||
class linePoints
|
||||
:
|
||||
public Pair<point>
|
||||
{
|
||||
public:
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- Default construct
|
||||
linePoints() = default;
|
||||
|
||||
//- Inherit constructors
|
||||
using Pair<point>::Pair;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from point references
|
||||
inline explicit linePoints(const linePointRef& pts);
|
||||
|
||||
//- Copy construct from subset of points
|
||||
inline linePoints
|
||||
(
|
||||
const UList<point>& points,
|
||||
const FixedList<label, 2>& indices
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The first vertex
|
||||
const point& a() const { return Pair<point>::first(); }
|
||||
|
||||
//- The second vertex
|
||||
const point& b() const { return Pair<point>::second(); }
|
||||
|
||||
//- The first vertex
|
||||
point& a() { return Pair<point>::first(); }
|
||||
|
||||
//- The second vertex
|
||||
point& b() { return Pair<point>::second(); }
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class line Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -106,20 +156,26 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- Return first point
|
||||
inline PointRef first() const noexcept { return a_; }
|
||||
//- The first point
|
||||
PointRef a() const noexcept { return a_; }
|
||||
|
||||
//- Return second (last) point
|
||||
inline PointRef second() const noexcept { return b_; }
|
||||
//- The second point
|
||||
PointRef b() const noexcept { return b_; }
|
||||
|
||||
//- Return last (second) point
|
||||
inline PointRef last() const noexcept { return b_; }
|
||||
//- The first point
|
||||
PointRef first() const noexcept { return a_; }
|
||||
|
||||
//- Return start (first) point
|
||||
inline PointRef start() const noexcept { return a_; }
|
||||
//- The second (last) point
|
||||
PointRef second() const noexcept { return b_; }
|
||||
|
||||
//- Return end (second) point
|
||||
inline PointRef end() const noexcept { return b_; }
|
||||
//- The last (second) point
|
||||
PointRef last() const noexcept { return b_; }
|
||||
|
||||
//- The start (first) point
|
||||
PointRef start() const noexcept { return a_; }
|
||||
|
||||
//- The end (second) point
|
||||
PointRef end() const noexcept { return b_; }
|
||||
|
||||
|
||||
// Properties
|
||||
@ -151,19 +207,10 @@ public:
|
||||
) const;
|
||||
|
||||
|
||||
// IOstream operators
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>> <Point, PointRef>
|
||||
(
|
||||
Istream& is,
|
||||
line& l
|
||||
);
|
||||
|
||||
friend Ostream& operator<< <Point, PointRef>
|
||||
(
|
||||
Ostream& os,
|
||||
const line& l
|
||||
);
|
||||
friend Istream& operator>> <Point, PointRef>(Istream&, line&);
|
||||
friend Ostream& operator<< <Point, PointRef>(Ostream&, const line&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -31,6 +31,22 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::linePoints::linePoints(const linePointRef& pts)
|
||||
:
|
||||
Pair<point>(pts.a(), pts.b())
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::linePoints::linePoints
|
||||
(
|
||||
const UList<point>& points,
|
||||
const FixedList<label, 2>& indices
|
||||
)
|
||||
:
|
||||
Pair<point>(points[indices.first()], points[indices.last()])
|
||||
{}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
inline Foam::line<Point, PointRef>::line(const Point& from, const Point& to)
|
||||
:
|
||||
@ -46,8 +62,8 @@ inline Foam::line<Point, PointRef>::line
|
||||
const FixedList<label, 2>& indices
|
||||
)
|
||||
:
|
||||
a_(points[indices[0]]),
|
||||
b_(points[indices[1]])
|
||||
a_(points[indices.first()]),
|
||||
b_(points[indices.last()])
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@ inline T& Foam::Pair<T>::second() noexcept
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::Pair<T>::other(const T& a) const
|
||||
inline const T& Foam::Pair<T>::other(const T& val) const
|
||||
{
|
||||
if (first() == second())
|
||||
{
|
||||
@ -139,15 +139,15 @@ inline const T& Foam::Pair<T>::other(const T& a) const
|
||||
<< "Call to other only valid for Pair with differing elements:"
|
||||
<< *this << abort(FatalError);
|
||||
}
|
||||
else if (a == first())
|
||||
else if (val == first())
|
||||
{
|
||||
return second();
|
||||
}
|
||||
else if (a != second())
|
||||
else if (val != second())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Pair " << *this
|
||||
<< " does not contain " << a << abort(FatalError);
|
||||
<< " does not contain " << val << abort(FatalError);
|
||||
}
|
||||
|
||||
return first();
|
||||
|
||||
@ -86,9 +86,9 @@ public:
|
||||
inline STLtriangle
|
||||
(
|
||||
const STLpoint& normal,
|
||||
const STLpoint& a,
|
||||
const STLpoint& b,
|
||||
const STLpoint& c,
|
||||
const STLpoint& p0,
|
||||
const STLpoint& p1,
|
||||
const STLpoint& p2,
|
||||
uint16_t attrib
|
||||
);
|
||||
|
||||
@ -127,18 +127,18 @@ public:
|
||||
(
|
||||
Ostream& os,
|
||||
const vector& norm,
|
||||
const point& pt0,
|
||||
const point& pt1,
|
||||
const point& pt2
|
||||
const point& p0,
|
||||
const point& p1,
|
||||
const point& p2
|
||||
);
|
||||
|
||||
//- Write components to Ostream (ASCII), calculating the normal
|
||||
inline static void write
|
||||
(
|
||||
Ostream& os,
|
||||
const point& pt0,
|
||||
const point& pt1,
|
||||
const point& pt2
|
||||
const point& p0,
|
||||
const point& p1,
|
||||
const point& p2
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -33,16 +33,16 @@ License
|
||||
inline Foam::STLtriangle::STLtriangle
|
||||
(
|
||||
const STLpoint& normal,
|
||||
const STLpoint& a,
|
||||
const STLpoint& b,
|
||||
const STLpoint& c,
|
||||
const STLpoint& p0,
|
||||
const STLpoint& p1,
|
||||
const STLpoint& p2,
|
||||
uint16_t attrib
|
||||
)
|
||||
:
|
||||
normal_(normal),
|
||||
a_(a),
|
||||
b_(b),
|
||||
c_(c),
|
||||
a_(p0),
|
||||
b_(p1),
|
||||
c_(p2),
|
||||
attrib_(attrib)
|
||||
{}
|
||||
|
||||
@ -88,17 +88,17 @@ inline void Foam::STLtriangle::write
|
||||
(
|
||||
Ostream& os,
|
||||
const vector& norm,
|
||||
const point& pt0,
|
||||
const point& pt1,
|
||||
const point& pt2
|
||||
const point& p0,
|
||||
const point& p1,
|
||||
const point& p2
|
||||
)
|
||||
{
|
||||
os << " facet normal "
|
||||
<< norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
|
||||
<< " outer loop" << nl
|
||||
<< " vertex " << pt0.x() << ' ' << pt0.y() << ' ' << pt0.z() << nl
|
||||
<< " vertex " << pt1.x() << ' ' << pt1.y() << ' ' << pt1.z() << nl
|
||||
<< " vertex " << pt2.x() << ' ' << pt2.y() << ' ' << pt2.z() << nl
|
||||
<< " vertex " << p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl
|
||||
<< " vertex " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl
|
||||
<< " vertex " << p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
|
||||
<< " endloop" << nl
|
||||
<< " endfacet" << nl;
|
||||
}
|
||||
@ -107,15 +107,15 @@ inline void Foam::STLtriangle::write
|
||||
inline void Foam::STLtriangle::write
|
||||
(
|
||||
Ostream& os,
|
||||
const point& pt0,
|
||||
const point& pt1,
|
||||
const point& pt2
|
||||
const point& p0,
|
||||
const point& p1,
|
||||
const point& p2
|
||||
)
|
||||
{
|
||||
// Calculate the normal ourselves
|
||||
const vector norm = triPointRef(pt0, pt1, pt2).unitNormal();
|
||||
const vector norm = triPointRef(p0, p1, p2).unitNormal();
|
||||
|
||||
write(os, norm, pt0, pt1, pt2);
|
||||
write(os, norm, p0, p1, p2);
|
||||
}
|
||||
|
||||
|
||||
@ -123,11 +123,11 @@ inline void Foam::STLtriangle::write
|
||||
|
||||
inline Foam::Ostream& Foam::operator<<(Ostream& os, const STLtriangle& tri)
|
||||
{
|
||||
os << tri.normal_ << token::SPACE
|
||||
<< tri.a_ << token::SPACE
|
||||
<< tri.b_ << token::SPACE
|
||||
<< tri.c_ << token::SPACE
|
||||
<< tri.attrib_;
|
||||
os << tri.normal() << token::SPACE
|
||||
<< tri.a() << token::SPACE
|
||||
<< tri.b() << token::SPACE
|
||||
<< tri.c() << token::SPACE
|
||||
<< tri.attrib();
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user