x, y = np.meshgrid(np.arange(range_x), np.arange(range_y)) # np.savetxt('reshape_data.txt', x, delimiter=' ', fmt="%i") x_o = x - range_x / 2 y_o = y - range_y / 2 x_i = x - dx y_i = y - dy z_critical = 50 R_o = 550 R_i = 200 data_crop = crop_pointcloud(data_crop, x_o, y_o, x_i, y_i, R_o, R_i, z_critical) data_crop = data_crop[:, :, 10:] 转c++ Eigen::Tensor
时间: 2024-03-19 15:41:21 浏览: 72
Eigen::Tensor<int, 3> x, y;
x.resize(range_x, range_y, 1);
y.resize(range_x, range_y, 1);
for (int i = 0; i < range_x; ++i) {
for (int j = 0; j < range_y; ++j) {
x(i, j, 0) = i;
y(i, j, 0) = j;
}
}
Eigen::Tensor<int, 3> x_o = x - range_x / 2;
Eigen::Tensor<int, 3> y_o = y - range_y / 2;
Eigen::Tensor<int, 3> x_i = x - dx;
Eigen::Tensor<int, 3> y_i = y - dy;
int z_critical = 50;
int R_o = 550;
int R_i = 200;
data_crop = crop_pointcloud(data_crop, x_o, y_o, x_i, y_i, R_o, R_i, z_critical);
data_crop = data_crop.slice(Eigen::array<int, 3>{0, 0, 10}, data_crop.dimensions());
相关问题
range_x = 100 range_y=100 x, y = np.meshgrid(np.arange(range_x), np.arange(range_y)) # np.savetxt('reshape_data.txt', x, delimiter=' ', fmt="%i") x_o = x - range_x / 2 y_o = y - range_y / 2 x_i = x - dx y_i = y - dy 转C++
这段代码的C++实现如下:
```cpp
int range_x = 100;
int range_y = 100;
vector<vector<int>> x(range_x, vector<int>(range_y));
vector<vector<int>> y(range_x, vector<int>(range_y));
for (int i = 0; i < range_x; i++) {
for (int j = 0; j < range_y; j++) {
x[i][j] = i;
y[i][j] = j;
}
}
vector<vector<int>> x_o(range_x, vector<int>(range_y));
vector<vector<int>> y_o(range_x, vector<int>(range_y));
vector<vector<int>> x_i(range_x, vector<int>(range_y));
vector<vector<int>> y_i(range_x, vector<int>(range_y));
for (int i = 0; i < range_x; i++) {
for (int j = 0; j < range_y; j++) {
x_o[i][j] = x[i][j] - range_x / 2;
y_o[i][j] = y[i][j] - range_y / 2;
x_i[i][j] = x[i][j] - dx;
y_i[i][j] = y[i][j] - dy;
}
}
```
其中,使用了vector来存储矩阵,通过双重循环遍历来实现numpy中的arange()函数的功能,最后分别计算了x_o、y_o、x_i和y_i。
x, y = np.meshgrid(np.arange(range_x), np.arange(range_y)) # np.savetxt('reshape_data.txt', x, delimiter=' ', fmt="%i") x_o = x - range_x / 2 y_o = y - range_y / 2 x_i = x - dx y_i = y - dy
这段代码的作用是创建一个平面网格,其中x和y的取值范围分别为0到range_x-1和0到range_y-1,然后将网格的中心移动到坐标系的原点,最后在x和y上分别减去dx和dy。其中,np.meshgrid()函数用于生成一个二维数组,np.arange()函数用于生成一个以0为起点,以指定长度为终点的等差数列。np.savetxt()函数用于将数据保存到文件中。
阅读全文