Version: 6.3.1

src/OBJECT/SMESH_vtkPVUpdateSuppressor.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003  Program:   ParaView
00004  Module:    $RCSfile: SMESH_vtkPVUpdateSuppressor.cxx,v $
00005 
00006  Copyright (c) Kitware, Inc.
00007  All rights reserved.
00008  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
00009 
00010  This software is distributed WITHOUT ANY WARRANTY; without even
00011  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012  PURPOSE.  See the above copyright notice for more information.
00013 
00014  =========================================================================*/
00015 #include "SMESH_vtkPVUpdateSuppressor.h"
00016 
00017 #include "vtkAlgorithmOutput.h"
00018 #include "vtkCollection.h"
00019 #include "vtkCommand.h"
00020 #include "vtkCompositeDataPipeline.h"
00021 #include "vtkDataObject.h"
00022 #include "vtkDemandDrivenPipeline.h"
00023 #include "vtkInformation.h"
00024 #include "vtkInformationDoubleVectorKey.h"
00025 #include "vtkInformationExecutivePortKey.h"
00026 #include "vtkInformationVector.h"
00027 #include "vtkObjectFactory.h"
00028 #include "vtkPolyData.h"
00029 //#include "vtkProcessModule.h"
00030 #include "vtkSmartPointer.h"
00031 #include "vtkUnstructuredGrid.h"
00032 //#include "vtkUpdateSuppressorPipeline.h"
00033 
00034 #include <vtkstd/map>
00035 
00036 #ifdef MYDEBUG
00037 # define vtkMyDebug(x)\
00038     cout << x;
00039 #else
00040 # define vtkMyDebug(x)
00041 #endif
00042 
00043 vtkCxxRevisionMacro(vtkPVUpdateSuppressor, "$Revision: 1.1.4.2 $")
00044 ;
00045 vtkStandardNewMacro(vtkPVUpdateSuppressor)
00046 ;
00047 //----------------------------------------------------------------------------
00048 vtkPVUpdateSuppressor::vtkPVUpdateSuppressor()
00049 {
00050   this->UpdatePiece = 0;
00051   this->UpdateNumberOfPieces = 1;
00052 
00053   this->UpdateTime = 0.0;
00054   this->UpdateTimeInitialized = false;
00055 
00056   this->Enabled = 1;
00057 
00058   //  vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
00059   //
00060   //  if (pm)
00061   //    {
00062   //    this->UpdateNumberOfPieces = pm->GetNumberOfLocalPartitions();
00063   //    this->UpdatePiece = pm->GetPartitionId();
00064   //    }
00065 }
00066 
00067 //----------------------------------------------------------------------------
00068 vtkPVUpdateSuppressor::~vtkPVUpdateSuppressor()
00069 {
00070 }
00071 
00072 //----------------------------------------------------------------------------
00073 void vtkPVUpdateSuppressor::SetUpdateTime(double utime)
00074 {
00075   this->UpdateTimeInitialized = true;
00076   if (this->UpdateTime != utime)
00077     {
00078       this->Modified();
00079       this->UpdateTime = utime;
00080     }
00081 }
00082 
00083 //----------------------------------------------------------------------------
00084 void vtkPVUpdateSuppressor::SetEnabled(int enable)
00085 {
00086   if (this->Enabled == enable)
00087     {
00088       return;
00089     }
00090   this->Enabled = enable;
00091   this->Modified();
00092   //  vtkUpdateSuppressorPipeline* executive =
00093   //    vtkUpdateSuppressorPipeline::SafeDownCast(this->GetExecutive());
00094   //  if (executive)
00095   //    {
00096   //    executive->SetEnabled(enable);
00097   //    }
00098 }
00099 
00100 //----------------------------------------------------------------------------
00101 void vtkPVUpdateSuppressor::ForceUpdate()
00102 {
00103   // Make sure that output type matches input type
00104   this->UpdateInformation();
00105 
00106   vtkDataObject *input = this->GetInput();
00107   if (input == 0)
00108     {
00109       vtkErrorMacro("No valid input.");
00110       return;
00111     }
00112   vtkDataObject *output = this->GetOutput();
00113 
00114   // int fixme; // I do not like this hack.  How can we get rid of it?
00115   // Assume the input is the collection filter.
00116   // Client needs to modify the collection filter because it is not
00117   // connected to a pipeline.
00118   vtkAlgorithm *source = input->GetProducerPort()->GetProducer();
00119   if (source && (source->IsA("vtkMPIMoveData")
00120       || source->IsA("vtkCollectPolyData") || source->IsA("vtkM2NDuplicate")
00121       || source->IsA("vtkM2NCollect")
00122       || source->IsA("vtkOrderedCompositeDistributor")
00123       || source->IsA("vtkClientServerMoveData")))
00124     {
00125       source->Modified();
00126     }
00127 
00128   vtkInformation* info = input->GetPipelineInformation();
00129   vtkStreamingDemandDrivenPipeline
00130       * sddp =
00131           vtkStreamingDemandDrivenPipeline::SafeDownCast(
00132                                                          vtkExecutive::PRODUCER()->GetExecutive(
00133                                                                                                 info));
00134   if (sddp)
00135     {
00136       sddp->SetUpdateExtent(info, this->UpdatePiece,
00137                             this->UpdateNumberOfPieces, 0);
00138     }
00139   else
00140     {
00141       input->SetUpdatePiece(this->UpdatePiece);
00142       input->SetUpdateNumberOfPieces(this->UpdateNumberOfPieces);
00143       input->SetUpdateGhostLevel(0);
00144     } vtkMyDebug("ForceUpdate ");
00145   if (this->UpdateTimeInitialized)
00146     {
00147       info->Set(vtkCompositeDataPipeline::UPDATE_TIME_STEPS(),
00148                 &this->UpdateTime, 1);
00149       vtkMyDebug(this->UpdateTime);
00150     } vtkMyDebug(endl);
00151 
00152   input->Update();
00153   // Input may have changed, we obtain the pointer again.
00154   input = this->GetInput();
00155 
00156   output->ShallowCopy(input);
00157   this->PipelineUpdateTime.Modified();
00158 }
00159 
00160 //----------------------------------------------------------------------------
00161 vtkExecutive* vtkPVUpdateSuppressor::CreateDefaultExecutive()
00162 {
00163   vtkUpdateSuppressorPipeline* executive = vtkUpdateSuppressorPipeline::New();
00164   executive->SetEnabled(this->Enabled);
00165   return executive;
00166 }
00167 
00168 //----------------------------------------------------------------------------
00169 int vtkPVUpdateSuppressor::RequestDataObject(
00170                                              vtkInformation* vtkNotUsed(reqInfo),
00171                                              vtkInformationVector** inputVector,
00172                                              vtkInformationVector* outputVector)
00173 {
00174   vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
00175   if (!inInfo)
00176     {
00177       return 0;
00178     }
00179 
00180   vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT());
00181   if (input)
00182     {
00183       // for each output
00184       for (int i = 0; i < this->GetNumberOfOutputPorts(); ++i)
00185         {
00186           vtkInformation* outInfo = outputVector->GetInformationObject(i);
00187           vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
00188 
00189           if (!output || !output->IsA(input->GetClassName()))
00190             {
00191               vtkDataObject* newOutput = input->NewInstance();
00192               newOutput->SetPipelineInformation(outInfo);
00193               newOutput->Delete();
00194               this->GetOutputPortInformation(i)->Set(
00195                                                      vtkDataObject::DATA_EXTENT_TYPE(),
00196                                                      newOutput->GetExtentType());
00197             }
00198         }
00199       return 1;
00200     }
00201   return 0;
00202 
00203 }
00204 
00205 //----------------------------------------------------------------------------
00206 int vtkPVUpdateSuppressor::RequestData(vtkInformation* vtkNotUsed(reqInfo),
00207                                        vtkInformationVector** inputVector,
00208                                        vtkInformationVector* outputVector)
00209 {
00210   // RequestData is only called by its executive when 
00211   // (Enabled==off) and thus acting as a passthrough filter
00212   vtkInformation *outInfo = outputVector->GetInformationObject(0);
00213   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
00214   vtkDataObject *input = inInfo->Get(vtkDataObject::DATA_OBJECT());
00215   vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
00216 
00217   output->ShallowCopy(input);
00218   return 1;
00219 }
00220 
00221 //----------------------------------------------------------------------------
00222 void vtkPVUpdateSuppressor::PrintSelf(ostream& os, vtkIndent indent)
00223 {
00224   this->Superclass::PrintSelf(os, indent);
00225   os << indent << "UpdatePiece: " << this->UpdatePiece << endl;
00226   os << indent << "UpdateNumberOfPieces: " << this->UpdateNumberOfPieces
00227       << endl;
00228   os << indent << "Enabled: " << this->Enabled << endl;
00229   os << indent << "UpdateTime: " << this->UpdateTime << endl;
00230 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS