sampling: use proxy surfaceWriter to generate obj, stl and other formats

This commit is contained in:
Mark Olesen
2009-03-17 14:13:03 +01:00
parent d3bc5c21b1
commit 681cd5fc30
11 changed files with 68 additions and 281 deletions

View File

@ -2,6 +2,7 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude -I$(LIB_SRC)/lagrangian/basic/lnInclude
@ -9,5 +10,6 @@ EXE_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-lmeshTools \ -lmeshTools \
-lsampling \ -lsampling \
-lsurfMesh \
-ltriSurface \ -ltriSurface \
-llagrangian -llagrangian

View File

@ -30,8 +30,10 @@ setFormat raw;
// dx : DX scalar or vector format // dx : DX scalar or vector format
// vtk : VTK ascii format // vtk : VTK ascii format
// raw : x y z value format for use with e.g. gnuplot 'splot'. // 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; surfaceFormat vtk;
// interpolationScheme. choice of // interpolationScheme. choice of

View File

@ -42,9 +42,8 @@ $(surfWriters)/surfaceWriters.C
$(surfWriters)/dx/dxSurfaceWriterRunTime.C $(surfWriters)/dx/dxSurfaceWriterRunTime.C
$(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C $(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C
$(surfWriters)/null/nullSurfaceWriterRunTime.C $(surfWriters)/null/nullSurfaceWriterRunTime.C
$(surfWriters)/proxy/proxySurfaceWriterRunTime.C
$(surfWriters)/raw/rawSurfaceWriterRunTime.C $(surfWriters)/raw/rawSurfaceWriterRunTime.C
$(surfWriters)/obj/objSurfaceWriterRunTime.C
$(surfWriters)/stl/stlSurfaceWriterRunTime.C
$(surfWriters)/vtk/vtkSurfaceWriterRunTime.C $(surfWriters)/vtk/vtkSurfaceWriterRunTime.C
graphField/writePatchGraph.C graphField/writePatchGraph.C

View File

@ -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<class Type>
Foam::objSurfaceWriter<Type>::objSurfaceWriter()
:
surfaceWriter<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::objSurfaceWriter<Type>::~objSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::objSurfaceWriter<Type>::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<face>
(
points,
faces
).write(fName);
}
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "stlSurfaceWriter.H" #include "proxySurfaceWriter.H"
#include "MeshedSurfaceProxy.H" #include "MeshedSurfaceProxy.H"
#include "OFstream.H" #include "OFstream.H"
@ -33,23 +33,24 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::stlSurfaceWriter<Type>::stlSurfaceWriter() Foam::proxySurfaceWriter<Type>::proxySurfaceWriter(const word& ext)
: :
surfaceWriter<Type>() surfaceWriter<Type>(),
ext_(ext)
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::stlSurfaceWriter<Type>::~stlSurfaceWriter() Foam::proxySurfaceWriter<Type>::~proxySurfaceWriter()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::stlSurfaceWriter<Type>::write void Foam::proxySurfaceWriter<Type>::write
( (
const fileName& outputDir, const fileName& outputDir,
const fileName& surfaceName, const fileName& surfaceName,
@ -58,12 +59,18 @@ void Foam::stlSurfaceWriter<Type>::write
const bool verbose const bool verbose
) const ) const
{ {
// avoid bad values
if (ext_.empty())
{
return;
}
if (!isDir(outputDir)) if (!isDir(outputDir))
{ {
mkDir(outputDir); mkDir(outputDir);
} }
fileName fName(outputDir/surfaceName + ".stl"); fileName fName(outputDir/surfaceName + "." + ext_);
if (verbose) if (verbose)
{ {

View File

@ -23,17 +23,17 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class Class
Foam::objSurfaceWriter Foam::proxySurfaceWriter
Description Description
SourceFiles SourceFiles
objSurfaceWriter.C proxySurfaceWriter.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef objSurfaceWriter_H #ifndef proxySurfaceWriter_H
#define objSurfaceWriter_H #define proxySurfaceWriter_H
#include "surfaceWriter.H" #include "surfaceWriter.H"
@ -43,30 +43,35 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class objSurfaceWriter Declaration Class proxySurfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type> template<class Type>
class objSurfaceWriter class proxySurfaceWriter
: :
public surfaceWriter<Type> public surfaceWriter<Type>
{ {
// Private data
//- The associated file extension
word ext_;
public: public:
//- Runtime type information //- Runtime type information
TypeName("obj"); TypeName("proxy");
// Constructors // Constructors
//- Construct null //- Construct for a given extension
objSurfaceWriter(); proxySurfaceWriter(const word& ext);
// Destructor // Destructor
virtual ~objSurfaceWriter(); virtual ~proxySurfaceWriter();
// Member Functions // Member Functions
@ -112,7 +117,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
# include "objSurfaceWriter.C" # include "proxySurfaceWriter.C"
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "stlSurfaceWriter.H" #include "proxySurfaceWriter.H"
#include "surfaceWriters.H" #include "surfaceWriters.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -35,7 +35,9 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(stlSurfaceWriter, bool); // create type names, but do not register with run-time tables
makeTypeSurfaceWritersTypeName(proxySurfaceWriter, bool);
makeSurfaceWritersTypeName(proxySurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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 Type>
class stlSurfaceWriter
:
public surfaceWriter<Type>
{
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<Type>& values,
const bool verbose = false
) const
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "stlSurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -25,6 +25,11 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "surfaceWriter.H" #include "surfaceWriter.H"
#include "MeshedSurfaceProxy.H"
#include "nullSurfaceWriter.H"
#include "proxySurfaceWriter.H"
#include "HashTable.H" #include "HashTable.H"
#include "word.H" #include "word.H"
@ -39,10 +44,8 @@ Foam::surfaceWriter<Type>::New(const word& writeType)
if (cstrIter == wordConstructorTablePtr_->end()) if (cstrIter == wordConstructorTablePtr_->end())
{ {
// unknown, check if it can handle 'bool' specialization // not supported for this data type, but it generally does work
// (ie, geometry write) // (it handles the 'bool' specialization - ie, geometry write)
// generally supported, but not for this data type
if if
( (
Foam::surfaceWriter<bool>::wordConstructorTablePtr_->found Foam::surfaceWriter<bool>::wordConstructorTablePtr_->found
@ -51,20 +54,32 @@ Foam::surfaceWriter<Type>::New(const word& writeType)
) )
) )
{ {
// use 'null' file instead // use 'null' handler instead
cstrIter = wordConstructorTablePtr_->find("null"); return autoPtr< surfaceWriter<Type> >
(
new nullSurfaceWriter<Type>()
);
}
else if (MeshedSurfaceProxy<face>::canWriteType(writeType))
{
// generally unknown, but can be written via MeshedSurfaceProxy
// use 'proxy' handler instead
return autoPtr< surfaceWriter<Type> >
(
new proxySurfaceWriter<Type>(writeType)
);
} }
if (cstrIter == wordConstructorTablePtr_->end()) if (cstrIter == wordConstructorTablePtr_->end())
{ {
FatalErrorIn FatalErrorIn
( (
"surfaceWriter::New(const word&)" "surfaceWriter::New(const word&)"
) << "Unknown write type " << writeType ) << "Unknown write type \"" << writeType << "\"\n\n"
<< endl << endl << "Valid write types : "
<< "Valid write types : " << endl << wordConstructorTablePtr_->toc() << nl
<< wordConstructorTablePtr_->toc() << "Valid proxy types : "
<< MeshedSurfaceProxy<face>::writeTypes() << endl
<< exit(FatalError); << exit(FatalError);
} }
} }

View File

@ -52,6 +52,8 @@ namespace Foam
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<class Type> class surfaceWriter; template<class Type> class surfaceWriter;
template<class Type> class nullSurfaceWriter;
template<class Type> class proxySurfaceWriter;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class surfaceWriter Declaration Class surfaceWriter Declaration