vtkWritePolyData.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2021 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 Class
25  Foam::vtkWritePolyData
26 
27 Description
28  General write functions for vtk polygonal data files
29 
30 SourceFiles
31  vtkWritePolyData.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef vtkWritePolyData_H
36 #define vtkWritePolyData_H
37 
38 #include "vtkWriteOps.H"
39 #include "fileName.H"
40 #include "Field.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Namespace vtkWritePolyData Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 namespace vtkWritePolyData
52 {
53 
54 //- Helper for templated write
55 template<class Types, class Type>
56 inline void setFieldTypeValue
57 (
58  UPtrList<const Field<Types>>& fieldTypeValues,
59  const label fieldi,
60  const Field<Type>& fieldTypeValue
61 )
62 {}
63 
64 
65 //- Helper for templated write
66 template<class Type>
67 inline void setFieldTypeValue
68 (
69  UPtrList<const Field<Type>>& fieldTypeValues,
70  const label fieldi,
71  const Field<Type>& fieldTypeValue
72 )
73 {
74  fieldTypeValues.set(fieldi, &fieldTypeValue);
75 }
76 
77 
78 //- Helper for templated write
80 (
81  wordList& fieldNames,
82  boolList& fieldIsPointValues,
83  UPtrList<const Field<label>>& fieldLabelValues
84  #define FieldTypeValuesNonConstArg(Type, nullArg) \
85  , UPtrList<const Field<Type>>& field##Type##Values
86  FOR_ALL_FIELD_TYPES(FieldTypeValuesNonConstArg)
87  #undef FieldTypeValuesNonConstArg
88 )
89 {}
90 
91 
92 //- Helper for templated write
93 template<class Type, class ... Args>
95 (
96  wordList& fieldNames,
97  boolList& fieldIsPointValues,
98  UPtrList<const Field<label>>& fieldLabelValues
99  #define FieldTypeValuesNonConstArg(Type, nullArg) \
100  , UPtrList<const Field<Type>>& field##Type##Values
101  FOR_ALL_FIELD_TYPES(FieldTypeValuesNonConstArg),
102  #undef FieldTypeValuesNonConstArg
103  const word& fieldName,
104  const bool fieldIsPointValue,
105  const Field<Type>& fieldTypeValue,
106  Args& ... args
107 )
108 {
109  const label fieldi = fieldNames.size() - 1 - sizeof...(Args)/3;
110 
111  fieldNames[fieldi] = fieldName;
112  fieldIsPointValues[fieldi] = fieldIsPointValue;
113  setFieldTypeValue(fieldLabelValues, fieldi, fieldTypeValue);
114  #define SetFieldTypeValue(Type, nullArg) \
115  setFieldTypeValue(field##Type##Values, fieldi, fieldTypeValue);
117  #undef SetFieldTypeValue
118 
120  (
121  fieldNames,
122  fieldIsPointValues,
123  fieldLabelValues
124  #define FieldTypeValuesParameter(Type, nullArg) , field##Type##Values
127  args ...
128  );
129 }
130 
131 
132 //- Write the field values out for a type
133 template<class Type, class DataType>
135 (
136  std::ostream& os,
137  const bool binary,
138  const wordList& fieldNames,
139  const boolList& fieldIsPointValues,
140  const UPtrList<const Field<Type>>& fieldTypeValues,
141  const bool writePointValues
142 );
143 
144 
145 //- Write VTK polygonal data to a file. Takes a PtrList of fields of labels and
146 // of every primitive type. Each PtrList should be the length of the total
147 // number of fields and only one PtrList should be non-null for each field
148 // index.
149 template<class PointField, class VertexList, class LineList, class FaceList>
150 void write
151 (
152  const fileName& file,
153  const word& title,
154  const bool binary,
155  const PointField& points,
156  const VertexList& vertices,
157  const LineList& lines,
158  const FaceList& faces,
159  const wordList& fieldNames,
160  const boolList& fieldIsPointValues,
161  const UPtrList<const Field<label>>& fieldLabelValues
162  #define FieldTypeValuesConstArg(Type, nullArg) \
163  , const UPtrList<const Field<Type>>& field##Type##Values
166 );
167 
168 
169 //- Write VTK polygonal data to a file. Takes any number of name,
170 // isPointValues, values arguments at the end. E.g.;
171 //
172 // write
173 // (
174 // // Output options
175 // "myPolyData.vtk", "myPolyData", false,
176 //
177 // // Geometry
178 // pp.localPoints(), labelList(), labelListList(), pp.localFaces(),
179 //
180 // // Fields
181 // "faceIDs", true, pp.addressing(),
182 // "facePressures", false, Field<scalar>(pp.size(), ...),
183 // "pointVelocities", true, Field<vector>(pp.nPoints(), ...)
184 // );
185 //
186 template
187 <
188  class PointField,
189  class VertexList,
190  class LineList,
191  class FaceList,
192  class ... Args
193 >
194 inline void write
195 (
196  const fileName& file,
197  const word& title,
198  const bool binary,
199  const PointField& points,
200  const VertexList& vertices,
201  const LineList& lines,
202  const FaceList& faces,
203  const Args& ... args
204 );
205 
206 };
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 } // End namespace Foam
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #ifdef NoRepository
215  #include "vtkWritePolyDataTemplates.C"
216 #endif
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
#define FieldTypeValuesParameter(Type, nullArg)
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
A class for handling file names.
Definition: fileName.H:79
void unpackFieldTypeValues(wordList &fieldNames, boolList &fieldIsPointValues, UPtrList< const Field< label >> &fieldLabelValues #define FieldTypeValuesNonConstArg(Type, nullArg))
Helper for templated write.
void writeFieldTypeValues(std::ostream &os, const bool binary, const wordList &fieldNames, const boolList &fieldIsPointValues, const UPtrList< const Field< Type >> &fieldTypeValues, const bool writePointValues)
Write the field values out for a type.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
General write functions for vtk polygonal data files.
#define FOR_ALL_FIELD_TYPES(Macro,...)
Definition: fieldTypes.H:50
#define FieldTypeValuesConstArg(Type, nullArg)
pointField vertices(const blockVertexList &bvl)
const pointField & points
#define FieldTypeValuesNonConstArg(Type, nullArg)
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
GeometricField< Type, pointPatchField, pointMesh > PointField
#define SetFieldTypeValue(Type, nullArg)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
void write(const fileName &file, const word &title, const bool binary, const PointField &points, const VertexList &vertices, const LineList &lines, const FaceList &faces, const wordList &fieldNames, const boolList &fieldIsPointValues, const UPtrList< const Field< label >> &fieldLabelValues #define FieldTypeValuesConstArg(Type, nullArg))
Write VTK polygonal data to a file. Takes a PtrList of fields of labels and.
void setFieldTypeValue(UPtrList< const Field< Types >> &fieldTypeValues, const label fieldi, const Field< Type > &fieldTypeValue)
Helper for templated write.
rDeltaTY field()
Foam::argList args(argc, argv)
Namespace for OpenFOAM.