vtkSelectionSource.cxx 5.65 KB
Newer Older
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkSelectionSource.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.

=========================================================================*/
#include "vtkSelectionSource.h"

#include "vtkCommand.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSelection.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTrivialProducer.h"

#include "vtkstd/vector"
#include "vtkstd/set"

29
vtkCxxRevisionMacro(vtkSelectionSource, "1.6");
30
31
32
33
34
35
36
37
38
39
40
41
42
43
vtkStandardNewMacro(vtkSelectionSource);

struct vtkSelectionSourceInternals
{
  typedef vtkstd::set<vtkIdType> IDSetType;
  typedef vtkstd::vector<IDSetType> IDsType;
  IDsType IDs;
};

//----------------------------------------------------------------------------
vtkSelectionSource::vtkSelectionSource()
{
  this->SetNumberOfInputPorts(0);
  this->Internal = new vtkSelectionSourceInternals;
44
45
  this->ContentType = vtkSelection::INDICES;
  this->FieldType = vtkSelection::CELL;
46
47
48
49
50
51
52
53
54
55
56
57
}

//----------------------------------------------------------------------------
vtkSelectionSource::~vtkSelectionSource()
{
  delete this->Internal;
}

//----------------------------------------------------------------------------
void vtkSelectionSource::RemoveAllIDs()
{
  this->Internal->IDs.clear();
58
  this->Modified();
59
60
61
62
63
}

//----------------------------------------------------------------------------
void vtkSelectionSource::AddID(vtkIdType proc, vtkIdType id)
{
64
65
66
  // proc == -1 means all processes. All other are stored at index proc+1
  proc++;

67
68
69
70
71
72
  if (proc >= (vtkIdType)this->Internal->IDs.size())
    {
    this->Internal->IDs.resize(proc+1);
    }
  vtkSelectionSourceInternals::IDSetType& idSet = this->Internal->IDs[proc];
  idSet.insert(id);
73
  this->Modified();
74
75
76
77
78
79
}

//----------------------------------------------------------------------------
void vtkSelectionSource::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
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
  os << indent << "ContentType: " ;
  switch (this->ContentType)
    {
  case vtkSelection::SELECTIONS:
    os << "SELECTIONS";
    break;
  case vtkSelection::COMPOSITE_SELECTIONS:
    os << "COMPOSITE_SELECTIONS";
    break;
  case vtkSelection::GLOBALIDS:
    os << "GLOBALIDS";
    break;
  case vtkSelection::VALUES:
    os << "VALUES";
    break;
  case vtkSelection::INDICES:
    os << "INDICES";
    break;
  case vtkSelection::FRUSTUM:
    os << "FRUSTUM";
    break;
  case vtkSelection::LOCATIONS:
    os << "LOCATIONS";
    break;
  case vtkSelection::THRESHOLDS:
    os << "THRESHOLDS";
    break;
  default:
    os << "UNKNOWN";
    }
  os << endl;

  os << indent << "FieldType: " ;
  switch (this->FieldType)
    {
  case vtkSelection::CELL:
    os << "CELL";
    break;
  case vtkSelection::POINT:
    os << "POINT";
    break;
  default:
    os << "UNKNOWN";
    }
  os << endl;
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
}

//----------------------------------------------------------------------------
int vtkSelectionSource::RequestInformation(
  vtkInformation* vtkNotUsed(request),
  vtkInformationVector** vtkNotUsed(inputVector),
  vtkInformationVector* outputVector)
{
  // We can handle multiple piece request.
  vtkInformation* info = outputVector->GetInformationObject(0);
  info->Set(
    vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(), -1);

  return 1;
}

//----------------------------------------------------------------------------
int vtkSelectionSource::RequestData(
  vtkInformation* vtkNotUsed( request ),
  vtkInformationVector** vtkNotUsed( inputVector ),
  vtkInformationVector* outputVector )
{
  vtkSelection* output = vtkSelection::GetData(outputVector);

  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  int piece = 0;
  if (outInfo->Has(
        vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()))
    {
    piece = outInfo->Get(
      vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
    }

158
159
160
161
162
163
164
165
  // Number of selected items common to all pieces
  vtkIdType numCommonElems = 0;
  if (!this->Internal->IDs.empty())
    {
    numCommonElems = this->Internal->IDs[0].size();
    }
  if (piece+1 >= (int)this->Internal->IDs.size() &&
      numCommonElems == 0)
166
167
168
169
170
    {
    vtkDebugMacro("No selection for piece: " << piece);
    return 1;
    }

171
172
173
174
  // idx == 0 is the list for all pieces
  // idx == piece+1 is the list for the current piece
  int pids[2] = {0, piece+1};
  for(int i=0; i<2; i++)
175
    {
176
177
178
179
180
    int idx = pids[i];
    vtkSelectionSourceInternals::IDSetType& selSet =
      this->Internal->IDs[idx];
    
    if (selSet.size() > 0)
181
      {
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
      output->GetProperties()->Set(vtkSelection::CONTENT_TYPE(), 
                                   this->ContentType);
      output->GetProperties()->Set(vtkSelection::FIELD_TYPE(),
                                   this->FieldType);
      // Create the selection list
      vtkIdTypeArray* selectionList = vtkIdTypeArray::New();
      selectionList->SetNumberOfTuples(selSet.size());
      // iterate over ids and insert to the selection list
      vtkSelectionSourceInternals::IDSetType::iterator iter =
        selSet.begin();
      for (vtkIdType idx2=0; iter != selSet.end(); iter++, idx2++)
        {
        selectionList->SetValue(idx2, *iter);
        }
      output->SetSelectionList(selectionList);
      selectionList->Delete();
198
199
200
201
202
203
      }
    }
  
  return 1;
}