File: vtkArrayListTemplate.txx

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (179 lines) | stat: -rw-r--r-- 6,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkArrayListTemplate.txx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See LICENSE file for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkArrayListTemplate.h"
#include "vtkFloatArray.h"

#include <cassert>

#ifndef vtkArrayListTemplate_txx
#define vtkArrayListTemplate_txx

//----------------------------------------------------------------------------
// Sort of a little object factory (in conjunction w/ vtkTemplateMacro())
template <typename T>
void CreateArrayPair(ArrayList *list, T *inData, T *outData,
                     vtkIdType numPts, int numComp, vtkDataArray *outArray, T nullValue)
{
  ArrayPair<T> *pair = new ArrayPair<T>(inData,outData,numPts,numComp,outArray,nullValue);
  list->Arrays.push_back(pair);
}

//----------------------------------------------------------------------------
// Sort of a little object factory (in conjunction w/ vtkTemplateMacro())
template <typename T>
void CreateRealArrayPair(ArrayList *list, T *inData, float *outData,vtkIdType numPts,
                         int numComp, vtkDataArray *outArray, float nullValue)
{
  RealArrayPair<T,float> *pair =
    new RealArrayPair<T,float>(inData,outData,numPts,numComp,outArray,nullValue);
  list->Arrays.push_back(pair);
}

//----------------------------------------------------------------------------
// Indicate arrays not to process
inline void ArrayList::
ExcludeArray(vtkDataArray *da)
{
  ExcludedArrays.push_back(da);
}

//----------------------------------------------------------------------------
// Has the specified array been excluded?
inline bool ArrayList::
IsExcluded(vtkDataArray *da)
{
  return (std::find(ExcludedArrays.begin(), ExcludedArrays.end(), da) != ExcludedArrays.end());
}

//----------------------------------------------------------------------------
// Add an array pair (input,output) using the name provided for the output.
inline vtkDataArray* ArrayList::
AddArrayPair(vtkIdType numPts, vtkDataArray *inArray,
             vtkStdString &outArrayName, double nullValue, bool promote)
{
  if (this->IsExcluded(inArray))
    {
    return NULL;
    }

  int iType = inArray->GetDataType();
  vtkDataArray *outArray;
  if ( promote && iType != VTK_FLOAT && iType != VTK_DOUBLE )
    {
    outArray = vtkFloatArray::New();
    outArray->SetNumberOfComponents(inArray->GetNumberOfComponents());
    outArray->SetNumberOfTuples(inArray->GetNumberOfTuples());
    outArray->SetName(outArrayName);
    void *iD = inArray->GetVoidPointer(0);
    void *oD = outArray->GetVoidPointer(0);
    switch (iType)
      {
      vtkTemplateMacro(CreateRealArrayPair(this, static_cast<VTK_TT *>(iD),
                       static_cast<float*>(oD),numPts,inArray->GetNumberOfComponents(),
                       outArray,static_cast<float>(nullValue)));
      }//over all VTK types
    }
  else
    {
    outArray = inArray->NewInstance();
    outArray->SetNumberOfComponents(inArray->GetNumberOfComponents());
    outArray->SetNumberOfTuples(inArray->GetNumberOfTuples());
    outArray->SetName(outArrayName);
    void *iD = inArray->GetVoidPointer(0);
    void *oD = outArray->GetVoidPointer(0);
    switch (iType)
      {
      vtkTemplateMacro(CreateArrayPair(this, static_cast<VTK_TT *>(iD),
                       static_cast<VTK_TT *>(oD),numPts,inArray->GetNumberOfComponents(),
                       outArray,static_cast<VTK_TT>(nullValue)));
      }//over all VTK types
    }//promote integral types

  assert(outArray->GetReferenceCount() > 1);
  outArray->FastDelete();
  return outArray;
}

//----------------------------------------------------------------------------
// Add the arrays to interpolate here. This presumes that vtkDataSetAttributes::CopyData() or
// vtkDataSetAttributes::InterpolateData() has been called, and the input and output array
// names match.
inline void ArrayList::
AddArrays(vtkIdType numOutPts, vtkDataSetAttributes *inPD, vtkDataSetAttributes *outPD,
          double nullValue, bool promote)
{
  // Build the vector of interpolation pairs. Note that InterpolateAllocate should have
  // been called at this point (output arrays created and allocated).
  char *name;
  vtkDataArray *iArray, *oArray;
  int iType, oType;
  void *iD, *oD;
  int iNumComp, oNumComp;
  int i, numArrays = outPD->GetNumberOfArrays();

  for (i=0; i < numArrays; ++i)
    {
    oArray = outPD->GetArray(i);
    if ( oArray && ! this->IsExcluded(oArray) )
      {
      name = oArray->GetName();
      iArray = inPD->GetArray(name);
      if ( iArray && ! this->IsExcluded(iArray) )
        {
        iType = iArray->GetDataType();
        oType = oArray->GetDataType();
        iNumComp = iArray->GetNumberOfComponents();
        oNumComp = oArray->GetNumberOfComponents();
        if ( promote && oType != VTK_FLOAT && oType != VTK_DOUBLE )
          {
          oType = VTK_FLOAT;
          vtkFloatArray *fArray = vtkFloatArray::New();
          fArray->SetName(oArray->GetName());
          fArray->SetNumberOfComponents(oNumComp);
          outPD->AddArray(fArray); //nasty side effect will replace current array in the same spot
          oArray = fArray;
          fArray->Delete();
          }
        oArray->SetNumberOfTuples(numOutPts);

        assert( iNumComp == oNumComp );
        if ( iType == oType )
          {
          iD = iArray->GetVoidPointer(0);
          oD = oArray->GetVoidPointer(0);
          switch (iType)
            {
            vtkTemplateMacro(CreateArrayPair(this, static_cast<VTK_TT *>(iD),
                             static_cast<VTK_TT *>(oD),numOutPts,oNumComp,
                             oArray,static_cast<VTK_TT>(nullValue)));
            }//over all VTK types
          }//if matching types
        else //promoted type
          {
          iD = iArray->GetVoidPointer(0);
          oD = oArray->GetVoidPointer(0);
          switch (iType)
            {
            vtkTemplateMacro(CreateRealArrayPair(this, static_cast<VTK_TT *>(iD),
                             static_cast<float*>(oD),numOutPts,iNumComp,
                             oArray,static_cast<float>(nullValue)));
            }//over all VTK types
          }//if promoted pair
        }//if matching input array
      }//if output array
    }//for each candidate array
}

#endif