File: vtkEnsembleSource.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,880 kB
  • sloc: cpp: 1,442,792; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 103; objc: 17
file content (181 lines) | stat: -rw-r--r-- 5,480 bytes parent folder | download | duplicates (5)
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkEnsembleSource.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 "vtkEnsembleSource.h"

#include "vtkDataObject.h"
#include "vtkInformation.h"
#include "vtkInformationDataObjectMetaDataKey.h"
#include "vtkInformationIntegerKey.h"
#include "vtkInformationIntegerRequestKey.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTable.h"

#include <vector>

vtkStandardNewMacro(vtkEnsembleSource);
vtkCxxSetObjectMacro(vtkEnsembleSource, MetaData, vtkTable);

vtkInformationKeyMacro(vtkEnsembleSource, META_DATA, DataObjectMetaData);
vtkInformationKeyMacro(vtkEnsembleSource, DATA_MEMBER, Integer);

// Subclass vtkInformationIntegerRequestKey to set the DataKey.
class vtkInformationEnsembleMemberRequestKey : public vtkInformationIntegerRequestKey
{
public:
  vtkInformationEnsembleMemberRequestKey(const char* name, const char* location) :
    vtkInformationIntegerRequestKey(name, location)
    {
    this->DataKey = vtkEnsembleSource::DATA_MEMBER();
    }
};
vtkInformationKeySubclassMacro(vtkEnsembleSource, UPDATE_MEMBER, EnsembleMemberRequest, IntegerRequest);

struct vtkEnsembleSourceInternal
{
  std::vector<vtkSmartPointer<vtkAlgorithm> > Algorithms;
};

vtkEnsembleSource::vtkEnsembleSource()
{
  this->SetNumberOfInputPorts(0);
  this->SetNumberOfOutputPorts(1);

  this->Internal = new vtkEnsembleSourceInternal;

  this->CurrentMember = 0;

  this->MetaData = 0;
}

vtkEnsembleSource::~vtkEnsembleSource()
{
  delete this->Internal;

  if (this->MetaData)
    {
    this->MetaData->Delete();
    this->MetaData = 0;
    }
}

int vtkEnsembleSource::ProcessRequest(vtkInformation *request,
                                      vtkInformationVector **inputVector,
                                      vtkInformationVector *outputVector)
{
  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  vtkAlgorithm* currentReader = this->GetCurrentReader(outInfo);
  if (currentReader)
    {
    if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
      {
      // Make sure to initialize our output to the right type.
      // Note all ensemble members are expected to produce the same
      // data type or we are toast.
      currentReader->UpdateDataObject();
      vtkDataObject* rOutput = currentReader->GetOutputDataObject(0);
      vtkDataObject* output = rOutput->NewInstance();
      outputVector->GetInformationObject(0)->Set(vtkDataObject::DATA_OBJECT(),
        output);
      output->Delete();
      return 1;
      }
    if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
      {
      if (this->MetaData)
        {
        outputVector->GetInformationObject(0)->Set(META_DATA(),
          this->MetaData);
        }
      // Call RequestInformation on all readers as they may initialize
      // data structures there. Note that this has to be done here
      // because current reader can be changed with a pipeline request
      // which does not cause REQUEST_INFORMATION to happen again.
      std::vector<vtkSmartPointer<vtkAlgorithm> >::iterator iter =
        this->Internal->Algorithms.begin();
      std::vector<vtkSmartPointer<vtkAlgorithm> >::iterator end =
        this->Internal->Algorithms.end();
      for(; iter != end; iter++)
        {
        int retVal = (*iter)->ProcessRequest(request, inputVector, outputVector);
        if (!retVal)
          {
          return retVal;
          }
        }
      return 1;
      }

    return currentReader->ProcessRequest(request, inputVector, outputVector);
    }
  return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}

void vtkEnsembleSource::AddMember(vtkAlgorithm* alg)
{
  this->Internal->Algorithms.push_back(alg);
}

void vtkEnsembleSource::RemoveAllMembers()
{
  this->Internal->Algorithms.clear();
}

unsigned int vtkEnsembleSource::GetNumberOfMembers()
{
  return static_cast<unsigned int>(this->Internal->Algorithms.size());
}

vtkAlgorithm* vtkEnsembleSource::GetCurrentReader(vtkInformation* outInfo)
{
  unsigned int currentMember = 0;
  if (outInfo->Has(UPDATE_MEMBER()))
    {
    currentMember = static_cast<unsigned int>(outInfo->Get(UPDATE_MEMBER()));
    }
  else
    {
    currentMember = this->CurrentMember;
    }
  if (currentMember >= this->GetNumberOfMembers())
    {
    return 0;
    }
  return this->Internal->Algorithms[currentMember];
}

int vtkEnsembleSource::FillOutputPortInformation(int, vtkInformation* info)
{
  info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
  return 1;
}

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

  os << indent << "Current member: " << this->CurrentMember << endl;
  os << indent << "MetaData: " << endl;
  if (this->MetaData)
    {
    this->MetaData->PrintSelf(os, indent.GetNextIndent());
    }
  else
    {
    os << indent << "(NULL)" << endl;
    }
}