Commit 681cd5fc authored by Mark Olesen's avatar Mark Olesen
Browse files

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

parent d3bc5c21
......@@ -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
......@@ -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
......
......@@ -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
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //
......@@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "stlSurfaceWriter.H"
#include "proxySurfaceWriter.H"
#include "MeshedSurfaceProxy.H"
#include "OFstream.H"
......@@ -33,23 +33,24 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::stlSurfaceWriter<Type>::stlSurfaceWriter()
Foam::proxySurfaceWriter<Type>::proxySurfaceWriter(const word& ext)
:
surfaceWriter<Type>()
surfaceWriter<Type>(),
ext_(ext)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::stlSurfaceWriter<Type>::~stlSurfaceWriter()
Foam::proxySurfaceWriter<Type>::~proxySurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::stlSurfaceWriter<Type>::write
void Foam::proxySurfaceWriter<Type>::write
(
const fileName& outputDir,
const fileName& surfaceName,
......@@ -58,12 +59,18 @@ void Foam::stlSurfaceWriter<Type>::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)
{
......
......@@ -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 Type>
class objSurfaceWriter
class proxySurfaceWriter
:
public surfaceWriter<Type>
{
// 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
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -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);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //
......@@ -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<Type>::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<bool>::wordConstructorTablePtr_->found
......@@ -51,20 +54,32 @@ Foam::surfaceWriter<Type>::New(const word& writeType)
)
)
{
// use 'null' file instead
cstrIter = wordConstructorTablePtr_->find("null");
// use 'null' handler instead
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())
{
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<face>::writeTypes() << endl
<< exit(FatalError);
}
}
......
......@@ -52,6 +52,8 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class Type> class surfaceWriter;
template<class Type> class nullSurfaceWriter;
template<class Type> class proxySurfaceWriter;
/*---------------------------------------------------------------------------*\
Class surfaceWriter Declaration
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment