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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
/*=========================================================================
Program: ParaView
Module: vtkSISourceProxy.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 "vtkSISourceProxy.h"
#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkClientServerInterpreter.h"
#include "vtkCommand.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
//#include "vtkGeometryRepresentation.h"
#include "vtkInformation.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkPVInstantiator.h"
#include "vtkPVPostFilter.h"
#include "vtkPVXMLElement.h"
#include "vtkSMMessage.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkTimerLog.h"
#include "vtkUnstructuredGrid.h"
#include <vector>
#include <sstream>
#include <assert.h>
//*****************************************************************************
class vtkSISourceProxy::vtkInternals
{
public:
std::vector<vtkSmartPointer<vtkAlgorithmOutput> > OutputPorts;
std::vector<vtkSmartPointer<vtkAlgorithm> > ExtractPieces;
std::vector<vtkSmartPointer<vtkPVPostFilter> > PostFilters;
};
//*****************************************************************************
vtkStandardNewMacro(vtkSISourceProxy);
//----------------------------------------------------------------------------
vtkSISourceProxy::vtkSISourceProxy()
{
this->ExecutiveName = 0;
this->SetExecutiveName("vtkPVCompositeDataPipeline");
this->Internals = new vtkInternals();
this->PortsCreated = false;
this->DisablePipelineExecution = false;
}
//----------------------------------------------------------------------------
vtkSISourceProxy::~vtkSISourceProxy()
{
this->SetExecutiveName(0);
delete this->Internals;
}
//----------------------------------------------------------------------------
vtkAlgorithmOutput* vtkSISourceProxy::GetOutputPort(int port)
{
this->CreateOutputPorts();
if (static_cast<int>(this->Internals->OutputPorts.size()) > port)
{
return this->Internals->OutputPorts[port];
}
return NULL;
}
//----------------------------------------------------------------------------
bool vtkSISourceProxy::CreateVTKObjects(vtkSMMessage* message)
{
if (this->ObjectsCreated)
{
return true;
}
if (!this->Superclass::CreateVTKObjects(message))
{
return false;
}
vtkAlgorithm* algorithm = vtkAlgorithm::SafeDownCast(this->GetVTKObject());
if (algorithm == NULL)
{
return true;
}
if (this->ExecutiveName &&
!this->GetVTKObject()->IsA("vtkPVDataRepresentation"))
{
if(!algorithm->GetExecutive()->IsA(this->ExecutiveName))
{
vtkExecutive* executive = vtkExecutive::SafeDownCast(
vtkPVInstantiator::CreateInstance(this->ExecutiveName));
if (executive)
{
algorithm->SetExecutive(executive);
executive->FastDelete();
}
}
}
// Register observer to record the execution time for each algorithm in the
// local timer-log.
algorithm->AddObserver(
vtkCommand::StartEvent, this, &vtkSISourceProxy::MarkStartEvent);
algorithm->AddObserver(
vtkCommand::EndEvent, this, &vtkSISourceProxy::MarkEndEvent);
return true;
}
//----------------------------------------------------------------------------
bool vtkSISourceProxy::CreateOutputPorts()
{
if (this->PortsCreated)
{
return true;
}
this->PortsCreated = true;
vtkAlgorithm* algo = vtkAlgorithm::SafeDownCast(this->GetVTKObject());
if (!algo)
{
return true;
}
int ports = algo->GetNumberOfOutputPorts();
this->Internals->OutputPorts.resize(ports);
this->Internals->ExtractPieces.resize(ports);
this->Internals->PostFilters.resize(ports);
for (int cc=0; cc < ports; cc++)
{
if (!this->InitializeOutputPort(algo, cc))
{
return false;
}
}
return true;
}
//----------------------------------------------------------------------------
bool vtkSISourceProxy::InitializeOutputPort(vtkAlgorithm* algo, int port)
{
// Save the output port in internal data-structure.
this->Internals->OutputPorts[port] = algo->GetOutputPort(port);
if (strcmp("vtkPVCompositeDataPipeline", this->ExecutiveName) == 0)
{
//add the post filters to the source proxy
//so that we can do automatic conversion of properties.
this->InsertPostFilterIfNecessary(algo, port);
}
return true;
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::InsertPostFilterIfNecessary(vtkAlgorithm*, int port)
{
vtkPVPostFilter* postFilter = vtkPVPostFilter::New();
this->Internals->PostFilters[port] = postFilter;
postFilter->FastDelete();
postFilter->SetInputConnection(this->Internals->OutputPorts[port]);
// Now substitute port to point to the post-filter.
this->Internals->OutputPorts[port] = postFilter->GetOutputPort(0);
}
//----------------------------------------------------------------------------
bool vtkSISourceProxy::ReadXMLAttributes(vtkPVXMLElement* element)
{
if (!this->Superclass::ReadXMLAttributes(element))
{
return false;
}
const char* executiveName = element->GetAttribute("executive");
if (executiveName)
{
this->SetExecutiveName(executiveName);
}
return true;
}
//----------------------------------------------------------------------------
// FIXME: avoid code-duplication with vtkGeometryRepresentation. However I
// cannot add dependecy on vtkGeometryRepresentation here. Fix it!!!
namespace
{
bool vtkGeometryRepresentationDoRequestGhostCells(vtkInformation* info)
{
vtkMultiProcessController* controller =
vtkMultiProcessController::GetGlobalController();
if (controller == NULL || controller->GetNumberOfProcesses() <= 1)
{
return false;
}
if (vtkUnstructuredGrid::GetData(info) != NULL ||
vtkCompositeDataSet::GetData(info) != NULL)
{
// ensure that there's no WholeExtent to ensure
// that this UG was never born out of a structured dataset.
bool has_whole_extent = (info->Has(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()) != 0);
if (!has_whole_extent)
{
//cout << "Need ghosts" << endl;
return true;
}
}
return false;
}
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::UpdatePipeline(int port, double time, bool doTime)
{
if(this->DisablePipelineExecution)
{
return;
}
int processid =
vtkMultiProcessController::GetGlobalController()->GetLocalProcessId();
int numprocs =
vtkMultiProcessController::GetGlobalController()->GetNumberOfProcesses();
// This will create the output ports if needed.
vtkAlgorithmOutput* output_port = this->GetOutputPort(port);
if (!output_port)
{
return;
}
vtkAlgorithm* algo = output_port->GetProducer();
assert(algo);
vtkStreamingDemandDrivenPipeline* sddp =
vtkStreamingDemandDrivenPipeline::SafeDownCast(
algo->GetExecutive());
sddp->UpdateInformation();
int real_port = output_port->GetIndex();
// Refer to BUG #11811 and BUG #12546. vtkGeometryRepresentation needs
// ghost-cells if available (11811), but not asking for ghost-cells earlier than the
// representation results in multiple executes (12546). Hence, we request
// ghost-cells in UpdatePipeline().
vtkInformation* outInfo = sddp->GetOutputInformation(real_port);
bool req_ghost_cells = vtkGeometryRepresentationDoRequestGhostCells(
outInfo);
outInfo->Set(sddp->UPDATE_PIECE_NUMBER(), processid);
outInfo->Set(sddp->UPDATE_NUMBER_OF_PIECES(), numprocs);
outInfo->Set(sddp->UPDATE_NUMBER_OF_GHOST_LEVELS(), req_ghost_cells?1 : 0);
if (doTime)
{
outInfo->Set(sddp->UPDATE_TIME_STEP(), time);
}
sddp->Update(real_port);
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::UpdatePipelineInformation()
{
if(this->DisablePipelineExecution)
{
return;
}
if (this->GetVTKObject())
{
vtkAlgorithm* algo = vtkAlgorithm::SafeDownCast(this->GetVTKObject());
if(algo)
{
algo->UpdateInformation();
}
}
// Call UpdatePipelineInformation() on all subproxies.
for (unsigned int cc=0; cc < this->GetNumberOfSubSIProxys(); cc++)
{
vtkSISourceProxy* src = vtkSISourceProxy::SafeDownCast(this->GetSubSIProxy(cc));
if (src)
{
src->UpdatePipelineInformation();
}
}
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::SetupSelectionProxy(int port, vtkSIProxy* extractSelection)
{
vtkAlgorithm* algo = vtkAlgorithm::SafeDownCast(
extractSelection->GetVTKObject());
algo->SetInputConnection(this->GetOutputPort(port));
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::MarkStartEvent()
{
std::ostringstream filterName;
filterName
<< "Execute "
<< (this->GetVTKClassName()? this->GetVTKClassName() : this->GetClassName())
<< " id: " << this->GetGlobalID();
vtkTimerLog::MarkStartEvent(filterName.str().c_str());
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::MarkEndEvent()
{
std::ostringstream filterName;
filterName
<< "Execute "
<< (this->GetVTKClassName()? this->GetVTKClassName() : this->GetClassName())
<< " id: " << this->GetGlobalID();
vtkTimerLog::MarkEndEvent(filterName.str().c_str());
}
//----------------------------------------------------------------------------
void vtkSISourceProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|