From a7195288321096a736fa2a7e770377957d70eb70 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 25 Jan 2017 11:58:55 +0100 Subject: [PATCH] ENH: use STL reader from surfMesh library for triSurface as well (issue #294) - initial step in reducing duplicate IO for triSurface. - write STL triangle using common core routines from fileFormats --- src/fileFormats/stl/STLCore.C | 4 +- src/fileFormats/stl/STLCore.H | 4 +- src/fileFormats/stl/STLReader.C | 27 +- src/fileFormats/stl/STLReader.H | 53 +- src/fileFormats/stl/STLReaderASCII.L | 13 +- src/fileFormats/stl/STLpoint.H | 10 +- src/fileFormats/stl/STLtriangle.H | 33 +- src/fileFormats/stl/STLtriangleI.H | 22 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 6 +- src/triSurface/Make/files | 2 - .../triSurface/interfaces/STL/readSTL.C | 84 +-- .../triSurface/interfaces/STL/readSTLASCII.L | 490 ------------------ .../triSurface/interfaces/STL/readSTLBINARY.C | 152 ------ .../triSurface/interfaces/STL/writeSTL.C | 105 ++-- src/triSurface/triSurface/triSurface.C | 4 +- src/triSurface/triSurface/triSurface.H | 6 +- 16 files changed, 203 insertions(+), 812 deletions(-) delete mode 100644 src/triSurface/triSurface/interfaces/STL/readSTLASCII.L delete mode 100644 src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C diff --git a/src/fileFormats/stl/STLCore.C b/src/fileFormats/stl/STLCore.C index a38d3a3cdf..9b7c0c2e1c 100644 --- a/src/fileFormats/stl/STLCore.C +++ b/src/fileFormats/stl/STLCore.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,7 +52,7 @@ bool Foam::fileFormats::STLCore::isBinaryName const STLFormat& format ) { - return (format == DETECT ? (filename.ext() == "stlb") : format == BINARY); + return (format == UNKNOWN ? (filename.ext() == "stlb") : format == BINARY); } diff --git a/src/fileFormats/stl/STLCore.H b/src/fileFormats/stl/STLCore.H index 548cfabde2..fede83b850 100644 --- a/src/fileFormats/stl/STLCore.H +++ b/src/fileFormats/stl/STLCore.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -61,7 +61,7 @@ public: { ASCII, //!< ASCII BINARY, //!< BINARY - DETECT //!< Detect based on (input) content or (output) extension + UNKNOWN //!< Detect based on (input) content or (output) extension }; diff --git a/src/fileFormats/stl/STLReader.C b/src/fileFormats/stl/STLReader.C index c507b02673..b7b91a0bb7 100644 --- a/src/fileFormats/stl/STLReader.C +++ b/src/fileFormats/stl/STLReader.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +37,7 @@ bool Foam::fileFormats::STLReader::readBINARY ) { sorted_ = true; + format_ = UNKNOWN; label nTris = 0; autoPtr streamPtr = readBinaryHeader(filename, nTris); @@ -123,6 +124,7 @@ bool Foam::fileFormats::STLReader::readBINARY names_.clear(); sizes_.transfer(dynSizes); + format_ = BINARY; return true; } @@ -133,7 +135,7 @@ bool Foam::fileFormats::STLReader::readFile const STLFormat& format ) { - if (format == DETECT ? detectBinaryHeader(filename) : format == BINARY) + if (format == UNKNOWN ? detectBinaryHeader(filename) : format == BINARY) { return readBINARY(filename); } @@ -155,10 +157,11 @@ Foam::fileFormats::STLReader::STLReader points_(), zoneIds_(), names_(), - sizes_() + sizes_(), + format_(STLCore::UNKNOWN) { // Auto-detect ASCII/BINARY format - readFile(filename, STLCore::DETECT); + readFile(filename, STLCore::UNKNOWN); } @@ -172,7 +175,8 @@ Foam::fileFormats::STLReader::STLReader points_(), zoneIds_(), names_(), - sizes_() + sizes_(), + format_(STLCore::UNKNOWN) { // Manually specified ASCII/BINARY format readFile(filename, format); @@ -185,4 +189,17 @@ Foam::fileFormats::STLReader::~STLReader() {} +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::fileFormats::STLReader::clear() +{ + sorted_ = true; + points_.clear(); + zoneIds_.clear(); + names_.clear(); + sizes_.clear(); + format_ = UNKNOWN; +} + + // ************************************************************************* // diff --git a/src/fileFormats/stl/STLReader.H b/src/fileFormats/stl/STLReader.H index db985181d0..9ed6838bc1 100644 --- a/src/fileFormats/stl/STLReader.H +++ b/src/fileFormats/stl/STLReader.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::fileFormats::STLReader Description - Internal class used by the STLsurfaceFormat + Internal class used by the STLsurfaceFormat and triSurface. SourceFiles STLReader.C @@ -72,17 +72,20 @@ class STLReader //- The solid count, in the order of their first appearance List