From 681cd5fc30e744d51ebb11b966b9cfe9b1b0123d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 17 Mar 2009 14:13:03 +0100 Subject: [PATCH] sampling: use proxy surfaceWriter to generate obj, stl and other formats --- .../sampling/sample/Make/options | 2 + .../postProcessing/sampling/sample/sampleDict | 6 +- src/sampling/Make/files | 3 +- .../writers/obj/objSurfaceWriter.C | 81 ------------ .../writers/obj/objSurfaceWriterRunTime.C | 44 ------- .../proxySurfaceWriter.C} | 19 ++- .../proxySurfaceWriter.H} | 27 ++-- .../proxySurfaceWriterRunTime.C} | 6 +- .../writers/stl/stlSurfaceWriter.H | 122 ------------------ .../sampledSurface/writers/surfaceWriter.C | 37 ++++-- .../sampledSurface/writers/surfaceWriter.H | 2 + 11 files changed, 68 insertions(+), 281 deletions(-) delete mode 100644 src/sampling/sampledSurface/writers/obj/objSurfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/obj/objSurfaceWriterRunTime.C rename src/sampling/sampledSurface/writers/{stl/stlSurfaceWriter.C => proxy/proxySurfaceWriter.C} (85%) rename src/sampling/sampledSurface/writers/{obj/objSurfaceWriter.H => proxy/proxySurfaceWriter.H} (86%) rename src/sampling/sampledSurface/writers/{stl/stlSurfaceWriterRunTime.C => proxy/proxySurfaceWriterRunTime.C} (89%) delete mode 100644 src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H diff --git a/applications/utilities/postProcessing/sampling/sample/Make/options b/applications/utilities/postProcessing/sampling/sample/Make/options index 04b22c08a4..ae583f3388 100644 --- a/applications/utilities/postProcessing/sampling/sample/Make/options +++ b/applications/utilities/postProcessing/sampling/sample/Make/options @@ -2,6 +2,7 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude @@ -9,5 +10,6 @@ EXE_LIBS = \ -lfiniteVolume \ -lmeshTools \ -lsampling \ + -lsurfMesh \ -ltriSurface \ -llagrangian diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index cf02cac67e..559eb28436 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -30,8 +30,10 @@ setFormat raw; // dx : DX scalar or vector format // vtk : VTK ascii format // raw : x y z value format for use with e.g. gnuplot 'splot'. -// obj : Wavefront obj. Does not contain values! -// stl : ascii stl. Does not contain values! +// +// Note: +// other formats such as obj, stl, etc can also be written (by proxy) +// but without any values! surfaceFormat vtk; // interpolationScheme. choice of diff --git a/src/sampling/Make/files b/src/sampling/Make/files index f8a18b8b1f..57306e542b 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -42,9 +42,8 @@ $(surfWriters)/surfaceWriters.C $(surfWriters)/dx/dxSurfaceWriterRunTime.C $(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C $(surfWriters)/null/nullSurfaceWriterRunTime.C +$(surfWriters)/proxy/proxySurfaceWriterRunTime.C $(surfWriters)/raw/rawSurfaceWriterRunTime.C -$(surfWriters)/obj/objSurfaceWriterRunTime.C -$(surfWriters)/stl/stlSurfaceWriterRunTime.C $(surfWriters)/vtk/vtkSurfaceWriterRunTime.C graphField/writePatchGraph.C diff --git a/src/sampling/sampledSurface/writers/obj/objSurfaceWriter.C b/src/sampling/sampledSurface/writers/obj/objSurfaceWriter.C deleted file mode 100644 index e01ea7ea81..0000000000 --- a/src/sampling/sampledSurface/writers/obj/objSurfaceWriter.C +++ /dev/null @@ -1,81 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -\*---------------------------------------------------------------------------*/ - -#include "objSurfaceWriter.H" - -#include "MeshedSurfaceProxy.H" -#include "OFstream.H" -#include "OSspecific.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::objSurfaceWriter::objSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::objSurfaceWriter::~objSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::objSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const bool verbose -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - fileName fName(outputDir/surfaceName + ".obj"); - - if (verbose) - { - Info<< "Writing geometry to " << fName << endl; - } - - MeshedSurfaceProxy - ( - points, - faces - ).write(fName); -} - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/obj/objSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/obj/objSurfaceWriterRunTime.C deleted file mode 100644 index 0225b1719e..0000000000 --- a/src/sampling/sampledSurface/writers/obj/objSurfaceWriterRunTime.C +++ /dev/null @@ -1,44 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -\*---------------------------------------------------------------------------*/ - -#include "objSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriterType(objSurfaceWriter, bool); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C similarity index 85% rename from src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C rename to src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C index 7248225f91..1dce1e4664 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ -#include "stlSurfaceWriter.H" +#include "proxySurfaceWriter.H" #include "MeshedSurfaceProxy.H" #include "OFstream.H" @@ -33,23 +33,24 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::stlSurfaceWriter::stlSurfaceWriter() +Foam::proxySurfaceWriter::proxySurfaceWriter(const word& ext) : - surfaceWriter() + surfaceWriter(), + ext_(ext) {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template -Foam::stlSurfaceWriter::~stlSurfaceWriter() +Foam::proxySurfaceWriter::~proxySurfaceWriter() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::stlSurfaceWriter::write +void Foam::proxySurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -58,12 +59,18 @@ void Foam::stlSurfaceWriter::write const bool verbose ) const { + // avoid bad values + if (ext_.empty()) + { + return; + } + if (!isDir(outputDir)) { mkDir(outputDir); } - fileName fName(outputDir/surfaceName + ".stl"); + fileName fName(outputDir/surfaceName + "." + ext_); if (verbose) { diff --git a/src/sampling/sampledSurface/writers/obj/objSurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H similarity index 86% rename from src/sampling/sampledSurface/writers/obj/objSurfaceWriter.H rename to src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index 4be055ddc9..ceeec731a7 100644 --- a/src/sampling/sampledSurface/writers/obj/objSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -23,17 +23,17 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::objSurfaceWriter + Foam::proxySurfaceWriter Description SourceFiles - objSurfaceWriter.C + proxySurfaceWriter.C \*---------------------------------------------------------------------------*/ -#ifndef objSurfaceWriter_H -#define objSurfaceWriter_H +#ifndef proxySurfaceWriter_H +#define proxySurfaceWriter_H #include "surfaceWriter.H" @@ -43,30 +43,35 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class objSurfaceWriter Declaration + Class proxySurfaceWriter Declaration \*---------------------------------------------------------------------------*/ template -class objSurfaceWriter +class proxySurfaceWriter : public surfaceWriter { + // Private data + + //- The associated file extension + word ext_; + public: //- Runtime type information - TypeName("obj"); + TypeName("proxy"); // Constructors - //- Construct null - objSurfaceWriter(); + //- Construct for a given extension + proxySurfaceWriter(const word& ext); // Destructor - virtual ~objSurfaceWriter(); + virtual ~proxySurfaceWriter(); // Member Functions @@ -112,7 +117,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "objSurfaceWriter.C" +# include "proxySurfaceWriter.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C similarity index 89% rename from src/sampling/sampledSurface/writers/stl/stlSurfaceWriterRunTime.C rename to src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C index f2be47bf2d..dd3a7ebff3 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriterRunTime.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ -#include "stlSurfaceWriter.H" +#include "proxySurfaceWriter.H" #include "surfaceWriters.H" #include "addToRunTimeSelectionTable.H" @@ -35,7 +35,9 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -makeSurfaceWriterType(stlSurfaceWriter, bool); +// create type names, but do not register with run-time tables +makeTypeSurfaceWritersTypeName(proxySurfaceWriter, bool); +makeSurfaceWritersTypeName(proxySurfaceWriter); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H b/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H deleted file mode 100644 index d5216f662d..0000000000 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.H +++ /dev/null @@ -1,122 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -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 2 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, write to the Free Software Foundation, - Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Class - Foam::stlSurfaceWriter - -Description - -SourceFiles - stlSurfaceWriter.C - -\*---------------------------------------------------------------------------*/ - -#ifndef stlSurfaceWriter_H -#define stlSurfaceWriter_H - -#include "surfaceWriter.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class stlSurfaceWriter Declaration -\*---------------------------------------------------------------------------*/ - -template -class stlSurfaceWriter -: - public surfaceWriter -{ - -public: - - //- Runtime type information - TypeName("stl"); - - - // Constructors - - //- Construct null - stlSurfaceWriter(); - - - // Destructor - - virtual ~stlSurfaceWriter(); - - - // Member Functions - - //- Always write separate geometry file - virtual bool separateFiles() - { - return true; - } - - // Write - - //- Write geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const bool verbose = false - ) const; - - //- Writes single surface to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const fileName& fieldName, - const Field& values, - const bool verbose = false - ) const - {} - -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository -# include "stlSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.C b/src/sampling/sampledSurface/writers/surfaceWriter.C index 532d0d0791..99e19b96dd 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.C +++ b/src/sampling/sampledSurface/writers/surfaceWriter.C @@ -25,6 +25,11 @@ License \*---------------------------------------------------------------------------*/ #include "surfaceWriter.H" + +#include "MeshedSurfaceProxy.H" +#include "nullSurfaceWriter.H" +#include "proxySurfaceWriter.H" + #include "HashTable.H" #include "word.H" @@ -39,10 +44,8 @@ Foam::surfaceWriter::New(const word& writeType) if (cstrIter == wordConstructorTablePtr_->end()) { - // unknown, check if it can handle 'bool' specialization - // (ie, geometry write) - - // generally supported, but not for this data type + // not supported for this data type, but it generally does work + // (it handles the 'bool' specialization - ie, geometry write) if ( Foam::surfaceWriter::wordConstructorTablePtr_->found @@ -51,20 +54,32 @@ Foam::surfaceWriter::New(const word& writeType) ) ) { - // use 'null' file instead - cstrIter = wordConstructorTablePtr_->find("null"); + // use 'null' handler instead + return autoPtr< surfaceWriter > + ( + new nullSurfaceWriter() + ); + } + else if (MeshedSurfaceProxy::canWriteType(writeType)) + { + // generally unknown, but can be written via MeshedSurfaceProxy + // use 'proxy' handler instead + return autoPtr< surfaceWriter > + ( + new proxySurfaceWriter(writeType) + ); } - if (cstrIter == wordConstructorTablePtr_->end()) { FatalErrorIn ( "surfaceWriter::New(const word&)" - ) << "Unknown write type " << writeType - << endl << endl - << "Valid write types : " << endl - << wordConstructorTablePtr_->toc() + ) << "Unknown write type \"" << writeType << "\"\n\n" + << "Valid write types : " + << wordConstructorTablePtr_->toc() << nl + << "Valid proxy types : " + << MeshedSurfaceProxy::writeTypes() << endl << exit(FatalError); } } diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index 1fc442d3d8..b645c522ef 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -52,6 +52,8 @@ namespace Foam // Forward declaration of friend functions and operators template class surfaceWriter; +template class nullSurfaceWriter; +template class proxySurfaceWriter; /*---------------------------------------------------------------------------*\ Class surfaceWriter Declaration