本文整理汇总了C++中eigen::Matrix::data方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::data方法的具体用法?C++ Matrix::data怎么用?C++ Matrix::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Matrix
的用法示例。
在下文中一共展示了Matrix::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRawDataAcces
bool testRawDataAcces() {
bool passed = true;
Eigen::Matrix<Scalar, 4, 1> raw = {0, 1, 0, 0};
Eigen::Map<RxSO3Type const> map_of_const_rxso3(raw.data());
SOPHUS_TEST_APPROX(passed, map_of_const_rxso3.quaternion().coeffs().eval(),
raw, Constants<Scalar>::epsilon());
SOPHUS_TEST_EQUAL(passed, map_of_const_rxso3.quaternion().coeffs().data(),
raw.data());
Eigen::Map<RxSO3Type const> const_shallow_copy = map_of_const_rxso3;
SOPHUS_TEST_EQUAL(passed, const_shallow_copy.quaternion().coeffs().eval(),
map_of_const_rxso3.quaternion().coeffs().eval());
Eigen::Matrix<Scalar, 4, 1> raw2 = {1, 0, 0, 0};
Eigen::Map<RxSO3Type> map_of_rxso3(raw.data());
Eigen::Quaternion<Scalar> quat;
quat.coeffs() = raw2;
map_of_rxso3.setQuaternion(quat);
SOPHUS_TEST_APPROX(passed, map_of_rxso3.quaternion().coeffs().eval(), raw2,
Constants<Scalar>::epsilon());
SOPHUS_TEST_EQUAL(passed, map_of_rxso3.quaternion().coeffs().data(),
raw.data());
SOPHUS_TEST_NEQ(passed, map_of_rxso3.quaternion().coeffs().data(),
quat.coeffs().data());
Eigen::Map<RxSO3Type> shallow_copy = map_of_rxso3;
SOPHUS_TEST_EQUAL(passed, shallow_copy.quaternion().coeffs().eval(),
map_of_rxso3.quaternion().coeffs().eval());
RxSO3Type const const_so3(quat);
for (int i = 0; i < 4; ++i) {
SOPHUS_TEST_EQUAL(passed, const_so3.data()[i], raw2.data()[i]);
}
RxSO3Type so3(quat);
for (int i = 0; i < 4; ++i) {
so3.data()[i] = raw[i];
}
for (int i = 0; i < 4; ++i) {
SOPHUS_TEST_EQUAL(passed, so3.data()[i], raw.data()[i]);
}
for (int i = 0; i < 10; ++i) {
Matrix3<Scalar> M = Matrix3<Scalar>::Random();
for (Scalar scale : {Scalar(0.01), Scalar(0.99), Scalar(1), Scalar(10)}) {
Matrix3<Scalar> R = makeRotationMatrix(M);
Matrix3<Scalar> sR = scale * R;
SOPHUS_TEST(passed, isScaledOrthogonalAndPositive(sR),
"isScaledOrthogonalAndPositive(sR): % *\n%", scale, R);
Matrix3<Scalar> sR_cols_swapped;
sR_cols_swapped << sR.col(1), sR.col(0), sR.col(2);
SOPHUS_TEST(passed, !isScaledOrthogonalAndPositive(sR_cols_swapped),
"isScaledOrthogonalAndPositive(-sR): % *\n%", scale, R);
}
}
return passed;
}
示例2: cv2eigen
void cv2eigen( const Mat& src,
Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
{
CV_DbgAssert(src.rows == _rows && src.cols == _cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
if( src.type() == _dst.type() )
transpose(src, _dst);
else if( src.cols == src.rows )
{
src.convertTo(_dst, _dst.type());
transpose(_dst, _dst);
}
else
Mat(src.t()).convertTo(_dst, _dst.type());
CV_DbgAssert(_dst.data == (uchar*)dst.data());
}
else
{
Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type());
CV_DbgAssert(_dst.data == (uchar*)dst.data());
}
}
示例3: cv2eigen
template<typename _Tp> static inline
void cv2eigen( const Mat& src,
Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
{
dst.resize(src.rows, src.cols);
if( !(dst.Flags & Eigen::RowMajorBit) )
{
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
if( src.type() == _dst.type() )
transpose(src, _dst);
else if( src.cols == src.rows )
{
src.convertTo(_dst, _dst.type());
transpose(_dst, _dst);
}
else
Mat(src.t()).convertTo(_dst, _dst.type());
}
else
{
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type());
}
}
示例4: create_vector_vbo
IGL_INLINE void igl::create_vector_vbo(
const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & V,
GLuint & V_vbo_id)
{
//// Expects that input is list of 3D vectors along rows
//assert(V.cols() == 3);
// Generate Buffers
glGenBuffers(1,&V_vbo_id);
// Bind Buffers
glBindBuffer(GL_ARRAY_BUFFER,V_vbo_id);
// Copy data to buffers
// We expect a matrix with each vertex position on a row, we then want to
// pass this data to OpenGL reading across rows (row-major)
if(V.Options & Eigen::RowMajor)
{
glBufferData(
GL_ARRAY_BUFFER,
sizeof(T)*V.size(),
V.data(),
GL_STATIC_DRAW);
}else
{
// Create temporary copy of transpose
Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> VT = V.transpose();
// If its column major then we need to temporarily store a transpose
glBufferData(
GL_ARRAY_BUFFER,
sizeof(T)*V.size(),
VT.data(),
GL_STATIC_DRAW);
}
// bind with 0, so, switch back to normal pointer operation
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
示例5: Evaluate
bool ReprojectionErrorFixed::Evaluate(double const* const* args,
double* residuals,
double** jac) const
{
double newPoint[3];
double rotationVec[3];
const double * const landmark = args[0];
Vector3d X(landmark);
X = RcamBase*(RbaseOrig*X + PbaseOrig) + PcamBase;
Vector2d point;
camera->projectPoint(X, point);
residuals[0] = point[0] - u;
residuals[1] = point[1] - v;
if (jac)
{
Eigen::Matrix<double, 2, 3> J;
camera->projectionJacobian(X, J);
// dp / dX
Eigen::Matrix<double, 2, 3, RowMajor> dpdX = J * RcamBase * RbaseOrig;
copy(dpdX.data(), dpdX.data() + 6, jac[0]);
}
return true;
}
示例6: temp_r
// dynVCLVec(viennacl::vector_range<viennacl::vector_base<T> > vec, int ctx_id){
// viennacl::context ctx;
//
// // explicitly pull context for thread safe forking
// ctx = viennacl::context(viennacl::ocl::get_context(static_cast<long>(ctx_id)));
//
// A.switch_memory_context(ctx);
// A = vec;
//
// size = A.size();
// begin = 1;
// last = size;
// ptr = &A;
// viennacl::range temp_r(0, size);
// r = temp_r;
// }
dynVCLVec(SEXP A_, int ctx_id) {
#ifdef UNDEF
Eigen::Matrix<T, Eigen::Dynamic, 1> Am;
Am = Rcpp::as<Eigen::Matrix<T, Eigen::Dynamic, 1> >(A_);
int K = Am.size();
viennacl::context ctx;
// explicitly pull context for thread safe forking
ctx = viennacl::context(viennacl::ocl::get_context(static_cast<long>(ctx_id)));
// std::cout << "about to initialize" << std::endl;
viennacl::vector_base<T> A = viennacl::vector_base<T>(K, ctx);
// std::cout << "initialized vector" << std::endl;
viennacl::fast_copy(Am.data(), Am.data() + Am.size(), A.begin());
// viennacl::fast_copy(Am.begin(), Am.end(), A.begin());
// std::cout << "copied" << std::endl;
size = A.size();
begin = 1;
last = size;
// ptr = &A;
viennacl::range temp_r(0, size);
r = temp_r;
shared = false;
shared_type = 0;
shptr = std::make_shared<viennacl::vector_base<T> >(A);
#endif
}
示例7: handleSimulation
void SetTwistHandler::handleSimulation(){
// called when the main script calls: simHandleModule
if(!_initialized){
_initialize();
}
Eigen::Quaternion < simFloat > orientation; //(x,y,z,w)
Eigen::Matrix< simFloat, 3, 1> linVelocity((simFloat)_twistCommands.twist.linear.x,
(simFloat)_twistCommands.twist.linear.y,
(simFloat)_twistCommands.twist.linear.z);
Eigen::Matrix< simFloat, 3, 1> angVelocity((simFloat)_twistCommands.twist.angular.x,
(simFloat)_twistCommands.twist.angular.y,
(simFloat)_twistCommands.twist.angular.z);
// Input velocity is expected to be in body frame but V-Rep expects it to be in world frame.
if(simGetObjectQuaternion(_associatedObjectID, -1, orientation.coeffs().data())!=-1){
linVelocity = orientation*linVelocity;
angVelocity = orientation*angVelocity;
} else {
std::stringstream ss;
ss << "- [" << _associatedObjectName << "] Error getting orientation. " << std::endl;
ConsoleHandler::printInConsole(ss);
}
simResetDynamicObject(_associatedObjectID);
//Set object velocity
if (_isStatic){
Eigen::Matrix<simFloat, 3, 1> position;
simGetObjectPosition(_associatedObjectID, -1, position.data());
const simFloat timeStep = simGetSimulationTimeStep();
position = position + timeStep*linVelocity;
simSetObjectPosition(_associatedObjectID, -1, position.data());
const simFloat angle = timeStep*angVelocity.norm();
if(angle > 1e-6){
orientation = Eigen::Quaternion< simFloat >(Eigen::AngleAxis< simFloat >(timeStep*angVelocity.norm(), angVelocity/angVelocity.norm()))*orientation;
}
simSetObjectQuaternion(_associatedObjectID, -1, orientation.coeffs().data());
} else {
// Apply the linear velocity to the object
if(simSetObjectFloatParameter(_associatedObjectID, 3000, linVelocity[0])
&& simSetObjectFloatParameter(_associatedObjectID, 3001, linVelocity[1])
&& simSetObjectFloatParameter(_associatedObjectID, 3002, linVelocity[2])==-1) {
std::stringstream ss;
ss << "- [" << _associatedObjectName << "] Error setting linear velocity. " << std::endl;;
ConsoleHandler::printInConsole(ss);
}
// Apply the angular velocity to the object
if(simSetObjectFloatParameter(_associatedObjectID, 3020, angVelocity[0])
&& simSetObjectFloatParameter(_associatedObjectID, 3021, angVelocity[1])
&& simSetObjectFloatParameter(_associatedObjectID, 3022, angVelocity[2])==-1) {
std::stringstream ss;
ss << "- [" << _associatedObjectName << "] Error setting angular velocity. " << std::endl;;
ConsoleHandler::printInConsole(ss);
}
}
}
示例8: handleSimulation
void GetTwistHandler::handleSimulation(){
// called when the main script calls: simHandleModule
if(!_initialized){
_initialize();
}
ros::Time now = ros::Time::now();
const simFloat currentSimulationTime = simGetSimulationTime();
if ((currentSimulationTime-_lastPublishedObjTwistTime) >= 1.0/_ObjTwistFrequency){
Eigen::Quaternion< simFloat > orientation; //(x,y,z,w)
Eigen::Matrix<simFloat, 3, 1> linVelocity;
Eigen::Matrix<simFloat, 3, 1> angVelocity;
bool error = false;
// Get object velocity. If the object is not static simGetVelocity is more accurate.
if (_isStatic){
error = error || simGetObjectVelocity(_associatedObjectID, linVelocity.data(), angVelocity.data()) == -1;
} else {
error = error || simGetVelocity(_associatedObjectID, linVelocity.data(), angVelocity.data()) == -1;
}
// Get object orientation
error = error || simGetObjectQuaternion(_associatedObjectID, -1, orientation.coeffs().data()) == -1;
if(!error){
linVelocity = orientation.conjugate()*linVelocity; // Express linear velocity in body frame
angVelocity = orientation.conjugate()*angVelocity; // Express angular velocity in body frame
// Fill the status msg
geometry_msgs::TwistStamped msg;
msg.twist.linear.x = linVelocity[0];
msg.twist.linear.y = linVelocity[1];
msg.twist.linear.z = linVelocity[2];
msg.twist.angular.x = angVelocity[0];
msg.twist.angular.y = angVelocity[1];
msg.twist.angular.z = angVelocity[2];
msg.header.stamp = now;
_pub.publish(msg);
_lastPublishedObjTwistTime = currentSimulationTime;
} else {
std::stringstream ss;
ss << "- [" << _associatedObjectName << "] Error getting object velocity and/or orientation." << std::endl;;
ConsoleHandler::printInConsole(ss);
}
}
}
示例9: normalizeContrast
void NNUtilities::normalizeContrast(OutType* output, const Vector2i size, const float percent)
{
Eigen::Map<Eigen::Matrix<OutType, Eigen::Dynamic, Eigen::Dynamic>> patch(output, size.x(), size.y());
Eigen::Matrix<OutType, Eigen::Dynamic, 1> sorted = Eigen::Map<Eigen::Matrix<OutType, Eigen::Dynamic, 1>>(patch.data(), size.x() * size.y());
std::sort(sorted.data(), sorted.data() + sorted.size());
OutType min = sorted(static_cast<int>((sorted.size() - 1) * percent));
OutType max = sorted(static_cast<int>((sorted.size() - 1) * (1.f - percent)));
if(max == 0)
patch.setConstant(0);
else
patch.array() = ((patch.array().max(min).min(max) - min).template cast<float>() * 255.f / (static_cast<float>(max - min))).template cast<OutType>();
}
示例10: eigen2cv
// Matx case
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
Matx<_Tp, _rows, _cols>& dst )
{
if( !(src.Flags & Eigen::RowMajorBit) )
{
dst = Matx<_Tp, _cols, _rows>(static_cast<const _Tp*>(src.data())).t();
}
else
{
dst = Matx<_Tp, _rows, _cols>(static_cast<const _Tp*>(src.data()));
}
}
示例11: temp_cloud
void grouped_vocabulary_tree<Point, K>::set_input_cloud(CloudPtrT& new_cloud, vector<pair<int, int> >& indices)
{
// to begin with, we might have to remove nan points
Eigen::Matrix<float, super::rows, 1> p;
CloudPtrT temp_cloud(new CloudT);
temp_cloud->reserve(new_cloud->size());
vector<pair<int, int> > temp_indices;
temp_indices.reserve(indices.size());
for (size_t i = 0; i < new_cloud->size(); ++i) {
p = eig(new_cloud->at(i));
if (std::find_if(p.data(), p.data()+super::rows, [] (float f) {
return std::isnan(f) || std::isinf(f);
}) == p.data()+super::rows) {
temp_cloud->push_back(new_cloud->at(i));
temp_indices.push_back(indices[i]);
}
}
cout << "Temp cloud size: " << temp_cloud->size() << endl;
cout << "Indices size: " << temp_indices.size() << endl;
//std::sort(temp_indices.begin(), temp_indices.end(), [](const pair<int, int>& p1, const pair<int, int>& p2) {
// return p1.first < p2.first && p1.second < p2.second;
//});
vector<int> new_indices(temp_indices.size());
pair<int, int> previous_p = make_pair(-1, -1);
int index_group_ind = -1;
int counter = 0;
for (const pair<int, int>& p : temp_indices) {
// everything with this index pair should have the same label, assume ordered
if (p != previous_p) {
++index_group_ind;
index_group[index_group_ind] = p.first; // these two really should be vectors instead
group_subgroup[index_group_ind] = p;
previous_p = p;
}
new_indices[counter] = index_group_ind;
++counter;
}
nbr_points = counter;
nbr_groups = index_group_ind + 1;
cout << "New indices size: " << temp_indices.size() << endl;
super::set_input_cloud(temp_cloud, new_indices);
}
示例12: eigen2cv
void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
{
if( !(src.Flags & Eigen::RowMajorBit) )
{
Mat _src(src.cols(), src.rows(), DataType<_Tp>::type,
(void*)src.data(), src.stride()*sizeof(_Tp));
transpose(_src, dst);
}
else
{
Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
(void*)src.data(), src.stride()*sizeof(_Tp));
_src.copyTo(dst);
}
}
示例13: extractRTFromBuffer
void CCubicGrids::extractRTFromBuffer(const cuda::GpuMat& cvgmSumBuf_, Eigen::Matrix3f* peimRw_, Eigen::Vector3f* peivTw_) const{
Mat cvmSumBuf;
cvgmSumBuf_.download(cvmSumBuf);
double* aHostTmp = (double*)cvmSumBuf.data;
//declare A and b
Eigen::Matrix<double, 6, 6, Eigen::RowMajor> A;
Eigen::Matrix<double, 6, 1> b;
//retrieve A and b from cvmSumBuf
short sShift = 0;
for (int i = 0; i < 6; ++i){ // rows
for (int j = i; j < 7; ++j) { // cols + b
double value = aHostTmp[sShift++];
if (j == 6) // vector b
b.data()[i] = value;
else
A.data()[j * 6 + i] = A.data()[i * 6 + j] = value;
}//for each col
}//for each row
//checking nullspace
double dDet = A.determinant();
if (fabs(dDet) < 1e-15 || dDet != dDet){
if (dDet != dDet)
PRINTSTR("Failure -- dDet cannot be qnan. ");
//reset ();
return;
}//if dDet is rational
//float maxc = A.maxCoeff();
Eigen::Matrix<float, 6, 1> result = A.llt().solve(b).cast<float>();
//Eigen::Matrix<float, 6, 1> result = A.jacobiSvd(ComputeThinU | ComputeThinV).solve(b);
float alpha = result(0);
float beta = result(1);
float gamma = result(2);
Eigen::Matrix3f Rinc = (Eigen::Matrix3f)Eigen::AngleAxisf(gamma, Eigen::Vector3f::UnitZ()) * Eigen::AngleAxisf(beta, Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(alpha, Eigen::Vector3f::UnitX());
Eigen::Vector3f tinc = result.tail<3>();
//compose
//eivTwCur = Rinc * eivTwCur + tinc;
//eimrmRwCur = Rinc * eimrmRwCur;
Eigen::Vector3f eivTinv = -peimRw_->transpose()* (*peivTw_);
Eigen::Matrix3f eimRinv = peimRw_->transpose();
eivTinv = Rinc * eivTinv + tinc;
eimRinv = Rinc * eimRinv;
*peivTw_ = -eimRinv.transpose() * eivTinv;
*peimRw_ = eimRinv.transpose();
}
示例14: test_sort_indices_desc
void test_sort_indices_desc(Eigen::Matrix<T,R,C> val) {
using stan::math::sort_indices_desc;
typedef Eigen::Matrix<AVAR,R,C> AVEC;
typedef Eigen::Matrix<double,R,C> VEC;
const size_t size = val.size();
AVEC x(size);
for(size_t i=0U; i<size; i++)
x.data()[i] = AVAR(val[i]);
std::vector<int> val_sorted = sort_indices_desc(val);
std::vector<int> x_sorted = sort_indices_desc(x);
for(size_t i=0U; i<size; i++)
EXPECT_EQ(val_sorted.data()[i],x_sorted.data()[i]);
for(size_t i=0U; i<size; i++)
for(size_t j=0U; j<size; j++)
if(val_sorted.data()[i] == val.data()[j])
EXPECT_EQ(x_sorted.data()[i],x.data()[j]);
else
EXPECT_FALSE(x_sorted.data()[i]==x.data()[j]);
}
示例15:
void OptimizedSelfAdjointMatrix6x6f::rankUpdate(const Eigen::Matrix<float, 6, 1>& u, const float& alpha)
{
__m128 s = _mm_set1_ps(alpha);
__m128 v1234 = _mm_loadu_ps(u.data());
__m128 v56xx = _mm_loadu_ps(u.data() + 4);
__m128 v1212 = _mm_movelh_ps(v1234, v1234);
__m128 v3434 = _mm_movehl_ps(v1234, v1234);
__m128 v5656 = _mm_movelh_ps(v56xx, v56xx);
__m128 v1122 = _mm_mul_ps(s, _mm_unpacklo_ps(v1212, v1212));
_mm_store_ps(data + 0, _mm_add_ps(_mm_load_ps(data + 0), _mm_mul_ps(v1122, v1212)));
_mm_store_ps(data + 4, _mm_add_ps(_mm_load_ps(data + 4), _mm_mul_ps(v1122, v3434)));
_mm_store_ps(data + 8, _mm_add_ps(_mm_load_ps(data + 8), _mm_mul_ps(v1122, v5656)));
__m128 v3344 = _mm_mul_ps(s, _mm_unpacklo_ps(v3434, v3434));
_mm_store_ps(data + 12, _mm_add_ps(_mm_load_ps(data + 12), _mm_mul_ps(v3344, v3434)));
_mm_store_ps(data + 16, _mm_add_ps(_mm_load_ps(data + 16), _mm_mul_ps(v3344, v5656)));
__m128 v5566 = _mm_mul_ps(s, _mm_unpacklo_ps(v5656, v5656));
_mm_store_ps(data + 20, _mm_add_ps(_mm_load_ps(data + 20), _mm_mul_ps(v5566, v5656)));
}