]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Write VTK using binary format.
authorageay <ageay>
Tue, 20 Aug 2013 15:32:48 +0000 (15:32 +0000)
committerageay <ageay>
Tue, 20 Aug 2013 15:32:48 +0000 (15:32 +0000)
19 files changed:
src/MEDCoupling/MEDCoupling1GTUMesh.cxx
src/MEDCoupling/MEDCoupling1GTUMesh.hxx
src/MEDCoupling/MEDCouplingCMesh.cxx
src/MEDCoupling/MEDCouplingCMesh.hxx
src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx
src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx
src/MEDCoupling/MEDCouplingExtrudedMesh.cxx
src/MEDCoupling/MEDCouplingExtrudedMesh.hxx
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling/MEDCouplingFieldDouble.hxx
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMesh.cxx
src/MEDCoupling/MEDCouplingMesh.hxx
src/MEDCoupling/MEDCouplingPointSet.cxx
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 0cf66514f21a3c576428211fdef0877b2ad383c7..7bb67e8f9a00454fb4e447237e8de38330d8cb43 100644 (file)
@@ -237,10 +237,10 @@ DataArrayInt *MEDCoupling1GTUMesh::checkTypeConsistencyAndContig(const std::vect
   return const_cast<DataArrayInt *>(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<MEDCouplingUMesh> m=buildUnstructured();
-  m->writeVTKLL(ofs,cellData,pointData);
+  m->writeVTKLL(ofs,cellData,pointData,byteData);
 }
 
 std::string MEDCoupling1GTUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
index 6af8c0ef2b6b83c7b8d7b903f3f371c8f2ecb9ca..8b0cd87525efb15f15364aaaef831501adc0b2c1 100644 (file)
@@ -47,7 +47,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT std::vector<int> getDistributionOfTypes() const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& 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;
index 6fdb51e6ff9cdd1ff747b1495f68d1fe7ad9886d..d6b5e13b7f2d6732b04e38c0547fe102c28172b7 100644 (file)
@@ -851,7 +851,7 @@ void MEDCouplingCMesh::unserialization(const std::vector<double>& 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<DataArrayDouble> coo=DataArrayDouble::New(); coo->alloc(1,1);
           coo->setIJ(0,0,0.);
-          coo->writeVTK(ofs,8,"Array");
+          coo->writeVTK(ofs,8,"Array",byteData);
         }
     }
   ofs << "      </Coordinates>\n";
index a6f8a182e6f0a4174020a101e5b9793d846e0d3b..f3e02ee4b0c5a45074ccfe1007f8085515ca9adc 100644 (file)
@@ -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;
index 4a7a18e7f9d49af12fc590610067ce572470e002..7bfadc53f4579998b3a49901bba0182f46d8a7db 100644 (file)
@@ -891,7 +891,7 @@ void MEDCouplingCurveLinearMesh::unserialization(const std::vector<double>& 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 << "      </CellData>\n";
   ofs << "      <Points>\n";
   if(getSpaceDimension()==3)
-    _coords->writeVTK(ofs,8,"Points");
+    _coords->writeVTK(ofs,8,"Points",byteData);
   else
     {
       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=_coords->changeNbOfComponents(3,0.);
-      coo->writeVTK(ofs,8,"Points");
+      coo->writeVTK(ofs,8,"Points",byteData);
     }
   ofs << "      </Points>\n";
   ofs << "    </Piece>\n";
index c165d1fb0c6384bc234211361ed07678b46b2af8..66b2743445ebb1219838b060e5d2e1483c828625 100644 (file)
@@ -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<DataArrayDouble> _coords;
index 27c8d6df5b7907d5300eaa9791aadec78d7950a2..fd36040373e98a3f81700fbc3bbd99eecc09daee 100644 (file)
@@ -932,10 +932,10 @@ void MEDCouplingExtrudedMesh::unserialization(const std::vector<double>& 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<MEDCouplingUMesh> m=buildUnstructured();
-  m->writeVTKLL(ofs,cellData,pointData);
+  m->writeVTKLL(ofs,cellData,pointData,byteData);
 }
 
 void MEDCouplingExtrudedMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
index 6c40f15deecd0d15509795022e43cba39e42a232..1c97019ad3dc86546350a3219c002a053671c8af 100644 (file)
@@ -118,7 +118,7 @@ namespace ParaMEDMEM
                            const int *conn2D, const int *conn2DIndx) throw(INTERP_KERNEL::Exception);
     void computeBaryCenterOfFace(const std::vector<int>& 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;
index 84bdb53d083f8e7ca53e7d62896810ea4cf792cb..b7b3711b501da4e4d001b280e1b4ceec6aa1f8df 100644 (file)
@@ -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<const MEDCouplingFieldDouble *> 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".<br>
  *  \ref  py_mcfielddouble_WriteVTK "Here is a Python example".
  */
-void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector<const MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception)
+void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary) throw(INTERP_KERNEL::Exception)
 {
   if(fs.empty())
     return;
@@ -3086,6 +3087,9 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector<co
       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 !");
+  MEDCouplingAutoRefCountObjectPtr<DataArrayByte> byteArr;
+  if(isBinary)
+    { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); }
   std::ostringstream coss,noss;
   for(std::size_t i=0;i<nfs;i++)
     {
@@ -3098,11 +3102,13 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector<co
         }
       TypeOfField typ=cur->getTypeOfField();
       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)
