X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPlugins%2FMEDReader%2FIO%2FvtkMEDReader.cxx;h=7c4b308cb9e3f0ba9c631f19c7a089d6352284db;hb=e54758a2008aa21844f649b1379360bf1a1ee61c;hp=b15d931bc2f90f0c6b56898b7db0844e8268f588;hpb=e32938b374fc9583c1dc3a69a3b3ec23e7c49b3e;p=modules%2Fparavis.git diff --git a/src/Plugins/MEDReader/IO/vtkMEDReader.cxx b/src/Plugins/MEDReader/IO/vtkMEDReader.cxx index b15d931b..7c4b308c 100644 --- a/src/Plugins/MEDReader/IO/vtkMEDReader.cxx +++ b/src/Plugins/MEDReader/IO/vtkMEDReader.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2014 CEA/DEN, EDF R&D +// Copyright (C) 2010-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -44,30 +44,128 @@ #include "vtkCellArray.h" #include "vtkDoubleArray.h" #include "vtkObjectFactory.h" +#include "vtkInformationDataObjectMetaDataKey.h" + +#ifdef MEDREADER_USE_MPI +#include "vtkMultiProcessController.h" +#endif #include "MEDFileFieldRepresentationTree.hxx" +#include #include #include #include #include +/*! + * This class stores properties in loading state mode (pvsm) when the MED file has not been read yet. + * The file is not read beacause FileName has not been informed yet ! So this class stores properties of vtkMEDReader instance that + * owns it and wait the vtkMEDReader::SetFileName to apply properties afterwards. + */ +class PropertyKeeper +{ +public: + PropertyKeeper(vtkMEDReader *master):_master(master),IsGVActivated(false),GVValue(0),IsCMActivated(false),CMValue(0) { } + void assignPropertiesIfNeeded(); + bool arePropertiesOnTreeToSetAfter() const; + // + void pushFieldStatusEntry(const char* name, int status); + void pushGenerateVectorsValue(int value); + void pushChangeModeValue(int value); + void pushTimesFlagsStatusEntry(const char* name, int status); +protected: + // pool of pairs to assign in SetFieldsStatus if needed. The use case is the load using pvsm. + std::vector< std::pair > SetFieldsStatusPairs; + // generate vector + bool IsGVActivated; + int GVValue; + // change mode + bool IsCMActivated; + int CMValue; + // + std::vector< std::pair > TimesFlagsStatusPairs; + vtkMEDReader *_master; +}; + +void PropertyKeeper::assignPropertiesIfNeeded() +{ + if(!this->SetFieldsStatusPairs.empty()) + { + for(std::vector< std::pair >::const_iterator it=this->SetFieldsStatusPairs.begin();it!=this->SetFieldsStatusPairs.end();it++) + _master->SetFieldsStatus((*it).first.c_str(),(*it).second); + this->SetFieldsStatusPairs.clear(); + } + if(!this->TimesFlagsStatusPairs.empty()) + { + for(std::vector< std::pair >::const_iterator it=this->TimesFlagsStatusPairs.begin();it!=this->TimesFlagsStatusPairs.end();it++) + _master->SetTimesFlagsStatus((*it).first.c_str(),(*it).second); + this->TimesFlagsStatusPairs.clear(); + } + if(this->IsGVActivated) + { + _master->GenerateVectors(this->GVValue); + this->IsGVActivated=false; + } + if(this->IsCMActivated) + { + _master->ChangeMode(this->CMValue); + this->IsCMActivated=false; + } +} + +void PropertyKeeper::pushFieldStatusEntry(const char* name, int status) +{ + bool found(false); + for(std::vector< std::pair >::const_iterator it=this->SetFieldsStatusPairs.begin();it!=this->SetFieldsStatusPairs.end() && !found;it++) + found=(*it).first==name; + if(!found) + this->SetFieldsStatusPairs.push_back(std::pair(name,status)); +} + +void PropertyKeeper::pushTimesFlagsStatusEntry(const char* name, int status) +{ + bool found(false); + for(std::vector< std::pair >::const_iterator it=this->TimesFlagsStatusPairs.begin();it!=this->TimesFlagsStatusPairs.end() && !found;it++) + found=(*it).first==name; + if(!found) + this->TimesFlagsStatusPairs.push_back(std::pair(name,status)); +} + +void PropertyKeeper::pushGenerateVectorsValue(int value) +{ + this->IsGVActivated=true; + this->GVValue=value; +} + +void PropertyKeeper::pushChangeModeValue(int value) +{ + this->IsCMActivated=true; + this->CMValue=value; +} + +bool PropertyKeeper::arePropertiesOnTreeToSetAfter() const +{ + return !SetFieldsStatusPairs.empty(); +} + class vtkMEDReader::vtkMEDReaderInternal { public: - vtkMEDReaderInternal():TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2) + vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master),MyMTime(0) { } - + bool PluginStart0() { + return false; // TODO Useless and buggy if(FirstCall0==0) return false; FirstCall0--; return true; } - + ~vtkMEDReaderInternal() { if(this->SIL) @@ -88,13 +186,37 @@ public: vtkMutableDirectedGraph* SIL; // store the lev0 id in Tree corresponding to the TIME_STEPS in the pipeline. int LastLev0; + // The property keeper is usable only in pvsm mode. + PropertyKeeper PK; + int MyMTime; + std::set _wonderful_set;// this set is used by SetFieldsStatus method to detect the fact that SetFieldsStatus has been called for all items ! Great Items are not sorted ! Why ? + std::map _wonderful_ref;// this map stores the state before a SetFieldsStatus status. + private: unsigned char FirstCall0; }; vtkStandardNewMacro(vtkMEDReader); -vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal) +// vtkInformationKeyMacro(vtkMEDReader, META_DATA, DataObjectMetaData); // Here we need to customize vtkMEDReader::META_DATA method +// start of overload of vtkInformationKeyMacro +static vtkInformationDataObjectMetaDataKey *vtkMEDReader_META_DATA=new vtkInformationDataObjectMetaDataKey("META_DATA","vtkMEDReader"); + +vtkInformationDataObjectMetaDataKey *vtkMEDReader::META_DATA() +{ + static const char ZE_KEY[]="vtkMEDReader::META_DATA"; + vtkInformationDataObjectMetaDataKey *ret(vtkMEDReader_META_DATA); + ParaMEDMEM::GlobalDict *gd(ParaMEDMEM::GlobalDict::GetInstance()); + if(!gd->hasKey(ZE_KEY)) + {// here META_DATA is put on global var to be exchanged with other filters without dependancy of MEDReader. Please do not change ZE_KEY ! + std::ostringstream oss; oss << ret; + gd->setKeyValue(ZE_KEY,oss.str()); + } + return ret; +} +// end of overload of vtkInformationKeyMacro + +vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal(this)) { this->SetNumberOfInputPorts(0); this->SetNumberOfOutputPorts(1); @@ -103,21 +225,35 @@ vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal) vtkMEDReader::~vtkMEDReader() { delete this->Internal; + this->Internal = 0; } -void vtkMEDReader::Reload(int a) +void vtkMEDReader::Reload() { - if(a==0) - return; - std::cerr << "vtkMEDReader::Reload" << a << std::endl; std::string fName((const char *)this->GetFileName()); delete this->Internal; - this->Internal=new vtkMEDReaderInternal; + this->Internal=new vtkMEDReaderInternal(this); this->SetFileName(fName.c_str()); } +int vtkMEDReader::GetServerModifTime() +{ + if( !this->Internal ) + return -1; + return this->Internal->MyMTime; +} + void vtkMEDReader::GenerateVectors(int val) { + if ( !this->Internal ) + return; + + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushGenerateVectorsValue(val); + return ; + } + //not pvsm mode (general case) bool val2((bool)val); if(val2!=this->Internal->GenerateVect) { @@ -128,8 +264,16 @@ void vtkMEDReader::GenerateVectors(int val) void vtkMEDReader::ChangeMode(int newMode) { + if ( !this->Internal ) + return; + + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushChangeModeValue(newMode); + return ; + } + //not pvsm mode (general case) this->Internal->IsStdOrMode=newMode!=0; - //std::cerr << "vtkMEDReader::ChangeMode : " << this->Internal->IsStdOrMode << std::endl; this->Modified(); } @@ -140,6 +284,8 @@ const char *vtkMEDReader::GetSeparator() void vtkMEDReader::SetFileName(const char *fname) { + if(!this->Internal) + return; try { this->Internal->FileName=fname; @@ -152,11 +298,22 @@ void vtkMEDReader::SetFileName(const char *fname) } if(this->Internal->Tree.getNumberOfLeavesArrays()==0) { - this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv); - this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client. + int iPart(-1),nbOfParts(-1); +#ifdef MEDREADER_USE_MPI + vtkMultiProcessController *vmpc(vtkMultiProcessController::GetGlobalController()); + if(vmpc) + { + iPart=vmpc->GetLocalProcessId(); + nbOfParts=vmpc->GetNumberOfProcesses(); + } +#endif + this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv,iPart,nbOfParts); + if(!this->Internal->PK.arePropertiesOnTreeToSetAfter()) + this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client. this->Internal->TK.setMaxNumberOfTimeSteps(this->Internal->Tree.getMaxNumberOfTimeSteps()); } this->Modified(); + this->Internal->PK.assignPropertiesIfNeeded(); } catch(INTERP_KERNEL::Exception& e) { @@ -174,27 +331,39 @@ void vtkMEDReader::SetFileName(const char *fname) char *vtkMEDReader::GetFileName() { + if (!this->Internal) + return 0; return const_cast(this->Internal->FileName.c_str()); } int vtkMEDReader::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) { - //std::cerr << "########################################## RequestInformation ##########################################" << std::endl; +// std::cout << "########################################## vtkMEDReader::RequestInformation ##########################################" << std::endl; if(!this->Internal) return 0; try { +// request->Print(cout); vtkInformation *outInfo(outputVector->GetInformationObject(0)); - outInfo->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),-1); outInfo->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkMultiBlockDataSet"); - this->UpdateSIL(outInfo); - // + this->UpdateSIL(request, outInfo); + + // Set the meta data graph as a meta data key in the information + // That's all that is needed to transfer it along the pipeline + outInfo->Set(vtkMEDReader::META_DATA(),this->Internal->SIL); + bool dummy(false); this->PublishTimeStepsIfNeeded(outInfo,dummy); } catch(INTERP_KERNEL::Exception& e) { - std::cerr << "Exception has been thrown in vtkMEDReader::RequestInformation : " << e.what() << std::endl; + std::ostringstream oss; + oss << "Exception has been thrown in vtkMEDReader::RequestInformation : " << e.what() << std::endl; + if(this->HasObserver("ErrorEvent") ) + this->InvokeEvent("ErrorEvent",const_cast(oss.str().c_str())); + else + vtkOutputWindowDisplayErrorText(const_cast(oss.str().c_str())); + vtkObject::BreakOnError(); return 0; } return 1; @@ -202,26 +371,27 @@ int vtkMEDReader::RequestInformation(vtkInformation *request, vtkInformationVect int vtkMEDReader::RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) { - //std::cerr << "########################################## RequestData ##########################################"; +// std::cout << "########################################## vtkMEDReader::RequestData ##########################################" << std::endl; if(!this->Internal) return 0; try { +// request->Print(cout); vtkInformation *outInfo(outputVector->GetInformationObject(0)); vtkMultiBlockDataSet *output(vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()))); bool isUpdated(false); double reqTS(0.); if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())) reqTS=outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()); - //std::cerr << reqTS << std::endl; this->FillMultiBlockDataSetInstance(output,reqTS); output->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(),reqTS); - this->UpdateSIL(outInfo); - //this->UpdateProgress((float) progress/((float) maxprogress-1)); + + // Is it really needed ? TODO + this->UpdateSIL(request, outInfo); } catch(INTERP_KERNEL::Exception& e) { - std::cerr << "Exception has been thrown in vtkMEDReader::RequestInformation : " << e.what() << std::endl; + std::cerr << "Exception has been thrown in vtkMEDReader::RequestData : " << e.what() << std::endl; return 0; } return 1; @@ -229,31 +399,64 @@ int vtkMEDReader::RequestData(vtkInformation *request, vtkInformationVector **in void vtkMEDReader::SetFieldsStatus(const char* name, int status) { - //std::cerr << "vtkMEDReader::SetFieldsStatus(" << name << "," << status << ") called !" << std::endl; - this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status); - if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1)) - if(!this->Internal->PluginStart0()) - this->Modified(); + if( !this->Internal ) + return; + + //this->Internal->_wonderful_set.insert(name); + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushFieldStatusEntry(name,status); + return ; + } + if(this->Internal->_wonderful_set.empty()) + this->Internal->_wonderful_ref=this->Internal->Tree.dumpState();// start of SetFieldsStatus serie -> store ref to compare at the end of the SetFieldsStatus serie. + this->Internal->_wonderful_set.insert(name); + //not pvsm mode (general case) + try + { + this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status); + if(this->Internal->_wonderful_set.size()==GetNumberOfFieldsTreeArrays()) + { + if(this->Internal->_wonderful_ref!=this->Internal->Tree.dumpState()) + { + if(!this->Internal->PluginStart0()) + { + this->Modified(); + } + this->Internal->MyMTime++; + } + this->Internal->_wonderful_set.clear(); + } + } + catch(INTERP_KERNEL::Exception& e) + { + if(!this->Internal->FileName.empty()) + { + std::cerr << "vtkMEDReader::SetFieldsStatus error : " << e.what() << " *** WITH STATUS=" << status << endl; + return ; + } + } } int vtkMEDReader::GetNumberOfFieldsTreeArrays() { if(!this->Internal) return 0; - int ret(this->Internal->Tree.getNumberOfLeavesArrays()); - //std::cerr << "vtkMEDReader::GetNumberOfFieldsTreeArrays called ! " << ret << std::endl; - return ret; + return this->Internal->Tree.getNumberOfLeavesArrays(); } const char *vtkMEDReader::GetFieldsTreeArrayName(int index) { - std::string ret(this->Internal->Tree.getNameOf(index)); - //std::cerr << "vtkMEDReader::GetFieldsTreeArrayName(" << index << ") called ! " << ret << std::endl; - return ret.c_str(); + if(!this->Internal) + return 0; + return this->Internal->Tree.getNameOfC(index); } int vtkMEDReader::GetFieldsTreeArrayStatus(const char *name) { + if(!this->Internal) + return -1; + int zeId(this->Internal->Tree.getIdHavingZeName(name)); int ret(this->Internal->Tree.getStatusOf(zeId)); return ret; @@ -261,6 +464,15 @@ int vtkMEDReader::GetFieldsTreeArrayStatus(const char *name) void vtkMEDReader::SetTimesFlagsStatus(const char *name, int status) { + if (!this->Internal) + return; + + if(this->Internal->FileName.empty()) + {//pvsm mode + this->Internal->PK.pushTimesFlagsStatusEntry(name,status); + return ; + } + //not pvsm mode (general case) int pos(0); std::istringstream iss(name); iss >> pos; this->Internal->TK.getTimesFlagArray()[pos].first=(bool)status; @@ -286,16 +498,20 @@ const char *vtkMEDReader::GetTimesFlagsArrayName(int index) int vtkMEDReader::GetTimesFlagsArrayStatus(const char *name) { + if(!this->Internal) + return -1; int pos(0); std::istringstream iss(name); iss >> pos; return (int)this->Internal->TK.getTimesFlagArray()[pos].first; } -void vtkMEDReader::UpdateSIL(vtkInformation *info) +void vtkMEDReader::UpdateSIL(vtkInformation* request, vtkInformation *info) { if(!this->Internal) - return ; + return; vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::New()); + + // This Should be more clever, TODO std::string meshName(this->BuildSIL(sil)); if(meshName!=this->Internal->DftMeshName) { @@ -303,8 +519,6 @@ void vtkMEDReader::UpdateSIL(vtkInformation *info) this->Internal->SIL->Delete(); this->Internal->SIL=sil; this->Internal->DftMeshName=meshName; - info->Set(vtkDataObject::SIL(),this->Internal->SIL); - //request->AppendUnique(vtkExecutive::KEYS_TO_COPY(),vtkDataObject::SIL()); } else { @@ -317,6 +531,8 @@ void vtkMEDReader::UpdateSIL(vtkInformation *info) */ std::string vtkMEDReader::BuildSIL(vtkMutableDirectedGraph* sil) { + if (!this->Internal) + return std::string(); sil->Initialize(); vtkSmartPointer childEdge(vtkSmartPointer::New()); childEdge->InsertNextValue(0); @@ -353,6 +569,9 @@ std::string vtkMEDReader::BuildSIL(vtkMutableDirectedGraph* sil) double vtkMEDReader::PublishTimeStepsIfNeeded(vtkInformation *outInfo, bool& isUpdated) { + if(!this->Internal) + return 0.0; + int lev0(-1); std::vector tsteps; if(!this->Internal->IsStdOrMode) @@ -375,6 +594,8 @@ double vtkMEDReader::PublishTimeStepsIfNeeded(vtkInformation *outInfo, bool& isU void vtkMEDReader::FillMultiBlockDataSetInstance(vtkMultiBlockDataSet *output, double reqTS) { + if( !this->Internal ) + return; std::string meshName; vtkDataSet *ret(this->Internal->Tree.buildVTKInstance(this->Internal->IsStdOrMode,reqTS,meshName,this->Internal->TK)); if(this->Internal->GenerateVect)