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