From 6843998fbd976b67d93e604086f8b990606f0dbb Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 20 Dec 2018 10:55:59 +0100 Subject: [PATCH] On the road --- src/MEDCoupling/MEDCouplingMemArray.cxx | 253 +----------------------- src/MEDCoupling/MEDCouplingMemArray.hxx | 40 ++-- src/MEDCoupling/MEDCouplingMemArray.txx | 252 ++++++++++++++++++++++- src/MEDCoupling/MEDCouplingTraits.cxx | 4 + src/MEDCoupling/MEDCouplingTraits.hxx | 2 + 5 files changed, 285 insertions(+), 266 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index aaa55d3bc..29354bb74 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -53,6 +53,8 @@ template class MEDCoupling::DataArrayIterator; template class MEDCoupling::DataArrayIterator; template class MEDCoupling::DataArrayDiscrete; template class MEDCoupling::DataArrayDiscreteSigned; +template class MEDCoupling::DataArrayDiscrete; +template class MEDCoupling::DataArrayDiscreteSigned; template class MEDCoupling::DataArrayTuple; template class MEDCoupling::DataArrayTuple; template class MEDCoupling::DataArrayTuple; @@ -884,27 +886,6 @@ bool DataArrayDouble::isMonotonic(bool increasing, double eps) const } } -/*! - * Returns a textual and human readable representation of \a this instance of - * DataArrayDouble. This text is shown when a DataArrayDouble is printed in Python. - * \return std::string - text describing \a this DataArrayDouble. - * - * \sa reprNotTooLong, reprZip - */ -std::string DataArrayDouble::repr() const -{ - std::ostringstream ret; - reprStream(ret); - return ret.str(); -} - -std::string DataArrayDouble::reprZip() const -{ - std::ostringstream ret; - reprZipStream(ret); - return ret.str(); -} - void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const { static const char SPACE[4]={' ',' ',' ',' '}; @@ -969,10 +950,10 @@ void DataArrayDouble::reprQuickOverview(std::ostream& stream) const stream << "DataArrayDouble C++ instance at " << this << ". "; if(isAllocated()) { - int nbOfCompo=(int)_info_on_compo.size(); + std::size_t nbOfCompo(_info_on_compo.size()); if(nbOfCompo>=1) { - int nbOfTuples=getNumberOfTuples(); + std::size_t nbOfTuples(getNumberOfTuples()); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); } @@ -3678,15 +3659,6 @@ DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCom return this->buildDA(nbOfTuples,nbOfCompo); } -/*! - * Returns a new instance of DataArrayInt. The caller is to delete this array - * using decrRef() as it is no more needed. - */ -DataArrayInt *DataArrayInt::New() -{ - return new DataArrayInt; -} - /*! * Returns the only one value in \a this, if and only if number of elements * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated. @@ -3708,27 +3680,6 @@ int DataArrayInt::intValue() const throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !"); } -/*! - * Returns an integer value characterizing \a this array, which is useful for a quick - * comparison of many instances of DataArrayInt. - * \return int - the hash value. - * \throw If \a this is not allocated. - */ -int DataArrayInt::getHashCode() const -{ - checkAllocated(); - std::size_t nbOfElems=getNbOfElems(); - int ret=nbOfElems*65536; - int delta=3; - if(nbOfElems>48) - delta=nbOfElems/8; - int ret0=0; - const int *pt=begin(); - for(std::size_t i=0;igetNumberOfTuples() << "\">"; - 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"; -} - -void DataArrayInt::reprCppStream(const std::string& varName, std::ostream& stream) const -{ - int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); - const int *data=getConstPointer(); - stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl; - if(nbTuples*nbComp>=1) - { - stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={"; - std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator(stream,",")); - stream << data[nbTuples*nbComp-1] << "};" << std::endl; - stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl; - } - else - stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl; - stream << varName << "->setName(\"" << getName() << "\");" << std::endl; -} - -/*! - * Method that gives a quick overvien of \a this for python. - */ -void DataArrayInt::reprQuickOverview(std::ostream& stream) const -{ - static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300; - stream << "DataArrayInt C++ instance at " << this << ". "; - if(isAllocated()) - { - int nbOfCompo=(int)_info_on_compo.size(); - if(nbOfCompo>=1) - { - int nbOfTuples=getNumberOfTuples(); - stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; - reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); - } - else - stream << "Number of components : 0."; - } - else - stream << "*** No data allocated ****"; -} - -void DataArrayInt::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const -{ - const int *data=begin(); - int nbOfTuples=getNumberOfTuples(); - int nbOfCompo=(int)_info_on_compo.size(); - std::ostringstream oss2; oss2 << "["; - std::string oss2Str(oss2.str()); - bool isFinished=true; - for(int i=0;i1) - { - oss2 << "("; - for(int j=0;jgetNumberOfComponents() != 1 - * \throw If any value of \a this can't be used as a valid index for - * [\a indArrBg, \a indArrEnd). - * - * \sa changeValue, findIdForEach - */ -void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) -{ - this->checkAllocated(); - if(this->getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !"); - int nbElemsIn((int)std::distance(indArrBg,indArrEnd)),nbOfTuples(getNumberOfTuples()),*pt(getPointer()); - for(int i=0;i=0 && *ptdeclareAsNew(); -} - -void DataArrayInt::transformWithIndArr(const MapKeyVal& m) -{ - this->checkAllocated(); - if(this->getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !"); - const std::map& dat(m.data()); - int nbOfTuples(getNumberOfTuples()),*pt(getPointer()); - for(int i=0;i::const_iterator it(dat.find(*pt)); - if(it!=dat.end()) - *pt=(*it).second; - else - { - std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !"; - throw INTERP_KERNEL::Exception(oss.str()); - } - } - this->declareAsNew(); -} - /*! * Creates a one-dimensional DataArrayInt (\a res) whose contents are computed from * values of \a this (\a a) and the given (\a indArr) arrays as follows: @@ -6916,3 +6676,8 @@ DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const { return this->buildDA(nbOfTuples,nbOfCompo); } + +DataArrayInt64 *DataArrayInt64::deepCopy() const +{ + return new DataArrayInt64(*this); +} diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 3887de629..56e0e9329 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -246,7 +246,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } MEDCOUPLING_EXPORT T *getPointer() { return _mem.getPointer(); declareAsNew(); } MEDCOUPLING_EXPORT void pack() const; - MEDCOUPLING_EXPORT bool isAllocated() const; + MEDCOUPLING_EXPORT bool isAllocated() const override; MEDCOUPLING_EXPORT void checkAllocated() const; MEDCOUPLING_EXPORT void desallocate(); MEDCOUPLING_EXPORT void reserve(std::size_t nbOfElems); @@ -353,6 +353,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string repr() const; + MEDCOUPLING_EXPORT std::string reprZip() const; MEDCOUPLING_EXPORT std::string reprNotTooLong() const; template MCAuto< typename Traits::ArrayType > convertToOtherTypeOfArr() const; @@ -415,8 +417,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); } MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const; MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const; - MEDCOUPLING_EXPORT std::string repr() const; - MEDCOUPLING_EXPORT std::string reprZip() const; MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const; MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; @@ -528,6 +528,7 @@ namespace MEDCoupling class DataArrayDiscrete : public DataArrayTemplateClassic { public: + MEDCOUPLING_EXPORT static typename Traits::ArrayType *New(); MEDCOUPLING_EXPORT bool isEqual(const DataArrayDiscrete& other) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDiscrete& other, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDiscrete& other) const; @@ -540,6 +541,13 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const; MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const; MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const; + MEDCOUPLING_EXPORT int getHashCode() const; + MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; + MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const; + MEDCOUPLING_EXPORT void transformWithIndArr(const T *indArrBg, const T *indArrEnd); + MEDCOUPLING_EXPORT void transformWithIndArr(const MapKeyVal& m); protected: template void switchOnTupleAlg(T val, std::vector& vec, ALG algo) const; @@ -560,21 +568,12 @@ namespace MEDCoupling class DataArrayInt32 : public DataArrayDiscreteSigned { + friend class DataArrayDiscrete; public: - MEDCOUPLING_EXPORT static DataArrayInt32 *New(); MEDCOUPLING_EXPORT int intValue() const; - MEDCOUPLING_EXPORT int getHashCode() const; MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok - MEDCOUPLING_EXPORT std::string repr() const; - MEDCOUPLING_EXPORT std::string reprZip() const; - MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const; - MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; - MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd); - MEDCOUPLING_EXPORT void transformWithIndArr(const MapKeyVal& m); - MEDCOUPLING_EXPORT DataArrayInt32 *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const; + MEDCOUPLING_EXPORT DataArrayInt32 *transformWithIndArrR(const int *indArr2Bg, const int *indArrEnd) const; MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd, DataArrayInt32 *& castArr, DataArrayInt32 *& rankInsideCast, DataArrayInt32 *& castsPresent) const; MEDCOUPLING_EXPORT bool isRange(int& strt, int& sttoopp, int& stteepp) const; @@ -678,6 +677,19 @@ namespace MEDCoupling class DataArrayInt64 : public DataArrayDiscrete { + friend class DataArrayDiscrete; + public: + MEDCOUPLING_EXPORT DataArrayInt64 *deepCopy() const; + MEDCOUPLING_EXPORT DataArrayInt64 *buildNewEmptyInstance() const { return DataArrayInt64::New(); }//ok + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleId(new2OldBg,new2OldEnd); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleId(const DataArrayInt32& di) const { return DataArrayTemplate::mySelectByTupleId(di); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); } + MEDCOUPLING_EXPORT DataArrayInt64 *keepSelectedComponents(const std::vector& compoIds) const { return DataArrayTemplate::myKeepSelectedComponents(compoIds); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate::mySelectByTupleIdSafeSlice(bg,end2,step); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleRanges(const std::vector >& ranges) const { return DataArrayTemplate::mySelectByTupleRanges(ranges); } + private: + ~DataArrayInt64() { } + DataArrayInt64() { } }; template diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index f2c2f4690..47e6961fa 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -601,7 +601,7 @@ namespace MEDCoupling { std::size_t sz(_mem.getNbOfElemAllocated()); sz*=sizeof(T); - return DataArray::getHeapMemorySizeWithoutChildren()+sz; + return this->getHeapMemorySizeWithoutChildren()+sz; } /*! @@ -1128,7 +1128,7 @@ namespace MEDCoupling template typename Traits::ArrayType *DataArrayTemplate::mySelectByTupleId(const DataArrayInt& di) const { - return DataArrayTemplate::mySelectByTupleId(di.begin(),di.end()); + return this->mySelectByTupleId(di.begin(),di.end()); } template @@ -3351,7 +3351,7 @@ struct NotInRange template void DataArrayTemplateClassic::reprWithoutNameStream(std::ostream& stream) const { - DataArray::reprWithoutNameStream(stream); + this->reprWithoutNameStream(stream); ImplReprTraits::SetPrecision(stream); this->_mem.repr(this->getNumberOfComponents(),stream); } @@ -3359,7 +3359,7 @@ struct NotInRange template void DataArrayTemplateClassic::reprZipWithoutNameStream(std::ostream& stream) const { - DataArray::reprWithoutNameStream(stream); + this->reprWithoutNameStream(stream); ImplReprTraits::SetPrecision(stream); this->_mem.reprZip(this->getNumberOfComponents(),stream); } @@ -3367,7 +3367,7 @@ struct NotInRange template void DataArrayTemplateClassic::reprNotTooLongWithoutNameStream(std::ostream& stream) const { - DataArray::reprWithoutNameStream(stream); + this->reprWithoutNameStream(stream); ImplReprTraits::SetPrecision(stream); this->_mem.reprNotTooLong(this->getNumberOfComponents(),stream); } @@ -3385,6 +3385,29 @@ struct NotInRange return ret.str(); } + /*! + * Returns a textual and human readable representation of \a this instance of + * DataArrayInt. This text is shown when a DataArrayInt is printed in Python. + * \return std::string - text describing \a this DataArrayInt. + * + * \sa reprNotTooLong, reprZip + */ + template + std::string DataArrayTemplateClassic::repr() const + { + std::ostringstream ret; + DataArrayTemplateClassic::reprStream(ret); + return ret.str(); + } + + template + std::string DataArrayTemplateClassic::reprZip() const + { + std::ostringstream ret; + DataArrayTemplateClassic::reprZipStream(ret); + return ret.str(); + } + ///////////////////////////////// /*! @@ -3438,7 +3461,17 @@ struct NotInRange std::string tmp; return isEqualIfNotWhy(other,tmp); } - + + /*! + * Returns a new instance of DataArrayInt. The caller is to delete this array + * using decrRef() as it is no more needed. + */ + template + typename Traits::ArrayType *DataArrayDiscrete::New() + { + return nullptr;//new typename Traits::ArrayType; + } + /*! * Checks if values of \a this and another DataArrayInt are equal. For more info see * \ref MEDCouplingArrayBasicsCompare. @@ -3462,7 +3495,8 @@ struct NotInRange template bool DataArrayDiscrete::isEqualWithoutConsideringStrAndOrder(const typename Traits::ArrayType& other) const { - MCAuto a(static_cast::ArrayType *>(this)->deepCopy()),b(other.deepCopy()); + MCAuto::ArrayType> a((static_cast::ArrayType *>(this))->deepCopy()); + MCAuto::ArrayType> b((static_cast::ArrayType *>(&other))->deepCopy()); a->sort(); b->sort(); return a->isEqualWithoutConsideringStr(*b); @@ -3586,7 +3620,7 @@ struct NotInRange const T *thisPt(this->begin()),*pt(partOfThis.begin()); MCAuto ret(DataArrayIdType::New()); ret->alloc(nbTuples,1); - T *retPt(ret->getPointer()); + mcIdType *retPt(ret->getPointer()); std::map m; for(std::size_t i=0;i + int DataArrayDiscrete::getHashCode() const + { + this->checkAllocated(); + std::size_t nbOfElems(this->getNbOfElems()); + int ret=nbOfElems*65536; + int delta=3; + if(nbOfElems>48) + delta=nbOfElems/8; + T ret0(0); + const T *pt(this->begin()); + for(std::size_t i=0;i + void DataArrayDiscrete::reprCppStream(const std::string& varName, std::ostream& stream) const + { + std::size_t nbTuples(this->getNumberOfTuples()),nbComp(this->getNumberOfComponents()); + const T *data(this->getConstPointer()); + stream << Traits::ArrayTypeName << " *" << varName << "=" << Traits::ArrayTypeName << "::New();" << std::endl; + if(nbTuples*nbComp>=1) + { + stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={"; + std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator(stream,",")); + stream << data[nbTuples*nbComp-1] << "};" << std::endl; + stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl; + } + else + stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl; + stream << varName << "->setName(\"" << this->getName() << "\");" << std::endl; + } + + /*! + * Method that gives a quick overvien of \a this for python. + */ + template + void DataArrayDiscrete::reprQuickOverview(std::ostream& stream) const + { + static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300; + stream << Traits::ArrayTypeName << " C++ instance at " << this << ". "; + if(this->isAllocated()) + { + std::size_t nbOfCompo(this->getNumberOfComponents()); + if(nbOfCompo>=1) + { + std::size_t nbOfTuples(this->getNumberOfTuples()); + stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; + reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); + } + else + stream << "Number of components : 0."; + } + else + stream << "*** No data allocated ****"; + } + + template + void DataArrayDiscrete::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const + { + const T *data(this->begin()); + std::size_t nbOfTuples(this->getNumberOfTuples()),nbOfCompo(this->getNumberOfComponents()); + std::ostringstream oss2; oss2 << "["; + std::string oss2Str(oss2.str()); + bool isFinished=true; + for(int i=0;i1) + { + oss2 << "("; + for(int j=0;j + void DataArrayDiscrete::writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const + { + static const char SPACE[4]={' ',' ',' ',' '}; + this->checkAllocated(); + std::string idt(indent,' '); + ofs << idt << "getNumberOfComponents() << "\""; + if(byteArr) + { + ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">"; + if(std::string(type)==Traits::VTKReprStr) + { + const char *data(reinterpret_cast(this->begin())); + std::size_t sz(this->getNbOfElems()*sizeof(T)); + byteArr->insertAtTheEnd(data,data+sz); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else if(std::string(type)=="Int8") + { + INTERP_KERNEL::AutoPtr tmp(new char[this->getNbOfElems()]); + std::copy(this->begin(),this->end(),(char *)tmp); + byteArr->insertAtTheEnd((char *)tmp,(char *)tmp+this->getNbOfElems()); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else if(std::string(type)=="UInt8") + { + INTERP_KERNEL::AutoPtr tmp(new unsigned char[this->getNbOfElems()]); + std::copy(this->begin(),this->end(),(unsigned char *)tmp); + byteArr->insertAtTheEnd((unsigned char *)tmp,(unsigned char *)tmp+this->getNbOfElems()); + byteArr->insertAtTheEnd(SPACE,SPACE+4); + } + else + { + std::ostringstream oss; + oss << Traits::ArrayTypeName << "::writeVTK : Only " << Traits::VTKReprStr << ", Int8 and UInt8 supported !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } + else + { + ofs << " RangeMin=\"" << this->getMinValueInArray() << "\" RangeMax=\"" << this->getMaxValueInArray() << "\" format=\"ascii\">\n" << idt; + std::copy(this->begin(),this->end(),std::ostream_iterator(ofs," ")); + } + ofs << std::endl << idt << "\n"; + } + + /*! + * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ], + * i.e. a current value is used as in index to get a new value from \a indArrBg. + * \param [in] indArrBg - pointer to the first element of array of new values to assign + * to \a this array. + * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that + * the last value of \a indArrBg is \a indArrEnd[ -1 ]. + * \throw If \a this->getNumberOfComponents() != 1 + * \throw If any value of \a this can't be used as a valid index for + * [\a indArrBg, \a indArrEnd). + * + * \sa changeValue, findIdForEach + */ + template + void DataArrayDiscrete::transformWithIndArr(const T *indArrBg, const T *indArrEnd) + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !"); + std::size_t nbElemsIn(std::distance(indArrBg,indArrEnd)),nbOfTuples(this->getNumberOfTuples()); + T *pt(this->getPointer()); + for(std::size_t i=0;i=0 && *ptdeclareAsNew(); + } + + template + void DataArrayDiscrete::transformWithIndArr(const MapKeyVal& m) + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !"); + const typename std::map& dat(m.data()); + std::size_t nbOfTuples(this->getNumberOfTuples()); + T *pt(this->getPointer()); + for(std::size_t i=0;i::const_iterator it(dat.find(*pt)); + if(it!=dat.end()) + *pt=(*it).second; + else + { + std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } + this->declareAsNew(); + } + //////////////////////////////////// /*! diff --git a/src/MEDCoupling/MEDCouplingTraits.cxx b/src/MEDCoupling/MEDCouplingTraits.cxx index 46e3f7b1f..8febd9af4 100644 --- a/src/MEDCoupling/MEDCouplingTraits.cxx +++ b/src/MEDCoupling/MEDCouplingTraits.cxx @@ -46,6 +46,8 @@ const char Traits::NPYStr[]="INT32"; const char Traits::ReprStr[]="int"; +const char Traits::VTKReprStr[]="Int32"; + const char Traits::ArrayTypeName[]="DataArrayChar"; const char Traits::ArrayTypeName[]="DataArrayInt64"; @@ -55,3 +57,5 @@ const char Traits::FieldTypeName[]="MEDCouplingFieldInt64"; const char Traits::NPYStr[]="INT64"; const char Traits::ReprStr[]="int64"; + +const char Traits::VTKReprStr[]="Int64"; diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index a14232eec..7059106c1 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -78,6 +78,7 @@ namespace MEDCoupling static const char FieldTypeName[]; static const char NPYStr[]; static const char ReprStr[]; + static const char VTKReprStr[]; typedef DataArrayInt32 ArrayType; typedef DataArrayInt32 ArrayTypeCh; typedef MEDCouplingFieldInt FieldType; @@ -91,6 +92,7 @@ namespace MEDCoupling static const char FieldTypeName[]; static const char NPYStr[]; static const char ReprStr[]; + static const char VTKReprStr[]; typedef DataArrayInt64 ArrayType; typedef DataArrayInt64 ArrayTypeCh; //typedef MEDCouplingFieldInt64 FieldType; -- 2.39.2