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
|
/*=========================================================================
Program: ParaView
Module: vtkSICompoundSourceProxy.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 "vtkSICompoundSourceProxy.h"
#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkInformation.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkPVXMLElement.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include <vector>
#include <sstream>
#include <assert.h>
//*****************************************************************************
class vtkSICompoundSourceProxy::vtkInternals
{
public:
struct PortInfo
{
std::string ProxyName;
std::string ExposedName;
std::string PortName;
unsigned int PortIndex;
PortInfo()
{
this->PortIndex = VTK_UNSIGNED_INT_MAX;
}
bool HasPortIndex()
{
return this->PortIndex != VTK_UNSIGNED_INT_MAX;
}
bool HasPortName()
{
return !this->HasPortIndex();
}
};
void RegisterExposedPort(const char* proxyName, const char* exposedName, int portIndex)
{
PortInfo info;
info.PortIndex = portIndex;
info.ProxyName = proxyName;
info.ExposedName = exposedName;
this->ExposedPorts.push_back(info);
this->NeedOutputPortCreation = true;
}
void RegisterExposedPort(const char* proxyName, const char* exposedName, const char* portName)
{
PortInfo info;
info.PortName = portName;
info.ProxyName = proxyName;
info.ExposedName = exposedName;
this->ExposedPorts.push_back(info);
this->NeedOutputPortCreation = true;
}
int GetNumberOfOutputPorts()
{
return static_cast<int>(this->ExposedPorts.size());
}
typedef std::vector<PortInfo> VectorOfPortInfo;
VectorOfPortInfo ExposedPorts;
std::vector<vtkSmartPointer<vtkAlgorithmOutput> > OutputPorts;
bool NeedOutputPortCreation;
};
//*****************************************************************************
vtkStandardNewMacro(vtkSICompoundSourceProxy);
//----------------------------------------------------------------------------
vtkSICompoundSourceProxy::vtkSICompoundSourceProxy()
{
this->Internals = new vtkInternals();
}
//----------------------------------------------------------------------------
vtkSICompoundSourceProxy::~vtkSICompoundSourceProxy()
{
delete this->Internals;
}
//----------------------------------------------------------------------------
vtkAlgorithmOutput* vtkSICompoundSourceProxy::GetOutputPort(int port)
{
if(this->Internals->NeedOutputPortCreation)
{
this->CreateOutputPorts();
}
if (static_cast<int>(this->Internals->OutputPorts.size()) > port)
{
return this->Internals->OutputPorts[port];
}
return NULL;
}
//----------------------------------------------------------------------------
bool vtkSICompoundSourceProxy::CreateOutputPorts()
{
if(this->Internals->NeedOutputPortCreation)
{
int ports = this->Internals->GetNumberOfOutputPorts();
this->Internals->OutputPorts.resize(ports);
for (int cc=0; cc < ports; cc++)
{
vtkSISourceProxy* subProxy = vtkSISourceProxy::SafeDownCast(
this->GetSubSIProxy(
this->Internals->ExposedPorts[cc].ProxyName.c_str()));
if (!subProxy)
{
vtkErrorMacro("Failed to locate subproxy: " <<
this->Internals->ExposedPorts[cc].ProxyName.c_str());
return false;
}
this->Internals->OutputPorts[cc] = subProxy->GetOutputPort(
this->Internals->ExposedPorts[cc].PortIndex);
}
this->Internals->NeedOutputPortCreation = false;
}
return true;
}
//----------------------------------------------------------------------------
bool vtkSICompoundSourceProxy::ReadXMLAttributes(vtkPVXMLElement* element)
{
if (!this->Superclass::ReadXMLAttributes(element))
{
return false;
}
// Initialise exposed output port -------------------------------------------
int index=0;
unsigned int numElems = element->GetNumberOfNestedElements();
for (unsigned int i=0; i < numElems; i++)
{
vtkPVXMLElement* currentElement = element->GetNestedElement(i);
if ( currentElement->GetName() &&
strcmp(currentElement->GetName(), "OutputPort") == 0)
{
const char* exposed_name = currentElement->GetAttribute("name");
const char* proxy_name = currentElement->GetAttribute("proxy");
const char* port_name = currentElement->GetAttribute("port_name");
if (!port_name && !currentElement->GetScalarAttribute("port_index", &index))
{
vtkErrorMacro("Missing output port 'index'.");
return 0;
}
if (!exposed_name)
{
vtkErrorMacro("Missing output port 'name'.");
return 0;
}
if (!proxy_name)
{
vtkErrorMacro("Missing output port 'proxy'.");
return 0;
}
if (port_name)
{
this->Internals->RegisterExposedPort(proxy_name, exposed_name, port_name);
}
else
{
this->Internals->RegisterExposedPort(proxy_name, exposed_name, index);
}
}
}
return true;
}
//----------------------------------------------------------------------------
void vtkSICompoundSourceProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|