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");
+}
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;
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
#include "CellModel.hxx"
#include "InterpolationUtils.hxx"
_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<MEDCouplingUMesh> m=buildUnstructured();
+ m->writeVTKLL(ofs,cellData,pointData);
+}
+
+std::string MEDCouplingExtrudedMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
+{
+ return _mesh2D->getVTKDataSetType();
+}
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);
+ std::string getVTKDataSetType() const throw(INTERP_KERNEL::Exception);
private:
MEDCouplingUMesh *_mesh2D;
MEDCouplingUMesh *_mesh1D;
_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<const MEDCouplingFieldDouble *>& 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;i<nfs;i++)
+ if(fs[i]->getMesh()!=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;i<nfs;i++)
+ {
+ const MEDCouplingFieldDouble *cur=fs[i];
+ std::string name(cur->getName());
+ 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());
+}
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<const MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception);
public:
const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; }
MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; }
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 << "<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," "));
+ ofs << std::endl << idt << "</DataArray>\n";
+}
+
void DataArrayDouble::reprStream(std::ostream& stream) const
{
stream << "Name of double array : \"" << _name << "\"\n";
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 !");
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;
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 !");
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;
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 << "<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," "));
+ ofs << std::endl << idt << "</DataArray>\n";
+}
+
void DataArrayInt::reprStream(std::ostream& stream) const
{
stream << "Name of int array : \"" << _name << "\"\n";
_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)
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)
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)
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();
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;
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);
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;
MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqualList(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector<int>& 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);
#include <set>
#include <cmath>
#include <sstream>
+#include <fstream>
#include <iterator>
using namespace ParaMEDMEM;
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 << "<VTKFile type=\"" << getVTKDataSetType() << "\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
+ writeVTKLL(ofs,cda,pda);
+ ofs << "</VTKFile>\n";
+ ofs.close();
+}
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);
+ /// @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;
#include "InterpKernelAutoPtr.hxx"
#include <sstream>
+#include <fstream>
#include <numeric>
#include <cstring>
#include <limits>
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 << " <Piece NumberOfPoints=\"" << getNumberOfNodes() << "\" NumberOfCells=\"" << getNumberOfCells() << "\">\n";
+ ofs << " <PointData>\n" << pointData << std::endl;
+ ofs << " </PointData>\n";
+ ofs << " <CellData>\n" << cellData << std::endl;
+ ofs << " </CellData>\n";
+ ofs << " <Points>\n";
+ if(getSpaceDimension()==3)
+ _coords->writeVTK(ofs,8,"Points");
+ else
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=_coords->changeNbOfComponents(3,0.);
+ coo->writeVTK(ofs,8,"Points");
+ }
+ ofs << " </Points>\n";
+ ofs << " <Cells>\n";
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c0=_nodal_connec_index->buildComplement(_nodal_connec->getNumberOfTuples()+1);
+ c0=_nodal_connec->selectByTupleId(c0->begin(),c0->end());
+ c0->writeVTK(ofs,8,"Int64","connectivity");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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<DataArrayInt> 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 << " </Cells>\n";
+ ofs << " </Piece>\n";
+ ofs << " </UnstructuredGrid>\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)
{
else
return 0;
}
-
MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
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 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;
{
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 !");
+}
+
~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;
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;
convertPyObjToVecFieldDblCst(li,tmp);
return MEDCouplingFieldDouble::MergeFields(tmp);
}
+
+ static void WriteVTK(const char *fileName, PyObject *li) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const MEDCouplingFieldDouble *> tmp;
+ convertPyObjToVecFieldDblCst(li,tmp);
+ MEDCouplingFieldDouble::WriteVTK(fileName,tmp);
+ }
}
};