2017-08-01 12:30:58 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
///original version written by Erwin Coumans, October 2013
|
|
|
|
|
|
|
|
#ifndef BT_MATRIX_X_H
|
|
|
|
#define BT_MATRIX_X_H
|
|
|
|
|
|
|
|
#include "LinearMath/btQuickprof.h"
|
|
|
|
#include "LinearMath/btAlignedObjectArray.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
//#define BT_DEBUG_OSTREAM
|
|
|
|
#ifdef BT_DEBUG_OSTREAM
|
|
|
|
#include <iostream>
|
2019-01-03 13:26:51 +00:00
|
|
|
#include <iomanip> // std::setw
|
|
|
|
#endif //BT_DEBUG_OSTREAM
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
class btIntSortPredicate
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
public:
|
|
|
|
bool operator()(const int& a, const int& b) const
|
|
|
|
{
|
|
|
|
return a < b;
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct btVectorX
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btAlignedObjectArray<T> m_storage;
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
btVectorX()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
btVectorX(int numRows)
|
|
|
|
{
|
|
|
|
m_storage.resize(numRows);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
void resize(int rows)
|
|
|
|
{
|
|
|
|
m_storage.resize(rows);
|
|
|
|
}
|
|
|
|
int cols() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int rows() const
|
|
|
|
{
|
|
|
|
return m_storage.size();
|
|
|
|
}
|
|
|
|
int size() const
|
|
|
|
{
|
|
|
|
return rows();
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
T nrm2() const
|
|
|
|
{
|
|
|
|
T norm = T(0);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
int nn = rows();
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
if (nn == 1)
|
|
|
|
{
|
|
|
|
norm = btFabs((*this)[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
T scale = 0.0;
|
|
|
|
T ssq = 1.0;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
/* The following loop is equivalent to this call to the LAPACK
|
|
|
|
auxiliary routine: CALL SLASSQ( N, X, INCX, SCALE, SSQ ) */
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
for (int ix = 0; ix < nn; ix++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
if ((*this)[ix] != 0.0)
|
|
|
|
{
|
|
|
|
T absxi = btFabs((*this)[ix]);
|
|
|
|
if (scale < absxi)
|
|
|
|
{
|
|
|
|
T temp;
|
|
|
|
temp = scale / absxi;
|
|
|
|
ssq = ssq * (temp * temp) + BT_ONE;
|
|
|
|
scale = absxi;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
T temp;
|
|
|
|
temp = absxi / scale;
|
|
|
|
ssq += temp * temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
norm = scale * sqrt(ssq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return norm;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
void setZero()
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
if (m_storage.size())
|
|
|
|
{
|
|
|
|
// for (int i=0;i<m_storage.size();i++)
|
|
|
|
// m_storage[i]=0;
|
|
|
|
//memset(&m_storage[0],0,sizeof(T)*m_storage.size());
|
2019-01-03 13:26:51 +00:00
|
|
|
btSetZero(&m_storage[0], m_storage.size());
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
const T& operator[](int index) const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_storage[index];
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
T& operator[](int index)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_storage[index];
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
T* getBufferPointerWritable()
|
|
|
|
{
|
|
|
|
return m_storage.size() ? &m_storage[0] : 0;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
const T* getBufferPointer() const
|
|
|
|
{
|
|
|
|
return m_storage.size() ? &m_storage[0] : 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
template <typename T>
|
|
|
|
void setElem(btMatrixX<T>& mat, int row, int col, T val)
|
|
|
|
{
|
|
|
|
mat.setElem(row,col,val);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
template <typename T>
|
2017-08-01 12:30:58 +00:00
|
|
|
struct btMatrixX
|
|
|
|
{
|
|
|
|
int m_rows;
|
|
|
|
int m_cols;
|
|
|
|
int m_operations;
|
|
|
|
int m_resizeOperations;
|
|
|
|
int m_setElemOperations;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btAlignedObjectArray<T> m_storage;
|
|
|
|
mutable btAlignedObjectArray<btAlignedObjectArray<int> > m_rowNonZeroElements1;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
T* getBufferPointerWritable()
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_storage.size() ? &m_storage[0] : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const T* getBufferPointer() const
|
|
|
|
{
|
|
|
|
return m_storage.size() ? &m_storage[0] : 0;
|
|
|
|
}
|
|
|
|
btMatrixX()
|
2019-01-03 13:26:51 +00:00
|
|
|
: m_rows(0),
|
|
|
|
m_cols(0),
|
|
|
|
m_operations(0),
|
|
|
|
m_resizeOperations(0),
|
|
|
|
m_setElemOperations(0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
btMatrixX(int rows, int cols)
|
|
|
|
: m_rows(rows),
|
|
|
|
m_cols(cols),
|
|
|
|
m_operations(0),
|
|
|
|
m_resizeOperations(0),
|
|
|
|
m_setElemOperations(0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
resize(rows, cols);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
void resize(int rows, int cols)
|
|
|
|
{
|
|
|
|
m_resizeOperations++;
|
|
|
|
m_rows = rows;
|
|
|
|
m_cols = cols;
|
|
|
|
{
|
|
|
|
BT_PROFILE("m_storage.resize");
|
2019-01-03 13:26:51 +00:00
|
|
|
m_storage.resize(rows * cols);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int cols() const
|
|
|
|
{
|
|
|
|
return m_cols;
|
|
|
|
}
|
|
|
|
int rows() const
|
|
|
|
{
|
|
|
|
return m_rows;
|
|
|
|
}
|
|
|
|
///we don't want this read/write operator(), because we cannot keep track of non-zero elements, use setElem instead
|
|
|
|
/*T& operator() (int row,int col)
|
|
|
|
{
|
|
|
|
return m_storage[col*m_rows+row];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void addElem(int row, int col, T val)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
if (val)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (m_storage[col + row * m_cols] == 0.f)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
setElem(row, col, val);
|
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_storage[row * m_cols + col] += val;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
void setElem(int row, int col, T val)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_setElemOperations++;
|
2019-01-03 13:26:51 +00:00
|
|
|
m_storage[row * m_cols + col] = val;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
void mulElem(int row, int col, T val)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_setElemOperations++;
|
|
|
|
//mul doesn't change sparsity info
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
m_storage[row * m_cols + col] *= val;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
void copyLowerToUpperTriangle()
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
int count = 0;
|
|
|
|
for (int row = 0; row < rows(); row++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int col = 0; col < row; col++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
setElem(col, row, (*this)(row, col));
|
2017-08-01 12:30:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//printf("copyLowerToUpperTriangle copied %d elements out of %dx%d=%d\n", count,rows(),cols(),cols()*rows());
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
const T& operator()(int row, int col) const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
return m_storage[col + row * m_cols];
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setZero()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BT_PROFILE("storage=0");
|
2019-06-11 11:18:05 +00:00
|
|
|
if (m_storage.size())
|
|
|
|
{
|
|
|
|
btSetZero(&m_storage[0], m_storage.size());
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
//memset(&m_storage[0],0,sizeof(T)*m_storage.size());
|
|
|
|
//for (int i=0;i<m_storage.size();i++)
|
2019-01-03 13:26:51 +00:00
|
|
|
// m_storage[i]=0;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
void setIdentity()
|
|
|
|
{
|
|
|
|
btAssert(rows() == cols());
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
setZero();
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int row = 0; row < rows(); row++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
setElem(row, row, 1);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 11:18:05 +00:00
|
|
|
void printMatrix(const char* msg) const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
printf("%s ---------------------\n", msg);
|
|
|
|
for (int i = 0; i < rows(); i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
printf("\n");
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int j = 0; j < cols(); j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
printf("%2.1f\t", (*this)(i, j));
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n---------------------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void rowComputeNonZeroElements() const
|
|
|
|
{
|
|
|
|
m_rowNonZeroElements1.resize(rows());
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int i = 0; i < rows(); i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_rowNonZeroElements1[i].resize(0);
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int j = 0; j < cols(); j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if ((*this)(i, j) != 0.f)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_rowNonZeroElements1[i].push_back(j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
btMatrixX transpose() const
|
|
|
|
{
|
|
|
|
//transpose is optimized for sparse matrices
|
2019-01-03 13:26:51 +00:00
|
|
|
btMatrixX tr(m_cols, m_rows);
|
2017-08-01 12:30:58 +00:00
|
|
|
tr.setZero();
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int i = 0; i < m_cols; i++)
|
|
|
|
for (int j = 0; j < m_rows; j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
T v = (*this)(j, i);
|
2017-08-01 12:30:58 +00:00
|
|
|
if (v)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
tr.setElem(i, j, v);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
btMatrixX operator*(const btMatrixX& other)
|
|
|
|
{
|
|
|
|
//btMatrixX*btMatrixX implementation, brute force
|
|
|
|
btAssert(cols() == other.rows());
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
btMatrixX res(rows(), other.cols());
|
2017-08-01 12:30:58 +00:00
|
|
|
res.setZero();
|
2019-01-03 13:26:51 +00:00
|
|
|
// BT_PROFILE("btMatrixX mul");
|
|
|
|
for (int j = 0; j < res.cols(); ++j)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int i = 0; i < res.rows(); ++i)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
T dotProd = 0;
|
|
|
|
// T dotProd2=0;
|
2017-08-01 12:30:58 +00:00
|
|
|
//int waste=0,waste2=0;
|
|
|
|
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
// bool useOtherCol = true;
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int v = 0; v < rows(); v++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
T w = (*this)(i, v);
|
|
|
|
if (other(v, j) != 0.f)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
dotProd += w * other(v, j);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dotProd)
|
2019-01-03 13:26:51 +00:00
|
|
|
res.setElem(i, j, dotProd);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this assumes the 4th and 8th rows of B and C are zero.
|
2019-01-03 13:26:51 +00:00
|
|
|
void multiplyAdd2_p8r(const btScalar* B, const btScalar* C, int numRows, int numRowsOther, int row, int col)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btScalar* bb = B;
|
|
|
|
for (int i = 0; i < numRows; i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btScalar* cc = C;
|
|
|
|
for (int j = 0; j < numRowsOther; j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btScalar sum;
|
2019-01-03 13:26:51 +00:00
|
|
|
sum = bb[0] * cc[0];
|
|
|
|
sum += bb[1] * cc[1];
|
|
|
|
sum += bb[2] * cc[2];
|
|
|
|
sum += bb[4] * cc[4];
|
|
|
|
sum += bb[5] * cc[5];
|
|
|
|
sum += bb[6] * cc[6];
|
|
|
|
addElem(row + i, col + j, sum);
|
2017-08-01 12:30:58 +00:00
|
|
|
cc += 8;
|
|
|
|
}
|
|
|
|
bb += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void multiply2_p8r(const btScalar* B, const btScalar* C, int numRows, int numRowsOther, int row, int col)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btAssert(numRows > 0 && numRowsOther > 0 && B && C);
|
|
|
|
const btScalar* bb = B;
|
|
|
|
for (int i = 0; i < numRows; i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const btScalar* cc = C;
|
|
|
|
for (int j = 0; j < numRowsOther; j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
btScalar sum;
|
2019-01-03 13:26:51 +00:00
|
|
|
sum = bb[0] * cc[0];
|
|
|
|
sum += bb[1] * cc[1];
|
|
|
|
sum += bb[2] * cc[2];
|
|
|
|
sum += bb[4] * cc[4];
|
|
|
|
sum += bb[5] * cc[5];
|
|
|
|
sum += bb[6] * cc[6];
|
|
|
|
setElem(row + i, col + j, sum);
|
2017-08-01 12:30:58 +00:00
|
|
|
cc += 8;
|
|
|
|
}
|
|
|
|
bb += 8;
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
void setSubMatrix(int rowstart, int colstart, int rowend, int colend, const T value)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
int numRows = rowend + 1 - rowstart;
|
|
|
|
int numCols = colend + 1 - colstart;
|
|
|
|
|
|
|
|
for (int row = 0; row < numRows; row++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int col = 0; col < numCols; col++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
setElem(rowstart + row, colstart + col, value);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
void setSubMatrix(int rowstart, int colstart, int rowend, int colend, const btMatrixX& block)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btAssert(rowend + 1 - rowstart == block.rows());
|
|
|
|
btAssert(colend + 1 - colstart == block.cols());
|
|
|
|
for (int row = 0; row < block.rows(); row++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int col = 0; col < block.cols(); col++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
setElem(rowstart + row, colstart + col, block(row, col));
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
void setSubMatrix(int rowstart, int colstart, int rowend, int colend, const btVectorX<T>& block)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btAssert(rowend + 1 - rowstart == block.rows());
|
|
|
|
btAssert(colend + 1 - colstart == block.cols());
|
|
|
|
for (int row = 0; row < block.rows(); row++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int col = 0; col < block.cols(); col++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
setElem(rowstart + row, colstart + col, block[row]);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
btMatrixX negative()
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
btMatrixX neg(rows(), cols());
|
|
|
|
for (int i = 0; i < rows(); i++)
|
|
|
|
for (int j = 0; j < cols(); j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
T v = (*this)(i, j);
|
|
|
|
neg.setElem(i, j, -v);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
return neg;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef btMatrixX<float> btMatrixXf;
|
|
|
|
typedef btVectorX<float> btVectorXf;
|
|
|
|
|
|
|
|
typedef btMatrixX<double> btMatrixXd;
|
|
|
|
typedef btVectorX<double> btVectorXd;
|
|
|
|
|
|
|
|
#ifdef BT_DEBUG_OSTREAM
|
2019-01-03 13:26:51 +00:00
|
|
|
template <typename T>
|
|
|
|
std::ostream& operator<<(std::ostream& os, const btMatrixX<T>& mat)
|
|
|
|
{
|
|
|
|
os << " [";
|
|
|
|
//printf("%s ---------------------\n",msg);
|
|
|
|
for (int i = 0; i < mat.rows(); i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int j = 0; j < mat.cols(); j++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
os << std::setw(12) << mat(i, j);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
if (i != mat.rows() - 1)
|
|
|
|
os << std::endl
|
|
|
|
<< " ";
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
os << " ]";
|
|
|
|
//printf("\n---------------------\n");
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
std::ostream& operator<<(std::ostream& os, const btVectorX<T>& mat)
|
|
|
|
{
|
|
|
|
os << " [";
|
|
|
|
//printf("%s ---------------------\n",msg);
|
|
|
|
for (int i = 0; i < mat.rows(); i++)
|
|
|
|
{
|
|
|
|
os << std::setw(12) << mat[i];
|
|
|
|
if (i != mat.rows() - 1)
|
|
|
|
os << std::endl
|
|
|
|
<< " ";
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
os << " ]";
|
|
|
|
//printf("\n---------------------\n");
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
return os;
|
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //BT_DEBUG_OSTREAM
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
inline void setElem(btMatrixXd& mat, int row, int col, double val)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
mat.setElem(row, col, val);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void setElem(btMatrixXf& mat, int row, int col, float val)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
mat.setElem(row, col, val);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
2019-01-03 13:26:51 +00:00
|
|
|
#define btVectorXu btVectorXd
|
|
|
|
#define btMatrixXu btMatrixXd
|
2017-08-01 12:30:58 +00:00
|
|
|
#else
|
2019-01-03 13:26:51 +00:00
|
|
|
#define btVectorXu btVectorXf
|
|
|
|
#define btMatrixXu btMatrixXf
|
|
|
|
#endif //BT_USE_DOUBLE_PRECISION
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //BT_MATRIX_H_H
|