consistency update

- OSspecific: chmod() -> chMod(), even although it's not used anywhere

- ListOps get subset() and inplaceSubset() templated on BoolListType

- added UList<bool>::operator[](..) const specialization.
  Returns false (actually pTraits<bool>::zero) for out-of-range elements.
  This lets us use List<bool> with lazy evaluation and no noticeable
  change in performance.

- use rcIndex() and fcIndex() wherever possible.
  Could check if branching or modulus is faster for fcIndex().

- UList and FixedList get 'const T* cdata() const' and 'T* data()' members.
  Similar to the STL front() and std::string::data() methods, they return a
  pointer to the first element without needing to write '&myList[0]', recast
  begin() or violate const-ness.
This commit is contained in:
Mark Olesen 2009-02-06 20:43:09 +01:00
parent 603364e1e3
commit 69918f23c5
55 changed files with 363 additions and 233 deletions

View File

@ -77,14 +77,22 @@ int main(int argc, char *argv[])
const PackedList<3>& constLst = list1;
Info<< "\ntest operator[] const with out-of-range index\n";
constLst.print(Info);
if (!constLst[20])
if (constLst[20])
{
Info<< "[20] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) list size should be unchanged (const)\n";
}
constLst.print(Info);
Info<< "\ntest operator[] non-const with out-of-range index\n";
if (!list1[20])
if (list1[20])
{
Info<< "[20] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) but list was resized?? (non-const)\n";
}
@ -268,6 +276,23 @@ int main(int argc, char *argv[])
Info<< "removed final value: " << list3.remove() << endl;
list3.print(Info);
List<bool> list4(4, true);
{
const List<bool>& constLst = list4;
Info<< "\ntest operator[] const with out-of-range index\n";
Info<< constLst << endl;
if (constLst[20])
{
Info<< "[20] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) list size should be unchanged (const)\n";
}
Info<< constLst << endl;
}
Info<< "\n\nDone.\n";
return 0;

View File

@ -69,7 +69,7 @@ void checkFaceEdges
forAll(f, fp)
{
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
if (edges[myEdges[fp]] != edge(f[fp], f[fp1]))
{

View File

@ -74,20 +74,17 @@ labelList getSortedEdges
const edge& e = edges[edgeI];
label fp = findIndex(f, e[0]);
label fp1 = (fp+1) % f.size();
label fp1 = f.fcIndex(fp);
if (f[fp1] == e[1])
{
// Edgei in fp-fp1 order
// EdgeI between fp -> fp1
faceEdges[fp] = edgeI;
}
else
{
// Edgei between fp-1 and fp
label fpMin1 = (fp == 0 ? f.size()-1 : fp-1);
faceEdges[fpMin1] = edgeI;
// EdgeI between fp-1 -> fp
faceEdges[f.rcIndex(fp)] = edgeI;
}
}

View File

@ -211,7 +211,7 @@ void Foam::cellSplitter::setRefinement
// Add other pyramids
for (label i = 1; i < cFaces.size(); i++)
{
{
label addedCellI =
meshMod.setAction
(
@ -277,7 +277,7 @@ void Foam::cellSplitter::setRefinement
label index = findIndex(f0, e[0]);
bool edgeInFaceOrder = (f0[(index+1) % f0.size()] == e[1]);
bool edgeInFaceOrder = (f0[f0.fcIndex(index)] == e[1]);
// Check if cellI is the face owner
@ -323,7 +323,7 @@ void Foam::cellSplitter::setRefinement
label index = findIndex(f1, e[0]);
bool edgeInFaceOrder = (f1[(index+1) % f1.size()] == e[1]);
bool edgeInFaceOrder = (f1[f1.fcIndex(index)] == e[1]);
// Check if cellI is the face owner
@ -362,7 +362,7 @@ void Foam::cellSplitter::setRefinement
}
}
}
//
// Update all existing faces for split owner or neighbour.
@ -441,7 +441,7 @@ void Foam::cellSplitter::setRefinement
label patchID, zoneID, zoneFlip;
getFaceInfo(faceI, patchID, zoneID, zoneFlip);
meshMod.setAction
(
polyModifyFace
@ -458,7 +458,7 @@ void Foam::cellSplitter::setRefinement
)
);
}
faceUpToDate[faceI] = true;
}
}

View File

@ -156,7 +156,7 @@ class vtkPV3Foam
bool empty() const
{
return (size_ == 0);
return !size_;
}
void reset()

View File

