File: vtkSMInputArrayDomain.cxx

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 (358 lines) | stat: -rw-r--r-- 10,147 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMInputArrayDomain.cxx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkSMInputArrayDomain.h"

#include "vtkObjectFactory.h"
#include "vtkPVArrayInformation.h"
#include "vtkPVDataInformation.h"
#include "vtkPVDataSetAttributesInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMUncheckedPropertyHelper.h"

vtkStandardNewMacro(vtkSMInputArrayDomain);

bool vtkSMInputArrayDomain::AutomaticPropertyConversion = false;

//---------------------------------------------------------------------------
static const char* const vtkSMInputArrayDomainAttributeTypes[] = {
  "point",
  "cell",
  "field",
  "any-except-field",
  "vertex",
  "edge",
  "row",
  "any",
  NULL
};

//---------------------------------------------------------------------------
vtkSMInputArrayDomain::vtkSMInputArrayDomain()
{
  this->AttributeType = vtkSMInputArrayDomain::ANY_EXCEPT_FIELD;
  this->NumberOfComponents = 0;
}

//---------------------------------------------------------------------------
vtkSMInputArrayDomain::~vtkSMInputArrayDomain()
{
}

//---------------------------------------------------------------------------
int vtkSMInputArrayDomain::IsInDomain(vtkSMProperty* property)
{
  if (this->IsOptional)
    {
    return 1;
    }

  if (!property)
    {
    return 0;
    }

  vtkSMUncheckedPropertyHelper helper(property);
  for (unsigned int cc=0, max=helper.GetNumberOfElements(); cc < max; cc++)
    {
    if (!this->IsInDomain(
        vtkSMSourceProxy::SafeDownCast(helper.GetAsProxy(cc)),
        helper.GetOutputPort(cc)))
      {
      return 0;
      }
    }

  return (helper.GetNumberOfElements() > 0);
}

//---------------------------------------------------------------------------
int vtkSMInputArrayDomain::IsInDomain(vtkSMSourceProxy* proxy,
                                      unsigned int outputport/*=0*/)
{
  if (!proxy)
    {
    return 0;
    }

  // Make sure the outputs are created.
  proxy->CreateOutputPorts();
  vtkPVDataInformation* info = proxy->GetDataInformation(outputport);
  if (!info)
    {
    return 0;
    }

  int attribute_types_to_try[] =
    {
    vtkDataObject::POINT,
    vtkDataObject::CELL,
    vtkDataObject::FIELD,
    vtkDataObject::VERTEX,
    vtkDataObject::EDGE,
    vtkDataObject::ROW,
    -1
    };

  for (int kk=0; attribute_types_to_try[kk] != -1; kk++)
    {
    int attribute_type = attribute_types_to_try[kk];
    
    // check if attribute_type is acceptable.
    if (this->IsAttributeTypeAcceptable(attribute_type))
      {
      vtkPVDataSetAttributesInformation* dsaInfo =
        info->GetAttributeInformation(attribute_types_to_try[kk]);
      if (this->HasAcceptableArray(dsaInfo))
        {
        return 1;
        }
      }
    }
  return 0;
}

//----------------------------------------------------------------------------
bool vtkSMInputArrayDomain::IsAttributeTypeAcceptable(
  int required_type, int attribute_type, int *acceptable_as_type/*=NULL*/)
{
  if (acceptable_as_type)
    {
    *acceptable_as_type = attribute_type;
    }

  if (required_type == ANY)
    {
    return attribute_type == POINT||
      attribute_type == CELL||
      attribute_type == FIELD ||
      attribute_type == EDGE||
      attribute_type == VERTEX||
      attribute_type == ROW;
    }

  if (required_type == ANY_EXCEPT_FIELD)
    {
    // Try out all attribute types except field data sequentially.
    int attribute_types_to_try[] =
      {
      vtkDataObject::POINT,
      vtkDataObject::CELL,
      vtkDataObject::VERTEX,
      vtkDataObject::EDGE,
      vtkDataObject::ROW,
      -1
      };
    for (int cc=0; attribute_types_to_try[cc] != -1; ++cc)
      {
      if (vtkSMInputArrayDomain::IsAttributeTypeAcceptable(
          attribute_types_to_try[cc], attribute_type, acceptable_as_type))
        {
        return true;
        }
      }
    return false;
    }

  switch (attribute_type)
    {
  case vtkDataObject::POINT:
    if (required_type == POINT)
      {
      return true;
      }
    if (required_type == CELL && vtkSMInputArrayDomain::AutomaticPropertyConversion)
      {
      // this a POINT array, however since AutomaticPropertyConversion is ON,
      // this array can is acceptable as a CELL array. In other words, caller
      // can pretend this array is a CELL array and VTK pipeline will take care
      // of it.
      if (acceptable_as_type)
        {
        *acceptable_as_type = CELL;
        }
      return true;
      }
    break;

  case vtkDataObject::CELL:
    if (required_type == CELL)
      {
      return true;
      }
    if (required_type == POINT && vtkSMInputArrayDomain::AutomaticPropertyConversion)
      {
      // this a CELL array, however since AutomaticPropertyConversion is ON,
      // this array can is acceptable as a POINT array. In other words, caller
      // can pretend this array is a POINT array and VTK pipeline will take care
      // of it.
      if (acceptable_as_type)
        {
        *acceptable_as_type = POINT;
        }
      return true;
      }
    break;

  default:
    break;
    }

  return required_type == attribute_type;
}
//----------------------------------------------------------------------------
bool vtkSMInputArrayDomain::IsArrayAcceptable(
    int required_number_of_components, vtkPVArrayInformation* arrayInfo)
{
  if (arrayInfo == NULL)
    {
    return false;
    }

  if (
      // acceptable if the domain doesn't dictate any component requirements.
      required_number_of_components <= 0 ||

      // acceptable if the components match those in array
      arrayInfo->GetNumberOfComponents() == required_number_of_components ||

      // when using automatic property conversion, we support automatic extraction
      // of a single component from multi-component arrays. However, we still
      // don't support automatic extraction of multiple components, so if the
      // filter needs more than 1 component, then the number of components must
      // match.
      (vtkSMInputArrayDomain::AutomaticPropertyConversion &&
       required_number_of_components == 1 &&
       arrayInfo->GetNumberOfComponents() > 1))
      {
      return true;
      }

  return false;
}

