Commit 36613fa5 authored by Mark Olesen's avatar Mark Olesen
Browse files

surfMesh: wrl(vrml97) and x3d output added

parent 681cd5fc
......@@ -40,6 +40,10 @@ $(surfaceFormats)/tri/TRIsurfaceFormatCore.C
$(surfaceFormats)/tri/TRIsurfaceFormatRunTime.C
$(surfaceFormats)/vtk/VTKsurfaceFormatCore.C
$(surfaceFormats)/vtk/VTKsurfaceFormatRunTime.C
$(surfaceFormats)/wrl/WRLsurfaceFormatCore.C
$(surfaceFormats)/wrl/WRLsurfaceFormatRunTime.C
$(surfaceFormats)/x3d/X3DsurfaceFormatCore.C
$(surfaceFormats)/x3d/X3DsurfaceFormatRunTime.C
LIB = $(FOAM_LIBBIN)/libsurfMesh
......@@ -26,7 +26,7 @@ Class
Foam::fileFormats::STARCDsurfaceFormatCore
Description
Internal class used by the OBJsurfaceFormat
Internal class used by the STARCDsurfaceFormat
SourceFiles
STARCDsurfaceFormatCore.C
......
......@@ -412,7 +412,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
const List<label>& zoneIds = surf.zoneIds();
unsigned int nTris = 0;
if (surf.isTri())
if (MeshedSurface<Face>::isTri())
{
nTris = faceLst.size();
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "WRLsurfaceFormat.H"
#include "Ostream.H"
#include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::WRLsurfaceFormat<Face>::WRLsurfaceFormat()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
void Foam::fileFormats::WRLsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
// for no zones, suppress the group name
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst, "")
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::WRLsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os, pointLst, faceLst.size(), zones);
os << "\n"
"Group {\n"
" children [\n"
" Shape {\n";
writeAppearance(os);
os <<
" geometry IndexedFaceSet {\n"
" coord Coordinate {\n"
" point [\n";
// Write vertex coords
forAll(pointLst, ptI)
{
const point& pt = pointLst[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os <<
" ]\n" // end point
" }\n" // end coord Coordinate
" coordIndex [\n";
label faceIndex = 0;
forAll(zones, zoneI)
{
const surfZone& zone = zones[zoneI];
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
forAll(f, fp)
{
os << f[fp] << ' ';
}
os << "-1,\n";
}
}
else
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << " -1,\n";
}
}
}
os <<
" ]\n" // end coordIndex
" }\n" // end geometry IndexedFaceSet
" }\n" // end Shape
" ]\n" // end children
"}\n"; // end Group
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fileFormats::WRLsurfaceFormat
Description
Provide a means of writing VRML97 (wrl) format.
SourceFiles
WRLsurfaceFormat.C
\*---------------------------------------------------------------------------*/
#ifndef WRLsurfaceFormat_H
#define WRLsurfaceFormat_H
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "WRLsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class WRLsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/
template<class Face>
class WRLsurfaceFormat
:
public MeshedSurface<Face>,
public WRLsurfaceFormatCore
{
// Private Member Functions
//- Disallow default bitwise copy construct
WRLsurfaceFormat(const WRLsurfaceFormat<Face>&);
//- Disallow default bitwise assignment
void operator=(const WRLsurfaceFormat<Face>&);
public:
// Constructors
//- Construct null
WRLsurfaceFormat();
// Selectors
// Destructor
virtual ~WRLsurfaceFormat()
{}
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write object file
virtual void write(const fileName& name) const
{
write(name, MeshedSurfaceProxy<Face>(*this));
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "WRLsurfaceFormat.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "WRLsurfaceFormatCore.H"
#include "clock.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileFormats::WRLsurfaceFormatCore::writeHeader
(
Ostream& os,
const pointField& pointLst,
const label nFaces,
const UList<surfZone>& zoneLst
)
{
os << "#VRML V2.0 utf8" << nl
<< nl
<< "# written " << clock::dateTime().c_str() << nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << nFaces << nl
<< "# zones : " << zoneLst.size() << nl;
// Print zone names as comment
forAll(zoneLst, zoneI)
{
os << "# " << zoneI << " " << zoneLst[zoneI].name()
<< " (nFaces: " << zoneLst[zoneI].size() << ")" << nl;
}
}
void Foam::fileFormats::WRLsurfaceFormatCore::writeAppearance
(
Ostream& os
)
{
os <<
" appearance Appearance {\n"
" material Material {\n"
" diffuseColor 0.8 0.8 0.8\n"
" specularColor 1.0 1.0 1.0\n"
" shininess 0.5\n"
" transparency 0.0\n"
" }\n" // end material
" }\n"; // end appearance
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fileFormats::WRLsurfaceFormatCore
Description
Internal class used by the WRLsurfaceFormat
SourceFiles
WRLsurfaceFormatCore.C
\*---------------------------------------------------------------------------*/
#ifndef WRLsurfaceFormatCore_H
#define WRLsurfaceFormatCore_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class WRLsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/
class WRLsurfaceFormatCore
{
protected:
// Protected Member Functions
//- Write file header
static void writeHeader
(
Ostream&,
const pointField&,
const label nFaces,
const UList<surfZone>&
);
//- Write appearance node
static void writeAppearance(Ostream&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "WRLsurfaceFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
WRLsurfaceFormat,
face,
write,
fileExtension,
wrl
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
WRLsurfaceFormat,
triFace,
write,
fileExtension,
wrl
);
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "X3DsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::X3DsurfaceFormat<Face>::X3DsurfaceFormat()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
void Foam::fileFormats::X3DsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
// for no zones, suppress the group name
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst, "")
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::X3DsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os);
os << "\n"
"<Group>\n"
" <Shape>\n";
writeAppearance(os);
// NOTE: we could provide an optimized IndexedTriangleSet output for
// triangulated surfaces too
os <<
" <IndexedFaceSet coordIndex='\n";
label faceIndex = 0;
forAll(zones, zoneI)