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