DelaunayMeshToolsTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "DelaunayMeshTools.H"
29 #include "meshTools.H"
30 #include "OFstream.H"
31 #include "pointConversion.H"
32 #include "pointIOField.H"
33 #include "indexedVertexOps.H"
34 
35 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
36 
37 template<class Triangulation>
39 (
40  const fileName& fName,
41  const Triangulation& t,
42  const indexedVertexEnum::vertexType startPointType,
43  const indexedVertexEnum::vertexType endPointType
44 )
45 {
46  OFstream str(fName);
47 
48  Pout<< nl
49  << "Writing points of types ("
50  << int(startPointType) << "-" << int(endPointType)
51  << ") to " << str.name() << endl;
52 
53  for
54  (
55  typename Triangulation::Finite_vertices_iterator vit =
56  t.finite_vertices_begin();
57  vit != t.finite_vertices_end();
58  ++vit
59  )
60  {
61  if (vit->type() >= startPointType && vit->type() <= endPointType)
62  {
63  meshTools::writeOBJ(str, topoint(vit->point()));
64  }
65  }
66 }
67 
68 
69 template<class Triangulation>
71 (
72  const fileName& fName,
73  const Triangulation& t,
74  const indexedVertexEnum::vertexType pointType
75 )
76 {
77  writeOBJ(fName, t, pointType, pointType);
78 }
79 
80 
81 template<class Triangulation>
83 (
84  const fileName& fName,
85  const Triangulation& t
86 )
87 {
88  OFstream str(fName);
89 
90  Pout<< nl
91  << "Writing fixed points to " << str.name() << endl;
92 
93  for
94  (
95  typename Triangulation::Finite_vertices_iterator vit =
96  t.finite_vertices_begin();
97  vit != t.finite_vertices_end();
98  ++vit
99  )
100  {
101  if (vit->fixed())
102  {
103  meshTools::writeOBJ(str, topoint(vit->point()));
104  }
105  }
106 }
107 
108 
109 template<class Triangulation>
111 (
112  const fileName& fName,
113  const Triangulation& t
114 )
115 {
116  OFstream str(fName);
117 
118  Pout<< nl
119  << "Writing boundary points to " << str.name() << endl;
120 
121  for
122  (
123  typename Triangulation::Finite_vertices_iterator vit =
124  t.finite_vertices_begin();
125  vit != t.finite_vertices_end();
126  ++vit
127  )
128  {
129  if (!vit->internalPoint())
130  {
131  meshTools::writeOBJ(str, topoint(vit->point()));
132  }
133  }
134 }
135 
136 
137 template<class Triangulation>
139 (
140  const fileName& fName,
141  const Triangulation& t,
142  const faceList& faces
143 )
144 {
145  OFstream str(fName);
146 
147  pointField points(t.number_of_finite_cells(), point::max);
148 
149  for
150  (
151  typename Triangulation::Finite_cells_iterator cit =
152  t.finite_cells_begin();
153  cit != t.finite_cells_end();
154  ++cit
155  )
156  {
157  if (!cit->hasFarPoint() && !t.is_infinite(cit))
158  {
159  points[cit->cellIndex()] = cit->dual();
160  }
161  }
162 
163  meshTools::writeOBJ(str, faces, points);
164 }
165 
166 
167 template<class Triangulation>
169 (
170  const fileName& instance,
171  const Triangulation& t
172 )
173 {
174  pointField internalDelaunayVertices(t.number_of_vertices());
175 
176  label vertI = 0;
177 
178  for
179  (
180  typename Triangulation::Finite_vertices_iterator vit =
181  t.finite_vertices_begin();
182  vit != t.finite_vertices_end();
183  ++vit
184  )
185  {
186  if (vit->internalPoint())
187  {
188  internalDelaunayVertices[vertI++] = topoint(vit->point());
189  }
190  }
191 
192  internalDelaunayVertices.setSize(vertI);
193 
194  pointIOField internalDVs
195  (
196  IOobject
197  (
198  "internalDelaunayVertices",
199  instance,
200  t.time(),
201  IOobject::NO_READ,
202  IOobject::AUTO_WRITE
203  ),
204  internalDelaunayVertices
205  );
206 
207  Info<< nl
208  << "Writing " << internalDVs.name()
209  << " to " << internalDVs.instance()
210  << endl;
211 
212  internalDVs.write();
213 }
214 
215 
216 template<class CellHandle>
218 (
219  Ostream& os,
220  const CellHandle& c,
221  label offset
222 )
223 {
224  // Supply offset as tet number
225  offset *= 4;
226 
227  os << "# cell index: " << label(c->cellIndex())
228  << " INT_MIN = " << INT_MIN
229  << endl;
230 
231  os << "# circumradius "
232  << mag(c->dual() - topoint(c->vertex(0)->point()))
233  << endl;
234 
235  for (int i = 0; i < 4; i++)
236  {
237  os << "# index / type / procIndex: "
238  << label(c->vertex(i)->index()) << " "
239  << label(c->vertex(i)->type()) << " "
240  << label(c->vertex(i)->procIndex())
241  <<
242  (
244  ? " # This vertex is uninitialised!"
245  : ""
246  )
247  << endl;
248 
249  meshTools::writeOBJ(os, topoint(c->vertex(i)->point()));
250  }
251 
252  os << "f " << 1 + offset << " " << 3 + offset << " " << 2 + offset << nl
253  << "f " << 2 + offset << " " << 3 + offset << " " << 4 + offset << nl
254  << "f " << 1 + offset << " " << 4 + offset << " " << 3 + offset << nl
255  << "f " << 1 + offset << " " << 2 + offset << " " << 4 + offset << endl;
256 
257 // os << "# circumcentre " << endl;
258 
259 // meshTools::writeOBJ(os, c->dual());
260 
261 // os << "l " << 1 + offset << " " << 5 + offset << endl;
262 }
263 
264 
265 template<class Triangulation>
267 (
268  const Triangulation& t
269 )
270 {
271  tmp<pointField> tpts(new pointField(t.vertexCount(), point::max));
272  pointField& pts = tpts.ref();
273 
274  for
275  (
276  typename Triangulation::Finite_vertices_iterator vit =
277  t.finite_vertices_begin();
278  vit != t.finite_vertices_end();
279  ++vit
280  )
281  {
282  if (vit->internalOrBoundaryPoint() && !vit->referred())
283  {
284  pts[vit->index()] = topoint(vit->point());
285  }
286  }
287 
288  return tpts;
289 }
290 
291 
292 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
meshTools.H
Foam::DelaunayMeshTools::writeOBJ
void writeOBJ(const fileName &fName, const List< Foam::point > &points)
Write list of points to file.
pointConversion.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
pointIOField.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
CGAL::indexedVertexOps::uninitialised
bool uninitialised(const VertexType &v)
Foam::DelaunayMeshTools::drawDelaunayCell
void drawDelaunayCell(Ostream &os, const CellHandle &c, label offset=0)
Draws a tet cell to an output stream. The offset is supplied as the tet.
Foam::topoint
pointFromPoint topoint(const Point &P)
Definition: pointConversion.H:72
OFstream.H
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
DelaunayMeshTools.H
Foam::DelaunayMeshTools::writeProcessorInterface
void writeProcessorInterface(const fileName &fName, const Triangulation &t, const faceList &faces)
Write the processor interface to an OBJ file.
Foam::DelaunayMeshTools::writeBoundaryPoints
void writeBoundaryPoints(const fileName &fName, const Triangulation &t)
Write the boundary Delaunay points to an OBJ file.
Foam::DelaunayMeshTools::writeFixedPoints
void writeFixedPoints(const fileName &fName, const Triangulation &t)
Write the fixed Delaunay points to an OBJ file.
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::DelaunayMeshTools::allPoints
tmp< pointField > allPoints(const Triangulation &t)
Extract all points in vertex-index order.
Foam::DelaunayMeshTools::writeInternalDelaunayVertices
void writeInternalDelaunayVertices(const fileName &instance, const Triangulation &t)
Write the internal Delaunay vertices of the tessellation as a.
indexedVertexOps.H