1 // Copyright (C) 2010-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkParaMEDCorbaSource.h"
22 #include "vtkPoints.h"
23 #include "vtkIntArray.h"
24 #include "vtkCellData.h"
25 #include "vtkCellTypes.h"
26 #include "vtkCharArray.h"
27 #include "vtkPointData.h"
28 #include "vtkDoubleArray.h"
29 #include "vtkMultiBlockDataSet.h"
30 #include "vtkUnstructuredGrid.h"
32 #include "vtkStreamingDemandDrivenPipeline.h"
33 #include "vtkGenericAttributeCollection.h"
34 #include "vtkInformationVector.h"
35 #include "vtkObjectFactory.h"
36 #include "vtkInformation.h"
42 #include "VTKMEDCouplingMeshClient.hxx"
43 #include "VTKMEDCouplingFieldClient.hxx"
44 #include "VTKMEDCouplingMultiFieldsClient.hxx"
45 #include "VTKParaMEDFieldClient.hxx"
48 #include "ParaMEDCouplingCorbaServant.hh"
51 vtkStandardNewMacro(vtkParaMEDCorbaSource);
52 //vtkCxxRevisionMacro(vtkParaMEDCorbaSource,"$Revision$");
54 void *vtkParaMEDCorbaSource::Orb=0;
56 vtkParaMEDCorbaSource::vtkParaMEDCorbaSource():mfieldsFetcher(0)
61 CORBA::ORB_var *OrbC=new CORBA::ORB_var;
63 *OrbC=CORBA::ORB_init(argc,0);
66 this->SetNumberOfInputPorts(0);
67 this->SetNumberOfOutputPorts(1);
70 vtkParaMEDCorbaSource::~vtkParaMEDCorbaSource()
72 delete mfieldsFetcher;
75 const char *vtkParaMEDCorbaSource::GetIORCorba()
80 void vtkParaMEDCorbaSource::SetIORCorba(char *ior)
86 int length=strlen(ior);
88 std::copy(ior,ior+length+1,&IOR[0]);
92 void vtkParaMEDCorbaSource::SetBufferingPolicy(int pol)
97 int vtkParaMEDCorbaSource::GetBufferingPolicy()
99 return BufferingPolicy;
102 //int vtkParaMEDCorbaSource::RequestUpdateExtent( vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo )
104 //return this->Superclass::RequestUpdateExtent(request,inInfo,outInfo);
106 /*vtkParaMEDCorbaDataSet* output = vtkParaMEDCorbaDataSet::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT() ) );
109 output = vtkParaMEDCorbaDataSet::New();
110 output->SetPipelineInformation( info );
112 this->GetOutputPortInformation( 0 )->Set( vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType() );
118 int vtkParaMEDCorbaSource::ProcessRequest(vtkInformation* request,
119 vtkInformationVector** inputVector,
120 vtkInformationVector* outputVector)
123 if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
125 return this->RequestData(request, inputVector, outputVector);
127 if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
129 return this->RequestInformation(request, inputVector, outputVector);
131 return this->Superclass::ProcessRequest(request, inputVector, outputVector);
134 int vtkParaMEDCorbaSource::FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info)
136 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
140 int vtkParaMEDCorbaSource::RequestInformation(vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outInfo)
142 vtkInformation* myInfo=outInfo->GetInformationObject(0);
143 //myInfo->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
146 //myInfo->Remove(vtkDataObject::DATA_TYPE_NAME());
147 //myInfo->Remove(PORT_REQUIREMENTS_FILLED());
148 //myInfo->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
149 //myInfo->Set(PORT_REQUIREMENTS_FILLED(),1);
150 //vtkUnstructuredGrid *tony=vtkUnstructuredGrid::New();
151 //tony->SetInformation(myInfo);
152 //myInfo->Set(vtkDataObject::DATA_OBJECT(),tony);
154 CORBA::ORB_var *OrbC=(CORBA::ORB_var *)this->Orb;
155 CORBA::Object_var obj=(*OrbC)->string_to_object(&IOR[0]);
157 Engines::MPIObject_ptr objPara=Engines::MPIObject::_narrow(obj);
158 if(CORBA::is_nil(objPara))
160 this->TotalNumberOfPieces=1;
161 SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_var multiPtr=SALOME_MED::MEDCouplingMultiFieldsCorbaInterface::_narrow(obj);
162 if(!CORBA::is_nil(multiPtr))
163 {//Request for multiFields
164 delete mfieldsFetcher;
165 mfieldsFetcher=new ParaMEDMEM2VTK::MEDCouplingMultiFieldsFetcher(BufferingPolicy,multiPtr);
166 std::vector<double> tsteps=mfieldsFetcher->getTimeStepsForPV();
168 timeRange[0]=tsteps.front();
169 timeRange[1]=tsteps.back();
170 myInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),&tsteps[0],tsteps.size());
171 myInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),timeRange,2);
176 Engines::IORTab *iorTab=objPara->tior();
177 this->TotalNumberOfPieces=iorTab->length();
179 CORBA::release(objPara);
181 myInfo->Set(CAN_HANDLE_PIECE_REQUEST(), 1);
186 int vtkParaMEDCorbaSource::RequestData(vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outputVector)
188 vtkInformation *outInfo=outputVector->GetInformationObject(0);
190 this->UpdatePiece = vtkStreamingDemandDrivenPipeline::GetUpdatePiece(outInfo);
191 this->NumberOfPieces = vtkStreamingDemandDrivenPipeline::GetUpdateNumberOfPieces(outInfo);
192 this->GhostLevel = vtkStreamingDemandDrivenPipeline::GetUpdateGhostLevel(outInfo);
193 this->StartPiece=((this->UpdatePiece*this->TotalNumberOfPieces)/this->NumberOfPieces);
194 this->EndPiece=(((this->UpdatePiece+1)*this->TotalNumberOfPieces)/this->NumberOfPieces);
195 vtkMultiBlockDataSet *ret0=vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
197 if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
198 reqTS = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
199 //Client request on ORB.
200 CORBA::ORB_var *OrbC=(CORBA::ORB_var *)this->Orb;
201 CORBA::Object_var obj=(*OrbC)->string_to_object(&IOR[0]);
203 Engines::MPIObject_var objPara=Engines::MPIObject::_narrow(obj);
204 if(CORBA::is_nil(objPara))
206 SALOME_MED::MEDCouplingMeshCorbaInterface_var meshPtr=SALOME_MED::MEDCouplingMeshCorbaInterface::_narrow(obj);
207 if(!CORBA::is_nil(meshPtr))
210 vtkDataSet *ret=ParaMEDMEM2VTK::BuildFromMEDCouplingMeshInstance(meshPtr,dummy);//bug VTK
213 ret0->SetBlock(0,ret);
217 SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_var fieldPtr=SALOME_MED::MEDCouplingFieldDoubleCorbaInterface::_narrow(obj);
218 if(!CORBA::is_nil(fieldPtr))
220 std::vector<double> ret2;
221 vtkDataSet *ret=ParaMEDMEM2VTK::BuildFullyFilledFromMEDCouplingFieldDoubleInstance(fieldPtr,ret2);
224 vtkErrorMacro("On single field CORBA fetching an error occurs !");
227 ret0->SetBlock(0,ret);
231 timeRange[0]=ret2[0];
232 timeRange[1]=ret2[0];
233 outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),&ret2[0],1);
234 outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),timeRange,2);
235 ret0->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(),ret2[0]);
238 SALOME_MED::MEDCouplingMultiFieldsCorbaInterface_var multiPtr=SALOME_MED::MEDCouplingMultiFieldsCorbaInterface::_narrow(obj);
239 if(!CORBA::is_nil(multiPtr))
241 vtkDataSet *ret=mfieldsFetcher->buildDataSetOnTime(reqTS);
244 vtkErrorMacro("On multi fields CORBA fetching an error occurs !");
247 ret0->SetBlock(0,ret);
249 ret0->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(),reqTS);
252 vtkErrorMacro("Unrecognized sequential CORBA reference !");
257 SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_var paraFieldCorba=SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow(obj);
258 if(!CORBA::is_nil(paraFieldCorba))
260 ParaMEDMEM2VTK::FillMEDCouplingParaFieldDoubleInstanceFrom(paraFieldCorba,this->StartPiece,this->EndPiece,ret0);
263 vtkErrorMacro("Unrecognized parallel CORBA reference !");
268 void vtkParaMEDCorbaSource::PrintSelf(ostream& os, vtkIndent indent)
270 this->Superclass::PrintSelf( os, indent );
271 os << "Data: " << this->MyDataSet << "\n";