From: ageay Date: Tue, 20 Aug 2013 15:32:48 +0000 (+0000) Subject: Write VTK using binary format. X-Git-Tag: DBugPolyhIntersector~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a4c57148025e46be5c14de97e7c5d4e41500860c;p=modules%2Fmed.git Write VTK using binary format. --- diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 0cf66514f..7bb67e8f9 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -237,10 +237,10 @@ DataArrayInt *MEDCoupling1GTUMesh::checkTypeConsistencyAndContig(const std::vect return const_cast(pfl); } -void MEDCoupling1GTUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) +void MEDCoupling1GTUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) { MEDCouplingAutoRefCountObjectPtr m=buildUnstructured(); - m->writeVTKLL(ofs,cellData,pointData); + m->writeVTKLL(ofs,cellData,pointData,byteData); } std::string MEDCoupling1GTUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 6af8c0ef2..8b0cd8752 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -47,7 +47,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::vector getDistributionOfTypes() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) 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 writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); // MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const; diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 6fdb51e6f..d6b5e13b7 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -851,7 +851,7 @@ 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) +void MEDCouplingCMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) { std::ostringstream extent; DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array}; @@ -872,12 +872,12 @@ void MEDCouplingCMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData for(int i=0;i<3;i++) { if(thisArr[i]) - thisArr[i]->writeVTK(ofs,8,"Array"); + thisArr[i]->writeVTK(ofs,8,"Array",byteData); else { MEDCouplingAutoRefCountObjectPtr coo=DataArrayDouble::New(); coo->alloc(1,1); coo->setIJ(0,0,0.); - coo->writeVTK(ofs,8,"Array"); + coo->writeVTK(ofs,8,"Array",byteData); } } ofs << " \n"; diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index a6f8a182e..f3e02ee4b 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -92,7 +92,7 @@ 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); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception); std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); private: DataArrayDouble *_x_array; diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx index 4a7a18e7f..7bfadc53f 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx @@ -891,7 +891,7 @@ void MEDCouplingCurveLinearMesh::unserialization(const std::vector& tiny } } -void MEDCouplingCurveLinearMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception) +void MEDCouplingCurveLinearMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) { std::ostringstream extent; int meshDim=(int)_structure.size(); @@ -907,11 +907,11 @@ void MEDCouplingCurveLinearMesh::writeVTKLL(std::ostream& ofs, const std::string ofs << " \n"; ofs << " \n"; if(getSpaceDimension()==3) - _coords->writeVTK(ofs,8,"Points"); + _coords->writeVTK(ofs,8,"Points",byteData); else { MEDCouplingAutoRefCountObjectPtr coo=_coords->changeNbOfComponents(3,0.); - coo->writeVTK(ofs,8,"Points"); + coo->writeVTK(ofs,8,"Points",byteData); } ofs << " \n"; ofs << " \n"; diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx index c165d1fb0..66b274344 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx @@ -99,7 +99,7 @@ namespace ParaMEDMEM MEDCouplingCurveLinearMesh(); MEDCouplingCurveLinearMesh(const MEDCouplingCurveLinearMesh& other, bool deepCpy); ~MEDCouplingCurveLinearMesh(); - void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception); std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); private: MEDCouplingAutoRefCountObjectPtr _coords; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 27c8d6df5..fd3604037 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -932,10 +932,10 @@ void MEDCouplingExtrudedMesh::unserialization(const std::vector& tinyInf 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) +void MEDCouplingExtrudedMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) { MEDCouplingAutoRefCountObjectPtr m=buildUnstructured(); - m->writeVTKLL(ofs,cellData,pointData); + m->writeVTKLL(ofs,cellData,pointData,byteData); } void MEDCouplingExtrudedMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 6c40f15de..1c97019ad 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -118,7 +118,7 @@ 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); + void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception); std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception); private: MEDCouplingUMesh *_mesh2D; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 84bdb53d0..b7b3711b5 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -352,10 +352,10 @@ std::string MEDCouplingFieldDouble::advancedRepr() const return ret.str(); } -void MEDCouplingFieldDouble::writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::writeVTK(const char *fileName, bool isBinary) const throw(INTERP_KERNEL::Exception) { std::vector fs(1,this); - MEDCouplingFieldDouble::WriteVTK(fileName,fs); + MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary); } bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const throw(INTERP_KERNEL::Exception) @@ -3063,6 +3063,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCoupli * \warning All the fields must be named and lie on the same non NULL mesh. * \param [in] fileName - the name of a VTK file to write in. * \param [in] fs - the fields to write. + * \param [in] isBinary - specifies the VTK format of the written file. By default true (Binary mode) * \throw If \a fs[ 0 ] == NULL. * \throw If the fields lie not on the same mesh. * \throw If the mesh is not set. @@ -3071,7 +3072,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCoupli * \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".
* \ref py_mcfielddouble_WriteVTK "Here is a Python example". */ -void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector& fs) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector& fs, bool isBinary) throw(INTERP_KERNEL::Exception) { if(fs.empty()) return; @@ -3086,6 +3087,9 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector byteArr; + if(isBinary) + { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } std::ostringstream coss,noss; for(std::size_t i=0;igetTypeOfField(); if(typ==ON_CELLS) - cur->getArray()->writeVTK(coss,8,cur->getName().c_str()); + cur->getArray()->writeVTK(coss,8,cur->getName().c_str(),byteArr); else if(typ==ON_NODES) - cur->getArray()->writeVTK(noss,8,cur->getName().c_str()); + cur->getArray()->writeVTK(noss,8,cur->getName().c_str(),byteArr); + else + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !"); } - m->writeVTKAdvanced(fileName,coss.str(),noss.str()); + m->writeVTKAdvanced(fileName,coss.str(),noss.str(),byteArr); } void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 61ee004f8..3a3533e87 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -43,7 +43,7 @@ namespace ParaMEDMEM void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; std::string advancedRepr() const; - void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception); + void writeVTK(const char *fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const throw(INTERP_KERNEL::Exception); bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; bool areCompatibleForMerge(const MEDCouplingField *other) const; @@ -187,7 +187,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); const MEDCouplingFieldDouble &operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); - static void WriteVTK(const char *fileName, const std::vector& fs) throw(INTERP_KERNEL::Exception); + static void WriteVTK(const char *fileName, const std::vector& fs, bool isBinary=true) 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 92777b419..424a20986 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -23,6 +23,7 @@ #include "BBTree.txx" #include "GenMathFormulae.hxx" +#include "InterpKernelAutoPtr.hxx" #include "InterpKernelExprParser.hxx" #include @@ -1144,13 +1145,28 @@ std::string DataArrayDouble::reprZip() const throw(INTERP_KERNEL::Exception) return ret.str(); } -void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception) +void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile, DataArrayByte *byteArr) const throw(INTERP_KERNEL::Exception) { + static const char SPACE[4]={' ',' ',' ',' '}; + checkAllocated(); std::string idt(indent,' '); ofs.precision(17); ofs << idt << "\n" << idt; - std::copy(begin(),end(),std::ostream_iterator(ofs," ")); + if(byteArr) + { + ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">"; + INTERP_KERNEL::AutoPtr tmp(new float[getNbOfElems()]); + std::copy(begin(),end(),(float *)tmp); + const char *data(reinterpret_cast((float *)tmp)); + std::size_t sz(getNbOfElems()*sizeof(float)); + byteArr->insertAtTheEnd(data,data+sz); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else + { + ofs << " RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\" format=\"ascii\">\n" << idt; + std::copy(begin(),end(),std::ostream_iterator(ofs," ")); + } ofs << std::endl << idt << "\n"; } @@ -5897,13 +5913,44 @@ std::string DataArrayInt::reprZip() const throw(INTERP_KERNEL::Exception) return ret.str(); } -void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception) +void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile, DataArrayByte *byteArr) const throw(INTERP_KERNEL::Exception) { + static const char SPACE[4]={' ',' ',' ',' '}; checkAllocated(); std::string idt(indent,' '); ofs << idt << "\n" << idt; - std::copy(begin(),end(),std::ostream_iterator(ofs," ")); + if(byteArr) + { + ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">"; + if(std::string(type)=="Int32") + { + const char *data(reinterpret_cast(begin())); + std::size_t sz(getNbOfElems()*sizeof(int)); + byteArr->insertAtTheEnd(data,data+sz); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else if(std::string(type)=="Int8") + { + INTERP_KERNEL::AutoPtr tmp(new char[getNbOfElems()]); + std::copy(begin(),end(),(char *)tmp); + byteArr->insertAtTheEnd((char *)tmp,(char *)tmp+getNbOfElems()); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else if(std::string(type)=="UInt8") + { + INTERP_KERNEL::AutoPtr tmp(new unsigned char[getNbOfElems()]); + std::copy(begin(),end(),(unsigned char *)tmp); + byteArr->insertAtTheEnd((unsigned char *)tmp,(unsigned char *)tmp+getNbOfElems()); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else + throw INTERP_KERNEL::Exception("DataArrayInt::writeVTK : Only Int32, Int8 and UInt8 supported !"); + } + else + { + ofs << " RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\" format=\"ascii\">\n" << idt; + std::copy(begin(),end(),std::ostream_iterator(ofs," ")); + } ofs << std::endl << idt << "\n"; } diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index fa254c59c..8d52c7033 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -110,6 +110,7 @@ namespace ParaMEDMEM }; class DataArrayInt; + class DataArrayByte; class DataArray : public RefCountObject, public TimeLabel { @@ -225,7 +226,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string repr() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string reprZip() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *nameInFile, DataArrayByte *byteArr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); @@ -457,7 +458,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void iota(int init=0) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string repr() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string reprZip() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile, DataArrayByte *byteArr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); @@ -734,6 +735,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayChar *Meld(const std::vector& arr) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const char *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + template + void insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const char *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void updateTime() const { } MEDCOUPLING_EXPORT MemArray& accessToMemArray() { return _mem; } @@ -866,7 +869,7 @@ namespace ParaMEDMEM template void DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception) { - int nbCompo=getNumberOfComponents(); + int nbCompo(getNumberOfComponents()); if(nbCompo==1) _mem.insertAtTheEnd(first,last); else if(nbCompo==0) @@ -881,7 +884,7 @@ namespace ParaMEDMEM template void DataArrayInt::insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception) { - int nbCompo=getNumberOfComponents(); + int nbCompo(getNumberOfComponents()); if(nbCompo==1) _mem.insertAtTheEnd(first,last); else if(nbCompo==0) @@ -892,6 +895,21 @@ namespace ParaMEDMEM else throw INTERP_KERNEL::Exception("DataArrayInt::insertAtTheEnd : not available for DataArrayInt with number of components different than 1 !"); } + + template + void DataArrayChar::insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception) + { + int nbCompo(getNumberOfComponents()); + if(nbCompo==1) + _mem.insertAtTheEnd(first,last); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.insertAtTheEnd(first,last); + } + else + throw INTERP_KERNEL::Exception("DataArrayChar::insertAtTheEnd : not available for DataArrayChar with number of components different than 1 !"); + } } #endif diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index 83d2764c8..d03247cc2 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -669,17 +669,31 @@ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints * \param [in] fileName - the name of the file to write in. * \throw If \a fileName is not a writable file. */ -void MEDCouplingMesh::writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception) +void MEDCouplingMesh::writeVTK(const char *fileName, bool isBinary) const throw(INTERP_KERNEL::Exception) { std::string cda,pda; - writeVTKAdvanced(fileName,cda,pda); + MEDCouplingAutoRefCountObjectPtr byteArr; + if(isBinary) + { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } + writeVTKAdvanced(fileName,cda,pda,byteArr); } -void MEDCouplingMesh::writeVTKAdvanced(const char *fileName, const std::string& cda, const std::string& pda) const throw(INTERP_KERNEL::Exception) +void MEDCouplingMesh::writeVTKAdvanced(const char *fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) { std::ofstream ofs(fileName); - ofs << "\n"; - writeVTKLL(ofs,cda,pda); - ofs << "\n"; - ofs.close(); + ofs << "\n"; + writeVTKLL(ofs,cda,pda,byteData); + if(byteData) + { + ofs << "\n_1234"; + ofs << std::flush; ofs.close(); + std::ofstream ofs2(fileName,std::ios_base::binary | std::ios_base::app); + ofs2.write(byteData->begin(),byteData->getNbOfElems()); ofs2 << std::flush; ofs2.close(); + std::ofstream ofs3(fileName,std::ios_base::app); ofs3 << "\n \n\n"; ofs3.close(); + } + else + { + ofs << "\n"; + ofs.close(); + } } diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index e98443682..af3d71d02 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -37,15 +37,16 @@ namespace ParaMEDMEM typedef enum { UNSTRUCTURED = 5, - UNSTRUCTURED_DESC = 6, CARTESIAN = 7, EXTRUDED = 8, CURVE_LINEAR = 9, SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED = 10, SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED = 11 } MEDCouplingMeshType; + // -- WARNING this enum must be synchronized with MEDCouplingCommon.i file ! -- class DataArrayInt; + class DataArrayByte; class DataArrayDouble; class MEDCouplingUMesh; class MEDCouplingFieldDouble; @@ -142,11 +143,11 @@ 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); + void writeVTK(const char *fileName, bool isBinary=true) 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); + void writeVTKAdvanced(const char *fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) 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; + virtual void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) = 0; virtual void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; protected: MEDCouplingMesh(); diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index f216276c6..50ae9094e 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -20,8 +20,8 @@ #include "MEDCouplingPointSet.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingUMesh.hxx" -#include "MEDCouplingUMeshDesc.hxx" #include "MEDCouplingMemArray.hxx" #include "PlanarIntersector.txx" #include "InterpKernelGeo2DQuadraticPolygon.hxx" @@ -815,8 +815,10 @@ MEDCouplingPointSet *MEDCouplingPointSet::BuildInstanceFromMeshType(MEDCouplingM { case UNSTRUCTURED: return MEDCouplingUMesh::New(); - case UNSTRUCTURED_DESC: - return MEDCouplingUMeshDesc::New(); + case SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED: + return MEDCoupling1SGTUMesh::New(); + case SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED: + return MEDCoupling1DGTUMesh::New(); default: throw INTERP_KERNEL::Exception("Invalid type of mesh specified"); } diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index efa6c63fa..70fba21d9 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8069,7 +8069,7 @@ 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) +void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception) { int nbOfCells=getNumberOfCells(); if(nbOfCells<=0) @@ -8083,11 +8083,11 @@ void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData ofs << " \n"; ofs << " \n"; if(getSpaceDimension()==3) - _coords->writeVTK(ofs,8,"Points"); + _coords->writeVTK(ofs,8,"Points",byteData); else { MEDCouplingAutoRefCountObjectPtr coo=_coords->changeNbOfComponents(3,0.); - coo->writeVTK(ofs,8,"Points"); + coo->writeVTK(ofs,8,"Points",byteData); } ofs << " \n"; ofs << " \n"; @@ -8118,12 +8118,12 @@ void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData } } types->transformWithIndArr(PARAMEDMEM2VTKTYPETRADUCER,PARAMEDMEM2VTKTYPETRADUCER+INTERP_KERNEL::NORM_MAXTYPE); - types->writeVTK(ofs,8,"UInt8","types"); - offsets->writeVTK(ofs,8,"Int32","offsets"); + types->writeVTK(ofs,8,"UInt8","types",byteData); + offsets->writeVTK(ofs,8,"Int32","offsets",byteData); if(szFaceOffsets!=0) {//presence of Polyhedra connectivity->reAlloc(szConn); - faceoffsets->writeVTK(ofs,8,"Int32","faceoffsets"); + faceoffsets->writeVTK(ofs,8,"Int32","faceoffsets",byteData); MEDCouplingAutoRefCountObjectPtr faces=DataArrayInt::New(); faces->alloc(szFaceOffsets,1); w1=faces->getPointer(); for(int i=0;iwriteVTK(ofs,8,"Int32","faces"); + faces->writeVTK(ofs,8,"Int32","faces",byteData); } - connectivity->writeVTK(ofs,8,"Int32","connectivity"); + connectivity->writeVTK(ofs,8,"Int32","connectivity",byteData); ofs << " \n"; ofs << " \n"; ofs << " \n"; diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 49d6c89a2..4941812c2 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -89,7 +89,7 @@ namespace ParaMEDMEM 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 writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); //tools MEDCOUPLING_EXPORT static int AreCellsEqual(const int *conn, const int *connI, int cell1, int cell2, int compType); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx index 65fb32382..762f4709c 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx @@ -935,7 +935,7 @@ void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases() CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos)); std::ostringstream ret; - dbl->writeVTK(ret,2,"file.tmp"); + dbl->writeVTK(ret,2,"file.tmp",0); CPPUNIT_ASSERT(!((ret.str().find(" tmp; convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,"MEDCouplingFieldDouble",tmp); - MEDCouplingFieldDouble::WriteVTK(fileName,tmp); + MEDCouplingFieldDouble::WriteVTK(fileName,tmp,isBinary); } } };