mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop
This commit is contained in:
@ -109,7 +109,31 @@ int main(int argc, char *argv[])
|
||||
SubList<label> test5SubList(test5, 4, 3);
|
||||
Info<< "List : " << test5 << endl;
|
||||
inplaceReverseList(test5SubList);
|
||||
Info<< "Reverse Sublist between 3 and 6 : " << test5 << endl;
|
||||
Info<< "Reverse Sublist between 3 and 6 : " << test5 << nl << endl;
|
||||
|
||||
Info<< nl << "Test lambda predicates:" << nl << endl;
|
||||
|
||||
List<label> test6(identity(11));
|
||||
// shift range for general testing
|
||||
std::for_each(test6.begin(), test6.end(), [](label& x){ x -= 4; });
|
||||
|
||||
Info<< "Subset of non-zero, even values: "
|
||||
<< subsetList
|
||||
(
|
||||
test6,
|
||||
[](const label& x){ return x && !(x % 2); }
|
||||
) << nl
|
||||
<< endl;
|
||||
|
||||
|
||||
test6.append(identity(13));
|
||||
|
||||
// Randomize the list
|
||||
std::random_shuffle(test6.begin(), test6.end());
|
||||
|
||||
Info<< "Randomized: " << flatOutput(test6) << endl;
|
||||
inplaceUniqueSort(test6);
|
||||
Info<< "Unique : " << flatOutput(test6) << endl;
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
|
||||
@ -39,11 +39,11 @@ Description
|
||||
setValue
|
||||
(
|
||||
fvMatrix<Type}>& eqn,
|
||||
const label fieldi
|
||||
const label fieldi
|
||||
)
|
||||
|
||||
where :
|
||||
fld is the field in fieldNames
|
||||
fieldi is the index in the fields entry
|
||||
eqn is the fvMatrix
|
||||
|
||||
energySource
|
||||
@ -55,7 +55,7 @@ Description
|
||||
|
||||
scalarCodedSourceCoeffs
|
||||
{
|
||||
fieldNames (h);
|
||||
fields (h);
|
||||
name sourceTime;
|
||||
|
||||
codeInclude
|
||||
|
||||
@ -28,7 +28,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::labelList Foam::emptyLabelList = Foam::labelList(0);
|
||||
const Foam::labelList Foam::emptyLabelList;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
@ -43,7 +43,7 @@ Foam::labelList Foam::invert
|
||||
|
||||
forAll(map, i)
|
||||
{
|
||||
label newPos = map[i];
|
||||
const label newPos = map[i];
|
||||
|
||||
if (newPos >= 0)
|
||||
{
|
||||
@ -89,7 +89,7 @@ Foam::labelListList Foam::invertOneToMany
|
||||
|
||||
forAll(map, i)
|
||||
{
|
||||
label newI = map[i];
|
||||
const label newI = map[i];
|
||||
|
||||
if (newI >= 0)
|
||||
{
|
||||
@ -105,10 +105,11 @@ Foam::labelList Foam::identity(const label len)
|
||||
{
|
||||
labelList map(len);
|
||||
|
||||
forAll(map, i)
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
map[i] = i;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@ -55,26 +55,27 @@ static const List<Type>& emptyList()
|
||||
return *reinterpret_cast<const List<Type>*>(&emptyLabelList);
|
||||
}
|
||||
|
||||
|
||||
//- Renumber the values (not the indices) of a list.
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
ListType renumber(const labelUList& oldToNew, const ListType&);
|
||||
ListType renumber(const labelUList& oldToNew, const ListType& lst);
|
||||
|
||||
//- Inplace renumber the values of a list.
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
void inplaceRenumber(const labelUList& oldToNew, ListType&);
|
||||
void inplaceRenumber(const labelUList& oldToNew, ListType& lst);
|
||||
|
||||
|
||||
//- Reorder the elements (indices, not values) of a list.
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
ListType reorder(const labelUList& oldToNew, const ListType&);
|
||||
ListType reorder(const labelUList& oldToNew, const ListType& lst);
|
||||
|
||||
//- Inplace reorder the elements of a list.
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
void inplaceReorder(const labelUList& oldToNew, ListType&);
|
||||
void inplaceReorder(const labelUList& oldToNew, ListType& lst);
|
||||
|
||||
|
||||
// Variants to work with iterators and sparse tables.
|
||||
@ -82,65 +83,92 @@ void inplaceReorder(const labelUList& oldToNew, ListType&);
|
||||
|
||||
//- Map values. Do not map negative values.
|
||||
template<class Container>
|
||||
void inplaceMapValue(const labelUList& oldToNew, Container&);
|
||||
void inplaceMapValue(const labelUList& oldToNew, Container& lst);
|
||||
|
||||
//- Recreate with mapped keys. Do not map elements with negative key.
|
||||
template<class Container>
|
||||
void inplaceMapKey(const labelUList& oldToNew, Container&);
|
||||
void inplaceMapKey(const labelUList& oldToNew, Container& lst);
|
||||
|
||||
|
||||
//- Generate the (stable) sort order for the list
|
||||
template<class T>
|
||||
void sortedOrder(const UList<T>&, labelList& order);
|
||||
void sortedOrder(const UList<T>& lst, labelList& order);
|
||||
|
||||
template<class T, class Cmp>
|
||||
void sortedOrder(const UList<T>&, labelList& order, const Cmp& cmp);
|
||||
void sortedOrder(const UList<T>& lst, labelList& order, const Cmp& cmp);
|
||||
|
||||
|
||||
//- Generate (sorted) indices corresponding to duplicate list values
|
||||
template<class T>
|
||||
void duplicateOrder(const UList<T>&, labelList& order);
|
||||
void duplicateOrder(const UList<T>& lst, labelList& order);
|
||||
|
||||
template<class T, class Cmp>
|
||||
void duplicateOrder(const UList<T>&, labelList& order, const Cmp& cmp);
|
||||
void duplicateOrder(const UList<T>& lst, labelList& order, const Cmp& cmp);
|
||||
|
||||
|
||||
//- Generate (sorted) indices corresponding to unique list values
|
||||
template<class T>
|
||||
void uniqueOrder(const UList<T>&, labelList& order);
|
||||
void uniqueOrder(const UList<T>& lst, labelList& order);
|
||||
|
||||
template<class T, class Cmp>
|
||||
void uniqueOrder(const UList<T>&, labelList& order, const Cmp& cmp);
|
||||
void uniqueOrder(const UList<T>& lst, labelList& order, const Cmp& cmp);
|
||||
|
||||
|
||||
//- Inplace sorting and removal of duplicates.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
template<class ListType>
|
||||
void inplaceUniqueSort(ListType& lst);
|
||||
|
||||
//- Inplace sorting and removal of duplicates.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
template<class ListType, class Cmp>
|
||||
void inplaceUniqueSort(ListType& lst, const Cmp& cmp);
|
||||
|
||||
|
||||
//- Extract elements of List when select is a certain value.
|
||||
// eg, to extract all selected elements:
|
||||
// subset<bool, labelList>(selectedElems, true, lst);
|
||||
// \deprecated use subsetList instead (deprecated Mar 2017)
|
||||
template<class T, class ListType>
|
||||
ListType subset(const UList<T>& select, const T& value, const ListType&);
|
||||
|
||||
//- Inplace extract elements of List when select is a certain value.
|
||||
// eg, to extract all selected elements:
|
||||
// inplaceSubset<bool, labelList>(selectedElems, true, lst);
|
||||
// \deprecated use inplaceSubsetList instead (deprecated Mar 2017)
|
||||
template<class T, class 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
|
||||
// Note a labelHashSet can also be used as the bool-list.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
template<class BoolListType, class ListType>
|
||||
ListType subset(const BoolListType& select, const ListType&);
|
||||
ListType subset(const BoolListType& select, const ListType& lst);
|
||||
|
||||
//- 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
|
||||
// Note a labelHashSet can also be used as the bool-list.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
template<class BoolListType, class ListType>
|
||||
void inplaceSubset(const BoolListType& select, ListType&);
|
||||
void inplaceSubset(const BoolListType& select, ListType& lst);
|
||||
|
||||
|
||||
//- Copy a subset of the input list when predicate is true.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
template<class ListType, class UnaryPredicate>
|
||||
ListType subsetList(const ListType& input, UnaryPredicate pred);
|
||||
|
||||
//- Inplace subset of the list when predicate is true.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
template<class ListType, class UnaryPredicate>
|
||||
void inplaceSubsetList(ListType& input, UnaryPredicate pred);
|
||||
|
||||
|
||||
//- Invert one-to-one map. Unmapped elements will be -1.
|
||||
labelList invert(const label len, const labelUList&);
|
||||
labelList invert(const label len, const labelUList& map);
|
||||
|
||||
//- Invert one-to-many map. Unmapped elements will be size 0.
|
||||
labelListList invertOneToMany(const label len, const labelUList&);
|
||||
labelListList invertOneToMany(const label len, const labelUList& map);
|
||||
|
||||
//- Invert many-to-many.
|
||||
// Input and output types need to be inherited from List.
|
||||
@ -156,7 +184,7 @@ List<OutList> invertManyToMany(const label len, const UList<InList>& in)
|
||||
return out;
|
||||
}
|
||||
|
||||
//- Create identity map (map[i] == i) of given length
|
||||
//- Create identity map of the given length with (map[i] == i)
|
||||
labelList identity(const label len);
|
||||
|
||||
//- Find first occurence of given element and return index,
|
||||
@ -173,8 +201,8 @@ label findIndex
|
||||
template<class ListType>
|
||||
labelList findIndices
|
||||
(
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
@ -182,9 +210,9 @@ labelList findIndices
|
||||
template<class ListType>
|
||||
void setValues
|
||||
(
|
||||
ListType&,
|
||||
ListType& l,
|
||||
const labelUList& indices,
|
||||
typename ListType::const_reference
|
||||
typename ListType::const_reference t
|
||||
);
|
||||
|
||||
//- Opposite of findIndices: set values at indices to given value
|
||||
@ -200,13 +228,13 @@ ListType createWithValues
|
||||
//- Find index of max element (and larger than given element).
|
||||
// return -1 if not found. Linear search.
|
||||
template<class ListType>
|
||||
label findMax(const ListType&, const label start=0);
|
||||
label findMax(const ListType& l, const label start=0);
|
||||
|
||||
|
||||
//- Find index of min element (and less than given element).
|
||||
// return -1 if not found. Linear search.
|
||||
template<class ListType>
|
||||
label findMin(const ListType&, const label start=0);
|
||||
label findMin(const ListType& l, const label start=0);
|
||||
|
||||
|
||||
//- Find first occurrence of given element in sorted list and return index,
|
||||
@ -214,8 +242,8 @@ label findMin(const ListType&, const label start=0);
|
||||
template<class ListType>
|
||||
label findSortedIndex
|
||||
(
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
@ -225,8 +253,8 @@ label findSortedIndex
|
||||
template<class ListType, class BinaryOp>
|
||||
label findLower
|
||||
(
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start,
|
||||
const BinaryOp& bop
|
||||
);
|
||||
@ -237,20 +265,24 @@ label findLower
|
||||
template<class ListType>
|
||||
label findLower
|
||||
(
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
|
||||
//- To construct a List from a C array. Has extra Container type
|
||||
// to initialise e.g. wordList from arrays of char*.
|
||||
//
|
||||
// \deprecated can often use initializer_list instead (deprecated Mar 2017)
|
||||
template<class Container, class T, int mRows>
|
||||
List<Container> initList(const T[mRows]);
|
||||
|
||||
|
||||
//- To construct a (square) ListList from a C array. Has extra Container type
|
||||
// to initialise e.g. faceList from arrays of labels.
|
||||
//
|
||||
// \deprecated can often use initializer_list instead (deprecated Mar 2017)
|
||||
template<class Container, class T, int mRows, int nColumns>
|
||||
List<Container> initListList(const T[mRows][nColumns]);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -34,11 +34,8 @@ ListType Foam::renumber
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
// Create copy
|
||||
ListType newLst(lst.size());
|
||||
|
||||
// ensure consistent addressable size (eg, DynamicList)
|
||||
newLst.setSize(lst.size());
|
||||
newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList)
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
@ -76,11 +73,8 @@ ListType Foam::reorder
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
// Create copy
|
||||
ListType newLst(lst.size());
|
||||
|
||||
// ensure consistent addressable size (eg, DynamicList)
|
||||
newLst.setSize(lst.size());
|
||||
newLst.setSize(lst.size()); // Consistent sizes (eg, DynamicList)
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
@ -104,11 +98,8 @@ void Foam::inplaceReorder
|
||||
ListType& lst
|
||||
)
|
||||
{
|
||||
// Create copy
|
||||
ListType newLst(lst.size());
|
||||
|
||||
// ensure consistent addressable size (eg, DynamicList)
|
||||
newLst.setSize(lst.size());
|
||||
newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList)
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
@ -236,8 +227,9 @@ void Foam::duplicateOrder
|
||||
|
||||
sortedOrder(lst, order, cmp);
|
||||
|
||||
const label last = (order.size()-1);
|
||||
label n = 0;
|
||||
for (label i = 0; i < order.size() - 1; ++i)
|
||||
for (label i = 0; i < last; ++i)
|
||||
{
|
||||
if (lst[order[i]] == lst[order[i+1]])
|
||||
{
|
||||
@ -271,20 +263,50 @@ void Foam::uniqueOrder
|
||||
|
||||
if (order.size() > 1)
|
||||
{
|
||||
const label last = (order.size()-1);
|
||||
label n = 0;
|
||||
for (label i = 0; i < order.size() - 1; ++i)
|
||||
for (label i = 0; i < last; ++i)
|
||||
{
|
||||
if (lst[order[i]] != lst[order[i+1]])
|
||||
{
|
||||
order[n++] = order[i];
|
||||
}
|
||||
}
|
||||
order[n++] = order[order.size()-1];
|
||||
order[n++] = order[last];
|
||||
order.setSize(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class ListType>
|
||||
void Foam::inplaceUniqueSort(ListType& lst)
|
||||
{
|
||||
inplaceUniqueSort
|
||||
(
|
||||
lst,
|
||||
typename UList<typename ListType::value_type>::less(lst)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class ListType, class Cmp>
|
||||
void Foam::inplaceUniqueSort(ListType& lst, const Cmp& cmp)
|
||||
{
|
||||
labelList order;
|
||||
uniqueOrder(lst, order, cmp);
|
||||
|
||||
ListType newLst(order.size());
|
||||
newLst.setSize(order.size()); // Consistent sizing (eg, DynamicList)
|
||||
|
||||
forAll(order, elemI)
|
||||
{
|
||||
newLst[elemI] = lst[order[elemI]];
|
||||
}
|
||||
|
||||
lst.transfer(newLst);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class ListType>
|
||||
ListType Foam::subset
|
||||
(
|
||||
@ -303,9 +325,7 @@ ListType Foam::subset
|
||||
}
|
||||
|
||||
ListType newLst(lst.size());
|
||||
|
||||
// ensure consistent addressable size (eg, DynamicList)
|
||||
newLst.setSize(lst.size());
|
||||
newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList)
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
@ -366,9 +386,7 @@ ListType Foam::subset
|
||||
// eg, when it is a PackedBoolList or a labelHashSet
|
||||
|
||||
ListType newLst(lst.size());
|
||||
|
||||
// ensure consistent addressable size (eg, DynamicList)
|
||||
newLst.setSize(lst.size());
|
||||
newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList)
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
@ -411,6 +429,54 @@ void Foam::inplaceSubset
|
||||
}
|
||||
|
||||
|
||||
template<class ListType, class UnaryPredicate>
|
||||
ListType Foam::subsetList
|
||||
(
|
||||
const ListType& lst,
|
||||
UnaryPredicate pred
|
||||
)
|
||||
{
|
||||
ListType newLst(lst.size());
|
||||
newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList)
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
if (pred(lst[elemI]))
|
||||
{
|
||||
newLst[nElem++] = lst[elemI];
|
||||
}
|
||||
}
|
||||
newLst.setSize(nElem);
|
||||
|
||||
return newLst;
|
||||
}
|
||||
|
||||
|
||||
template<class ListType, class UnaryPredicate>
|
||||
void Foam::inplaceSubsetList
|
||||
(
|
||||
ListType& lst,
|
||||
UnaryPredicate pred
|
||||
)
|
||||
{
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
if (pred(lst[elemI]))
|
||||
{
|
||||
if (nElem != elemI)
|
||||
{
|
||||
lst[nElem] = lst[elemI];
|
||||
}
|
||||
++nElem;
|
||||
}
|
||||
}
|
||||
|
||||
lst.setSize(nElem);
|
||||
}
|
||||
|
||||
|
||||
template<class InList, class OutList>
|
||||
void Foam::invertManyToMany
|
||||
(
|
||||
|
||||
@ -515,7 +515,9 @@ Foam::Time::Time
|
||||
*this,
|
||||
argList::validOptions.found("withFunctionObjects")
|
||||
? args.optionFound("withFunctionObjects")
|
||||
: !args.optionFound("noFunctionObjects")
|
||||
: argList::validOptions.found("noFunctionObjects")
|
||||
? !args.optionFound("noFunctionObjects")
|
||||
: false
|
||||
)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
@ -590,7 +592,6 @@ Foam::Time::Time
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
|
||||
|
||||
// Explicitly set read flags on objectRegistry so anything constructed
|
||||
// from it reads as well (e.g. fvSolution).
|
||||
readOpt() = IOobject::MUST_READ_IF_MODIFIED;
|
||||
|
||||
@ -45,7 +45,7 @@ SourceFiles
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
// single-string matches:
|
||||
// Single-string matches:
|
||||
|
||||
//- Return true if string matches one of the regular expressions
|
||||
inline bool findStrings
|
||||
@ -57,14 +57,14 @@ namespace Foam
|
||||
return matcher.match(str);
|
||||
}
|
||||
|
||||
// multi-string matches:
|
||||
// Multi-string matches:
|
||||
|
||||
//- Return list indices for matching strings
|
||||
template<class Matcher, class StringType>
|
||||
labelList findMatchingStrings
|
||||
(
|
||||
const Matcher&,
|
||||
const UList<StringType>&,
|
||||
const Matcher& matcher,
|
||||
const UList<StringType>& lst,
|
||||
const bool invert=false
|
||||
);
|
||||
|
||||
@ -92,7 +92,7 @@ namespace Foam
|
||||
)
|
||||
{
|
||||
const regExp re(rePattern);
|
||||
return findStrings(re, lst, invert);
|
||||
return findMatchingStrings(re, lst, invert);
|
||||
}
|
||||
|
||||
//- Return list indices for strings matching the regular expression
|
||||
|
||||
@ -32,9 +32,30 @@ License
|
||||
|
||||
//! \cond fileScope
|
||||
|
||||
// The number of bytes in the STL binary header
|
||||
// The number of bytes in the STL binary header
|
||||
static const unsigned STLHeaderSize = 80;
|
||||
|
||||
// Check if "SOLID" or "solid" appears as the first non-space content.
|
||||
// Assume that any leading space is less than 75 chars or so, otherwise
|
||||
// it is really bad input.
|
||||
static bool startsWithSolid(const char header[STLHeaderSize])
|
||||
{
|
||||
unsigned pos = 0;
|
||||
while (std::isspace(header[pos]) && pos < STLHeaderSize)
|
||||
{
|
||||
++pos;
|
||||
}
|
||||
|
||||
return
|
||||
(
|
||||
pos < (STLHeaderSize-5) // At least 5 chars remaining
|
||||
&& std::toupper(header[pos+0]) == 'S'
|
||||
&& std::toupper(header[pos+1]) == 'O'
|
||||
&& std::toupper(header[pos+2]) == 'L'
|
||||
&& std::toupper(header[pos+3]) == 'I'
|
||||
&& std::toupper(header[pos+4]) == 'D'
|
||||
);
|
||||
}
|
||||
//! \endcond
|
||||
|
||||
|
||||
@ -58,10 +79,10 @@ bool Foam::fileFormats::STLCore::isBinaryName
|
||||
|
||||
// Check binary by getting the header and number of facets
|
||||
// this seems to work better than the old token-based method
|
||||
// - some programs (eg, pro-STAR) have 'solid' as the first word in
|
||||
// the binary header.
|
||||
// - using wordToken can cause an abort if non-word (binary) content
|
||||
// is detected ... this is not exactly what we want.
|
||||
// - some programs (eg, pro-STAR) have 'solid' as the first word in
|
||||
// the binary header. This is just wrong and not our fault.
|
||||
int Foam::fileFormats::STLCore::detectBinaryHeader
|
||||
(
|
||||
const fileName& filename
|
||||
@ -93,27 +114,24 @@ int Foam::fileFormats::STLCore::detectBinaryHeader
|
||||
char header[STLHeaderSize];
|
||||
is.read(header, STLHeaderSize);
|
||||
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good())
|
||||
// If the stream is bad, it can't be a binary STL
|
||||
if (!is.good() || startsWithSolid(header))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Read the number of triangles in the STL file
|
||||
// (note: read as int so we can check whether >2^31)
|
||||
int nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
// (note: read as signed so we can check whether >2^31)
|
||||
int32_t nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(int32_t));
|
||||
|
||||
// Check that stream is OK and number of triangles is positive,
|
||||
// if not this may be an ASCII file
|
||||
//
|
||||
// Also compare the file size with that expected from the number of tris
|
||||
// If the comparison is not sensible then it may be an ASCII file
|
||||
if
|
||||
(
|
||||
!is
|
||||
|| nTris < 0
|
||||
)
|
||||
// If the comparison is still not sensible then it may be an ASCII file
|
||||
if (!is || nTris < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -176,7 +194,7 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
is.read(header, STLHeaderSize);
|
||||
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good())
|
||||
if (!is.good()) // could check again: startsWithSolid(header)
|
||||
{
|
||||
streamPtr.clear();
|
||||
|
||||
@ -187,8 +205,8 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
|
||||
// Read the number of triangles in the STl file
|
||||
// (note: read as int so we can check whether >2^31)
|
||||
int nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
int32_t nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(int32_t));
|
||||
|
||||
// Check that stream is OK and number of triangles is positive,
|
||||
// if not this maybe an ASCII file
|
||||
@ -230,7 +248,7 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
void Foam::fileFormats::STLCore::writeBinaryHeader
|
||||
(
|
||||
ostream& os,
|
||||
unsigned int nTris
|
||||
uint32_t nTris
|
||||
)
|
||||
{
|
||||
// STL header with extra information about nTris
|
||||
@ -244,7 +262,7 @@ void Foam::fileFormats::STLCore::writeBinaryHeader
|
||||
}
|
||||
|
||||
os.write(header, STLHeaderSize);
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(uint32_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ protected:
|
||||
|
||||
//- Check contents to detect if the file is a binary STL.
|
||||
// Return the estimated number of triangles or 0 on error.
|
||||
static int detectBinaryHeader(const fileName&);
|
||||
static int detectBinaryHeader(const fileName& filename);
|
||||
|
||||
|
||||
//- Read STL binary file header.
|
||||
@ -92,7 +92,7 @@ protected:
|
||||
);
|
||||
|
||||
//- Write STL binary file and number of triangles to stream
|
||||
static void writeBinaryHeader(ostream&, unsigned int);
|
||||
static void writeBinaryHeader(ostream& os, uint32_t nTris);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -42,24 +42,6 @@ namespace Foam
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
//- Plus op for FixedList<scalar>
|
||||
template<class T, unsigned Size>
|
||||
class ListPlusEqOp
|
||||
{
|
||||
public:
|
||||
void operator()
|
||||
(
|
||||
FixedList<T, Size>& x,
|
||||
const FixedList<T, Size>& y
|
||||
) const
|
||||
{
|
||||
forAll(x, i)
|
||||
{
|
||||
x[i] += y[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ License
|
||||
#include "SortableList.H"
|
||||
#include "PackedBoolList.H"
|
||||
#include "surfZoneList.H"
|
||||
#include "surfaceFormatsCore.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -41,6 +42,69 @@ namespace Foam
|
||||
}
|
||||
|
||||
|
||||
// Note that these lists are a stop-gap measure until the read/write handling
|
||||
// gets properly updated
|
||||
const Foam::wordHashSet Foam::triSurface::readTypes_
|
||||
{
|
||||
"ftr", "stl", "stlb", "gts", "obj", "off", "tri", "ac", "nas", "vtk"
|
||||
};
|
||||
|
||||
|
||||
const Foam::wordHashSet Foam::triSurface::writeTypes_
|
||||
{
|
||||
"ftr", "stl", "stlb", "gts", "obj", "off", "tri", "ac", "smesh", "vtk"
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::triSurface::canReadType(const word& ext, const bool verbose)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
readTypes(),
|
||||
ext,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::triSurface::canWriteType(const word& ext, const bool verbose)
|
||||
{
|
||||
return fileFormats::surfaceFormatsCore::checkSupport
|
||||
(
|
||||
writeTypes(),
|
||||
ext,
|
||||
verbose,
|
||||
"writing"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::triSurface::canRead(const fileName& name, const bool verbose)
|
||||
{
|
||||
word ext = name.ext();
|
||||
if (ext == "gz")
|
||||
{
|
||||
ext = name.lessExt().ext();
|
||||
}
|
||||
return canReadType(ext, verbose);
|
||||
}
|
||||
|
||||
|
||||
const Foam::wordHashSet& Foam::triSurface::readTypes()
|
||||
{
|
||||
return readTypes_;
|
||||
}
|
||||
|
||||
|
||||
const Foam::wordHashSet& Foam::triSurface::writeTypes()
|
||||
{
|
||||
return writeTypes_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName Foam::triSurface::triSurfInstance(const Time& d)
|
||||
|
||||
@ -90,6 +90,9 @@ class triSurface
|
||||
// during reading and writing)
|
||||
geometricSurfacePatchList patches_;
|
||||
|
||||
static const wordHashSet readTypes_;
|
||||
static const wordHashSet writeTypes_;
|
||||
|
||||
|
||||
// Demand driven private data.
|
||||
|
||||
@ -240,6 +243,18 @@ public:
|
||||
//- Name of triSurface directory to use.
|
||||
static fileName triSurfInstance(const Time&);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const fileName& name, const bool verbose=false);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canReadType(const word& ext, const bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWriteType(const word& ext, const bool verbose=false);
|
||||
|
||||
static const wordHashSet& readTypes();
|
||||
static const wordHashSet& writeTypes();
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user