surfaceGenerateBoundingBox.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Finds feature edges and corners of a triangulated surface
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "IFstream.H"
31 #include "fileName.H"
32 #include "triSurf.H"
33 #include "triSurfModifier.H"
34 #include "boundBox.H"
35 #include "OFstream.H"
36 
37 #include <cstdlib>
38 #include <sstream>
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // Main program:
42 using namespace Foam;
43 
44 int main(int argc, char *argv[])
45 {
47  argList::validArgs.clear();
48  argList::validArgs.append("input surface file");
49  argList::validArgs.append("output surface file");
50  argList::validArgs.append("x-neg");
51  argList::validArgs.append("x-pos");
52  argList::validArgs.append("y-neg");
53  argList::validArgs.append("y-pos");
54  argList::validArgs.append("z-neg");
55  argList::validArgs.append("z-pos");
56 
57  argList args(argc, argv);
58 
59  fileName inFileName(args.args()[1]);
60  fileName outFileName(args.args()[2]);
61 
62  if (outFileName == inFileName)
63  {
65  << "Output file " << outFileName
66  << " would overwrite the input file."
67  << exit(FatalError);
68  }
69 
70  triSurf origSurface(inFileName);
71  triSurfModifier sMod(origSurface);
72  pointField& points = sMod.pointsAccess();
73 
74  const boundBox bb(points);
75 
76  vector negOffset, posOffset;
77  for(label i=3;i<9;++i)
78  {
79  std::stringstream ss;
80  ss << args.args()[i];
81 
82  scalar s;
83  ss >> s;
84 
85  if( i % 2 )
86  {
87  negOffset[(i-3)/2] = s;
88  }
89  else
90  {
91  posOffset[(i-3)/2] = s;
92  }
93  }
94 
95  Info << "Neg offset " << negOffset << endl;
96  Info << "Pos offset " << posOffset << endl;
97 
98  const boundBox newBB(bb.min()-negOffset, bb.max()+posOffset);
99  Info << "Surface bounding box " << bb << endl;
100  Info << "Generated bounding box " << newBB << endl;
101 
102  //- generate bounding box points
103  const label nPoints = points.size();
104  points.setSize(nPoints + 8);
105 
106  points[nPoints] = newBB.min();
107  points[nPoints+1] =
108  point(newBB.max().x(), newBB.min().y(), newBB.min().z());
109  points[nPoints+2] =
110  point(newBB.min().x(), newBB.max().y(), newBB.min().z());
111  points[nPoints+3] =
112  point(newBB.max().x(), newBB.max().y(), newBB.min().z());
113  points[nPoints+4] =
114  point(newBB.min().x(), newBB.min().y(), newBB.max().z());
115  points[nPoints+5] =
116  point(newBB.max().x(), newBB.min().y(), newBB.max().z());
117  points[nPoints+6] =
118  point(newBB.min().x(), newBB.max().y(), newBB.max().z());
119  points[nPoints+7] = newBB.max();
120 
121  //- generate bounding bound triangles
122  const label nTriangles = origSurface.size();
123  LongList<labelledTri>& newTriangles = sMod.facetsAccess();
124  newTriangles.setSize(nTriangles+12);
125 
126  //- create patches
127  geometricSurfacePatchList& newPatches = sMod.patchesAccess();
128  const label nPatches = origSurface.patches().size();
129  newPatches.setSize(nPatches+6);
130 
131  newPatches[nPatches].name() = "xMin";
132  newPatches[nPatches+1].name() = "xMax";
133  newPatches[nPatches+2].name() = "yMin";
134  newPatches[nPatches+3].name() = "yMax";
135  newPatches[nPatches+4].name() = "zMin";
136  newPatches[nPatches+5].name() = "zMax";
137 
138  //- negative x direction
139  newTriangles[nTriangles] =
141  newTriangles[nTriangles+1] =
143  //- positive x direction
144  newTriangles[nTriangles+2] =
146  newTriangles[nTriangles+3] =
148  //- negative y direction
149  newTriangles[nTriangles+4] =
151  newTriangles[nTriangles+5] =
153  //- positive y direction
154  newTriangles[nTriangles+6] =
156  newTriangles[nTriangles+7] =
158  //- negative z direction
159  newTriangles[nTriangles+8] =
161  newTriangles[nTriangles+9] =
163  //- positive z direction
164  newTriangles[nTriangles+10] =
166  newTriangles[nTriangles+11] =
168 
169  //- write the surface
170  origSurface.writeSurface(outFileName);
171 
172  Info << "End\n" << endl;
173 
174  return 0;
175 }
176 
177 
178 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
triSurf.H
Foam::argList::args
const stringList & args() const
Return arguments.
Definition: argListI.H:66
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
nPatches
label nPatches
Definition: readKivaGrid.H:402
main
int main(int argc, char *argv[])
Definition: surfaceGenerateBoundingBox.C:44
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
triSurfModifier.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::triSurfModifier
Definition: triSurfModifier.H:48
Foam::triSurfModifier::patchesAccess
geometricSurfacePatchList & patchesAccess()
access to patches
Definition: triSurfModifierI.H:52
OFstream.H
Foam::LongList::setSize
void setSize(const label)
Reset size of List.
Definition: LongListI.H:223
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::LongList
Definition: LongList.H:55
Foam::argList::executable
const word & executable() const
Name of executable without the path.
Definition: argListI.H:30
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::triSurfModifier::pointsAccess
pointField & pointsAccess()
non-const access to points
Definition: triSurfModifierI.H:37
argList.H
Foam::triSurfFacets::patches
const geometricSurfacePatchList & patches() const
access to patches
Definition: triSurfFacetsI.H:49
fileName.H
Foam::triSurfModifier::facetsAccess
LongList< labelledTri > & facetsAccess()
access to facets
Definition: triSurfModifierI.H:42
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
IFstream.H
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
boundBox.H
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::triSurfFacets::size
label size() const
return the number of triangles
Definition: triSurfFacetsI.H:39
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::point
vector point
Point is a vector.
Definition: point.H:41
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::triSurf
Definition: triSurf.H:59