00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #include <OpenFOAM/argList.H>
00073 #include <OpenFOAM/timeSelector.H>
00074 #include <OpenFOAM/Time.H>
00075 #include <OpenFOAM/polyMesh.H>
00076 #include <triSurface/triSurface.H>
00077 #include <surfMesh/surfMesh.H>
00078 #include <surfMesh/surfFields.H>
00079 #include <surfMesh/surfPointFields.H>
00080 #include <OpenFOAM/PackedBoolList.H>
00081
00082 #include <surfMesh/MeshedSurfaces.H>
00083 #include <surfMesh/UnsortedMeshedSurfaces.H>
00084
00085 using namespace Foam;
00086
00087
00088
00089
00090 int main(int argc, char *argv[])
00091 {
00092 argList::noParallel();
00093 argList::validArgs.append("inputFile");
00094 argList::validArgs.append("outputFile");
00095 argList::validOptions.insert("clean", "");
00096 argList::validOptions.insert("orient", "");
00097 argList::validOptions.insert("surfMesh", "");
00098 argList::validOptions.insert("scale", "scale");
00099 argList::validOptions.insert("triSurface", "");
00100 argList::validOptions.insert("unsorted", "");
00101 argList::validOptions.insert("triFace", "");
00102 # include <OpenFOAM/setRootCase.H>
00103 const stringList& params = args.additionalArgs();
00104
00105 scalar scaleFactor = 0;
00106 args.optionReadIfPresent("scale", scaleFactor);
00107
00108 fileName importName(params[0]);
00109 fileName exportName(params[1]);
00110
00111 if (importName == exportName)
00112 {
00113 FatalErrorIn(args.executable())
00114 << "Output file " << exportName << " would overwrite input file."
00115 << exit(FatalError);
00116 }
00117
00118 if
00119 (
00120 !MeshedSurface<face>::canRead(importName, true)
00121 || !MeshedSurface<face>::canWriteType(exportName.ext(), true)
00122 )
00123 {
00124 return 1;
00125 }
00126
00127 if (args.optionFound("triSurface"))
00128 {
00129 triSurface surf(importName);
00130
00131 Info<< "Read surface:" << endl;
00132 surf.writeStats(Info);
00133 Info<< endl;
00134
00135 if (args.optionFound("orient"))
00136 {
00137 Info<< "Checking surface orientation" << endl;
00138 PatchTools::checkOrientation(surf, true);
00139 Info<< endl;
00140 }
00141
00142 if (args.optionFound("clean"))
00143 {
00144 Info<< "Cleaning up surface" << endl;
00145 surf.cleanup(true);
00146 surf.writeStats(Info);
00147 Info<< endl;
00148 }
00149
00150 Info<< "writing " << exportName;
00151 if (scaleFactor <= 0)
00152 {
00153 Info<< " without scaling" << endl;
00154 }
00155 else
00156 {
00157 Info<< " with scaling " << scaleFactor << endl;
00158 surf.scalePoints(scaleFactor);
00159 surf.writeStats(Info);
00160 Info<< endl;
00161 }
00162
00163
00164 surf.write(exportName, true);
00165 }
00166 else if (args.optionFound("unsorted"))
00167 {
00168 UnsortedMeshedSurface<face> surf(importName);
00169
00170 Info<< "Read surface:" << endl;
00171 surf.writeStats(Info);
00172 Info<< endl;
00173
00174 if (args.optionFound("orient"))
00175 {
00176 Info<< "Checking surface orientation" << endl;
00177 PatchTools::checkOrientation(surf, true);
00178 Info<< endl;
00179 }
00180
00181 if (args.optionFound("clean"))
00182 {
00183 Info<< "Cleaning up surface" << endl;
00184 surf.cleanup(true);
00185 surf.writeStats(Info);
00186 Info<< endl;
00187 }
00188
00189 Info<< "writing " << exportName;
00190 if (scaleFactor <= 0)
00191 {
00192 Info<< " without scaling" << endl;
00193 }
00194 else
00195 {
00196 Info<< " with scaling " << scaleFactor << endl;
00197 surf.scalePoints(scaleFactor);
00198 surf.writeStats(Info);
00199 Info<< endl;
00200 }
00201 surf.write(exportName);
00202 }
00203 #if 1
00204 else if (args.optionFound("triFace"))
00205 {
00206 MeshedSurface<triFace> surf(importName);
00207
00208 Info<< "Read surface:" << endl;
00209 surf.writeStats(Info);
00210 Info<< endl;
00211
00212 if (args.optionFound("orient"))
00213 {
00214 Info<< "Checking surface orientation" << endl;
00215 PatchTools::checkOrientation(surf, true);
00216 Info<< endl;
00217 }
00218
00219 if (args.optionFound("clean"))
00220 {
00221 Info<< "Cleaning up surface" << endl;
00222 surf.cleanup(true);
00223 surf.writeStats(Info);
00224 Info<< endl;
00225 }
00226
00227 Info<< "writing " << exportName;
00228 if (scaleFactor <= 0)
00229 {
00230 Info<< " without scaling" << endl;
00231 }
00232 else
00233 {
00234 Info<< " with scaling " << scaleFactor << endl;
00235 surf.scalePoints(scaleFactor);
00236 surf.writeStats(Info);
00237 Info<< endl;
00238 }
00239 surf.write(exportName);
00240 }
00241 #endif
00242 else
00243 {
00244 MeshedSurface<face> surf(importName);
00245
00246 Info<< "Read surface:" << endl;
00247 surf.writeStats(Info);
00248 Info<< endl;
00249
00250 if (args.optionFound("orient"))
00251 {
00252 Info<< "Checking surface orientation" << endl;
00253 PatchTools::checkOrientation(surf, true);
00254 Info<< endl;
00255 }
00256
00257 if (args.optionFound("clean"))
00258 {
00259 Info<< "Cleaning up surface" << endl;
00260 surf.cleanup(true);
00261 surf.writeStats(Info);
00262 Info<< endl;
00263 }
00264
00265
00266 Info<< "writing " << exportName;
00267 if (scaleFactor <= 0)
00268 {
00269 Info<< " without scaling" << endl;
00270 }
00271 else
00272 {
00273 Info<< " with scaling " << scaleFactor << endl;
00274 surf.scalePoints(scaleFactor);
00275 surf.writeStats(Info);
00276 Info<< endl;
00277 }
00278 surf.write(exportName);
00279
00280 if (args.optionFound("surfMesh"))
00281 {
00282 Foam::Time runTime
00283 (
00284 args.rootPath(),
00285 args.caseName()
00286 );
00287
00288
00289 runTime.setTime(instant(0, runTime.constant()), 0);
00290
00291 Info<< "runTime.instance() = " << runTime.instance() << endl;
00292 Info<< "runTime.timeName() = " << runTime.timeName() << endl;
00293
00294
00295 Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
00296 << endl;
00297 surf.write
00298 (
00299 runTime,
00300 "yetAnother"
00301 );
00302
00303 surfMesh surfIn
00304 (
00305 IOobject
00306 (
00307 "default",
00308 runTime.timeName(),
00309 runTime,
00310 IOobject::MUST_READ,
00311 IOobject::NO_WRITE
00312 )
00313 );
00314
00315
00316 MeshedSurface<face> surfIn2(runTime, "foobar");
00317
00318 Info<<"surfIn2 = " << surfIn2.size() << endl;
00319
00320 Info<< "surfIn = " << surfIn.size() << endl;
00321
00322
00323 Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
00324 surfIn.write("oldSurfIn.obj");
00325
00326
00327 Info<< "runTime.instance() = " << runTime.instance() << endl;
00328
00329 surfMesh surfOut
00330 (
00331 IOobject
00332 (
00333 "mySurf",
00334 runTime.instance(),
00335 runTime,
00336 IOobject::NO_READ,
00337 IOobject::NO_WRITE,
00338 false
00339 ),
00340 surf.xfer()
00341 );
00342
00343 Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
00344 surfOut.write();
00345
00346 surfLabelField zoneIds
00347 (
00348 IOobject
00349 (
00350 "zoneIds",
00351 surfOut.instance(),
00352 surfOut,
00353 IOobject::NO_READ,
00354 IOobject::NO_WRITE
00355 ),
00356 surfOut,
00357 dimless
00358 );
00359
00360 Info<<" surf name= " << surfOut.name() <<nl;
00361 Info<< "rename to anotherSurf" << endl;
00362 surfOut.rename("anotherSurf");
00363
00364 Info<<" surf name= " << surfOut.name() <<nl;
00365
00366
00367 runTime.setTime(instant(1), 1);
00368 surfOut.setInstance(runTime.timeName());
00369
00370
00371
00372 Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
00373 surfOut.write();
00374
00375
00376 surfOut.write("someName.ofs");
00377
00378 #if 1
00379 const surfZoneList& zones = surfOut.surfZones();
00380 forAll(zones, zoneI)
00381 {
00382 SubList<label>
00383 (
00384 zoneIds,
00385 zones[zoneI].size(),
00386 zones[zoneI].start()
00387 ) = zoneI;
00388 }
00389
00390 Info<< "write zoneIds (for testing only): "
00391 << zoneIds.objectPath() << endl;
00392 zoneIds.write();
00393
00394 surfPointLabelField pointIds
00395 (
00396 IOobject
00397 (
00398 "zoneIds.",
00399
00400 surfOut.instance(),
00401
00402 surfOut,
00403 IOobject::NO_READ,
00404 IOobject::NO_WRITE
00405 ),
00406 surfOut,
00407 dimless
00408 );
00409
00410 forAll(pointIds, i)
00411 {
00412 pointIds[i] = i;
00413 }
00414
00415 Info<< "write pointIds (for testing only): "
00416 << pointIds.objectPath() << endl;
00417 pointIds.write();
00418
00419 Info<<"surfMesh with these names: " << surfOut.names() << endl;
00420
00421 #endif
00422 }
00423 }
00424
00425 Info<< "\nEnd\n" << endl;
00426
00427 return 0;
00428 }
00429
00430