Commit b1be223a authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: meshTools output for treeBoundBox, points.

ENH: OBJstream output for treeBoundBox
parent 430d8e1c
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -26,6 +26,7 @@ License
#include "meshTools.H"
#include "polyMesh.H"
#include "hexMatcher.H"
#include "treeBoundBox.H"
// * * * * * * * * * * * * * * * 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
(
Ostream& os,
const triad& t,
const point& pt
const point& origin
)
{
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
)
{
os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
os << "v" << ' ' << p2.x() << ' ' << p2.y() << ' ' << p2.z() << endl;
os << "l" << " " << (count + 1) << " " << (count + 2) << endl;
os << "v " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl;
os << "v " << p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl;
os << "l " << (count + 1) << " " << (count + 2) << endl;
count += 2;
}
......@@ -247,12 +262,28 @@ void Foam::meshTools::writeOBJ
const point& p2
)
{
os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
os << "v " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl;
os << "vn "
<< (p2.x() - p1.x()) << ' '
<< (p2.y() - p1.y()) << ' '
<< (p2.z() - p1.z()) << endl;
}
void Foam::meshTools::writeOBJ
(
Ostream& os,
const treeBoundBox& bb
)
{
writeOBJ(os, bb.points());
os << "vn"
<< ' ' << p2.x() - p1.x()
<< ' ' << p2.y() - p1.y()
<< ' ' << p2.z() - p1.z() << endl;
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,
const cellList& cells,
const faceList& faces,
const pointField& points,
const UList<point>& points,
const labelList& cellLabels
)
{
......@@ -342,7 +373,7 @@ Foam::label Foam::meshTools::findEdge
{
forAll(candidates, i)
{
label edgeI = candidates[i];
const label edgeI = candidates[i];
const edge& e = edges[edgeI];
......
......@@ -49,8 +49,9 @@ SourceFiles
namespace Foam
{
class primitiveMesh;
class polyMesh;
class primitiveMesh;
class treeBoundBox;
/*---------------------------------------------------------------------------*\
Namespace meshTools Declaration
......@@ -101,23 +102,30 @@ namespace meshTools
// OBJ writing
//- Write obj representation of point
//- Write obj representation of a point
void writeOBJ
(
Ostream& os,
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
void writeOBJ
(
Ostream& os,
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
void writeOBJ
(
......@@ -135,13 +143,20 @@ namespace meshTools
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
template<class FaceType>
void writeOBJ
(
Ostream& os,
const UList<FaceType>&,
const pointField&,
const UList<FaceType>& faces,
const UList<point>& points,
const labelList& faceLabels
);
......@@ -150,17 +165,17 @@ namespace meshTools
void writeOBJ
(
Ostream& os,
const UList<FaceType>&,
const pointField&
const UList<FaceType>& faces,
const UList<point>& points
);
//- Write obj representation of cell subset
void writeOBJ
(
Ostream& os,
const cellList&,
const faceList&,
const pointField&,
const cellList& cells,
const faceList& faces,
const UList<point>& points,
const labelList& cellLabels
);
......@@ -170,7 +185,7 @@ namespace meshTools
//- Is edge used by cell
bool edgeOnCell
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label edgeI
);
......@@ -178,7 +193,7 @@ namespace meshTools
//- Is edge used by face
bool edgeOnFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label facei,
const label edgeI
);
......@@ -186,7 +201,7 @@ namespace meshTools
//- Is face used by cell
bool faceOnCell
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label facei
);
......@@ -203,7 +218,7 @@ namespace meshTools
//- Return edge between two mesh vertices. Returns -1 if no edge.
label findEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label v0,
const label v1
);
......@@ -211,7 +226,7 @@ namespace meshTools
//- Return edge shared by two faces. Throws error if no edge found.
label getSharedEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label f0,
const label f1
);
......@@ -219,7 +234,7 @@ namespace meshTools
//- Return face shared by two cells. Throws error if none found.
label getSharedFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label cell0,
const label cell1
);
......@@ -227,7 +242,7 @@ namespace meshTools
//- Get faces on cell using edgeI. Throws error if no two found.
void getEdgeFaces
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label edgeI,
label& face0,
......@@ -238,17 +253,17 @@ namespace meshTools
// connected to vertex but not edgeI. Throws error if none found.
label otherEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const labelList& edgeLabels,
const label edgeI,
const label vertI
const label thisEdgeI,
const label thisVertI
);
//- Return face on cell using edgeI but not facei. Throws error
// if none found.
label otherFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label facei,
const label edgeI
......@@ -258,7 +273,7 @@ namespace meshTools
// if face not internal.
label otherCell
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label facei
);
......@@ -267,7 +282,7 @@ namespace meshTools
// of startVertI)
label walkFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label facei,
const label startEdgeI,
const label startVertI,
......@@ -309,19 +324,19 @@ namespace meshTools
//- Given edge on hex find other 'parallel', non-connected edges.
void getParallelEdges
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label e0,
label&,
label&,
label&
label& e1,
label& e2,
label& e3
);
//- Given edge on hex find all 'parallel' (i.e. non-connected)
// edges and average direction of them
vector edgeToCutDir
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label edgeI
);
......@@ -330,7 +345,7 @@ namespace meshTools
// return one of them.
label cutDirToEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const vector& cutDir
);
......
......@@ -28,7 +28,7 @@ void Foam::meshTools::writeOBJ
(
Ostream& os,
const UList<FaceType>& faces,
const pointField& points,
const UList<point>& points,
const labelList& faceLabels
)
{
......@@ -64,7 +64,7 @@ void Foam::meshTools::writeOBJ
(
Ostream& os,
const UList<FaceType>& faces,
const pointField& points
const UList<point>& points
)
{
labelList allFaces(faces.size());
......
......@@ -24,8 +24,8 @@ License
\*---------------------------------------------------------------------------*/
#include "OBJstream.H"
//#include "token.H"
#include "primitivePatch.H"
#include "treeBoundBox.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -98,51 +98,13 @@ Foam::Ostream& Foam::OBJstream::write(const char* str)
Foam::Ostream& Foam::OBJstream::write(const word& str)
{
write(str.c_str());
return *this;
return writeQuoted(str, false);
}
Foam::Ostream& Foam::OBJstream::write(const string& str)
{
OFstream::write(token::BEGIN_STRING);
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;
return writeQuoted(str, true);
}
......@@ -159,7 +121,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
int backslash = 0;
for
(
string::const_iterator iter = str.begin();
std::string::const_iterator iter = str.begin();
iter != str.end();
++iter
)
......@@ -199,7 +161,15 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
else
{
// 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;
......@@ -208,8 +178,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
Foam::Ostream& Foam::OBJstream::write(const point& pt)
{
write("v ") << pt.x() << ' ' << pt.y() << ' ' << pt.z()
<< nl;
write("v ") << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
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)
{
write(pt);
OFstream::write("vn ") << n.x() << ' ' << n.y()
<< ' ' << n.z() << nl;
OFstream::write("vn ") << n.x() << ' ' << n.y() << ' ' << n.z() << nl;
return *this;
}
......@@ -261,7 +229,7 @@ Foam::Ostream& Foam::OBJstream::write
const bool lines
)
{
label start = nVertices_;
const label start = nVertices_+1; // 1-offset for obj included here
write(f.a());
write(f.b());
write(f.c());
......@@ -270,16 +238,16 @@ Foam::Ostream& Foam::OBJstream::write
write('l');
for (int i = 0; i < 3; i++)
{
write(' ') << start+1+i;
write(' ') << i+start;
}
write(' ') << start+1 << '\n';
write(' ') << start << '\n';
}
else
{
write('f');
for (int i = 0; i < 3; i++)
{
write(' ') << start+1+i;
write(' ') << i+start;
}
write('\n');
}
......@@ -294,7 +262,7 @@ Foam::Ostream& Foam::OBJstream::write
const bool lines
)
{
label start = nVertices_;
const label start = nVertices_+1; // 1-offset for obj included here
forAll(f, i)
{
write(points[f[i]]);
......@@ -304,16 +272,16 @@ Foam::Ostream& Foam::OBJstream::write
write('l');
forAll(f, i)
{
write(' ') << start+1+i;
write(' ') << i+start;
}
write(' ') << start+1 << '\n';
write(' ') << start << '\n';
}
else
{
write('f');
forAll(f, i)
{
write(' ') << start+1+i;
write(' ') << i+start;
}
write('\n');
}
......@@ -323,19 +291,19 @@ Foam::Ostream& Foam::OBJstream::write
Foam::Ostream& Foam::OBJstream::write
(
const faceList& fcs,
const UList<face>& faces,
const pointField& points,
const bool lines
)
{
SubList<face> allFcs(fcs, fcs.size());
SubList<face> allFcs(faces, faces.size());
primitivePatch pp(allFcs, points);
const pointField& localPoints = pp.localPoints();
const faceList& localFaces = pp.localFaces();
label start = nVertices_;
const label start = nVertices_+1; // 1-offset for obj included here
forAll(localPoints, i)
{
......@@ -349,7 +317,7 @@ Foam::Ostream& Foam::OBJstream::write
{
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
......@@ -360,7 +328,7 @@ Foam::Ostream& Foam::OBJstream::write
write('f');
forAll(f, i)
{
write(' ') << start+f[i]+1;
write(' ') << f[i]+start;
}
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
(