File: TestAppendSelection.cxx

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (255 lines) | stat: -rw-r--r-- 8,237 bytes parent folder | download | duplicates (4)
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestAppendSelection.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm 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.

=========================================================================*/
/*----------------------------------------------------------------------------
 Copyright (c) Sandia Corporation
 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/

#include "vtkAppendSelection.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"

#define VTK_CREATE(type,name) \
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()

int SelectionCompare(
  vtkSelectionNode* a,
  vtkSelectionNode* b)
{
  int errors = 0;
  vtkIdTypeArray* alist = vtkIdTypeArray::SafeDownCast(
    a->GetSelectionList());
  vtkIdTypeArray* blist = vtkIdTypeArray::SafeDownCast(
    b->GetSelectionList());
  if (a->GetContentType() != b->GetContentType())
    {
    cerr << "ERROR: Content type does not match." << endl;
    errors++;
    }
  if (a->GetContentType() == vtkSelectionNode::VALUES)
    {
    if (!alist->GetName() || 
        !blist->GetName() || 
        strcmp(alist->GetName(), blist->GetName()))
      {
      cerr << "ERROR: The array names do not match." << endl;
      }
    }
  if (a->GetFieldType() != b->GetFieldType())
    {
    cerr << "ERROR: Field type does not match." << endl;
    errors++;
    }
  if ((alist && !blist) || (!alist && blist))
    {
    cerr << "ERROR: One has a selection list while the other does not." << endl;
    errors++;
    }
  if (alist && blist)
    {
    int numComps = alist->GetNumberOfComponents();
    vtkIdType numTuples = alist->GetNumberOfTuples();
    int bnumComps = blist->GetNumberOfComponents();
    vtkIdType bnumTuples = blist->GetNumberOfTuples();
    if (numTuples != bnumTuples)
      {
      cerr << "ERROR: The number of tuples in the selection list do not match ("
           << numTuples << "!=" << bnumTuples << ")." << endl;
      errors++;
      }
    else if (numComps != bnumComps)
      {
      cerr << "ERROR: The number of components in the selection list do not match ("
           << numComps << "!=" << bnumComps << ")." << endl;
      errors++;
      }
    else
      {
      for (vtkIdType i = 0; i < numComps*numTuples; i++)
        {
        if (alist->GetValue(i) != blist->GetValue(i))
          {
          cerr << "ERROR: Selection lists do not match at sel " 
               << i 
               << "(" 
               << alist->GetValue(i) 
               << " != " 
               << blist->GetValue(i) 
               << ")." 
               << endl;
          errors++;
          break;
          }
        }
      }
    }
  return errors;
}

int SelectionCompare(
  vtkSelection* a,
  vtkSelection* b)
{
  int errors = 0;
  if (a->GetNumberOfNodes() != b->GetNumberOfNodes())
    {
    cerr << "ERROR: Number of nodes do not match." << endl;
    errors++;
    }
  else
    {
    for (unsigned int cc=0; cc < a->GetNumberOfNodes(); cc++)
      {
      errors += SelectionCompare(a->GetNode(cc), b->GetNode(cc));
      }
    }
  return errors;
}

int TestAppendSelectionCase(
  vtkSelection* input1, 
  vtkSelection* input2,
  vtkSelection* correct)
{
  VTK_CREATE(vtkAppendSelection, append);
  append->AddInput(input1);
  append->AddInput(input2);
  append->Update();
  vtkSelection* output = append->GetOutput();
  return SelectionCompare(output, correct);
}

int TestAppendSelection(int, char*[])
{
  int errors = 0;

  {
  cerr << "Testing appending sel selections ..." << endl;
  VTK_CREATE(vtkSelection, sel1);
  VTK_CREATE(vtkSelectionNode, sel1Node);
  VTK_CREATE(vtkIdTypeArray, sel1Arr);
  sel1->AddNode(sel1Node);
  sel1Node->SetContentType(vtkSelectionNode::INDICES);
  sel1Node->SetFieldType(vtkSelectionNode::CELL);
  sel1Node->SetSelectionList(sel1Arr);
  sel1Arr->InsertNextValue(0);
  sel1Arr->InsertNextValue(1);
  sel1Arr->InsertNextValue(2);
  VTK_CREATE(vtkSelection, sel2);
  VTK_CREATE(vtkSelectionNode, sel2Node);
  VTK_CREATE(vtkIdTypeArray, sel2Arr);
  sel2->AddNode(sel2Node);
  sel2Node->SetContentType(vtkSelectionNode::INDICES);
  sel2Node->SetFieldType(vtkSelectionNode::CELL);
  sel2Node->SetSelectionList(sel2Arr);
  sel2Arr->InsertNextValue(3);
  sel2Arr->InsertNextValue(4);
  sel2Arr->InsertNextValue(5);
  VTK_CREATE(vtkSelection, selAppend);
  VTK_CREATE(vtkSelectionNode, selAppendNode);
  VTK_CREATE(vtkIdTypeArray, selAppendArr);
  selAppend->AddNode(selAppendNode);
  selAppendNode->SetContentType(vtkSelectionNode::INDICES);
  selAppendNode->SetFieldType(vtkSelectionNode::CELL);
  selAppendNode->SetSelectionList(selAppendArr);
  selAppendArr->InsertNextValue(0);
  selAppendArr->InsertNextValue(1);
  selAppendArr->InsertNextValue(2);
  selAppendArr->InsertNextValue(3);
  selAppendArr->InsertNextValue(4);
  selAppendArr->InsertNextValue(5);
  errors += TestAppendSelectionCase(sel1, sel2, selAppend);
  cerr << "... done." << endl;
  }

  {
  cerr << "Testing appending value selections ..." << endl;
  VTK_CREATE(vtkSelection, sel1);
  VTK_CREATE(vtkSelectionNode, sel1Node);
  VTK_CREATE(vtkIdTypeArray, sel1Arr);
  sel1->AddNode(sel1Node);
  sel1Arr->SetName("arrayname");
  sel1Node->SetContentType(vtkSelectionNode::VALUES);
  sel1Node->SetFieldType(vtkSelectionNode::CELL);
  sel1Node->SetSelectionList(sel1Arr);
  sel1Arr->InsertNextValue(0);
  sel1Arr->InsertNextValue(1);
  sel1Arr->InsertNextValue(2);
  VTK_CREATE(vtkSelection, sel2);
  VTK_CREATE(vtkSelectionNode, sel2Node);
  VTK_CREATE(vtkIdTypeArray, sel2Arr);
  sel2->AddNode(sel2Node);
  sel2Arr->SetName("arrayname");
  sel2Node->SetContentType(vtkSelectionNode::VALUES);
  sel2Node->SetFieldType(vtkSelectionNode::CELL);
  sel2Node->SetSelectionList(sel2Arr);
  sel2Arr->InsertNextValue(3);
  sel2Arr->InsertNextValue(4);
  sel2Arr->InsertNextValue(5);
  VTK_CREATE(vtkSelection, selAppend);
  VTK_CREATE(vtkSelectionNode, selAppendNode);
  VTK_CREATE(vtkIdTypeArray, selAppendArr);
  selAppend->AddNode(selAppendNode);
  selAppendArr->SetName("arrayname");
  selAppendNode->SetContentType(vtkSelectionNode::VALUES);
  selAppendNode->SetFieldType(vtkSelectionNode::CELL);
  selAppendNode->SetSelectionList(selAppendArr);
  selAppendArr->InsertNextValue(0);
  selAppendArr->InsertNextValue(1);
  selAppendArr->InsertNextValue(2);
  selAppendArr->InsertNextValue(3);
  selAppendArr->InsertNextValue(4);
  selAppendArr->InsertNextValue(5);
  errors += TestAppendSelectionCase(sel1, sel2, selAppend);
  cerr << "... done." << endl;
  }

  {
  cerr << "Testing appending cell selections with different process ids..." << endl;
  VTK_CREATE(vtkSelection, sel1);
  VTK_CREATE(vtkSelectionNode, sel1Node);
  VTK_CREATE(vtkIdTypeArray, sel1Arr);
  sel1->AddNode(sel1Node);
  sel1Node->SetContentType(vtkSelectionNode::INDICES);
  sel1Node->SetFieldType(vtkSelectionNode::CELL);
  sel1Node->SetSelectionList(sel1Arr);
  sel1Node->GetProperties()->Set(vtkSelectionNode::PROCESS_ID(), 0);
  sel1Arr->InsertNextValue(0);
  sel1Arr->InsertNextValue(1);
  sel1Arr->InsertNextValue(2);
  VTK_CREATE(vtkSelection, sel2);
  VTK_CREATE(vtkSelectionNode, sel2Node);
  VTK_CREATE(vtkIdTypeArray, sel2Arr);
  sel2->AddNode(sel2Node);
  sel2Node->SetContentType(vtkSelectionNode::INDICES);
  sel2Node->SetFieldType(vtkSelectionNode::CELL);
  sel2Node->SetSelectionList(sel2Arr);
  sel2Node->GetProperties()->Set(vtkSelectionNode::PROCESS_ID(), 1);
  sel2Arr->InsertNextValue(3);
  sel2Arr->InsertNextValue(4);
  sel2Arr->InsertNextValue(5);
  VTK_CREATE(vtkSelection, selAppend);
  selAppend->AddNode(sel1Node);
  selAppend->AddNode(sel2Node);
  errors += TestAppendSelectionCase(sel1, sel2, selAppend);
  cerr << "... done." << endl;
  }

  return errors;
}