Point Cloud Library (PCL)  1.9.1-dev
texture_mapping.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #ifndef PCL_SURFACE_IMPL_TEXTURE_MAPPING_HPP_
39 #define PCL_SURFACE_IMPL_TEXTURE_MAPPING_HPP_
40 
41 #include <pcl/common/distances.h>
42 #include <pcl/surface/texture_mapping.h>
43 
44 ///////////////////////////////////////////////////////////////////////////////////////////////
45 template<typename PointInT> std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >
47  const Eigen::Vector3f &p1,
48  const Eigen::Vector3f &p2,
49  const Eigen::Vector3f &p3)
50 {
51  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates;
52  // process for each face
53  Eigen::Vector3f p1p2 (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]);
54  Eigen::Vector3f p1p3 (p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]);
55  Eigen::Vector3f p2p3 (p3[0] - p2[0], p3[1] - p2[1], p3[2] - p2[2]);
56 
57  // Normalize
58  p1p2 = p1p2 / std::sqrt (p1p2.dot (p1p2));
59  p1p3 = p1p3 / std::sqrt (p1p3.dot (p1p3));
60  p2p3 = p2p3 / std::sqrt (p2p3.dot (p2p3));
61 
62  // compute vector normal of a face
63  Eigen::Vector3f f_normal = p1p2.cross (p1p3);
64  f_normal = f_normal / std::sqrt (f_normal.dot (f_normal));
65 
66  // project vector field onto the face: vector v1_projected = v1 - Dot(v1, n) * n;
67  Eigen::Vector3f f_vector_field = vector_field_ - vector_field_.dot (f_normal) * f_normal;
68 
69  // Normalize
70  f_vector_field = f_vector_field / std::sqrt (f_vector_field.dot (f_vector_field));
71 
72  // texture coordinates
73  Eigen::Vector2f tp1, tp2, tp3;
74 
75  double alpha = std::acos (f_vector_field.dot (p1p2));
76 
77  // distance between 3 vertices of triangles
78  double e1 = (p2 - p3).norm () / f_;
79  double e2 = (p1 - p3).norm () / f_;
80  double e3 = (p1 - p2).norm () / f_;
81 
82  // initialize
83  tp1[0] = 0.0;
84  tp1[1] = 0.0;
85 
86  tp2[0] = static_cast<float> (e3);
87  tp2[1] = 0.0;
88 
89  // determine texture coordinate tp3;
90  double cos_p1 = (e2 * e2 + e3 * e3 - e1 * e1) / (2 * e2 * e3);
91  double sin_p1 = sqrt (1 - (cos_p1 * cos_p1));
92 
93  tp3[0] = static_cast<float> (cos_p1 * e2);
94  tp3[1] = static_cast<float> (sin_p1 * e2);
95 
96  // rotating by alpha (angle between V and pp1 & pp2)
97  Eigen::Vector2f r_tp2, r_tp3;
98  r_tp2[0] = static_cast<float> (tp2[0] * std::cos (alpha) - tp2[1] * std::sin (alpha));
99  r_tp2[1] = static_cast<float> (tp2[0] * std::sin (alpha) + tp2[1] * std::cos (alpha));
100 
101  r_tp3[0] = static_cast<float> (tp3[0] * std::cos (alpha) - tp3[1] * std::sin (alpha));
102  r_tp3[1] = static_cast<float> (tp3[0] * std::sin (alpha) + tp3[1] * std::cos (alpha));
103 
104  // shifting
105  tp1[0] = tp1[0];
106  tp2[0] = r_tp2[0];
107  tp3[0] = r_tp3[0];
108  tp1[1] = tp1[1];
109  tp2[1] = r_tp2[1];
110  tp3[1] = r_tp3[1];
111 
112  float min_x = tp1[0];
113  float min_y = tp1[1];
114  if (min_x > tp2[0])
115  min_x = tp2[0];
116  if (min_x > tp3[0])
117  min_x = tp3[0];
118  if (min_y > tp2[1])
119  min_y = tp2[1];
120  if (min_y > tp3[1])
121  min_y = tp3[1];
122 
123  if (min_x < 0)
124  {
125  tp1[0] = tp1[0] - min_x;
126  tp2[0] = tp2[0] - min_x;
127  tp3[0] = tp3[0] - min_x;
128  }
129  if (min_y < 0)
130  {
131  tp1[1] = tp1[1] - min_y;
132  tp2[1] = tp2[1] - min_y;
133  tp3[1] = tp3[1] - min_y;
134  }
135 
136  tex_coordinates.push_back (tp1);
137  tex_coordinates.push_back (tp2);
138  tex_coordinates.push_back (tp3);
139  return (tex_coordinates);
140 }
141 
142 ///////////////////////////////////////////////////////////////////////////////////////////////
143 template<typename PointInT> void
145 {
146  // mesh information
147  int nr_points = tex_mesh.cloud.width * tex_mesh.cloud.height;
148  int point_size = static_cast<int> (tex_mesh.cloud.data.size ()) / nr_points;
149 
150  // temporary PointXYZ
151  float x, y, z;
152  // temporary face
153  Eigen::Vector3f facet[3];
154 
155  // texture coordinates for each mesh
156  std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > >texture_map;
157 
158  for (size_t m = 0; m < tex_mesh.tex_polygons.size (); ++m)
159  {
160  // texture coordinates for each mesh
161  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
162 
163  // processing for each face
164  for (size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
165  {
166  size_t idx;
167 
168  // get facet information
169  for (size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
170  {
171  idx = tex_mesh.tex_polygons[m][i].vertices[j];
172  memcpy (&x, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
173  memcpy (&y, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
174  memcpy (&z, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
175  facet[j][0] = x;
176  facet[j][1] = y;
177  facet[j][2] = z;
178  }
179 
180  // get texture coordinates of each face
181  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates = mapTexture2Face (facet[0], facet[1], facet[2]);
182  for (const auto &tex_coordinate : tex_coordinates)
183  texture_map_tmp.push_back (tex_coordinate);
184  }// end faces
185 
186  // texture materials
187  std::stringstream tex_name;
188  tex_name << "material_" << m;
189  tex_name >> tex_material_.tex_name;
190  tex_material_.tex_file = tex_files_[m];
191  tex_mesh.tex_materials.push_back (tex_material_);
192 
193  // texture coordinates
194  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
195  }// end meshes
196 }
197 
198 ///////////////////////////////////////////////////////////////////////////////////////////////
199 template<typename PointInT> void
201 {
202  // mesh information
203  int nr_points = tex_mesh.cloud.width * tex_mesh.cloud.height;
204  int point_size = static_cast<int> (tex_mesh.cloud.data.size ()) / nr_points;
205 
206  float x_lowest = 100000;
207  float x_highest = 0;
208  float y_lowest = 100000;
209  //float y_highest = 0 ;
210  float z_lowest = 100000;
211  float z_highest = 0;
212  float x_, y_, z_;
213 
214  for (int i = 0; i < nr_points; ++i)
215  {
216  memcpy (&x_, &tex_mesh.cloud.data[i * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
217  memcpy (&y_, &tex_mesh.cloud.data[i * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
218  memcpy (&z_, &tex_mesh.cloud.data[i * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
219  // x
220  if (x_ <= x_lowest)
221  x_lowest = x_;
222  if (x_ > x_lowest)
223  x_highest = x_;
224 
225  // y
226  if (y_ <= y_lowest)
227  y_lowest = y_;
228  //if (y_ > y_lowest) y_highest = y_;
229 
230  // z
231  if (z_ <= z_lowest)
232  z_lowest = z_;
233  if (z_ > z_lowest)
234  z_highest = z_;
235  }
236  // x
237  float x_range = (x_lowest - x_highest) * -1;
238  float x_offset = 0 - x_lowest;
239  // x
240  // float y_range = (y_lowest - y_highest)*-1;
241  // float y_offset = 0 - y_lowest;
242  // z
243  float z_range = (z_lowest - z_highest) * -1;
244  float z_offset = 0 - z_lowest;
245 
246  // texture coordinates for each mesh
247  std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > >texture_map;
248 
249  for (size_t m = 0; m < tex_mesh.tex_polygons.size (); ++m)
250  {
251  // texture coordinates for each mesh
252  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
253 
254  // processing for each face
255  for (size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
256  {
257  size_t idx;
258  Eigen::Vector2f tmp_VT;
259  for (size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
260  {
261  idx = tex_mesh.tex_polygons[m][i].vertices[j];
262  memcpy (&x_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
263  memcpy (&y_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
264  memcpy (&z_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
265 
266  // calculate uv coordinates
267  tmp_VT[0] = (x_ + x_offset) / x_range;
268  tmp_VT[1] = (z_ + z_offset) / z_range;
269  texture_map_tmp.push_back (tmp_VT);
270  }
271  }// end faces
272 
273  // texture materials
274  std::stringstream tex_name;
275  tex_name << "material_" << m;
276  tex_name >> tex_material_.tex_name;
277  tex_material_.tex_file = tex_files_[m];
278  tex_mesh.tex_materials.push_back (tex_material_);
279 
280  // texture coordinates
281  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
282  }// end meshes
283 }
284 
285 ///////////////////////////////////////////////////////////////////////////////////////////////
286 template<typename PointInT> void
288 {
289 
290  if (tex_mesh.tex_polygons.size () != cams.size () + 1)
291  {
292  PCL_ERROR ("The mesh should be divided into nbCamera+1 sub-meshes.\n");
293  PCL_ERROR ("You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.tex_polygons.size ());
294  return;
295  }
296 
297  PCL_INFO ("You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.tex_polygons.size ());
298 
299  typename pcl::PointCloud<PointInT>::Ptr originalCloud (new pcl::PointCloud<PointInT>);
300  typename pcl::PointCloud<PointInT>::Ptr camera_transformed_cloud (new pcl::PointCloud<PointInT>);
301 
302  // convert mesh's cloud to pcl format for ease
303  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *originalCloud);
304 
305  // texture coordinates for each mesh
306  std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > texture_map;
307 
308  for (size_t m = 0; m < cams.size (); ++m)
309  {
310  // get current camera parameters
311  Camera current_cam = cams[m];
312 
313  // get camera transform
314  Eigen::Affine3f cam_trans = current_cam.pose;
315 
316  // transform cloud into current camera frame
317  pcl::transformPointCloud (*originalCloud, *camera_transformed_cloud, cam_trans.inverse ());
318 
319  // vector of texture coordinates for each face
320  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
321 
322  // processing each face visible by this camera
323  for (const auto &tex_polygon : tex_mesh.tex_polygons[m])
324  {
325  Eigen::Vector2f tmp_VT;
326  // for each point of this face
327  for (const unsigned int &vertex : tex_polygon.vertices)
328  {
329  // get point
330  PointInT pt = camera_transformed_cloud->points[vertex];
331 
332  // compute UV coordinates for this point
333  getPointUVCoordinates (pt, current_cam, tmp_VT);
334  texture_map_tmp.push_back (tmp_VT);
335  }// end points
336  }// end faces
337 
338  // texture materials
339  std::stringstream tex_name;
340  tex_name << "material_" << m;
341  tex_name >> tex_material_.tex_name;
342  tex_material_.tex_file = current_cam.texture_file;
343  tex_mesh.tex_materials.push_back (tex_material_);
344 
345  // texture coordinates
346  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
347  }// end cameras
348 
349  // push on extra empty UV map (for unseen faces) so that obj writer does not crash!
350  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
351  for (const auto &tex_polygon : tex_mesh.tex_polygons[cams.size ()])
352  for (size_t j = 0; j < tex_polygon.vertices.size (); ++j)
353  {
354  Eigen::Vector2f tmp_VT;
355  tmp_VT[0] = -1;
356  tmp_VT[1] = -1;
357  texture_map_tmp.push_back (tmp_VT);
358  }
359 
360  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
361 
362  // push on an extra dummy material for the same reason
363  tex_material_.tex_name = "material_" + std::to_string(cams.size());
364  tex_material_.tex_file = "occluded.jpg";
365  tex_mesh.tex_materials.push_back (tex_material_);
366 }
367 
368 ///////////////////////////////////////////////////////////////////////////////////////////////
369 template<typename PointInT> bool
371 {
372  Eigen::Vector3f direction;
373  direction (0) = pt.x;
374  direction (1) = pt.y;
375  direction (2) = pt.z;
376 
377  std::vector<int> indices;
378 
379  PointCloudConstPtr cloud (new PointCloud());
380  cloud = octree->getInputCloud();
381 
382  double distance_threshold = octree->getResolution();
383 
384  // raytrace
385  octree->getIntersectedVoxelIndices(direction, -direction, indices);
386 
387  int nbocc = static_cast<int> (indices.size ());
388  for (const int &index : indices)
389  {
390  // if intersected point is on the over side of the camera
391  if (pt.z * cloud->points[index].z < 0)
392  {
393  nbocc--;
394  continue;
395  }
396 
397  if (fabs (cloud->points[index].z - pt.z) <= distance_threshold)
398  {
399  // points are very close to each-other, we do not consider the occlusion
400  nbocc--;
401  }
402  }
403 
404  if (nbocc == 0)
405  return (false);
406  else
407  return (true);
408 }
409 
410 ///////////////////////////////////////////////////////////////////////////////////////////////
411 template<typename PointInT> void
413  PointCloudPtr &filtered_cloud,
414  const double octree_voxel_size, std::vector<int> &visible_indices,
415  std::vector<int> &occluded_indices)
416 {
417  // variable used to filter occluded points by depth
418  double maxDeltaZ = octree_voxel_size;
419 
420  // create an octree to perform rayTracing
421  OctreePtr octree (new Octree (octree_voxel_size));
422  // create octree structure
423  octree->setInputCloud (input_cloud);
424  // update bounding box automatically
425  octree->defineBoundingBox ();
426  // add points in the tree
427  octree->addPointsFromInputCloud ();
428 
429  visible_indices.clear ();
430 
431  // for each point of the cloud, raycast toward camera and check intersected voxels.
432  Eigen::Vector3f direction;
433  std::vector<int> indices;
434  for (size_t i = 0; i < input_cloud->points.size (); ++i)
435  {
436  direction (0) = input_cloud->points[i].x;
437  direction (1) = input_cloud->points[i].y;
438  direction (2) = input_cloud->points[i].z;
439 
440  // if point is not occluded
441  octree->getIntersectedVoxelIndices (direction, -direction, indices);
442 
443  int nbocc = static_cast<int> (indices.size ());
444  for (const int &index : indices)
445  {
446  // if intersected point is on the over side of the camera
447  if (input_cloud->points[i].z * input_cloud->points[index].z < 0)
448  {
449  nbocc--;
450  continue;
451  }
452 
453  if (fabs (input_cloud->points[index].z - input_cloud->points[i].z) <= maxDeltaZ)
454  {
455  // points are very close to each-other, we do not consider the occlusion
456  nbocc--;
457  }
458  }
459 
460  if (nbocc == 0)
461  {
462  // point is added in the filtered mesh
463  filtered_cloud->points.push_back (input_cloud->points[i]);
464  visible_indices.push_back (static_cast<int> (i));
465  }
466  else
467  {
468  occluded_indices.push_back (static_cast<int> (i));
469  }
470  }
471 
472 }
473 
474 ///////////////////////////////////////////////////////////////////////////////////////////////
475 template<typename PointInT> void
476 pcl::TextureMapping<PointInT>::removeOccludedPoints (const pcl::TextureMesh &tex_mesh, pcl::TextureMesh &cleaned_mesh, const double octree_voxel_size)
477 {
478  // copy mesh
479  cleaned_mesh = tex_mesh;
480 
482  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
483 
484  // load points into a PCL format
485  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
486 
487  std::vector<int> visible, occluded;
488  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
489 
490  // Now that we know which points are visible, let's iterate over each face.
491  // if the face has one invisible point => out!
492  for (size_t polygons = 0; polygons < cleaned_mesh.tex_polygons.size (); ++polygons)
493  {
494  // remove all faces from cleaned mesh
495  cleaned_mesh.tex_polygons[polygons].clear ();
496  // iterate over faces
497  for (size_t faces = 0; faces < tex_mesh.tex_polygons[polygons].size (); ++faces)
498  {
499  // check if all the face's points are visible
500  bool faceIsVisible = true;
501  std::vector<int>::iterator it;
502 
503  // iterate over face's vertex
504  for (const unsigned int &vertex : tex_mesh.tex_polygons[polygons][faces].vertices)
505  {
506  it = find (occluded.begin (), occluded.end (), vertex);
507 
508  if (it == occluded.end ())
509  {
510  // point is not in the occluded vector
511  // PCL_INFO (" VISIBLE!\n");
512  }
513  else
514  {
515  // point was occluded
516  // PCL_INFO(" OCCLUDED!\n");
517  faceIsVisible = false;
518  }
519  }
520 
521  if (faceIsVisible)
522  {
523  cleaned_mesh.tex_polygons[polygons].push_back (tex_mesh.tex_polygons[polygons][faces]);
524  }
525 
526  }
527  }
528 }
529 
530 ///////////////////////////////////////////////////////////////////////////////////////////////
531 template<typename PointInT> void
533  const double octree_voxel_size)
534 {
535  PointCloudPtr cloud (new PointCloud);
536 
537  // load points into a PCL format
538  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
539 
540  std::vector<int> visible, occluded;
541  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
542 
543 }
544 
545 ///////////////////////////////////////////////////////////////////////////////////////////////
546 template<typename PointInT> int
548  const pcl::texture_mapping::CameraVector &cameras, const double octree_voxel_size,
549  PointCloud &visible_pts)
550 {
551  if (tex_mesh.tex_polygons.size () != 1)
552  {
553  PCL_ERROR ("The mesh must contain only 1 sub-mesh!\n");
554  return (-1);
555  }
556 
557  if (cameras.size () == 0)
558  {
559  PCL_ERROR ("Must provide at least one camera info!\n");
560  return (-1);
561  }
562 
563  // copy mesh
564  sorted_mesh = tex_mesh;
565  // clear polygons from cleaned_mesh
566  sorted_mesh.tex_polygons.clear ();
567 
568  typename pcl::PointCloud<PointInT>::Ptr original_cloud (new pcl::PointCloud<PointInT>);
569  typename pcl::PointCloud<PointInT>::Ptr transformed_cloud (new pcl::PointCloud<PointInT>);
570  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
571 
572  // load points into a PCL format
573  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *original_cloud);
574 
575  // for each camera
576  for (const auto &camera : cameras)
577  {
578  // get camera pose as transform
579  Eigen::Affine3f cam_trans = camera.pose;
580 
581  // transform original cloud in camera coordinates
582  pcl::transformPointCloud (*original_cloud, *transformed_cloud, cam_trans.inverse ());
583 
584  // find occlusions on transformed cloud
585  std::vector<int> visible, occluded;
586  removeOccludedPoints (transformed_cloud, filtered_cloud, octree_voxel_size, visible, occluded);
587  visible_pts = *filtered_cloud;
588 
589  // find visible faces => add them to polygon N for camera N
590  // add polygon group for current camera in clean
591  std::vector<pcl::Vertices> visibleFaces_currentCam;
592  // iterate over the faces of the current mesh
593  for (size_t faces = 0; faces < tex_mesh.tex_polygons[0].size (); ++faces)
594  {
595  // check if all the face's points are visible
596  bool faceIsVisible = true;
597  std::vector<int>::iterator it;
598 
599  // iterate over face's vertex
600  for (size_t current_pt_indice = 0; faceIsVisible && current_pt_indice < tex_mesh.tex_polygons[0][faces].vertices.size (); ++current_pt_indice)
601  {
602  // TODO this is far too long! Better create an helper function that raycasts here.
603  it = find (occluded.begin (), occluded.end (), tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]);
604 
605  if (it == occluded.end ())
606  {
607  // point is not occluded
608  // does it land on the camera's image plane?
609  PointInT pt = transformed_cloud->points[tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]];
610  Eigen::Vector2f dummy_UV;
611  if (!getPointUVCoordinates (pt, camera, dummy_UV))
612  {
613  // point is not visible by the camera
614  faceIsVisible = false;
615  }
616  }
617  else
618  {
619  faceIsVisible = false;
620  }
621  }
622 
623  if (faceIsVisible)
624  {
625  // push current visible face into the sorted mesh
626  visibleFaces_currentCam.push_back (tex_mesh.tex_polygons[0][faces]);
627  // remove it from the unsorted mesh
628  tex_mesh.tex_polygons[0].erase (tex_mesh.tex_polygons[0].begin () + faces);
629  faces--;
630  }
631 
632  }
633  sorted_mesh.tex_polygons.push_back (visibleFaces_currentCam);
634  }
635 
636  // we should only have occluded and non-visible faces left in tex_mesh.tex_polygons[0]
637  // we need to add them as an extra polygon in the sorted mesh
638  sorted_mesh.tex_polygons.push_back (tex_mesh.tex_polygons[0]);
639  return (0);
640 }
641 
642 ///////////////////////////////////////////////////////////////////////////////////////////////
643 template<typename PointInT> void
646  const double octree_voxel_size, const bool show_nb_occlusions,
647  const int max_occlusions)
648  {
649  // variable used to filter occluded points by depth
650  double maxDeltaZ = octree_voxel_size * 2.0;
651 
652  // create an octree to perform rayTracing
654  octree = new pcl::octree::OctreePointCloudSearch<PointInT> (octree_voxel_size);
655  // create octree structure
656  octree->setInputCloud (input_cloud);
657  // update bounding box automatically
658  octree->defineBoundingBox ();
659  // add points in the tree
660  octree->addPointsFromInputCloud ();
661 
662  // ray direction
663  Eigen::Vector3f direction;
664 
665  std::vector<int> indices;
666  // point from where we ray-trace
667  pcl::PointXYZI pt;
668 
669  std::vector<double> zDist;
670  std::vector<double> ptDist;
671  // for each point of the cloud, ray-trace toward the camera and check intersected voxels.
672  for (size_t i = 0; i < input_cloud->points.size (); ++i)
673  {
674  direction (0) = input_cloud->points[i].x;
675  pt.x = input_cloud->points[i].x;
676  direction (1) = input_cloud->points[i].y;
677  pt.y = input_cloud->points[i].y;
678  direction (2) = input_cloud->points[i].z;
679  pt.z = input_cloud->points[i].z;
680 
681  // get number of occlusions for that point
682  indices.clear ();
683  int nbocc = octree->getIntersectedVoxelIndices (direction, -direction, indices);
684 
685  nbocc = static_cast<int> (indices.size ());
686 
687  // TODO need to clean this up and find tricks to get remove aliasaing effect on planes
688  for (const int &index : indices)
689  {
690  // if intersected point is on the over side of the camera
691  if (pt.z * input_cloud->points[index].z < 0)
692  {
693  nbocc--;
694  }
695  else if (fabs (input_cloud->points[index].z - pt.z) <= maxDeltaZ)
696  {
697  // points are very close to each-other, we do not consider the occlusion
698  nbocc--;
699  }
700  else
701  {
702  zDist.push_back (fabs (input_cloud->points[index].z - pt.z));
703  ptDist.push_back (pcl::euclideanDistance (input_cloud->points[index], pt));
704  }
705  }
706 
707  if (show_nb_occlusions)
708  (nbocc <= max_occlusions) ? (pt.intensity = static_cast<float> (nbocc)) : (pt.intensity = static_cast<float> (max_occlusions));
709  else
710  (nbocc == 0) ? (pt.intensity = 0) : (pt.intensity = 1);
711 
712  colored_cloud->points.push_back (pt);
713  }
714 
715  if (zDist.size () >= 2)
716  {
717  std::sort (zDist.begin (), zDist.end ());
718  std::sort (ptDist.begin (), ptDist.end ());
719  }
720 }
721 
722 ///////////////////////////////////////////////////////////////////////////////////////////////
723 template<typename PointInT> void
725  double octree_voxel_size, bool show_nb_occlusions, int max_occlusions)
726 {
727  // load points into a PCL format
729  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
730 
731  showOcclusions (cloud, colored_cloud, octree_voxel_size, show_nb_occlusions, max_occlusions);
732 }
733 
734 ///////////////////////////////////////////////////////////////////////////////////////////////
735 template<typename PointInT> void
737 {
738 
739  if (mesh.tex_polygons.size () != 1)
740  return;
741 
743 
744  pcl::fromPCLPointCloud2 (mesh.cloud, *mesh_cloud);
745 
746  std::vector<pcl::Vertices> faces;
747 
748  for (int current_cam = 0; current_cam < static_cast<int> (cameras.size ()); ++current_cam)
749  {
750  PCL_INFO ("Processing camera %d of %d.\n", current_cam+1, cameras.size ());
751 
752  // transform mesh into camera's frame
753  typename pcl::PointCloud<PointInT>::Ptr camera_cloud (new pcl::PointCloud<PointInT>);
754  pcl::transformPointCloud (*mesh_cloud, *camera_cloud, cameras[current_cam].pose.inverse ());
755 
756  // CREATE UV MAP FOR CURRENT FACES
758  std::vector<bool> visibility;
759  visibility.resize (mesh.tex_polygons[current_cam].size ());
760  std::vector<UvIndex> indexes_uv_to_points;
761  // for each current face
762 
763  //TODO change this
764  pcl::PointXY nan_point;
765  nan_point.x = std::numeric_limits<float>::quiet_NaN ();
766  nan_point.y = std::numeric_limits<float>::quiet_NaN ();
767  UvIndex u_null;
768  u_null.idx_cloud = -1;
769  u_null.idx_face = -1;
770 
771  int cpt_invisible=0;
772  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[current_cam].size ()); ++idx_face)
773  {
774  //project each vertice, if one is out of view, stop
775  pcl::PointXY uv_coord1;
776  pcl::PointXY uv_coord2;
777  pcl::PointXY uv_coord3;
778 
779  if (isFaceProjected (cameras[current_cam],
780  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[0]],
781  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[1]],
782  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[2]],
783  uv_coord1,
784  uv_coord2,
785  uv_coord3))
786  {
787  // face is in the camera's FOV
788 
789  // add UV coordinates
790  projections->points.push_back (uv_coord1);
791  projections->points.push_back (uv_coord2);
792  projections->points.push_back (uv_coord3);
793 
794  // remember corresponding face
795  UvIndex u1, u2, u3;
796  u1.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[0];
797  u2.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[1];
798  u3.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[2];
799  u1.idx_face = idx_face; u2.idx_face = idx_face; u3.idx_face = idx_face;
800  indexes_uv_to_points.push_back (u1);
801  indexes_uv_to_points.push_back (u2);
802  indexes_uv_to_points.push_back (u3);
803 
804  //keep track of visibility
805  visibility[idx_face] = true;
806  }
807  else
808  {
809  projections->points.push_back (nan_point);
810  projections->points.push_back (nan_point);
811  projections->points.push_back (nan_point);
812  indexes_uv_to_points.push_back (u_null);
813  indexes_uv_to_points.push_back (u_null);
814  indexes_uv_to_points.push_back (u_null);
815  //keep track of visibility
816  visibility[idx_face] = false;
817  cpt_invisible++;
818  }
819  }
820 
821  // projections contains all UV points of the current faces
822  // indexes_uv_to_points links a uv point to its point in the camera cloud
823  // visibility contains tells if a face was in the camera FOV (false = skip)
824 
825  // TODO handle case were no face could be projected
826  if (visibility.size () - cpt_invisible !=0)
827  {
828  //create kdtree
830  kdtree.setInputCloud (projections);
831 
832  std::vector<int> idxNeighbors;
833  std::vector<float> neighborsSquaredDistance;
834  // af first (idx_pcan < current_cam), check if some of the faces attached to previous cameras occlude the current faces
835  // then (idx_pcam == current_cam), check for self occlusions. At this stage, we skip faces that were already marked as occluded
836  cpt_invisible = 0;
837  for (int idx_pcam = 0 ; idx_pcam <= current_cam ; ++idx_pcam)
838  {
839  // project all faces
840  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[idx_pcam].size ()); ++idx_face)
841  {
842 
843  if (idx_pcam == current_cam && !visibility[idx_face])
844  {
845  // we are now checking for self occlusions within the current faces
846  // the current face was already declared as occluded.
847  // therefore, it cannot occlude another face anymore => we skip it
848  continue;
849  }
850 
851  // project each vertice, if one is out of view, stop
852  pcl::PointXY uv_coord1;
853  pcl::PointXY uv_coord2;
854  pcl::PointXY uv_coord3;
855 
856  if (isFaceProjected (cameras[current_cam],
857  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]],
858  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]],
859  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]],
860  uv_coord1,
861  uv_coord2,
862  uv_coord3))
863  {
864  // face is in the camera's FOV
865  //get its circumsribed circle
866  double radius;
867  pcl::PointXY center;
868  // getTriangleCircumcenterAndSize (uv_coord1, uv_coord2, uv_coord3, center, radius);
869  getTriangleCircumcscribedCircleCentroid(uv_coord1, uv_coord2, uv_coord3, center, radius); // this function yields faster results than getTriangleCircumcenterAndSize
870 
871  // get points inside circ.circle
872  if (kdtree.radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
873  {
874  // for each neighbor
875  for (const int &idxNeighbor : idxNeighbors)
876  {
877  if (std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]].z,
878  std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]].z,
879  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]].z))
880  < camera_cloud->points[indexes_uv_to_points[idxNeighbor].idx_cloud].z)
881  {
882  // neighbor is farther than all the face's points. Check if it falls into the triangle
883  if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbor]))
884  {
885  // current neighbor is inside triangle and is closer => the corresponding face
886  visibility[indexes_uv_to_points[idxNeighbor].idx_face] = false;
887  cpt_invisible++;
888  //TODO we could remove the projections of this face from the kd-tree cloud, but I fond it slower, and I need the point to keep ordered to querry UV coordinates later
889  }
890  }
891  }
892  }
893  }
894  }
895  }
896  }
897 
898  // now, visibility is true for each face that belongs to the current camera
899  // if a face is not visible, we push it into the next one.
900 
901  if (static_cast<int> (mesh.tex_coordinates.size ()) <= current_cam)
902  {
903  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
904  mesh.tex_coordinates.push_back (dummy_container);
905  }
906  mesh.tex_coordinates[current_cam].resize (3 * visibility.size ());
907 
908  std::vector<pcl::Vertices> occluded_faces;
909  occluded_faces.resize (visibility.size ());
910  std::vector<pcl::Vertices> visible_faces;
911  visible_faces.resize (visibility.size ());
912 
913  int cpt_occluded_faces = 0;
914  int cpt_visible_faces = 0;
915 
916  for (size_t idx_face = 0 ; idx_face < visibility.size () ; ++idx_face)
917  {
918  if (visibility[idx_face])
919  {
920  // face is visible by the current camera copy UV coordinates
921  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](0) = projections->points[idx_face*3].x;
922  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](1) = projections->points[idx_face*3].y;
923 
924  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](0) = projections->points[idx_face*3 + 1].x;
925  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](1) = projections->points[idx_face*3 + 1].y;
926 
927  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](0) = projections->points[idx_face*3 + 2].x;
928  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](1) = projections->points[idx_face*3 + 2].y;
929 
930  visible_faces[cpt_visible_faces] = mesh.tex_polygons[current_cam][idx_face];
931 
932  cpt_visible_faces++;
933  }
934  else
935  {
936  // face is occluded copy face into temp vector
937  occluded_faces[cpt_occluded_faces] = mesh.tex_polygons[current_cam][idx_face];
938  cpt_occluded_faces++;
939  }
940  }
941  mesh.tex_coordinates[current_cam].resize (cpt_visible_faces*3);
942 
943  occluded_faces.resize (cpt_occluded_faces);
944  mesh.tex_polygons.push_back (occluded_faces);
945 
946  visible_faces.resize (cpt_visible_faces);
947  mesh.tex_polygons[current_cam].clear ();
948  mesh.tex_polygons[current_cam] = visible_faces;
949  }
950 
951  // we have been through all the cameras.
952  // if any faces are left, they were not visible by any camera
953  // we still need to produce uv coordinates for them
954 
955  if (mesh.tex_coordinates.size() <= cameras.size ())
956  {
957  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
958  mesh.tex_coordinates.push_back(dummy_container);
959  }
960 
961 
962  for(size_t idx_face = 0 ; idx_face < mesh.tex_polygons[cameras.size()].size() ; ++idx_face)
963  {
964  Eigen::Vector2f UV1, UV2, UV3;
965  UV1(0) = -1.0; UV1(1) = -1.0;
966  UV2(0) = -1.0; UV2(1) = -1.0;
967  UV3(0) = -1.0; UV3(1) = -1.0;
968  mesh.tex_coordinates[cameras.size()].push_back(UV1);
969  mesh.tex_coordinates[cameras.size()].push_back(UV2);
970  mesh.tex_coordinates[cameras.size()].push_back(UV3);
971  }
972 
973 }
974 
975 ///////////////////////////////////////////////////////////////////////////////////////////////
976 template<typename PointInT> inline void
978 {
979  // we simplify the problem by translating the triangle's origin to its first point
980  pcl::PointXY ptB, ptC;
981  ptB.x = p2.x - p1.x; ptB.y = p2.y - p1.y; // B'=B-A
982  ptC.x = p3.x - p1.x; ptC.y = p3.y - p1.y; // C'=C-A
983 
984  double D = 2.0*(ptB.x*ptC.y - ptB.y*ptC.x); // D'=2(B'x*C'y - B'y*C'x)
985 
986  // Safety check to avoid division by zero
987  if(D == 0)
988  {
989  circomcenter.x = p1.x;
990  circomcenter.y = p1.y;
991  }
992  else
993  {
994  // compute squares once
995  double bx2 = ptB.x * ptB.x; // B'x^2
996  double by2 = ptB.y * ptB.y; // B'y^2
997  double cx2 = ptC.x * ptC.x; // C'x^2
998  double cy2 = ptC.y * ptC.y; // C'y^2
999 
1000  // compute circomcenter's coordinates (translate back to original coordinates)
1001  circomcenter.x = static_cast<float> (p1.x + (ptC.y*(bx2 + by2) - ptB.y*(cx2 + cy2)) / D);
1002  circomcenter.y = static_cast<float> (p1.y + (ptB.x*(cx2 + cy2) - ptC.x*(bx2 + by2)) / D);
1003  }
1004 
1005  radius = sqrt( (circomcenter.x - p1.x)*(circomcenter.x - p1.x) + (circomcenter.y - p1.y)*(circomcenter.y - p1.y));//2.0* (p1.x*(p2.y - p3.y) + p2.x*(p3.y - p1.y) + p3.x*(p1.y - p2.y));
1006 }
1007 
1008 ///////////////////////////////////////////////////////////////////////////////////////////////
1009 template<typename PointInT> inline void
1011 {
1012  // compute centroid's coordinates (translate back to original coordinates)
1013  circumcenter.x = static_cast<float> (p1.x + p2.x + p3.x ) / 3;
1014  circumcenter.y = static_cast<float> (p1.y + p2.y + p3.y ) / 3;
1015  double r1 = (circumcenter.x - p1.x) * (circumcenter.x - p1.x) + (circumcenter.y - p1.y) * (circumcenter.y - p1.y) ;
1016  double r2 = (circumcenter.x - p2.x) * (circumcenter.x - p2.x) + (circumcenter.y - p2.y) * (circumcenter.y - p2.y) ;
1017  double r3 = (circumcenter.x - p3.x) * (circumcenter.x - p3.x) + (circumcenter.y - p3.y) * (circumcenter.y - p3.y) ;
1018 
1019  // radius
1020  radius = std::sqrt( std::max( r1, std::max( r2, r3) )) ;
1021 }
1022 
1023 
1024 ///////////////////////////////////////////////////////////////////////////////////////////////
1025 template<typename PointInT> inline bool
1026 pcl::TextureMapping<PointInT>::getPointUVCoordinates(const PointInT &pt, const Camera &cam, pcl::PointXY &UV_coordinates)
1027 {
1028  if (pt.z > 0)
1029  {
1030  // compute image center and dimension
1031  double sizeX = cam.width;
1032  double sizeY = cam.height;
1033  double cx, cy;
1034  if (cam.center_w > 0)
1035  cx = cam.center_w;
1036  else
1037  cx = sizeX / 2.0;
1038  if (cam.center_h > 0)
1039  cy = cam.center_h;
1040  else
1041  cy = sizeY / 2.0;
1042 
1043  double focal_x, focal_y;
1044  if (cam.focal_length_w > 0)
1045  focal_x = cam.focal_length_w;
1046  else
1047  focal_x = cam.focal_length;
1048  if (cam.focal_length_h > 0)
1049  focal_y = cam.focal_length_h;
1050  else
1051  focal_y = cam.focal_length;
1052 
1053  // project point on camera's image plane
1054  UV_coordinates.x = static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX); //horizontal
1055  UV_coordinates.y = 1.0f - static_cast<float> ((focal_y * (pt.y / pt.z) + cy) / sizeY); //vertical
1056 
1057  // point is visible!
1058  if (UV_coordinates.x >= 0.0 && UV_coordinates.x <= 1.0 && UV_coordinates.y >= 0.0 && UV_coordinates.y <= 1.0)
1059  return (true); // point was visible by the camera
1060  }
1061 
1062  // point is NOT visible by the camera
1063  UV_coordinates.x = -1.0f;
1064  UV_coordinates.y = -1.0f;
1065  return (false); // point was not visible by the camera
1066 }
1067 
1068 ///////////////////////////////////////////////////////////////////////////////////////////////
1069 template<typename PointInT> inline bool
1071 {
1072  // Compute vectors
1073  Eigen::Vector2d v0, v1, v2;
1074  v0(0) = p3.x - p1.x; v0(1) = p3.y - p1.y; // v0= C - A
1075  v1(0) = p2.x - p1.x; v1(1) = p2.y - p1.y; // v1= B - A
1076  v2(0) = pt.x - p1.x; v2(1) = pt.y - p1.y; // v2= P - A
1077 
1078  // Compute dot products
1079  double dot00 = v0.dot(v0); // dot00 = dot(v0, v0)
1080  double dot01 = v0.dot(v1); // dot01 = dot(v0, v1)
1081  double dot02 = v0.dot(v2); // dot02 = dot(v0, v2)
1082  double dot11 = v1.dot(v1); // dot11 = dot(v1, v1)
1083  double dot12 = v1.dot(v2); // dot12 = dot(v1, v2)
1084 
1085  // Compute barycentric coordinates
1086  double invDenom = 1.0 / (dot00*dot11 - dot01*dot01);
1087  double u = (dot11*dot02 - dot01*dot12) * invDenom;
1088  double v = (dot00*dot12 - dot01*dot02) * invDenom;
1089 
1090  // Check if point is in triangle
1091  return ((u >= 0) && (v >= 0) && (u + v < 1));
1092 }
1093 
1094 ///////////////////////////////////////////////////////////////////////////////////////////////
1095 template<typename PointInT> inline bool
1096 pcl::TextureMapping<PointInT>::isFaceProjected (const Camera &camera, const PointInT &p1, const PointInT &p2, const PointInT &p3, pcl::PointXY &proj1, pcl::PointXY &proj2, pcl::PointXY &proj3)
1097 {
1098  return (getPointUVCoordinates(p1, camera, proj1)
1099  &&
1100  getPointUVCoordinates(p2, camera, proj2)
1101  &&
1102  getPointUVCoordinates(p3, camera, proj3)
1103  );
1104 }
1105 
1106 #define PCL_INSTANTIATE_TextureMapping(T) \
1107  template class PCL_EXPORTS pcl::TextureMapping<T>;
1108 
1109 #endif /* TEXTURE_MAPPING_HPP_ */
1110 
void mapMultipleTexturesToMeshUV(pcl::TextureMesh &tex_mesh, pcl::texture_mapping::CameraVector &cams)
Map textures acquired from a set of cameras onto a mesh.
void getTriangleCircumcscribedCircleCentroid(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circumcenter, double &radius)
Returns the centroid of a triangle and the corresponding circumscribed circle&#39;s radius.
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map...
Definition: conversions.h:168
KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures.
Definition: kdtree_flann.h:68
std::vector< std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > > > tex_coordinates
Definition: TextureMesh.h:100
void addPointsFromInputCloud()
Add points from input point cloud to octree.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:409
std::vector< Camera, Eigen::aligned_allocator< Camera > > CameraVector
void mapTexture2MeshUV(pcl::TextureMesh &tex_mesh)
Map texture to a mesh UV mapping.
PointCloud::ConstPtr PointCloudConstPtr
std::vector< pcl::TexMaterial > tex_materials
Definition: TextureMesh.h:101
void setInputCloud(const PointCloudConstPtr &cloud_arg, const IndicesConstPtr &indices_arg=IndicesConstPtr())
Provide a pointer to the input data set.
bool getPointUVCoordinates(const PointInT &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
computes UV coordinates of point, observed by one particular camera
void textureMeshwithMultipleCameras(pcl::TextureMesh &mesh, const pcl::texture_mapping::CameraVector &cameras)
Segment and texture faces by camera visibility.
void removeOccludedPoints(const PointCloudPtr &input_cloud, PointCloudPtr &filtered_cloud, const double octree_voxel_size, std::vector< int > &visible_indices, std::vector< int > &occluded_indices)
Remove occluded points from a point cloud.
A 2D point structure representing Euclidean xy coordinates.
float euclideanDistance(const PointType1 &p1, const PointType2 &p2)
Calculate the euclidean distance between the two given points.
Definition: distances.h:196
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:427
void mapTexture2Mesh(pcl::TextureMesh &tex_mesh)
Map texture to a mesh synthesis algorithm.
void defineBoundingBox()
Investigate dimensions of pointcloud data set and define corresponding bounding box for octree...
bool isFaceProjected(const Camera &camera, const PointInT &p1, const PointInT &p2, const PointInT &p3, pcl::PointXY &proj1, pcl::PointXY &proj2, pcl::PointXY &proj3)
Returns true if all the vertices of one face are projected on the camera&#39;s image plane.
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields=true)
Apply an affine transform defined by an Eigen Transform.
Definition: transforms.hpp:215
pcl::uint32_t width
bool isPointOccluded(const PointInT &pt, const OctreePtr octree)
Check if a point is occluded using raycasting on octree.
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset.
Structure to store camera pose and focal length.
Structure that links a uv coordinate to its 3D point and face.
int getIntersectedVoxelIndices(Eigen::Vector3f origin, Eigen::Vector3f direction, std::vector< int > &k_indices, int max_voxel_count=0) const
Get indices of all voxels that are intersected by a ray (origin, direction).
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > > mapTexture2Face(const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, const Eigen::Vector3f &p3)
Map texture to a face.
std::vector< ::pcl::PCLPointField > fields
int radiusSearch(const PointT &point, double radius, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
Search for all the nearest neighbors of the query point in a given radius.
pcl::uint32_t height
Octree pointcloud search class
Definition: octree_search.h:56
pcl::PCLPointCloud2 cloud
Definition: TextureMesh.h:95
void showOcclusions(const PointCloudPtr &input_cloud, pcl::PointCloud< pcl::PointXYZI >::Ptr &colored_cloud, const double octree_voxel_size, const bool show_nb_occlusions=true, const int max_occlusions=4)
Colors a point cloud, depending on its occlusions.
PointCloud::Ptr PointCloudPtr
void getTriangleCircumcenterAndSize(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circumcenter, double &radius)
Returns the circumcenter of a triangle and the circle&#39;s radius.
int sortFacesByCamera(pcl::TextureMesh &tex_mesh, pcl::TextureMesh &sorted_mesh, const pcl::texture_mapping::CameraVector &cameras, const double octree_voxel_size, PointCloud &visible_pts)
Segment faces by camera visibility.
bool checkPointInsideTriangle(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, const pcl::PointXY &pt)
Returns True if a point lays within a triangle.
std::vector< pcl::uint8_t > data
std::vector< std::vector< pcl::Vertices > > tex_polygons
Definition: TextureMesh.h:99