mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: additional methods for OBJstream
- write point fields - writeLine (takes two points) - writeFace (takes list of face loop points)
This commit is contained in:
@ -34,7 +34,7 @@ License
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(OBJstream, 0);
|
||||
defineTypeName(OBJstream);
|
||||
}
|
||||
|
||||
|
||||
@ -161,35 +161,45 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::write(const point& pt)
|
||||
Foam::Ostream& Foam::OBJstream::write(const point& p)
|
||||
{
|
||||
write("v ") << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
||||
write('v') << ' ' << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::write(const point& pt, const vector& n)
|
||||
Foam::Ostream& Foam::OBJstream::write(const point& p, const vector& n)
|
||||
{
|
||||
write(pt);
|
||||
write(p);
|
||||
OFstream::write("vn ") << n.x() << ' ' << n.y() << ' ' << n.z() << nl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::write(const UList<point>& points)
|
||||
{
|
||||
for (const point& p : points)
|
||||
{
|
||||
write('v') << ' ' << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::write(const edge& e, const UList<point>& points)
|
||||
{
|
||||
write(points[e[0]]);
|
||||
write(points[e[1]]);
|
||||
write("l ") << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
write(points[e.first()]);
|
||||
write(points[e.second()]);
|
||||
write('l') << ' ' << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::write(const linePointRef& ln)
|
||||
{
|
||||
write(ln.start());
|
||||
write(ln.end());
|
||||
write("l ") << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
write(ln.first());
|
||||
write(ln.second());
|
||||
write('l') << ' ' << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -201,9 +211,22 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
const vector& n1
|
||||
)
|
||||
{
|
||||
write(ln.start(), n0);
|
||||
write(ln.end(), n1);
|
||||
write("l ") << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
write(ln.first(), n0);
|
||||
write(ln.second(), n1);
|
||||
write('l') << ' ' << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::writeLine
|
||||
(
|
||||
const point& p0,
|
||||
const point& p1
|
||||
)
|
||||
{
|
||||
write(p0);
|
||||
write(p1);
|
||||
write('l') << ' ' << nVertices_-1 << ' ' << nVertices_ << nl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -221,7 +244,7 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
if (lines)
|
||||
{
|
||||
write('l');
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
write(' ') << i+start;
|
||||
}
|
||||
@ -230,7 +253,39 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
else
|
||||
{
|
||||
write('f');
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
write(' ') << i+start;
|
||||
}
|
||||
write('\n');
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::OBJstream::writeFace
|
||||
(
|
||||
const UList<point>& points,
|
||||
const bool lines
|
||||
)
|
||||
{
|
||||
const label start = nVertices_+1; // 1-offset for obj included here
|
||||
|
||||
write(points);
|
||||
|
||||
if (lines)
|
||||
{
|
||||
write('l');
|
||||
forAll(points, i)
|
||||
{
|
||||
write(' ') << i+start;
|
||||
}
|
||||
write(' ') << start << '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
write('f');
|
||||
forAll(points, i)
|
||||
{
|
||||
write(' ') << i+start;
|
||||
}
|
||||
@ -248,9 +303,10 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
)
|
||||
{
|
||||
const label start = nVertices_+1; // 1-offset for obj included here
|
||||
forAll(f, i)
|
||||
|
||||
for (const label fp : f)
|
||||
{
|
||||
write(points[f[i]]);
|
||||
write(points[fp]);
|
||||
}
|
||||
if (lines)
|
||||
{
|
||||
@ -283,35 +339,27 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
{
|
||||
primitivePatch pp(SubList<face>(faces), points);
|
||||
|
||||
const pointField& localPoints = pp.localPoints();
|
||||
const faceList& localFaces = pp.localFaces();
|
||||
|
||||
const label start = nVertices_+1; // 1-offset for obj included here
|
||||
|
||||
forAll(localPoints, i)
|
||||
{
|
||||
write(localPoints[i]);
|
||||
}
|
||||
write(pp.localPoints());
|
||||
|
||||
if (lines)
|
||||
{
|
||||
const edgeList& edges = pp.edges();
|
||||
forAll(edges, edgeI)
|
||||
for (const edge& e : pp.edges())
|
||||
{
|
||||
const edge& e = edges[edgeI];
|
||||
|
||||
write("l ") << e[0]+start << ' ' << e[1]+start << nl;
|
||||
write('l') << ' '
|
||||
<< e.first()+start << ' '
|
||||
<< e.second()+start << nl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
forAll(localFaces, facei)
|
||||
for (const face& f : pp.localFaces())
|
||||
{
|
||||
const face& f = localFaces[facei];
|
||||
write('f');
|
||||
forAll(f, i)
|
||||
for (const label fp : f)
|
||||
{
|
||||
write(' ') << f[i]+start;
|
||||
write(' ') << fp+start;
|
||||
}
|
||||
write('\n');
|
||||
}
|
||||
@ -335,46 +383,39 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
label objPointId = nVertices_+1; // 1-offset for obj included here
|
||||
|
||||
Map<label> markedPoints(2*edges.size());
|
||||
forAll(edges, edgei)
|
||||
{
|
||||
const edge& e = edges[edgei];
|
||||
|
||||
if (markedPoints.insert(e[0], objPointId))
|
||||
for (const edge& e : edges)
|
||||
{
|
||||
if (markedPoints.insert(e.first(), objPointId))
|
||||
{
|
||||
write(points[e[0]]);
|
||||
write(points[e.first()]);
|
||||
++objPointId;
|
||||
}
|
||||
if (markedPoints.insert(e[1], objPointId))
|
||||
if (markedPoints.insert(e.second(), objPointId))
|
||||
{
|
||||
write(points[e[1]]);
|
||||
write(points[e.second()]);
|
||||
++objPointId;
|
||||
}
|
||||
}
|
||||
|
||||
forAll(edges, edgei)
|
||||
for (const edge& e : edges)
|
||||
{
|
||||
const edge& e = edges[edgei];
|
||||
|
||||
write("l ")
|
||||
<< markedPoints[e[0]] << ' '
|
||||
<< markedPoints[e[1]] << nl;
|
||||
write('l') << ' '
|
||||
<< markedPoints[e.first()] << ' '
|
||||
<< markedPoints[e.second()] << nl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const label start = nVertices_+1; // 1-offset for obj included here
|
||||
|
||||
forAll(points, i)
|
||||
{
|
||||
write(points[i]);
|
||||
}
|
||||
write(points);
|
||||
|
||||
forAll(edges, edgei)
|
||||
for (const edge& e : edges)
|
||||
{
|
||||
const edge& e = edges[edgei];
|
||||
|
||||
write("l ")
|
||||
<< e[0]+start << ' ' << e[1]+start << nl;
|
||||
write('l') << ' '
|
||||
<< e.first()+start << ' '
|
||||
<< e.second()+start << nl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,31 +431,25 @@ Foam::Ostream& Foam::OBJstream::write
|
||||
{
|
||||
const label start = nVertices_+1; // 1-offset for obj included here
|
||||
|
||||
pointField points(bb.points());
|
||||
forAll(points, i)
|
||||
{
|
||||
write(points[i]);
|
||||
}
|
||||
write(bb.points());
|
||||
|
||||
if (lines)
|
||||
{
|
||||
forAll(treeBoundBox::edges, edgei)
|
||||
for (const edge& e : treeBoundBox::edges)
|
||||
{
|
||||
const edge& e = treeBoundBox::edges[edgei];
|
||||
|
||||
write("l ") << e[0]+start << ' ' << e[1]+start << nl;
|
||||
write('l') << ' '
|
||||
<< e.first()+start << ' '
|
||||
<< e.second()+start << nl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
forAll(treeBoundBox::faces, facei)
|
||||
for (const face& f : treeBoundBox::faces)
|
||||
{
|
||||
const face& f = treeBoundBox::faces[facei];
|
||||
|
||||
write('f');
|
||||
forAll(f, i)
|
||||
for (const label fp : f)
|
||||
{
|
||||
write(' ') << f[i]+start;
|
||||
write(' ') << fp+start;
|
||||
}
|
||||
write('\n');
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2012-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,7 +28,8 @@ Class
|
||||
Foam::OBJstream
|
||||
|
||||
Description
|
||||
OFstream that keeps track of vertices
|
||||
An OFstream that keeps track of vertices and provides convenience
|
||||
output methods for OBJ files.
|
||||
|
||||
SourceFiles
|
||||
OBJstream.C
|
||||
@ -73,8 +74,8 @@ class OBJstream
|
||||
|
||||
public:
|
||||
|
||||
//- Declare type-name (with debug switch)
|
||||
ClassName("OBJstream");
|
||||
//- Declare type-name (no debug switch)
|
||||
ClassNameNoDebug("OBJstream");
|
||||
|
||||
|
||||
// Constructors
|
||||
@ -105,13 +106,11 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the number of vertices written
|
||||
label nVertices() const
|
||||
{
|
||||
return nVertices_;
|
||||
}
|
||||
//- Return the number of vertices written
|
||||
label nVertices() const noexcept
|
||||
{
|
||||
return nVertices_;
|
||||
}
|
||||
|
||||
|
||||
// Ostream implementation
|
||||
@ -143,12 +142,15 @@ public:
|
||||
// Direct write functionality
|
||||
|
||||
//- Write point
|
||||
Ostream& write(const point& pt);
|
||||
Ostream& write(const point& p);
|
||||
|
||||
//- Write point and vector normal ('vn')
|
||||
Ostream& write(const point& pt, const vector& n);
|
||||
Ostream& write(const point& p, const vector& n);
|
||||
|
||||
//- Write edge as points and line
|
||||
//- Write multiple points
|
||||
Ostream& write(const UList<point>& points);
|
||||
|
||||
//- Write edge as points with line
|
||||
Ostream& write(const edge& e, const UList<point>& points);
|
||||
|
||||
//- Write line
|
||||
@ -162,10 +164,20 @@ public:
|
||||
const vector& n1
|
||||
);
|
||||
|
||||
//- Write triangle as points and lines/filled-polygon
|
||||
//- Write line joining two points
|
||||
Ostream& writeLine(const point& p0, const point& p1);
|
||||
|
||||
//- Write triangle as points with lines/filled-polygon
|
||||
Ostream& write(const triPointRef& f, const bool lines = true);
|
||||
|
||||
//- Write face as points and lines/filled-polygon
|
||||
//- Write face loop points with lines/filled-polygon
|
||||
Ostream& writeFace
|
||||
(
|
||||
const UList<point>& points,
|
||||
const bool lines = true
|
||||
);
|
||||
|
||||
//- Write face as points with lines/filled-polygon
|
||||
Ostream& write
|
||||
(
|
||||
const face& f,
|
||||
@ -173,7 +185,7 @@ public:
|
||||
const bool lines = true
|
||||
);
|
||||
|
||||
//- Write patch faces as points and lines/filled-polygon
|
||||
//- Write patch faces as points with lines/filled-polygon
|
||||
Ostream& write
|
||||
(
|
||||
const UList<face>& faces,
|
||||
@ -181,7 +193,7 @@ public:
|
||||
const bool lines = true
|
||||
);
|
||||
|
||||
//- Write edges as points and lines.
|
||||
//- Write edges as points with lines.
|
||||
// Optionally eliminate unused points.
|
||||
Ostream& write
|
||||
(
|
||||
@ -190,12 +202,8 @@ public:
|
||||
const bool compact = false
|
||||
);
|
||||
|
||||
//- Write tree-bounding box as lines/filled-polygons
|
||||
Ostream& write
|
||||
(
|
||||
const treeBoundBox& bb,
|
||||
const bool lines = true
|
||||
);
|
||||
//- Write tree-bounding box with lines/filled-polygons
|
||||
Ostream& write(const treeBoundBox& bb, const bool lines = true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user