From b8e5cc37a1b9a942f230da44208e4e563bc10108 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 29 Sep 2011 08:33:02 +0000 Subject: [PATCH] VTK files writing for quick check on debug. --- src/MEDCoupling/MEDCouplingCMesh.cxx | 9 +++ src/MEDCoupling/MEDCouplingCMesh.hxx | 2 + src/MEDCoupling/MEDCouplingExtrudedMesh.cxx | 12 ++++ src/MEDCoupling/MEDCouplingExtrudedMesh.hxx | 2 + src/MEDCoupling/MEDCouplingFieldDouble.cxx | 36 ++++++++++ src/MEDCoupling/MEDCouplingFieldDouble.hxx | 1 + src/MEDCoupling/MEDCouplingMemArray.cxx | 78 ++++++++++++++++++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 6 ++ src/MEDCoupling/MEDCouplingMesh.cxx | 20 ++++++ src/MEDCoupling/MEDCouplingMesh.hxx | 6 ++ src/MEDCoupling/MEDCouplingUMesh.cxx | 42 ++++++++++- src/MEDCoupling/MEDCouplingUMesh.hxx | 3 + src/MEDCoupling/MEDCouplingUMeshDesc.cxx | 11 +++ src/MEDCoupling/MEDCouplingUMeshDesc.hxx | 2 + src/MEDCoupling_Swig/MEDCoupling.i | 8 +++ 15 files changed, 235 insertions(+), 3 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 78325929e..4cd6ea90f 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -971,3 +971,12 @@ void MEDCouplingCMesh::unserialization(const std::vector& tinyInfoD, con setTime(tinyInfoD[0],tinyInfo[3],tinyInfo[4]); } +void MEDCouplingCMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingCMesh::writeVTKLL : not implemented yet !"); +} + +std::string MEDCouplingCMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) +{ + return std::string("RectilinearGrid"); +} diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index 64cdd2a15..33d316249 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -102,6 +102,8 @@ namespace ParaMEDMEM MEDCouplingCMesh(); MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCpy); ~MEDCouplingCMesh(); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception); + std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); private: DataArrayDouble *_x_array; DataArrayDouble *_y_array; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 21bd5f594..8e187d956 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "CellModel.hxx" #include "InterpolationUtils.hxx" @@ -838,3 +839,14 @@ void MEDCouplingExtrudedMesh::unserialization(const std::vector& tinyInf _mesh3D_ids->alloc(szIds,1); std::copy(a1Ptr,a1Ptr+szIds,_mesh3D_ids->getPointer()); } + +void MEDCouplingExtrudedMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr m=buildUnstructured(); + m->writeVTKLL(ofs,cellData,pointData); +} + +std::string MEDCouplingExtrudedMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) +{ + return _mesh2D->getVTKDataSetType(); +} diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 549536931..8bf350930 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -110,6 +110,8 @@ namespace ParaMEDMEM const int *conn2D, const int *conn2DIndx) throw(INTERP_KERNEL::Exception); void computeBaryCenterOfFace(const std::vector& nodalConnec, int lev1DId); ~MEDCouplingExtrudedMesh(); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception); + std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); private: MEDCouplingUMesh *_mesh2D; MEDCouplingUMesh *_mesh1D; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 5f59890de..79042319b 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1578,3 +1578,39 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCoupli _time_discr->divideEqual(other._time_discr); return *this; } + +/*! + * This method writes the field series 'fs' in the VTK file 'fileName'. + * If 'fs' is empty no file is written. If fields lies on more than one mesh an exception will be thrown and no file will be written too. + * If the single mesh is empty an exception will be thrown. + * Finally there is a field in 'fs' with no name an exception will be thrown too. + */ +void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector& fs) throw(INTERP_KERNEL::Exception) +{ + if(fs.empty()) + return; + std::size_t nfs=fs.size(); + const MEDCouplingMesh *m=fs[0]->getMesh(); + for(std::size_t i=1;igetMesh()!=m) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are not lying on a same mesh ! Expected by VTK ! MEDCouplingFieldDouble::setMesh or MEDCouplingFieldDouble::changeUnderlyingMesh can help to that."); + if(!m) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !"); + std::ostringstream coss,noss; + for(std::size_t i=0;igetName()); + if(name.empty()) + { + std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + TypeOfField typ=cur->getTypeOfField(); + if(typ==ON_CELLS) + cur->getArray()->writeVTK(coss,8,cur->getName()); + else if(typ==ON_NODES) + cur->getArray()->writeVTK(noss,8,cur->getName()); + } + m->writeVTKAdvanced(fileName,coss.str(),noss.str()); +} diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index db1b332a0..909f32335 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -175,6 +175,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return DivideFields(this,&other); } const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + static void WriteVTK(const char *fileName, const std::vector& fs) throw(INTERP_KERNEL::Exception); public: const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; } MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; } diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 9c62cd09c..c52068946 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -416,6 +416,16 @@ std::string DataArrayDouble::reprZip() const return ret.str(); } +void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception) +{ + std::string idt(indent,' '); + ofs.precision(15); + ofs << idt << "\n" << idt; + std::copy(begin(),end(),std::ostream_iterator(ofs," ")); + ofs << std::endl << idt << "\n"; +} + void DataArrayDouble::reprStream(std::ostream& stream) const { stream << "Name of double array : \"" << _name << "\"\n"; @@ -977,7 +987,7 @@ void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception) double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before or call 'getMaxValueInArray' method !"); int nbOfTuples=getNumberOfTuples(); if(nbOfTuples<=0) throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !"); @@ -987,6 +997,16 @@ double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exc return *loc; } +/*! + * Idem to DataArrayDouble::getMaxValue expect that here number of components can be >=1. + */ +double DataArrayDouble::getMaxValueInArray() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const double *loc=std::max_element(begin(),end()); + return *loc; +} + double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception) { int tmp; @@ -999,7 +1019,7 @@ double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !"); int nbOfTuples=getNumberOfTuples(); if(nbOfTuples<=0) throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !"); @@ -1009,6 +1029,16 @@ double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exc return *loc; } +/*! + * Idem to DataArrayDouble::getMinValue expect that here number of components can be >=1. + */ +double DataArrayDouble::getMinValueInArray() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const double *loc=std::min_element(begin(),end()); + return *loc; +} + double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception) { int tmp; @@ -2211,6 +2241,15 @@ std::string DataArrayInt::reprZip() const return ret.str(); } +void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception) +{ + std::string idt(indent,' '); + ofs << idt << "\n" << idt; + std::copy(begin(),end(),std::ostream_iterator(ofs," ")); + ofs << std::endl << idt << "\n"; +} + void DataArrayInt::reprStream(std::ostream& stream) const { stream << "Name of int array : \"" << _name << "\"\n"; @@ -2235,6 +2274,13 @@ void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const _mem.reprZip(getNumberOfComponents(),stream); } +/*! + * This method expects a number of components equal to 1. + * This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v is replaced by + * indArr[v] where 'indArr' is defined by ['indArrBg','indArrEnd'). + * This method is safe that is to say if there is a value in 'this' not in [0,std::distance('indArrBg','indArrEnd')) an exception + * will be thrown. + */ void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) @@ -2321,6 +2367,14 @@ void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd, castsPresent=ret3; } +/*! + * This method expects a number of components equal to 1. + * This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v on place i, place indArr[v] will have + * value i. + * indArr[v] where 'indArr' is defined by ['indArrBg','indArrEnd'). + * This method is half/safe that is to say if there is location i so that indArr[v] is not in [0,this->getNumberOfTuples()) an exception + * will be thrown. + */ DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) @@ -3231,6 +3285,16 @@ int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception return *loc; } +/*! + * Idem to DataArrayInt::getMaxValue expect that here number of components can be >=1. + */ +int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const int *loc=std::max_element(begin(),end()); + return *loc; +} + int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) @@ -3244,6 +3308,16 @@ int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception return *loc; } +/*! + * Idem to DataArrayInt::getMinValue expect that here number of components can be >=1. + */ +int DataArrayInt::getMinValueInArray() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const int *loc=std::min_element(begin(),end()); + return *loc; +} + void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception) { checkAllocated(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 8603cfda0..cac2828c7 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -148,6 +148,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isMonotonic(double eps) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; @@ -193,7 +194,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT void checkNoNullValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT double getMaxValueInArray() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT double getMinValueInArray() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getAverageValue() const throw(INTERP_KERNEL::Exception); @@ -306,6 +309,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void iota(int init=0) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; @@ -362,7 +366,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int getMaxValueInArray() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int getMinValueInArray() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyLin(int a, int b) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void applyInv(int numerator) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index 4cf46d526..f1e56e168 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include using namespace ParaMEDMEM; @@ -326,3 +327,22 @@ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints eltsIndex[i+1]=eltsIndex[i]; } } + +/*! + * This method writes a file in VTK format into file 'fileName'. + * An exception is thrown if the file is not writable. + */ +void MEDCouplingMesh::writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception) +{ + std::string cda,pda; + writeVTKAdvanced(fileName,cda,pda); +} + +void MEDCouplingMesh::writeVTKAdvanced(const char *fileName, const std::string& cda, const std::string& pda) const throw(INTERP_KERNEL::Exception) +{ + std::ofstream ofs(fileName); + ofs << "\n"; + writeVTKLL(ofs,cda,pda); + ofs << "\n"; + ofs.close(); +} diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index cee3750a3..31399a09b 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -120,9 +120,15 @@ namespace ParaMEDMEM virtual void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const = 0; virtual void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings) = 0; + void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); + /// @cond INTERNAL + void writeVTKAdvanced(const char *fileName, const std::string& cda, const std::string& pda) const throw(INTERP_KERNEL::Exception); + /// @endcond + virtual void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) = 0; protected: MEDCouplingMesh(); MEDCouplingMesh(const MEDCouplingMesh& other); + virtual std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception) = 0; virtual ~MEDCouplingMesh() { } private: std::string _name; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 49a744e45..54025ae42 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -32,6 +32,7 @@ #include "InterpKernelAutoPtr.hxx" #include +#include #include #include #include @@ -4449,6 +4450,46 @@ void MEDCouplingUMesh::fillInCompact3DMode(int spaceDim, int nbOfNodesInCell, co throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillInCompact3DMode : Invalid spaceDim specified : must be 2 or 3 !"); } +void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) +{ + static const int PARAMEDMEM2VTKTYPETRADUCER[INTERP_KERNEL::NORM_MAXTYPE+1]={1,3,21,5,9,7,22,-1,23,-1,-1,-1,-1,-1,10,14,13,-1,12,-1,24,-1,16,27,-1,26,-1,-1,-1,-1,25,42}; + ofs << " <" << getVTKDataSetType() << ">\n"; + ofs << " \n"; + ofs << " \n" << pointData << std::endl; + ofs << " \n"; + ofs << " \n" << cellData << std::endl; + ofs << " \n"; + ofs << " \n"; + if(getSpaceDimension()==3) + _coords->writeVTK(ofs,8,"Points"); + else + { + MEDCouplingAutoRefCountObjectPtr coo=_coords->changeNbOfComponents(3,0.); + coo->writeVTK(ofs,8,"Points"); + } + ofs << " \n"; + ofs << " \n"; + MEDCouplingAutoRefCountObjectPtr c0=_nodal_connec_index->buildComplement(_nodal_connec->getNumberOfTuples()+1); + c0=_nodal_connec->selectByTupleId(c0->begin(),c0->end()); + c0->writeVTK(ofs,8,"Int64","connectivity"); + MEDCouplingAutoRefCountObjectPtr c1=_nodal_connec_index->deltaShiftIndex(); + c1->applyLin(1,-1); + c1->computeOffsets2(); + c1=c1->selectByTupleId2(1,c1->getNumberOfTuples(),1); + c1->writeVTK(ofs,8,"Int64","offsets"); + MEDCouplingAutoRefCountObjectPtr c2=_nodal_connec->selectByTupleId(_nodal_connec_index->getConstPointer(),_nodal_connec_index->getConstPointer()+getNumberOfCells()); + c2->transformWithIndArr(PARAMEDMEM2VTKTYPETRADUCER,PARAMEDMEM2VTKTYPETRADUCER+INTERP_KERNEL::NORM_MAXTYPE); + c2->writeVTK(ofs,8,"UInt8","types"); + ofs << " \n"; + ofs << " \n"; + ofs << " \n"; +} + +std::string MEDCouplingUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) +{ + return std::string("UnstructuredGrid"); +} + MEDCouplingUMeshCellIterator::MEDCouplingUMeshCellIterator(MEDCouplingUMesh *mesh):_mesh(mesh),_cell(new MEDCouplingUMeshCell(mesh)), _own_cell(true),_cell_id(-1),_nb_cell(0) { @@ -4613,4 +4654,3 @@ const int *MEDCouplingUMeshCell::getAllConn(int& lgth) const else return 0; } - diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index afb987949..e6e680c2b 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -83,6 +83,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; MEDCOUPLING_EXPORT void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); + MEDCOUPLING_EXPORT std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); //tools MEDCOUPLING_EXPORT bool areCellsEqual(int cell1, int cell2, int compType) const; MEDCOUPLING_EXPORT bool areCellsEqual0(int cell1, int cell2) const; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 4e5d004a2..9f956fa6b 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -491,3 +491,14 @@ int MEDCouplingUMeshDesc::getCellContainingPoint(const double *pos, double eps) { throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getCellContainingPoint : not implemented yet !"); } + +void MEDCouplingUMeshDesc::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::writeVTKLL : not implemented yet !"); +} + +std::string MEDCouplingUMeshDesc::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getVTKDataSetType : not implemented yet !"); +} + diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index e8367df2b..ba62253a2 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -91,6 +91,8 @@ namespace ParaMEDMEM ~MEDCouplingUMeshDesc(); void computeTypes(); void checkFullyDefined() const throw(INTERP_KERNEL::Exception); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception); + std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); private: int _mesh_dim; DataArrayInt *_desc_connec; diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 983789907..a5da7e980 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -370,6 +370,7 @@ namespace ParaMEDMEM virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception) = 0; virtual std::string simpleRepr() const = 0; virtual std::string advancedRepr() const = 0; + void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); // tools virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const throw(INTERP_KERNEL::Exception) = 0; @@ -4672,6 +4673,13 @@ namespace ParaMEDMEM convertPyObjToVecFieldDblCst(li,tmp); return MEDCouplingFieldDouble::MergeFields(tmp); } + + static void WriteVTK(const char *fileName, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyObjToVecFieldDblCst(li,tmp); + MEDCouplingFieldDouble::WriteVTK(fileName,tmp); + } } }; -- 2.39.2