1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 Convert between surface formats with optional scaling or
29 transformations (rotate/translate) on a coordinateSystem.
32 - surfaceMeshConvert inputFile outputFile [OPTION]
35 Perform some surface checking/cleanup on the input surface.
37 \param -scaleIn \<scale\> \n
38 Specify a scaling factor when reading files.
40 \param -scaleOut \<scale\> \n
41 Specify a scaling factor when writing files.
43 \param -dict \<dictionary\> \n
44 Specify an alternative dictionary for constant/coordinateSystems.
46 \param -from \<coordinateSystem\> \n
47 Specify a coordinate System when reading files.
49 \param -to \<coordinateSystem\> \n
50 Specify a coordinate System when writing files.
56 The filename extensions are used to determine the file format type.
58 \*---------------------------------------------------------------------------*/
61 #include "timeSelector.H"
64 #include "MeshedSurfaces.H"
65 #include "coordinateSystems.H"
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 int main(int argc, char *argv[])
76 "convert between surface formats"
79 argList::noParallel();
80 argList::validArgs.append("inputFile");
81 argList::validArgs.append("outputFile");
83 argList::addBoolOption
86 "perform some surface checking/cleanup on the input surface"
92 "geometry scaling factor on input"
98 "geometry scaling factor on output"
104 "specify alternative dictionary for the coordinateSystems descriptions"
110 "specify the source coordinate system, applied after '-scaleIn'"
116 "specify the target coordinate system, applied before '-scaleOut'"
118 argList::addBoolOption
121 "triangulate surface"
125 argList args(argc, argv);
126 Time runTime(args.rootPath(), args.caseName());
128 const fileName importName = args[1];
129 const fileName exportName = args[2];
131 // disable inplace editing
132 if (importName == exportName)
134 FatalErrorIn(args.executable())
135 << "Output file " << exportName << " would overwrite input file."
139 // check that reading/writing is supported
142 !MeshedSurface<face>::canRead(importName, true)
143 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
150 // get the coordinate transformations
151 autoPtr<coordinateSystem> fromCsys;
152 autoPtr<coordinateSystem> toCsys;
154 if (args.optionFound("from") || args.optionFound("to"))
156 autoPtr<IOobject> csDictIoPtr;
158 if (args.optionFound("dict"))
160 const fileName dictPath = args["dict"];
168 ? dictPath/coordinateSystems::typeName
184 coordinateSystems::typeName,
195 if (!csDictIoPtr->headerOk())
197 FatalErrorIn(args.executable())
198 << "Cannot open coordinateSystems file\n "
199 << csDictIoPtr->objectPath() << nl
203 coordinateSystems csLst(csDictIoPtr());
205 if (args.optionFound("from"))
207 const word csName = args["from"];
209 const label csIndex = csLst.findIndex(csName);
212 FatalErrorIn(args.executable())
213 << "Cannot find -from " << csName << nl
214 << "available coordinateSystems: " << csLst.toc() << nl
218 fromCsys.reset(new coordinateSystem(csLst[csIndex]));
221 if (args.optionFound("to"))
223 const word csName = args["to"];
225 const label csIndex = csLst.findIndex(csName);
228 FatalErrorIn(args.executable())
229 << "Cannot find -to " << csName << nl
230 << "available coordinateSystems: " << csLst.toc() << nl
234 toCsys.reset(new coordinateSystem(csLst[csIndex]));
238 // maybe fix this later
239 if (fromCsys.valid() && toCsys.valid())
241 FatalErrorIn(args.executable())
242 << "Only allowed '-from' or '-to' option at the moment."
249 MeshedSurface<face> surf(importName);
251 if (args.optionFound("clean"))
257 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
259 Info<< " -scaleIn " << scaleIn << endl;
260 surf.scalePoints(scaleIn);
264 if (fromCsys.valid())
266 Info<< " -from " << fromCsys().name() << endl;
267 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
268 surf.movePoints(tpf());
273 Info<< " -to " << toCsys().name() << endl;
274 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
275 surf.movePoints(tpf());
279 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
281 Info<< " -scaleOut " << scaleOut << endl;
282 surf.scalePoints(scaleOut);
285 if (args.optionFound("tri"))
287 Info<< "triangulate" << endl;
291 Info<< "writing " << exportName;
292 surf.write(exportName);
295 Info<< "\nEnd\n" << endl;
300 // ************************************************************************* //