index 61ee004f89df814e4c9c26851cbf6c4946aa8b70..3a3533e8729515fdd7aa66c6bb1fe8ecf36b3386 100644 (file)
@@ -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<const MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception);
+    static void WriteVTK(const char *fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary=true) throw(INTERP_KERNEL::Exception);
   public:
     const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; }
     MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; }
index 92777b41972c3fbc8b9243e3b1290cb1da84c41b..424a2098654b44c644a9cff89287ae819a56dd7c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "BBTree.txx"
 #include "GenMathFormulae.hxx"
+#include "InterpKernelAutoPtr.hxx"
 #include "InterpKernelExprParser.hxx"
 
 #include <set>
@@ -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 << "<DataArray type=\"Float32\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
-  ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
-  std::copy(begin(),end(),std::ostream_iterator<double>(ofs," "));
+  if(byteArr)
+    {
+      ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">";
+      INTERP_KERNEL::AutoPtr<float> tmp(new float[getNbOfElems()]);
+      std::copy(begin(),end(),(float *)tmp);
+      const char *data(reinterpret_cast<const char *>((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<double>(ofs," "));
+    }
   ofs << std::endl << idt << "</DataArray>\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 << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
-  ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
-  std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
+  if(byteArr)
+    {
+      ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">";
+      if(std::string(type)=="Int32")
+        {
+          const char *data(reinterpret_cast<const char *>(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<char> 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<unsigned char> 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<int>(ofs," "));
+    }
   ofs << std::endl << idt << "</DataArray>\n";
 }
 
index fa254c59c42ad54a8ad50c97f93ea08ba16324fb..8d52c703326b11376c96a0016b5c1dea7eabf57b 100644 (file)
@@ -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<const DataArrayChar *>& 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<class InputIterator>
+    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<char>& accessToMemArray() { return _mem; }
@@ -866,7 +869,7 @@ namespace ParaMEDMEM
   template<class InputIterator>
   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<class InputIterator>
   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<class InputIterator>
+  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
index 83d2764c87c0d8ff3705ef2cdb91c8c2f4949a2a..d03247cc2b414d079d77220063e964cbaa57dc96 100644 (file)
@@ -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<DataArrayByte> 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 << "<VTKFile type=\""  << getVTKDataSetType() << "\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
-  writeVTKLL(ofs,cda,pda);
-  ofs << "</VTKFile>\n";
-  ofs.close();
+  ofs << "<VTKFile type=\""  << getVTKDataSetType() << "\" version=\"0.1\" byte_order=\"" << MEDCouplingByteOrderStr() << "\">\n";
+  writeVTKLL(ofs,cda,pda,byteData);
+  if(byteData)
+    {
+      ofs << "<AppendedData encoding=\"raw\">\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  </AppendedData>\n</VTKFile>\n"; ofs3.close();
+    }
+  else
+    {
+      ofs << "</VTKFile>\n";
+      ofs.close();
+    }
 }
index e98443682c3025ba18223282571155fc41569c26..af3d71d026a5a89056324108dae04eaaa08e13ed 100644 (file)
@@ -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<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,
                                  const std::vector<std::string>& 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();
index f216276c6c66bf1a23f73bccf30944f76fc775de..50ae9094ec203f0a39b328e8c79fd9b9b55d37fb 100644 (file)
@@ -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");
     }
index efa6c63faeba05ec256e9f1b763982739d74f6a4..70fba21d9750110f3e1a569f6b916e42278c20fc 100644 (file)
@@ -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 << "      </CellData>\n";
   ofs << "      <Points>\n";
   if(getSpaceDimension()==3)
-    _coords->writeVTK(ofs,8,"Points");
+    _coords->writeVTK(ofs,8,"Points",byteData);
   else
     {
       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=_coords->changeNbOfComponents(3,0.);
-      coo->writeVTK(ofs,8,"Points");
+      coo->writeVTK(ofs,8,"Points",byteData);
     }
   ofs << "      </Points>\n";
   ofs << "      <Cells>\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<DataArrayInt> faces=DataArrayInt::New(); faces->alloc(szFaceOffsets,1);
       w1=faces->getPointer();
       for(int i=0;i<nbOfCells;i++)
@@ -8140,9 +8140,9 @@ void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData
                 w6=w5+1;
               }
           }
