foamVtkToolsI.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) 2017-2019 OpenCFD Ltd.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
31 (
32  vtkUnsignedCharArray* array,
33  const label size
34 )
35 {
36  array->SetNumberOfComponents(1);
37  array->SetNumberOfTuples(size);
38 
39  return UList<uint8_t>(array->WritePointer(0, size), size);
40 }
41 
42 
44 (
45  vtkIdTypeArray* array,
46  const label size
47 )
48 {
49  array->SetNumberOfComponents(1);
50  array->SetNumberOfTuples(size);
51 
52  return UList<vtkIdType>(array->WritePointer(0, size), size);
53 }
54 
55 
57 (
58  vtkCellArray* cells,
59  const label nCells,
60  const label size
61 )
62 {
63  cells->GetData()->SetNumberOfTuples(size);
64 
65  return UList<vtkIdType>(cells->WritePointer(nCells, size), size);
66 }
67 
68 
71 {
72  auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
73 
74  vtkpoints->SetNumberOfPoints(pts.size());
75 
76  vtkIdType pointId = 0;
77  for (const point& pt : pts)
78  {
79  vtkpoints->SetPoint(pointId++, pt.v_);
80  }
81 
82  return vtkpoints;
83 }
84 
85 
88 {
89  auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
90 
91  vtkpoints->SetNumberOfPoints(addr.size());
92 
93  vtkIdType pointId = 0;
94  for (const label pointi : addr)
95  {
96  vtkpoints->SetPoint(pointId++, pts[pointi].v_);
97  }
98 
99  return vtkpoints;
100 }
101 
102 
105 {
106  auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
107 
108  vtkmesh->SetPoints(Tools::Points(pts));
109  vtkmesh->SetVerts(Tools::identityVertices(pts.size()));
110 
111  return vtkmesh;
112 }
113 
114 
117 {
118  auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
119 
120  vtkmesh->SetPoints(Tools::Points(pts, addr));
121  vtkmesh->SetVerts(Tools::identityVertices(addr.size()));
122 
123  return vtkmesh;
124 }
125 
126 
128 {
129  double range[2]{GREAT, -GREAT};
130 
131  if (data)
132  {
133  if (data->GetNumberOfComponents() == 1)
134  {
135  data->GetRange(range);
136  }
137  else
138  {
139  // Mag
140  data->GetRange(range, -1);
141  }
142  }
143 
144  return scalarMinMax(range[0], range[1]);
145 }
146 
147 
149 (
150  const label size
151 )
152 {
153  // VTK_VERTEX: need 2 values (size=1 and index=id) per vertex
155 
156  UList<vtkIdType> list = asUList(cells, size, 2*size);
157 
158  // Cell connectivity for vertex
159  // [size, ids.., size, ids...] -> therefore [1, id, 1, id, ...]
160  auto iter = list.begin();
161  for (label id=0; id < size; ++id)
162  {
163  *(iter++) = 1;
164  *(iter++) = id;
165  }
166 
167  return cells;
168 };
169 
170 
171 template<class Type>
173 (
174  float output[],
175  const Type& val
176 )
177 {
178  for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
179  {
180  output[cmpt] = component(val, cmpt);
181  }
182  remapTuple<Type>(output);
183 }
184 
185 
186 template<class Type>
188 (
189  double output[],
190  const Type& val
191 )
192 {
193  for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
194  {
195  output[cmpt] = component(val, cmpt);
196  }
197  remapTuple<Type>(output);
198 }
199 
200 
201 // ************************************************************************* //
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::vtk::Tools::Vertices
vtkSmartPointer< vtkPolyData > Vertices(const UList< point > &pts)
Return vtkPolyData of vertices for each point.
Definition: foamVtkToolsI.H:104
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::vtk::Tools::asUList
UList< uint8_t > asUList(vtkUnsignedCharArray *array, const label size)
Wrap vtkUnsignedCharArray as a UList.
Definition: foamVtkToolsI.H:31
vtkSmartPointer
Definition: runTimePostProcessing.H:148
Foam::UList::begin
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:276
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::vtk::Tools::identityVertices
vtkSmartPointer< vtkCellArray > identityVertices(const label size)
An identity list of VTK_VERTEX.
Definition: foamVtkToolsI.H:149
Foam::scalarMinMax
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:117
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::Vector< scalar >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::vtk::Tools::Points
vtkSmartPointer< vtkPoints > Points(const UList< point > &pts)
Return a list of points as vtkPoints.
Definition: foamVtkToolsI.H:70
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::vtk::Tools::foamToVtkTuple
void foamToVtkTuple(float output[], const Type &val)
Copy/transcribe OpenFOAM data types to VTK format.
Definition: foamVtkToolsI.H:173
Foam::MinMax< scalar >
Foam::vtk::Tools::rangeOf
scalarMinMax rangeOf(vtkDataArray *data)
Min/Max of scalar, or mag() of non-scalars. Includes nullptr check.
Definition: foamVtkToolsI.H:127
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54