File: vtkSMNumberOfComponentsDomain.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 (170 lines) | stat: -rw-r--r-- 5,513 bytes parent folder | download | duplicates (3)
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
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMNumberOfComponentsDomain.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 "vtkSMNumberOfComponentsDomain.h"

#include "vtkObjectFactory.h"
#include "vtkPVArrayInformation.h"
#include "vtkPVDataInformation.h"
#include "vtkPVDataSetAttributesInformation.h"
#include "vtkSMDomainIterator.h"
#include "vtkSMInputArrayDomain.h"
#include "vtkSMInputProperty.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMStringVectorProperty.h"

vtkStandardNewMacro(vtkSMNumberOfComponentsDomain);
//----------------------------------------------------------------------------
vtkSMNumberOfComponentsDomain::vtkSMNumberOfComponentsDomain()
{
}

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

//----------------------------------------------------------------------------
void vtkSMNumberOfComponentsDomain::Update(vtkSMProperty*)
{
  vtkSMProxyProperty* ip = vtkSMProxyProperty::SafeDownCast(
    this->GetRequiredProperty("Input"));
  vtkSMStringVectorProperty* svp = vtkSMStringVectorProperty::SafeDownCast(
    this->GetRequiredProperty("ArraySelection"));
  if (!ip || !svp)
    {
    // Missing required properties.
    this->SetEntries(std::vector<vtkEntry>());
    return;
    }

  if (svp->GetNumberOfUncheckedElements() != 5 &&
      svp->GetNumberOfUncheckedElements() != 2 && 
      svp->GetNumberOfUncheckedElements() != 1)
    {
    // We can only handle array selection properties with 5, 2 or 1 elements.
    // For 5 elements the array name is at indices [4]; for 2
    // elements it's at [1], while for 1 elements, it's at [0].
    this->SetEntries(std::vector<vtkEntry>());
    return;
    }

  int index = svp->GetNumberOfUncheckedElements()-1;
  const char* arrayName = svp->GetUncheckedElement(index);
  if (!arrayName || arrayName[0] == 0)
    {
    // No array choosen.
    this->SetEntries(std::vector<vtkEntry>());
    return;
    }

  vtkSMInputArrayDomain* iad = 0;
  vtkSMDomainIterator* di = ip->NewDomainIterator();
  di->Begin();
  while (!di->IsAtEnd())
    {
    // We have to figure out whether we are working with cell data,
    // point data or both.
    iad = vtkSMInputArrayDomain::SafeDownCast(di->GetDomain());
    if (iad)
      {
      break;
      }
    di->Next();
    }
  di->Delete();
  if (!iad)
    {
    // Failed to locate a vtkSMInputArrayDomain on the input property, which is
    // required.
    this->SetEntries(std::vector<vtkEntry>());
    return;
    }

  vtkSMInputProperty* inputProp = vtkSMInputProperty::SafeDownCast(ip);
  unsigned int i;
  unsigned int numProxs = ip->GetNumberOfUncheckedProxies();
  for (i=0; i<numProxs; i++)
    {
    // Use the first input
    vtkSMSourceProxy* source = 
      vtkSMSourceProxy::SafeDownCast(ip->GetUncheckedProxy(i));
    if (source)
      {
      this->Update(arrayName, source, iad,
        (inputProp? inputProp->GetUncheckedOutputPortForConnection(i): 0));
      return;
      }
    }
}

//---------------------------------------------------------------------------
void vtkSMNumberOfComponentsDomain::Update(const char* arrayName,
                                   vtkSMSourceProxy* sp,
                                   vtkSMInputArrayDomain* iad,
                                   int outputport)
{
  // Make sure the outputs are created.
  sp->CreateOutputPorts();
  vtkPVDataInformation* info = sp->GetDataInformation(outputport);
  if (!info)
    {
    this->SetEntries(std::vector<vtkEntry>());
    return;
    }

  int iadAttributeType = iad->GetAttributeType();
  vtkPVArrayInformation* ai = 0;

  if (iadAttributeType == vtkSMInputArrayDomain::POINT ||
    iadAttributeType == vtkSMInputArrayDomain::ANY)
    {
    ai = info->GetPointDataInformation()->GetArrayInformation(arrayName);
    }
  else if (iadAttributeType == vtkSMInputArrayDomain::CELL || 
    (iadAttributeType == vtkSMInputArrayDomain::ANY && !ai))
    {
    ai = info->GetCellDataInformation()->GetArrayInformation(arrayName);
    }
  else if (iadAttributeType == vtkSMInputArrayDomain::VERTEX || 
    (iadAttributeType == vtkSMInputArrayDomain::ANY && !ai))
    {
    ai = info->GetVertexDataInformation()->GetArrayInformation(arrayName);
    }
  else if (iadAttributeType == vtkSMInputArrayDomain::EDGE || 
    (iadAttributeType == vtkSMInputArrayDomain::ANY && !ai))
    {
    ai = info->GetEdgeDataInformation()->GetArrayInformation(arrayName);
    }
  else if (iadAttributeType == vtkSMInputArrayDomain::ROW || 
    (iadAttributeType == vtkSMInputArrayDomain::ANY && !ai))
    {
    ai = info->GetRowDataInformation()->GetArrayInformation(arrayName);
    }

  if (ai)
    {
    std::vector<vtkEntry> entries;
    entries.push_back(vtkEntry(0, ai->GetNumberOfComponents()-1));
    this->SetEntries(std::vector<vtkEntry>());
    }
}

//----------------------------------------------------------------------------
void vtkSMNumberOfComponentsDomain::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}