initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / surface / surfaceMeshExport / surfaceMeshExport.C
blobb6538d0bc17900e50a8cf57635b7078aecd04b3a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     surfaceMeshExport
28 Description
29     Export from surfMesh to various third-party surface formats with
30     optional scaling or transformations (rotate/translate) on a
31     coordinateSystem.
33 Usage
34     - surfaceMeshExport outputFile [OPTION]
36     @param -clean \n
37     Perform some surface checking/cleanup on the input surface.
39     @param -name \<name\> \n
40     Specify an alternative surface name when writing.
42     @param -scaleIn \<scale\> \n
43     Specify a scaling factor when reading files.
45     @param -scaleOut \<scale\> \n
46     Specify a scaling factor when writing files.
48     @param -dict \<dictionary\> \n
49     Specify an alternative dictionary for constant/coordinateSystems.
51     @param -from \<coordinateSystem\> \n
52     Specify a coordinate System when reading files.
54     @param -to \<coordinateSystem\> \n
55     Specify a coordinate System when writing files.
57 Note
58     The filename extensions are used to determine the file format type.
60 \*---------------------------------------------------------------------------*/
62 #include "argList.H"
63 #include "timeSelector.H"
64 #include "Time.H"
66 #include "MeshedSurfaces.H"
67 #include "coordinateSystems.H"
69 using namespace Foam;
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 //  Main program:
74 int main(int argc, char *argv[])
76     argList::noParallel();
77     argList::validArgs.append("outputFile");
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     argList args(argc, argv);
87     Time runTime(args.rootPath(), args.caseName());
88     const stringList& params = args.additionalArgs();
90     fileName exportName(params[0]);
91     word importName("default");
92     args.optionReadIfPresent("name", importName);
94     // check that writing is supported
95     if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
96     {
97         return 1;
98     }
101     // get the coordinate transformations
102     autoPtr<coordinateSystem> fromCsys;
103     autoPtr<coordinateSystem> toCsys;
105     if (args.optionFound("from") || args.optionFound("to"))
106     {
107         autoPtr<IOobject> ioPtr;
109         if (args.optionFound("dict"))
110         {
111             fileName dictPath(args.option("dict"));
113             ioPtr.set
114             (
115                 new IOobject
116                 (
117                     (
118                         isDir(dictPath)
119                       ? dictPath/coordinateSystems::typeName
120                       : dictPath
121                     ),
122                     runTime,
123                     IOobject::MUST_READ,
124                     IOobject::NO_WRITE,
125                     false
126                 )
127             );
128         }
129         else
130         {
131             ioPtr.set
132             (
133                 new IOobject
134                 (
135                     coordinateSystems::typeName,
136                     runTime.constant(),
137                     runTime,
138                     IOobject::MUST_READ,
139                     IOobject::NO_WRITE,
140                     false
141                 )
142             );
143         }
146         if (!ioPtr->headerOk())
147         {
148             FatalErrorIn(args.executable())
149                 << "Cannot open coordinateSystems file\n    "
150                 << ioPtr->objectPath() << nl
151                 << exit(FatalError);
152         }
154         coordinateSystems csLst(ioPtr());
156         if (args.optionFound("from"))
157         {
158             const word csName(args.option("from"));
160             label csId = csLst.find(csName);
161             if (csId < 0)
162             {
163                 FatalErrorIn(args.executable())
164                     << "Cannot find -from " << csName << nl
165                     << "available coordinateSystems: " << csLst.toc() << nl
166                     << exit(FatalError);
167             }
169             fromCsys.reset(new coordinateSystem(csLst[csId]));
170         }
172         if (args.optionFound("to"))
173         {
174             const word csName(args.option("to"));
176             label csId = csLst.find(csName);
177             if (csId < 0)
178             {
179                 FatalErrorIn(args.executable())
180                     << "Cannot find -to " << csName << nl
181                     << "available coordinateSystems: " << csLst.toc() << nl
182                     << exit(FatalError);
183             }
185             toCsys.reset(new coordinateSystem(csLst[csId]));
186         }
189         // maybe fix this later
190         if (fromCsys.valid() && toCsys.valid())
191         {
192             FatalErrorIn(args.executable())
193                 << "Only allowed  '-from' or '-to' option at the moment."
194                 << exit(FatalError);
195         }
196     }
199     surfMesh smesh
200     (
201         IOobject
202         (
203             importName,
204             runTime.constant(),
205             runTime,
206             IOobject::MUST_READ,
207             IOobject::NO_WRITE
208         )
209     );
211     Info<< "read surfMesh:\n  " << smesh.objectPath() << endl;
214     // Simply copy for now, but really should have a separate write method
216     MeshedSurface<face> surf(smesh);
218     if (args.optionFound("clean"))
219     {
220         surf.cleanup(true);
221     }
223     scalar scaleIn = 0;
224     if (args.optionReadIfPresent("scaleIn", scaleIn) && scaleIn > 0)
225     {
226         Info<< " -scaleIn " << scaleIn << endl;
227         surf.scalePoints(scaleIn);
228     }
230     if (fromCsys.valid())
231     {
232         Info<< " -from " << fromCsys().name() << endl;
233         tmp<pointField> tpf = fromCsys().localPosition(surf.points());
234         surf.movePoints(tpf());
235     }
237     if (toCsys.valid())
238     {
239         Info<< " -to " << toCsys().name() << endl;
240         tmp<pointField> tpf = toCsys().globalPosition(surf.points());
241         surf.movePoints(tpf());
242     }
244     scalar scaleOut = 0;
245     if (args.optionReadIfPresent("scaleOut", scaleOut) && scaleOut > 0)
246     {
247         Info<< " -scaleOut " << scaleOut << endl;
248         surf.scalePoints(scaleOut);
249     }
252     surf.writeStats(Info);
253     Info<< endl;
255     Info<< "writing " << exportName << endl;
256     surf.write(exportName);
258     Info<< "\nEnd\n" << endl;
260     return 0;
263 // ************************************************************************* //