File: vtkMultiGroupDataExtractGroup.cxx

package info (click to toggle)
paraview 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 124,600 kB
  • ctags: 133,728
  • sloc: cpp: 958,817; ansic: 509,658; tcl: 45,787; xml: 23,401; python: 19,574; perl: 3,112; yacc: 1,787; java: 1,517; sh: 665; asm: 471; lex: 400; makefile: 168; objc: 28
file content (281 lines) | stat: -rwxr-xr-x 8,618 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
/*=========================================================================

Program:   Visualization Toolkit
Module:    $RCSfile: vtkMultiGroupDataExtractGroup.cxx,v $

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 "vtkMultiGroupDataExtractGroup.h"

#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkDataSet.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkMultiGroupDataInformation.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"

vtkCxxRevisionMacro(vtkMultiGroupDataExtractGroup, "$Revision: 1.10 $");
vtkStandardNewMacro(vtkMultiGroupDataExtractGroup);

//----------------------------------------------------------------------------
vtkMultiGroupDataExtractGroup::vtkMultiGroupDataExtractGroup()
{
  this->MinGroup = 0;
  this->MaxGroup = 0;

}

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

//----------------------------------------------------------------------------
int vtkMultiGroupDataExtractGroup::RequestDataObject(
  vtkInformation*, 
  vtkInformationVector** inputVector , 
  vtkInformationVector* outputVector)
{
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  if (!inInfo)
    {
    return 0;
    }
  vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
    inInfo->Get(vtkDataObject::DATA_OBJECT()));
  
  if (input)
    {
    vtkInformation* info = outputVector->GetInformationObject(0);
    vtkCompositeDataSet *output = vtkCompositeDataSet::SafeDownCast(
      info->Get(vtkDataObject::DATA_OBJECT()));
    
    if (!output || !output->IsA(input->GetClassName())) 
      {
      output = input->NewInstance();
      output->SetPipelineInformation(info);
      output->Delete();
      }
    return 1;
    }
  return 0;
}

//----------------------------------------------------------------------------
int vtkMultiGroupDataExtractGroup::RequestInformation(
  vtkInformation*,
  vtkInformationVector** inputVector,
  vtkInformationVector* outputVector)
{
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  vtkMultiGroupDataInformation* inCompInfo = 
    vtkMultiGroupDataInformation::SafeDownCast(
      inInfo->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));
  if (!inCompInfo)
    {
    vtkDebugMacro("Expected information not found. "
                  "Cannot provide information.");
    return 1;
    }

  unsigned int numInputGroups = inCompInfo->GetNumberOfGroups();

  unsigned int numGroups;
  vtkMultiGroupDataInformation* compInfo = 
    vtkMultiGroupDataInformation::New();
  if (this->MaxGroup >= numInputGroups)
    {
    numGroups = numInputGroups;
    }
  else
    {
    numGroups = this->MaxGroup+1;
    }
  if (numGroups < this->MinGroup)
    {
    numGroups = this->MinGroup;
    }
  compInfo->SetNumberOfGroups(numGroups-this->MinGroup);

  for (unsigned int i=0; i<numGroups; i++)
    {
    if (i < this->MinGroup)
      {
      continue;
      }
    else if (i > this->MaxGroup)
      {
      compInfo->SetNumberOfDataSets(i-this->MinGroup, 0);
      }
    else
      {
      compInfo->SetNumberOfDataSets(i-this->MinGroup,
                                    inCompInfo->GetNumberOfDataSets(i));
      }
    unsigned int numDataSets = compInfo->GetNumberOfDataSets(i-this->MinGroup);
    for (unsigned int j=0; j<numDataSets; j++)
      {
      if (inCompInfo->HasInformation(i, j))
        {
        vtkInformation* outdInfo = compInfo->GetInformation(i-this->MinGroup, j);
        vtkInformation* indInfo = inCompInfo->GetInformation(i-this->MinGroup, j);
        outdInfo->Copy(indInfo);
        }
      }
    }

  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  outInfo->Set(
    vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION(), compInfo);
  compInfo->Delete();

  return 1;
}

//----------------------------------------------------------------------------
int vtkMultiGroupDataExtractGroup::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
{
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  vtkMultiGroupDataSet *input = vtkMultiGroupDataSet::SafeDownCast(
    inInfo->Get(vtkDataObject::DATA_OBJECT()));
  if (!input) {return 0;}

  vtkInformation* info = outputVector->GetInformationObject(0);
  vtkMultiGroupDataSet *output = vtkMultiGroupDataSet::SafeDownCast(
    info->Get(vtkDataObject::DATA_OBJECT()));
  if (!output) {return 0;}

  unsigned int numGroups = this->MaxGroup-this->MinGroup+1;

  // Detect the case where we are extracting 1 group and that group
  // is a multigroup dataset. In that situation, directly copy
  // that data object to the output instead of assigning it as
  // as sub-dataset. This is done to avoid creating a multi-group
  // of multi-group when it is not necessary.
  if (!input->IsA("vtkHierarchicalDataSet") && numGroups == 1)
    {
    unsigned int numDataSets = input->GetNumberOfDataSets(this->MinGroup);
    unsigned int numActualDS = 0;
    unsigned int dsIdx = 0;
    for (unsigned int dataSet=0; dataSet<numDataSets; dataSet++)
      {
      vtkDataObject* dobj = input->GetDataSet(this->MinGroup, dataSet);
      if (dobj)
        {
        numActualDS++;
        dsIdx = dataSet;
        }
      }
    if (numActualDS == 1)
      {
      vtkDataObject* dobj = input->GetDataSet(this->MinGroup, dsIdx);
      if (dobj->IsA("vtkMultiGroupDataSet"))
        {
        output->ShallowCopy(dobj);
        return 1;
        }
      }
    }

  output->SetNumberOfGroups(numGroups);
  unsigned int numInputGroups = input->GetNumberOfGroups();

  float progress = 0;
  int counter = 0;
  float delProg = 1.0/numInputGroups;
  for (unsigned int group=0; group<numInputGroups; group++)
    {
    if (group < this->MinGroup)
      {
      continue;
      }
    else if (group > this->MaxGroup)
      {
      output->SetNumberOfDataSets(group-this->MinGroup, 0);
      continue;
      }
    unsigned int numDataSets = input->GetNumberOfDataSets(group);
    output->SetNumberOfDataSets(group-this->MinGroup, numDataSets);
    float delProg2 = delProg / numDataSets;
    for (unsigned int dataSet=0; dataSet<numDataSets; dataSet++)
      {
      progress += delProg2;
      if ( counter % 100 == 0 )
        {
        this->UpdateProgress(progress);
        }
      vtkDataObject* dObj = input->GetDataSet(group, dataSet);
      if (dObj)
        {
        vtkDataObject* copy = dObj->NewInstance();
        copy->ShallowCopy(dObj);
        output->SetDataSet(group-this->MinGroup, dataSet, copy);
        copy->Delete();
        }
      }
    }
  vtkMultiGroupDataInformation* compInfo = 
    vtkMultiGroupDataInformation::SafeDownCast(
      info->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));

  if (compInfo)
    {
    output->SetMultiGroupDataInformation(compInfo);
    }

  vtkHierarchicalBoxDataSet* hbds = 
    vtkHierarchicalBoxDataSet::SafeDownCast(output);
  if (hbds)
    {
    vtkHierarchicalBoxDataSet* ihbds = 
      vtkHierarchicalBoxDataSet::SafeDownCast(input);
    if (numInputGroups > 0)
      {
      for (unsigned int group=0; group<numInputGroups-1; group++)
        {
        if (group < this->MinGroup)
          {
          continue;
          }
        hbds->SetRefinementRatio(group-this->MinGroup,
                                 ihbds->GetRefinementRatio(group));
        }
      }
    }

  // Last group should not be blanked (uniform grid only)
  unsigned int numDataSets = output->GetNumberOfDataSets(numGroups-1);
  for (unsigned int dataSet=0; dataSet<numDataSets; dataSet++)
    {
    vtkUniformGrid* ug = vtkUniformGrid::SafeDownCast(
      output->GetDataSet(numGroups-1, dataSet));
    if (ug)
      {
      ug->SetCellVisibilityArray(0);
      }
    }

  return 1;
}

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

  os << indent << "MinGroup:" << this->MinGroup << endl;
  os << indent << "MaxGroup:" << this->MaxGroup << endl;
}