[DEV] update Basic element capabilities
This commit is contained in:
parent
033c9dd63a
commit
74a6e35fa3
122
etk/Vector.h
122
etk/Vector.h
@ -184,9 +184,9 @@ namespace etk
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
Iterator(Vector<MY_TYPE> * Evb, int32_t pos):
|
||||
Iterator(Vector<MY_TYPE> * obj, int32_t pos):
|
||||
m_current(pos),
|
||||
m_vector(Evb)
|
||||
m_vector(obj)
|
||||
{
|
||||
// nothing to do ...
|
||||
}
|
||||
@ -209,15 +209,14 @@ namespace etk
|
||||
{
|
||||
ChangeAllocation(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Re-copy constructor (copy all needed data)
|
||||
* @param[in] Evb Vector that might be copy
|
||||
*/
|
||||
Vector(const etk::Vector<MY_TYPE> & Evb)
|
||||
Vector(const etk::Vector<MY_TYPE> & obj)
|
||||
{
|
||||
m_allocated = Evb.m_allocated;
|
||||
m_size = Evb.m_size;
|
||||
m_allocated = obj.m_allocated;
|
||||
m_size = obj.m_size;
|
||||
m_data = NULL;
|
||||
//TK_DEBUG("USE Specific vector allocator ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment);
|
||||
// allocate all same data
|
||||
@ -229,10 +228,9 @@ namespace etk
|
||||
// Copy all data ...
|
||||
for(int32_t iii=0; iii<m_allocated; iii++) {
|
||||
// copy operator ...
|
||||
m_data[iii] = Evb.m_data[iii];
|
||||
m_data[iii] = obj.m_data[iii];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destructor of the current Class
|
||||
*/
|
||||
@ -245,24 +243,43 @@ namespace etk
|
||||
m_allocated = 0;
|
||||
m_size = 0;
|
||||
}
|
||||
/**
|
||||
* @brief Swap the data of 2 Vectors
|
||||
* @param[in] obj second vector to swap data.
|
||||
*/
|
||||
void Swap(etk::Vector<MY_TYPE>& obj)
|
||||
{
|
||||
// avoid Swap of itself
|
||||
if(this != &obj) {
|
||||
MY_TYPE* tmpData = m_data;
|
||||
int32_t tmpAllocated = m_allocated;
|
||||
int32_t tmpSize = m_size;
|
||||
m_data = obj.m_data;
|
||||
m_allocated = obj.m_allocated;
|
||||
m_size = obj.m_size;
|
||||
obj.m_data = tmpData;
|
||||
obj.m_allocated = tmpAllocated;
|
||||
obj.m_size = tmpSize;
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Re-copy operator
|
||||
* @param[in] Evb Vector that might be copy
|
||||
* @return reference on the curent re-copy vector
|
||||
*/
|
||||
Vector& operator=(const etk::Vector<MY_TYPE> & Evb)
|
||||
Vector& operator=(const etk::Vector<MY_TYPE> & obj)
|
||||
{
|
||||
//TK_DEBUG("USE RECOPY vector ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment);
|
||||
if( this != &Evb ) // avoid copy to itself
|
||||
if( this != &obj ) // avoid copy to itself
|
||||
{
|
||||
if (NULL!=m_data) {
|
||||
delete[] m_data;
|
||||
m_data = NULL;
|
||||
}
|
||||
// Set the new value
|
||||
m_allocated = Evb.m_allocated;
|
||||
m_size = Evb.m_size;
|
||||
m_allocated = obj.m_allocated;
|
||||
m_size = obj.m_size;
|
||||
// allocate all same data
|
||||
m_data = new MY_TYPE[m_allocated];
|
||||
if (NULL==m_data) {
|
||||
@ -271,7 +288,7 @@ namespace etk
|
||||
}
|
||||
for(int32_t iii=0; iii<m_allocated; iii++) {
|
||||
// copy operator ...
|
||||
m_data[iii] = Evb.m_data[iii];
|
||||
m_data[iii] = obj.m_data[iii];
|
||||
}
|
||||
}
|
||||
// Return the curent pointer
|
||||
@ -282,9 +299,9 @@ namespace etk
|
||||
* @brief Add at the Last position of the Vector
|
||||
* @param[in] item Element to add at the end of vector
|
||||
*/
|
||||
Vector& operator+= (const etk::Vector<MY_TYPE> & Evb) // += operator
|
||||
Vector& operator+= (const etk::Vector<MY_TYPE> & obj) // += operator
|
||||
{
|
||||
int32_t nbElememt = Evb.Size();
|
||||
int32_t nbElememt = obj.Size();
|
||||
int32_t idx = m_size;
|
||||
Resize(m_size+nbElememt);
|
||||
if (m_size<=idx) {
|
||||
@ -293,13 +310,11 @@ namespace etk
|
||||
}
|
||||
for(int32_t iii=0; iii<nbElememt; iii++) {
|
||||
// copy operator ...
|
||||
m_data[idx+iii] = Evb.m_data[iii];
|
||||
m_data[idx+iii] = obj.m_data[iii];
|
||||
}
|
||||
// Return the curent pointer
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the number of element in the vector
|
||||
* @return The number requested
|
||||
@ -308,7 +323,6 @@ namespace etk
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the number of element in the vector
|
||||
* @return The number requested
|
||||
@ -328,7 +342,6 @@ namespace etk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Allocated size in the vector
|
||||
* @return The size of allocation
|
||||
@ -337,7 +350,6 @@ namespace etk
|
||||
{
|
||||
return m_allocated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a current element in the vector
|
||||
* @param[in] pos Desired position read
|
||||
@ -354,7 +366,6 @@ namespace etk
|
||||
#endif
|
||||
return m_data[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an copy Element an a special position
|
||||
* @param[in] pos Position in the vector that might be get [0..Size()]
|
||||
@ -364,7 +375,6 @@ namespace etk
|
||||
{
|
||||
return Get(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an Element an a special position
|
||||
* @param[in] pos Position in the vector that might be get [0..Size()]
|
||||
@ -381,7 +391,6 @@ namespace etk
|
||||
#endif
|
||||
return m_data[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add at the Last position of the Vector
|
||||
* @param[in] item Element to add at the end of vector
|
||||
@ -396,7 +405,6 @@ namespace etk
|
||||
TK_ERROR("Resize does not work corectly ... not added item");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add at the Last position of the Vector
|
||||
* @param[in] item Element to add at the end of vector
|
||||
@ -416,7 +424,6 @@ namespace etk
|
||||
m_data[idx+iii] = item[iii];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove the last element of the vector
|
||||
*/
|
||||
@ -426,7 +433,6 @@ namespace etk
|
||||
Resize(m_size-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove all alement in the current vector
|
||||
*/
|
||||
@ -436,15 +442,11 @@ namespace etk
|
||||
Resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in,out] ---
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
* @brief Insert N element in the Vector.
|
||||
* @param[in] pos Position to add the elements.
|
||||
* @param[in] item Pointer on a table of the elements to add.
|
||||
* @param[in] nbElement Number of element to add in the Vector
|
||||
*/
|
||||
void Insert(int32_t pos, const MY_TYPE * item, int32_t nbElement)
|
||||
{
|
||||
@ -472,28 +474,19 @@ namespace etk
|
||||
m_data[pos+iii] = item[iii];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in,out] ---
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
* @brief Insert one element in the Vector at a specific position
|
||||
* @param[in] pos Position to add the elements.
|
||||
* @param[in] item Element to add.
|
||||
*/
|
||||
void Insert(int32_t pos, const MY_TYPE& item)
|
||||
{
|
||||
Insert(pos, &item, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove N element
|
||||
*
|
||||
* @param[in] pos Position to remove the data
|
||||
* @param[in] nbElement number of element to remove
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
void EraseLen(int32_t pos, int32_t nbElement)
|
||||
{
|
||||
@ -515,28 +508,26 @@ namespace etk
|
||||
// Request resize of the current buffer
|
||||
Resize(m_size-nbElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove one element
|
||||
*
|
||||
* @param[in] pos Position to remove the data
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
void Erase(int32_t pos)
|
||||
inline void Erase(int32_t pos)
|
||||
{
|
||||
EraseLen(pos, 1);
|
||||
}
|
||||
/**
|
||||
* @brief Remove one element
|
||||
* @param[in] pos Position to remove the data
|
||||
*/
|
||||
inline void Remove(int32_t pos)
|
||||
{
|
||||
EraseLen(pos, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove N elements
|
||||
*
|
||||
* @param[in] pos Position to remove the data
|
||||
* @param[in] posEnd Last position number
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
void Erase(int32_t pos, int32_t posEnd)
|
||||
{
|
||||
@ -559,8 +550,6 @@ namespace etk
|
||||
// Request resize of the current buffer
|
||||
Resize(m_size-nbElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief extract data between two point :
|
||||
* @param[in] posStart start position to extract data
|
||||
@ -583,7 +572,14 @@ namespace etk
|
||||
out.PushBack(&m_data[posStart], posEnd-posStart);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the pointer on the sata
|
||||
* @return the type pointer on data
|
||||
*/
|
||||
MY_TYPE* DataPointer(void)
|
||||
{
|
||||
return &m_data[0];
|
||||
}
|
||||
/**
|
||||
* @brief Get an iterator an an specific position
|
||||
* @param[in] pos Requested position of the iterator in the vector
|
||||
@ -593,7 +589,6 @@ namespace etk
|
||||
{
|
||||
return Iterator(this, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an Iterator on the start position of the Vector
|
||||
* @return The Iterator
|
||||
@ -602,7 +597,6 @@ namespace etk
|
||||
{
|
||||
return Position(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an Iterator on the end position of the Vector
|
||||
* @return The Iterator
|
||||
@ -611,7 +605,6 @@ namespace etk
|
||||
{
|
||||
return Position( Size()-1 );
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Change the current size of the vector
|
||||
@ -625,7 +618,6 @@ namespace etk
|
||||
}
|
||||
m_size = newSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Change the current allocation to the corect one (depend on the current size)
|
||||
* @param[in] newSize Minimum number of element needed
|
||||
|
@ -252,6 +252,15 @@ namespace etk
|
||||
T& operator () (int32_t line, int32_t colomn) {
|
||||
return m_data[line*m_size.x + colomn];
|
||||
}
|
||||
/*****************************************************
|
||||
* - operator
|
||||
*****************************************************/
|
||||
Matrix<T> operator - (void) {
|
||||
Matrix<T> tmp(m_size);
|
||||
for (int32_t iii=0; iii<m_data.Size(); iii++) {
|
||||
tmp.m_data[iii] = -m_data[iii];
|
||||
return tmp;
|
||||
}
|
||||
/*****************************************************
|
||||
* Other mathematical function
|
||||
*****************************************************/
|
||||
@ -265,7 +274,7 @@ namespace etk
|
||||
Matrix<T> tmpMatrix(m_size.x, m_size.y);
|
||||
for (int32_t jjj=0; jjj< m_size.y; jjj++) {
|
||||
for (int32_t iii=0; iii< m_size.x; iii++) {
|
||||
tmpMatrix[jjj][iii] = (*this)[iii][jjj];
|
||||
tmpMatrix(jjj,iii) = (*this)(iii,jjj);
|
||||
}
|
||||
}
|
||||
return tmpMatrix;
|
||||
@ -275,7 +284,7 @@ namespace etk
|
||||
* @ param[in] obj The convolution operator
|
||||
* @ return the value of the convolution
|
||||
*/
|
||||
Matrix<T> Convolution(Matrix<T>& obj)
|
||||
Matrix<T>& Convolution(Matrix<T>& obj)
|
||||
{
|
||||
Matrix<T> tmppp(1,1);
|
||||
// TODO : ...
|
||||
@ -288,8 +297,18 @@ namespace etk
|
||||
*/
|
||||
Matrix<T>& Fix(int32_t decalage)
|
||||
{
|
||||
Matrix<T> tmppp(1,1);
|
||||
// TODO : ...
|
||||
Matrix<T> tmppp(m_size);
|
||||
T tmpVal = 0;
|
||||
for(int32_t iii=0; iii<m_data.Size(); iii++) {
|
||||
tmpVal = m_data[iii];
|
||||
if (tmpVal < 0 && (tmpVal & ~(~0 << decalage))) {
|
||||
tmpVal = tmpVal >> decalage;
|
||||
tmpVal++;
|
||||
} else {
|
||||
tmpVal = tmpVal >> decalage;
|
||||
}
|
||||
tmppp.m_data[iii] = tmpVal;
|
||||
}
|
||||
return tmppp;
|
||||
};
|
||||
/**
|
||||
@ -297,16 +316,136 @@ namespace etk
|
||||
* @ param[in] decalage The power of 2 of the division
|
||||
* @ return the result
|
||||
*/
|
||||
Matrix<T>& Round2(int32_t decalage)
|
||||
Matrix<T>& Round(int32_t decalage)
|
||||
{
|
||||
Matrix<T> tmppp(1,1);
|
||||
// TODO : ...
|
||||
Matrix<T> tmppp(m_size);
|
||||
for(int32_t iii=0; iii<m_data.Size(); iii++) {
|
||||
tmppp.m_data[iii] = ( m_data[iii]+(1<<(decalage-1)) ) >> decalage;
|
||||
}
|
||||
return tmppp;
|
||||
};
|
||||
/**
|
||||
* @ brief Generate a resised matrix
|
||||
* @ param[in] size new output size
|
||||
* @ return Te resied matrix
|
||||
*/
|
||||
Matrix<T>& Resize(etk::Vector2D<int32_t> size)
|
||||
{
|
||||
Matrix<T> tmppp(size);
|
||||
for(int32_t iii=0; iii<m_data.m_size.x && iii<tmppp.m_size.x; iii++) {
|
||||
for(int32_t jjj=0; jjj<m_data.m_size.y && jjj<tmppp.m_size.y; jjj++) {
|
||||
tmppp(iii,jjj) = (*this)(iii,jjj);
|
||||
}
|
||||
}
|
||||
return tmppp;
|
||||
};
|
||||
/**
|
||||
* @brief Select element in the matrix from a list of element Ids
|
||||
* @param[in] np Width of the output matrix
|
||||
* @param[in] p List pointer of x
|
||||
* @param[in] np Heigh of the output matrix
|
||||
* @param[in] q List pointer of y
|
||||
* @return the new matrix
|
||||
*/
|
||||
Matrix<T>& Select(int32_t np, int32_t *p, int32_t nq, int32_t *q)
|
||||
{
|
||||
if (np < 1 || nq < 1) {
|
||||
TK_WARNING("bad index array sizes");
|
||||
}
|
||||
Matrix<T> tmppp(np,nq);
|
||||
for (int32_t iii=0; iii<np; iii++) {
|
||||
for (int32_t jjj=0; jjj<nq; jjj++) {
|
||||
if( p[i] < 0
|
||||
|| p[i] >= m_size.x
|
||||
|| q[i] < 0
|
||||
|| q[i] >= m_size.y) {
|
||||
TK_WARNING("bad index arrays");
|
||||
}
|
||||
tmppp(iii,jjj) = (*this)(p[i],q[j]);
|
||||
}
|
||||
}
|
||||
return tmppp;
|
||||
}
|
||||
/*****************************************************
|
||||
* other stupid action :
|
||||
* utilities :
|
||||
*****************************************************/
|
||||
Vector2D<int32_t> Size(void) { return m_size; };
|
||||
/**
|
||||
* @brief Clear the Upper triangle of the current Matrix
|
||||
* <pre>
|
||||
* x 0 0 0 0
|
||||
* x x 0 0 0
|
||||
* x x x 0 0
|
||||
* x x x x 0
|
||||
* x x x x x
|
||||
* </pre>
|
||||
*/
|
||||
void ClearUpperTriangle(void)
|
||||
{
|
||||
if (m_size.x != m_size.y) {
|
||||
TK_WARNING("better to do with square Matrix");
|
||||
}
|
||||
for (int32_t iii=0; iii<m_size.x; iii++) {
|
||||
for (int32_t jjj=iii+1; jjj<m_size.y; jjj++)
|
||||
m_data[iii*m_size.x + jjj] = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Clear the Lower triangle of the current Matrix
|
||||
* <pre>
|
||||
* x x x x x
|
||||
* 0 x x x x
|
||||
* 0 0 x x x
|
||||
* 0 0 0 x x
|
||||
* 0 0 0 0 x
|
||||
* </pre>
|
||||
*/
|
||||
void ClearLowerTriangle(void)
|
||||
{
|
||||
if (m_size.x != m_size.y) {
|
||||
TK_WARNING("better to do with square Matrix");
|
||||
}
|
||||
for (int32_t iii=0; iii<m_size.x; iii++) {
|
||||
for (int32_t jjj=0; jjj<m_size.y && jjj<iii; jjj++)
|
||||
m_data[iii*m_size.x + jjj] = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Generate a compleate random Matrix.
|
||||
* @param[in] range The min/max value of the random Generation [-range..range].
|
||||
*/
|
||||
void MakeRandom(float range)
|
||||
{
|
||||
for(int32_t iii=0; iii<m_data.Size(); iii++) {
|
||||
m_data[iii] = (T)etk::tool::frand(-range, range);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Return the maximum of the diff for this Matrix.
|
||||
* @param[in] input The compared Matix.
|
||||
* @return The absolute max value.
|
||||
*/
|
||||
T MaxDifference(const Matrix<T>& input)
|
||||
{
|
||||
if (m_size != input.m_size)
|
||||
TK_WARNING("better to do with same size Matrix");
|
||||
}
|
||||
T max = 0;
|
||||
for(int32_t iii=0; iii<m_data.Size() && iii<input.m_data.Size(); iii++) {
|
||||
T diff = m_data[iii] - input.m_data[iii];
|
||||
if (diff<0) {
|
||||
diff = -diff;
|
||||
}
|
||||
if (diff > max)
|
||||
max = diff;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
};
|
||||
/**
|
||||
* @brief Clear all the matrix.
|
||||
*/
|
||||
void Clear(void)
|
||||
{
|
||||
// copy data for the same size :
|
||||
@ -314,46 +453,31 @@ namespace etk
|
||||
m_data[iii] = (T)0;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Set the diagonal at 1
|
||||
*/
|
||||
void Identity(void)
|
||||
{
|
||||
// copy data for the same size :
|
||||
for (int32_t iii=0; iii< etk_min(m_size.x, m_size.y); iii++) {
|
||||
(*this)[iii][iii] = (T)1;
|
||||
(*this)(iii,iii) = (T)1;
|
||||
}
|
||||
};
|
||||
|
||||
void Set(int32_t iii, int32_t jjj, T value)
|
||||
{
|
||||
m_data[iii*m_size.x+jjj] = value;
|
||||
}
|
||||
T Get(int32_t iii, int32_t jjj)
|
||||
{
|
||||
return m_data[iii*m_size.x+jjj];
|
||||
}
|
||||
void Display(void)
|
||||
{
|
||||
/*
|
||||
TK_INFO("Matrix display : ");
|
||||
for (int32_t jjj=0; jjj< m_size.y; jjj++) {
|
||||
if (m_size.x == 0) {
|
||||
TK_INFO(" --- , ");
|
||||
} else if (m_size.x == 1) {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , ");
|
||||
} else if (m_size.x == 2) {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , " << (*this)[jjj][1] << " , ");
|
||||
} else if (m_size.x == 3) {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , " << (*this)[jjj][1] << " , " << (*this)[jjj][2] << " , ");
|
||||
} else if (m_size.x == 4) {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , " << (*this)[jjj][1] << " , " << (*this)[jjj][2] << " , " << (*this)[jjj][3] << " , ");
|
||||
} else if (m_size.x == 5) {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , " << (*this)[jjj][1] << " , " << (*this)[jjj][2] << " , " << (*this)[jjj][3] << " , " << (*this)[jjj][4] << " , ");
|
||||
} else if (m_size.x == 6) {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , " << (*this)[jjj][1] << " , " << (*this)[jjj][2] << " , " << (*this)[jjj][3] << " , " << (*this)[jjj][4] << " , " << (*this)[jjj][5] << " , ");
|
||||
} else {
|
||||
TK_INFO(" " << (*this)[jjj][0] << " , " << (*this)[jjj][1] << " , " << (*this)[jjj][2] << " , " << (*this)[jjj][3] << " , " << (*this)[jjj][4] << " , " << (*this)[jjj][5] << " , " << (*this)[jjj][6] << " , ");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Clear and set the diagonal at 1
|
||||
*/
|
||||
void Eye(void)
|
||||
{
|
||||
Clear();
|
||||
Identity();
|
||||
};
|
||||
/**
|
||||
* @brief Get the size of the current Matrix.
|
||||
* @return Dimention of the matrix
|
||||
*/
|
||||
Vector2D<int32_t> Size(void)
|
||||
{
|
||||
return m_size;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user