1 /*=========================================================================
6 Copyright (c) Kitware, Inc.
8 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
14 =========================================================================*/
15 #include "SMESH_vtkPVUpdateSuppressor.h"
17 #include "vtkAlgorithmOutput.h"
18 #include "vtkCollection.h"
19 #include "vtkCommand.h"
20 #include "vtkCompositeDataPipeline.h"
21 #include "vtkDataObject.h"
22 #include "vtkDemandDrivenPipeline.h"
23 #include "vtkInformation.h"
24 #include "vtkInformationDoubleVectorKey.h"
25 #include "vtkInformationExecutivePortKey.h"
26 #include "vtkInformationVector.h"
27 #include "vtkObjectFactory.h"
28 #include "vtkPolyData.h"
29 //#include "vtkProcessModule.h"
30 #include "vtkSmartPointer.h"
31 #include "vtkUnstructuredGrid.h"
32 //#include "vtkUpdateSuppressorPipeline.h"
37 # define vtkMyDebug(x)\
40 # define vtkMyDebug(x)
43 vtkCxxRevisionMacro(vtkPVUpdateSuppressor, "$Revision$")
45 vtkStandardNewMacro(vtkPVUpdateSuppressor)
47 //----------------------------------------------------------------------------
48 vtkPVUpdateSuppressor::vtkPVUpdateSuppressor()
50 this->UpdatePiece = 0;
51 this->UpdateNumberOfPieces = 1;
53 this->UpdateTime = 0.0;
54 this->UpdateTimeInitialized = false;
58 // vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
62 // this->UpdateNumberOfPieces = pm->GetNumberOfLocalPartitions();
63 // this->UpdatePiece = pm->GetPartitionId();
67 //----------------------------------------------------------------------------
68 vtkPVUpdateSuppressor::~vtkPVUpdateSuppressor()
72 //----------------------------------------------------------------------------
73 void vtkPVUpdateSuppressor::SetUpdateTime(double utime)
75 this->UpdateTimeInitialized = true;
76 if (this->UpdateTime != utime)
79 this->UpdateTime = utime;
83 //----------------------------------------------------------------------------
84 void vtkPVUpdateSuppressor::SetEnabled(int enable)
86 if (this->Enabled == enable)
90 this->Enabled = enable;
92 // vtkUpdateSuppressorPipeline* executive =
93 // vtkUpdateSuppressorPipeline::SafeDownCast(this->GetExecutive());
96 // executive->SetEnabled(enable);
100 //----------------------------------------------------------------------------
101 void vtkPVUpdateSuppressor::ForceUpdate()
103 // Make sure that output type matches input type
104 this->UpdateInformation();
106 vtkDataObject *input = this->GetInput();
109 vtkErrorMacro("No valid input.");
112 vtkDataObject *output = this->GetOutput();
114 // int fixme; // I do not like this hack. How can we get rid of it?
115 // Assume the input is the collection filter.
116 // Client needs to modify the collection filter because it is not
117 // connected to a pipeline.
118 vtkAlgorithm *source = input->GetProducerPort()->GetProducer();
119 if (source && (source->IsA("vtkMPIMoveData")
120 || source->IsA("vtkCollectPolyData") || source->IsA("vtkM2NDuplicate")
121 || source->IsA("vtkM2NCollect")
122 || source->IsA("vtkOrderedCompositeDistributor")
123 || source->IsA("vtkClientServerMoveData")))
128 vtkInformation* info = input->GetPipelineInformation();
129 vtkStreamingDemandDrivenPipeline
131 vtkStreamingDemandDrivenPipeline::SafeDownCast(
132 vtkExecutive::PRODUCER()->GetExecutive(
136 sddp->SetUpdateExtent(info, this->UpdatePiece,
137 this->UpdateNumberOfPieces, 0);
141 input->SetUpdatePiece(this->UpdatePiece);
142 input->SetUpdateNumberOfPieces(this->UpdateNumberOfPieces);
143 input->SetUpdateGhostLevel(0);
144 } vtkMyDebug("ForceUpdate ");
145 if (this->UpdateTimeInitialized)
147 info->Set(vtkCompositeDataPipeline::UPDATE_TIME_STEPS(),
148 &this->UpdateTime, 1);
149 vtkMyDebug(this->UpdateTime);
153 // Input may have changed, we obtain the pointer again.
154 input = this->GetInput();
156 output->ShallowCopy(input);
157 this->PipelineUpdateTime.Modified();
160 //----------------------------------------------------------------------------
161 vtkExecutive* vtkPVUpdateSuppressor::CreateDefaultExecutive()
163 vtkUpdateSuppressorPipeline* executive = vtkUpdateSuppressorPipeline::New();
164 executive->SetEnabled(this->Enabled);
168 //----------------------------------------------------------------------------
169 int vtkPVUpdateSuppressor::RequestDataObject(
170 vtkInformation* vtkNotUsed(reqInfo),
171 vtkInformationVector** inputVector,
172 vtkInformationVector* outputVector)
174 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
180 vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT());
184 for (int i = 0; i < this->GetNumberOfOutputPorts(); ++i)
186 vtkInformation* outInfo = outputVector->GetInformationObject(i);
187 vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
189 if (!output || !output->IsA(input->GetClassName()))
191 vtkDataObject* newOutput = input->NewInstance();
192 newOutput->SetPipelineInformation(outInfo);
194 this->GetOutputPortInformation(i)->Set(
195 vtkDataObject::DATA_EXTENT_TYPE(),
196 newOutput->GetExtentType());
205 //----------------------------------------------------------------------------
206 int vtkPVUpdateSuppressor::RequestData(vtkInformation* vtkNotUsed(reqInfo),
207 vtkInformationVector** inputVector,
208 vtkInformationVector* outputVector)
210 // RequestData is only called by its executive when
211 // (Enabled==off) and thus acting as a passthrough filter
212 vtkInformation *outInfo = outputVector->GetInformationObject(0);
213 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
214 vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT());
215 vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
217 output->ShallowCopy(input);
221 //----------------------------------------------------------------------------
222 void vtkPVUpdateSuppressor::PrintSelf(ostream& os, vtkIndent indent)
224 this->Superclass::PrintSelf(os, indent);
225 os << indent << "UpdatePiece: " << this->UpdatePiece << endl;
226 os << indent << "UpdateNumberOfPieces: " << this->UpdateNumberOfPieces
228 os << indent << "Enabled: " << this->Enabled << endl;
229 os << indent << "UpdateTime: " << this->UpdateTime << endl;