VTK  9.3.20240416
vtkArrayListTemplate.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) Kitware, Inc.
3 // SPDX-License-Identifier: BSD-3-Clause
34 #ifndef vtkArrayListTemplate_h
35 #define vtkArrayListTemplate_h
36 
37 #include "vtkAbstractArray.h"
38 #include "vtkDataSetAttributes.h"
39 #include "vtkSmartPointer.h"
40 #include "vtkStdString.h"
41 
42 #include <algorithm>
43 #include <vector>
44 
45 // Create a generic class supporting virtual dispatch to type-specific
46 // subclasses.
47 VTK_ABI_NAMESPACE_BEGIN
49 {
51  int NumComp;
53 
54  BaseArrayPair(vtkIdType num, int numComp, vtkAbstractArray* outArray)
55  : Num(num)
56  , NumComp(numComp)
57  , OutputArray(outArray)
58  {
59  }
60  virtual ~BaseArrayPair() = default;
61 
62  virtual void Copy(vtkIdType inId, vtkIdType outId) = 0;
63  virtual void Interpolate(
64  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) = 0;
65  virtual void InterpolateOutput(
66  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) = 0;
67  virtual void Average(int numPts, const vtkIdType* ids, vtkIdType outId) = 0;
68  virtual void WeightedAverage(
69  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) = 0;
70  virtual void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) = 0;
71  virtual void AssignNullValue(vtkIdType outId) = 0;
72 #ifdef VTK_USE_64BIT_IDS
73  virtual void Copy(unsigned int inId, unsigned int outId) = 0;
74  virtual void Interpolate(
75  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) = 0;
76  virtual void InterpolateOutput(
77  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) = 0;
78  virtual void Average(int numPts, const unsigned int* ids, unsigned int outId) = 0;
79  virtual void WeightedAverage(
80  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) = 0;
81  virtual void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) = 0;
82  virtual void AssignNullValue(unsigned int outId) = 0;
83 #endif
84  virtual void Copy(unsigned short inId, unsigned short outId) = 0;
85  virtual void Interpolate(
86  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) = 0;
87  virtual void InterpolateOutput(
88  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) = 0;
89  virtual void Average(int numPts, const unsigned short* ids, unsigned short outId) = 0;
90  virtual void WeightedAverage(
91  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) = 0;
92  virtual void InterpolateEdge(
93  unsigned short v0, unsigned short v1, double t, unsigned short outId) = 0;
94  virtual void AssignNullValue(unsigned short outId) = 0;
95 
96  virtual void Realloc(vtkIdType sze) = 0;
97 };
98 
99 // Type specific interpolation on a matched pair of data arrays
100 template <typename T>
101 struct ArrayPair : public BaseArrayPair
102 {
103  T* Input;
104  T* Output;
106 
107  ArrayPair(T* in, T* out, vtkIdType num, int numComp, vtkAbstractArray* outArray, T null)
108  : BaseArrayPair(num, numComp, outArray)
109  , Input(in)
110  , Output(out)
111  , NullValue(null)
112  {
113  }
114  ~ArrayPair() override = default; // calm down some finicky compilers
115 protected:
116  template <typename IdTypeT>
117  void Copy(IdTypeT inId, IdTypeT outId)
118  {
119  for (int j = 0; j < this->NumComp; ++j)
120  {
121  this->Output[outId * this->NumComp + j] =
122  static_cast<T>(this->Input[inId * this->NumComp + j]);
123  }
124  }
125 
126  template <typename IdTypeT>
127  void Interpolate(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
128  {
129  for (int j = 0; j < this->NumComp; ++j)
130  {
131  double v = 0.0;
132  for (int i = 0; i < numWeights; ++i)
133  {
134  v += weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
135  }
136  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
137  }
138  }
139 
140  template <typename IdTypeT>
141  void InterpolateOutput(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
142  {
143  for (int j = 0; j < this->NumComp; ++j)
144  {
145  double v = 0.0;
146  for (int i = 0; i < numWeights; ++i)
147  {
148  v += weights[i] * static_cast<double>(this->Output[ids[i] * this->NumComp + j]);
149  }
150  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
151  }
152  }
153 
154  template <typename IdTypeT>
155  void Average(int numPts, const IdTypeT* ids, IdTypeT outId)
156  {
157  for (int j = 0; j < this->NumComp; ++j)
158  {
159  double v = 0.0;
160  for (int i = 0; i < numPts; ++i)
161  {
162  v += static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
163  }
164  v /= static_cast<double>(numPts);
165  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
166  }
167  }
168 
169  template <typename IdTypeT>
170  void WeightedAverage(int numPts, const IdTypeT* ids, const double* weights, IdTypeT outId)
171  {
172  for (int j = 0; j < this->NumComp; ++j)
173  {
174  double v = 0.0;
175  for (int i = 0; i < numPts; ++i)
176  {
177  v += (weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]));
178  }
179  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
180  }
181  }
182 
183  template <typename IdTypeT>
184  void InterpolateEdge(IdTypeT v0, IdTypeT v1, double t, IdTypeT outId)
185  {
186  double v;
187  for (int j = 0; j < this->NumComp; ++j)
188  {
189  v = this->Input[v0 * this->NumComp + j] +
190  t * (this->Input[v1 * this->NumComp + j] - this->Input[v0 * this->NumComp + j]);
191  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
192  }
193  }
194 
195  template <typename IdTypeT>
196  void AssignNullValue(IdTypeT outId)
197  {
198  for (int j = 0; j < this->NumComp; ++j)
199  {
200  this->Output[outId * this->NumComp + j] = this->NullValue;
201  }
202  }
203 
204 public:
205  void Copy(vtkIdType inId, vtkIdType outId) override { this->Copy<vtkIdType>(inId, outId); }
207  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
208  {
209  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
210  }
212  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
213  {
214  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
215  }
216  void Average(int numPts, const vtkIdType* ids, vtkIdType outId) override
217  {
218  this->Average<vtkIdType>(numPts, ids, outId);
219  }
221  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) override
222  {
223  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
224  }
225  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
226  {
227  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
228  }
229  void AssignNullValue(vtkIdType outId) override { this->AssignNullValue<vtkIdType>(outId); }
230 #ifdef VTK_USE_64BIT_IDS
231  void Copy(unsigned int inId, unsigned int outId) override
232  {
233  this->Copy<unsigned int>(inId, outId);
234  }
235  void Interpolate(
236  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
237  {
238  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
239  }
240  void InterpolateOutput(
241  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
242  {
243  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
244  }
245  void Average(int numPts, const unsigned int* ids, unsigned int outId) override
246  {
247  this->Average<unsigned int>(numPts, ids, outId);
248  }
249  void WeightedAverage(
250  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) override
251  {
252  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
253  }
254  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) override
255  {
256  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
257  }
258  void AssignNullValue(unsigned int outId) override { this->AssignNullValue<unsigned int>(outId); }
259 #endif
260  void Copy(unsigned short inId, unsigned short outId) override
261  {
262  this->Copy<unsigned short>(inId, outId);
263  }
265  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
266  {
267  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
268  }
270  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
271  {
272  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
273  }
274  void Average(int numPts, const unsigned short* ids, unsigned short outId) override
275  {
276  this->Average<unsigned short>(numPts, ids, outId);
277  }
279  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) override
280  {
281  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
282  }
284  unsigned short v0, unsigned short v1, double t, unsigned short outId) override
285  {
286  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
287  }
288  void AssignNullValue(unsigned short outId) override
289  {
290  this->AssignNullValue<unsigned short>(outId);
291  }
292 
293  void Realloc(vtkIdType sze) override
294  {
295  this->OutputArray->Resize(sze);
296  this->OutputArray->SetNumberOfTuples(sze);
297  this->Output = static_cast<T*>(this->OutputArray->GetVoidPointer(0));
298  }
299 };
300 
301 template <>
303 {
306  double NullValue;
307 
308  ArrayPair(vtkStdString* in, vtkStdString* out, vtkIdType num, int numComp,
309  vtkAbstractArray* outArray, double null)
310  : BaseArrayPair(num, numComp, outArray)
311  , Input(in)
312  , Output(out)
313  , NullValue(null)
314  {
315  }
316  ~ArrayPair() override = default; // calm down some finicky compilers
317 protected:
318  template <typename IdTypeT>
319  void Copy(IdTypeT inId, IdTypeT outId)
320  {
321  for (int j = 0; j < this->NumComp; ++j)
322  {
323  this->Output[outId * this->NumComp + j] =
324  static_cast<vtkStdString>(this->Input[inId * this->NumComp + j]);
325  }
326  }
327  template <typename IdTypeT>
329  int numWeights, const IdTypeT* ids, const double* vtkNotUsed(weights), IdTypeT outId)
330  {
331  for (int i = 0; i < numWeights; ++i)
332  {
333  this->Copy(ids[i], outId);
334  }
335  }
336  template <typename IdTypeT>
337  void InterpolateOutput(int vtkNotUsed(numWeights), const IdTypeT* vtkNotUsed(ids),
338  const double* vtkNotUsed(weights), IdTypeT vtkNotUsed(outId))
339  {
340  }
341  template <typename IdTypeT>
342  void Average(int numPts, const IdTypeT* ids, IdTypeT outId)
343  {
344  for (int i = 0; i < numPts; ++i)
345  {
346  this->Copy(ids[i], outId);
347  }
348  }
349  template <typename IdTypeT>
351  int numPts, const IdTypeT* ids, const double* vtkNotUsed(weights), IdTypeT outId)
352  {
353  for (int i = 0; i < numPts; ++i)
354  {
355  this->Copy(ids[i], outId);
356  }
357  }
358  template <typename IdTypeT>
359  void InterpolateEdge(IdTypeT v0, IdTypeT v1, double vtkNotUsed(t), IdTypeT outId)
360  {
361  vtkStdString s;
362  for (int j = 0; j < this->NumComp; ++j)
363  {
364  s = std::string(this->Input[v0 * this->NumComp + j]) +
365  std::string(this->Input[v1 * this->NumComp + j]);
366  this->Output[outId * this->NumComp + j] = s;
367  }
368  }
369 
370  template <typename IdTypeT>
371  void AssignNullValue(IdTypeT outId)
372  {
373  for (int j = 0; j < this->NumComp; ++j)
374  {
375  this->Output[outId * this->NumComp + j] = std::to_string(this->NullValue);
376  }
377  }
378 
379 public:
380  void Copy(vtkIdType inId, vtkIdType outId) override { this->Copy<vtkIdType>(inId, outId); }
382  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
383  {
384  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
385  }
387  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
388  {
389  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
390  }
391  void Average(int numPts, const vtkIdType* ids, vtkIdType outId) override
392  {
393  this->Average<vtkIdType>(numPts, ids, outId);
394  }
396  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) override
397  {
398  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
399  }
400  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
401  {
402  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
403  }
404  void AssignNullValue(vtkIdType outId) override { this->AssignNullValue<vtkIdType>(outId); }
405 #ifdef VTK_USE_64BIT_IDS
406  void Copy(unsigned int inId, unsigned int outId) override
407  {
408  this->Copy<unsigned int>(inId, outId);
409  }
410  void Interpolate(
411  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
412  {
413  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
414  }
415  void InterpolateOutput(
416  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
417  {
418  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
419  }
420  void Average(int numPts, const unsigned int* ids, unsigned int outId) override
421  {
422  this->Average<unsigned int>(numPts, ids, outId);
423  }
424  void WeightedAverage(
425  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) override
426  {
427  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
428  }
429  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) override
430  {
431  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
432  }
433  void AssignNullValue(unsigned int outId) override { this->AssignNullValue<unsigned int>(outId); }
434 #endif
435  void Copy(unsigned short inId, unsigned short outId) override
436  {
437  this->Copy<unsigned short>(inId, outId);
438  }
440  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
441  {
442  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
443  }
445  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
446  {
447  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
448  }
449  void Average(int numPts, const unsigned short* ids, unsigned short outId) override
450  {
451  this->Average<unsigned short>(numPts, ids, outId);
452  }
454  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) override
455  {
456  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
457  }
459  unsigned short v0, unsigned short v1, double t, unsigned short outId) override
460  {
461  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
462  }
463  void AssignNullValue(unsigned short outId) override
464  {
465  this->AssignNullValue<unsigned short>(outId);
466  }
467 
468  void Realloc(vtkIdType sze) override
469  {
470  this->OutputArray->Resize(sze);
471  this->OutputArray->SetNumberOfTuples(sze);
472  this->Output = static_cast<vtkStdString*>(this->OutputArray->GetVoidPointer(0));
473  }
474 };
475 
476 // Type specific interpolation on a pair of data arrays with different types, where the
477 // output type is expected to be a real type (i.e., float or double).
478 template <typename TInput, typename TOutput>
480 {
481  TInput* Input;
482  TOutput* Output;
483  TOutput NullValue;
484 
486  TInput* in, TOutput* out, vtkIdType num, int numComp, vtkAbstractArray* outArray, TOutput null)
487  : BaseArrayPair(num, numComp, outArray)
488  , Input(in)
489  , Output(out)
490  , NullValue(null)
491  {
492  }
493  ~RealArrayPair() override = default; // calm down some finicky compilers
494 protected:
495  template <typename IdTypeT>
496  void Copy(IdTypeT inId, IdTypeT outId)
497  {
498  for (int j = 0; j < this->NumComp; ++j)
499  {
500  this->Output[outId * this->NumComp + j] =
501  static_cast<TOutput>(this->Input[inId * this->NumComp + j]);
502  }
503  }
504 
505  template <typename IdTypeT>
506  void Interpolate(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
507  {
508  for (int j = 0; j < this->NumComp; ++j)
509  {
510  double v = 0.0;
511  for (int i = 0; i < numWeights; ++i)
512  {
513  v += weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
514  }
515  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
516  }
517  }
518 
519  template <typename IdTypeT>
520  void InterpolateOutput(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
521  {
522  for (int j = 0; j < this->NumComp; ++j)
523  {
524  double v = 0.0;
525  for (int i = 0; i < numWeights; ++i)
526  {
527  v += weights[i] * static_cast<double>(this->Output[ids[i] * this->NumComp + j]);
528  }
529  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
530  }
531  }
532 
533  template <typename IdTypeT>
534  void Average(int numPts, const IdTypeT* ids, IdTypeT outId)
535  {
536  for (int j = 0; j < this->NumComp; ++j)
537  {
538  double v = 0.0;
539  for (int i = 0; i < numPts; ++i)
540  {
541  v += static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
542  }
543  v /= static_cast<double>(numPts);
544  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
545  }
546  }
547 
548  template <typename IdTypeT>
549  void WeightedAverage(int numPts, const IdTypeT* ids, const double* weights, IdTypeT outId)
550  {
551  for (int j = 0; j < this->NumComp; ++j)
552  {
553  double v = 0.0;
554  for (int i = 0; i < numPts; ++i)
555  {
556  v += (weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]));
557  }
558  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
559  }
560  }
561 
562  template <typename IdTypeT>
563  void InterpolateEdge(IdTypeT v0, IdTypeT v1, double t, IdTypeT outId)
564  {
565  double v;
566  for (int j = 0; j < this->NumComp; ++j)
567  {
568  v = this->Input[v0 * this->NumComp + j] +
569  t * (this->Input[v1 * this->NumComp + j] - this->Input[v0 * this->NumComp + j]);
570  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
571  }
572  }
573 
574  template <typename IdTypeT>
575  void AssignNullValue(IdTypeT outId)
576  {
577  for (int j = 0; j < this->NumComp; ++j)
578  {
579  this->Output[outId * this->NumComp + j] = this->NullValue;
580  }
581  }
582 
583 public:
584  void Copy(vtkIdType inId, vtkIdType outId) override { this->Copy<vtkIdType>(inId, outId); }
586  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
587  {
588  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
589  }
591  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
592  {
593  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
594  }
595  void Average(int numPts, const vtkIdType* ids, vtkIdType outId) override
596  {
597  this->Average<vtkIdType>(numPts, ids, outId);
598  }
600  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) override
601  {
602  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
603  }
604  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
605  {
606  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
607  }
608  void AssignNullValue(vtkIdType outId) override { this->AssignNullValue<vtkIdType>(outId); }
609 #ifdef VTK_USE_64BIT_IDS
610  void Copy(unsigned int inId, unsigned int outId) override
611  {
612  this->Copy<unsigned int>(inId, outId);
613  }
614  void Interpolate(
615  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
616  {
617  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
618  }
619  void InterpolateOutput(
620  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
621  {
622  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
623  }
624  void Average(int numPts, const unsigned int* ids, unsigned int outId) override
625  {
626  this->Average<unsigned int>(numPts, ids, outId);
627  }
628  void WeightedAverage(
629  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) override
630  {
631  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
632  }
633  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) override
634  {
635  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
636  }
637  void AssignNullValue(unsigned int outId) override { this->AssignNullValue<unsigned int>(outId); }
638 #endif
639  void Copy(unsigned short inId, unsigned short outId) override
640  {
641  this->Copy<unsigned short>(inId, outId);
642  }
644  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
645  {
646  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
647  }
649  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
650  {
651  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
652  }
653  void Average(int numPts, const unsigned short* ids, unsigned short outId) override
654  {
655  this->Average<unsigned short>(numPts, ids, outId);
656  }
658  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) override
659  {
660  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
661  }
663  unsigned short v0, unsigned short v1, double t, unsigned short outId) override
664  {
665  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
666  }
667  void AssignNullValue(unsigned short outId) override
668  {
669  this->AssignNullValue<unsigned short>(outId);
670  }
671 
672  void Realloc(vtkIdType sze) override
673  {
674  this->OutputArray->Resize(sze);
675  this->OutputArray->SetNumberOfTuples(sze);
676  this->Output = static_cast<TOutput*>(this->OutputArray->GetVoidPointer(0));
677  }
678 };
679 
680 // Forward declarations. This makes working with vtkTemplateMacro easier.
681 struct ArrayList;
682 
683 template <typename T>
685  ArrayList* list, T* inData, T* outData, vtkIdType numTuples, int numComp, T nullValue);
686 
687 // A list of the arrays to interpolate, and a method to invoke interpolation on the list
688 struct ArrayList
689 {
690  // The list of arrays, and the arrays not to process
691  std::vector<BaseArrayPair*> Arrays;
692  std::vector<vtkAbstractArray*> ExcludedArrays;
693 
694  // Add the arrays to interpolate here (from attribute data). Note that this method is
695  // not thread-safe due to its use of vtkDataSetAttributes.
697  double nullValue = 0.0, vtkTypeBool promote = true);
698 
699  // Add an array that interpolates from its own attribute values
701  vtkIdType numOutPts, vtkDataSetAttributes* attr, double nullValue = 0.0);
702 
703  // Add a pair of arrays (manual insertion). Returns the output array created,
704  // if any. No array may be created if \c inArray was previously marked as
705  // excluded using ExcludeArray().
707  vtkStdString& outArrayName, double nullValue, vtkTypeBool promote);
708 
709  // Any array excluded here is not added by AddArrays() or AddArrayPair, hence not
710  // processed. Also check whether an array is excluded.
713 
714  // Only you can prevent memory leaks!
716  {
717  for (auto& array : this->Arrays)
718  {
719  delete array;
720  }
721  }
722 
723 protected:
724  template <typename TIdType>
725  void Copy(TIdType inId, TIdType outId)
726  {
727  for (auto& array : this->Arrays)
728  {
729  array->Copy(inId, outId);
730  }
731  }
732 
733  template <typename TIdType>
734  void Interpolate(int numWeights, const TIdType* ids, const double* weights, TIdType outId)
735  {
736  for (auto& array : this->Arrays)
737  {
738  array->Interpolate(numWeights, ids, weights, outId);
739  }
740  }
741 
742  template <typename TIdType>
743  void InterpolateOutput(int numWeights, const TIdType* ids, const double* weights, TIdType outId)
744  {
745  for (auto& array : this->Arrays)
746  {
747  array->InterpolateOutput(numWeights, ids, weights, outId);
748  }
749  }
750 
751  template <typename TIdType>
752  void Average(int numPts, const TIdType* ids, TIdType outId)
753  {
754  for (auto& array : this->Arrays)
755  {
756  array->Average(numPts, ids, outId);
757  }
758  }
759 
760  template <typename TIdType>
761  void WeightedAverage(int numPts, const TIdType* ids, const double* weights, TIdType outId)
762  {
763  for (auto& array : this->Arrays)
764  {
765  array->WeightedAverage(numPts, ids, weights, outId);
766  }
767  }
768 
769  template <typename TIdType>
770  void InterpolateEdge(TIdType v0, TIdType v1, double t, TIdType outId)
771  {
772  for (auto& array : this->Arrays)
773  {
774  array->InterpolateEdge(v0, v1, t, outId);
775  }
776  }
777 
778  template <typename TIdType>
779  void AssignNullValue(TIdType outId)
780  {
781  for (auto& array : this->Arrays)
782  {
783  array->AssignNullValue(outId);
784  }
785  }
786 
787 public:
792  void Copy(vtkIdType inId, vtkIdType outId) { this->Copy<vtkIdType>(inId, outId); }
796  void Interpolate(int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId)
797  {
798  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
799  }
804  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId)
805  {
806  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
807  }
811  void Average(int numPts, const vtkIdType* ids, vtkIdType outId)
812  {
813  this->Average<vtkIdType>(numPts, ids, outId);
814  }
818  void WeightedAverage(int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId)
819  {
820  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
821  }
825  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId)
826  {
827  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
828  }
832  void AssignNullValue(vtkIdType outId) { this->AssignNullValue<vtkIdType>(outId); }
833 #ifdef VTK_USE_64BIT_IDS
838  void Copy(unsigned int inId, unsigned int outId) { this->Copy<unsigned int>(inId, outId); }
842  void Interpolate(
843  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId)
844  {
845  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
846  }
850  void InterpolateOutput(
851  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId)
852  {
853  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
854  }
858  void Average(int numPts, const unsigned int* ids, unsigned int outId)
859  {
860  this->Average<unsigned int>(numPts, ids, outId);
861  }
865  void WeightedAverage(
866  int numPts, const unsigned int* ids, const double* weights, unsigned int outId)
867  {
868  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
869  }
873  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId)
874  {
875  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
876  }
880  void AssignNullValue(unsigned int outId) { this->AssignNullValue<unsigned int>(outId); }
881 #endif
886  void Copy(unsigned short inId, unsigned short outId) { this->Copy<unsigned short>(inId, outId); }
891  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId)
892  {
893  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
894  }
899  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId)
900  {
901  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
902  }
906  void Average(int numPts, const unsigned short* ids, unsigned short outId)
907  {
908  this->Average<unsigned short>(numPts, ids, outId);
909  }
914  int numPts, const unsigned short* ids, const double* weights, unsigned short outId)
915  {
916  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
917  }
921  void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId)
922  {
923  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
924  }
928  void AssignNullValue(unsigned short outId) { this->AssignNullValue<unsigned short>(outId); }
929 
933  void Realloc(vtkIdType sze)
934  {
935  for (auto& array : this->Arrays)
936  {
937  array->Realloc(sze);
938  }
939  }
940 
944  vtkIdType GetNumberOfArrays() { return static_cast<vtkIdType>(this->Arrays.size()); }
945 };
946 
947 VTK_ABI_NAMESPACE_END
948 #include "vtkArrayListTemplate.txx"
949 
950 #endif
951 // VTK-HeaderTest-Exclude: vtkArrayListTemplate.h
Abstract superclass for all arrays.
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
virtual void * GetVoidPointer(vtkIdType valueIdx)=0
Return a void pointer.
represent and manipulate attribute data in a dataset
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
@ string
Definition: vtkX3D.h:490
void Average(int numPts, const vtkIdType *ids, vtkIdType outId)
Loop over the arrays and have them averaged.
void Copy(unsigned short inId, unsigned short outId)
Loop over the array pairs and copy data from one to another.
void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId)
Loop over the arrays perform edge interpolation.
void InterpolateEdge(TIdType v0, TIdType v1, double t, TIdType outId)
void AddSelfInterpolatingArrays(vtkIdType numOutPts, vtkDataSetAttributes *attr, double nullValue=0.0)
void Interpolate(int numWeights, const TIdType *ids, const double *weights, TIdType outId)
void AssignNullValue(vtkIdType outId)
Loop over the arrays and assign the null value.
void WeightedAverage(int numPts, const vtkIdType *ids, const double *weights, vtkIdType outId)
Loop over the arrays and weighted average the attributes.
void Interpolate(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId)
Loop over the arrays and have them interpolate themselves.
vtkAbstractArray * AddArrayPair(vtkIdType numTuples, vtkAbstractArray *inArray, vtkStdString &outArrayName, double nullValue, vtkTypeBool promote)
vtkTypeBool IsExcluded(vtkAbstractArray *da)
std::vector< vtkAbstractArray * > ExcludedArrays
void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId)
Loop over the arrays perform edge interpolation.
vtkIdType GetNumberOfArrays()
Return the number of arrays.
void Copy(vtkIdType inId, vtkIdType outId)
Loop over the array pairs and copy data from one to another.
void AddArrays(vtkIdType numOutPts, vtkDataSetAttributes *inPD, vtkDataSetAttributes *outPD, double nullValue=0.0, vtkTypeBool promote=true)
void AssignNullValue(TIdType outId)
void Average(int numPts, const TIdType *ids, TIdType outId)
void WeightedAverage(int numPts, const unsigned short *ids, const double *weights, unsigned short outId)
Loop over the arrays and weighted average the attributes.
void ExcludeArray(vtkAbstractArray *da)
void Average(int numPts, const unsigned short *ids, unsigned short outId)
Loop over the arrays and have them averaged.
void InterpolateOutput(int numWeights, const TIdType *ids, const double *weights, TIdType outId)
void Realloc(vtkIdType sze)
Extend (realloc) the arrays.
void InterpolateOutput(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId)
Loop over the arrays and have them interpolate themselves based on the output arrays.
void WeightedAverage(int numPts, const TIdType *ids, const double *weights, TIdType outId)
void Copy(TIdType inId, TIdType outId)
std::vector< BaseArrayPair * > Arrays
void AssignNullValue(unsigned short outId)
Loop over the arrays and assign the null value.
void InterpolateOutput(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId)
Loop over the arrays and have them interpolate themselves based on the output arrays.
void Interpolate(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId)
Loop over the arrays and have them interpolate themselves.
ArrayPair(vtkStdString *in, vtkStdString *out, vtkIdType num, int numComp, vtkAbstractArray *outArray, double null)
void Realloc(vtkIdType sze) override
void AssignNullValue(IdTypeT outId)
void Copy(unsigned short inId, unsigned short outId) override
void InterpolateOutput(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId) override
void Copy(vtkIdType inId, vtkIdType outId) override
void Interpolate(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId) override
void Interpolate(int numWeights, const IdTypeT *ids, const double *vtkNotUsed(weights), IdTypeT outId)
void WeightedAverage(int numPts, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void AssignNullValue(vtkIdType outId) override
void AssignNullValue(unsigned short outId) override
~ArrayPair() override=default
void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
void InterpolateOutput(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId) override
void Interpolate(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void InterpolateOutput(int vtkNotUsed(numWeights), const IdTypeT *vtkNotUsed(ids), const double *vtkNotUsed(weights), IdTypeT vtkNotUsed(outId))
void Copy(IdTypeT inId, IdTypeT outId)
void InterpolateEdge(IdTypeT v0, IdTypeT v1, double vtkNotUsed(t), IdTypeT outId)
void WeightedAverage(int numPts, const IdTypeT *ids, const double *vtkNotUsed(weights), IdTypeT outId)
void Average(int numPts, const IdTypeT *ids, IdTypeT outId)
void Average(int numPts, const vtkIdType *ids, vtkIdType outId) override
void Average(int numPts, const unsigned short *ids, unsigned short outId) override
void WeightedAverage(int numPts, const unsigned short *ids, const double *weights, unsigned short outId) override
void AssignNullValue(unsigned short outId) override
void Interpolate(int numWeights, const IdTypeT *ids, const double *weights, IdTypeT outId)
void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
void AssignNullValue(IdTypeT outId)
void InterpolateOutput(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void Average(int numPts, const unsigned short *ids, unsigned short outId) override
void InterpolateOutput(int numWeights, const IdTypeT *ids, const double *weights, IdTypeT outId)
void AssignNullValue(vtkIdType outId) override
void Copy(unsigned short inId, unsigned short outId) override
void Average(int numPts, const vtkIdType *ids, vtkIdType outId) override
void WeightedAverage(int numPts, const unsigned short *ids, const double *weights, unsigned short outId) override
void WeightedAverage(int numPts, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void Copy(IdTypeT inId, IdTypeT outId)
~ArrayPair() override=default
ArrayPair(T *in, T *out, vtkIdType num, int numComp, vtkAbstractArray *outArray, T null)
void Interpolate(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void Average(int numPts, const IdTypeT *ids, IdTypeT outId)
void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId) override
void Copy(vtkIdType inId, vtkIdType outId) override
void Realloc(vtkIdType sze) override
void InterpolateOutput(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId) override
void WeightedAverage(int numPts, const IdTypeT *ids, const double *weights, IdTypeT outId)
void InterpolateEdge(IdTypeT v0, IdTypeT v1, double t, IdTypeT outId)
void Interpolate(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId) override
virtual void WeightedAverage(int numPts, const unsigned short *ids, const double *weights, unsigned short outId)=0
virtual void InterpolateOutput(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId)=0
BaseArrayPair(vtkIdType num, int numComp, vtkAbstractArray *outArray)
virtual void Average(int numPts, const vtkIdType *ids, vtkIdType outId)=0
virtual void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId)=0
virtual void Average(int numPts, const unsigned short *ids, unsigned short outId)=0
virtual void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId)=0
virtual void AssignNullValue(unsigned short outId)=0
virtual void AssignNullValue(vtkIdType outId)=0
virtual void Copy(vtkIdType inId, vtkIdType outId)=0
virtual ~BaseArrayPair()=default
virtual void Interpolate(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId)=0
virtual void WeightedAverage(int numPts, const vtkIdType *ids, const double *weights, vtkIdType outId)=0
virtual void Realloc(vtkIdType sze)=0
virtual void Copy(unsigned short inId, unsigned short outId)=0
vtkSmartPointer< vtkAbstractArray > OutputArray
virtual void InterpolateOutput(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId)=0
virtual void Interpolate(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId)=0
void InterpolateEdge(IdTypeT v0, IdTypeT v1, double t, IdTypeT outId)
void Interpolate(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void Average(int numPts, const unsigned short *ids, unsigned short outId) override
void InterpolateOutput(int numWeights, const vtkIdType *ids, const double *weights, vtkIdType outId) override
void InterpolateOutput(int numWeights, const IdTypeT *ids, const double *weights, IdTypeT outId)
~RealArrayPair() override=default
void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
void Interpolate(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId) override
void Copy(IdTypeT inId, IdTypeT outId)
void Copy(vtkIdType inId, vtkIdType outId) override
void AssignNullValue(vtkIdType outId) override
void Realloc(vtkIdType sze) override
void Average(int numPts, const IdTypeT *ids, IdTypeT outId)
void Copy(unsigned short inId, unsigned short outId) override
void AssignNullValue(unsigned short outId) override
void Average(int numPts, const vtkIdType *ids, vtkIdType outId) override
void AssignNullValue(IdTypeT outId)
void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId) override
void InterpolateOutput(int numWeights, const unsigned short *ids, const double *weights, unsigned short outId) override
RealArrayPair(TInput *in, TOutput *out, vtkIdType num, int numComp, vtkAbstractArray *outArray, TOutput null)
void WeightedAverage(int numPts, const unsigned short *ids, const double *weights, unsigned short outId) override
void WeightedAverage(int numPts, const IdTypeT *ids, const double *weights, IdTypeT outId)
void Interpolate(int numWeights, const IdTypeT *ids, const double *weights, IdTypeT outId)
void WeightedAverage(int numPts, const vtkIdType *ids, const double *weights, vtkIdType outId) override
int vtkTypeBool
Definition: vtkABI.h:64
void CreateArrayPair(ArrayList *list, T *inData, T *outData, vtkIdType numTuples, int numComp, T nullValue)
int vtkIdType
Definition: vtkType.h:315