-      faces->writeVTK(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 << "      </Cells>\n";
   ofs << "    </Piece>\n";
   ofs << "  </" << getVTKDataSetType() << ">\n";
index 49d6c89a2aba36d6bc68603df71abbe6aeeac28c..4941812c21a3f4a8a0be2f4f58965d4ded45fa86 100644 (file)
@@ -89,7 +89,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const;
     MEDCOUPLING_EXPORT void unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& 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);
index 65fb32382417d80774893a57d0862219102f92e2..762f4709c196c0582e6105c1641d89cdd0f2a1d3 100644 (file)
@@ -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("<DataArray"))==std::string::npos));
   CPPUNIT_ASSERT(!((ret.str().find("Float32"))==std::string::npos));
   CPPUNIT_ASSERT(!((ret.str().find("16 15 14 13 12 11 10"))==std::string::npos));
index 1d7434b7c8864670bc339912fb4d505c24ad6773..c8339a20163f3fe276f6b02db766dafec3a6d52d 100644 (file)
@@ -611,10 +611,11 @@ namespace ParaMEDMEM
   typedef enum
     {
       UNSTRUCTURED = 5,
-      UNSTRUCTURED_DESC = 6,
       CARTESIAN = 7,
       EXTRUDED = 8,
-      CURVE_LINEAR = 9
+      CURVE_LINEAR = 9,
+      SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED = 10,
+      SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED = 11
     } MEDCouplingMeshType;
 
   class DataArrayInt;
@@ -685,7 +686,7 @@ namespace ParaMEDMEM
     virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception);
     virtual std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
     virtual std::string advancedRepr() const throw(INTERP_KERNEL::Exception);
-    void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception);
+    void writeVTK(const char *fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception);
     // tools
     virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception);
     virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const throw(INTERP_KERNEL::Exception);
@@ -3348,7 +3349,7 @@ namespace ParaMEDMEM
     void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception);
     std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
     std::string advancedRepr() const throw(INTERP_KERNEL::Exception);
-    void writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception);
+    void writeVTK(const char *fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *clone(bool recDeepCpy) const;
     MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const;
     MEDCouplingFieldDouble *deepCpy() const;
@@ -4416,11 +4417,11 @@ namespace ParaMEDMEM
         return MEDCouplingFieldDouble::MergeFields(tmp);
       }
 
-      static void WriteVTK(const char *fileName, PyObject *li) throw(INTERP_KERNEL::Exception)
+      static void WriteVTK(const char *fileName, PyObject *li, bool isBinary=true) throw(INTERP_KERNEL::Exception)
       {
         std::vector<const MEDCouplingFieldDouble *> tmp;
         convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingFieldDouble *>(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,"MEDCouplingFieldDouble",tmp);
-        MEDCouplingFieldDouble::WriteVTK(fileName,tmp);
+        MEDCouplingFieldDouble::WriteVTK(fileName,tmp,isBinary);
       }
     }
   };