mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: meshTools output for treeBoundBox, points.
ENH: OBJstream output for treeBoundBox
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -26,6 +26,7 @@ License
|
|||||||
#include "meshTools.H"
|
#include "meshTools.H"
|
||||||
#include "polyMesh.H"
|
#include "polyMesh.H"
|
||||||
#include "hexMatcher.H"
|
#include "hexMatcher.H"
|
||||||
|
#include "treeBoundBox.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -209,16 +210,31 @@ void Foam::meshTools::writeOBJ
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::meshTools::writeOBJ
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const UList<point>& pts
|
||||||
|
)
|
||||||
|
{
|
||||||
|
forAll(pts, i)
|
||||||
|
{
|
||||||
|
const point& pt = pts[i];
|
||||||
|
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::meshTools::writeOBJ
|
void Foam::meshTools::writeOBJ
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const triad& t,
|
const triad& t,
|
||||||
const point& pt
|
const point& origin
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
forAll(t, dirI)
|
forAll(t, dirI)
|
||||||
{
|
{
|
||||||
writeOBJ(os, pt, pt + t[dirI]);
|
writeOBJ(os, origin, origin + t[dirI]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,10 +247,9 @@ void Foam::meshTools::writeOBJ
|
|||||||
label& count
|
label& count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
|
os << "v " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl;
|
||||||
os << "v" << ' ' << p2.x() << ' ' << p2.y() << ' ' << p2.z() << endl;
|
os << "v " << p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl;
|
||||||
|
os << "l " << (count + 1) << " " << (count + 2) << endl;
|
||||||
os << "l" << " " << (count + 1) << " " << (count + 2) << endl;
|
|
||||||
|
|
||||||
count += 2;
|
count += 2;
|
||||||
}
|
}
|
||||||
@ -247,12 +262,28 @@ void Foam::meshTools::writeOBJ
|
|||||||
const point& p2
|
const point& p2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
|
os << "v " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl;
|
||||||
|
|
||||||
os << "vn "
|
os << "vn "
|
||||||
<< ' ' << p2.x() - p1.x()
|
<< (p2.x() - p1.x()) << ' '
|
||||||
<< ' ' << p2.y() - p1.y()
|
<< (p2.y() - p1.y()) << ' '
|
||||||
<< ' ' << p2.z() - p1.z() << endl;
|
<< (p2.z() - p1.z()) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::meshTools::writeOBJ
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const treeBoundBox& bb
|
||||||
|
)
|
||||||
|
{
|
||||||
|
writeOBJ(os, bb.points());
|
||||||
|
|
||||||
|
forAll(treeBoundBox::edges, edgei)
|
||||||
|
{
|
||||||
|
const edge& e = treeBoundBox::edges[edgei];
|
||||||
|
|
||||||
|
os << "l " << (e[0] + 1) << ' ' << (e[1] + 1) << nl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -261,7 +292,7 @@ void Foam::meshTools::writeOBJ
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const cellList& cells,
|
const cellList& cells,
|
||||||
const faceList& faces,
|
const faceList& faces,
|
||||||
const pointField& points,
|
const UList<point>& points,
|
||||||
const labelList& cellLabels
|
const labelList& cellLabels
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -342,7 +373,7 @@ Foam::label Foam::meshTools::findEdge
|
|||||||
{
|
{
|
||||||
forAll(candidates, i)
|
forAll(candidates, i)
|
||||||
{
|
{
|
||||||
label edgeI = candidates[i];
|
const label edgeI = candidates[i];
|
||||||
|
|
||||||
const edge& e = edges[edgeI];
|
const edge& e = edges[edgeI];
|
||||||
|
|
||||||
|
|||||||
@ -49,8 +49,9 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
class primitiveMesh;
|
|
||||||
class polyMesh;
|
class polyMesh;
|
||||||
|
class primitiveMesh;
|
||||||
|
class treeBoundBox;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Namespace meshTools Declaration
|
Namespace meshTools Declaration
|
||||||
@ -101,23 +102,30 @@ namespace meshTools
|
|||||||
|
|
||||||
// OBJ writing
|
// OBJ writing
|
||||||
|
|
||||||
//- Write obj representation of point
|
//- Write obj representation of a point
|
||||||
void writeOBJ
|
void writeOBJ
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const point& pt
|
const point& pt
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write obj representation of a triad. Requires the location of the
|
//- Write obj representation of points
|
||||||
|
void writeOBJ
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const UList<point>& pts
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write obj representation of a triad. Requires the origin of the
|
||||||
// triad to be supplied
|
// triad to be supplied
|
||||||
void writeOBJ
|
void writeOBJ
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const triad& t,
|
const triad& t,
|
||||||
const point& pt
|
const point& origin
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write obj representation of a line connecting two points
|
//- Write obj representation of a line connecting two points.
|
||||||
// Need to keep track of points that have been added. count starts at 0
|
// Need to keep track of points that have been added. count starts at 0
|
||||||
void writeOBJ
|
void writeOBJ
|
||||||
(
|
(
|
||||||
@ -135,13 +143,20 @@ namespace meshTools
|
|||||||
const point& p2
|
const point& p2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Write obj representation of tree-bounding box as a series of lines
|
||||||
|
void writeOBJ
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const treeBoundBox& bb
|
||||||
|
);
|
||||||
|
|
||||||
//- Write obj representation of faces subset
|
//- Write obj representation of faces subset
|
||||||
template<class FaceType>
|
template<class FaceType>
|
||||||
void writeOBJ
|
void writeOBJ
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const UList<FaceType>&,
|
const UList<FaceType>& faces,
|
||||||
const pointField&,
|
const UList<point>& points,
|
||||||
const labelList& faceLabels
|
const labelList& faceLabels
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -150,17 +165,17 @@ namespace meshTools
|
|||||||
void writeOBJ
|
void writeOBJ
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const UList<FaceType>&,
|
const UList<FaceType>& faces,
|
||||||
const pointField&
|
const UList<point>& points
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write obj representation of cell subset
|
//- Write obj representation of cell subset
|
||||||
void writeOBJ
|
void writeOBJ
|
||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const cellList&,
|
const cellList& cells,
|
||||||
const faceList&,
|
const faceList& faces,
|
||||||
const pointField&,
|
const UList<point>& points,
|
||||||
const labelList& cellLabels
|
const labelList& cellLabels
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -170,7 +185,7 @@ namespace meshTools
|
|||||||
//- Is edge used by cell
|
//- Is edge used by cell
|
||||||
bool edgeOnCell
|
bool edgeOnCell
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label edgeI
|
const label edgeI
|
||||||
);
|
);
|
||||||
@ -178,7 +193,7 @@ namespace meshTools
|
|||||||
//- Is edge used by face
|
//- Is edge used by face
|
||||||
bool edgeOnFace
|
bool edgeOnFace
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label facei,
|
const label facei,
|
||||||
const label edgeI
|
const label edgeI
|
||||||
);
|
);
|
||||||
@ -186,7 +201,7 @@ namespace meshTools
|
|||||||
//- Is face used by cell
|
//- Is face used by cell
|
||||||
bool faceOnCell
|
bool faceOnCell
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label facei
|
const label facei
|
||||||
);
|
);
|
||||||
@ -203,7 +218,7 @@ namespace meshTools
|
|||||||
//- Return edge between two mesh vertices. Returns -1 if no edge.
|
//- Return edge between two mesh vertices. Returns -1 if no edge.
|
||||||
label findEdge
|
label findEdge
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label v0,
|
const label v0,
|
||||||
const label v1
|
const label v1
|
||||||
);
|
);
|
||||||
@ -211,7 +226,7 @@ namespace meshTools
|
|||||||
//- Return edge shared by two faces. Throws error if no edge found.
|
//- Return edge shared by two faces. Throws error if no edge found.
|
||||||
label getSharedEdge
|
label getSharedEdge
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label f0,
|
const label f0,
|
||||||
const label f1
|
const label f1
|
||||||
);
|
);
|
||||||
@ -219,7 +234,7 @@ namespace meshTools
|
|||||||
//- Return face shared by two cells. Throws error if none found.
|
//- Return face shared by two cells. Throws error if none found.
|
||||||
label getSharedFace
|
label getSharedFace
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label cell0,
|
const label cell0,
|
||||||
const label cell1
|
const label cell1
|
||||||
);
|
);
|
||||||
@ -227,7 +242,7 @@ namespace meshTools
|
|||||||
//- Get faces on cell using edgeI. Throws error if no two found.
|
//- Get faces on cell using edgeI. Throws error if no two found.
|
||||||
void getEdgeFaces
|
void getEdgeFaces
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label edgeI,
|
const label edgeI,
|
||||||
label& face0,
|
label& face0,
|
||||||
@ -238,17 +253,17 @@ namespace meshTools
|
|||||||
// connected to vertex but not edgeI. Throws error if none found.
|
// connected to vertex but not edgeI. Throws error if none found.
|
||||||
label otherEdge
|
label otherEdge
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const labelList& edgeLabels,
|
const labelList& edgeLabels,
|
||||||
const label edgeI,
|
const label thisEdgeI,
|
||||||
const label vertI
|
const label thisVertI
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Return face on cell using edgeI but not facei. Throws error
|
//- Return face on cell using edgeI but not facei. Throws error
|
||||||
// if none found.
|
// if none found.
|
||||||
label otherFace
|
label otherFace
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label facei,
|
const label facei,
|
||||||
const label edgeI
|
const label edgeI
|
||||||
@ -258,7 +273,7 @@ namespace meshTools
|
|||||||
// if face not internal.
|
// if face not internal.
|
||||||
label otherCell
|
label otherCell
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label facei
|
const label facei
|
||||||
);
|
);
|
||||||
@ -267,7 +282,7 @@ namespace meshTools
|
|||||||
// of startVertI)
|
// of startVertI)
|
||||||
label walkFace
|
label walkFace
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label facei,
|
const label facei,
|
||||||
const label startEdgeI,
|
const label startEdgeI,
|
||||||
const label startVertI,
|
const label startVertI,
|
||||||
@ -309,19 +324,19 @@ namespace meshTools
|
|||||||
//- Given edge on hex find other 'parallel', non-connected edges.
|
//- Given edge on hex find other 'parallel', non-connected edges.
|
||||||
void getParallelEdges
|
void getParallelEdges
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label e0,
|
const label e0,
|
||||||
label&,
|
label& e1,
|
||||||
label&,
|
label& e2,
|
||||||
label&
|
label& e3
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Given edge on hex find all 'parallel' (i.e. non-connected)
|
//- Given edge on hex find all 'parallel' (i.e. non-connected)
|
||||||
// edges and average direction of them
|
// edges and average direction of them
|
||||||
vector edgeToCutDir
|
vector edgeToCutDir
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const label edgeI
|
const label edgeI
|
||||||
);
|
);
|
||||||
@ -330,7 +345,7 @@ namespace meshTools
|
|||||||
// return one of them.
|
// return one of them.
|
||||||
label cutDirToEdge
|
label cutDirToEdge
|
||||||
(
|
(
|
||||||
const primitiveMesh&,
|
const primitiveMesh& mesh,
|
||||||
const label celli,
|
const label celli,
|
||||||
const vector& cutDir
|
const vector& cutDir
|
||||||
);
|
);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ void Foam::meshTools::writeOBJ
|
|||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const UList<FaceType>& faces,
|
const UList<FaceType>& faces,
|
||||||
const pointField& points,
|
const UList<point>& points,
|
||||||
const labelList& faceLabels
|
const labelList& faceLabels
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -64,7 +64,7 @@ void Foam::meshTools::writeOBJ
|
|||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const UList<FaceType>& faces,
|
const UList<FaceType>& faces,
|
||||||
const pointField& points
|
const UList<point>& points
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
labelList allFaces(faces.size());
|
labelList allFaces(faces.size());
|
||||||
|
|||||||
@ -24,8 +24,8 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "OBJstream.H"
|
#include "OBJstream.H"
|
||||||
//#include "token.H"
|
|
||||||
#include "primitivePatch.H"
|
#include "primitivePatch.H"
|
||||||
|
#include "treeBoundBox.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -98,51 +98,13 @@ Foam::Ostream& Foam::OBJstream::write(const char* str)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OBJstream::write(const word& str)
|
Foam::Ostream& Foam::OBJstream::write(const word& str)
|
||||||
{
|
{
|
||||||
write(str.c_str());
|
return writeQuoted(str, false);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::OBJstream::write(const string& str)
|
Foam::Ostream& Foam::OBJstream::write(const string& str)
|
||||||
{
|
{
|
||||||
OFstream::write(token::BEGIN_STRING);
|
return writeQuoted(str, true);
|
||||||
|
|
||||||
int backslash = 0;
|
|
||||||
for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter)
|
|
||||||
{
|
|
||||||
char c = *iter;
|
|
||||||
|
|
||||||
if (c == '\\')
|
|
||||||
{
|
|
||||||
backslash++;
|
|
||||||
// suppress output until we know if other characters follow
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (c == token::NL)
|
|
||||||
{
|
|
||||||
lineNumber_++;
|
|
||||||
backslash++; // backslash escape for newline
|
|
||||||
}
|
|
||||||
else if (c == token::END_STRING)
|
|
||||||
{
|
|
||||||
backslash++; // backslash escape for quote
|
|
||||||
}
|
|
||||||
|
|
||||||
// output pending backslashes
|
|
||||||
while (backslash)
|
|
||||||
{
|
|
||||||
OFstream::write('\\');
|
|
||||||
backslash--;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeAndCheck(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// silently drop any trailing backslashes
|
|
||||||
// they would otherwise appear like an escaped end-quote
|
|
||||||
|
|
||||||
OFstream::write(token::END_STRING);
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -159,7 +121,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
|
|||||||
int backslash = 0;
|
int backslash = 0;
|
||||||
for
|
for
|
||||||
(
|
(
|
||||||
string::const_iterator iter = str.begin();
|
std::string::const_iterator iter = str.begin();
|
||||||
iter != str.end();
|
iter != str.end();
|
||||||
++iter
|
++iter
|
||||||
)
|
)
|
||||||
@ -199,7 +161,15 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// output unquoted string, only advance line number on newline
|
// output unquoted string, only advance line number on newline
|
||||||
write(str.c_str());
|
for
|
||||||
|
(
|
||||||
|
std::string::const_iterator iter = str.begin();
|
||||||
|
iter != str.end();
|
||||||
|
++iter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
writeAndCheck(*iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -208,8 +178,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OBJstream::write(const point& pt)
|
Foam::Ostream& Foam::OBJstream::write(const point& pt)
|
||||||
{
|
{
|
||||||
write("v ") << pt.x() << ' ' << pt.y() << ' ' << pt.z()
|
write("v ") << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
|
||||||
<< nl;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +186,7 @@ Foam::Ostream& Foam::OBJstream::write(const point& pt)
|
|||||||
Foam::Ostream& Foam::OBJstream::write(const point& pt, const vector& n)
|
Foam::Ostream& Foam::OBJstream::write(const point& pt, const vector& n)
|
||||||
{
|
{
|
||||||
write(pt);
|
write(pt);
|
||||||
OFstream::write("vn ") << n.x() << ' ' << n.y()
|
OFstream::write("vn ") << n.x() << ' ' << n.y() << ' ' << n.z() << nl;
|
||||||
<< ' ' << n.z() << nl;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +229,7 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
const bool lines
|
const bool lines
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label start = nVertices_;
|
const label start = nVertices_+1; // 1-offset for obj included here
|
||||||
write(f.a());
|
write(f.a());
|
||||||
write(f.b());
|
write(f.b());
|
||||||
write(f.c());
|
write(f.c());
|
||||||
@ -270,16 +238,16 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
write('l');
|
write('l');
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
write(' ') << start+1+i;
|
write(' ') << i+start;
|
||||||
}
|
}
|
||||||
write(' ') << start+1 << '\n';
|
write(' ') << start << '\n';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
write('f');
|
write('f');
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
write(' ') << start+1+i;
|
write(' ') << i+start;
|
||||||
}
|
}
|
||||||
write('\n');
|
write('\n');
|
||||||
}
|
}
|
||||||
@ -294,7 +262,7 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
const bool lines
|
const bool lines
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label start = nVertices_;
|
const label start = nVertices_+1; // 1-offset for obj included here
|
||||||
forAll(f, i)
|
forAll(f, i)
|
||||||
{
|
{
|
||||||
write(points[f[i]]);
|
write(points[f[i]]);
|
||||||
@ -304,16 +272,16 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
write('l');
|
write('l');
|
||||||
forAll(f, i)
|
forAll(f, i)
|
||||||
{
|
{
|
||||||
write(' ') << start+1+i;
|
write(' ') << i+start;
|
||||||
}
|
}
|
||||||
write(' ') << start+1 << '\n';
|
write(' ') << start << '\n';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
write('f');
|
write('f');
|
||||||
forAll(f, i)
|
forAll(f, i)
|
||||||
{
|
{
|
||||||
write(' ') << start+1+i;
|
write(' ') << i+start;
|
||||||
}
|
}
|
||||||
write('\n');
|
write('\n');
|
||||||
}
|
}
|
||||||
@ -323,19 +291,19 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OBJstream::write
|
Foam::Ostream& Foam::OBJstream::write
|
||||||
(
|
(
|
||||||
const faceList& fcs,
|
const UList<face>& faces,
|
||||||
const pointField& points,
|
const pointField& points,
|
||||||
const bool lines
|
const bool lines
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
SubList<face> allFcs(fcs, fcs.size());
|
SubList<face> allFcs(faces, faces.size());
|
||||||
|
|
||||||
primitivePatch pp(allFcs, points);
|
primitivePatch pp(allFcs, points);
|
||||||
|
|
||||||
const pointField& localPoints = pp.localPoints();
|
const pointField& localPoints = pp.localPoints();
|
||||||
const faceList& localFaces = pp.localFaces();
|
const faceList& localFaces = pp.localFaces();
|
||||||
|
|
||||||
label start = nVertices_;
|
const label start = nVertices_+1; // 1-offset for obj included here
|
||||||
|
|
||||||
forAll(localPoints, i)
|
forAll(localPoints, i)
|
||||||
{
|
{
|
||||||
@ -349,7 +317,7 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
{
|
{
|
||||||
const edge& e = edges[edgeI];
|
const edge& e = edges[edgeI];
|
||||||
|
|
||||||
write("l ") << start+e[0]+1 << ' ' << start+e[1]+1 << nl;
|
write("l ") << e[0]+start << ' ' << e[1]+start << nl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -360,7 +328,7 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
write('f');
|
write('f');
|
||||||
forAll(f, i)
|
forAll(f, i)
|
||||||
{
|
{
|
||||||
write(' ') << start+f[i]+1;
|
write(' ') << f[i]+start;
|
||||||
}
|
}
|
||||||
write('\n');
|
write('\n');
|
||||||
}
|
}
|
||||||
@ -369,4 +337,108 @@ Foam::Ostream& Foam::OBJstream::write
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Ostream& Foam::OBJstream::write
|
||||||
|
(
|
||||||
|
const UList<edge>& edges,
|
||||||
|
const UList<point>& points,
|
||||||
|
const bool compact
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (compact)
|
||||||
|
{
|
||||||
|
// Code similar to PrimitivePatch::calcMeshData()
|
||||||
|
// Unsorted version
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
write(points[e[0]]);
|
||||||
|
++objPointId;
|
||||||
|
}
|
||||||
|
if (markedPoints.insert(e[1], objPointId))
|
||||||
|
{
|
||||||
|
write(points[e[1]]);
|
||||||
|
++objPointId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forAll(edges, edgei)
|
||||||
|
{
|
||||||
|
const edge& e = edges[edgei];
|
||||||
|
|
||||||
|
write("l ")
|
||||||
|
<< markedPoints[e[0]] << ' '
|
||||||
|
<< markedPoints[e[1]] << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const label start = nVertices_+1; // 1-offset for obj included here
|
||||||
|
|
||||||
|
forAll(points, i)
|
||||||
|
{
|
||||||
|
write(points[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
forAll(edges, edgei)
|
||||||
|
{
|
||||||
|
const edge& e = edges[edgei];
|
||||||
|
|
||||||
|
write("l ")
|
||||||
|
<< e[0]+start << ' ' << e[1]+start << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Ostream& Foam::OBJstream::write
|
||||||
|
(
|
||||||
|
const treeBoundBox& bb,
|
||||||
|
const bool lines
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const label start = nVertices_+1; // 1-offset for obj included here
|
||||||
|
|
||||||
|
pointField points(bb.points());
|
||||||
|
forAll(points, i)
|
||||||
|
{
|
||||||
|
write(points[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines)
|
||||||
|
{
|
||||||
|
forAll(treeBoundBox::edges, edgei)
|
||||||
|
{
|
||||||
|
const edge& e = treeBoundBox::edges[edgei];
|
||||||
|
|
||||||
|
write("l ") << e[0]+start << ' ' << e[1]+start << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forAll(treeBoundBox::faces, facei)
|
||||||
|
{
|
||||||
|
const face& f = treeBoundBox::faces[facei];
|
||||||
|
|
||||||
|
write('f');
|
||||||
|
forAll(f, i)
|
||||||
|
{
|
||||||
|
write(' ') << f[i]+start;
|
||||||
|
}
|
||||||
|
write('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Class
|
|||||||
Foam::OBJstream
|
Foam::OBJstream
|
||||||
|
|
||||||
Description
|
Description
|
||||||
OFstream which keeps track of vertices
|
OFstream that keeps track of vertices
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
OBJstream.C
|
OBJstream.C
|
||||||
@ -47,6 +47,8 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class treeBoundBox;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class OBJstream Declaration
|
Class OBJstream Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -64,7 +66,7 @@ class OBJstream
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
void writeAndCheck(const char);
|
void writeAndCheck(const char c);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -105,21 +107,22 @@ public:
|
|||||||
using Ostream::write;
|
using Ostream::write;
|
||||||
|
|
||||||
//- Write character
|
//- Write character
|
||||||
virtual Ostream& write(const char);
|
virtual Ostream& write(const char c);
|
||||||
|
|
||||||
//- Write character string
|
//- Write character string
|
||||||
virtual Ostream& write(const char*);
|
virtual Ostream& write(const char* str);
|
||||||
|
|
||||||
//- Write word
|
//- Write word
|
||||||
virtual Ostream& write(const word&);
|
virtual Ostream& write(const word& str);
|
||||||
|
|
||||||
virtual Ostream& write(const string&);
|
//- Write string
|
||||||
|
virtual Ostream& write(const string& str);
|
||||||
|
|
||||||
//- Write std::string surrounded by quotes.
|
//- Write std::string surrounded by quotes.
|
||||||
// Optional write without quotes.
|
// Optional write without quotes.
|
||||||
virtual Ostream& writeQuoted
|
virtual Ostream& writeQuoted
|
||||||
(
|
(
|
||||||
const std::string&,
|
const std::string& str,
|
||||||
const bool quoted=true
|
const bool quoted=true
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -127,41 +130,57 @@ public:
|
|||||||
// Direct write functionality
|
// Direct write functionality
|
||||||
|
|
||||||
//- Write point
|
//- Write point
|
||||||
Ostream& write(const point&);
|
Ostream& write(const point& pt);
|
||||||
|
|
||||||
//- Write point and vector normal ('vn')
|
//- Write point and vector normal ('vn')
|
||||||
Ostream& write(const point&, const vector&);
|
Ostream& write(const point& pt, const vector& n);
|
||||||
|
|
||||||
//- Write edge as points with line
|
//- Write edge as points and line
|
||||||
Ostream& write(const edge&, const UList<point>&);
|
Ostream& write(const edge& e, const UList<point>& points);
|
||||||
|
|
||||||
//- Write line
|
//- Write line
|
||||||
Ostream& write(const linePointRef&);
|
Ostream& write(const linePointRef& ln);
|
||||||
|
|
||||||
//- Write line with points and vector normals ('vn')
|
//- Write line with points and vector normals ('vn')
|
||||||
Ostream& write
|
Ostream& write
|
||||||
(
|
(
|
||||||
const linePointRef&,
|
const linePointRef& ln,
|
||||||
const vector& n0,
|
const vector& n0,
|
||||||
const vector& n1
|
const vector& n1
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write triangle as points with lines or filled polygon
|
//- Write triangle as points and lines/filled-polygon
|
||||||
Ostream& write(const triPointRef&, const bool lines = true);
|
Ostream& write(const triPointRef& f, const bool lines = true);
|
||||||
|
|
||||||
//- Write face as points with lines or filled polygon
|
//- Write face as points and lines/filled-polygon
|
||||||
Ostream& write
|
Ostream& write
|
||||||
(
|
(
|
||||||
const face&,
|
const face& f,
|
||||||
const UList<point>&,
|
const UList<point>& points,
|
||||||
const bool lines = true
|
const bool lines = true
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write patch as points and faces with lines or filled polygons
|
//- Write patch faces as points and lines/filled-polygon
|
||||||
Ostream& write
|
Ostream& write
|
||||||
(
|
(
|
||||||
const faceList&,
|
const UList<face>& faces,
|
||||||
const pointField&,
|
const pointField& points,
|
||||||
|
const bool lines = true
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write edges as points and lines.
|
||||||
|
// Optionally eliminate unused points.
|
||||||
|
Ostream& write
|
||||||
|
(
|
||||||
|
const UList<edge>& edges,
|
||||||
|
const UList<point>& points,
|
||||||
|
const bool compact = false
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Write tree-bounding box as lines/filled-polygons
|
||||||
|
Ostream& write
|
||||||
|
(
|
||||||
|
const treeBoundBox& bb,
|
||||||
const bool lines = true
|
const bool lines = true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user