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 /= std::sqrt (p1p2.dot (p1p2));
59  p1p3 /= std::sqrt (p1p3.dot (p1p3));
60  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 /= 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 /= 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] -= min_x;
126  tp2[0] -= min_x;
127  tp3[0] -= min_x;
128  }
129  if (min_y < 0)
130  {
131  tp1[1] -= min_y;
132  tp2[1] -= min_y;
133  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 (std::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 (std::size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
165  {
166  std::size_t idx;
167 
168  // get facet information
169  for (std::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 (std::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 (std::size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
256  {
257  std::size_t idx;
258  Eigen::Vector2f tmp_VT;
259  for (std::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 (std::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 (std::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 (std::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  return (nbocc != 0);
405 }
406 
407 ///////////////////////////////////////////////////////////////////////////////////////////////
408 template<typename PointInT> void
410  PointCloudPtr &filtered_cloud,
411  const double octree_voxel_size, std::vector<int> &visible_indices,
412  std::vector<int> &occluded_indices)
413 {
414  // variable used to filter occluded points by depth
415  double maxDeltaZ = octree_voxel_size;
416 
417  // create an octree to perform rayTracing
418  OctreePtr octree (new Octree (octree_voxel_size));
419  // create octree structure
420  octree->setInputCloud (input_cloud);
421  // update bounding box automatically
422  octree->defineBoundingBox ();
423  // add points in the tree
424  octree->addPointsFromInputCloud ();
425 
426  visible_indices.clear ();
427 
428  // for each point of the cloud, raycast toward camera and check intersected voxels.
429  Eigen::Vector3f direction;
430  std::vector<int> indices;
431  for (std::size_t i = 0; i < input_cloud->points.size (); ++i)
432  {
433  direction (0) = input_cloud->points[i].x;
434  direction (1) = input_cloud->points[i].y;
435  direction (2) = input_cloud->points[i].z;
436 
437  // if point is not occluded
438  octree->getIntersectedVoxelIndices (direction, -direction, indices);
439 
440  int nbocc = static_cast<int> (indices.size ());
441  for (const int &index : indices)
442  {
443  // if intersected point is on the over side of the camera
444  if (input_cloud->points[i].z * input_cloud->points[index].z < 0)
445  {
446  nbocc--;
447  continue;
448  }
449 
450  if (std::fabs (input_cloud->points[index].z - input_cloud->points[i].z) <= maxDeltaZ)
451  {
452  // points are very close to each-other, we do not consider the occlusion
453  nbocc--;
454  }
455  }
456 
457  if (nbocc == 0)
458  {
459  // point is added in the filtered mesh
460  filtered_cloud->points.push_back (input_cloud->points[i]);
461  visible_indices.push_back (static_cast<int> (i));
462  }
463  else
464  {
465  occluded_indices.push_back (static_cast<int> (i));
466  }
467  }
468 
469 }
470 
471 ///////////////////////////////////////////////////////////////////////////////////////////////
472 template<typename PointInT> void
473 pcl::TextureMapping<PointInT>::removeOccludedPoints (const pcl::TextureMesh &tex_mesh, pcl::TextureMesh &cleaned_mesh, const double octree_voxel_size)
474 {
475  // copy mesh
476  cleaned_mesh = tex_mesh;
477 
479  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
480 
481  // load points into a PCL format
482  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
483 
484  std::vector<int> visible, occluded;
485  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
486 
487  // Now that we know which points are visible, let's iterate over each face.
488  // if the face has one invisible point => out!
489  for (std::size_t polygons = 0; polygons < cleaned_mesh.tex_polygons.size (); ++polygons)
490  {
491  // remove all faces from cleaned mesh
492  cleaned_mesh.tex_polygons[polygons].clear ();
493  // iterate over faces
494  for (std::size_t faces = 0; faces < tex_mesh.tex_polygons[polygons].size (); ++faces)
495  {
496  // check if all the face's points are visible
497  bool faceIsVisible = true;
498  std::vector<int>::iterator it;
499 
500  // iterate over face's vertex
501  for (const unsigned int &vertex : tex_mesh.tex_polygons[polygons][faces].vertices)
502  {
503  it = find (occluded.begin (), occluded.end (), vertex);
504 
505  if (it == occluded.end ())
506  {
507  // point is not in the occluded vector
508  // PCL_INFO (" VISIBLE!\n");
509  }
510  else
511  {
512  // point was occluded
513  // PCL_INFO(" OCCLUDED!\n");
514  faceIsVisible = false;
515  }
516  }
517 
518  if (faceIsVisible)
519  {
520  cleaned_mesh.tex_polygons[polygons].push_back (tex_mesh.tex_polygons[polygons][faces]);
521  }
522 
523  }
524  }
525 }
526 
527 ///////////////////////////////////////////////////////////////////////////////////////////////
528 template<typename PointInT> void
530  const double octree_voxel_size)
531 {
532  PointCloudPtr cloud (new PointCloud);
533 
534  // load points into a PCL format
535  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
536 
537  std::vector<int> visible, occluded;
538  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
539 
540 }
541 
542 ///////////////////////////////////////////////////////////////////////////////////////////////
543 template<typename PointInT> int
545  const pcl::texture_mapping::CameraVector &cameras, const double octree_voxel_size,
546  PointCloud &visible_pts)
547 {
548  if (tex_mesh.tex_polygons.size () != 1)
549  {
550  PCL_ERROR ("The mesh must contain only 1 sub-mesh!\n");
551  return (-1);
552  }
553 
554  if (cameras.empty ())
555  {
556  PCL_ERROR ("Must provide at least one camera info!\n");
557  return (-1);
558  }
559 
560  // copy mesh
561  sorted_mesh = tex_mesh;
562  // clear polygons from cleaned_mesh
563  sorted_mesh.tex_polygons.clear ();
564 
565  typename pcl::PointCloud<PointInT>::Ptr original_cloud (new pcl::PointCloud<PointInT>);
566  typename pcl::PointCloud<PointInT>::Ptr transformed_cloud (new pcl::PointCloud<PointInT>);
567  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
568 
569  // load points into a PCL format
570  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *original_cloud);
571 
572  // for each camera
573  for (const auto &camera : cameras)
574  {
575  // get camera pose as transform
576  Eigen::Affine3f cam_trans = camera.pose;
577 
578  // transform original cloud in camera coordinates
579  pcl::transformPointCloud (*original_cloud, *transformed_cloud, cam_trans.inverse ());
580 
581  // find occlusions on transformed cloud
582  std::vector<int> visible, occluded;
583  removeOccludedPoints (transformed_cloud, filtered_cloud, octree_voxel_size, visible, occluded);
584  visible_pts = *filtered_cloud;
585 
586  // find visible faces => add them to polygon N for camera N
587  // add polygon group for current camera in clean
588  std::vector<pcl::Vertices> visibleFaces_currentCam;
589  // iterate over the faces of the current mesh
590  for (std::size_t faces = 0; faces < tex_mesh.tex_polygons[0].size (); ++faces)
591  {
592  // check if all the face's points are visible
593  bool faceIsVisible = true;
594  std::vector<int>::iterator it;
595 
596  // iterate over face's vertex
597  for (std::size_t current_pt_indice = 0; faceIsVisible && current_pt_indice < tex_mesh.tex_polygons[0][faces].vertices.size (); ++current_pt_indice)
598  {
599  // TODO this is far too long! Better create an helper function that raycasts here.
600  it = find (occluded.begin (), occluded.end (), tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]);
601 
602  if (it == occluded.end ())
603  {
604  // point is not occluded
605  // does it land on the camera's image plane?
606  PointInT pt = transformed_cloud->points[tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]];
607  Eigen::Vector2f dummy_UV;
608  if (!getPointUVCoordinates (pt, camera, dummy_UV))
609  {
610  // point is not visible by the camera
611  faceIsVisible = false;
612  }
613  }
614  else
615  {
616  faceIsVisible = false;
617  }
618  }
619 
620  if (faceIsVisible)
621  {
622  // push current visible face into the sorted mesh
623  visibleFaces_currentCam.push_back (tex_mesh.tex_polygons[0][faces]);
624  // remove it from the unsorted mesh
625  tex_mesh.tex_polygons[0].erase (tex_mesh.tex_polygons[0].begin () + faces);
626  faces--;
627  }
628 
629  }
630  sorted_mesh.tex_polygons.push_back (visibleFaces_currentCam);
631  }
632 
633  // we should only have occluded and non-visible faces left in tex_mesh.tex_polygons[0]
634  // we need to add them as an extra polygon in the sorted mesh
635  sorted_mesh.tex_polygons.push_back (tex_mesh.tex_polygons[0]);
636  return (0);
637 }
638 
639 ///////////////////////////////////////////////////////////////////////////////////////////////
640 template<typename PointInT> void
643  const double octree_voxel_size, const bool show_nb_occlusions,
644  const int max_occlusions)
645  {
646  // variable used to filter occluded points by depth
647  double maxDeltaZ = octree_voxel_size * 2.0;
648 
649  // create an octree to perform rayTracing
651  octree = new pcl::octree::OctreePointCloudSearch<PointInT> (octree_voxel_size);
652  // create octree structure
653  octree->setInputCloud (input_cloud);
654  // update bounding box automatically
655  octree->defineBoundingBox ();
656  // add points in the tree
657  octree->addPointsFromInputCloud ();
658 
659  // ray direction
660  Eigen::Vector3f direction;
661 
662  std::vector<int> indices;
663  // point from where we ray-trace
664  pcl::PointXYZI pt;
665 
666  std::vector<double> zDist;
667  std::vector<double> ptDist;
668  // for each point of the cloud, ray-trace toward the camera and check intersected voxels.
669  for (std::size_t i = 0; i < input_cloud->points.size (); ++i)
670  {
671  direction (0) = input_cloud->points[i].x;
672  pt.x = input_cloud->points[i].x;
673  direction (1) = input_cloud->points[i].y;
674  pt.y = input_cloud->points[i].y;
675  direction (2) = input_cloud->points[i].z;
676  pt.z = input_cloud->points[i].z;
677 
678  // get number of occlusions for that point
679  indices.clear ();
680  int nbocc = octree->getIntersectedVoxelIndices (direction, -direction, indices);
681 
682  nbocc = static_cast<int> (indices.size ());
683 
684  // TODO need to clean this up and find tricks to get remove aliasaing effect on planes
685  for (const int &index : indices)
686  {
687  // if intersected point is on the over side of the camera
688  if (pt.z * input_cloud->points[index].z < 0)
689  {
690  nbocc--;
691  }
692  else if (std::fabs (input_cloud->points[index].z - pt.z) <= maxDeltaZ)
693  {
694  // points are very close to each-other, we do not consider the occlusion
695  nbocc--;
696  }
697  else
698  {
699  zDist.push_back (std::fabs (input_cloud->points[index].z - pt.z));
700  ptDist.push_back (pcl::euclideanDistance (input_cloud->points[index], pt));
701  }
702  }
703 
704  if (show_nb_occlusions)
705  (nbocc <= max_occlusions) ? (pt.intensity = static_cast<float> (nbocc)) : (pt.intensity = static_cast<float> (max_occlusions));
706  else
707  (nbocc == 0) ? (pt.intensity = 0) : (pt.intensity = 1);
708 
709  colored_cloud->points.push_back (pt);
710  }
711 
712  if (zDist.size () >= 2)
713  {
714  std::sort (zDist.begin (), zDist.end ());
715  std::sort (ptDist.begin (), ptDist.end ());
716  }
717 }
718 
719 ///////////////////////////////////////////////////////////////////////////////////////////////
720 template<typename PointInT> void
722  double octree_voxel_size, bool show_nb_occlusions, int max_occlusions)
723 {
724  // load points into a PCL format
726  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
727 
728  showOcclusions (cloud, colored_cloud, octree_voxel_size, show_nb_occlusions, max_occlusions);
729 }
730 
731 ///////////////////////////////////////////////////////////////////////////////////////////////
732 template<typename PointInT> void
734 {
735 
736  if (mesh.tex_polygons.size () != 1)
737  return;
738 
740 
741  pcl::fromPCLPointCloud2 (mesh.cloud, *mesh_cloud);
742 
743  std::vector<pcl::Vertices> faces;
744 
745  for (int current_cam = 0; current_cam < static_cast<int> (cameras.size ()); ++current_cam)
746  {
747  PCL_INFO ("Processing camera %d of %d.\n", current_cam+1, cameras.size ());
748 
749  // transform mesh into camera's frame
750  typename pcl::PointCloud<PointInT>::Ptr camera_cloud (new pcl::PointCloud<PointInT>);
751  pcl::transformPointCloud (*mesh_cloud, *camera_cloud, cameras[current_cam].pose.inverse ());
752 
753  // CREATE UV MAP FOR CURRENT FACES
755  std::vector<bool> visibility;
756  visibility.resize (mesh.tex_polygons[current_cam].size ());
757  std::vector<UvIndex> indexes_uv_to_points;
758  // for each current face
759 
760  //TODO change this
761  pcl::PointXY nan_point;
762  nan_point.x = std::numeric_limits<float>::quiet_NaN ();
763  nan_point.y = std::numeric_limits<float>::quiet_NaN ();
764  UvIndex u_null;
765  u_null.idx_cloud = -1;
766  u_null.idx_face = -1;
767 
768  int cpt_invisible=0;
769  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[current_cam].size ()); ++idx_face)
770  {
771  //project each vertice, if one is out of view, stop
772  pcl::PointXY uv_coord1;
773  pcl::PointXY uv_coord2;
774  pcl::PointXY uv_coord3;
775 
776  if (isFaceProjected (cameras[current_cam],
777  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[0]],
778  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[1]],
779  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[2]],
780  uv_coord1,
781  uv_coord2,
782  uv_coord3))
783  {
784  // face is in the camera's FOV
785 
786  // add UV coordinates
787  projections->points.push_back (uv_coord1);
788  projections->points.push_back (uv_coord2);
789  projections->points.push_back (uv_coord3);
790 
791  // remember corresponding face
792  UvIndex u1, u2, u3;
793  u1.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[0];
794  u2.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[1];
795  u3.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[2];
796  u1.idx_face = idx_face; u2.idx_face = idx_face; u3.idx_face = idx_face;
797  indexes_uv_to_points.push_back (u1);
798  indexes_uv_to_points.push_back (u2);
799  indexes_uv_to_points.push_back (u3);
800 
801  //keep track of visibility
802  visibility[idx_face] = true;
803  }
804  else
805  {
806  projections->points.push_back (nan_point);
807  projections->points.push_back (nan_point);
808  projections->points.push_back (nan_point);
809  indexes_uv_to_points.push_back (u_null);
810  indexes_uv_to_points.push_back (u_null);
811  indexes_uv_to_points.push_back (u_null);
812  //keep track of visibility
813  visibility[idx_face] = false;
814  cpt_invisible++;
815  }
816  }
817 
818  // projections contains all UV points of the current faces
819  // indexes_uv_to_points links a uv point to its point in the camera cloud
820  // visibility contains tells if a face was in the camera FOV (false = skip)
821 
822  // TODO handle case were no face could be projected
823  if (visibility.size () - cpt_invisible !=0)
824  {
825  //create kdtree
827  kdtree.setInputCloud (projections);
828 
829  std::vector<int> idxNeighbors;
830  std::vector<float> neighborsSquaredDistance;
831  // af first (idx_pcan < current_cam), check if some of the faces attached to previous cameras occlude the current faces
832  // then (idx_pcam == current_cam), check for self occlusions. At this stage, we skip faces that were already marked as occluded
833  cpt_invisible = 0;
834  for (int idx_pcam = 0 ; idx_pcam <= current_cam ; ++idx_pcam)
835  {
836  // project all faces
837  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[idx_pcam].size ()); ++idx_face)
838  {
839 
840  if (idx_pcam == current_cam && !visibility[idx_face])
841  {
842  // we are now checking for self occlusions within the current faces
843  // the current face was already declared as occluded.
844  // therefore, it cannot occlude another face anymore => we skip it
845  continue;
846  }
847 
848  // project each vertice, if one is out of view, stop
849  pcl::PointXY uv_coord1;
850  pcl::PointXY uv_coord2;
851  pcl::PointXY uv_coord3;
852 
853  if (isFaceProjected (cameras[current_cam],
854  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]],
855  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]],
856  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]],
857  uv_coord1,
858  uv_coord2,
859  uv_coord3))
860  {
861  // face is in the camera's FOV
862  //get its circumsribed circle
863  double radius;
864  pcl::PointXY center;
865  // getTriangleCircumcenterAndSize (uv_coord1, uv_coord2, uv_coord3, center, radius);
866  getTriangleCircumcscribedCircleCentroid(uv_coord1, uv_coord2, uv_coord3, center, radius); // this function yields faster results than getTriangleCircumcenterAndSize
867 
868  // get points inside circ.circle
869  if (kdtree.radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
870  {
871  // for each neighbor
872  for (const int &idxNeighbor : idxNeighbors)
873  {
874  if (std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]].z,
875  std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]].z,
876  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]].z))
877  < camera_cloud->points[indexes_uv_to_points[idxNeighbor].idx_cloud].z)
878  {
879  // neighbor is farther than all the face's points. Check if it falls into the triangle
880  if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbor]))
881  {
882  // current neighbor is inside triangle and is closer => the corresponding face
883  visibility[indexes_uv_to_points[idxNeighbor].idx_face] = false;
884  cpt_invisible++;
885  //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
886  }
887  }
888  }
889  }
890  }
891  }
892  }
893  }
894 
895  // now, visibility is true for each face that belongs to the current camera
896  // if a face is not visible, we push it into the next one.
897 
898  if (static_cast<int> (mesh.tex_coordinates.size ()) <= current_cam)
899  {
900  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
901  mesh.tex_coordinates.push_back (dummy_container);
902  }
903  mesh.tex_coordinates[current_cam].resize (3 * visibility.size ());
904 
905  std::vector<pcl::Vertices> occluded_faces;
906  occluded_faces.resize (visibility.size ());
907  std::vector<pcl::Vertices> visible_faces;
908  visible_faces.resize (visibility.size ());
909 
910  int cpt_occluded_faces = 0;
911  int cpt_visible_faces = 0;
912 
913  for (std::size_t idx_face = 0 ; idx_face < visibility.size () ; ++idx_face)
914  {
915  if (visibility[idx_face])
916  {
917  // face is visible by the current camera copy UV coordinates
918  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](0) = projections->points[idx_face*3].x;
919  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](1) = projections->points[idx_face*3].y;
920 
921  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](0) = projections->points[idx_face*3 + 1].x;
922  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](1) = projections->points[idx_face*3 + 1].y;
923 
924  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](0) = projections->points[idx_face*3 + 2].x;
925  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](1) = projections->points[idx_face*3 + 2].y;
926 
927  visible_faces[cpt_visible_faces] = mesh.tex_polygons[current_cam][idx_face];
928 
929  cpt_visible_faces++;
930  }
931  else
932  {
933  // face is occluded copy face into temp vector
934  occluded_faces[cpt_occluded_faces] = mesh.tex_polygons[current_cam][idx_face];
935  cpt_occluded_faces++;
936  }
937  }
938  mesh.tex_coordinates[current_cam].resize (cpt_visible_faces*3);
939 
940  occluded_faces.resize (cpt_occluded_faces);
941  mesh.tex_polygons.push_back (occluded_faces);
942 
943  visible_faces.resize (cpt_visible_faces);
944  mesh.tex_polygons[current_cam].clear ();
945  mesh.tex_polygons[current_cam] = visible_faces;
946  }
947 
948  // we have been through all the cameras.
949  // if any faces are left, they were not visible by any camera
950  // we still need to produce uv coordinates for them
951 
952  if (mesh.tex_coordinates.size() <= cameras.size ())
953  {
954  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
955  mesh.tex_coordinates.push_back(dummy_container);
956  }
957 
958 
959  for(std::size_t idx_face = 0 ; idx_face < mesh.tex_polygons[cameras.size()].size() ; ++idx_face)
960  {
961  Eigen::Vector2f UV1, UV2, UV3;
962  UV1(0) = -1.0; UV1(1) = -1.0;
963  UV2(0) = -1.0; UV2(1) = -1.0;
964  UV3(0) = -1.0; UV3(1) = -1.0;
965  mesh.tex_coordinates[cameras.size()].push_back(UV1);
966  mesh.tex_coordinates[cameras.size()].push_back(UV2);
967  mesh.tex_coordinates[cameras.size()].push_back(UV3);
968  }
969 
970 }
971 
972 ///////////////////////////////////////////////////////////////////////////////////////////////
973 template<typename PointInT> inline void
975 {
976  // we simplify the problem by translating the triangle's origin to its first point
977  pcl::PointXY ptB, ptC;
978  ptB.x = p2.x - p1.x; ptB.y = p2.y - p1.y; // B'=B-A
979  ptC.x = p3.x - p1.x; ptC.y = p3.y - p1.y; // C'=C-A
980 
981  double D = 2.0*(ptB.x*ptC.y - ptB.y*ptC.x); // D'=2(B'x*C'y - B'y*C'x)
982 
983  // Safety check to avoid division by zero
984  if(D == 0)
985  {
986  circomcenter.x = p1.x;
987  circomcenter.y = p1.y;
988  }
989  else
990  {
991  // compute squares once
992  double bx2 = ptB.x * ptB.x; // B'x^2
993  double by2 = ptB.y * ptB.y; // B'y^2
994  double cx2 = ptC.x * ptC.x; // C'x^2
995  double cy2 = ptC.y * ptC.y; // C'y^2
996 
997  // compute circomcenter's coordinates (translate back to original coordinates)
998  circomcenter.x = static_cast<float> (p1.x + (ptC.y*(bx2 + by2) - ptB.y*(cx2 + cy2)) / D);
999  circomcenter.y = static_cast<float> (p1.y + (ptB.x*(cx2 + cy2) - ptC.x*(bx2 + by2)) / D);
1000  }
1001 
1002  radius = std::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));
1003 }
1004 
1005 ///////////////////////////////////////////////////////////////////////////////////////////////
1006 template<typename PointInT> inline void
1008 {
1009  // compute centroid's coordinates (translate back to original coordinates)
1010  circumcenter.x = static_cast<float> (p1.x + p2.x + p3.x ) / 3;
1011  circumcenter.y = static_cast<float> (p1.y + p2.y + p3.y ) / 3;
1012  double r1 = (circumcenter.x - p1.x) * (circumcenter.x - p1.x) + (circumcenter.y - p1.y) * (circumcenter.y - p1.y) ;
1013  double r2 = (circumcenter.x - p2.x) * (circumcenter.x - p2.x) + (circumcenter.y - p2.y) * (circumcenter.y - p2.y) ;
1014  double r3 = (circumcenter.x - p3.x) * (circumcenter.x - p3.x) + (circumcenter.y - p3.y) * (circumcenter.y - p3.y) ;
1015 
1016  // radius
1017  radius = std::sqrt( std::max( r1, std::max( r2, r3) )) ;
1018 }
1019 
1020 
1021 ///////////////////////////////////////////////////////////////////////////////////////////////
1022 template<typename PointInT> inline bool
1023 pcl::TextureMapping<PointInT>::getPointUVCoordinates(const PointInT &pt, const Camera &cam, pcl::PointXY &UV_coordinates)
1024 {
1025  if (pt.z > 0)
1026  {
1027  // compute image center and dimension
1028  double sizeX = cam.width;
1029  double sizeY = cam.height;
1030  double cx, cy;
1031  if (cam.center_w > 0)
1032  cx = cam.center_w;
1033  else
1034  cx = sizeX / 2.0;
1035  if (cam.center_h > 0)
1036  cy = cam.center_h;
1037  else
1038  cy = sizeY / 2.0;
1039 
1040  double focal_x, focal_y;
1041  if (cam.focal_length_w > 0)
1042  focal_x = cam.focal_length_w;
1043  else
1044  focal_x = cam.focal_length;
1045  if (cam.focal_length_h > 0)
1046  focal_y = cam.focal_length_h;
1047  else
1048  focal_y = cam.focal_length;
1049 
1050  // project point on camera's image plane
1051  UV_coordinates.x = static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX); //horizontal
1052  UV_coordinates.y = 1.0f - static_cast<float> ((focal_y * (pt.y / pt.z) + cy) / sizeY); //vertical
1053 
1054  // point is visible!
1055  if (UV_coordinates.x >= 0.0 && UV_coordinates.x <= 1.0 && UV_coordinates.y >= 0.0 && UV_coordinates.y <= 1.0)
1056  return (true); // point was visible by the camera
1057  }
1058 
1059  // point is NOT visible by the camera
1060  UV_coordinates.x = -1.0f;
1061  UV_coordinates.y = -1.0f;
1062  return (false); // point was not visible by the camera
1063 }
1064 
1065 ///////////////////////////////////////////////////////////////////////////////////////////////
1066 template<typename PointInT> inline bool
1068 {
1069  // Compute vectors
1070  Eigen::Vector2d v0, v1, v2;
1071  v0(0) = p3.x - p1.x; v0(1) = p3.y - p1.y; // v0= C - A
1072  v1(0) = p2.x - p1.x; v1(1) = p2.y - p1.y; // v1= B - A
1073  v2(0) = pt.x - p1.x; v2(1) = pt.y - p1.y; // v2= P - A
1074 
1075  // Compute dot products
1076  double dot00 = v0.dot(v0); // dot00 = dot(v0, v0)
1077  double dot01 = v0.dot(v1); // dot01 = dot(v0, v1)
1078  double dot02 = v0.dot(v2); // dot02 = dot(v0, v2)
1079  double dot11 = v1.dot(v1); // dot11 = dot(v1, v1)
1080  double dot12 = v1.dot(v2); // dot12 = dot(v1, v2)
1081 
1082  // Compute barycentric coordinates
1083  double invDenom = 1.0 / (dot00*dot11 - dot01*dot01);
1084  double u = (dot11*dot02 - dot01*dot12) * invDenom;
1085  double v = (dot00*dot12 - dot01*dot02) * invDenom;
1086 
1087  // Check if point is in triangle
1088  return ((u >= 0) && (v >= 0) && (u + v < 1));
1089 }
1090 
1091 ///////////////////////////////////////////////////////////////////////////////////////////////
1092 template<typename PointInT> inline bool
1093 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)
1094 {
1095  return (getPointUVCoordinates(p1, camera, proj1)
1096  &&
1097  getPointUVCoordinates(p2, camera, proj2)
1098  &&
1099  getPointUVCoordinates(p3, camera, proj3)
1100  );
1101 }
1102 
1103 #define PCL_INSTANTIATE_TextureMapping(T) \
1104  template class PCL_EXPORTS pcl::TextureMapping<T>;
1105 
1106 #endif /* TEXTURE_MAPPING_HPP_ */
1107 
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:67
std::vector< std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > > > tex_coordinates
Definition: TextureMesh.h:95
std::vector<::pcl::PCLPointField > fields
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:394
void mapTexture2MeshUV(pcl::TextureMesh &tex_mesh)
Map texture to a mesh UV mapping.
std::vector< pcl::TexMaterial > tex_materials
Definition: TextureMesh.h:96
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.
Define standard C methods to do distance calculations.
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.
std::uint32_t height
float euclideanDistance(const PointType1 &p1, const PointType2 &p2)
Calculate the euclidean distance between the two given points.
Definition: distances.h:200
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...
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).
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
bool isPointOccluded(const PointInT &pt, const OctreePtr octree)
Check if a point is occluded using raycasting on octree.
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:412
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.
typename Octree::Ptr OctreePtr
std::vector< Camera, Eigen::aligned_allocator< Camera > > CameraVector
Structure that links a uv coordinate to its 3D point and face.
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::uint32_t width
std::vector< std::uint8_t > data
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.
typename PointCloud::Ptr PointCloudPtr
Octree pointcloud search class
Definition: octree_search.h:56
pcl::PCLPointCloud2 cloud
Definition: TextureMesh.h:90
typename PointCloud::ConstPtr PointCloudConstPtr
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.
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< std::vector< pcl::Vertices > > tex_polygons
Definition: TextureMesh.h:94