//----------------------------------------------------------------------------
bool vtkSMInputArrayDomain::IsAttributeTypeAcceptable(int attributeType)
{
  return vtkSMInputArrayDomain::IsAttributeTypeAcceptable(
    this->AttributeType, attributeType, NULL);
}

//----------------------------------------------------------------------------
bool vtkSMInputArrayDomain::HasAcceptableArray(
  vtkPVDataSetAttributesInformation* attrInfo)
{
  for (int idx=0, num = attrInfo->GetNumberOfArrays(); idx < num; ++idx)
    {
    vtkPVArrayInformation* arrayInfo = attrInfo->GetArrayInformation(idx);
    if (vtkSMInputArrayDomain::IsArrayAcceptable(
      this->NumberOfComponents, arrayInfo))
      {
      return true;
      }
    }

  return false;
}

//---------------------------------------------------------------------------
int vtkSMInputArrayDomain::ReadXMLAttributes(
  vtkSMProperty* prop, vtkPVXMLElement* element)
{
  this->Superclass::ReadXMLAttributes(prop, element);

  if (this->GetRequiredProperty("FieldDataSelection"))
    {
    vtkWarningMacro(
      "vtkSMInputArrayDomain no longer supports required property "
      "'FieldDataSelection'. Please update the domain definition.");
    }

  const char* attribute_type = element->GetAttribute("attribute_type");
  if (attribute_type)
    {
    this->SetAttributeType(attribute_type);
    }

  int numComponents;
  if (element->GetScalarAttribute("number_of_components", &numComponents))
    {
    numComponents = numComponents < 0? 0 : numComponents;
    this->SetNumberOfComponents(numComponents);
    }

  return 1;
}

//---------------------------------------------------------------------------
const char* vtkSMInputArrayDomain::GetAttributeTypeAsString()
{
  if (this->AttributeType < vtkSMInputArrayDomain::NUMBER_OF_ATTRIBUTE_TYPES)
    {
    return vtkSMInputArrayDomainAttributeTypes[this->AttributeType];
    }

  return "(invalid)";
}

//---------------------------------------------------------------------------
void vtkSMInputArrayDomain::SetAttributeType(const char* type)
{
  if (type == NULL)
    {
    vtkErrorMacro("No type specified");
    return;
    }

  for (int cc=0; cc < vtkSMInputArrayDomain::NUMBER_OF_ATTRIBUTE_TYPES; ++cc)
    {
    if (strcmp(type, vtkSMInputArrayDomainAttributeTypes[cc]) == 0)
      {
      this->SetAttributeType(cc);
      return;
      }
    }
  // for old code where none==field.
  if (strcmp(type, "none") == 0)
    {
    this->SetAttributeType(vtkSMInputArrayDomain::FIELD);
    return;
    }
  vtkErrorMacro("Unrecognized attribute type: " << type);
}

//---------------------------------------------------------------------------
void vtkSMInputArrayDomain::SetAutomaticPropertyConversion(bool convert)
{
  if ( vtkSMInputArrayDomain::AutomaticPropertyConversion != convert )
    {
    vtkSMInputArrayDomain::AutomaticPropertyConversion = convert;
    }
}

//---------------------------------------------------------------------------
bool vtkSMInputArrayDomain::GetAutomaticPropertyConversion()
{
  return vtkSMInputArrayDomain::AutomaticPropertyConversion;
}

//---------------------------------------------------------------------------
void vtkSMInputArrayDomain::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "NumberOfComponents: " << this->NumberOfComponents << endl;
  os << indent << "AttributeType: " << this->AttributeType
    << " (" << this->GetAttributeTypeAsString() << ")" << endl;
}