1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | 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/>.
29 Convert between surface formats with optional scaling or
30 transformations (rotate/translate) on a coordinateSystem.
33 - surfaceMeshConvert inputFile outputFile [OPTION]
36 Perform some surface checking/cleanup on the input surface.
38 @param -scaleIn \<scale\> \n
39 Specify a scaling factor when reading files.
41 @param -scaleOut \<scale\> \n
42 Specify a scaling factor when writing files.
44 @param -dict \<dictionary\> \n
45 Specify an alternative dictionary for constant/coordinateSystems.
47 @param -from \<coordinateSystem\> \n
48 Specify a coordinate System when reading files.
50 @param -to \<coordinateSystem\> \n
51 Specify a coordinate System when writing files.
54 The filename extensions are used to determine the file format type.
56 \*---------------------------------------------------------------------------*/
59 #include "timeSelector.H"
60 #include "objectRegistry.H"
62 #include "MeshedSurfaces.H"
63 #include "coordinateSystems.H"
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 int main(int argc, char *argv[])
72 argList::noParallel();
73 argList::validArgs.append("inputFile");
74 argList::validArgs.append("outputFile");
75 argList::validOptions.insert("clean", "");
76 argList::validOptions.insert("scaleIn", "scale");
77 argList::validOptions.insert("scaleOut", "scale");
78 argList::validOptions.insert("dict", "coordinateSystemsDict");
79 argList::validOptions.insert("from", "sourceCoordinateSystem");
80 argList::validOptions.insert("to", "targetCoordinateSystem");
82 argList args(argc, argv);
83 Time runTime(args.rootPath(), args.caseName());
84 const stringList& params = args.additionalArgs();
86 fileName importName(params[0]);
87 fileName exportName(params[1]);
89 // disable inplace editing
90 if (importName == exportName)
92 FatalErrorIn(args.executable())
93 << "Output file " << exportName << " would overwrite input file."
97 // check that reading/writing is supported
100 !MeshedSurface<face>::canRead(importName, true)
101 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
108 // get the coordinate transformations
109 autoPtr<coordinateSystem> fromCsys;
110 autoPtr<coordinateSystem> toCsys;
112 if (args.optionFound("from") || args.optionFound("to"))
114 autoPtr<IOobject> csDictIoPtr;
116 if (args.optionFound("dict"))
118 fileName dictPath(args.option("dict"));
126 ? dictPath/coordinateSystems::typeName
142 coordinateSystems::typeName,
153 if (!csDictIoPtr->headerOk())
155 FatalErrorIn(args.executable())
156 << "Cannot open coordinateSystems file\n "
157 << csDictIoPtr->objectPath() << nl
161 coordinateSystems csLst(csDictIoPtr());
163 if (args.optionFound("from"))
165 const word csName(args.option("from"));
167 label csId = csLst.find(csName);
170 FatalErrorIn(args.executable())
171 << "Cannot find -from " << csName << nl
172 << "available coordinateSystems: " << csLst.toc() << nl
176 fromCsys.reset(new coordinateSystem(csLst[csId]));
179 if (args.optionFound("to"))
181 const word csName(args.option("to"));
183 label csId = csLst.find(csName);
186 FatalErrorIn(args.executable())
187 << "Cannot find -to " << csName << nl
188 << "available coordinateSystems: " << csLst.toc() << nl
192 toCsys.reset(new coordinateSystem(csLst[csId]));
196 // maybe fix this later
197 if (fromCsys.valid() && toCsys.valid())
199 FatalErrorIn(args.executable())
200 << "Only allowed '-from' or '-to' option at the moment."
207 MeshedSurface<face> surf(importName);
209 if (args.optionFound("clean"))
215 if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
217 Info<< " -scaleIn " << scaleIn << endl;
218 surf.scalePoints(scaleIn);
222 if (fromCsys.valid())
224 Info<< " -from " << fromCsys().name() << endl;
225 tmp<pointField> tpf = fromCsys().localPosition(surf.points());
226 surf.movePoints(tpf());
231 Info<< " -to " << toCsys().name() << endl;
232 tmp<pointField> tpf = toCsys().globalPosition(surf.points());
233 surf.movePoints(tpf());
237 if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
239 Info<< " -scaleOut " << scaleOut << endl;
240 surf.scalePoints(scaleOut);
243 Info<< "writing " << exportName;
244 surf.write(exportName);
247 Info<< "\nEnd\n" << endl;
252 // ************************************************************************* //