1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Import from various third-party surface formats into surfMesh
29 with optional scaling or transformations (rotate/translate)
30 on a coordinateSystem.
33 - surfaceMeshImport inputFile [OPTION]
36 Perform some surface checking/cleanup on the input surface.
38 @param -name \<name\> \n
39 Specify an alternative surface name when writing.
41 @param -scaleIn \<scale\> \n
42 Specify a scaling factor when reading files.
44 @param -scaleOut \<scale\> \n
45 Specify a scaling factor when writing files.
47 @param -dict \<dictionary\> \n
48 Specify an alternative dictionary for constant/coordinateSystems.
50 @param -from \<coordinateSystem\> \n
51 Specify a coordinate System when reading files.
53 @param -to \<coordinateSystem\> \n
54 Specify a coordinate System when writing files.
57 The filename extensions are used to determine the file format type.
59 \*---------------------------------------------------------------------------*/
62 #include "timeSelector.H"
63 #include "objectRegistry.H"
66 #include "MeshedSurfaces.H"
67 #include "coordinateSystems.H"
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 int main(int argc, char *argv[])
76 argList::noParallel();
77 argList::validArgs.append("inputFile");
78 argList::validOptions.insert("name", "name");
79 argList::validOptions.insert("clean", "");
80 argList::validOptions.insert("scaleIn", "scale");
81 argList::validOptions.insert("scaleOut", "scale");
82 argList::validOptions.insert("dict", "coordinateSystemsDict");
83 argList::validOptions.insert("from", "sourceCoordinateSystem");
84 argList::validOptions.insert("to", "targetCoordinateSystem");
86 # include "setRootCase.H"
87 # include "createTime.H"
89 const stringList& params = args.additionalArgs();
91 // try for the latestTime, but create "constant" as needed
92 instantList Times = runTime.times();
95 label startTime = Times.size()-1;
96 runTime.setTime(Times[startTime], startTime);
100 runTime.setTime(instant(0, runTime.constant()), 0);
104 fileName importName(params[0]);
105 word exportName("default");
106 args.optionReadIfPresent("name", exportName);
108 // check that reading is supported
109 if (!MeshedSurface<face>::canRead(importName, true))
115 // get the coordinate transformations
116 autoPtr<coordinateSystem> fromCsys;
117 autoPtr<coordinateSystem> toCsys;
119 if (args.optionFound("from") || args.optionFound("to"))
121 autoPtr<IOobject> ioPtr;
123 if (args.optionFound("dict"))
125 fileName dictPath(args.option("dict"));
133 ? dictPath/coordinateSystems::typeName
149 coordinateSystems::typeName,
160 if (!ioPtr->headerOk())
162 FatalErrorIn(args.executable())
163 << "Cannot open coordinateSystems file\n "
164 << ioPtr->objectPath() << nl
168 coordinateSystems csLst(ioPtr());
170 if (args.optionFound("from"))
172 const word csName(args.option("from"));
174 label csId = csLst.find(csName);
177 FatalErrorIn(args.executable())
178 << "Cannot find -from " << csName << nl
179 << "available coordinateSystems: " << csLst.toc() << nl
183 fromCsys.reset(new coordinateSystem(csLst[csId]));
186 if (args.optionFound("to"))
188 const word csName(args.option("to"));
190 label csId = csLst.find(csName);
193 FatalErrorIn(args.executable())
194 << "Cannot find -to " << csName << nl
195 << "available coordinateSystems: " << csLst.toc() << nl
199 toCsys.reset(new coordinateSystem(csLst[csId]));
203 // maybe fix this later
204 if (fromCsys.valid() && toCsys.valid())
206 FatalErrorIn(args.executable())
207 << "Only allowed '-from' or '-to' option at the moment."
214 MeshedSurface<face> surf(importName);
216 if (args.optionFound("clean"))
223 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
225 Info<< " -scaleIn " << scaleIn << endl;
226 surf.scalePoints(scaleIn);
229 if (fromCsys.valid())
231 Info<< " -from " << fromCsys().name() << endl;
232 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
233 surf.movePoints(tpf());
238 Info<< " -to " << toCsys().name() << endl;
239 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
240 surf.movePoints(tpf());
244 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
246 Info<< " -scaleOut " << scaleOut << endl;
247 surf.scalePoints(scaleOut);
262 Info<< "writing surfMesh:\n " << smesh.objectPath() << endl;
265 Info<< "\nEnd\n" << endl;
270 // ************************************************************************* //