mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: triSurface: unstructured ascii vtk reading
This commit is contained in:
@ -28,10 +28,10 @@ OSspecific/${WM_OSTYPE:-POSIX}/Allwmake
|
||||
wmake $makeType OpenFOAM
|
||||
|
||||
wmake $makeType fileFormats
|
||||
wmake $makeType surfMesh
|
||||
wmake $makeType triSurface
|
||||
wmake $makeType meshTools
|
||||
wmake $makeType edgeMesh
|
||||
wmake $makeType surfMesh
|
||||
|
||||
# Decomposition methods needed by dummyThirdParty
|
||||
parallel/decompose/AllwmakeLnInclude
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -63,6 +63,42 @@ PrimitivePatch
|
||||
{}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
class Face,
|
||||
template<class> class FaceList,
|
||||
class PointField,
|
||||
class PointType
|
||||
>
|
||||
Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
|
||||
PrimitivePatch
|
||||
(
|
||||
const Xfer<FaceList<Face> >& faces,
|
||||
const Xfer<List<PointType> >& points
|
||||
)
|
||||
:
|
||||
FaceList<Face>(faces),
|
||||
points_(points),
|
||||
edgesPtr_(NULL),
|
||||
nInternalEdges_(-1),
|
||||
boundaryPointsPtr_(NULL),
|
||||
faceFacesPtr_(NULL),
|
||||
edgeFacesPtr_(NULL),
|
||||
faceEdgesPtr_(NULL),
|
||||
pointEdgesPtr_(NULL),
|
||||
pointFacesPtr_(NULL),
|
||||
localFacesPtr_(NULL),
|
||||
meshPointsPtr_(NULL),
|
||||
meshPointMapPtr_(NULL),
|
||||
edgeLoopsPtr_(NULL),
|
||||
localPointsPtr_(NULL),
|
||||
localPointOrderPtr_(NULL),
|
||||
faceCentresPtr_(NULL),
|
||||
faceNormalsPtr_(NULL),
|
||||
pointNormalsPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
class Face,
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -243,6 +243,13 @@ public:
|
||||
const Field<PointType>& points
|
||||
);
|
||||
|
||||
//- Construct from components
|
||||
PrimitivePatch
|
||||
(
|
||||
const Xfer<FaceList<Face> >& faces,
|
||||
const Xfer<List<PointType> >& points
|
||||
);
|
||||
|
||||
//- Construct from components, reuse storage
|
||||
PrimitivePatch
|
||||
(
|
||||
|
||||
@ -125,8 +125,11 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
|
||||
|
||||
cells_.setSize(cellTypes.size());
|
||||
cellMap_.setSize(cellTypes.size(), -1);
|
||||
faces_.setSize(cellTypes.size());
|
||||
faceMap_.setSize(cellTypes.size(), -1);
|
||||
lines_.setSize(cellTypes.size());
|
||||
lineMap_.setSize(cellTypes.size(), -1);
|
||||
|
||||
label dataIndex = 0;
|
||||
label cellI = 0;
|
||||
@ -179,6 +182,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
) << "Expected size 2 for VTK_LINE but found "
|
||||
<< nRead << exit(FatalIOError);
|
||||
}
|
||||
lineMap_[lineI] = i;
|
||||
labelList& segment = lines_[lineI++];
|
||||
segment.setSize(2);
|
||||
segment[0] = cellVertData[dataIndex++];
|
||||
@ -190,6 +194,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
{
|
||||
//warnUnhandledType(inFile, cellTypes[i], warningGiven);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
lineMap_[lineI] = i;
|
||||
labelList& segment = lines_[lineI++];
|
||||
segment.setSize(nRead);
|
||||
forAll(segment, i)
|
||||
@ -201,6 +206,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
|
||||
case VTK_TRIANGLE:
|
||||
{
|
||||
faceMap_[faceI] = i;
|
||||
face& f = faces_[faceI++];
|
||||
f.setSize(3);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
@ -221,6 +227,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
|
||||
case VTK_QUAD:
|
||||
{
|
||||
faceMap_[faceI] = i;
|
||||
face& f = faces_[faceI++];
|
||||
f.setSize(4);
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
@ -242,6 +249,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
|
||||
case VTK_POLYGON:
|
||||
{
|
||||
faceMap_[faceI] = i;
|
||||
face& f = faces_[faceI++];
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
f.setSize(nRead);
|
||||
@ -268,6 +276,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
tetPoints[1] = cellVertData[dataIndex++];
|
||||
tetPoints[2] = cellVertData[dataIndex++];
|
||||
tetPoints[3] = cellVertData[dataIndex++];
|
||||
cellMap_[cellI] = i;
|
||||
cells_[cellI++] = cellShape(tet, tetPoints, true);
|
||||
}
|
||||
break;
|
||||
@ -289,6 +298,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
pyrPoints[2] = cellVertData[dataIndex++];
|
||||
pyrPoints[3] = cellVertData[dataIndex++];
|
||||
pyrPoints[4] = cellVertData[dataIndex++];
|
||||
cellMap_[cellI] = i;
|
||||
cells_[cellI++] = cellShape(pyr, pyrPoints, true);
|
||||
}
|
||||
break;
|
||||
@ -311,6 +321,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
prismPoints[3] = cellVertData[dataIndex++];
|
||||
prismPoints[4] = cellVertData[dataIndex++];
|
||||
prismPoints[5] = cellVertData[dataIndex++];
|
||||
cellMap_[cellI] = i;
|
||||
cells_[cellI++] = cellShape(prism, prismPoints, true);
|
||||
}
|
||||
break;
|
||||
@ -335,6 +346,7 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
hexPoints[5] = cellVertData[dataIndex++];
|
||||
hexPoints[6] = cellVertData[dataIndex++];
|
||||
hexPoints[7] = cellVertData[dataIndex++];
|
||||
cellMap_[cellI] = i;
|
||||
cells_[cellI++] = cellShape(hex, hexPoints, true);
|
||||
}
|
||||
break;
|
||||
@ -351,8 +363,11 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
Info<< "Read " << cellI << " cells;" << faceI << " faces." << endl;
|
||||
}
|
||||
cells_.setSize(cellI);
|
||||
cellMap_.setSize(cellI);
|
||||
faces_.setSize(faceI);
|
||||
faceMap_.setSize(faceI);
|
||||
lines_.setSize(lineI);
|
||||
lineMap_.setSize(lineI);
|
||||
}
|
||||
|
||||
|
||||
@ -655,9 +670,11 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
|
||||
labelList lineVerts;
|
||||
readBlock(inFile, nNumbers, lineVerts);
|
||||
lines_.setSize(nLines);
|
||||
lineMap_.setSize(nLines);
|
||||
label elemI = 0;
|
||||
forAll(lines_, lineI)
|
||||
{
|
||||
lineMap_[lineI] = lineI;
|
||||
labelList& f = lines_[lineI];
|
||||
f.setSize(lineVerts[elemI++]);
|
||||
forAll(f, fp)
|
||||
@ -682,6 +699,7 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
|
||||
label elemI = 0;
|
||||
forAll(faces_, faceI)
|
||||
{
|
||||
faceMap_[faceI] = faceI;
|
||||
face& f = faces_[faceI];
|
||||
f.setSize(faceVerts[elemI++]);
|
||||
forAll(f, fp)
|
||||
|
||||
@ -25,7 +25,8 @@ Class
|
||||
Foam::vtkUnstructuredReader
|
||||
|
||||
Description
|
||||
Reader for vtk unstructured legacy files
|
||||
Reader for vtk unstructured legacy files. Supports single CELLS, POINTS
|
||||
etc. entry only.
|
||||
|
||||
SourceFiles
|
||||
vtkUnstructuredReader.C
|
||||
@ -45,9 +46,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class vtkUnstructuredReader Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -137,12 +135,20 @@ private:
|
||||
//- 3D cells.
|
||||
cellShapeList cells_;
|
||||
|
||||
//- Map from cells back to original ID
|
||||
labelList cellMap_;
|
||||
|
||||
//- 2D cells (=faces)
|
||||
faceList faces_;
|
||||
|
||||
//- Map from faces back to original ID
|
||||
labelList faceMap_;
|
||||
|
||||
//- 1D cells (=edges)
|
||||
labelListList lines_;
|
||||
|
||||
labelList lineMap_;
|
||||
|
||||
|
||||
// Data
|
||||
|
||||
@ -258,6 +264,11 @@ public:
|
||||
return cells_;
|
||||
}
|
||||
|
||||
const labelList& cellMap() const
|
||||
{
|
||||
return cellMap_;
|
||||
}
|
||||
|
||||
//- 2D cells (=faces)
|
||||
const faceList& faces() const
|
||||
{
|
||||
@ -269,6 +280,11 @@ public:
|
||||
return faces_;
|
||||
}
|
||||
|
||||
const labelList& faceMap() const
|
||||
{
|
||||
return faceMap_;
|
||||
}
|
||||
|
||||
//- 1D cells (=open lines)
|
||||
const labelListList& lines() const
|
||||
{
|
||||
@ -280,6 +296,11 @@ public:
|
||||
return lines_;
|
||||
}
|
||||
|
||||
const labelList& lineMap() const
|
||||
{
|
||||
return lineMap_;
|
||||
}
|
||||
|
||||
//- cell based fields
|
||||
const objectRegistry& cellData() const
|
||||
{
|
||||
|
||||
@ -25,6 +25,7 @@ $(interfaces)/TRI/readTRI.C
|
||||
$(interfaces)/DX/writeDX.C
|
||||
$(interfaces)/AC3D/readAC.C
|
||||
$(interfaces)/AC3D/writeAC.C
|
||||
$(interfaces)/VTK/readVTK.C
|
||||
$(interfaces)/VTK/writeVTK.C
|
||||
$(interfaces)/NAS/readNAS.C
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/fileFormats/lnInclude
|
||||
-I$(LIB_SRC)/fileFormats/lnInclude \
|
||||
-I$(LIB_SRC)/surfMesh/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lfileFormats
|
||||
-lfileFormats \
|
||||
-lsurfMesh
|
||||
|
||||
111
src/triSurface/triSurface/interfaces/VTK/readVTK.C
Normal file
111
src/triSurface/triSurface/interfaces/VTK/readVTK.C
Normal file
@ -0,0 +1,111 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
|
||||
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "triSurface.H"
|
||||
#include "VTKsurfaceFormat.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::triSurface::readVTK(const fileName& fName)
|
||||
{
|
||||
// Read (and triagulate) point, faces, zone info
|
||||
fileFormats::VTKsurfaceFormat<triFace> surf(fName);
|
||||
|
||||
List<labelledTri> tris(surf.faces().size());
|
||||
forAll(tris, i)
|
||||
{
|
||||
const triFace& f = surf[i];
|
||||
tris[i] = labelledTri(f[0], f[1], f[2], 0);
|
||||
}
|
||||
|
||||
// Add regions from zone
|
||||
const List<surfZone>& surfZones = surf.surfZones();
|
||||
|
||||
geometricSurfacePatchList patches;
|
||||
|
||||
if (surfZones.size())
|
||||
{
|
||||
patches.setSize(surfZones.size());
|
||||
forAll(surfZones, zoneI)
|
||||
{
|
||||
const surfZone& zone = surfZones[zoneI];
|
||||
|
||||
// Add patch. Convert synthetic 'zone' name into 'patch' for now.
|
||||
// (vtk format does not contain region names)
|
||||
word regionName = zone.name();
|
||||
if (regionName != (string("zone") + name(zoneI)))
|
||||
{
|
||||
regionName = string("patch") + name(zoneI);
|
||||
}
|
||||
|
||||
patches[zoneI] = geometricSurfacePatch
|
||||
(
|
||||
(
|
||||
zone.geometricType() != word::null
|
||||
? zone.geometricType()
|
||||
: "empty"
|
||||
),
|
||||
regionName,
|
||||
zoneI
|
||||
);
|
||||
|
||||
// Set triangle regions
|
||||
for (label i = zone.start(); i < zone.start()+zone.size(); i++)
|
||||
{
|
||||
tris[i].region() = zoneI;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add single patch
|
||||
patches[0] = geometricSurfacePatch("empty", "patch0", 0);
|
||||
|
||||
// Triangle regions already set to 0
|
||||
}
|
||||
|
||||
|
||||
// Create triSurface
|
||||
*this = triSurface
|
||||
(
|
||||
tris.xfer(),
|
||||
patches,
|
||||
xferCopy<List<point> >(surf.points())
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -412,6 +412,10 @@ bool Foam::triSurface::read
|
||||
{
|
||||
return readNAS(name);
|
||||
}
|
||||
else if (ext == "vtk")
|
||||
{
|
||||
return readVTK(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn
|
||||
@ -419,7 +423,7 @@ bool Foam::triSurface::read
|
||||
"triSurface::read(const fileName&, const word&)"
|
||||
) << "unknown file extension " << ext
|
||||
<< ". Supported extensions are '.ftr', '.stl', '.stlb', '.gts'"
|
||||
<< ", '.obj', '.ac', '.off', '.nas' and '.tri'"
|
||||
<< ", '.obj', '.ac', '.off', '.nas', '.tri' and '.vtk'"
|
||||
<< exit(FatalError);
|
||||
|
||||
return false;
|
||||
@ -639,6 +643,20 @@ Foam::triSurface::triSurface
|
||||
{}
|
||||
|
||||
|
||||
Foam::triSurface::triSurface
|
||||
(
|
||||
const Xfer<List<labelledTri> >& triangles,
|
||||
const geometricSurfacePatchList& patches,
|
||||
const Xfer<List<point> >& points
|
||||
)
|
||||
:
|
||||
ParentType(triangles, points),
|
||||
patches_(patches),
|
||||
sortedEdgeFacesPtr_(NULL),
|
||||
edgeOwnerPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Foam::triSurface::triSurface
|
||||
(
|
||||
const List<labelledTri>& triangles,
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -131,6 +131,7 @@ class triSurface
|
||||
bool readTRI(const fileName&);
|
||||
bool readAC(const fileName&);
|
||||
bool readNAS(const fileName&);
|
||||
bool readVTK(const fileName&);
|
||||
|
||||
//- Generic write routine. Chooses writer based on extension.
|
||||
void write(const fileName&, const word& ext, const bool sort) const;
|
||||
@ -258,6 +259,14 @@ public:
|
||||
const bool reUse
|
||||
);
|
||||
|
||||
//- Construct from triangles, patches, points.
|
||||
triSurface
|
||||
(
|
||||
const Xfer<List<labelledTri> >&,
|
||||
const geometricSurfacePatchList&,
|
||||
const Xfer<List<point> >&
|
||||
);
|
||||
|
||||
//- Construct from triangles, points. Set patchnames to default.
|
||||
triSurface(const List<labelledTri>&, const pointField&);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user