]> SALOME platform Git repositories - modules/smesh.git/blob - src/OBJECT/SMESH_vtkPVUpdateSuppressor.cxx
Salome HOME
0021275: EDF 1681 SMESH: Find the number of nodes of any group
[modules/smesh.git] / src / OBJECT / SMESH_vtkPVUpdateSuppressor.cxx
1 /*=========================================================================
2
3  Program:   ParaView
4  Module:    $RCSfile$
5
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9
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.
13
14  =========================================================================*/
15 #include "SMESH_vtkPVUpdateSuppressor.h"
16
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"
33
34 #include <vtkstd/map>
35
36 #ifdef MYDEBUG
37 # define vtkMyDebug(x)\
38     cout << x;
39 #else
40 # define vtkMyDebug(x)
41 #endif
42
43 vtkCxxRevisionMacro(vtkPVUpdateSuppressor, "$Revision$")
44 ;
45 vtkStandardNewMacro(vtkPVUpdateSuppressor)
46 ;
47 //----------------------------------------------------------------------------
48 vtkPVUpdateSuppressor::vtkPVUpdateSuppressor()
49 {
50   this->UpdatePiece = 0;
51   this->UpdateNumberOfPieces = 1;
52
53   this->UpdateTime = 0.0;
54   this->UpdateTimeInitialized = false;
55
56   this->Enabled = 1;
57
58   //  vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
59   //
60   //  if (pm)
61   //    {
62   //    this->UpdateNumberOfPieces = pm->GetNumberOfLocalPartitions();
63   //    this->UpdatePiece = pm->GetPartitionId();
64   //    }
65 }
66
67 //----------------------------------------------------------------------------
68 vtkPVUpdateSuppressor::~vtkPVUpdateSuppressor()
69 {
70 }
71
72 //----------------------------------------------------------------------------
73 void vtkPVUpdateSuppressor::SetUpdateTime(double utime)
74 {
75   this->UpdateTimeInitialized = true;
76   if (this->UpdateTime != utime)
77     {
78       this->Modified();
79       this->UpdateTime = utime;
80     }
81 }
82
83 //----------------------------------------------------------------------------
84 void vtkPVUpdateSuppressor::SetEnabled(int enable)
85 {
86   if (this->Enabled == enable)
87     {
88       return;
89     }
90   this->Enabled = enable;
91   this->Modified();
92   //  vtkUpdateSuppressorPipeline* executive =
93   //    vtkUpdateSuppressorPipeline::SafeDownCast(this->GetExecutive());
94   //  if (executive)
95   //    {
96   //    executive->SetEnabled(enable);
97   //    }
98 }
99
100 //----------------------------------------------------------------------------
101 void vtkPVUpdateSuppressor::ForceUpdate()
102 {
103   // Make sure that output type matches input type
104   this->UpdateInformation();
105
106   vtkDataObject *input = this->GetInput();
107   if (input == 0)
108     {
109       vtkErrorMacro("No valid input.");
110       return;
111     }
112   vtkDataObject *output = this->GetOutput();
113
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")))
124     {
125       source->Modified();
126     }
127
128   vtkInformation* info = input->GetPipelineInformation();
129   vtkStreamingDemandDrivenPipeline
130       * sddp =
131           vtkStreamingDemandDrivenPipeline::SafeDownCast(
132                                                          vtkExecutive::PRODUCER()->GetExecutive(
133                                                                                                 info));
134   if (sddp)
135     {
136       sddp->SetUpdateExtent(info, this->UpdatePiece,
137                             this->UpdateNumberOfPieces, 0);
138     }
139   else
140     {
141       input->SetUpdatePiece(this->UpdatePiece);
142       input->SetUpdateNumberOfPieces(this->UpdateNumberOfPieces);
143       input->SetUpdateGhostLevel(0);
144     } vtkMyDebug("ForceUpdate ");
145   if (this->UpdateTimeInitialized)
146     {
147       info->Set(vtkCompositeDataPipeline::UPDATE_TIME_STEPS(),
148                 &this->UpdateTime, 1);
149       vtkMyDebug(this->UpdateTime);
150     } vtkMyDebug(endl);
151
152   input->Update();
153   // Input may have changed, we obtain the pointer again.
154   input = this->GetInput();
155
156   output->ShallowCopy(input);
157   this->PipelineUpdateTime.Modified();
158 }
159
160 //----------------------------------------------------------------------------
161 vtkExecutive* vtkPVUpdateSuppressor::CreateDefaultExecutive()
162 {
163   vtkUpdateSuppressorPipeline* executive = vtkUpdateSuppressorPipeline::New();
164   executive->SetEnabled(this->Enabled);
165   return executive;
166 }
167
168 //----------------------------------------------------------------------------
169 int vtkPVUpdateSuppressor::RequestDataObject(
170                                              vtkInformation* vtkNotUsed(reqInfo),
171                                              vtkInformationVector** inputVector,
172                                              vtkInformationVector* outputVector)
173 {
174   vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
175   if (!inInfo)
176     {
177       return 0;
178     }
179
180   vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT());
181   if (input)
182     {
183       // for each output
184       for (int i = 0; i < this->GetNumberOfOutputPorts(); ++i)
185         {
186           vtkInformation* outInfo = outputVector->GetInformationObject(i);
187           vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
188
189           if (!output || !output->IsA(input->GetClassName()))
190             {
191               vtkDataObject* newOutput = input->NewInstance();
192               newOutput->SetPipelineInformation(outInfo);
193               newOutput->Delete();
194               this->GetOutputPortInformation(i)->Set(
195                                                      vtkDataObject::DATA_EXTENT_TYPE(),
196                                                      newOutput->GetExtentType());
197             }
198         }
199       return 1;
200     }
201   return 0;
202
203 }
204
205 //----------------------------------------------------------------------------
206 int vtkPVUpdateSuppressor::RequestData(vtkInformation* vtkNotUsed(reqInfo),
207                                        vtkInformationVector** inputVector,
208                                        vtkInformationVector* outputVector)
209 {
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());
216
217   output->ShallowCopy(input);
218   return 1;
219 }
220
221 //----------------------------------------------------------------------------
222 void vtkPVUpdateSuppressor::PrintSelf(ostream& os, vtkIndent indent)
223 {
224   this->Superclass::PrintSelf(os, indent);
225   os << indent << "UpdatePiece: " << this->UpdatePiece << endl;
226   os << indent << "UpdateNumberOfPieces: " << this->UpdateNumberOfPieces
227       << endl;
228   os << indent << "Enabled: " << this->Enabled << endl;
229   os << indent << "UpdateTime: " << this->UpdateTime << endl;
230 }