Point Cloud Library (PCL)  1.10.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  Eigen::Vector2f tmp_VT;
258  for (std::size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
259  {
260  std::size_t idx = tex_mesh.tex_polygons[m][i].vertices[j];
261  memcpy (&x_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
262  memcpy (&y_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
263  memcpy (&z_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
264 
265  // calculate uv coordinates
266  tmp_VT[0] = (x_ + x_offset) / x_range;
267  tmp_VT[1] = (z_ + z_offset) / z_range;
268  texture_map_tmp.push_back (tmp_VT);
269  }
270  }// end faces
271 
272  // texture materials
273  std::stringstream tex_name;
274  tex_name << "material_" << m;
275  tex_name >> tex_material_.tex_name;
276  tex_material_.tex_file = tex_files_[m];
277  tex_mesh.tex_materials.push_back (tex_material_);
278 
279  // texture coordinates
280  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
281  }// end meshes
282 }
283 
284 ///////////////////////////////////////////////////////////////////////////////////////////////
285 template<typename PointInT> void
287 {
288 
289  if (tex_mesh.tex_polygons.size () != cams.size () + 1)
290  {
291  PCL_ERROR ("The mesh should be divided into nbCamera+1 sub-meshes.\n");
292  PCL_ERROR ("You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.tex_polygons.size ());
293  return;
294  }
295 
296  PCL_INFO ("You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.tex_polygons.size ());
297 
298  typename pcl::PointCloud<PointInT>::Ptr originalCloud (new pcl::PointCloud<PointInT>);
299  typename pcl::PointCloud<PointInT>::Ptr camera_transformed_cloud (new pcl::PointCloud<PointInT>);
300 
301  // convert mesh's cloud to pcl format for ease
302  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *originalCloud);
303 
304  for (std::size_t m = 0; m < cams.size (); ++m)
305  {
306  // get current camera parameters
307  Camera current_cam = cams[m];
308 
309  // get camera transform
310  Eigen::Affine3f cam_trans = current_cam.pose;
311 
312  // transform cloud into current camera frame
313  pcl::transformPointCloud (*originalCloud, *camera_transformed_cloud, cam_trans.inverse ());
314 
315  // vector of texture coordinates for each face
316  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
317 
318  // processing each face visible by this camera
319  for (const auto &tex_polygon : tex_mesh.tex_polygons[m])
320  {
321  Eigen::Vector2f tmp_VT;
322  // for each point of this face
323  for (const unsigned int &vertex : tex_polygon.vertices)
324  {
325  // get point
326  PointInT pt = camera_transformed_cloud->points[vertex];
327 
328  // compute UV coordinates for this point
329  getPointUVCoordinates (pt, current_cam, tmp_VT);
330  texture_map_tmp.push_back (tmp_VT);
331  }// end points
332  }// end faces
333 
334  // texture materials
335  std::stringstream tex_name;
336  tex_name << "material_" << m;
337  tex_name >> tex_material_.tex_name;
338  tex_material_.tex_file = current_cam.texture_file;
339  tex_mesh.tex_materials.push_back (tex_material_);
340 
341  // texture coordinates
342  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
343  }// end cameras
344 
345  // push on extra empty UV map (for unseen faces) so that obj writer does not crash!
346  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
347  for (const auto &tex_polygon : tex_mesh.tex_polygons[cams.size ()])
348  for (std::size_t j = 0; j < tex_polygon.vertices.size (); ++j)
349  {
350  Eigen::Vector2f tmp_VT;
351  tmp_VT[0] = -1;
352  tmp_VT[1] = -1;
353  texture_map_tmp.push_back (tmp_VT);
354  }
355 
356  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
357 
358  // push on an extra dummy material for the same reason
359  tex_material_.tex_name = "material_" + std::to_string(cams.size());
360  tex_material_.tex_file = "occluded.jpg";
361  tex_mesh.tex_materials.push_back (tex_material_);
362 }
363 
364 ///////////////////////////////////////////////////////////////////////////////////////////////
365 template<typename PointInT> bool
367 {
368  Eigen::Vector3f direction;
369  direction (0) = pt.x;
370  direction (1) = pt.y;
371  direction (2) = pt.z;
372 
373  std::vector<int> indices;
374 
375  PointCloudConstPtr cloud (new PointCloud());
376  cloud = octree->getInputCloud();
377 
378  double distance_threshold = octree->getResolution();
379 
380  // raytrace
381  octree->getIntersectedVoxelIndices(direction, -direction, indices);
382 
383  int nbocc = static_cast<int> (indices.size ());
384  for (const int &index : indices)
385  {
386  // if intersected point is on the over side of the camera
387  if (pt.z * cloud->points[index].z < 0)
388  {
389  nbocc--;
390  continue;
391  }
392 
393  if (std::fabs (cloud->points[index].z - pt.z) <= distance_threshold)
394  {
395  // points are very close to each-other, we do not consider the occlusion
396  nbocc--;
397  }
398  }
399 
400  return (nbocc != 0);
401 }
402 
403 ///////////////////////////////////////////////////////////////////////////////////////////////
404 template<typename PointInT> void
406  PointCloudPtr &filtered_cloud,
407  const double octree_voxel_size, std::vector<int> &visible_indices,
408  std::vector<int> &occluded_indices)
409 {
410  // variable used to filter occluded points by depth
411  double maxDeltaZ = octree_voxel_size;
412 
413  // create an octree to perform rayTracing
414  Octree octree (octree_voxel_size);
415  // create octree structure
416  octree.setInputCloud (input_cloud);
417  // update bounding box automatically
418  octree.defineBoundingBox ();
419  // add points in the tree
420  octree.addPointsFromInputCloud ();
421 
422  visible_indices.clear ();
423 
424  // for each point of the cloud, raycast toward camera and check intersected voxels.
425  Eigen::Vector3f direction;
426  std::vector<int> indices;
427  for (std::size_t i = 0; i < input_cloud->points.size (); ++i)
428  {
429  direction (0) = input_cloud->points[i].x;
430  direction (1) = input_cloud->points[i].y;
431  direction (2) = input_cloud->points[i].z;
432 
433  // if point is not occluded
434  octree.getIntersectedVoxelIndices (direction, -direction, indices);
435 
436  int nbocc = static_cast<int> (indices.size ());
437  for (const int &index : indices)
438  {
439  // if intersected point is on the over side of the camera
440  if (input_cloud->points[i].z * input_cloud->points[index].z < 0)
441  {
442  nbocc--;
443  continue;
444  }
445 
446  if (std::fabs (input_cloud->points[index].z - input_cloud->points[i].z) <= maxDeltaZ)
447  {
448  // points are very close to each-other, we do not consider the occlusion
449  nbocc--;
450  }
451  }
452 
453  if (nbocc == 0)
454  {
455  // point is added in the filtered mesh
456  filtered_cloud->points.push_back (input_cloud->points[i]);
457  visible_indices.push_back (static_cast<int> (i));
458  }
459  else
460  {
461  occluded_indices.push_back (static_cast<int> (i));
462  }
463  }
464 
465 }
466 
467 ///////////////////////////////////////////////////////////////////////////////////////////////
468 template<typename PointInT> void
469 pcl::TextureMapping<PointInT>::removeOccludedPoints (const pcl::TextureMesh &tex_mesh, pcl::TextureMesh &cleaned_mesh, const double octree_voxel_size)
470 {
471  // copy mesh
472  cleaned_mesh = tex_mesh;
473 
475  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
476 
477  // load points into a PCL format
478  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
479 
480  std::vector<int> visible, occluded;
481  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
482 
483  // Now that we know which points are visible, let's iterate over each face.
484  // if the face has one invisible point => out!
485  for (std::size_t polygons = 0; polygons < cleaned_mesh.tex_polygons.size (); ++polygons)
486  {
487  // remove all faces from cleaned mesh
488  cleaned_mesh.tex_polygons[polygons].clear ();
489  // iterate over faces
490  for (std::size_t faces = 0; faces < tex_mesh.tex_polygons[polygons].size (); ++faces)
491  {
492  // check if all the face's points are visible
493  bool faceIsVisible = true;
494  std::vector<int>::iterator it;
495 
496  // iterate over face's vertex
497  for (const unsigned int &vertex : tex_mesh.tex_polygons[polygons][faces].vertices)
498  {
499  it = find (occluded.begin (), occluded.end (), vertex);
500 
501  if (it == occluded.end ())
502  {
503  // point is not in the occluded vector
504  // PCL_INFO (" VISIBLE!\n");
505  }
506  else
507  {
508  // point was occluded
509  // PCL_INFO(" OCCLUDED!\n");
510  faceIsVisible = false;
511  }
512  }
513 
514  if (faceIsVisible)
515  {
516  cleaned_mesh.tex_polygons[polygons].push_back (tex_mesh.tex_polygons[polygons][faces]);
517  }
518 
519  }
520  }
521 }
522 
523 ///////////////////////////////////////////////////////////////////////////////////////////////
524 template<typename PointInT> void
526  const double octree_voxel_size)
527 {
528  PointCloudPtr cloud (new PointCloud);
529 
530  // load points into a PCL format
531  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
532 
533  std::vector<int> visible, occluded;
534  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
535 
536 }
537 
538 ///////////////////////////////////////////////////////////////////////////////////////////////
539 template<typename PointInT> int
541  const pcl::texture_mapping::CameraVector &cameras, const double octree_voxel_size,
542  PointCloud &visible_pts)
543 {
544  if (tex_mesh.tex_polygons.size () != 1)
545  {
546  PCL_ERROR ("The mesh must contain only 1 sub-mesh!\n");
547  return (-1);
548  }
549 
550  if (cameras.empty ())
551  {
552  PCL_ERROR ("Must provide at least one camera info!\n");
553  return (-1);
554  }
555 
556  // copy mesh
557  sorted_mesh = tex_mesh;
558  // clear polygons from cleaned_mesh
559  sorted_mesh.tex_polygons.clear ();
560 
561  typename pcl::PointCloud<PointInT>::Ptr original_cloud (new pcl::PointCloud<PointInT>);
562  typename pcl::PointCloud<PointInT>::Ptr transformed_cloud (new pcl::PointCloud<PointInT>);
563  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
564 
565  // load points into a PCL format
566  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *original_cloud);
567 
568  // for each camera
569  for (const auto &camera : cameras)
570  {
571  // get camera pose as transform
572  Eigen::Affine3f cam_trans = camera.pose;
573 
574  // transform original cloud in camera coordinates
575  pcl::transformPointCloud (*original_cloud, *transformed_cloud, cam_trans.inverse ());
576 
577  // find occlusions on transformed cloud
578  std::vector<int> visible, occluded;
579  removeOccludedPoints (transformed_cloud, filtered_cloud, octree_voxel_size, visible, occluded);
580  visible_pts = *filtered_cloud;
581 
582  // find visible faces => add them to polygon N for camera N
583  // add polygon group for current camera in clean
584  std::vector<pcl::Vertices> visibleFaces_currentCam;
585  // iterate over the faces of the current mesh
586  for (std::size_t faces = 0; faces < tex_mesh.tex_polygons[0].size (); ++faces)
587  {
588  // check if all the face's points are visible
589  bool faceIsVisible = true;
590  std::vector<int>::iterator it;
591 
592  // iterate over face's vertex
593  for (std::size_t current_pt_indice = 0; faceIsVisible && current_pt_indice < tex_mesh.tex_polygons[0][faces].vertices.size (); ++current_pt_indice)
594  {
595  // TODO this is far too long! Better create an helper function that raycasts here.
596  it = find (occluded.begin (), occluded.end (), tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]);
597 
598  if (it == occluded.end ())
599  {
600  // point is not occluded
601  // does it land on the camera's image plane?
602  PointInT pt = transformed_cloud->points[tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]];
603  Eigen::Vector2f dummy_UV;
604  if (!getPointUVCoordinates (pt, camera, dummy_UV))
605  {
606  // point is not visible by the camera
607  faceIsVisible = false;
608  }
609  }
610  else
611  {
612  faceIsVisible = false;
613  }
614  }
615 
616  if (faceIsVisible)
617  {
618  // push current visible face into the sorted mesh
619  visibleFaces_currentCam.push_back (tex_mesh.tex_polygons[0][faces]);
620  // remove it from the unsorted mesh
621  tex_mesh.tex_polygons[0].erase (tex_mesh.tex_polygons[0].begin () + faces);
622  faces--;
623  }
624 
625  }
626  sorted_mesh.tex_polygons.push_back (visibleFaces_currentCam);
627  }
628 
629  // we should only have occluded and non-visible faces left in tex_mesh.tex_polygons[0]
630  // we need to add them as an extra polygon in the sorted mesh
631  sorted_mesh.tex_polygons.push_back (tex_mesh.tex_polygons[0]);
632  return (0);
633 }
634 
635 ///////////////////////////////////////////////////////////////////////////////////////////////
636 template<typename PointInT> void
639  const double octree_voxel_size, const bool show_nb_occlusions,
640  const int max_occlusions)
641  {
642  // variable used to filter occluded points by depth
643  double maxDeltaZ = octree_voxel_size * 2.0;
644 
645  // create an octree to perform rayTracing
646  Octree octree (octree_voxel_size);
647  // create octree structure
648  octree.setInputCloud (input_cloud);
649  // update bounding box automatically
650  octree.defineBoundingBox ();
651  // add points in the tree
652  octree.addPointsFromInputCloud ();
653 
654  // ray direction
655  Eigen::Vector3f direction;
656 
657  std::vector<int> indices;
658  // point from where we ray-trace
659  pcl::PointXYZI pt;
660 
661  std::vector<double> zDist;
662  std::vector<double> ptDist;
663  // for each point of the cloud, ray-trace toward the camera and check intersected voxels.
664  for (std::size_t i = 0; i < input_cloud->points.size (); ++i)
665  {
666  direction (0) = input_cloud->points[i].x;
667  pt.x = input_cloud->points[i].x;
668  direction (1) = input_cloud->points[i].y;
669  pt.y = input_cloud->points[i].y;
670  direction (2) = input_cloud->points[i].z;
671  pt.z = input_cloud->points[i].z;
672 
673  // get number of occlusions for that point
674  indices.clear ();
675  int nbocc = octree.getIntersectedVoxelIndices (direction, -direction, indices);
676 
677  nbocc = static_cast<int> (indices.size ());
678 
679  // TODO need to clean this up and find tricks to get remove aliasaing effect on planes
680  for (const int &index : indices)
681  {
682  // if intersected point is on the over side of the camera
683  if (pt.z * input_cloud->points[index].z < 0)
684  {
685  nbocc--;
686  }
687  else if (std::fabs (input_cloud->points[index].z - pt.z) <= maxDeltaZ)
688  {
689  // points are very close to each-other, we do not consider the occlusion
690  nbocc--;
691  }
692  else
693  {
694  zDist.push_back (std::fabs (input_cloud->points[index].z - pt.z));
695  ptDist.push_back (pcl::euclideanDistance (input_cloud->points[index], pt));
696  }
697  }
698 
699  if (show_nb_occlusions)
700  (nbocc <= max_occlusions) ? (pt.intensity = static_cast<float> (nbocc)) : (pt.intensity = static_cast<float> (max_occlusions));
701  else
702  (nbocc == 0) ? (pt.intensity = 0) : (pt.intensity = 1);
703 
704  colored_cloud->points.push_back (pt);
705  }
706 
707  if (zDist.size () >= 2)
708  {
709  std::sort (zDist.begin (), zDist.end ());
710  std::sort (ptDist.begin (), ptDist.end ());
711  }
712 }
713 
714 ///////////////////////////////////////////////////////////////////////////////////////////////
715 template<typename PointInT> void
717  double octree_voxel_size, bool show_nb_occlusions, int max_occlusions)
718 {
719  // load points into a PCL format
721  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
722 
723  showOcclusions (cloud, colored_cloud, octree_voxel_size, show_nb_occlusions, max_occlusions);
724 }
725 
726 ///////////////////////////////////////////////////////////////////////////////////////////////
727 template<typename PointInT> void
729 {
730 
731  if (mesh.tex_polygons.size () != 1)
732  return;
733 
735 
736  pcl::fromPCLPointCloud2 (mesh.cloud, *mesh_cloud);
737 
738  std::vector<pcl::Vertices> faces;
739 
740  for (int current_cam = 0; current_cam < static_cast<int> (cameras.size ()); ++current_cam)
741  {
742  PCL_INFO ("Processing camera %d of %d.\n", current_cam+1, cameras.size ());
743 
744  // transform mesh into camera's frame
745  typename pcl::PointCloud<PointInT>::Ptr camera_cloud (new pcl::PointCloud<PointInT>);
746  pcl::transformPointCloud (*mesh_cloud, *camera_cloud, cameras[current_cam].pose.inverse ());
747 
748  // CREATE UV MAP FOR CURRENT FACES
750  std::vector<bool> visibility;
751  visibility.resize (mesh.tex_polygons[current_cam].size ());
752  std::vector<UvIndex> indexes_uv_to_points;
753  // for each current face
754 
755  //TODO change this
756  pcl::PointXY nan_point;
757  nan_point.x = std::numeric_limits<float>::quiet_NaN ();
758  nan_point.y = std::numeric_limits<float>::quiet_NaN ();
759  UvIndex u_null;
760  u_null.idx_cloud = -1;
761  u_null.idx_face = -1;
762 
763  int cpt_invisible=0;
764  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[current_cam].size ()); ++idx_face)
765  {
766  //project each vertice, if one is out of view, stop
767  pcl::PointXY uv_coord1;
768  pcl::PointXY uv_coord2;
769  pcl::PointXY uv_coord3;
770 
771  if (isFaceProjected (cameras[current_cam],
772  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[0]],
773  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[1]],
774  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[2]],
775  uv_coord1,
776  uv_coord2,
777  uv_coord3))
778  {
779  // face is in the camera's FOV
780 
781  // add UV coordinates
782  projections->points.push_back (uv_coord1);
783  projections->points.push_back (uv_coord2);
784  projections->points.push_back (uv_coord3);
785 
786  // remember corresponding face
787  UvIndex u1, u2, u3;
788  u1.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[0];
789  u2.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[1];
790  u3.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[2];
791  u1.idx_face = idx_face; u2.idx_face = idx_face; u3.idx_face = idx_face;
792  indexes_uv_to_points.push_back (u1);
793  indexes_uv_to_points.push_back (u2);
794  indexes_uv_to_points.push_back (u3);
795 
796  //keep track of visibility
797  visibility[idx_face] = true;
798  }
799  else
800  {
801  projections->points.push_back (nan_point);
802  projections->points.push_back (nan_point);
803  projections->points.push_back (nan_point);
804  indexes_uv_to_points.push_back (u_null);
805  indexes_uv_to_points.push_back (u_null);
806  indexes_uv_to_points.push_back (u_null);
807  //keep track of visibility
808  visibility[idx_face] = false;
809  cpt_invisible++;
810  }
811  }
812 
813  // projections contains all UV points of the current faces
814  // indexes_uv_to_points links a uv point to its point in the camera cloud
815  // visibility contains tells if a face was in the camera FOV (false = skip)
816 
817  // TODO handle case were no face could be projected
818  if (visibility.size () - cpt_invisible !=0)
819  {
820  //create kdtree
822  kdtree.setInputCloud (projections);
823 
824  std::vector<int> idxNeighbors;
825  std::vector<float> neighborsSquaredDistance;
826  // af first (idx_pcan < current_cam), check if some of the faces attached to previous cameras occlude the current faces
827  // then (idx_pcam == current_cam), check for self occlusions. At this stage, we skip faces that were already marked as occluded
828  cpt_invisible = 0;
829  for (int idx_pcam = 0 ; idx_pcam <= current_cam ; ++idx_pcam)
830  {
831  // project all faces
832  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[idx_pcam].size ()); ++idx_face)
833  {
834 
835  if (idx_pcam == current_cam && !visibility[idx_face])
836  {
837  // we are now checking for self occlusions within the current faces
838  // the current face was already declared as occluded.
839  // therefore, it cannot occlude another face anymore => we skip it
840  continue;
841  }
842 
843  // project each vertice, if one is out of view, stop
844  pcl::PointXY uv_coord1;
845  pcl::PointXY uv_coord2;
846  pcl::PointXY uv_coord3;
847 
848  if (isFaceProjected (cameras[current_cam],
849  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]],
850  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]],
851  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]],
852  uv_coord1,
853  uv_coord2,
854  uv_coord3))
855  {
856  // face is in the camera's FOV
857  //get its circumsribed circle
858  double radius;
859  pcl::PointXY center;
860  // getTriangleCircumcenterAndSize (uv_coord1, uv_coord2, uv_coord3, center, radius);
861  getTriangleCircumcscribedCircleCentroid(uv_coord1, uv_coord2, uv_coord3, center, radius); // this function yields faster results than getTriangleCircumcenterAndSize
862 
863  // get points inside circ.circle
864  if (kdtree.radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
865  {
866  // for each neighbor
867  for (const int &idxNeighbor : idxNeighbors)
868  {
869  if (std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]].z,
870  std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]].z,
871  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]].z))
872  < camera_cloud->points[indexes_uv_to_points[idxNeighbor].idx_cloud].z)
873  {
874  // neighbor is farther than all the face's points. Check if it falls into the triangle
875  if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbor]))
876  {
877  // current neighbor is inside triangle and is closer => the corresponding face
878  visibility[indexes_uv_to_points[idxNeighbor].idx_face] = false;
879  cpt_invisible++;
880  //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
881  }
882  }
883  }
884  }
885  }
886  }
887  }
888  }
889 
890  // now, visibility is true for each face that belongs to the current camera
891  // if a face is not visible, we push it into the next one.
892 
893  if (static_cast<int> (mesh.tex_coordinates.size ()) <= current_cam)
894  {
895  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
896  mesh.tex_coordinates.push_back (dummy_container);
897  }
898  mesh.tex_coordinates[current_cam].resize (3 * visibility.size ());
899 
900  std::vector<pcl::Vertices> occluded_faces;
901  occluded_faces.resize (visibility.size ());
902  std::vector<pcl::Vertices> visible_faces;
903  visible_faces.resize (visibility.size ());
904 
905  int cpt_occluded_faces = 0;
906  int cpt_visible_faces = 0;
907 
908  for (std::size_t idx_face = 0 ; idx_face < visibility.size () ; ++idx_face)
909  {
910  if (visibility[idx_face])
911  {
912  // face is visible by the current camera copy UV coordinates
913  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](0) = projections->points[idx_face*3].x;
914  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](1) = projections->points[idx_face*3].y;
915 
916  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](0) = projections->points[idx_face*3 + 1].x;
917  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](1) = projections->points[idx_face*3 + 1].y;
918 
919  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](0) = projections->points[idx_face*3 + 2].x;
920  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](1) = projections->points[idx_face*3 + 2].y;
921 
922  visible_faces[cpt_visible_faces] = mesh.tex_polygons[current_cam][idx_face];
923 
924  cpt_visible_faces++;
925  }
926  else
927  {
928  // face is occluded copy face into temp vector
929  occluded_faces[cpt_occluded_faces] = mesh.tex_polygons[current_cam][idx_face];
930  cpt_occluded_faces++;
931  }
932  }
933  mesh.tex_coordinates[current_cam].resize (cpt_visible_faces*3);
934 
935  occluded_faces.resize (cpt_occluded_faces);
936  mesh.tex_polygons.push_back (occluded_faces);
937 
938  visible_faces.resize (cpt_visible_faces);
939  mesh.tex_polygons[current_cam].clear ();
940  mesh.tex_polygons[current_cam] = visible_faces;
941  }
942 
943  // we have been through all the cameras.
944  // if any faces are left, they were not visible by any camera
945  // we still need to produce uv coordinates for them
946 
947  if (mesh.tex_coordinates.size() <= cameras.size ())
948  {
949  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
950  mesh.tex_coordinates.push_back(dummy_container);
951  }
952 
953 
954  for(std::size_t idx_face = 0 ; idx_face < mesh.tex_polygons[cameras.size()].size() ; ++idx_face)
955  {
956  Eigen::Vector2f UV1, UV2, UV3;
957  UV1(0) = -1.0; UV1(1) = -1.0;
958  UV2(0) = -1.0; UV2(1) = -1.0;
959  UV3(0) = -1.0; UV3(1) = -1.0;
960  mesh.tex_coordinates[cameras.size()].push_back(UV1);
961  mesh.tex_coordinates[cameras.size()].push_back(UV2);
962  mesh.tex_coordinates[cameras.size()].push_back(UV3);
963  }
964 
965 }
966 
967 ///////////////////////////////////////////////////////////////////////////////////////////////
968 template<typename PointInT> inline void
970 {
971  // we simplify the problem by translating the triangle's origin to its first point
972  pcl::PointXY ptB, ptC;
973  ptB.x = p2.x - p1.x; ptB.y = p2.y - p1.y; // B'=B-A
974  ptC.x = p3.x - p1.x; ptC.y = p3.y - p1.y; // C'=C-A
975 
976  double D = 2.0*(ptB.x*ptC.y - ptB.y*ptC.x); // D'=2(B'x*C'y - B'y*C'x)
977 
978  // Safety check to avoid division by zero
979  if(D == 0)
980  {
981  circomcenter.x = p1.x;
982  circomcenter.y = p1.y;
983  }
984  else
985  {
986  // compute squares once
987  double bx2 = ptB.x * ptB.x; // B'x^2
988  double by2 = ptB.y * ptB.y; // B'y^2
989  double cx2 = ptC.x * ptC.x; // C'x^2
990  double cy2 = ptC.y * ptC.y; // C'y^2
991 
992  // compute circomcenter's coordinates (translate back to original coordinates)
993  circomcenter.x = static_cast<float> (p1.x + (ptC.y*(bx2 + by2) - ptB.y*(cx2 + cy2)) / D);
994  circomcenter.y = static_cast<float> (p1.y + (ptB.x*(cx2 + cy2) - ptC.x*(bx2 + by2)) / D);
995  }
996 
997  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));
998 }
999 
1000 ///////////////////////////////////////////////////////////////////////////////////////////////
1001 template<typename PointInT> inline void
1003 {
1004  // compute centroid's coordinates (translate back to original coordinates)
1005  circumcenter.x = static_cast<float> (p1.x + p2.x + p3.x ) / 3;
1006  circumcenter.y = static_cast<float> (p1.y + p2.y + p3.y ) / 3;
1007  double r1 = (circumcenter.x - p1.x) * (circumcenter.x - p1.x) + (circumcenter.y - p1.y) * (circumcenter.y - p1.y) ;
1008  double r2 = (circumcenter.x - p2.x) * (circumcenter.x - p2.x) + (circumcenter.y - p2.y) * (circumcenter.y - p2.y) ;
1009  double r3 = (circumcenter.x - p3.x) * (circumcenter.x - p3.x) + (circumcenter.y - p3.y) * (circumcenter.y - p3.y) ;
1010 
1011  // radius
1012  radius = std::sqrt( std::max( r1, std::max( r2, r3) )) ;
1013 }
1014 
1015 
1016 ///////////////////////////////////////////////////////////////////////////////////////////////
1017 template<typename PointInT> inline bool
1018 pcl::TextureMapping<PointInT>::getPointUVCoordinates(const PointInT &pt, const Camera &cam, pcl::PointXY &UV_coordinates)
1019 {
1020  if (pt.z > 0)
1021  {
1022  // compute image center and dimension
1023  double sizeX = cam.width;
1024  double sizeY = cam.height;
1025  double cx, cy;
1026  if (cam.center_w > 0)
1027  cx = cam.center_w;
1028  else
1029  cx = sizeX / 2.0;
1030  if (cam.center_h > 0)
1031  cy = cam.center_h;
1032  else
1033  cy = sizeY / 2.0;
1034 
1035  double focal_x, focal_y;
1036  if (cam.focal_length_w > 0)
1037  focal_x = cam.focal_length_w;
1038  else
1039  focal_x = cam.focal_length;
1040  if (cam.focal_length_h > 0)
1041  focal_y = cam.focal_length_h;
1042  else
1043  focal_y = cam.focal_length;
1044 
1045  // project point on camera's image plane
1046  UV_coordinates.x = static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX); //horizontal
1047  UV_coordinates.y = 1.0f - static_cast<float> ((focal_y * (pt.y / pt.z) + cy) / sizeY); //vertical
1048 
1049  // point is visible!
1050  if (UV_coordinates.x >= 0.0 && UV_coordinates.x <= 1.0 && UV_coordinates.y >= 0.0 && UV_coordinates.y <= 1.0)
1051  return (true); // point was visible by the camera
1052  }
1053 
1054  // point is NOT visible by the camera
1055  UV_coordinates.x = -1.0f;
1056  UV_coordinates.y = -1.0f;
1057  return (false); // point was not visible by the camera
1058 }
1059 
1060 ///////////////////////////////////////////////////////////////////////////////////////////////
1061 template<typename PointInT> inline bool
1063 {
1064  // Compute vectors
1065  Eigen::Vector2d v0, v1, v2;
1066  v0(0) = p3.x - p1.x; v0(1) = p3.y - p1.y; // v0= C - A
1067  v1(0) = p2.x - p1.x; v1(1) = p2.y - p1.y; // v1= B - A
1068  v2(0) = pt.x - p1.x; v2(1) = pt.y - p1.y; // v2= P - A
1069 
1070  // Compute dot products
1071  double dot00 = v0.dot(v0); // dot00 = dot(v0, v0)
1072  double dot01 = v0.dot(v1); // dot01 = dot(v0, v1)
1073  double dot02 = v0.dot(v2); // dot02 = dot(v0, v2)
1074  double dot11 = v1.dot(v1); // dot11 = dot(v1, v1)
1075  double dot12 = v1.dot(v2); // dot12 = dot(v1, v2)
1076 
1077  // Compute barycentric coordinates
1078  double invDenom = 1.0 / (dot00*dot11 - dot01*dot01);
1079  double u = (dot11*dot02 - dot01*dot12) * invDenom;
1080  double v = (dot00*dot12 - dot01*dot02) * invDenom;
1081 
1082  // Check if point is in triangle
1083  return ((u >= 0) && (v >= 0) && (u + v < 1));
1084 }
1085 
1086 ///////////////////////////////////////////////////////////////////////////////////////////////
1087 template<typename PointInT> inline bool
1088 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)
1089 {
1090  return (getPointUVCoordinates(p1, camera, proj1)
1091  &&
1092  getPointUVCoordinates(p2, camera, proj2)
1093  &&
1094  getPointUVCoordinates(p3, camera, proj3)
1095  );
1096 }
1097 
1098 #define PCL_INSTANTIATE_TextureMapping(T) \
1099  template class PCL_EXPORTS pcl::TextureMapping<T>;
1100 
1101 #endif /* TEXTURE_MAPPING_HPP_ */
1102 
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
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:414
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:396
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:220
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.
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:57
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