VTK  9.2.20230328
vtkArrayListTemplate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkArrayListTemplate.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See LICENSE file for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
45 #ifndef vtkArrayListTemplate_h
46 #define vtkArrayListTemplate_h
47 
48 #include "vtkAbstractArray.h"
49 #include "vtkDataSetAttributes.h"
50 #include "vtkSmartPointer.h"
51 #include "vtkStdString.h"
52 
53 #include <algorithm>
54 #include <vector>
55 
56 // Create a generic class supporting virtual dispatch to type-specific
57 // subclasses.
58 VTK_ABI_NAMESPACE_BEGIN
60 {
62  int NumComp;
64 
65  BaseArrayPair(vtkIdType num, int numComp, vtkAbstractArray* outArray)
66  : Num(num)
67  , NumComp(numComp)
68  , OutputArray(outArray)
69  {
70  }
71  virtual ~BaseArrayPair() = default;
72 
73  virtual void Copy(vtkIdType inId, vtkIdType outId) = 0;
74  virtual void Interpolate(
75  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) = 0;
76  virtual void InterpolateOutput(
77  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) = 0;
78  virtual void Average(int numPts, const vtkIdType* ids, vtkIdType outId) = 0;
79  virtual void WeightedAverage(
80  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) = 0;
81  virtual void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) = 0;
82  virtual void AssignNullValue(vtkIdType outId) = 0;
83 #ifdef VTK_USE_64BIT_IDS
84  virtual void Copy(unsigned int inId, unsigned int outId) = 0;
85  virtual void Interpolate(
86  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) = 0;
87  virtual void InterpolateOutput(
88  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) = 0;
89  virtual void Average(int numPts, const unsigned int* ids, unsigned int outId) = 0;
90  virtual void WeightedAverage(
91  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) = 0;
92  virtual void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) = 0;
93  virtual void AssignNullValue(unsigned int outId) = 0;
94 #endif
95  virtual void Copy(unsigned short inId, unsigned short outId) = 0;
96  virtual void Interpolate(
97  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) = 0;
98  virtual void InterpolateOutput(
99  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) = 0;
100  virtual void Average(int numPts, const unsigned short* ids, unsigned short outId) = 0;
101  virtual void WeightedAverage(
102  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) = 0;
103  virtual void InterpolateEdge(
104  unsigned short v0, unsigned short v1, double t, unsigned short outId) = 0;
105  virtual void AssignNullValue(unsigned short outId) = 0;
106 
107  virtual void Realloc(vtkIdType sze) = 0;
108 };
109 
110 // Type specific interpolation on a matched pair of data arrays
111 template <typename T>
112 struct ArrayPair : public BaseArrayPair
113 {
114  T* Input;
115  T* Output;
117 
118  ArrayPair(T* in, T* out, vtkIdType num, int numComp, vtkAbstractArray* outArray, T null)
119  : BaseArrayPair(num, numComp, outArray)
120  , Input(in)
121  , Output(out)
122  , NullValue(null)
123  {
124  }
125  ~ArrayPair() override = default; // calm down some finicky compilers
126 protected:
127  template <typename IdTypeT>
128  void Copy(IdTypeT inId, IdTypeT outId)
129  {
130  for (int j = 0; j < this->NumComp; ++j)
131  {
132  this->Output[outId * this->NumComp + j] =
133  static_cast<T>(this->Input[inId * this->NumComp + j]);
134  }
135  }
136 
137  template <typename IdTypeT>
138  void Interpolate(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
139  {
140  for (int j = 0; j < this->NumComp; ++j)
141  {
142  double v = 0.0;
143  for (int i = 0; i < numWeights; ++i)
144  {
145  v += weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
146  }
147  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
148  }
149  }
150 
151  template <typename IdTypeT>
152  void InterpolateOutput(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
153  {
154  for (int j = 0; j < this->NumComp; ++j)
155  {
156  double v = 0.0;
157  for (int i = 0; i < numWeights; ++i)
158  {
159  v += weights[i] * static_cast<double>(this->Output[ids[i] * this->NumComp + j]);
160  }
161  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
162  }
163  }
164 
165  template <typename IdTypeT>
166  void Average(int numPts, const IdTypeT* ids, IdTypeT outId)
167  {
168  for (int j = 0; j < this->NumComp; ++j)
169  {
170  double v = 0.0;
171  for (int i = 0; i < numPts; ++i)
172  {
173  v += static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
174  }
175  v /= static_cast<double>(numPts);
176  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
177  }
178  }
179 
180  template <typename IdTypeT>
181  void WeightedAverage(int numPts, const IdTypeT* ids, const double* weights, IdTypeT outId)
182  {
183  for (int j = 0; j < this->NumComp; ++j)
184  {
185  double v = 0.0;
186  for (int i = 0; i < numPts; ++i)
187  {
188  v += (weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]));
189  }
190  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
191  }
192  }
193 
194  template <typename IdTypeT>
195  void InterpolateEdge(IdTypeT v0, IdTypeT v1, double t, IdTypeT outId)
196  {
197  double v;
198  for (int j = 0; j < this->NumComp; ++j)
199  {
200  v = this->Input[v0 * this->NumComp + j] +
201  t * (this->Input[v1 * this->NumComp + j] - this->Input[v0 * this->NumComp + j]);
202  this->Output[outId * this->NumComp + j] = static_cast<T>(v);
203  }
204  }
205 
206  template <typename IdTypeT>
207  void AssignNullValue(IdTypeT outId)
208  {
209  for (int j = 0; j < this->NumComp; ++j)
210  {
211  this->Output[outId * this->NumComp + j] = this->NullValue;
212  }
213  }
214 
215 public:
216  void Copy(vtkIdType inId, vtkIdType outId) override { this->Copy<vtkIdType>(inId, outId); }
218  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
219  {
220  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
221  }
223  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
224  {
225  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
226  }
227  void Average(int numPts, const vtkIdType* ids, vtkIdType outId) override
228  {
229  this->Average<vtkIdType>(numPts, ids, outId);
230  }
232  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) override
233  {
234  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
235  }
236  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
237  {
238  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
239  }
240  void AssignNullValue(vtkIdType outId) override { this->AssignNullValue<vtkIdType>(outId); }
241 #ifdef VTK_USE_64BIT_IDS
242  void Copy(unsigned int inId, unsigned int outId) override
243  {
244  this->Copy<unsigned int>(inId, outId);
245  }
246  void Interpolate(
247  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
248  {
249  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
250  }
251  void InterpolateOutput(
252  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
253  {
254  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
255  }
256  void Average(int numPts, const unsigned int* ids, unsigned int outId) override
257  {
258  this->Average<unsigned int>(numPts, ids, outId);
259  }
260  void WeightedAverage(
261  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) override
262  {
263  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
264  }
265  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) override
266  {
267  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
268  }
269  void AssignNullValue(unsigned int outId) override { this->AssignNullValue<unsigned int>(outId); }
270 #endif
271  void Copy(unsigned short inId, unsigned short outId) override
272  {
273  this->Copy<unsigned short>(inId, outId);
274  }
276  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
277  {
278  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
279  }
281  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
282  {
283  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
284  }
285  void Average(int numPts, const unsigned short* ids, unsigned short outId) override
286  {
287  this->Average<unsigned short>(numPts, ids, outId);
288  }
290  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) override
291  {
292  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
293  }
295  unsigned short v0, unsigned short v1, double t, unsigned short outId) override
296  {
297  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
298  }
299  void AssignNullValue(unsigned short outId) override
300  {
301  this->AssignNullValue<unsigned short>(outId);
302  }
303 
304  void Realloc(vtkIdType sze) override
305  {
306  this->OutputArray->Resize(sze);
307  this->OutputArray->SetNumberOfTuples(sze);
308  this->Output = static_cast<T*>(this->OutputArray->GetVoidPointer(0));
309  }
310 };
311 
312 template <>
314 {
317  double NullValue;
318 
319  ArrayPair(vtkStdString* in, vtkStdString* out, vtkIdType num, int numComp,
320  vtkAbstractArray* outArray, double null)
321  : BaseArrayPair(num, numComp, outArray)
322  , Input(in)
323  , Output(out)
324  , NullValue(null)
325  {
326  }
327  ~ArrayPair() override = default; // calm down some finicky compilers
328 protected:
329  template <typename IdTypeT>
330  void Copy(IdTypeT inId, IdTypeT outId)
331  {
332  for (int j = 0; j < this->NumComp; ++j)
333  {
334  this->Output[outId * this->NumComp + j] =
335  static_cast<vtkStdString>(this->Input[inId * this->NumComp + j]);
336  }
337  }
338  template <typename IdTypeT>
340  int numWeights, const IdTypeT* ids, const double* vtkNotUsed(weights), IdTypeT outId)
341  {
342  for (int i = 0; i < numWeights; ++i)
343  {
344  this->Copy(ids[i], outId);
345  }
346  }
347  template <typename IdTypeT>
348  void InterpolateOutput(int vtkNotUsed(numWeights), const IdTypeT* vtkNotUsed(ids),
349  const double* vtkNotUsed(weights), IdTypeT vtkNotUsed(outId))
350  {
351  }
352  template <typename IdTypeT>
353  void Average(int numPts, const IdTypeT* ids, IdTypeT outId)
354  {
355  for (int i = 0; i < numPts; ++i)
356  {
357  this->Copy(ids[i], outId);
358  }
359  }
360  template <typename IdTypeT>
362  int numPts, const IdTypeT* ids, const double* vtkNotUsed(weights), IdTypeT outId)
363  {
364  for (int i = 0; i < numPts; ++i)
365  {
366  this->Copy(ids[i], outId);
367  }
368  }
369  template <typename IdTypeT>
370  void InterpolateEdge(IdTypeT v0, IdTypeT v1, double vtkNotUsed(t), IdTypeT outId)
371  {
372  vtkStdString s;
373  for (int j = 0; j < this->NumComp; ++j)
374  {
375  s = std::string(this->Input[v0 * this->NumComp + j]) +
376  std::string(this->Input[v1 * this->NumComp + j]);
377  this->Output[outId * this->NumComp + j] = s;
378  }
379  }
380 
381  template <typename IdTypeT>
382  void AssignNullValue(IdTypeT outId)
383  {
384  for (int j = 0; j < this->NumComp; ++j)
385  {
386  this->Output[outId * this->NumComp + j] = std::to_string(this->NullValue);
387  }
388  }
389 
390 public:
391  void Copy(vtkIdType inId, vtkIdType outId) override { this->Copy<vtkIdType>(inId, outId); }
393  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
394  {
395  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
396  }
398  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
399  {
400  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
401  }
402  void Average(int numPts, const vtkIdType* ids, vtkIdType outId) override
403  {
404  this->Average<vtkIdType>(numPts, ids, outId);
405  }
407  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) override
408  {
409  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
410  }
411  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
412  {
413  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
414  }
415  void AssignNullValue(vtkIdType outId) override { this->AssignNullValue<vtkIdType>(outId); }
416 #ifdef VTK_USE_64BIT_IDS
417  void Copy(unsigned int inId, unsigned int outId) override
418  {
419  this->Copy<unsigned int>(inId, outId);
420  }
421  void Interpolate(
422  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
423  {
424  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
425  }
426  void InterpolateOutput(
427  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
428  {
429  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
430  }
431  void Average(int numPts, const unsigned int* ids, unsigned int outId) override
432  {
433  this->Average<unsigned int>(numPts, ids, outId);
434  }
435  void WeightedAverage(
436  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) override
437  {
438  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
439  }
440  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) override
441  {
442  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
443  }
444  void AssignNullValue(unsigned int outId) override { this->AssignNullValue<unsigned int>(outId); }
445 #endif
446  void Copy(unsigned short inId, unsigned short outId) override
447  {
448  this->Copy<unsigned short>(inId, outId);
449  }
451  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
452  {
453  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
454  }
456  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
457  {
458  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
459  }
460  void Average(int numPts, const unsigned short* ids, unsigned short outId) override
461  {
462  this->Average<unsigned short>(numPts, ids, outId);
463  }
465  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) override
466  {
467  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
468  }
470  unsigned short v0, unsigned short v1, double t, unsigned short outId) override
471  {
472  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
473  }
474  void AssignNullValue(unsigned short outId) override
475  {
476  this->AssignNullValue<unsigned short>(outId);
477  }
478 
479  void Realloc(vtkIdType sze) override
480  {
481  this->OutputArray->Resize(sze);
482  this->OutputArray->SetNumberOfTuples(sze);
483  this->Output = static_cast<vtkStdString*>(this->OutputArray->GetVoidPointer(0));
484  }
485 };
486 
487 // Type specific interpolation on a pair of data arrays with different types, where the
488 // output type is expected to be a real type (i.e., float or double).
489 template <typename TInput, typename TOutput>
491 {
492  TInput* Input;
493  TOutput* Output;
494  TOutput NullValue;
495 
497  TInput* in, TOutput* out, vtkIdType num, int numComp, vtkAbstractArray* outArray, TOutput null)
498  : BaseArrayPair(num, numComp, outArray)
499  , Input(in)
500  , Output(out)
501  , NullValue(null)
502  {
503  }
504  ~RealArrayPair() override = default; // calm down some finicky compilers
505 protected:
506  template <typename IdTypeT>
507  void Copy(IdTypeT inId, IdTypeT outId)
508  {
509  for (int j = 0; j < this->NumComp; ++j)
510  {
511  this->Output[outId * this->NumComp + j] =
512  static_cast<TOutput>(this->Input[inId * this->NumComp + j]);
513  }
514  }
515 
516  template <typename IdTypeT>
517  void Interpolate(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
518  {
519  for (int j = 0; j < this->NumComp; ++j)
520  {
521  double v = 0.0;
522  for (int i = 0; i < numWeights; ++i)
523  {
524  v += weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
525  }
526  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
527  }
528  }
529 
530  template <typename IdTypeT>
531  void InterpolateOutput(int numWeights, const IdTypeT* ids, const double* weights, IdTypeT outId)
532  {
533  for (int j = 0; j < this->NumComp; ++j)
534  {
535  double v = 0.0;
536  for (int i = 0; i < numWeights; ++i)
537  {
538  v += weights[i] * static_cast<double>(this->Output[ids[i] * this->NumComp + j]);
539  }
540  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
541  }
542  }
543 
544  template <typename IdTypeT>
545  void Average(int numPts, const IdTypeT* ids, IdTypeT outId)
546  {
547  for (int j = 0; j < this->NumComp; ++j)
548  {
549  double v = 0.0;
550  for (int i = 0; i < numPts; ++i)
551  {
552  v += static_cast<double>(this->Input[ids[i] * this->NumComp + j]);
553  }
554  v /= static_cast<double>(numPts);
555  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
556  }
557  }
558 
559  template <typename IdTypeT>
560  void WeightedAverage(int numPts, const IdTypeT* ids, const double* weights, IdTypeT outId)
561  {
562  for (int j = 0; j < this->NumComp; ++j)
563  {
564  double v = 0.0;
565  for (int i = 0; i < numPts; ++i)
566  {
567  v += (weights[i] * static_cast<double>(this->Input[ids[i] * this->NumComp + j]));
568  }
569  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
570  }
571  }
572 
573  template <typename IdTypeT>
574  void InterpolateEdge(IdTypeT v0, IdTypeT v1, double t, IdTypeT outId)
575  {
576  double v;
577  for (int j = 0; j < this->NumComp; ++j)
578  {
579  v = this->Input[v0 * this->NumComp + j] +
580  t * (this->Input[v1 * this->NumComp + j] - this->Input[v0 * this->NumComp + j]);
581  this->Output[outId * this->NumComp + j] = static_cast<TOutput>(v);
582  }
583  }
584 
585  template <typename IdTypeT>
586  void AssignNullValue(IdTypeT outId)
587  {
588  for (int j = 0; j < this->NumComp; ++j)
589  {
590  this->Output[outId * this->NumComp + j] = this->NullValue;
591  }
592  }
593 
594 public:
595  void Copy(vtkIdType inId, vtkIdType outId) override { this->Copy<vtkIdType>(inId, outId); }
597  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
598  {
599  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
600  }
602  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId) override
603  {
604  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
605  }
606  void Average(int numPts, const vtkIdType* ids, vtkIdType outId) override
607  {
608  this->Average<vtkIdType>(numPts, ids, outId);
609  }
611  int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId) override
612  {
613  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
614  }
615  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId) override
616  {
617  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
618  }
619  void AssignNullValue(vtkIdType outId) override { this->AssignNullValue<vtkIdType>(outId); }
620 #ifdef VTK_USE_64BIT_IDS
621  void Copy(unsigned int inId, unsigned int outId) override
622  {
623  this->Copy<unsigned int>(inId, outId);
624  }
625  void Interpolate(
626  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
627  {
628  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
629  }
630  void InterpolateOutput(
631  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId) override
632  {
633  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
634  }
635  void Average(int numPts, const unsigned int* ids, unsigned int outId) override
636  {
637  this->Average<unsigned int>(numPts, ids, outId);
638  }
639  void WeightedAverage(
640  int numPts, const unsigned int* ids, const double* weights, unsigned int outId) override
641  {
642  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
643  }
644  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId) override
645  {
646  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
647  }
648  void AssignNullValue(unsigned int outId) override { this->AssignNullValue<unsigned int>(outId); }
649 #endif
650  void Copy(unsigned short inId, unsigned short outId) override
651  {
652  this->Copy<unsigned short>(inId, outId);
653  }
655  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
656  {
657  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
658  }
660  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId) override
661  {
662  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
663  }
664  void Average(int numPts, const unsigned short* ids, unsigned short outId) override
665  {
666  this->Average<unsigned short>(numPts, ids, outId);
667  }
669  int numPts, const unsigned short* ids, const double* weights, unsigned short outId) override
670  {
671  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
672  }
674  unsigned short v0, unsigned short v1, double t, unsigned short outId) override
675  {
676  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
677  }
678  void AssignNullValue(unsigned short outId) override
679  {
680  this->AssignNullValue<unsigned short>(outId);
681  }
682 
683  void Realloc(vtkIdType sze) override
684  {
685  this->OutputArray->Resize(sze);
686  this->OutputArray->SetNumberOfTuples(sze);
687  this->Output = static_cast<TOutput*>(this->OutputArray->GetVoidPointer(0));
688  }
689 };
690 
691 // Forward declarations. This makes working with vtkTemplateMacro easier.
692 struct ArrayList;
693 
694 template <typename T>
696  ArrayList* list, T* inData, T* outData, vtkIdType numTuples, int numComp, T nullValue);
697 
698 // A list of the arrays to interpolate, and a method to invoke interpolation on the list
699 struct ArrayList
700 {
701  // The list of arrays, and the arrays not to process
702  std::vector<BaseArrayPair*> Arrays;
703  std::vector<vtkAbstractArray*> ExcludedArrays;
704 
705  // Add the arrays to interpolate here (from attribute data). Note that this method is
706  // not thread-safe due to its use of vtkDataSetAttributes.
708  double nullValue = 0.0, vtkTypeBool promote = true);
709 
710  // Add an array that interpolates from its own attribute values
712  vtkIdType numOutPts, vtkDataSetAttributes* attr, double nullValue = 0.0);
713 
714  // Add a pair of arrays (manual insertion). Returns the output array created,
715  // if any. No array may be created if \c inArray was previously marked as
716  // excluded using ExcludeArray().
718  vtkStdString& outArrayName, double nullValue, vtkTypeBool promote);
719 
720  // Any array excluded here is not added by AddArrays() or AddArrayPair, hence not
721  // processed. Also check whether an array is excluded.
724 
725  // Only you can prevent memory leaks!
727  {
728  for (auto& array : this->Arrays)
729  {
730  delete array;
731  }
732  }
733 
734 protected:
735  template <typename TIdType>
736  void Copy(TIdType inId, TIdType outId)
737  {
738  for (auto& array : this->Arrays)
739  {
740  array->Copy(inId, outId);
741  }
742  }
743 
744  template <typename TIdType>
745  void Interpolate(int numWeights, const TIdType* ids, const double* weights, TIdType outId)
746  {
747  for (auto& array : this->Arrays)
748  {
749  array->Interpolate(numWeights, ids, weights, outId);
750  }
751  }
752 
753  template <typename TIdType>
754  void InterpolateOutput(int numWeights, const TIdType* ids, const double* weights, TIdType outId)
755  {
756  for (auto& array : this->Arrays)
757  {
758  array->InterpolateOutput(numWeights, ids, weights, outId);
759  }
760  }
761 
762  template <typename TIdType>
763  void Average(int numPts, const TIdType* ids, TIdType outId)
764  {
765  for (auto& array : this->Arrays)
766  {
767  array->Average(numPts, ids, outId);
768  }
769  }
770 
771  template <typename TIdType>
772  void WeightedAverage(int numPts, const TIdType* ids, const double* weights, TIdType outId)
773  {
774  for (auto& array : this->Arrays)
775  {
776  array->WeightedAverage(numPts, ids, weights, outId);
777  }
778  }
779 
780  template <typename TIdType>
781  void InterpolateEdge(TIdType v0, TIdType v1, double t, TIdType outId)
782  {
783  for (auto& array : this->Arrays)
784  {
785  array->InterpolateEdge(v0, v1, t, outId);
786  }
787  }
788 
789  template <typename TIdType>
790  void AssignNullValue(TIdType outId)
791  {
792  for (auto& array : this->Arrays)
793  {
794  array->AssignNullValue(outId);
795  }
796  }
797 
798 public:
803  void Copy(vtkIdType inId, vtkIdType outId) { this->Copy<vtkIdType>(inId, outId); }
807  void Interpolate(int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId)
808  {
809  this->Interpolate<vtkIdType>(numWeights, ids, weights, outId);
810  }
815  int numWeights, const vtkIdType* ids, const double* weights, vtkIdType outId)
816  {
817  this->InterpolateOutput<vtkIdType>(numWeights, ids, weights, outId);
818  }
822  void Average(int numPts, const vtkIdType* ids, vtkIdType outId)
823  {
824  this->Average<vtkIdType>(numPts, ids, outId);
825  }
829  void WeightedAverage(int numPts, const vtkIdType* ids, const double* weights, vtkIdType outId)
830  {
831  this->WeightedAverage<vtkIdType>(numPts, ids, weights, outId);
832  }
836  void InterpolateEdge(vtkIdType v0, vtkIdType v1, double t, vtkIdType outId)
837  {
838  this->InterpolateEdge<vtkIdType>(v0, v1, t, outId);
839  }
843  void AssignNullValue(vtkIdType outId) { this->AssignNullValue<vtkIdType>(outId); }
844 #ifdef VTK_USE_64BIT_IDS
849  void Copy(unsigned int inId, unsigned int outId) { this->Copy<unsigned int>(inId, outId); }
853  void Interpolate(
854  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId)
855  {
856  this->Interpolate<unsigned int>(numWeights, ids, weights, outId);
857  }
861  void InterpolateOutput(
862  int numWeights, const unsigned int* ids, const double* weights, unsigned int outId)
863  {
864  this->InterpolateOutput<unsigned int>(numWeights, ids, weights, outId);
865  }
869  void Average(int numPts, const unsigned int* ids, unsigned int outId)
870  {
871  this->Average<unsigned int>(numPts, ids, outId);
872  }
876  void WeightedAverage(
877  int numPts, const unsigned int* ids, const double* weights, unsigned int outId)
878  {
879  this->WeightedAverage<unsigned int>(numPts, ids, weights, outId);
880  }
884  void InterpolateEdge(unsigned int v0, unsigned int v1, double t, unsigned int outId)
885  {
886  this->InterpolateEdge<unsigned int>(v0, v1, t, outId);
887  }
891  void AssignNullValue(unsigned int outId) { this->AssignNullValue<unsigned int>(outId); }
892 #endif
897  void Copy(unsigned short inId, unsigned short outId) { this->Copy<unsigned short>(inId, outId); }
902  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId)
903  {
904  this->Interpolate<unsigned short>(numWeights, ids, weights, outId);
905  }
910  int numWeights, const unsigned short* ids, const double* weights, unsigned short outId)
911  {
912  this->InterpolateOutput<unsigned short>(numWeights, ids, weights, outId);
913  }
917  void Average(int numPts, const unsigned short* ids, unsigned short outId)
918  {
919  this->Average<unsigned short>(numPts, ids, outId);
920  }
925  int numPts, const unsigned short* ids, const double* weights, unsigned short outId)
926  {
927  this->WeightedAverage<unsigned short>(numPts, ids, weights, outId);
928  }
932  void InterpolateEdge(unsigned short v0, unsigned short v1, double t, unsigned short outId)
933  {
934  this->InterpolateEdge<unsigned short>(v0, v1, t, outId);
935  }
939  void AssignNullValue(unsigned short outId) { this->AssignNullValue<unsigned short>(outId); }
940 
944  void Realloc(vtkIdType sze)
945  {
946  for (auto& array : this->Arrays)
947  {
948  array->Realloc(sze);
949  }
950  }
951 
955  vtkIdType GetNumberOfArrays() { return static_cast<vtkIdType>(this->Arrays.size()); }
956 };
957 
958 VTK_ABI_NAMESPACE_END
959 #include "vtkArrayListTemplate.txx"
960 
961 #endif
962 // 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:110
@ string
Definition: vtkX3D.h:502
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:71
void CreateArrayPair(ArrayList *list, T *inData, T *outData, vtkIdType numTuples, int numComp, T nullValue)
int vtkIdType
Definition: vtkType.h:327