/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | Copyright (C) 2016-2107 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "VTKsurfaceFormat.H" #include "vtkUnstructuredReader.H" #include "scalarIOField.H" #include "faceTraits.H" #include "OFstream.H" #include "foamVtkOutput.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // File-scope constant. // // TODO: make this run-time selectable (ASCII | BINARY) // - Legacy mode only static const Foam::vtk::formatType fmtType = Foam::vtk::formatType::LEGACY_ASCII; // Foam::vtk::formatType::LEGACY_BINARY; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template void Foam::fileFormats::VTKsurfaceFormat::writePolys ( vtk::formatter& format, const UList& faces ) { // connectivity count without additional storage (done internally) label nConnectivity = 0; for (const Face& f : faces) { nConnectivity += f.size(); } vtk::legacy::beginPolys ( format.os(), faces.size(), nConnectivity ); // legacy: size + connectivity together // [nPts, id1, id2, ..., nPts, id1, id2, ...] for (const Face& f : faces) { format.write(f.size()); // The size prefix vtk::writeList(format, f); } format.flush(); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::fileFormats::VTKsurfaceFormat::VTKsurfaceFormat ( const fileName& filename ) { read(filename); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template bool Foam::fileFormats::VTKsurfaceFormat::read ( const fileName& filename ) { this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction << "Cannot read file " << filename << exit(FatalError); } // Assume groups are not intermixed bool sorted = true; // Construct dummy time so we have something to create an objectRegistry // from Time dummyTime ( "dummyRoot", "dummyCase", "system", "constant", false // enableFunctionObjects ); // Make dummy object registry objectRegistry obr ( IOobject ( "dummy", dummyTime, IOobject::NO_READ, IOobject::NO_WRITE, false ) ); // Read all vtkUnstructuredReader reader(obr, is); const faceList& faces = reader.faces(); // Assume all faces in zone0 unless a region field is present labelList zones(faces.size(), 0); for (auto fieldName : { "region", "STLSolidLabeling" }) { const labelIOField* lptr = reader.cellData().lookupObjectPtr(fieldName); if (lptr) { label i = 0; for (const auto& region : *lptr) { zones[i++] = label(region); } break; } const scalarIOField* sptr = reader.cellData().lookupObjectPtr(fieldName); if (sptr) { label i = 0; for (const auto& region : *sptr) { zones[i++] = label(region); } break; } } // Create zone names const label nZones = max(zones)+1; wordList zoneNames(nZones); forAll(zoneNames, i) { zoneNames[i] = "zone" + Foam::name(i); } // Check if it needs triangulation label nTri = 0; if (faceTraits::isTri()) { for (const face& f : faces) { nTri += f.nTriangles(); } } if (nTri > faces.size()) { // We are here if the target surface needs triangles and // the source surface has non-triangles DynamicList dynFaces(nTri); DynamicList