OGS
VtkMeshNodalCoordinatesTemplate-impl.h
Go to the documentation of this file.
1
15#include <vtkIdList.h>
16#include <vtkObjectFactory.h>
17#include <vtkVariant.h>
18#include <vtkVariantCast.h>
19
20#include "MeshLib/Node.h"
21
22namespace MeshLib {
23
24// Can't use vtkStandardNewMacro with a template.
25template <class Scalar> VtkMeshNodalCoordinatesTemplate<Scalar> *
26VtkMeshNodalCoordinatesTemplate<Scalar>::New()
27{
28 VTK_STANDARD_NEW_BODY(VtkMeshNodalCoordinatesTemplate<Scalar>);
29}
30
31template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
32::PrintSelf(ostream &os, vtkIndent indent)
33{
35 os, indent);
36 //os << indent << "XArray: " << this->XArray << std::endl;
37 //os << indent << "YArray: " << this->YArray << std::endl;
38 //os << indent << "ZArray: " << this->ZArray << std::endl;
39 //os << indent << "TempDoubleArray: " << this->TempDoubleArray << std::endl;
40}
41
42template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
44{
45 this->_nodes = nullptr;
46 delete [] this->TempDoubleArray;
47 this->TempDoubleArray = nullptr;
48 this->MaxId = -1;
49 this->Size = 0;
50 this->NumberOfComponents = 1;
51}
52
53template <class Scalar>
55 std::vector<Node*> const& nodes)
56{
57 Initialize();
58 _nodes = &nodes;
59 this->NumberOfComponents = 3;
60 this->Size = this->NumberOfComponents * _nodes->size();
61 this->MaxId = this->Size - 1;
62 this->TempDoubleArray = new double [this->NumberOfComponents];
63 this->Modified();
64}
65
66template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
67::GetTuples(vtkIdList *ptIds, vtkAbstractArray *output)
68{
69 vtkDataArray *outArray = vtkDataArray::FastDownCast(output);
70 if(!outArray)
71 {
72 vtkWarningMacro(<<"Input is not a vtkDataArray");
73 return;
74 }
75
76 const vtkIdType numTuples = ptIds->GetNumberOfIds();
77
78 outArray->SetNumberOfComponents(this->NumberOfComponents);
79 outArray->SetNumberOfTuples(numTuples);
80
81 const vtkIdType numPoints = ptIds->GetNumberOfIds();
82 for (vtkIdType i = 0; i < numPoints; i++)
83 {
84 outArray->SetTuple(i, this->GetTuple(ptIds->GetId(i)));
85 }
86}
87
88template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
89::GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output)
90{
91 vtkDataArray *da = vtkDataArray::FastDownCast(output);
92 if(!da)
93 {
94 vtkWarningMacro(<<"Input is not a vtkDataArray");
95 return;
96 }
97
98 if(da->GetNumberOfComponents() != this->GetNumberOfComponents())
99 {
100 vtkErrorMacro(<<"Incorrect number of components in input array.");
101 return;
102 }
103
104 for (vtkIdType daTubleId = 0; p1 <= p2; ++p1)
105 {
106 da->SetTuple(daTubleId++, this->GetTuple(p1));
107 }
108}
109
110template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
112{
113
114}
115
116template <class Scalar> vtkArrayIterator* VtkMeshNodalCoordinatesTemplate<Scalar>
118{
119 vtkErrorMacro(<<"Not implemented.");
120 return nullptr;
121}
122
123template <class Scalar> vtkIdType VtkMeshNodalCoordinatesTemplate<Scalar>
124::LookupValue(vtkVariant value)
125{
126 bool valid = true;
127 Scalar val = vtkVariantCast<Scalar>(value, &valid);
128 if (valid)
129 {
130 return this->Lookup(val, 0);
131 }
132 return -1;
133}
134
135template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
136::LookupValue(vtkVariant value, vtkIdList *ids)
137{
138 bool valid = true;
139 Scalar val = vtkVariantCast<Scalar>(value, &valid);
140 ids->Reset();
141 if(valid)
142 {
143 vtkIdType index = 0;
144 while ((index = this->Lookup(val, index)) >= 0)
145 {
146 ids->InsertNextId(index++);
147 }
148 }
149}
150
151template <class Scalar> vtkVariant VtkMeshNodalCoordinatesTemplate<Scalar>
152::GetVariantValue(vtkIdType idx)
153{
154 return vtkVariant(this->GetValueReference(idx));
155}
156
157template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
159{
160 // no fast lookup implemented
161}
162
163template <class Scalar> double* VtkMeshNodalCoordinatesTemplate<Scalar>
164::GetTuple(vtkIdType i)
165{
166 this->GetTuple(i, this->TempDoubleArray);
167 return this->TempDoubleArray;
168}
169
170template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
171::GetTuple(vtkIdType i, double *tuple)
172{
173 tuple[0] = (*(*this->_nodes)[i])[0];
174 tuple[1] = (*(*this->_nodes)[i])[1];
175 tuple[2] = (*(*this->_nodes)[i])[2];
176}
177
178template <class Scalar> vtkIdType VtkMeshNodalCoordinatesTemplate<Scalar>
180{
181 return this->Lookup(value, 0);
182}
183
184template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
185::LookupTypedValue(Scalar value, vtkIdList *ids)
186{
187 ids->Reset();
188 vtkIdType index = 0;
189 while ((index = this->Lookup(value, index)) >= 0)
190 {
191 ids->InsertNextId(index++);
192 }
193}
194
195template <class Scalar> Scalar& VtkMeshNodalCoordinatesTemplate<Scalar>
197{
198 const vtkIdType tuple = idx / this->NumberOfComponents;
199 const vtkIdType comp = idx % this->NumberOfComponents;
200 return (*(*this->_nodes)[tuple])[comp];
201}
202
203template <class Scalar>
205 vtkIdType /*unused*/)
206{
207 vtkErrorMacro("Read only container.");
208 return 0;
209}
210
211template <class Scalar>
213{
214 vtkErrorMacro("Read only container.");
215 return 0;
216}
217
218template <class Scalar>
220 vtkIdType /*unused*/)
221{
222 vtkErrorMacro("Read only container.");
223 return;
224}
225
226template <class Scalar>
228 vtkIdType /*unused*/, vtkIdType /*unused*/, vtkAbstractArray* /*unused*/)
229{
230 vtkErrorMacro("Read only container.");
231 return;
232}
233
234template <class Scalar>
236 const float* /*unused*/)
237{
238 vtkErrorMacro("Read only container.");
239 return;
240}
241
242template <class Scalar>
244 const double* /*unused*/)
245{
246 vtkErrorMacro("Read only container.");
247 return;
248}
249
250template <class Scalar>
252 vtkIdType /*unused*/, vtkIdType /*unused*/, vtkAbstractArray* /*unused*/)
253{
254 vtkErrorMacro("Read only container.");
255 return;
256}
257
258template <class Scalar>
260 vtkIdType /*unused*/, const float* /*unused*/)
261{
262 vtkErrorMacro("Read only container.");
263 return;
264}
265
266template <class Scalar>
268 vtkIdType /*unused*/, const double* /*unused*/)
269{
270 vtkErrorMacro("Read only container.");
271 return;
272}
273
274template <class Scalar>
276 vtkIdList* /*unused*/, vtkIdList* /*unused*/, vtkAbstractArray* /*unused*/)
277{
278 vtkErrorMacro("Read only container.");
279 return;
280}
281
282template <class Scalar>
284 vtkIdType /*unused*/, vtkIdType /*unused*/, vtkIdType /*unused*/,
285 vtkAbstractArray* /*unused*/)
286{
287 vtkErrorMacro("Read only container.");
288 return;
289}
290
291template <class Scalar>
293 vtkIdType /*unused*/, vtkAbstractArray* /*unused*/)
294{
295 vtkErrorMacro("Read only container.");
296 return -1;
297}
298
299template <class Scalar>
301 const float* /*unused*/)
302{
303 vtkErrorMacro("Read only container.");
304 return -1;
305}
306
307template <class Scalar>
309 const double* /*unused*/)
310{
311 vtkErrorMacro("Read only container.");
312 return -1;
313}
314
315template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
316::InsertVariantValue(vtkIdType /*idx*/, vtkVariant /*value*/)
317{
318 vtkErrorMacro("Read only container.");
319}
320
321template <class Scalar>
323 vtkAbstractArray* /*unused*/)
324{
325 vtkErrorMacro("Read only container.");
326 return;
327}
328
329template <class Scalar>
331{
332 vtkErrorMacro("Read only container.");
333 return;
334}
335
336template <class Scalar>
338 vtkIdType /*unused*/, vtkIdList* /*unused*/, vtkAbstractArray* /*unused*/,
339 double* /*unused*/)
340{
341 vtkErrorMacro("Read only container.");
342 return;
343}
344
345template <class Scalar>
347 vtkIdType /*unused*/, vtkIdType /*unused*/, vtkAbstractArray* /*unused*/,
348 vtkIdType /*unused*/, vtkAbstractArray* /*unused*/, double /*unused*/)
349{
350 vtkErrorMacro("Read only container.");
351 return;
352}
353
354template <class Scalar>
356 vtkIdType /*unused*/, vtkVariant /*unused*/)
357{
358 vtkErrorMacro("Read only container.");
359 return;
360}
361
362template <class Scalar>
364{
365 vtkErrorMacro("Read only container.");
366 return;
367}
368
369template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
371{
372 vtkErrorMacro("Read only container.");
373 return;
374}
375
376template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
378{
379 vtkErrorMacro("Read only container.");
380 return;
381}
382
383template <class Scalar>
385 Scalar /*unused*/)
386{
387 vtkErrorMacro("Read only container.");
388 return;
389}
390
391template <class Scalar>
393 Scalar /*unused*/)
394{
395 vtkErrorMacro("Read only container.");
396 return -1;
397}
398
399template <class Scalar>
401 Scalar /*unused*/)
402{
403 vtkErrorMacro("Read only container.");
404 return;
405}
406
407template <class Scalar>
409 default;
410
411template <class Scalar> VtkMeshNodalCoordinatesTemplate<Scalar>
413{
414 delete [] this->TempDoubleArray;
415}
416
417template <class Scalar> vtkIdType VtkMeshNodalCoordinatesTemplate<Scalar>
418::Lookup(const Scalar &val, vtkIdType index)
419{
420 while(index <= this->MaxId)
421 {
422 if (this->GetValueReference(index++) == val)
423 {
424 return index;
425 }
426 }
427 return -1;
428}
429
430
431template <class Scalar> Scalar& VtkMeshNodalCoordinatesTemplate<Scalar>
432::GetValueReference(vtkIdType idx) const
433{
434 const vtkIdType tuple = idx / this->NumberOfComponents;
435 const vtkIdType comp = idx % this->NumberOfComponents;
436 return (*(*this->_nodes)[tuple])[comp];
437}
438
439template <class Scalar> Scalar VtkMeshNodalCoordinatesTemplate<Scalar>
440::GetValue(vtkIdType idx) const
441{
442 return this->GetValueReference(idx);
443}
444
445template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar>
446::GetTypedTuple(vtkIdType tupleId, Scalar *tuple) const
447{
448 tuple[0] = (*(*this->_nodes)[tupleId])[0];
449 tuple[1] = (*(*this->_nodes)[tupleId])[1];
450 tuple[2] = (*(*this->_nodes)[tupleId])[2];
451}
452
453template <class Scalar>
455 vtkIdType /*unused*/, const Scalar* /*unused*/)
456{
457 vtkErrorMacro("Read only container.");
458 return;
459}
460
461template <class Scalar>
463 vtkIdType /*unused*/, const Scalar* /*unused*/)
464{
465 vtkErrorMacro("Read only container.");
466 return;
467}
468
469template <class Scalar>
471 const Scalar* /*unused*/)
472{
473 vtkErrorMacro("Read only container.");
474 return -1;
475}
476} // namespace MeshLib
Definition of the Node class.
void SetValue(vtkIdType idx, Scalar value) override
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
void SetVariantValue(vtkIdType idx, vtkVariant value) override
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
void SetTypedTuple(vtkIdType i, const Scalar *t) override
void SetNodes(std::vector< Node * > const &nodes)
Pass the nodes from OGS mesh.
void InterpolateTuple(vtkIdType i, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights) override
void InsertTypedTuple(vtkIdType i, const Scalar *t) override
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override