From: Ovidiu Mircescu Date: Thu, 11 Aug 2016 14:48:38 +0000 (+0200) Subject: Add a visualization component. X-Git-Tag: SHAPER_2.7.0~15^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=945d69d1773111a3283cd9ce0c1fc68b9b984480;p=modules%2Fparavis.git Add a visualization component. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 48719435..c4667a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -274,6 +274,7 @@ IF(SALOME_BUILD_TESTS AND NOT SALOME_LIGHT_ONLY) ENDIF() ADD_SUBDIRECTORY(bin) ADD_SUBDIRECTORY(examples) +ADD_SUBDIRECTORY(idl) # Header configuration # ==================== diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt new file mode 100644 index 00000000..4f6a89e5 --- /dev/null +++ b/idl/CMakeLists.txt @@ -0,0 +1,28 @@ + +INCLUDE(UseOmniORB) # Provided by KERNEL + +INCLUDE_DIRECTORIES( + ${OMNIORB_INCLUDE_DIR} + ${KERNEL_INCLUDE_DIRS} + ${PROJECT_BINARY_DIR}/idl +) + +SET(SalomeIDLPARAVIS_IDLSOURCES + PARAVIS.idl + +) + +SET(_idl_include_dirs + ${KERNEL_ROOT_DIR}/idl/salome + ${MED_ROOT_DIR}/idl/salome + +) + +SET(_idl_link_flags + ${KERNEL_SalomeIDLKernel} + ${MED_SalomeIDLMED} + +) + +OMNIORB_ADD_MODULE(SalomeIDLPARAVIS "${SalomeIDLPARAVIS_IDLSOURCES}" "${_idl_include_dirs}" "${_idl_link_flags}") +INSTALL(TARGETS SalomeIDLPARAVIS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) diff --git a/idl/PARAVIS.idl b/idl/PARAVIS.idl new file mode 100644 index 00000000..cc89534e --- /dev/null +++ b/idl/PARAVIS.idl @@ -0,0 +1,28 @@ + +#ifndef _PARAVIS_IDL_ +#define _PARAVIS_IDL_ + +#include "SALOME_Exception.idl" +#include "SALOME_Component.idl" +#include "SALOME_Comm.idl" + + +#include "MEDCouplingCorbaServant.idl" +#include "SALOME_MPIObject.idl" +#include "ParaMEDCouplingCorbaServant.idl" + +module PARAVIS_ORB +{ +typedef sequence stringvec; +typedef sequence dblevec; +typedef sequence intvec; +typedef Engines::dataref dataref; + + interface VisualizationComponent: Engines::MPIObject, Engines::EngineComponent + { + void Visualize(in SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface field,in string path_python_file) raises (SALOME::SALOME_Exception); + }; + +}; + +#endif diff --git a/resources/PARAVISCatalog.xml.in b/resources/PARAVISCatalog.xml.in index df256d70..c10b27ef 100644 --- a/resources/PARAVISCatalog.xml.in +++ b/resources/PARAVISCatalog.xml.in @@ -59,5 +59,56 @@ + + + + VisualizationComponent + VisualizationComponent + Data + EDF-RD + @SALOMEPARAVIS_VERSION@ + + 0 + SO + + + + VisualizationComponent + + + + + + Visualize + EDF-RD + 1.0 + + 0 + + + + field + +SALOME_MED/ParaMEDCouplingFieldDoubleCorbaInterface + + + + + path_python_file + + string + + + + + + + + + + + + + diff --git a/src/Insitu/CMakeLists.txt b/src/Insitu/CMakeLists.txt index 62d1db06..1bc1057f 100644 --- a/src/Insitu/CMakeLists.txt +++ b/src/Insitu/CMakeLists.txt @@ -1,42 +1,3 @@ - -SET(BUILD_SHARED_LIBS TRUE) -INCLUDE_DIRECTORIES( - ${MEDCOUPLING_INCLUDE_DIRS} - ${MPI_INCLUDE_PATH} - ${PARAVIS_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/../Plugins/MEDReader/IO/ -) - - -SET(_link_LIBRARIES - ${MEDCoupling_medcoupling} - ${MEDCoupling_interpkernel} - ${MPI_LIBRARIES} - ${VTK_LIBRARIES} - ${PARAVIS_MEDLoaderForPV} - #${MEDLoaderForPV} - ${MEDCoupling_medloader} - ${MEDFILE_C_LIBRARIES} - vtkPVCatalyst - vtkPVPythonCatalyst -) - -SET(_lib_HEADERS - visu.hxx -) - -SET(_lib_SOURCES - visu.cxx -) - -ADD_LIBRARY(visulib ${_lib_SOURCES}) -TARGET_LINK_LIBRARIES(visulib ${_link_LIBRARIES} ) - -INSTALL(TARGETS visulib - RUNTIME DESTINATION lib/salome - LIBRARY DESTINATION lib/salome - ARCHIVE DESTINATION lib/salome - ) -INSTALL(FILES ${_lib_HEADERS} DESTINATION include/salome ) - +ADD_SUBDIRECTORY(VisualizationComponent) +ADD_SUBDIRECTORY(VisualizationLibrary) diff --git a/src/Insitu/VisualizationComponent/CMakeLists.txt b/src/Insitu/VisualizationComponent/CMakeLists.txt new file mode 100644 index 00000000..d3344fa0 --- /dev/null +++ b/src/Insitu/VisualizationComponent/CMakeLists.txt @@ -0,0 +1,67 @@ + +# --- options --- +# additional include directories +INCLUDE_DIRECTORIES( + ${KERNEL_INCLUDE_DIRS} + ${OMNIORB_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} + ${PROJECT_BINARY_DIR}/idl + ${CMAKE_CURRENT_SOURCE_DIR}/../VisualizationLibrary +) + +# --- definitions --- +ADD_DEFINITIONS( + ${OMNIORB_DEFINITIONS} +) + +# find additional libraries +FIND_LIBRARY( _userlib_visulib visulib PATH /home/I35256/salome/install/V7_main_git/modules/install/PARAVIS_master/lib/salome) +#FIND_LIBRARY( _userlib_MEDLoaderForPV MEDLoaderForPV PATH /home/I35256/salome/install/V7_main_git/modules/install/PARAVIS_master/lib/salome) + + +# libraries to link to +SET(_link_LIBRARIES + ${OMNIORB_LIBRARIES} + ${KERNEL_SalomeIDLKernel} + ${KERNEL_OpUtil} + ${KERNEL_SalomeContainer} + SalomeIDLPARAVIS + ${KERNEL_SalomeMPIContainer} + #${_userlib_visulib} + #${_userlib_MEDLoaderForPV} + ${PARAVIS_MEDLoaderForPV} + ${PARAVIS_visulib} + ${MED_SalomeIDLMED} + ${MED_med} + ${MED_medcouplingcorba} + ${MED_medcouplingclient} + + ${MED_paramedmemcompo} + ${MED_paramedcouplingcorba} +) + +# --- headers --- + +# header files / no moc processing + +SET(PARAVIS_HEADERS + VisualizationComponent.hxx +) + +# --- sources --- + +# sources / static +SET(PARAVIS_SOURCES + VisualizationComponent.cxx + +) + +# --- rules --- + +ADD_LIBRARY(VisualizationComponentEngine ${PARAVIS_SOURCES}) +TARGET_LINK_LIBRARIES(VisualizationComponentEngine ${_link_LIBRARIES} ) +#SET_TARGET_PROPERTIES( VisualizationComponentEngine PROPERTIES INSTALL_RPATH /home/I35256/salome/install/V7_main_git/modules/install/PARAVIS_master/lib/salome) + +INSTALL(TARGETS VisualizationComponentEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + +INSTALL(FILES ${PARAVIS_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/Insitu/VisualizationComponent/VisualizationComponent.cxx b/src/Insitu/VisualizationComponent/VisualizationComponent.cxx new file mode 100644 index 00000000..0a9446ba --- /dev/null +++ b/src/Insitu/VisualizationComponent/VisualizationComponent.cxx @@ -0,0 +1,261 @@ + +#include "VisualizationComponent.hxx" +#include +#include +#include +#include +#include +#include "Utils_CorbaException.hxx" +#include +#include + +typedef struct +{ + bool exception; + std::string msg; +} exception_st; + +//DEFS + +#include "visu.hxx" +#include "MEDCouplingFieldDoubleClient.hxx" +#include "ParaMEDCouplingFieldDoubleServant.hxx" +#include "omniORB4/poa.h" + +//ENDDEF + + +using namespace std; + +//! Constructor for component "VisualizationComponent" instance +/*! + * + */ +VisualizationComponent_i::VisualizationComponent_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName, + bool regist) + : Engines_Component_i(orb, poa, contId, instanceName, interfaceName, + false, regist) +{ + _thisObj = this ; + _id = _poa->activate_object(_thisObj); +} + +VisualizationComponent_i::VisualizationComponent_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + Engines::Container_ptr container, + const char *instanceName, + const char *interfaceName, + bool regist) + : Engines_Component_i(orb, poa, container, instanceName, interfaceName, + false, regist) +{ + _thisObj = this ; + _id = _poa->activate_object(_thisObj); +} + +//! Destructor for component "VisualizationComponent" instance +VisualizationComponent_i::~VisualizationComponent_i() +{ +} + + +void * th_Visualize(void * s) +{ + std::ostringstream msg; + exception_st *est = new exception_st; + est->exception = false; + + thread_Visualize_struct *st = (thread_Visualize_struct *)s; + + try + { + + PARAVIS_ORB::VisualizationComponent_var compo = PARAVIS_ORB::VisualizationComponent::_narrow((*(st->tior))[st->ip]); + compo->Visualize(st->field,st->path_python_file); + } + catch(const SALOME::SALOME_Exception &ex) + { + est->exception = true; + est->msg = ex.details.text; + } + catch(const CORBA::Exception &ex) + { + est->exception = true; + msg << "CORBA::Exception: " << ex; + est->msg = msg.str(); + } + + delete st; + return ((void*)est); +} + +void VisualizationComponent_i::Visualize(SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr field,const char* path_python_file) +{ + beginService("VisualizationComponent_i::Visualize"); + void *ret_th; + pthread_t *th; + exception_st *est; + + try + { + // Run the service in every MPI process + if(_numproc == 0) + { + th = new pthread_t[_nbproc]; + for(int ip=1;ip<_nbproc;ip++) + { + thread_Visualize_struct *st = new thread_Visualize_struct; + st->ip = ip; + st->tior = _tior; + st->field = field; +st->path_python_file = path_python_file; + pthread_create(&(th[ip]),NULL,th_Visualize,(void*)st); + } + } + +//BODY + +const MEDCoupling::MEDCouplingFieldDouble * local_field(NULL); +int nb_fields = field->tior()->length(); +if(nb_fields == _nbproc) +{ + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr local_corba_field = + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow((*(field->tior()))[_numproc]); + + + PortableServer::ServantBase *ret; + try { + ret=PortableServer::POA::_the_root_poa()->reference_to_servant(local_corba_field); + std::cerr << "Servant succeeded!" << std::endl; + MEDCoupling::ParaMEDCouplingFieldDoubleServant* servant_field = + dynamic_cast(ret); + if(servant_field != NULL) + { + std::cerr << "In-situ configuration!" << std::endl; + // same container, same mpi proc, use the pointer directly. + local_field = servant_field->getPointer(); + ret->_remove_ref(); + } + } + catch(...){ + // different container - need to make a copy of the field. + ret = NULL; + std::cerr << "Co-processing configuration!" << std::endl; + local_field = MEDCoupling::MEDCouplingFieldDoubleClient::New(local_corba_field); + } +} +else if(nb_fields < _nbproc) +{ + if(_numproc < nb_fields) + { + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr local_corba_field = + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow((*(field->tior()))[_numproc]); + local_field = MEDCoupling::MEDCouplingFieldDoubleClient::New(local_corba_field); + } +} +else //nb_fields > _nbproc +{ + int q = nb_fields / _nbproc; // int division + int r = nb_fields - q * _nbproc; + int start, end; + + if(_numproc < r) + { + // get one more field to process + start = _numproc * (q + 1); + end = start + q + 1; + } + else + { + start = r * (q + 1) + (_numproc - r) * q; + end = start + q; + } + + std::cerr << "Proc n° " << _numproc << ". Merge fields from " << start << " to " << end << std::endl; + + std::vector fieldsToProcess; + for(int i = start; i < end; i++) + { + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr local_corba_field = + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow((*(field->tior()))[i]); + fieldsToProcess.push_back(MEDCoupling::MEDCouplingFieldDoubleClient::New(local_corba_field)); + } + + local_field = MEDCoupling::MEDCouplingFieldDouble::MergeFields(fieldsToProcess); +} + +Visualization v; +v.run(const_cast(local_field), path_python_file); + +//ENDBODY + if(_numproc == 0) + { + for(int ip=1;ip<_nbproc;ip++) + { + pthread_join(th[ip],&ret_th); + est = (exception_st*)ret_th; + if(est->exception) + { + std::ostringstream msg; + msg << "[" << ip << "] " << est->msg; + delete est; + delete[] th; + THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(),SALOME::INTERNAL_ERROR); + } + delete est; + } + delete[] th; + } + } + catch ( const SALOME_Exception & ex) + { + THROW_SALOME_CORBA_EXCEPTION(CORBA::string_dup(ex.what()), SALOME::INTERNAL_ERROR); + } + catch ( const SALOME::SALOME_Exception & ex) + { + throw; + } + catch ( const std::exception& ex) + { + THROW_SALOME_CORBA_EXCEPTION(CORBA::string_dup(ex.what()), SALOME::INTERNAL_ERROR); + } + catch (...) + { + THROW_SALOME_CORBA_EXCEPTION("unknown exception", SALOME::INTERNAL_ERROR); + } + endService("VisualizationComponent_i::Visualize"); +} + + + +extern "C" +{ + PortableServer::ObjectId * VisualizationComponentEngine_factory( CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName) + { + MESSAGE("PortableServer::ObjectId * VisualizationComponentEngine_factory()"); + int is_mpi_container; + bool regist; + int numproc; + + MPI_Initialized(&is_mpi_container); + if (!is_mpi_container) + { + int argc = 0; + char ** argv = NULL; + MPI_Init(&argc, &argv); + } + + MPI_Comm_rank( MPI_COMM_WORLD, &numproc ); + regist = ( numproc == 0 ); + VisualizationComponent_i * myEngine = new VisualizationComponent_i(orb, poa, contId, instanceName, interfaceName, regist); + return myEngine->getId() ; + } +} diff --git a/src/Insitu/VisualizationComponent/VisualizationComponent.hxx b/src/Insitu/VisualizationComponent/VisualizationComponent.hxx new file mode 100644 index 00000000..d3b65d87 --- /dev/null +++ b/src/Insitu/VisualizationComponent/VisualizationComponent.hxx @@ -0,0 +1,51 @@ + +#ifndef _VisualizationComponent_HXX_ +#define _VisualizationComponent_HXX_ + +#include +#include "Superv_Component_i.hxx" +#include "PARAVIS.hh" +#include "MPIObject_i.hxx" + +//COMPODEFS + + +void * th_Visualize(void * s); +typedef struct { + int ip; // mpi process id + Engines::IORTab* tior; + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr field; +const char* path_python_file; +} thread_Visualize_struct; + + +//ENDDEF + +class VisualizationComponent_i: public virtual POA_PARAVIS_ORB::VisualizationComponent, + + public virtual MPIObject_i, + public virtual Engines_Component_i +{ + public: + VisualizationComponent_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, const char *interfaceName, + bool regist = true); + VisualizationComponent_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, + Engines::Container_ptr container, + const char *instanceName, const char *interfaceName, + bool regist = true); + virtual ~VisualizationComponent_i(); + void Visualize(SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr field,const char* path_python_file); +}; + +extern "C" +{ + PortableServer::ObjectId * VisualizationComponentEngine_factory( CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName); +} +#endif + diff --git a/src/Insitu/VisualizationLibrary/CMakeLists.txt b/src/Insitu/VisualizationLibrary/CMakeLists.txt new file mode 100644 index 00000000..5ff03098 --- /dev/null +++ b/src/Insitu/VisualizationLibrary/CMakeLists.txt @@ -0,0 +1,42 @@ + +SET(BUILD_SHARED_LIBS TRUE) +INCLUDE_DIRECTORIES( + ${MEDCOUPLING_INCLUDE_DIRS} + ${MPI_INCLUDE_PATH} + ${PARAVIS_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/../../Plugins/MEDReader/IO/ +) + + +SET(_link_LIBRARIES + ${MEDCoupling_medcoupling} + ${MEDCoupling_interpkernel} + ${MPI_LIBRARIES} + ${VTK_LIBRARIES} + ${PARAVIS_MEDLoaderForPV} + #${MEDLoaderForPV} + ${MEDCoupling_medloader} + ${MEDFILE_C_LIBRARIES} + vtkPVCatalyst + vtkPVPythonCatalyst +) + +SET(_lib_HEADERS + visu.hxx +) + +SET(_lib_SOURCES + visu.cxx +) + +ADD_LIBRARY(visulib ${_lib_SOURCES}) +TARGET_LINK_LIBRARIES(visulib ${_link_LIBRARIES} ) + +INSTALL(TARGETS visulib + RUNTIME DESTINATION lib/salome + LIBRARY DESTINATION lib/salome + ARCHIVE DESTINATION lib/salome + ) +INSTALL(FILES ${_lib_HEADERS} DESTINATION include/salome ) + + diff --git a/src/Insitu/VisualizationLibrary/visu.cxx b/src/Insitu/VisualizationLibrary/visu.cxx new file mode 100755 index 00000000..282ac207 --- /dev/null +++ b/src/Insitu/VisualizationLibrary/visu.cxx @@ -0,0 +1,158 @@ +#include "visu.hxx" +#include "MEDFileField.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingCMesh.hxx" +#include "MEDCouplingCurveLinearMesh.hxx" +#include "MEDFileMesh.hxx" +#include "MEDFileFieldRepresentationTree.hxx" +#include +#include "mpi.h" + +#include +#include +#include +#include +#include "vtkDataSet.h" +#include "vtkCellData.h" + +#include +#include +#include + +using namespace MEDCoupling; + + +void Visualization::CatalystInitialize(const std::string& script) +{ + + if(Processor == NULL) + { + Processor = vtkCPProcessor::New(); + Processor->Initialize(); + } + else + { + Processor->RemoveAllPipelines(); + } + // Add in the Python script + vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New(); + char *c = const_cast(script.c_str()); + pipeline->Initialize(c); + Processor->AddPipeline(pipeline); + pipeline->Delete(); + return; +} + +void Visualization::CatalystFinalize() +{ + if(Processor) + { + Processor->Delete(); + Processor = NULL; + } + + return; +} + +void Visualization::CatalystCoProcess(vtkDataSet *VTKGrid, double time, + unsigned int timeStep) +{ + vtkCPDataDescription* dataDescription = vtkCPDataDescription::New(); + // specify the simulation time and time step for Catalyst + dataDescription->AddInput("input"); + dataDescription->SetTimeData(time, timeStep); + + if(Processor->RequestDataDescription(dataDescription) != 0) + { + // Make a map from input to our VTK grid so that + // Catalyst gets the proper input dataset for the pipeline. + dataDescription->GetInputDescriptionByName("input")->SetGrid(VTKGrid); + // Call Catalyst to execute the desired pipelines. + Processor->CoProcess(dataDescription); + } + dataDescription->Delete(); +} + +void Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field, vtkDataSet *&VTKGrid) +//vtkDataSet * Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field) +{ + MEDCoupling::MEDCouplingFieldDouble *f = field; + MEDCoupling::MCAuto ff(MEDFileField1TS::New()); + ff->setFieldNoProfileSBT(f); + MCAuto fmts(MEDFileFieldMultiTS::New()); + fmts->pushBackTimeStep(ff); + MCAuto fs(MEDFileFields::New()); + fs->pushField(fmts); + + MEDCouplingMesh *m(f->getMesh()); + MCAuto mm; + if(dynamic_cast(m)) + { + MCAuto mmu(MEDFileUMesh::New()); + mmu->setMeshAtLevel(0,dynamic_cast(m)); + mmu->forceComputationOfParts(); + mm=DynamicCast(mmu); + } + else if(dynamic_cast(m)) + { + MCAuto mmc(MEDFileCMesh::New()); + mmc->setMesh(dynamic_cast(m)); + mm=DynamicCast(mmc); + } + else if(dynamic_cast(m)) + { + // MCAuto mmc(MEDFileCLMesh::New()); + MCAuto mmc(MEDFileCurveLinearMesh::New()); + mmc->setMesh(dynamic_cast(m)); + //mm=DynamicCast(mmc); + mm=0; + } + else + { + throw ; + } + MCAuto ms(MEDFileMeshes::New()); + ms->pushMesh(mm); + ms->getMeshesNames(); + // + int proc_id; + MPI_Comm_rank(MPI_COMM_WORLD,&proc_id); + // + MEDFileFieldRepresentationTree Tree; + Tree.loadInMemory(fs,ms); + + Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(0,true); + Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(1,false); + Tree.activateTheFirst();//"TS0/Fluid domain/ComSup0/TempC@@][@@P0" + std::string meshName; + TimeKeeper TK(0); + int tmp1,tmp2; + double tmp3(f->getTime(tmp1,tmp2)); + vtkDataSet *ret(Tree.buildVTKInstance(false,tmp3,meshName,TK)); + VTKGrid = ret; +} + +Visualization::Visualization() +{ +Processor = NULL; +} + + +// ajouter en parametre le fichier python qui contient le pipeline +// enlever le const s'il gene +void Visualization::run(MEDCoupling::MEDCouplingFieldDouble* field, const std::string& pathPipeline) +{ + int proc_id; + MPI_Comm_rank(MPI_COMM_WORLD,&proc_id); + + vtkDataSet *VTKGrid = 0; + ConvertToVTK(field, VTKGrid); + + const char *fileName = pathPipeline.c_str(); + CatalystInitialize(fileName); + CatalystCoProcess(VTKGrid, 0.0, 0); + CatalystFinalize(); + + return ; +} + diff --git a/src/Insitu/VisualizationLibrary/visu.hxx b/src/Insitu/VisualizationLibrary/visu.hxx new file mode 100755 index 00000000..30d408eb --- /dev/null +++ b/src/Insitu/VisualizationLibrary/visu.hxx @@ -0,0 +1,30 @@ +#ifndef _VISU_HXX_ +#define _VISU_HXX_ + +#include +#include "MEDCouplingFieldDouble.hxx" + +namespace MEDCoupling +{ + class MEDCouplingFieldDouble; +} + +class vtkCPProcessor; +class vtkDataSet; + +class Visualization +{ + vtkCPProcessor* Processor; + + //private : + public : + void CatalystInitialize(const std::string& pipeline); + void CatalystFinalize(); + void CatalystCoProcess(vtkDataSet *VTKGrid, double time, unsigned int timeStep); + void ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field, vtkDataSet *&VTKGrid); + public : + Visualization(); + void run(MEDCoupling::MEDCouplingFieldDouble*, const std::string& pathPipeline); +}; + +#endif //_VISU_HXX_ diff --git a/src/Insitu/visu.cxx b/src/Insitu/visu.cxx deleted file mode 100755 index 9c85828f..00000000 --- a/src/Insitu/visu.cxx +++ /dev/null @@ -1,166 +0,0 @@ -#include "visu.hxx" -#include "MEDFileField.hxx" -#include "MEDCouplingUMesh.hxx" -#include "MEDCouplingCMesh.hxx" -#include "MEDCouplingCurveLinearMesh.hxx" -#include "MEDFileMesh.hxx" -#include "MEDFileFieldRepresentationTree.hxx" -#include -#include "mpi.h" - -#include -#include -#include -#include -#include "vtkDataSet.h" -#include "vtkCellData.h" - -#include -#include -#include - -using namespace MEDCoupling; - - -void Visualization::CatalystInitialize(const std::string& script) -{ - - if(Processor == NULL) - { - Processor = vtkCPProcessor::New(); - Processor->Initialize(); - } - else - { - Processor->RemoveAllPipelines(); - } - // Add in the Python script - vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New(); - char *c = const_cast(script.c_str()); - pipeline->Initialize(c); - Processor->AddPipeline(pipeline); - pipeline->Delete(); - return; -} - -void Visualization::CatalystFinalize() -{ - if(Processor) - { - Processor->Delete(); - Processor = NULL; - } - - return; -} - -void Visualization::CatalystCoProcess(vtkDataSet *VTKGrid, double time, - unsigned int timeStep) -{ - vtkCPDataDescription* dataDescription = vtkCPDataDescription::New(); - // specify the simulation time and time step for Catalyst - dataDescription->AddInput("input"); - dataDescription->SetTimeData(time, timeStep); - - if(Processor->RequestDataDescription(dataDescription) != 0) - { - // Make a map from input to our VTK grid so that - // Catalyst gets the proper input dataset for the pipeline. - dataDescription->GetInputDescriptionByName("input")->SetGrid(VTKGrid); - // Call Catalyst to execute the desired pipelines. - Processor->CoProcess(dataDescription); - } - dataDescription->Delete(); -} - -void Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field, vtkDataSet *&VTKGrid) -//vtkDataSet * Visualization::ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field) -{ - MEDCoupling::MEDCouplingFieldDouble *f = field; - MEDCoupling::MCAuto ff(MEDFileField1TS::New()); - ff->setFieldNoProfileSBT(f); - MCAuto fmts(MEDFileFieldMultiTS::New()); - fmts->pushBackTimeStep(ff); - MCAuto fs(MEDFileFields::New()); - fs->pushField(fmts); - - MEDCouplingMesh *m(f->getMesh()); - MCAuto mm; - if(dynamic_cast(m)) - { - MCAuto mmu(MEDFileUMesh::New()); - mmu->setMeshAtLevel(0,dynamic_cast(m)); - mmu->forceComputationOfParts(); - mm=DynamicCast(mmu); - } - else if(dynamic_cast(m)) - { - MCAuto mmc(MEDFileCMesh::New()); - mmc->setMesh(dynamic_cast(m)); - mm=DynamicCast(mmc); - } - else if(dynamic_cast(m)) - { - // MCAuto mmc(MEDFileCLMesh::New()); - MCAuto mmc(MEDFileCurveLinearMesh::New()); - mmc->setMesh(dynamic_cast(m)); - //mm=DynamicCast(mmc); - mm=0; - } - else - { - throw ; - } - MCAuto ms(MEDFileMeshes::New()); - ms->pushMesh(mm); - ms->getMeshesNames(); - // - int proc_id; - MPI_Comm_rank(MPI_COMM_WORLD,&proc_id); - // - MEDFileFieldRepresentationTree Tree; - Tree.loadInMemory(fs,ms); - - Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(0,true); - Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(1,false); - Tree.activateTheFirst();//"TS0/Fluid domain/ComSup0/TempC@@][@@P0" - std::string meshName; - TimeKeeper TK(0); - int tmp1,tmp2; - double tmp3(f->getTime(tmp1,tmp2)); - vtkDataSet *ret(Tree.buildVTKInstance(false,tmp3,meshName,TK)); - VTKGrid = ret; -} - -Visualization::Visualization() -{ -Processor = NULL; -} - - -// ajouter en parametre le fichier python qui contient le pipeline -// enlever le const s'il gene -void Visualization::run(MEDCoupling::MEDCouplingFieldDouble* field, const std::string& pathPipeline) -{ - int proc_id; - MPI_Comm_rank(MPI_COMM_WORLD,&proc_id); - - if( field == NULL) - { - std::cerr << "Description n° " << proc_id << ": NULL pointer" << std::endl; - } - std::cerr << "Description n° " << proc_id << ":" - << field->getDescription() << std::endl; - - - vtkDataSet *VTKGrid = 0; - ConvertToVTK(field, VTKGrid); - - const char *fileName = pathPipeline.c_str(); - CatalystInitialize(fileName); - CatalystCoProcess(VTKGrid, 0.0, 0); - CatalystFinalize(); - - return ; -} - diff --git a/src/Insitu/visu.hxx b/src/Insitu/visu.hxx deleted file mode 100755 index 30d408eb..00000000 --- a/src/Insitu/visu.hxx +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _VISU_HXX_ -#define _VISU_HXX_ - -#include -#include "MEDCouplingFieldDouble.hxx" - -namespace MEDCoupling -{ - class MEDCouplingFieldDouble; -} - -class vtkCPProcessor; -class vtkDataSet; - -class Visualization -{ - vtkCPProcessor* Processor; - - //private : - public : - void CatalystInitialize(const std::string& pipeline); - void CatalystFinalize(); - void CatalystCoProcess(vtkDataSet *VTKGrid, double time, unsigned int timeStep); - void ConvertToVTK(MEDCoupling::MEDCouplingFieldDouble* field, vtkDataSet *&VTKGrid); - public : - Visualization(); - void run(MEDCoupling::MEDCouplingFieldDouble*, const std::string& pathPipeline); -}; - -#endif //_VISU_HXX_