@ -351,7 +351,7 @@ label otherEdge
return -1;
}
// Starting from startPoint on startEdge on startFace walk along border
// and insert faces along the way. Walk keeps always one point or one edge
@ -461,18 +461,8 @@ label sharedFace
label startIndex = findIndex(f, e.start());
bool edgeOrder;
if (f[(startIndex + 1) % f.size()] == e.end())
{
// points in face in same order as edge
edgeOrder = true;
}
else
{
// points in face in reverse order as edge
edgeOrder = false;
}
// points in face in same order as edge
bool edgeOrder = (f[f.fcIndex(startIndex)] == e.end());
// Get faces using edge in sorted order. (sorted such that walking
// around them in anti-clockwise order corresponds to edge vector
@ -485,25 +475,18 @@ label sharedFace
if (edgeOrder)
{
// Get face before firstFaceI
if (faceIndex == 0)
{
return eFaces[eFaces.size() - 1];
}
else
{
return eFaces[faceIndex - 1];
}
return eFaces[eFaces.rcIndex(faceIndex)];
}
else
{
// Get face after firstFaceI
return eFaces[(faceIndex+1) % eFaces.size()];
return eFaces[eFaces.fcIndex(faceIndex)];
}
}
// Calculate (inward pointing) normals on edges shared by faces in faceToEdge and
// averages them to pointNormals.
// averages them to pointNormals.
void calcPointVecs
(
const triSurface& surf,
@ -602,7 +585,7 @@ void calcPointVecs
}
scalar magMidVec = mag(midVec);
if (magMidVec > SMALL)
{
midVec /= magMidVec;
@ -925,7 +908,7 @@ int main(int argc, char *argv[])
newPoints[newPointI] = newPoints[pointI] + 0.1 * minLen * n;
}
}
//
// Renumber all faces in connectedFaces

View File

@ -432,7 +432,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
// Set the file mode
bool Foam::chmod(const fileName& name, const mode_t m)
bool Foam::chMod(const fileName& name, const mode_t m)
{
return ::chmod(name.c_str(), m) == 0;
}

View File

@ -226,7 +226,7 @@ bool Foam::HashTable<T, Key, Hash>::set
const bool protect
)
{
if (tableSize_ == 0)
if (!tableSize_)
{
resize(2);
}
@ -556,7 +556,7 @@ void Foam::HashTable<T, Key, Hash>::operator=
}
// could be zero-sized from a previous transfer()
if (tableSize_ == 0)
if (!tableSize_)
{
resize(rhs.tableSize_);
}

View File

@ -54,7 +54,7 @@ inline Foam::label Foam::HashTable<T, Key, Hash>::size() const
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::empty() const
{
return (nElmts_ == 0);
return !nElmts_;
}

View File

@ -41,7 +41,7 @@ inline Foam::label Foam::StaticHashTable<T, Key, Hash>::size() const
template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::empty() const
{
return (nElmts_ == 0);
return !nElmts_;
}

View File

@ -83,7 +83,7 @@ inline Foam::label Foam::DLListBase::size() const
inline bool Foam::DLListBase::empty() const
{
return (nElmts_ == 0);
return !nElmts_;
}

View File

@ -73,7 +73,7 @@ inline Foam::label Foam::SLListBase::size() const
inline bool Foam::SLListBase::empty() const
{
return (nElmts_ == 0);
return !nElmts_;
}

View File

@ -135,10 +135,21 @@ public:
inline label fcIndex(const label i) const;
//- Return the reverse circular index, i.e. the previous index
// which returns to the last at the begining of the list
// which returns to the last at the beginning of the list
inline label rcIndex(const label i) const;
//- Return a const pointer to the first data element,
// similar to the STL front() method and the string::data() method
// This can be used (with caution) when interfacing with C code.
inline const T* cdata() const;
//- Return a pointer to the first data element,
// similar to the STL front() method and the string::data() method
// This can be used (with caution) when interfacing with C code.
inline T* data();
// Check
//- Check start is within valid range (0 ... size-1).
@ -174,10 +185,10 @@ public:
// Member operators
//- Return subscript-checked element of FixedList.
//- Return element of FixedList.
inline T& operator[](const label);
//- Return subscript-checked element of constant FixedList.
//- Return element of constant FixedList.
inline const T& operator[](const label) const;
//- Assignment from array operator. Takes linear time.
@ -282,7 +293,7 @@ public:
//- Return size of the largest possible FixedList.
inline label max_size() const;
//- Return true if the FixedList is empty (i.e., if size() == 0).
//- Return true if the FixedList is empty (ie, size() is zero).
inline bool empty() const;
//- Swap two FixedLists of the same type in constant time.

View File

