20 #include <vtkTriangleFilter.h> 21 #include <vtkPolyDataMapper.h> 22 #include <vtkTriangle.h> 29 extension_ = boost::filesystem::extension(cad_file_path);
30 ROS_INFO(
"File extension: %s", extension_.c_str());
37 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
41 pcl::PolygonMesh mesh;
43 pcl::io::mesh2vtk(mesh, polydata);
47 vtkSmartPointer<vtkOBJReader> readerQuery = vtkSmartPointer<vtkOBJReader>::New();
49 readerQuery->Update();
50 polydata = readerQuery->GetOutput();
58 pcl::copyPointCloud(*CAD_cloud, *cloud);
61 ROS_ERROR(
"Error converting CAD mesh to pointcloud");
105 vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
106 triangleFilter->SetInputData(polydata);
107 triangleFilter->Update();
109 vtkSmartPointer<vtkPolyDataMapper> triangleMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
110 triangleMapper->SetInputConnection(triangleFilter->GetOutputPort());
111 triangleMapper->Update();
112 polydata = triangleMapper->GetInput();
114 polydata->BuildCells();
115 vtkSmartPointer<vtkCellArray> cells = polydata->GetPolys();
117 double p1[3], p2[3], p3[3], totalArea = 0;
118 std::vector<double> cumulativeAreas(cells->GetNumberOfCells(), 0);
120 vtkIdType npts = 0, *ptIds = NULL;
121 for (cells->InitTraversal(); cells->GetNextCell(npts, ptIds); i++)
123 polydata->GetPoint(ptIds[0], p1);
124 polydata->GetPoint(ptIds[1], p2);
125 polydata->GetPoint(ptIds[2], p3);
126 totalArea += vtkTriangle::TriangleArea(p1, p2, p3);
127 cumulativeAreas[i] = totalArea;
130 cloud_out.points.resize(n_samples);
131 cloud_out.width =
static_cast<pcl::uint32_t
>(n_samples);
132 cloud_out.height = 1;
134 for (i = 0; i < n_samples; i++)
138 cloud_out.points[i].x = p[0];
139 cloud_out.points[i].y = p[1];
140 cloud_out.points[i].z = p[2];
149 std::vector<double>::iterator low = std::lower_bound(cumulativeAreas->begin(), cumulativeAreas->end(), r);
150 vtkIdType el = vtkIdType(low - cumulativeAreas->begin());
152 double A[3], B[3], C[3];
154 vtkIdType* ptIds = NULL;
155 polydata->GetCellPoints(el, npts, ptIds);
156 polydata->GetPoint(ptIds[0], A);
157 polydata->GetPoint(ptIds[1], B);
158 polydata->GetPoint(ptIds[2], C);
159 randomPointTriangle(
float(A[0]),
float(A[1]),
float(A[2]),
float(B[0]),
float(B[1]),
float(B[2]),
float(C[0]),
160 float(C[1]),
float(C[2]), p);
165 double ran = seed * (1.0 / (RAND_MAX + 1.0));
170 float c2,
float c3, Eigen::Vector4f& p)
174 float r1sqr = sqrtf(r1);
175 float OneMinR1Sqr = (1 - r1sqr);
176 float OneMinR2 = (1 - r2);
183 c1 = r1sqr * (r2 * c1 + b1) + a1;
184 c2 = r1sqr * (r2 * c2 + b2) + a2;
185 c3 = r1sqr * (r2 * c3 + b3) + a3;
int SAMPLE_POINTS_
number of points to sample CAD mesh.
static bool isValidCloud(PointCloudXYZ::Ptr cloud)
Check whether cloud contains data and is not empty.
std::string extension_
cad file path extension to check formats.
void randPSurface(vtkPolyData *polydata, std::vector< double > *cumulativeAreas, double totalArea, Eigen::Vector4f &p)
Extracted from Point Cloud Library (PCL) –> pcl/tools/mesh_sampling.cpp Copyright (c) 2010-2011...
std::string cad_file_path_
path to CAD file to be converted.
void convertCloud(PointCloudRGB::Ptr cloud)
convert cloud defined by path in construstor into cloud
double uniformDeviate(int seed)
Extracted from Point Cloud Library (PCL) –> pcl/tools/mesh_sampling.cpp Copyright (c) 2010-2011...
CADToPointCloud(const std::string &cad_file_path, int sample_points)
Construct a new CADToPointCloud object.
void uniformSampling(vtkSmartPointer< vtkPolyData > polydata, size_t n_samples, PointCloudRGB &cloud_out)
Extracted from Point Cloud Library (PCL) –> pcl/tools/mesh_sampling.cpp Copyright (c) 2010-2011...
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
void randomPointTriangle(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3, Eigen::Vector4f &p)
Extracted from Point Cloud Library (PCL) –> pcl/tools/mesh_sampling.cpp Copyright (c) 2010-2011...