forked from sxyu/avatar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvatarPCL.cpp
44 lines (39 loc) · 1.44 KB
/
AvatarPCL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Version.h"
#include "AvatarPCL.h"
#ifdef OPENARK_PCL_ENABLED
#include <pcl/conversions.h>
#include <boost/smart_ptr.hpp>
namespace ark {
namespace avatar_pcl {
pcl::PointCloud<pcl::PointXYZ>::Ptr getCloud(const Avatar& ava) {
auto pointCloud =
pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
pointCloud->points.resize(ava.model.numPoints());
pointCloud->getMatrixXfMap().block<3, Eigen::Dynamic>(
0, 0, 3, pointCloud->size()) = ava.cloud.cast<float>();
return pointCloud;
}
pcl::PointCloud<pcl::PointXYZ>::Ptr getJointCloud(const Avatar& ava) {
auto pointCloud =
pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
pointCloud->resize(ava.model.numJoints());
pointCloud->getMatrixXfMap().block<3, Eigen::Dynamic>(
0, 0, 3, pointCloud->size()) = ava.jointPos.cast<float>();
return pointCloud;
}
pcl::PolygonMesh::Ptr getMesh(const Avatar& ava) {
auto pclCloud = getCloud(ava);
auto mesh = boost::make_shared<pcl::PolygonMesh>();
pcl::toPCLPointCloud2(*pclCloud, mesh->cloud);
mesh->polygons.reserve(ava.model.numFaces());
for (int i = 0; i < ava.model.numFaces(); ++i) {
mesh->polygons.emplace_back();
auto& face = mesh->polygons.back().vertices;
face.resize(3);
for (int j = 0; j < 3; ++j) face[j] = ava.model.mesh(j, i);
}
return mesh;
}
} // namespace avatar_pcl
} // namespace ark
#endif