@ -121,7 +121,7 @@ inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
template<class T, Foam::label Size>
inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
{
return (i == 0 ? Size-1 : i-1);
return (i ? i-1 : Size-1);
}
@ -195,9 +195,26 @@ inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
}
}
template<class T, Foam::label Size>
inline const T*
Foam::FixedList<T, Size>::cdata() const
{
return v_;
}
template<class T, Foam::label Size>
inline T*
Foam::FixedList<T, Size>::data()
{
return v_;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// Return subscript-checked element access
// element access
template<class T, Foam::label Size>
inline T& Foam::FixedList<T, Size>::operator[](const label i)
{
@ -208,7 +225,7 @@ inline T& Foam::FixedList<T, Size>::operator[](const label i)
}
// Return subscript-checked const element access
// const element access
template<class T, Foam::label Size>
inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
{

View File

@ -119,7 +119,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
}
else
{
is.read(reinterpret_cast<char*>(L.begin()), Size*sizeof(T));
is.read(reinterpret_cast<char*>(L.data()), Size*sizeof(T));
is.fatalCheck
(
@ -231,7 +231,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
}
else
{
os.write(reinterpret_cast<const char*>(L.v_), Size*sizeof(T));
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
}
// Check state of IOstream

View File

@ -117,7 +117,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
{
if (s)
{
is.read(reinterpret_cast<char*>(L.begin()), s*sizeof(T));
is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T));
is.fatalCheck
(

View File

@ -90,17 +90,31 @@ void duplicateOrder(const UList<T>&, labelList& order);
template<class T>
void uniqueOrder(const UList<T>&, labelList& order);
//- Extract elements of List whose region is certain value.
// Use e.g. to extract all selected elements:
// subset<boolList, labelList>(selectedElems, true, lst);
//- Extract elements of List when select is a certain value.
// eg, to extract all selected elements:
// subset<bool, labelList>(selectedElems, true, lst);
template<class T, class ListType>
ListType subset(const UList<T>& regions, const T& region, const ListType&);
ListType subset(const UList<T>& select, const T& value, const ListType&);
//- Inplace extract elements of List whose region is certain value. Use e.g.
// to extract all selected elements:
// inplaceSubset<boolList, labelList>(selectedElems, true, lst);
//- Inplace extract elements of List when select is a certain value.
// eg, to extract all selected elements:
// inplaceSubset<bool, labelList>(selectedElems, true, lst);
template<class T, class ListType>
void inplaceSubset(const UList<T>& regions, const T& region, ListType&);
void inplaceSubset(const UList<T>& select, const T& value, ListType&);
//- Extract elements of List when select is true
// eg, to extract all selected elements:
// subset<boolList, labelList>(selectedElems, lst);
// Note a labelHashSet could also be used for the bool-list
template<class BoolListType, class ListType>
ListType subset(const BoolListType& select, const ListType&);
//- Inplace extract elements of List when select is true
// eg, to extract all selected elements:
// inplaceSubset<boolList, labelList>(selectedElems, lst);
// Note a labelHashSet could also be used for the bool-list
template<class BoolListType, class ListType>
void inplaceSubset(const BoolListType& select, ListType&);
//- Invert one-to-one map. Unmapped elements will be -1.
labelList invert(const label len, const UList<label>&);
@ -108,8 +122,9 @@ labelList invert(const label len, const UList<label>&);
//- Invert one-to-many map. Unmapped elements will be size 0.
labelListList invertOneToMany(const label len, const UList<label>&);
//- Invert many-to-many. Input and output types need to be inherited
// from List. E.g. faces to pointFaces.
//- Invert many-to-many.
// Input and output types need to be inherited from List.
// eg, faces to pointFaces.
template<class InList, class OutList>
void invertManyToMany(const label len, const UList<InList>&, List<OutList>&);

View File

@ -243,16 +243,17 @@ void Foam::uniqueOrder
template<class T, class ListType>
ListType Foam::subset
(
const UList<T>& regions,
const T& region,
const UList<T>& select,
const T& value,
const ListType& lst
)
{
if (regions.size() < lst.size())
// select must at least cover the list range
if (select.size() < lst.size())
{
FatalErrorIn("subset(const UList<T>&, const T&, const ListType&)")
<< "Regions is of size " << regions.size()
<< "; list it is supposed to index is of size " << lst.size()
<< "select is of size " << select.size()
<< "; but it must index a list of size " << lst.size()
<< abort(FatalError);
}
@ -261,7 +262,7 @@ ListType Foam::subset
label nElem = 0;
forAll(lst, elemI)
{
if (regions[elemI] == region)
if (select[elemI] == value)
{
newLst[nElem++] = lst[elemI];
}
@ -275,23 +276,77 @@ ListType Foam::subset
template<class T, class ListType>
void Foam::inplaceSubset
(
const UList<T>& regions,
const T& region,
const UList<T>& select,
const T& value,
ListType& lst
)
{
if (regions.size() < lst.size())
// select must at least cover the list range
if (select.size() < lst.size())
{
FatalErrorIn("inplaceSubset(const UList<T>&, const T&, ListType&)")
<< "Regions is of size " << regions.size()
<< "; list it is supposed to index is of size " << lst.size()
<< "select is of size " << select.size()
<< "; but it must index a list of size " << lst.size()
<< abort(FatalError);
}
label nElem = 0;
forAll(lst, elemI)
{
if (regions[elemI] == region)
if (select[elemI] == value)
{
if (nElem != elemI)
{
lst[nElem] = lst[elemI];
}
++nElem;
}
}
lst.setSize(nElem);
}
template<class BoolListType, class ListType>
ListType Foam::subset
(
const BoolListType& select,
const ListType& lst
)
{
// select can have a different size
// eg, when it is a PackedBoolList or a labelHashSet
ListType newLst(lst.size());
label nElem = 0;
forAll(lst, elemI)
{
if (select[elemI])
{
newLst[nElem++] = lst[elemI];
}
}
newLst.setSize(nElem);
return newLst;
}
template<class BoolListType, class ListType>
void Foam::inplaceSubset
(
const BoolListType& select,
ListType& lst
)
{
// select can have a different size
// eg, when it is a PackedBoolList or a labelHashSet
label nElem = 0;
forAll(lst, elemI)
{
if (select[elemI])
{
if (nElem != elemI)
{

View File

@ -185,7 +185,7 @@ public:
//- Number of entries.
inline label size() const;
//- Return true if the list is empty (i.e., size() == 0).
//- Return true if the list is empty (ie, size() is zero).
inline bool empty() const;
//- Get value at index I.

View File

@ -158,7 +158,7 @@ public:
//- Return the number of elements in the PtrList
inline label size() const;
//- Return true if the PtrList is empty (i.e., if size() == 0).
//- Return true if the PtrList is empty (ie, size() is zero).
inline bool empty() const;

View File

@ -27,7 +27,7 @@ Class
Description
A 1D vector of objects of type \<T\>, where the size of the vector is
known and used for subscript bounds checking, etc.
known and can be used for subscript bounds checking, etc.
Storage is not allocated during construction or use but is supplied to
the constructor as an argument. This type of list is particularly useful
@ -140,6 +140,17 @@ public:
label byteSize() const;
//- Return a const pointer to the first data element,
// similar to the STL front() method and the string::data() method
// This can be used (with caution) when interfacing with C code.
inline const T* cdata() const;
//- Return a pointer to the first data element,
// similar to the STL front() method and the string::data() method
// This can be used (with caution) when interfacing with C code.
inline T* data();
// Check
//- Check start is within valid range (0 ... size-1).
@ -164,10 +175,12 @@ public:
// Member operators
//- Return subscript-checked element of UList.
//- Return element of UList.
inline T& operator[](const label);
//- Return subscript-checked element of constant UList.
//- Return element of constant UList.
// Note that the bool specialization adds lazy evaluation so reading
// an out-of-range element returns false without any ill-effects
inline const T& operator[](const label) const;
//- Allow cast to a const List<T>&
@ -266,7 +279,7 @@ public:
//- Return size of the largest possible UList.
inline label max_size() const;
//- Return true if the UList is empty (i.e., if size() == 0).
//- Return true if the UList is empty (ie, size() is zero).
inline bool empty() const;
//- Swap two ULists of the same type in constant time.

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "pTraits.H"
#include "Swap.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -64,7 +65,7 @@ inline Foam::label Foam::UList<T>::fcIndex(const label i) const
template<class T>
inline Foam::label Foam::UList<T>::rcIndex(const label i) const
{
return (i == 0 ? size()-1 : i-1);
return (i ? i-1 : size()-1);
}
@ -113,9 +114,24 @@ inline void Foam::UList<T>::checkIndex(const label i) const
}
template<class T>
inline const T* Foam::UList<T>::cdata() const
{
return v_;
}
template<class T>
inline T* Foam::UList<T>::data()
{
return v_;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// Return subscript-checked element access
// element access
template<class T>
inline T& Foam::UList<T>::operator[](const label i)
{
@ -126,7 +142,28 @@ inline T& Foam::UList<T>::operator[](const label i)
}
// Return subscript-checked const element access
namespace Foam
{
// Template specialization for bool
template<>
inline const bool& Foam::UList<bool>::operator[](const label i) const
{
// lazy evaluation - return false for out-of-range
if (i < size_)
{
return v_[i];
}
else
{
return Foam::pTraits<bool>::zero;
}
}
} // end of namespace Foam
// const element access
template<class T>
inline const T& Foam::UList<T>::operator[](const label i) const
{
@ -248,7 +285,7 @@ inline Foam::label Foam::UList<T>::max_size() const
template<class T>
inline bool Foam::UList<T>::empty() const
{
return (size_ == 0);
return !size_;
}

View File

@ -124,7 +124,7 @@ public:
//- Return the number of elements in the UPtrList
inline label size() const;
//- Return true if the UPtrList is empty (i.e., if size() == 0).
//- Return true if the UPtrList is empty (ie, size() is zero).
inline bool empty() const;

View File

@ -31,11 +31,7 @@ License
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(Time, 0);
}
defineTypeNameAndDebug(Foam::Time, 0);
template<>
const char* Foam::NamedEnum<Foam::Time::stopAtControls, 4>::names[] =
@ -100,9 +96,11 @@ void Foam::Time::adjustDeltaT()
void Foam::Time::setControls()
{
// default is to resume calculation from "latestTime"
word startFrom("latestTime");
controlDict_.readIfPresent("startFrom", startFrom);
word startFrom = controlDict_.lookupOrDefault<word>
(
"startFrom",
"latestTime"
);
if (startFrom == "startTime")
{
@ -421,7 +419,7 @@ Foam::instant Foam::Time::findClosestTime(const scalar t) const
label nearestIndex = -1;
scalar deltaT = GREAT;
for (label i=1; i<times.size(); i++)
for (label i=1; i < times.size(); i++)
{
scalar diff = mag(times[i].value() - t);
if (diff < deltaT)

View File

@ -103,7 +103,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
const List<instant>& Times
) const
{
return subset(selected(Times), true, Times);
return subset(selected(Times), Times);
}
@ -112,7 +112,7 @@ void Foam::timeSelector::inplaceSelect
List<instant>& Times
) const
{
inplaceSubset(selected(Times), true, Times);
inplaceSubset(selected(Times), Times);
}
@ -219,7 +219,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
}
}
return subset(selectTimes, true, timeDirs);
return subset(selectTimes, timeDirs);
}
else
{

View File

@ -123,7 +123,7 @@ Foam::List<Foam::scalar> Foam::scalarRanges::select
const List<scalar>& values
) const
{
return subset(selected(values), true, values);
return subset(selected(values), values);
}
@ -132,7 +132,7 @@ void Foam::scalarRanges::inplaceSelect
List<scalar>& values
) const
{
inplaceSubset(selected(values), true, values);
inplaceSubset(selected(values), values);
}

View File

@ -110,7 +110,7 @@ fileName findEtcFile(const fileName&, bool mandatory=false);
bool mkDir(const fileName&, mode_t=0777);
//- Set the file mode
bool chmod(const fileName&, const mode_t);
bool chMod(const fileName&, const mode_t);
//- Return the file mode
mode_t mode(const fileName&);

View File

@ -44,7 +44,7 @@ void Foam::interpolationTable<Type>::readTable()
// Check that the data are okay
check();
if (this->size() == 0)
if (this->empty())
{
FatalErrorIn
(

View File

@ -82,7 +82,7 @@ public:
//- Return true if the reference count is zero
bool okToDelete() const
{
return (count_ == 0);
return !count_;
}

View File

@ -36,7 +36,7 @@ inline Foam::label Foam::face::right(const label i) const
// Edge to the left of face vertex i
inline Foam::label Foam::face::left(const label i) const
{
return i == 0 ? size() - 1 : (i - 1);
return i ? i-1 : size()-1;
}

View File

@ -867,7 +867,7 @@ bool primitiveMesh::checkFaceAngles
forAll(f, fp0)
{
// Get vertex after fp
label fp1 = (fp0 + 1) % f.size();
label fp1 = f.fcIndex(fp0);
// Normalized vector between two consecutive points
vector e10(p[f[fp1]] - p[f[fp0]]);
@ -1636,12 +1636,12 @@ bool primitiveMesh::checkCommonOrder
// Vertices before and after on curFace
label fpPlus1 = (fp+1) % curFace.size();
label fpMin1 = (fp == 0 ? curFace.size()-1 : fp-1);
label fpPlus1 = curFace.fcIndex(fp);
label fpMin1 = curFace.rcIndex(fp);
// Vertices before and after on nbFace
label nbPlus1 = (nb+1) % nbFace.size();
label nbMin1 = (nb == 0 ? nbFace.size()-1 : nb-1);
label nbPlus1 = nbFace.fcIndex(nb);
label nbMin1 = nbFace.rcIndex(nb);
// Find order of walking by comparing next points on both
// faces.

View File

@ -155,20 +155,10 @@ void Foam::walkPatch::faceToFace
indexInFace_.append(fp);
// Visit neighbouring faces in order, starting at fp.
for (label i = 0; i < f.size(); i++)
{
label fp1;
if (reverse_)
{
fp1 = (fp == 0 ? f.size()-1 : fp-1);
}
else
{
fp1 = (fp + 1) % f.size();
}
label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
if

View File

@ -340,8 +340,8 @@ Foam::label Foam::octreeDataFaceList::getSampleType
// Face intersection point lies on edge between two face triangles
// Calculate edge normal as average of the two triangle normals
label fpPrev = (fp == 0 ? f.size()-1 : fp-1);
label fpNext = (fp + 1) % f.size();
label fpPrev = f.rcIndex(fp);
label fpNext = f.fcIndex(fp);
vector e = points[f[fp]] - ctr;
vector ePrev = points[f[fpPrev]] - ctr;
@ -434,7 +434,7 @@ bool Foam::octreeDataFaceList::intersects
// Disable picking up intersections behind us.
scalar oldTol = intersection::setPlanarTol(0.0);
pointHit inter =
pointHit inter =
f.ray
(
start,
@ -486,7 +486,7 @@ bool Foam::octreeDataFaceList::findTightest
else
{
// Construct bb around sample and myFar
const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z()));
tightest.min() = sample - dist2;
tightest.max() = sample + dist2;
@ -558,7 +558,7 @@ Foam::scalar Foam::octreeDataFaceList::calcNearest
}
return nearHit.distance();
}
void Foam::octreeDataFaceList::write
(

View File

@ -374,7 +374,7 @@ void Foam::cellCuts::calcFaceCuts() const
label cutI = 0;
// Do point-edge-point walk over face and collect all cuts.
// Problem is that we want to start from one of the endpoints of a
// Problem is that we want to start from one of the endpoints of a
// string of connected cuts; we don't want to start somewhere in the
// middle.
@ -387,17 +387,16 @@ void Foam::cellCuts::calcFaceCuts() const
if (pointIsCut_[v0])
{
label fpMin1 = (fp == 0 ? f.size()-1 : fp-1);
label vMin1 = f[fpMin1];
label vMin1 = f[f.rcIndex(fp)];
if
if
(
!pointIsCut_[vMin1]
&& !edgeIsCut_[findEdge(faceI, v0, vMin1)]
)
{
cuts[cutI++] = vertToEVert(v0);
startFp = (fp+1) % f.size();
startFp = f.fcIndex(fp);
break;
}
}
@ -408,7 +407,7 @@ void Foam::cellCuts::calcFaceCuts() const
{
forAll(f, fp)
{
label fp1 = (fp+1) % f.size();
label fp1 = f.fcIndex(fp);
label v0 = f[fp];
label v1 = f[fp1];
@ -438,7 +437,7 @@ void Foam::cellCuts::calcFaceCuts() const
forAll(f, i)
{
label fp1 = (fp+1) % f.size();
label fp1 = f.fcIndex(fp);
// Get the three items: current vertex, next vertex and edge
// inbetween
@ -659,7 +658,7 @@ bool Foam::cellCuts::crossEdge
return true;
}
else
{
{
// No success. Restore state (i.e. backtrack)
nVisited = oldNVisited;
@ -794,7 +793,7 @@ bool Foam::cellCuts::walkFace
// Walk across cuts (cut edges or cut vertices) of cell. Stops when hit cut
// Walk across cuts (cut edges or cut vertices) of cell. Stops when hit cut
// already visited. Returns true when loop of 3 or more vertices found.
bool Foam::cellCuts::walkCell
(
@ -1202,7 +1201,7 @@ Foam::labelList Foam::cellCuts::nonAnchorPoints
if
(
findIndex(anchorPoints, pointI) == -1
findIndex(anchorPoints, pointI) == -1
&& findIndex(loop, vertToEVert(pointI)) == -1
)
{
@ -1556,7 +1555,7 @@ bool Foam::cellCuts::calcAnchors
}
prevStat = eStat;
}
}
}
}
@ -2135,7 +2134,7 @@ bool Foam::cellCuts::setFromCellLoop
// Storage for points on one side of cell
labelList anchorPoints;
okLoop =
okLoop =
validLoop(cellI, loop, loopWeights, faceSplitCuts, anchorPoints);
if (okLoop)
@ -3007,7 +3006,7 @@ void Foam::cellCuts::flip(const label cellI)
mesh().cellPoints()[cellI],
cellAnchorPoints_[cellI],
loop
);
);
}

View File

@ -53,7 +53,6 @@ namespace Foam
{
defineTypeNameAndDebug(geomCellLooper, 0);
addToRunTimeSelectionTable(cellLooper, geomCellLooper, word);
}
@ -187,8 +186,8 @@ bool Foam::geomCellLooper::edgeEndsCut
const edge& e = mesh().edges()[edgeI];
label prevCut = loop[(index == 0 ? loop.size()-1 : index-1)];
label nextCut = loop[(index == loop.size()-1 ? 0 : index+1)];
const label prevCut = loop[loop.rcIndex(index)];
const label nextCut = loop[loop.fcIndex(index)];
if (!isEdge(prevCut) && !isEdge(nextCut))
{
@ -360,7 +359,7 @@ bool Foam::geomCellLooper::cut
}
else
{
// Cut through edge end point. Might be duplicate
// Cut through edge end point. Might be duplicate
// since connected edge might also be snapped to same
// endpoint so only insert if unique.
label cut = vertToEVert(cutVertI);

View File

@ -76,24 +76,11 @@ bool Foam::meshCutAndRemove::isIn
return false;
}
label nextIndex = (index + 1) % cuts.size();
if (cuts[nextIndex] == twoCuts[1])
{
return true;
}
label prevIndex = (index == 0 ? cuts.size()-1 : index - 1);
if (cuts[prevIndex] == twoCuts[1])
{
return true;
}
else
{
return false;
}
return
(
cuts[cuts.fcIndex(index)] == twoCuts[1]
|| cuts[cuts.rcIndex(index)] == twoCuts[1]
);
}
@ -502,11 +489,11 @@ Foam::face Foam::meshCutAndRemove::addEdgeCutsToFace(const label faceI) const
forAll(f, fp)
{
// Duplicate face vertex .
// Duplicate face vertex.
newFace[newFp++] = f[fp];
// Check if edge has been cut.
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
HashTable<label, edge, Hash<edge> >::const_iterator fnd =
addedPoints_.find(edge(f[fp], f[fp1]));
@ -558,7 +545,7 @@ Foam::face Foam::meshCutAndRemove::loopToFace
newFace[newFaceI++] = vertI;
label nextCut = loop[(fp+1) % loop.size()];
label nextCut = loop[loop.fcIndex(fp)];
if (!isEdge(nextCut))
{

View File

@ -72,24 +72,11 @@ bool Foam::meshCutter::isIn
return false;
}
label nextIndex = (index + 1) % cuts.size();
if (cuts[nextIndex] == twoCuts[1])
{
return true;
}
label prevIndex = (index == 0 ? cuts.size()-1 : index - 1);
if (cuts[prevIndex] == twoCuts[1])
{
return true;
}
else
{
return false;
}
return
(
cuts[cuts.fcIndex(index)] == twoCuts[1]
|| cuts[cuts.rcIndex(index)] == twoCuts[1]
);
}
@ -459,7 +446,7 @@ Foam::face Foam::meshCutter::addEdgeCutsToFace(const label faceI) const
newFace[newFp++] = f[fp];
// Check if edge has been cut.
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
HashTable<label, edge, Hash<edge> >::const_iterator fnd =
addedPoints_.find(edge(f[fp], f[fp1]));
@ -511,7 +498,7 @@ Foam::face Foam::meshCutter::loopToFace
newFace[newFaceI++] = vertI;
label nextCut = loop[(fp+1) % loop.size()];
label nextCut = loop[loop.fcIndex(fp)];
if (!isEdge(nextCut))
{

View File

@ -1284,7 +1284,7 @@ bool Foam::polyMeshGeometry::checkFaceAngles
forAll(f, fp0)
{
// Get vertex after fp
label fp1 = (fp0 + 1) % f.size();
label fp1 = f.fcIndex(fp0);
// Normalized vector between two consecutive points
vector e10(p[f[fp1]] - p[f[fp0]]);

View File

@ -69,7 +69,7 @@ bool Foam::combineFaces::convexFace
forAll(f, fp0)
{
// Get vertex after fp
label fp1 = (fp0 + 1) % f.size();
label fp1 = f.fcIndex(fp0);
// Normalized vector between two consecutive points
vector e10(points[f[fp1]] - points[f[fp0]]);
@ -730,7 +730,7 @@ void Foam::combineFaces::setRefinement
}
else
{
// Count removed points
// Count removed points
label n = 0;
forAll(nPointFaces, pointI)
{

View File

@ -71,7 +71,7 @@ Foam::label Foam::faceCollapser::findEdge
label edgeI = edgeLabels[i];
const edge& e = edges[edgeI];
if
(
(e[0] == v0 && e[1] == v1)
@ -113,7 +113,7 @@ void Foam::faceCollapser::filterFace
newFace.append(v0);
// Look ahead one to get edge.
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
label v1 = f[fp1];
@ -410,7 +410,7 @@ void Foam::faceCollapser::setRefinement
forAll(f, fp)
{
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
// Get index in sorted list
label sorted0 = sortedFp[fp];

View File

@ -50,7 +50,7 @@ bool Foam::cellFeatures::faceAlignedEdge(const label faceI, const label edgeI)
{
if (f[fp] == e.start())
{
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
return f[fp1] == e.end();
}
@ -112,7 +112,7 @@ Foam::label Foam::cellFeatures::nextEdge
<< thisEdgeI << " at vertex " << thisVertI << endl
<< "This might mean that the externalEdges do not form a closed loop"
<< abort(FatalError);
return -1;
}
@ -146,12 +146,12 @@ bool Foam::cellFeatures::isCellFeatureEdge
const face& f0 = mesh_.faces()[face0];
label face0Start = findIndex(f0, e.start());
label face0End = (face0Start + 1) % f0.size();
label face0End = f0.fcIndex(face0Start);
const face& f1 = mesh_.faces()[face1];
label face1Start = findIndex(f1, e.start());
label face1End = (face1Start + 1) % f1.size();
label face1End = f1.fcIndex(face1Start);
if
(
@ -268,7 +268,7 @@ void Foam::cellFeatures::calcSuperFaces() const
{
faceMap_[superI].shrink();
}
// Construct superFaces

View File

@ -440,8 +440,8 @@ Foam::label Foam::octreeDataFace::getSampleType
// Face intersection point lies on edge between two face triangles
// Calculate edge normal as average of the two triangle normals
label fpPrev = (fp == 0 ? f.size()-1 : fp-1);
label fpNext = (fp + 1) % f.size();
const label fpPrev = f.rcIndex(fp);
const label fpNext = f.fcIndex(fp);
vector e = points[f[fp]] - mesh_.faceCentres()[faceI];
vector ePrev = points[f[fpPrev]] - mesh_.faceCentres()[faceI];
@ -530,7 +530,7 @@ bool Foam::octreeDataFace::overlaps
forAll(f, fp)
{
label fp1 = (fp == f.size()-1 ? 0 : fp+1);
const label fp1 = f.fcIndex(fp);
bool triIntersects = triangleFuncs::intersectBb
(

View File

@ -808,7 +808,7 @@ bool Foam::primitiveMeshGeometry::checkFaceAngles
forAll(f, fp0)
{
// Get vertex after fp
label fp1 = (fp0 + 1) % f.size();
label fp1 = f.fcIndex(fp0);
// Normalized vector between two consecutive points
vector e10(p[f[fp1]] - p[f[fp0]]);

View File

@ -241,14 +241,14 @@ void Foam::booleanSurface::propagateEdgeSide
{
// Edge (and hence eFaces) in same order as prevVert0.
// Take next face from sorted list
nextInd = (ind + 1) % eFaces.size();
prevInd = (ind > 0 ? ind - 1 : eFaces.size()-1);
nextInd = eFaces.fcIndex(ind);
prevInd = eFaces.rcIndex(ind);
}
else
{
// Take previous face from sorted neighbours
nextInd = (ind > 0 ? ind - 1 : eFaces.size()-1);
prevInd = (ind + 1) % eFaces.size();
nextInd = eFaces.rcIndex(ind);
prevInd = eFaces.fcIndex(ind);
}

View File

@ -222,11 +222,11 @@ bool Foam::intersectedSurface::sameEdgeOrder
{
// Get prev/next vertex on fA
label vA1 = fA[(fpA + 1) % 3];
label vAMin1 = fA[fpA == 0 ? 2 : fpA-1];
label vAMin1 = fA[fpA ? fpA-1 : 2];
// Get prev/next vertex on fB
label vB1 = fB[(fpB + 1) % 3];
label vBMin1 = fB[fpB == 0 ? 2 : fpB-1];
label vBMin1 = fB[fpB ? fpB-1 : 2];
if (vA1 == vB1 || vAMin1 == vBMin1)
{
@ -1308,14 +1308,14 @@ Foam::intersectedSurface::intersectedSurface
// Construct mapping back into original surface
faceMap_.setSize(size());
for(label faceI = 0; faceI < surf.size()-1; faceI++)
for (label faceI = 0; faceI < surf.size()-1; faceI++)
{
for(label triI = startTriI[faceI]; triI < startTriI[faceI+1]; triI++)
for (label triI = startTriI[faceI]; triI < startTriI[faceI+1]; triI++)
{
faceMap_[triI] = faceI;
}
}
for(label triI = startTriI[surf.size()-1]; triI < size(); triI++)
for (label triI = startTriI[surf.size()-1]; triI < size(); triI++)
{
faceMap_[triI] = surf.size()-1;
}

View File

@ -473,7 +473,7 @@ Foam::label Foam::BasicMeshedSurface<Face>::triangulate
for (label fp = 1; fp < f.size() - 1; ++fp)
{
label fp1 = (fp + 1) % f.size();
label fp1 = f.fcIndex(fp);
newFaces[newFaceI] = triFace(f[0], f[fp], f[fp1]);
faceMap[newFaceI] = faceI;

View File

@ -269,6 +269,22 @@ void Foam::surfMesh::transfer
}
Foam::Xfer< Foam::MeshedSurface<Foam::face> >
Foam::surfMesh::xfer()
{
Xfer< MeshedSurface<face> > xf;
xf().storedPoints().transfer(storedPoints_);
xf().storedFaces().transfer(storedFaces_);
xf().storedZones().transfer(surfZones_);
// Clear addressing.
MeshReference::clearGeom();
return xf;
}
void Foam::surfMesh::rename(const word& newName)
{
FatalErrorIn

View File

@ -315,6 +315,9 @@ public:
// Storage management
//- Transfer contents to the Xfer container as a MeshedSurface
Xfer< MeshedSurface<face> > xfer();
//- Clear geometry
void clearGeom();

View File

@ -227,7 +227,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
// points may be incomplete
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2]));
sizes[zoneI]++;

View File

@ -182,7 +182,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
// points may be incomplete
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{
label fp2 = (fp1 + 1) % f.size();
label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2]));
dynZones.append(zoneI);

View File

@ -130,7 +130,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
// cannot use face::triangulation (points may be incomplete)
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{
label fp2 = (fp1 + 1) % f.size();
label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2]));
}

View File

@ -54,7 +54,7 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
const point& p0 = pointLst[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
label fp2 = f.fcIndex(fp1);
const point& p1 = pointLst[f[fp1]];
const point& p2 = pointLst[f[fp2]];
@ -95,7 +95,7 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
const point& p0 = pointLst[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
label fp2 = f.fcIndex(fp1);
STLtriangle stlTri
(

View File

@ -45,7 +45,7 @@ inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
const point& p0 = pointLst[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
label fp2 = f.fcIndex(fp1);
const point& p1 = pointLst[f[fp1]];
const point& p2 = pointLst[f[fp2]];

View File

@ -33,17 +33,17 @@ License
const Foam::scalar Foam::faceTriangulation::edgeRelTol = 1E-6;
//- Edge to the right of face vertex i
// Edge to the right of face vertex i
Foam::label Foam::faceTriangulation::right(const label, label i)
{
return i;
}
//- Edge to the left of face vertex i
// Edge to the left of face vertex i
Foam::label Foam::faceTriangulation::left(const label size, label i)
{
return i == 0 ? size - 1 : (i - 1);
return i ? i-1 : size-1;
}
@ -60,10 +60,8 @@ Foam::tmp<Foam::vectorField> Foam::faceTriangulation::calcEdges
forAll(f, i)
{
label ni = f.fcIndex(i);
point thisPt = points[f[i]];
point nextPt = points[f[ni]];
point nextPt = points[f[f.fcIndex(i)]];
vector vec(nextPt - thisPt);
vec /= mag(vec) + VSMALL;
@ -109,7 +107,7 @@ void Foam::faceTriangulation::calcHalfAngle
// Return true and intersection point if intersection between p1 and p2.
Foam::pointHit Foam::faceTriangulation::rayEdgeIntersect
(
const vector& normal,
const vector& normal,
const point& rayOrigin,
const vector& rayDir,
const point& p1,
@ -225,10 +223,10 @@ void Foam::faceTriangulation::findDiagonal
label minIndex = -1;
scalar minPosOnEdge = GREAT;
for(label i = 0; i < f.size() - 2; i++)
for (label i = 0; i < f.size() - 2; i++)
{
scalar posOnEdge;
pointHit inter =
pointHit inter =
rayEdgeIntersect
(
normal,
@ -258,7 +256,7 @@ void Foam::faceTriangulation::findDiagonal
index1 = -1;
index2 = -1;
return;
return;
}
const label leftIndex = minIndex;
@ -299,7 +297,7 @@ void Foam::faceTriangulation::findDiagonal
// all vertices except for startIndex and ones to left and right of it.
faceVertI = f.fcIndex(f.fcIndex(startIndex));
for(label i = 0; i < f.size() - 3; i++)
for (label i = 0; i < f.size() - 3; i++)
{
const point& pt = points[f[faceVertI]];
@ -400,7 +398,7 @@ Foam::label Foam::faceTriangulation::findStart
return minIndex;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -153,7 +153,7 @@ bool triSurface::readOBJ(const fileName& OBJfileName)
// Cannot use face::triangulation since no complete points yet.
for (label fp = 1; fp < verts.size() - 1; fp++)
{
label fp1 = (fp + 1) % verts.size();
label fp1 = verts.fcIndex(fp);
labelledTri tri(verts[0], verts[fp], verts[fp1], groupID);