当前位置:网站首页>PCL eigen introduction and simple use
PCL eigen introduction and simple use
2022-07-02 10:57:00 【AICVer】
Eigen It can be used for Linear Algebra 、 matrix 、 Vector operation, etc C++ library .
Related code operations are as follows :
//#include "stdafx.h"// The original blog used this , But my computer can't find , So replace... With the following three lines .
#include <stdio.h>
#include "stdlib.h"
#include <tchar.h>
#include <iostream>
#include <Eigen/Dense>
// Ten 、eigen Use
using namespace std;
using namespace Eigen;
template <typename T>
static void matrix_mul_matrix(T* p1, int iRow1, int iCol1, T* p2, int iRow2, int iCol2, T* p3)
{
if (iRow1 != iRow2) return;
// Column priority
//Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > map1(p1, iRow1, iCol1);
//Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > map2(p2, iRow2, iCol2);
//Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > map3(p3, iCol1, iCol2);
// Line first
Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > map1(p1, iRow1, iCol1);
Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > map2(p2, iRow2, iCol2);
Eigen::Map< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > map3(p3, iCol1, iCol2);
map3 = map1 * map2;
}
int main(int argc, char* argv[])
{
//1. Definition of matrix
cout << "1. Definition of matrix " << endl;
Eigen::MatrixXd m(2, 2);
Eigen::Vector3d vec3d;
Eigen::Vector4d vec4d(1.0, 2.0, 3.0, 4.0);
//2. Dynamic matrix 、 Static matrix
cout << "2. Dynamic matrix 、 Static matrix " << endl;
Eigen::MatrixXd matrixXd;
Eigen::Matrix3d matrix3d;
//3. Access to matrix elements
cout << "3. Access to matrix elements " << endl;
m(0, 0) = 1;
m(0, 1) = 2;
m(1, 0) = m(0, 0) + 3;
m(1, 1) = m(0, 0) * m(0, 1);
std::cout << m << std::endl << std::endl;
//4. Set the elements of the matrix
cout << "4. Set the elements of the matrix " << endl;
m << -1.5, 2.4,
6.7, 2.0;
std::cout << m << std::endl << std::endl;
int row = 4;
int col = 5;
Eigen::MatrixXf matrixXf(row, col);
matrixXf << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20;
std::cout << matrixXf << std::endl << std::endl;
matrixXf << Eigen::MatrixXf::Identity(row, col);//Identity Unit matrix means :Identity matrix
std::cout << matrixXf << std::endl << std::endl;
//5. Reset matrix size
cout << "5. Reset matrix size " << endl;
Eigen::MatrixXd matrixXd1(3, 3);
m = matrixXd1;
std::cout << m.rows() << " " << m.cols() << std::endl << std::endl;
//6. Matrix operations
cout << "6. Matrix operations " << endl;
m << 1, 2, 7,
3, 4, 8,
5, 6, 9;
std::cout << m << std::endl;
matrixXd1 = Eigen::Matrix3d::Random();
m += matrixXd1;
std::cout << m << std::endl << std::endl;
m *= 2;
std::cout << m << std::endl << std::endl;
std::cout << -m << std::endl << std::endl;
std::cout << m << std::endl << std::endl;
//7. Transpose matrix 、 Conjugate matrix 、 Adjoint matrix
cout << "7. Transpose matrix 、 Conjugate matrix 、 Adjoint matrix " << endl;
std::cout << m.transpose() << std::endl << std::endl;
std::cout << m.conjugate() << std::endl << std::endl;
std::cout << m.adjoint() << std::endl << std::endl;
std::cout << m << std::endl << std::endl;
m.transposeInPlace();
std::cout << m << std::endl << std::endl;
//8. matrix multiplication 、 Matrix vector multiplication
cout << "8. matrix multiplication 、 Matrix vector multiplication " << endl;
std::cout << m*m << std::endl << std::endl;
vec3d = Eigen::Vector3d(1, 2, 3);
std::cout << m * vec3d << std::endl << std::endl;
std::cout << vec3d.transpose()*m << std::endl << std::endl;
//9. Block operation of matrix
cout << "9. Block operation of matrix " << endl;
std::cout << m << std::endl << std::endl;
std::cout << m.block(1, 1, 2, 2) << std::endl << std::endl;
std::cout << m.block<1, 2>(0, 0) << std::endl << std::endl;
std::cout << m.col(1) << std::endl << std::endl;
std::cout << m.row(0) << std::endl << std::endl;
//10. Block operation of vector
cout << "10. Block operation of vector " << endl;
Eigen::ArrayXf arrayXf(10);
arrayXf << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
std::cout << vec3d << std::endl << std::endl;
std::cout << arrayXf << std::endl << std::endl;
std::cout << arrayXf.head(5) << std::endl << std::endl;
std::cout << arrayXf.tail(4) * 2 << std::endl << std::endl;
//11. Solve the eigenvalues and eigenvectors of the matrix
cout << "11. Solve the eigenvalues and eigenvectors of the matrix " << endl;
Eigen::Matrix2f matrix2f;
matrix2f << 1, 2, 3, 4;
Eigen::SelfAdjointEigenSolver<Eigen::Matrix2f> eigenSolver(matrix2f);// Form is this form , In case of high-dimensional problems, replace them with high-dimensional ones matrix2f.
if (eigenSolver.info() == Eigen::Success) {
std::cout << eigenSolver.eigenvalues() << std::endl << std::endl;
std::cout << eigenSolver.eigenvectors() << std::endl << std::endl;
}
//12. class Map And the use of dynamic matrix
cout << "12. class Map And the use of dynamic matrix " << endl;
int array1[4] = {
1, 2, 3, 4 };
int array2[4] = {
5, 6, 7, 8 };
int array3[4] = {
0, 0, 0, 0 };
matrix_mul_matrix(array1, 2, 2, array2, 2, 2, array3);
for (int i = 0; i < 4; i++)
std::cout << array3[i] << std::endl;
return 0;
}
边栏推荐
- 12.进程同步与信号量
- [SUCTF2018]followme
- JSP webshell免杀——webshell免杀
- 互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
- PCL Eigen介绍及简单使用
- Operator-1 first acquaintance with operator
- 从.bag文件中读取并保存.jpg图片和.pcd点云
- Flutter——Canvas自定义曲线图
- Use WinDbg to statically analyze dump files (summary of practical experience)
- 14. Code implementation of semaphore
猜你喜欢
随机推荐
shell编程01_Shell基础
Kustomize user manual
Considerations for Apache deploying static web page projects
1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
学习open62541 --- [66] UA_String的生成方法
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
Session cookies and tokens
软件产品管理系统有哪些?12个最佳产品管理工具盘点
一招快速实现自定义快应用titlebar
"Matching" is true love, a new attitude for young people to make friends
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
快应用中实现自定义抽屉组件
全网显示 IP 归属地,是怎么实现的?
SPSS做Shapiro-Wilk正态分析
首份中国企业敏捷实践白皮书发布| 附完整下载
华为AppLinking中统一链接的创建和使用
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
JSP webshell免殺——JSP的基礎
js promise. all
LabVIEW为什么浮点数会丢失精度


![2.hacking-lab脚本关[详细writeup]](/img/f3/29745761cd5ad4df84c78ac904ea51.png)




![[SUCTF2018]followme](/img/63/9104f9c8bd24937b0fc65053efec96.png)

