Back to index

salome-paravis  6.5.0
vtkParaMEDCorbaSource.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "vtkParaMEDCorbaSource.h"
00021 
00022 #include "vtkPoints.h"
00023 #include "vtkIntArray.h"
00024 #include "vtkCellData.h"
00025 #include "vtkCellTypes.h"
00026 #include "vtkCharArray.h"
00027 #include "vtkPointData.h"
00028 #include "vtkDoubleArray.h"
00029 #include "vtkMultiBlockDataSet.h"
00030 #include "vtkUnstructuredGrid.h"
00031 //
00032 #include "vtkStreamingDemandDrivenPipeline.h"
00033 #include "vtkGenericAttributeCollection.h"
00034 #include "vtkInformationVector.h"
00035 #include "vtkObjectFactory.h"
00036 #include "vtkInformation.h"
00037 //
00038 #include "vtkstd/string"
00039 #include "vtksys/ios/fstream"
00040 #include "vtkstd/algorithm"
00041 
00042 #include "VTKMEDCouplingMeshClient.hxx"
00043 #include "VTKMEDCouplingFieldClient.hxx"
00044 #include "VTKMEDCouplingMultiFieldsClient.hxx"
00045 #include "VTKParaMEDFieldClient.hxx"
00046 
00047 //Work with IOR.
00048 #include "ParaMEDCouplingCorbaServant.hh"
00049 //
00050 
00051 vtkStandardNewMacro(vtkParaMEDCorbaSource);
00052 vtkCxxRevisionMacro(vtkParaMEDCorbaSource,"$Revision: 1.1.2.4.10.1 $");
00053 
00054 void *vtkParaMEDCorbaSource::Orb=0;
00055 
00056 vtkParaMEDCorbaSource::vtkParaMEDCorbaSource():mfieldsFetcher(0)
00057 {
00058   this->MyDataSet=0;
00059   if(!Orb)
00060     {
00061       CORBA::ORB_var *OrbC=new CORBA::ORB_var;
00062       int argc=0;
00063       *OrbC=CORBA::ORB_init(argc,0);
00064       this->Orb=OrbC;
00065     }
00066   this->SetNumberOfInputPorts(0);
00067   this->SetNumberOfOutputPorts(1);
00068 }
00069 
00070 vtkParaMEDCorbaSource::~vtkParaMEDCorbaSource()
00071 {
00072   delete mfieldsFetcher;
00073 }
00074 
00075 const char *vtkParaMEDCorbaSource::GetIORCorba()
00076 {
00077   return &IOR[0];
00078 }
00079 
00080 void vtkParaMEDCorbaSource::SetIORCorba(char *ior)
00081 {
00082   if(!ior)
00083     return;
00084   if(ior[0]=='\0')
00085     return;
00086   int length=strlen(ior);
00087   IOR.resize(length+1);
00088   vtkstd::copy(ior,ior+length+1,&IOR[0]);
00089   this->Modified();
00090 }
00091 
00092 void vtkParaMEDCorbaSource::SetBufferingPolicy(int pol)
00093 {
00094   BufferingPolicy=pol;
00095 }
00096 
00097 int vtkParaMEDCorbaSource::GetBufferingPolicy()
00098 {
00099   return BufferingPolicy;
00100 }
00101 
00102  //int vtkParaMEDCorbaSource::RequestUpdateExtent( vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo )
00103  //{
00104  //return this->Superclass::RequestUpdateExtent(request,inInfo,outInfo);
00105 
00106   /*vtkParaMEDCorbaDataSet* output = vtkParaMEDCorbaDataSet::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT() ) );
00107   if ( ! output )
00108     {
00109     output = vtkParaMEDCorbaDataSet::New();
00110     output->SetPipelineInformation( info );
00111     output->Delete();
00112     this->GetOutputPortInformation( 0 )->Set( vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType() );
00113     }*/
00114 
00115  // return 1;
00116  //}
00117 
00118 int vtkParaMEDCorbaSource::ProcessRequest(vtkInformation* request,
00119                                          vtkInformationVector** inputVector,
00120                                          vtkInformationVector* outputVector)
00121 {
00122   // generate the data
00123   if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
00124     {
00125     return this->RequestData(request, inputVector, outputVector);
00126     }
00127   if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
00128     {
00129     return this->RequestInformation(request, inputVector, outputVector);
00130     }
00131   return this->Superclass::ProcessRequest(request, inputVector, outputVector);
00132 }
00133 
00134 int vtkParaMEDCorbaSource::FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info)
00135 {
00136   info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
00137   return 1;
00138 }
00139 
00140 int vtkParaMEDCorbaSource::RequestInformation(vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo)
00141 {
00142   vtkInformation* myInfo=outInfo->GetInformationObject(0);
00143   //myInfo->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
00144   if(!IOR.empty())
00145     {
00146       //myInfo->Remove(vtkDataObject::DATA_TYPE_NAME());
00147       //myInfo->Remove(PORT_REQUIREMENTS_FILLED());
00148       //myInfo->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
00149       //myInfo->Set(PORT_REQUIREMENTS_FILLED(),1);
00150       //vtkUnstructuredGrid *tony=vtkUnstructuredGrid::New();
00151       //tony->SetInformation(myInfo);
00152       //myInfo->Set(vtkDataObject::DATA_OBJECT(),tony);
00153       //
00154       CORBA::ORB_var *OrbC=(CORBA::ORB_var *)this->Orb;
00155       CORBA::Object_var obj=(*OrbC)->string_to_object(&IOR[0]);
00156       //
00157       Engines::MPIObject_ptr objPara=Engines::MPIObject::_narrow(obj);
00158       if(CORBA::is_nil(objPara))
00159         {//sequential
00160          this->TotalNumberOfPieces=1;
00161          SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_var multiPtr=SALOME_MED::MEDCouplingMultiFieldsCorbaInterface::_narrow(obj);
00162           if(!CORBA::is_nil(multiPtr))
00163            {//Request for multiFields
00164               delete mfieldsFetcher;
00165               mfieldsFetcher=new ParaMEDMEM2VTK::MEDCouplingMultiFieldsFetcher(BufferingPolicy,multiPtr);
00166               std::vector<double> tsteps=mfieldsFetcher->getTimeStepsForPV();
00167               double timeRange[2];
00168               timeRange[0]=tsteps.front();
00169               timeRange[1]=tsteps.back();
00170               myInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),&tsteps[0],tsteps.size());
00171               myInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),timeRange,2);
00172            }
00173         }
00174       else
00175         {
00176           Engines::IORTab *iorTab=objPara->tior();
00177           this->TotalNumberOfPieces=iorTab->length();
00178           delete iorTab;
00179           CORBA::release(objPara);
00180         }
00181       myInfo->Set(vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES(),this->TotalNumberOfPieces);
00182     }
00183   return 1;
00184 }
00185 
00186 int vtkParaMEDCorbaSource::RequestData(vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outputVector)
00187 {
00188   vtkInformation *outInfo=outputVector->GetInformationObject(0);
00189   //
00190   this->UpdatePiece = this->GetOutputDataObject(0)->GetUpdatePiece();//emulation vtkUnstructuredGrid::GetUpdateExtent(int&,int&,int&)
00191   this->NumberOfPieces = this->GetOutputDataObject(0)->GetUpdateNumberOfPieces();//emulation vtkUnstructuredGrid::GetUpdateExtent(int&,int&,int&)
00192   this->GhostLevel = this->GetOutputDataObject(0)->GetUpdateGhostLevel();//emulation vtkUnstructuredGrid::GetUpdateExtent(int&,int&,int&)
00193   this->StartPiece=((this->UpdatePiece*this->TotalNumberOfPieces)/this->NumberOfPieces);
00194   this->EndPiece=(((this->UpdatePiece+1)*this->TotalNumberOfPieces)/this->NumberOfPieces);
00195   vtkMultiBlockDataSet *ret0=vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
00196   double *reqTS = 0;
00197   if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS()))
00198     reqTS = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS());
00199   //Client request on ORB.
00200   CORBA::ORB_var *OrbC=(CORBA::ORB_var *)this->Orb;
00201   CORBA::Object_var obj=(*OrbC)->string_to_object(&IOR[0]);
00202   //
00203   Engines::MPIObject_var objPara=Engines::MPIObject::_narrow(obj);
00204   if(CORBA::is_nil(objPara))
00205     {//sequential
00206        SALOME_MED::MEDCouplingMeshCorbaInterface_var meshPtr=SALOME_MED::MEDCouplingMeshCorbaInterface::_narrow(obj);
00207        if(!CORBA::is_nil(meshPtr))
00208          {
00209            bool dummy;//bug VTK
00210            vtkDataSet *ret=ParaMEDMEM2VTK::BuildFromMEDCouplingMeshInstance(meshPtr,dummy);//bug VTK
00211            if(!ret)
00212              return 0;
00213            ret0->SetBlock(0,ret);
00214            ret->Delete();
00215            return 1;
00216          }
00217        SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_var fieldPtr=SALOME_MED::MEDCouplingFieldDoubleCorbaInterface::_narrow(obj);
00218        if(!CORBA::is_nil(fieldPtr))
00219          {
00220            std::vector<double> ret2;
00221            vtkDataSet *ret=ParaMEDMEM2VTK::BuildFullyFilledFromMEDCouplingFieldDoubleInstance(fieldPtr,ret2);
00222            if(!ret)
00223              {
00224                vtkErrorMacro("On single field CORBA fetching an error occurs !");
00225                return 0;
00226              }
00227            ret0->SetBlock(0,ret);
00228            ret->Delete();
00229            //
00230            double timeRange[2];
00231            timeRange[0]=ret2[0];
00232            timeRange[1]=ret2[0];
00233            outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),&ret2[0],1);
00234            outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),timeRange,2);
00235            ret0->GetInformation()->Set(vtkDataObject::DATA_TIME_STEPS(), &ret2[0], 1);
00236            return 1;
00237          }
00238        SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_var multiPtr=SALOME_MED::MEDCouplingMultiFieldsCorbaInterface::_narrow(obj);
00239        if(!CORBA::is_nil(multiPtr))
00240          {
00241            vtkDataSet *ret=mfieldsFetcher->buildDataSetOnTime(reqTS[0]);
00242            if(!ret)
00243              {
00244                vtkErrorMacro("On multi fields CORBA fetching an error occurs !");
00245                return 0;
00246              }
00247            ret0->SetBlock(0,ret);
00248            ret->Delete();
00249            ret0->GetInformation()->Set(vtkDataObject::DATA_TIME_STEPS(),reqTS, 1);
00250            return 1;
00251          }
00252        vtkErrorMacro("Unrecognized sequential CORBA reference !");
00253        return 0;
00254     }
00255   else
00256     {
00257       SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_var paraFieldCorba=SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow(obj);
00258       if(!CORBA::is_nil(paraFieldCorba))
00259         {
00260           ParaMEDMEM2VTK::FillMEDCouplingParaFieldDoubleInstanceFrom(paraFieldCorba,this->StartPiece,this->EndPiece,ret0);
00261           return 1;
00262         }
00263       vtkErrorMacro("Unrecognized parallel CORBA reference !");
00264       return 0;
00265     }
00266 }
00267 
00268 void vtkParaMEDCorbaSource::PrintSelf(ostream& os, vtkIndent indent)
00269 {
00270   this->Superclass::PrintSelf( os, indent );
00271   os << "Data: " << this->MyDataSet << "\n";
00272 }
00273