foamPvCore.H
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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Description
28  Helpers for OpenFOAM reader interfaces in ParaView.
29 
30 SourceFiles
31  foamPvCore.C
32  foamPvCoreTemplates.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef foamPvCore_H
37 #define foamPvCore_H
38 
39 #include "fileName.H"
40 #include "stringList.H"
41 #include "boolList.H"
42 #include "pointList.H"
43 #include "wordList.H"
44 #include "Hash.H"
45 #include "HashSet.H"
46 #include "Map.H"
47 #include "labelRange.H"
48 
49 // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
50 
51 class vtkCellArray;
52 class vtkDataArraySelection;
53 class vtkDataSet;
54 class vtkIndent;
55 class vtkMultiBlockDataSet;
56 class vtkPoints;
57 template<class T> class vtkSmartPointer;
58 
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 class IOobjectList;
66 
67 /*---------------------------------------------------------------------------*\
68  Class foamPvCore Declaration
69 \*---------------------------------------------------------------------------*/
70 
72 {
73 public:
74 
75  //- Bookkeeping for GUI checklists and multi-block organization
76  // Works like a SubList selection.
77  class arrayRange
78  :
79  public labelRange
80  {
81  const char *name_;
82  int block_;
83 
84  public:
85 
86  //- Construct with given name for the specified block
87  arrayRange(const char *name, int blockNo=0)
88  :
89  labelRange(),
90  name_(name),
91  block_(blockNo)
92  {}
93 
94  //- Return the block holding these datasets
95  int block() const
96  {
97  return block_;
98  }
99 
100  //- Assign block number, return previous value
101  int block(int blockNo)
102  {
103  int prev = block_;
104  block_ = blockNo;
105  return prev;
106  }
107 
108  //- Return the name
109  const char* name() const
110  {
111  return name_;
112  }
113 
114  //- Reset the start/size directly
115  using labelRange::reset;
116 
117  //- Reset the size to zero and optionally assign a new start
118  void reset(label startAt = 0)
119  {
120  clear();
121  setStart(startAt);
122  }
123 
124  //- Increment the size
126  {
127  setSize(size() + n);
128  }
129 
130  //- True if the labelRange intersects any key in the Map
131  template<class T>
132  bool intersects(const Map<T>& map) const
133  {
134  for (const label idx : *this)
135  {
136  if (map.found(idx))
137  {
138  return true;
139  }
140  }
141 
142  return false;
143  }
144 
145  //- The intersection ids with keys in the Map
146  template<class T>
147  List<label> intersection(const Map<T>& map) const
148  {
149  List<label> indices(Foam::min(map.size(), this->size()));
150 
151  if (indices.size())
152  {
153  label n = 0;
154 
155  for (const label idx : *this)
156  {
157  if (map.found(idx))
158  {
159  indices[n++] = idx;
160  }
161  }
162 
163  indices.setSize(n);
164  }
165 
166  return indices;
167  }
168 
169  }; // End class arrayRange
170 
171 
172 public:
173 
174  //- Construct null
175  constexpr foamPvCore() noexcept {}
176 
177 
178  //- Print information about vtkDataArraySelection
180  (
181  Ostream& os,
182  vtkDataArraySelection* select
183  );
184 
185 
186  //- Convenience method for the VTK multiblock API
187  static void addToBlock
188  (
189  vtkMultiBlockDataSet* output,
190  vtkDataSet* dataset,
191  const arrayRange& selector,
192  const label datasetNo,
193  const std::string& datasetName
194  );
195 
196  //- Add names to array selection
197  template<class StringType>
198  static label addToArray
199  (
200  vtkDataArraySelection* select,
201  const std::string& prefix,
202  const UList<StringType>& names
203  );
204 
205  //- Add names to array selection
206  template<class StringType>
207  static label addToArray
208  (
209  vtkDataArraySelection* select,
210  const UList<StringType>& names,
211  const std::string& suffix = string::null
212  );
213 
214  //- Add objects of Type to array selection
215  template<class Type>
216  static label addToSelection
217  (
218  vtkDataArraySelection* select,
219  const std::string& prefix,
220  const IOobjectList& objects
221  );
222 
223  //- Add objects of Type to array selection
224  template<class Type>
225  static label addToSelection
226  (
227  vtkDataArraySelection* select,
228  const IOobjectList& objects,
229  const std::string& suffix = string::null
230  );
231 
232  //- Add objects of Type to array selection
233  template<class Type>
234  static label addToSelection
235  (
236  vtkDataArraySelection* select,
237  const std::string& prefix,
238  const HashTable<wordHashSet>& objects
239  );
240 
241 
242  //- Add objects of Type to array selection
243  template<class Type>
244  static label addToSelection
245  (
246  vtkDataArraySelection* select,
247  const HashTable<wordHashSet>& objects,
248  const std::string& suffix = string::null
249  );
250 
251 
252  //- Retrieve the current selections as a wordHashSet,
253  //- while stripping off any prefix or suffix
254  static wordHashSet getSelected
255  (
256  vtkDataArraySelection* select
257  );
258 
259 
260  //- Retrieve sub-list of the current selections as a wordHashSet,
261  //- while stripping off any prefix or suffix
262  static wordHashSet getSelected
263  (
264  vtkDataArraySelection* select,
265  const labelRange& selector
266  );
267 
268 
269  //- Retrieve the currently enabled selections as hashset
271  (
272  vtkDataArraySelection* select
273  );
274 
275  //- Retrieve the currently enabled selections as id/name map
277  (
278  vtkDataArraySelection* select
279  );
280 
281  //- Enable the selection(s)
282  template<class AnyValue, class AnyHasher>
283  static void setSelectedArrayEntries
284  (
285  vtkDataArraySelection* select,
287  );
288 
289 
290  //- Extract the first word characters after a slash
291  static word getFoamName(const std::string& str);
292 
293 
294  //- Simple memory used debugging information
295  static void printMemory();
296 
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 }; // End class foamPvCore
301 
302 } // End namespace Foam
303 
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 
306 #ifdef NoRepository
307  #include "foamPvCoreTemplates.C"
308 #endif
309 
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 #endif
314 
315 // ************************************************************************* //
Foam::labelRange::setSize
void setSize(const label n) noexcept
Change the size - alias for resize()
Definition: labelRangeI.H:201
Foam::labelRange::reset
bool reset(const label start, const label size) noexcept
Reset start and size, enforcing non-negative size.
Definition: labelRangeI.H:275
Foam::foamPvCore::getFoamName
static word getFoamName(const std::string &str)
Extract the first word characters after a slash.
boolList.H
Foam::foamPvCore::setSelectedArrayEntries
static void setSelectedArrayEntries(vtkDataArraySelection *select, const HashTable< AnyValue, string, AnyHasher > &enabled)
Enable the selection(s)
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::foamPvCore::addToBlock
static void addToBlock(vtkMultiBlockDataSet *output, vtkDataSet *dataset, const arrayRange &selector, const label datasetNo, const std::string &datasetName)
Convenience method for the VTK multiblock API.
Foam::foamPvCore::arrayRange
Bookkeeping for GUI checklists and multi-block organization.
Definition: foamPvCore.H:77
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: HashTableFwd.H:46
vtkSmartPointer
Definition: runTimePostProcessing.H:148
Foam::foamPvCore::printDataArraySelection
static Ostream & printDataArraySelection(Ostream &os, vtkDataArraySelection *select)
Print information about vtkDataArraySelection.
Foam::foamPvCore::arrayRange::intersects
bool intersects(const Map< T > &map) const
True if the labelRange intersects any key in the Map.
Definition: foamPvCore.H:132
Foam::labelRange::size
label size() const noexcept
The effective size of the range.
Definition: labelRangeI.H:226
Foam::HashSet< word >
Foam::foamPvCore::getSelected
static wordHashSet getSelected(vtkDataArraySelection *select)
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
wordList.H
Foam::foamPvCore::getSelectedArrayMap
static Map< string > getSelectedArrayMap(vtkDataArraySelection *select)
Retrieve the currently enabled selections as id/name map.
Foam::foamPvCore
Definition: foamPvCore.H:71
Foam::labelRange::clear
void clear() noexcept
Reset to zero start and zero size.
Definition: labelRangeI.H:208
Map.H
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::label
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:62
Foam::foamPvCore::arrayRange::arrayRange
arrayRange(const char *name, int blockNo=0)
Construct with given name for the specified block.
Definition: foamPvCore.H:87
Foam::foamPvCore::addToArray
static label addToArray(vtkDataArraySelection *select, const std::string &prefix, const UList< StringType > &names)
Add names to array selection.
pointList.H
fileName.H
Foam::foamPvCore::arrayRange::name
const char * name() const
Return the name.
Definition: foamPvCore.H:109
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
HashSet.H
Foam::string::null
static const string null
An empty string.
Definition: string.H:147
foamPvCoreTemplates.C
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::foamPvCore::addToSelection
static label addToSelection(vtkDataArraySelection *select, const std::string &prefix, const IOobjectList &objects)
Add objects of Type to array selection.
Foam::foamPvCore::arrayRange::intersection
List< label > intersection(const Map< T > &map) const
The intersection ids with keys in the Map.
Definition: foamPvCore.H:147
labelRange.H
Foam::List< label >
Foam::foamPvCore::foamPvCore
constexpr foamPvCore() noexcept
Construct null.
Definition: foamPvCore.H:175
Foam::foamPvCore::arrayRange::block
int block(int blockNo)
Assign block number, return previous value.
Definition: foamPvCore.H:101
Foam::UList< StringType >
Hash.H
Foam::foamPvCore::getSelectedArraySet
static HashSet< string > getSelectedArraySet(vtkDataArraySelection *select)
Retrieve the currently enabled selections as hashset.
Foam::labelRange::setStart
void setStart(const label i) noexcept
Change the start position.
Definition: labelRangeI.H:188
Foam::foamPvCore::printMemory
static void printMemory()
Simple memory used debugging information.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::foamPvCore::arrayRange::operator+=
void operator+=(label n)
Increment the size.
Definition: foamPvCore.H:125
Foam::foamPvCore::arrayRange::block
int block() const
Return the block holding these datasets.
Definition: foamPvCore.H:95
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::foamPvCore::arrayRange::reset
void reset(label startAt=0)
Reset the size to zero and optionally assign a new start.
Definition: foamPvCore.H:118
stringList.H