55int main(
int argc,
char *argv[])
59 "A surface analysis tool that subsets the surface to choose a"
60 " region of interest."
63 argList::noParallel();
64 argList::addArgument(
"dict",
"The surfaceSubsetDict");
65 argList::addArgument(
"input",
"The input surface file");
66 argList::addArgument(
"output",
"The output surface file");
69 Info<<
"Reading dictionary " <<
args[1] <<
" ..." <<
endl;
79 surf1.writeStats(Info);
85 meshSubsetDict.lookup(
"localPoints")
90 meshSubsetDict.lookup(
"edges")
95 meshSubsetDict.lookup(
"faces")
100 meshSubsetDict.lookup(
"zone")
106 if (markedZone.size())
108 if (markedZone.size() != 2)
111 <<
"zone specification should be two points, min and max of "
112 <<
"the boundingbox" <<
endl
113 <<
"zone:" << markedZone
117 zoneBb.
min() = markedZone[0];
118 zoneBb.
max() = markedZone[1];
123 <<
"Defined zone is invalid: " << zoneBb <<
nl;
128 const bool addFaceNeighbours =
129 meshSubsetDict.get<
bool>(
"addFaceNeighbours");
131 const bool invertSelection =
132 meshSubsetDict.getOrDefault(
"invertSelection",
false);
137 bitSet facesToSubset(surf1.size(),
false);
144 if (markedPoints.size())
146 Info<<
"Found " << markedPoints.size() <<
" marked point(s)." <<
endl;
148 for (
const label pointi : markedPoints)
150 if (pointi < 0 || pointi >= surf1.nPoints())
153 <<
"localPoint label " << pointi <<
"out of range."
154 <<
" Surface has " << surf1.nPoints() <<
" localPoints."
158 const labelList& curFaces = surf1.pointFaces()[pointi];
160 facesToSubset.
set(curFaces);
169 if (markedEdges.size())
171 Info<<
"Found " << markedEdges.size() <<
" marked edge(s)." <<
endl;
173 for (
const label edgei : markedEdges)
175 if (edgei < 0 || edgei >= surf1.nEdges())
178 <<
"edge label " << edgei <<
"out of range."
179 <<
" Surface has " << surf1.nEdges() <<
" edges."
183 const labelList& curFaces = surf1.edgeFaces()[edgei];
185 facesToSubset.
set(curFaces);
196 Info<<
"Using zone " << zoneBb <<
endl;
200 const point centre = surf1[facei].
centre(surf1.points());
204 facesToSubset.set(facei);
214 if (meshSubsetDict.found(
"surface"))
218 const auto surfName(surfDict.
get<
fileName>(
"name"));
223 ? volumeType::OUTSIDE
227 Info<<
"Selecting faces with centre located "
228 << volumeType::names[volType] <<
" of surface "
242 searchSelectSurf.tree();
247 if (!facesToSubset[facei])
249 const point fc(surf1[facei].centre(surf1.points()));
251 if (volType == selectTree.getVolumeType(fc))
253 facesToSubset.set(facei);
260 if (meshSubsetDict.found(
"plane"))
264 const plane pl(planeDict);
265 const scalar
distance(planeDict.
get<scalar>(
"distance"));
266 const scalar cosAngle(planeDict.
get<scalar>(
"cosAngle"));
271 forAll(surf1.faceCentres(), facei)
273 const point& fc = surf1.faceCentres()[facei];
274 const point& nf = surf1.faceNormals()[facei];
276 if (pl.distance(fc) < distance &&
mag(pl.normal() & nf) > cosAngle)
278 facesToSubset.set(facei);
290 label nFaceNeighbours = 0;
292 if (markedFaces.size())
294 Info<<
"Found " << markedFaces.size() <<
" marked face(s)." <<
endl;
297 for (
const label facei : markedFaces)
299 if (facei < 0 || facei >= surf1.size())
302 <<
"Face label " << facei <<
"out of range."
303 <<
" Surface has " << surf1.size() <<
" faces."
308 facesToSubset.set(facei);
311 if (addFaceNeighbours)
313 const labelList& curFaces = surf1.faceFaces()[facei];
315 for (
const label neiFacei : curFaces)
317 if (facesToSubset.set(neiFacei))
326 if (addFaceNeighbours)
328 Info<<
"Added " << nFaceNeighbours
329 <<
" faces because of addFaceNeighbours" <<
endl;
335 Info<<
"Inverting selection." <<
endl;
337 facesToSubset.flip();
345 surf2.writeStats(Info);
348 Info<<
"Writing surface to " << outFileName <<
endl;
350 surf2.
write(outFileName);
Input from file stream, using an ISstream.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
const Vector< Cmpt > & centre(const Foam::UList< Vector< Cmpt > > &) const
Return *this (used for point which is a typedef to Vector<scalar>.
Extract command arguments and options from the supplied argc and argv parameters.
T get(const label index) const
Get a value from the argument at index.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
A bounding box defined in terms of min/max extrema points.
bool valid() const
Bounding box is non-inverted.
const point & min() const
Minimum describing the bounding box.
const point & max() const
Maximum describing the bounding box.
bool contains(const point &pt) const
Contains point? (inside or on edge)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
A class for handling file names.
Non-pointer based hierarchical recursive searching.
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Helper class to search on triSurface.
Triangulated surface description with patch information.
type
Volume classification types.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
scalar distance(const vector &p1, const vector &p2)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.