- C3d aggiornamento librerie ( 118044).
This commit is contained in:
SaraP
2025-08-28 14:47:28 +02:00
parent daccdfc398
commit f05795ffff
53 changed files with 1756 additions and 520 deletions
+132
View File
@@ -378,6 +378,138 @@ public:
}; //MbNurbsPointInfo
//------------------------------------------------------------------------------
/** \brief \ru Веса NURBS кривой.
\en Weights of a NURBS curve. \~
\details \ru Веса NURBS кривой.
\en Weights of a NURBS curve. \~
\ingroup Data_Structures
*/ // ---
class MATH_CLASS MbWeightVector {
private:
size_t m_count; ///< \ru Количество весов контрольных точек. \en A number of weights of the control points.
double m_commonWeight; ///< \ru Общий вес контрольных точек. \en A common weight of control points.
c3d::DoubleVector m_weights; ///< \ru Множество весов контрольных точек. \en Set of weights of the control points.
public:
/// \ru Конструктор по умолчанию. \en Default constructor.
MbWeightVector() : m_count( 0 ), m_commonWeight( UNDEFINED_DBL ), m_weights() {}
/// \ru Конструктор копирования. \en Copy-constructor.
MbWeightVector( const MbWeightVector & wv ) : m_count( wv.m_count ), m_commonWeight( wv.m_commonWeight ), m_weights( wv.m_weights ) {}
~MbWeightVector() {}
/// \ru Количество весов. \en Number of weights.
size_t Count() const { return m_count; }
/// \ru Общий вес? \en Is it used a common weight?
bool IsCommonWeight() const {
C3D_ASSERT( ( m_commonWeight != UNDEFINED_DBL ) == ( m_weights.size() < 1 ) );
return ( m_commonWeight != UNDEFINED_DBL );
}
/// \ru Инициализация по общему весу. \en Initialize by common weight.
bool InitWeights( double wt, size_t cnt ) {
ClearVector();
m_count = cnt;
m_commonWeight = wt;
return ( m_commonWeight > -MB_MAXDOUBLE && m_commonWeight < MB_MAXDOUBLE );
}
/// \ru Инициализация по массиву весов. \en Initialize by weights array.
template<class Vector>
bool InitWeights( const Vector & wts ) {
bool res = false;
m_count = wts.size();
m_commonWeight = UNDEFINED_DBL;
if ( CanAdjust(wts) ) {
m_commonWeight = wts[0];
ClearVector();
res = true;
}
else {
m_weights.assign( wts.begin(), wts.end() );
res = wts.size() > 0;
}
return res;
}
/// \ru Инициализация по вектору весов. \en Initialize by weights vector.
bool InitWeights( const MbWeightVector & wv ) {
m_count = wv.m_count;
m_commonWeight = wv.m_commonWeight;
m_weights = wv.m_weights;
return true;
}
/// \ru Получить веса. \en Get weights array.
template<class Vector>
void GetWeights( Vector & wts, bool clear = false ) const {
C3D_ASSERT( (m_commonWeight != UNDEFINED_DBL) == (m_weights.size() < 1) );
if ( clear )
wts.clear();
if ( m_commonWeight != UNDEFINED_DBL )
wts.resize( m_count + wts.size(), m_commonWeight);
else
std::copy( m_weights.begin(), m_weights.end(), std::back_inserter( wts ) );
}
/// \ru Установить веса. \en Get weights array.
template<class Vector>
bool SetWeights( const Vector & wts ) { return InitWeights( wts ); }
/// \ru Получить вес по индексу. \en Get weight by index.
double GetWeight( size_t index ) const { return index < m_weights.size() ? m_weights[index] : m_commonWeight; }
/// \ru Получить вес по индексу. Устаревшая функция, не рекомендуется к использованию.
/// \en Get weight by index. Deprecated function, not recommended for use.
DEPRECATE_DECLARE_REPLACE( SetWeight( size_t index, double wt ) )
double & SetWeight( size_t index );
/// \ru Установить вес по индексу. \en Set weight by index.
bool SetWeight( size_t index, double wt );
/// \ru Добавить вес. \en Add weight.
void AddWeight( double wt );
/// \ru Вставить вес. \en Insert weight.
void InsertWeight( size_t index, double wt );
/// \ru Удалить вес по индексу. \en Remove weight at index.
bool RemoveWeight( size_t index );
/// \ru Удалить группу весов в интервале [index1, index2). \en Remove group of weights in the [index1, index2) interval.
bool RemoveWeights( size_t index1, size_t index2 );
/// \ru Получить общий вес (использовать после проверки IsCommonWeight). \en Get common weight (to be used after checking IsCommonWeight).
double GetCommonWeight() const { return m_commonWeight; }
/// \ru Инвертировать веса. \en Reverse weights.
void Reverse() { if ( m_commonWeight == UNDEFINED_DBL ) std::reverse( m_weights.begin(), m_weights.end() ); }
/// \ru Сбросить данные. \en Flush data.
void FlushData() { m_count = 0; m_commonWeight = UNDEFINED_DBL; ClearVector(); }
/// \ru Можно ли оптимизировать расход памяти? \en Is it possible to adjust memory of weights array?
template<class Vector>
bool CanAdjust( const Vector & wts, double eps = DOUBLE_REGION ) const {
bool res = wts.size() > 0;
if ( res ) {
const double & w0 = wts[0];
for ( size_t i = 1; res && i < m_count; i++ )
res = ::fabs( wts[i] - w0 ) < eps;
}
return res;
}
/// \ru Оптимизировать расход памяти. \en Adjust memory of weights array.
bool Adjust( double eps = DOUBLE_REGION );
/// \ru Оператор присваивания. \en Assignment operator.
MbWeightVector & operator = ( const MbWeightVector & wv ) { InitWeights( wv ); return *this; }
/// \ru Оператор присваивания. \en Assignment operator.
template<class Vector>
MbWeightVector & operator = ( const Vector & wv ) { InitWeights( wv ); return *this; }
/// \ru Сравнение. \en Comparison.
bool IsSame( const MbWeightVector & wv, double eps ) const;
private:
bool FillVector();
void ClearVector();
MbWeightVector( const c3d::DoubleVector & wv ); // Запрещено.
MbWeightVector( const SArray<double> & wv ); // Запрещено.
};
//------------------------------------------------------------------------------
/** \brief \ru Дать меру расстояния.
\en Get a measure of the distance. \~