texture_mapping.hpp
Go to the documentation of this file.
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>
43 #include <pcl/search/octree.h>
44 
46 template<typename PointInT> std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >
48  const Eigen::Vector3f &p1,
49  const Eigen::Vector3f &p2,
50  const Eigen::Vector3f &p3)
51 {
52  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates;
53  // process for each face
54  Eigen::Vector3f p1p2 (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]);
55  Eigen::Vector3f p1p3 (p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]);
56  Eigen::Vector3f p2p3 (p3[0] - p2[0], p3[1] - p2[1], p3[2] - p2[2]);
57 
58  // Normalize
59  p1p2 = p1p2 / std::sqrt (p1p2.dot (p1p2));
60  p1p3 = p1p3 / std::sqrt (p1p3.dot (p1p3));
61  p2p3 = p2p3 / std::sqrt (p2p3.dot (p2p3));
62 
63  // compute vector normal of a face
64  Eigen::Vector3f f_normal = p1p2.cross (p1p3);
65  f_normal = f_normal / std::sqrt (f_normal.dot (f_normal));
66 
67  // project vector field onto the face: vector v1_projected = v1 - Dot(v1, n) * n;
68  Eigen::Vector3f f_vector_field = vector_field_ - vector_field_.dot (f_normal) * f_normal;
69 
70  // Normalize
71  f_vector_field = f_vector_field / std::sqrt (f_vector_field.dot (f_vector_field));
72 
73  // texture coordinates
74  Eigen::Vector2f tp1, tp2, tp3;
75 
76  double alpha = std::acos (f_vector_field.dot (p1p2));
77 
78  // distance between 3 vertices of triangles
79  double e1 = (p2 - p3).norm () / f_;
80  double e2 = (p1 - p3).norm () / f_;
81  double e3 = (p1 - p2).norm () / f_;
82 
83  // initialize
84  tp1[0] = 0.0;
85  tp1[1] = 0.0;
86 
87  tp2[0] = static_cast<float> (e3);
88  tp2[1] = 0.0;
89 
90  // determine texture coordinate tp3;
91  double cos_p1 = (e2 * e2 + e3 * e3 - e1 * e1) / (2 * e2 * e3);
92  double sin_p1 = sqrt (1 - (cos_p1 * cos_p1));
93 
94  tp3[0] = static_cast<float> (cos_p1 * e2);
95  tp3[1] = static_cast<float> (sin_p1 * e2);
96 
97  // rotating by alpha (angle between V and pp1 & pp2)
98  Eigen::Vector2f r_tp2, r_tp3;
99  r_tp2[0] = static_cast<float> (tp2[0] * std::cos (alpha) - tp2[1] * std::sin (alpha));
100  r_tp2[1] = static_cast<float> (tp2[0] * std::sin (alpha) + tp2[1] * std::cos (alpha));
101 
102  r_tp3[0] = static_cast<float> (tp3[0] * std::cos (alpha) - tp3[1] * std::sin (alpha));
103  r_tp3[1] = static_cast<float> (tp3[0] * std::sin (alpha) + tp3[1] * std::cos (alpha));
104 
105  // shifting
106  tp1[0] = tp1[0];
107  tp2[0] = r_tp2[0];
108  tp3[0] = r_tp3[0];
109  tp1[1] = tp1[1];
110  tp2[1] = r_tp2[1];
111  tp3[1] = r_tp3[1];
112 
113  float min_x = tp1[0];
114  float min_y = tp1[1];
115  if (min_x > tp2[0])
116  min_x = tp2[0];
117  if (min_x > tp3[0])
118  min_x = tp3[0];
119  if (min_y > tp2[1])
120  min_y = tp2[1];
121  if (min_y > tp3[1])
122  min_y = tp3[1];
123 
124  if (min_x < 0)
125  {
126  tp1[0] = tp1[0] - min_x;
127  tp2[0] = tp2[0] - min_x;
128  tp3[0] = tp3[0] - min_x;
129  }
130  if (min_y < 0)
131  {
132  tp1[1] = tp1[1] - min_y;
133  tp2[1] = tp2[1] - min_y;
134  tp3[1] = tp3[1] - min_y;
135  }
136 
137  tex_coordinates.push_back (tp1);
138  tex_coordinates.push_back (tp2);
139  tex_coordinates.push_back (tp3);
140  return (tex_coordinates);
141 }
142 
144 template<typename PointInT> void
146 {
147  // mesh information
148  int nr_points = tex_mesh.cloud.width * tex_mesh.cloud.height;
149  int point_size = static_cast<int> (tex_mesh.cloud.data.size ()) / nr_points;
150 
151  // temporary PointXYZ
152  float x, y, z;
153  // temporary face
154  Eigen::Vector3f facet[3];
155 
156  // texture coordinates for each mesh
157  std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > >texture_map;
158 
159  for (size_t m = 0; m < tex_mesh.tex_polygons.size (); ++m)
160  {
161  // texture coordinates for each mesh
162 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
163  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
164 #else
165  std::vector<Eigen::Vector2f> texture_map_tmp;
166 #endif
167 
168  // processing for each face
169  for (size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
170  {
171  size_t idx;
172 
173  // get facet information
174  for (size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
175  {
176  idx = tex_mesh.tex_polygons[m][i].vertices[j];
177  memcpy (&x, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
178  memcpy (&y, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
179  memcpy (&z, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
180  facet[j][0] = x;
181  facet[j][1] = y;
182  facet[j][2] = z;
183  }
184 
185  // get texture coordinates of each face
186  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates = mapTexture2Face (facet[0], facet[1], facet[2]);
187  for (size_t n = 0; n < tex_coordinates.size (); ++n)
188  texture_map_tmp.push_back (tex_coordinates[n]);
189  }// end faces
190 
191  // texture materials
192  std::stringstream tex_name;
193  tex_name << "material_" << m;
194  tex_name >> tex_material_.tex_name;
195  tex_material_.tex_file = tex_files_[m];
196  tex_mesh.tex_materials.push_back (tex_material_);
197 
198  // texture coordinates
199  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
200  }// end meshes
201 }
202 
204 template<typename PointInT> void
206 {
207  // mesh information
208  int nr_points = tex_mesh.cloud.width * tex_mesh.cloud.height;
209  int point_size = static_cast<int> (tex_mesh.cloud.data.size ()) / nr_points;
210 
211  float x_lowest = 100000;
212  float x_highest = 0;
213  float y_lowest = 100000;
214  //float y_highest = 0 ;
215  float z_lowest = 100000;
216  float z_highest = 0;
217  float x_, y_, z_;
218 
219  for (int i = 0; i < nr_points; ++i)
220  {
221  memcpy (&x_, &tex_mesh.cloud.data[i * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
222  memcpy (&y_, &tex_mesh.cloud.data[i * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
223  memcpy (&z_, &tex_mesh.cloud.data[i * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
224  // x
225  if (x_ <= x_lowest)
226  x_lowest = x_;
227  if (x_ > x_lowest)
228  x_highest = x_;
229 
230  // y
231  if (y_ <= y_lowest)
232  y_lowest = y_;
233  //if (y_ > y_lowest) y_highest = y_;
234 
235  // z
236  if (z_ <= z_lowest)
237  z_lowest = z_;
238  if (z_ > z_lowest)
239  z_highest = z_;
240  }
241  // x
242  float x_range = (x_lowest - x_highest) * -1;
243  float x_offset = 0 - x_lowest;
244  // x
245  // float y_range = (y_lowest - y_highest)*-1;
246  // float y_offset = 0 - y_lowest;
247  // z
248  float z_range = (z_lowest - z_highest) * -1;
249  float z_offset = 0 - z_lowest;
250 
251  // texture coordinates for each mesh
252  std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > >texture_map;
253 
254  for (size_t m = 0; m < tex_mesh.tex_polygons.size (); ++m)
255  {
256  // texture coordinates for each mesh
257 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
258  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
259 #else
260  std::vector<Eigen::Vector2f> texture_map_tmp;
261 #endif
262 
263  // processing for each face
264  for (size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
265  {
266  size_t idx;
267  Eigen::Vector2f tmp_VT;
268  for (size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
269  {
270  idx = tex_mesh.tex_polygons[m][i].vertices[j];
271  memcpy (&x_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[0].offset], sizeof(float));
272  memcpy (&y_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[1].offset], sizeof(float));
273  memcpy (&z_, &tex_mesh.cloud.data[idx * point_size + tex_mesh.cloud.fields[2].offset], sizeof(float));
274 
275  // calculate uv coordinates
276  tmp_VT[0] = (x_ + x_offset) / x_range;
277  tmp_VT[1] = (z_ + z_offset) / z_range;
278  texture_map_tmp.push_back (tmp_VT);
279  }
280  }// end faces
281 
282  // texture materials
283  std::stringstream tex_name;
284  tex_name << "material_" << m;
285  tex_name >> tex_material_.tex_name;
286  tex_material_.tex_file = tex_files_[m];
287  tex_mesh.tex_materials.push_back (tex_material_);
288 
289  // texture coordinates
290  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
291  }// end meshes
292 }
293 
295 template<typename PointInT> void
297 {
298 
299  if (tex_mesh.tex_polygons.size () != cams.size () + 1)
300  {
301  PCL_ERROR ("The mesh should be divided into nbCamera+1 sub-meshes.\n");
302  PCL_ERROR ("You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.tex_polygons.size ());
303  return;
304  }
305 
306  PCL_INFO ("You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.tex_polygons.size ());
307 
308  typename pcl::PointCloud<PointInT>::Ptr originalCloud (new pcl::PointCloud<PointInT>);
309  typename pcl::PointCloud<PointInT>::Ptr camera_transformed_cloud (new pcl::PointCloud<PointInT>);
310 
311  // convert mesh's cloud to pcl format for ease
312  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *originalCloud);
313 
314  // texture coordinates for each mesh
315  std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > texture_map;
316 
317  for (size_t m = 0; m < cams.size (); ++m)
318  {
319  // get current camera parameters
320  Camera current_cam = cams[m];
321 
322  // get camera transform
323  Eigen::Affine3f cam_trans = current_cam.pose;
324 
325  // transform cloud into current camera frame
326  pcl::transformPointCloud (*originalCloud, *camera_transformed_cloud, cam_trans.inverse ());
327 
328  // vector of texture coordinates for each face
329 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
330  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
331 #else
332  std::vector<Eigen::Vector2f> texture_map_tmp;
333 #endif
334 
335  // processing each face visible by this camera
336  PointInT pt;
337  size_t idx;
338  for (size_t i = 0; i < tex_mesh.tex_polygons[m].size (); ++i)
339  {
340  Eigen::Vector2f tmp_VT;
341  // for each point of this face
342  for (size_t j = 0; j < tex_mesh.tex_polygons[m][i].vertices.size (); ++j)
343  {
344  // get point
345  idx = tex_mesh.tex_polygons[m][i].vertices[j];
346  pt = camera_transformed_cloud->points[idx];
347 
348  // compute UV coordinates for this point
349  getPointUVCoordinates (pt, current_cam, tmp_VT);
350  texture_map_tmp.push_back (tmp_VT);
351 
352  }// end points
353  }// end faces
354 
355  // texture materials
356  std::stringstream tex_name;
357  tex_name << "material_" << m;
358  tex_name >> tex_material_.tex_name;
359  tex_material_.tex_file = current_cam.texture_file;
360  tex_mesh.tex_materials.push_back (tex_material_);
361 
362  // texture coordinates
363  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
364  }// end cameras
365 
366  // push on extra empty UV map (for unseen faces) so that obj writer does not crash!
367 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
368  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
369 #else
370  std::vector<Eigen::Vector2f> texture_map_tmp;
371 #endif
372  for (size_t i = 0; i < tex_mesh.tex_polygons[cams.size ()].size (); ++i)
373  for (size_t j = 0; j < tex_mesh.tex_polygons[cams.size ()][i].vertices.size (); ++j)
374  {
375  Eigen::Vector2f tmp_VT;
376  tmp_VT[0] = -1;
377  tmp_VT[1] = -1;
378  texture_map_tmp.push_back (tmp_VT);
379  }
380 
381  tex_mesh.tex_coordinates.push_back (texture_map_tmp);
382 
383  // push on an extra dummy material for the same reason
384  std::stringstream tex_name;
385  tex_name << "material_" << cams.size ();
386  tex_name >> tex_material_.tex_name;
387  tex_material_.tex_file = "occluded.jpg";
388  tex_mesh.tex_materials.push_back (tex_material_);
389 
390 }
391 
393 template<typename PointInT> bool
395 {
396  Eigen::Vector3f direction;
397  direction (0) = pt.x;
398  direction (1) = pt.y;
399  direction (2) = pt.z;
400 
401  std::vector<int> indices;
402 
403  PointCloudConstPtr cloud (new PointCloud());
404  cloud = octree->getInputCloud();
405 
406  double distance_threshold = octree->getResolution();
407 
408  // raytrace
409  octree->getIntersectedVoxelIndices(direction, -direction, indices);
410 
411  int nbocc = static_cast<int> (indices.size ());
412  for (size_t j = 0; j < indices.size (); j++)
413  {
414  // if intersected point is on the over side of the camera
415  if (pt.z * cloud->points[indices[j]].z < 0)
416  {
417  nbocc--;
418  continue;
419  }
420 
421  if (fabs (cloud->points[indices[j]].z - pt.z) <= distance_threshold)
422  {
423  // points are very close to each-other, we do not consider the occlusion
424  nbocc--;
425  }
426  }
427 
428  if (nbocc == 0)
429  return (false);
430  else
431  return (true);
432 }
433 
435 template<typename PointInT> void
437  PointCloudPtr &filtered_cloud,
438  const double octree_voxel_size, std::vector<int> &visible_indices,
439  std::vector<int> &occluded_indices)
440 {
441  // variable used to filter occluded points by depth
442  double maxDeltaZ = octree_voxel_size;
443 
444  // create an octree to perform rayTracing
445  OctreePtr octree (new Octree (octree_voxel_size));
446  // create octree structure
447  octree->setInputCloud (input_cloud);
448  // update bounding box automatically
449  octree->defineBoundingBox ();
450  // add points in the tree
451  octree->addPointsFromInputCloud ();
452 
453  visible_indices.clear ();
454 
455  // for each point of the cloud, raycast toward camera and check intersected voxels.
456  Eigen::Vector3f direction;
457  std::vector<int> indices;
458  for (size_t i = 0; i < input_cloud->points.size (); ++i)
459  {
460  direction (0) = input_cloud->points[i].x;
461  direction (1) = input_cloud->points[i].y;
462  direction (2) = input_cloud->points[i].z;
463 
464  // if point is not occluded
465  octree->getIntersectedVoxelIndices (direction, -direction, indices);
466 
467  int nbocc = static_cast<int> (indices.size ());
468  for (size_t j = 0; j < indices.size (); j++)
469  {
470  // if intersected point is on the over side of the camera
471  if (input_cloud->points[i].z * input_cloud->points[indices[j]].z < 0)
472  {
473  nbocc--;
474  continue;
475  }
476 
477  if (fabs (input_cloud->points[indices[j]].z - input_cloud->points[i].z) <= maxDeltaZ)
478  {
479  // points are very close to each-other, we do not consider the occlusion
480  nbocc--;
481  }
482  }
483 
484  if (nbocc == 0)
485  {
486  // point is added in the filtered mesh
487  filtered_cloud->points.push_back (input_cloud->points[i]);
488  visible_indices.push_back (static_cast<int> (i));
489  }
490  else
491  {
492  occluded_indices.push_back (static_cast<int> (i));
493  }
494  }
495 
496 }
497 
499 template<typename PointInT> void
500 pcl::TextureMapping<PointInT>::removeOccludedPoints (const pcl::TextureMesh &tex_mesh, pcl::TextureMesh &cleaned_mesh, const double octree_voxel_size)
501 {
502  // copy mesh
503  cleaned_mesh = tex_mesh;
504 
505  typename pcl::PointCloud<PointInT>::Ptr cloud (new pcl::PointCloud<PointInT>);
506  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
507 
508  // load points into a PCL format
509  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
510 
511  std::vector<int> visible, occluded;
512  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
513 
514  // Now that we know which points are visible, let's iterate over each face.
515  // if the face has one invisible point => out!
516  for (size_t polygons = 0; polygons < cleaned_mesh.tex_polygons.size (); ++polygons)
517  {
518  // remove all faces from cleaned mesh
519  cleaned_mesh.tex_polygons[polygons].clear ();
520  // iterate over faces
521  for (size_t faces = 0; faces < tex_mesh.tex_polygons[polygons].size (); ++faces)
522  {
523  // check if all the face's points are visible
524  bool faceIsVisible = true;
525  std::vector<int>::iterator it;
526 
527  // iterate over face's vertex
528  for (size_t points = 0; points < tex_mesh.tex_polygons[polygons][faces].vertices.size (); ++points)
529  {
530  it = find (occluded.begin (), occluded.end (), tex_mesh.tex_polygons[polygons][faces].vertices[points]);
531 
532  if (it == occluded.end ())
533  {
534  // point is not in the occluded vector
535  // PCL_INFO (" VISIBLE!\n");
536  }
537  else
538  {
539  // point was occluded
540  // PCL_INFO(" OCCLUDED!\n");
541  faceIsVisible = false;
542  }
543  }
544 
545  if (faceIsVisible)
546  {
547  cleaned_mesh.tex_polygons[polygons].push_back (tex_mesh.tex_polygons[polygons][faces]);
548  }
549 
550  }
551  }
552 }
553 
555 template<typename PointInT> void
556 pcl::TextureMapping<PointInT>::removeOccludedPoints (const pcl::TextureMesh &tex_mesh, PointCloudPtr &filtered_cloud,
557  const double octree_voxel_size)
558 {
559  PointCloudPtr cloud (new PointCloud);
560 
561  // load points into a PCL format
562  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
563 
564  std::vector<int> visible, occluded;
565  removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
566 
567 }
568 
570 template<typename PointInT> int
571 pcl::TextureMapping<PointInT>::sortFacesByCamera (pcl::TextureMesh &tex_mesh, pcl::TextureMesh &sorted_mesh,
572  const pcl::texture_mapping::CameraVector &cameras, const double octree_voxel_size,
573  PointCloud &visible_pts)
574 {
575  if (tex_mesh.tex_polygons.size () != 1)
576  {
577  PCL_ERROR ("The mesh must contain only 1 sub-mesh!\n");
578  return (-1);
579  }
580 
581  if (cameras.size () == 0)
582  {
583  PCL_ERROR ("Must provide at least one camera info!\n");
584  return (-1);
585  }
586 
587  // copy mesh
588  sorted_mesh = tex_mesh;
589  // clear polygons from cleaned_mesh
590  sorted_mesh.tex_polygons.clear ();
591 
592  typename pcl::PointCloud<PointInT>::Ptr original_cloud (new pcl::PointCloud<PointInT>);
593  typename pcl::PointCloud<PointInT>::Ptr transformed_cloud (new pcl::PointCloud<PointInT>);
594  typename pcl::PointCloud<PointInT>::Ptr filtered_cloud (new pcl::PointCloud<PointInT>);
595 
596  // load points into a PCL format
597  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *original_cloud);
598 
599  // for each camera
600  for (size_t cam = 0; cam < cameras.size (); ++cam)
601  {
602  // get camera pose as transform
603  Eigen::Affine3f cam_trans = cameras[cam].pose;
604 
605  // transform original cloud in camera coordinates
606  pcl::transformPointCloud (*original_cloud, *transformed_cloud, cam_trans.inverse ());
607 
608  // find occlusions on transformed cloud
609  std::vector<int> visible, occluded;
610  removeOccludedPoints (transformed_cloud, filtered_cloud, octree_voxel_size, visible, occluded);
611  visible_pts = *filtered_cloud;
612 
613  // find visible faces => add them to polygon N for camera N
614  // add polygon group for current camera in clean
615  std::vector<pcl::Vertices> visibleFaces_currentCam;
616  // iterate over the faces of the current mesh
617  for (size_t faces = 0; faces < tex_mesh.tex_polygons[0].size (); ++faces)
618  {
619  // check if all the face's points are visible
620  bool faceIsVisible = true;
621  std::vector<int>::iterator it;
622 
623  // iterate over face's vertex
624  for (size_t current_pt_indice = 0; faceIsVisible && current_pt_indice < tex_mesh.tex_polygons[0][faces].vertices.size (); ++current_pt_indice)
625  {
626  // TODO this is far too long! Better create an helper function that raycasts here.
627  it = find (occluded.begin (), occluded.end (), tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]);
628 
629  if (it == occluded.end ())
630  {
631  // point is not occluded
632  // does it land on the camera's image plane?
633  PointInT pt = transformed_cloud->points[tex_mesh.tex_polygons[0][faces].vertices[current_pt_indice]];
634  Eigen::Vector2f dummy_UV;
635  if (!getPointUVCoordinates (pt, cameras[cam], dummy_UV))
636  {
637  // point is not visible by the camera
638  faceIsVisible = false;
639  }
640  }
641  else
642  {
643  faceIsVisible = false;
644  }
645  }
646 
647  if (faceIsVisible)
648  {
649  // push current visible face into the sorted mesh
650  visibleFaces_currentCam.push_back (tex_mesh.tex_polygons[0][faces]);
651  // remove it from the unsorted mesh
652  tex_mesh.tex_polygons[0].erase (tex_mesh.tex_polygons[0].begin () + faces);
653  faces--;
654  }
655 
656  }
657  sorted_mesh.tex_polygons.push_back (visibleFaces_currentCam);
658  }
659 
660  // we should only have occluded and non-visible faces left in tex_mesh.tex_polygons[0]
661  // we need to add them as an extra polygon in the sorted mesh
662  sorted_mesh.tex_polygons.push_back (tex_mesh.tex_polygons[0]);
663  return (0);
664 }
665 
667 template<typename PointInT> void
669  pcl::PointCloud<pcl::PointXYZI>::Ptr &colored_cloud,
670  const double octree_voxel_size, const bool show_nb_occlusions,
671  const int max_occlusions)
672  {
673  // variable used to filter occluded points by depth
674  double maxDeltaZ = octree_voxel_size * 2.0;
675 
676  // create an octree to perform rayTracing
677  pcl::octree::OctreePointCloudSearch<PointInT> *octree;
678  octree = new pcl::octree::OctreePointCloudSearch<PointInT> (octree_voxel_size);
679  // create octree structure
680  octree->setInputCloud (input_cloud);
681  // update bounding box automatically
682  octree->defineBoundingBox ();
683  // add points in the tree
684  octree->addPointsFromInputCloud ();
685 
686  // ray direction
687  Eigen::Vector3f direction;
688 
689  std::vector<int> indices;
690  // point from where we ray-trace
691  pcl::PointXYZI pt;
692 
693  std::vector<double> zDist;
694  std::vector<double> ptDist;
695  // for each point of the cloud, ray-trace toward the camera and check intersected voxels.
696  for (size_t i = 0; i < input_cloud->points.size (); ++i)
697  {
698  direction (0) = input_cloud->points[i].x;
699  pt.x = input_cloud->points[i].x;
700  direction (1) = input_cloud->points[i].y;
701  pt.y = input_cloud->points[i].y;
702  direction (2) = input_cloud->points[i].z;
703  pt.z = input_cloud->points[i].z;
704 
705  // get number of occlusions for that point
706  indices.clear ();
707  int nbocc = octree->getIntersectedVoxelIndices (direction, -direction, indices);
708 
709  nbocc = static_cast<int> (indices.size ());
710 
711  // TODO need to clean this up and find tricks to get remove aliasaing effect on planes
712  for (size_t j = 0; j < indices.size (); j++)
713  {
714  // if intersected point is on the over side of the camera
715  if (pt.z * input_cloud->points[indices[j]].z < 0)
716  {
717  nbocc--;
718  }
719  else if (fabs (input_cloud->points[indices[j]].z - pt.z) <= maxDeltaZ)
720  {
721  // points are very close to each-other, we do not consider the occlusion
722  nbocc--;
723  }
724  else
725  {
726  zDist.push_back (fabs (input_cloud->points[indices[j]].z - pt.z));
727  ptDist.push_back (pcl::euclideanDistance (input_cloud->points[indices[j]], pt));
728  }
729  }
730 
731  if (show_nb_occlusions)
732  (nbocc <= max_occlusions) ? (pt.intensity = static_cast<float> (nbocc)) : (pt.intensity = static_cast<float> (max_occlusions));
733  else
734  (nbocc == 0) ? (pt.intensity = 0) : (pt.intensity = 1);
735 
736  colored_cloud->points.push_back (pt);
737  }
738 
739  if (zDist.size () >= 2)
740  {
741  std::sort (zDist.begin (), zDist.end ());
742  std::sort (ptDist.begin (), ptDist.end ());
743  }
744 }
745 
747 template<typename PointInT> void
748 pcl::TextureMapping<PointInT>::showOcclusions (pcl::TextureMesh &tex_mesh, pcl::PointCloud<pcl::PointXYZI>::Ptr &colored_cloud,
749  double octree_voxel_size, bool show_nb_occlusions, int max_occlusions)
750 {
751  // load points into a PCL format
752  typename pcl::PointCloud<PointInT>::Ptr cloud (new pcl::PointCloud<PointInT>);
753  pcl::fromPCLPointCloud2 (tex_mesh.cloud, *cloud);
754 
755  showOcclusions (cloud, colored_cloud, octree_voxel_size, show_nb_occlusions, max_occlusions);
756 }
757 
759 template<typename PointInT> void
761 {
762 
763  if (mesh.tex_polygons.size () != 1)
764  return;
765 
766  typename pcl::PointCloud<PointInT>::Ptr mesh_cloud (new pcl::PointCloud<PointInT>);
767 
768  pcl::fromPCLPointCloud2 (mesh.cloud, *mesh_cloud);
769 
770  std::vector<pcl::Vertices> faces;
771 
772  for (int current_cam = 0; current_cam < static_cast<int> (cameras.size ()); ++current_cam)
773  {
774  PCL_INFO ("Processing camera %d of %d.\n", current_cam+1, cameras.size ());
775 
776  // transform mesh into camera's frame
777  typename pcl::PointCloud<PointInT>::Ptr camera_cloud (new pcl::PointCloud<PointInT>);
778  pcl::transformPointCloud (*mesh_cloud, *camera_cloud, cameras[current_cam].pose.inverse ());
779 
780  // CREATE UV MAP FOR CURRENT FACES
781  pcl::PointCloud<pcl::PointXY>::Ptr projections (new pcl::PointCloud<pcl::PointXY>);
782  std::vector<pcl::Vertices>::iterator current_face;
783  std::vector<bool> visibility;
784  visibility.resize (mesh.tex_polygons[current_cam].size ());
785  std::vector<UvIndex> indexes_uv_to_points;
786  // for each current face
787 
788  //TODO change this
789  pcl::PointXY nan_point;
790  nan_point.x = std::numeric_limits<float>::quiet_NaN ();
791  nan_point.y = std::numeric_limits<float>::quiet_NaN ();
792  UvIndex u_null;
793  u_null.idx_cloud = -1;
794  u_null.idx_face = -1;
795 
796  int cpt_invisible=0;
797  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[current_cam].size ()); ++idx_face)
798  {
799  //project each vertice, if one is out of view, stop
800  pcl::PointXY uv_coord1;
801  pcl::PointXY uv_coord2;
802  pcl::PointXY uv_coord3;
803 
804  if (isFaceProjected (cameras[current_cam],
805  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[0]],
806  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[1]],
807  camera_cloud->points[mesh.tex_polygons[current_cam][idx_face].vertices[2]],
808  uv_coord1,
809  uv_coord2,
810  uv_coord3))
811  {
812  // face is in the camera's FOV
813 
814  // add UV coordinates
815  projections->points.push_back (uv_coord1);
816  projections->points.push_back (uv_coord2);
817  projections->points.push_back (uv_coord3);
818 
819  // remember corresponding face
820  UvIndex u1, u2, u3;
821  u1.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[0];
822  u2.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[1];
823  u3.idx_cloud = mesh.tex_polygons[current_cam][idx_face].vertices[2];
824  u1.idx_face = idx_face; u2.idx_face = idx_face; u3.idx_face = idx_face;
825  indexes_uv_to_points.push_back (u1);
826  indexes_uv_to_points.push_back (u2);
827  indexes_uv_to_points.push_back (u3);
828 
829  //keep track of visibility
830  visibility[idx_face] = true;
831  }
832  else
833  {
834  projections->points.push_back (nan_point);
835  projections->points.push_back (nan_point);
836  projections->points.push_back (nan_point);
837  indexes_uv_to_points.push_back (u_null);
838  indexes_uv_to_points.push_back (u_null);
839  indexes_uv_to_points.push_back (u_null);
840  //keep track of visibility
841  visibility[idx_face] = false;
842  cpt_invisible++;
843  }
844  }
845 
846  // projections contains all UV points of the current faces
847  // indexes_uv_to_points links a uv point to its point in the camera cloud
848  // visibility contains tells if a face was in the camera FOV (false = skip)
849 
850  // TODO handle case were no face could be projected
851  if (visibility.size () - cpt_invisible !=0)
852  {
853  //create kdtree
854  pcl::KdTreeFLANN<pcl::PointXY> kdtree;
855  kdtree.setInputCloud (projections);
856 
857  std::vector<int> idxNeighbors;
858  std::vector<float> neighborsSquaredDistance;
859  // af first (idx_pcan < current_cam), check if some of the faces attached to previous cameras occlude the current faces
860  // then (idx_pcam == current_cam), check for self occlusions. At this stage, we skip faces that were already marked as occluded
861  cpt_invisible = 0;
862  for (int idx_pcam = 0 ; idx_pcam <= current_cam ; ++idx_pcam)
863  {
864  // project all faces
865  for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[idx_pcam].size ()); ++idx_face)
866  {
867 
868  if (idx_pcam == current_cam && !visibility[idx_face])
869  {
870  // we are now checking for self occlusions within the current faces
871  // the current face was already declared as occluded.
872  // therefore, it cannot occlude another face anymore => we skip it
873  continue;
874  }
875 
876  // project each vertice, if one is out of view, stop
877  pcl::PointXY uv_coord1;
878  pcl::PointXY uv_coord2;
879  pcl::PointXY uv_coord3;
880 
881  if (isFaceProjected (cameras[current_cam],
882  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]],
883  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]],
884  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]],
885  uv_coord1,
886  uv_coord2,
887  uv_coord3))
888  {
889  // face is in the camera's FOV
890  //get its circumsribed circle
891  double radius;
892  pcl::PointXY center;
893  // getTriangleCircumcenterAndSize (uv_coord1, uv_coord2, uv_coord3, center, radius);
894  getTriangleCircumcscribedCircleCentroid(uv_coord1, uv_coord2, uv_coord3, center, radius); // this function yields faster results than getTriangleCircumcenterAndSize
895 
896  // get points inside circ.circle
897  if (kdtree.radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
898  {
899  // for each neighbor
900  for (size_t i = 0; i < idxNeighbors.size (); ++i)
901  {
902  if (std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[0]].z,
903  std::max (camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[1]].z,
904  camera_cloud->points[mesh.tex_polygons[idx_pcam][idx_face].vertices[2]].z))
905  < camera_cloud->points[indexes_uv_to_points[idxNeighbors[i]].idx_cloud].z)
906  {
907  // neighbor is farther than all the face's points. Check if it falls into the triangle
908  if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbors[i]]))
909  {
910  // current neighbor is inside triangle and is closer => the corresponding face
911  visibility[indexes_uv_to_points[idxNeighbors[i]].idx_face] = false;
912  cpt_invisible++;
913  //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
914  }
915  }
916  }
917  }
918  }
919  }
920  }
921  }
922 
923  // now, visibility is true for each face that belongs to the current camera
924  // if a face is not visible, we push it into the next one.
925 
926  if (static_cast<int> (mesh.tex_coordinates.size ()) <= current_cam)
927  {
928 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
929  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
930 #else
931  std::vector<Eigen::Vector2f> dummy_container;
932 #endif
933  mesh.tex_coordinates.push_back (dummy_container);
934  }
935  mesh.tex_coordinates[current_cam].resize (3 * visibility.size ());
936 
937  std::vector<pcl::Vertices> occluded_faces;
938  occluded_faces.resize (visibility.size ());
939  std::vector<pcl::Vertices> visible_faces;
940  visible_faces.resize (visibility.size ());
941 
942  int cpt_occluded_faces = 0;
943  int cpt_visible_faces = 0;
944 
945  for (size_t idx_face = 0 ; idx_face < visibility.size () ; ++idx_face)
946  {
947  if (visibility[idx_face])
948  {
949  // face is visible by the current camera copy UV coordinates
950  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](0) = projections->points[idx_face*3].x;
951  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3](1) = projections->points[idx_face*3].y;
952 
953  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](0) = projections->points[idx_face*3 + 1].x;
954  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](1) = projections->points[idx_face*3 + 1].y;
955 
956  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](0) = projections->points[idx_face*3 + 2].x;
957  mesh.tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](1) = projections->points[idx_face*3 + 2].y;
958 
959  visible_faces[cpt_visible_faces] = mesh.tex_polygons[current_cam][idx_face];
960 
961  cpt_visible_faces++;
962  }
963  else
964  {
965  // face is occluded copy face into temp vector
966  occluded_faces[cpt_occluded_faces] = mesh.tex_polygons[current_cam][idx_face];
967  cpt_occluded_faces++;
968  }
969  }
970  mesh.tex_coordinates[current_cam].resize (cpt_visible_faces*3);
971 
972  occluded_faces.resize (cpt_occluded_faces);
973  mesh.tex_polygons.push_back (occluded_faces);
974 
975  visible_faces.resize (cpt_visible_faces);
976  mesh.tex_polygons[current_cam].clear ();
977  mesh.tex_polygons[current_cam] = visible_faces;
978 
979  int nb_faces = 0;
980  for (int i = 0; i < static_cast<int> (mesh.tex_polygons.size ()); i++)
981  nb_faces += static_cast<int> (mesh.tex_polygons[i].size ());
982  }
983 
984  // we have been through all the cameras.
985  // if any faces are left, they were not visible by any camera
986  // we still need to produce uv coordinates for them
987 
988  if (mesh.tex_coordinates.size() <= cameras.size ())
989  {
990 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
991  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
992 #else
993  std::vector<Eigen::Vector2f> dummy_container;
994 #endif
995  mesh.tex_coordinates.push_back(dummy_container);
996  }
997 
998 
999  for(size_t idx_face = 0 ; idx_face < mesh.tex_polygons[cameras.size()].size() ; ++idx_face)
1000  {
1001  Eigen::Vector2f UV1, UV2, UV3;
1002  UV1(0) = -1.0; UV1(1) = -1.0;
1003  UV2(0) = -1.0; UV2(1) = -1.0;
1004  UV3(0) = -1.0; UV3(1) = -1.0;
1005  mesh.tex_coordinates[cameras.size()].push_back(UV1);
1006  mesh.tex_coordinates[cameras.size()].push_back(UV2);
1007  mesh.tex_coordinates[cameras.size()].push_back(UV3);
1008  }
1009 
1010 }
1011 
1013 {
1014 public:
1015  FaceInfo(float d,
1016  float a,
1017  float edge,
1018  bool facingCam,
1019  const pcl::PointXY & uv1,
1020  const pcl::PointXY & uv2,
1021  const pcl::PointXY & uv3,
1022  const pcl::PointXY & center) :
1023  distance(d),
1024  angle(a),
1025  longestEdgeSqrd(edge),
1026  facingTheCam(facingCam),
1027  uv_coord1(uv1),
1028  uv_coord2(uv2),
1029  uv_coord3(uv3),
1030  uv_center(center)
1031  {}
1032  float distance;
1033  float angle;
1036  pcl::PointXY uv_coord1;
1037  pcl::PointXY uv_coord2;
1038  pcl::PointXY uv_coord3;
1039  pcl::PointXY uv_center;
1040 };
1041 
1042 bool ptInTriangle(const pcl::PointXY & p0, const pcl::PointXY & p1, const pcl::PointXY & p2, const pcl::PointXY & p) {
1043  float A = 1/2 * (-p1.y * p2.x + p0.y * (-p1.x + p2.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y);
1044  float sign = A < 0 ? -1 : 1;
1045  float s = (p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y) * sign;
1046  float t = (p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y) * sign;
1047 
1048  return s > 0 && t > 0 && (s + t) < 2 * A * sign;
1049 }
1050 
1052 template<typename PointInT> bool
1054  pcl::TextureMesh &mesh,
1055  const pcl::texture_mapping::CameraVector &cameras,
1056  const rtabmap::ProgressState * state,
1057  std::vector<std::map<int, pcl::PointXY> > * vertexToPixels)
1058 {
1059 
1060  if (mesh.tex_polygons.size () != 1)
1061  return false;
1062 
1063  typename pcl::PointCloud<PointInT>::Ptr mesh_cloud (new pcl::PointCloud<PointInT>);
1064 
1065  pcl::fromPCLPointCloud2 (mesh.cloud, *mesh_cloud);
1066 
1067  std::vector<pcl::Vertices> faces;
1068  faces.swap(mesh.tex_polygons[0]);
1069 
1070  mesh.tex_polygons.clear();
1071  mesh.tex_polygons.resize(cameras.size()+1);
1072  mesh.tex_coordinates.clear();
1073  mesh.tex_coordinates.resize(cameras.size()+1);
1074 
1075  // pre compute all cam inverse and visibility
1076  std::vector<std::map<int, FaceInfo > > visibleFaces(cameras.size());
1077  std::vector<Eigen::Affine3f> invCamTransform(cameras.size());
1078  std::vector<std::list<int> > faceCameras(faces.size());
1079  UINFO("Precompute visible faces per cam (%d faces, %d cams)", (int)faces.size(), (int)cameras.size());
1080  for (unsigned int current_cam = 0; current_cam < cameras.size(); ++current_cam)
1081  {
1082  UDEBUG("Texture camera %d...", current_cam);
1083 
1084  typename pcl::PointCloud<PointInT>::Ptr camera_cloud (new pcl::PointCloud<PointInT>);
1085  pcl::transformPointCloud(*mesh_cloud, *camera_cloud, cameras[current_cam].pose.inverse());
1086 
1087  std::vector<int> visibilityIndices;
1088  visibilityIndices.resize (faces.size ());
1089  pcl::PointCloud<pcl::PointXY>::Ptr projections (new pcl::PointCloud<pcl::PointXY>);
1090  projections->resize(faces.size()*3);
1091  std::map<float, int> sortedVisibleFaces;
1092  int oi=0;
1093  for(unsigned int idx_face=0; idx_face<faces.size(); ++idx_face)
1094  {
1095  pcl::Vertices & face = faces[idx_face];
1096 
1097  int j=oi*3;
1098  pcl::PointXY & uv_coords1 = projections->at(j);
1099  pcl::PointXY & uv_coords2 = projections->at(j+1);
1100  pcl::PointXY & uv_coords3 = projections->at(j+2);
1101  PointInT & pt0 = camera_cloud->points[face.vertices[0]];
1102  PointInT & pt1 = camera_cloud->points[face.vertices[1]];
1103  PointInT & pt2 = camera_cloud->points[face.vertices[2]];
1104  if (isFaceProjected (cameras[current_cam],
1105  pt0,
1106  pt1,
1107  pt2,
1108  uv_coords1,
1109  uv_coords2,
1110  uv_coords3))
1111  {
1112  // check if the polygon is facing the camera, assuming counterclockwise normal
1113  Eigen::Vector3f v0(
1114  uv_coords2.x - uv_coords1.x,
1115  uv_coords2.y - uv_coords1.y,
1116  0);
1117  Eigen::Vector3f v1(
1118  uv_coords3.x - uv_coords1.x,
1119  uv_coords3.y - uv_coords1.y,
1120  0);
1121  Eigen::Vector3f normal = v0.cross(v1);
1122  float angle = normal.dot(Eigen::Vector3f(0.0f,0.0f,1.0f));
1123  bool facingTheCam = angle>0.0f;
1124  float distanceToCam = std::min(std::min(pt0.z, pt1.z), pt2.z);
1125  float angleToCam = 0.0f;
1126  Eigen::Vector3f e0 = Eigen::Vector3f(
1127  pt1.x - pt0.x,
1128  pt1.y - pt0.y,
1129  pt1.z - pt0.z);
1130  Eigen::Vector3f e1 = Eigen::Vector3f(
1131  pt2.x - pt0.x,
1132  pt2.y - pt0.y,
1133  pt2.z - pt0.z);
1134  Eigen::Vector3f e2 = Eigen::Vector3f(
1135  pt2.x - pt1.x,
1136  pt2.y - pt1.y,
1137  pt2.z - pt1.z);
1138  if(facingTheCam && this->max_angle_)
1139  {
1140  Eigen::Vector3f normal3D;
1141  normal3D = e0.cross(e1);
1142  angleToCam = pcl::getAngle3D(Eigen::Vector4f(normal3D[0], normal3D[1], normal3D[2], 0.0f), Eigen::Vector4f(0.0f,0.0f,-1.0f,0.0f));
1143  }
1144 
1145  // longest edge
1146  float e0norm2 = e0[0]*e0[0] + e0[1]*e0[1] + e0[2]*e0[2];
1147  float e1norm2 = e1[0]*e1[0] + e1[1]*e1[1] + e1[2]*e1[2];
1148  float e2norm2 = e2[0]*e2[0] + e2[1]*e2[1] + e2[2]*e2[2];
1149  float longestEdgeSqrd = std::max(std::max(e0norm2, e1norm2), e2norm2);
1150 
1151  pcl::PointXY center;
1152  center.x = (uv_coords1.x+uv_coords2.x+uv_coords3.x)/3.0f;
1153  center.y = (uv_coords1.y+uv_coords2.y+uv_coords3.y)/3.0f;
1154  visibleFaces[current_cam].insert(visibleFaces[current_cam].end(), std::make_pair(idx_face, FaceInfo(distanceToCam, angleToCam, longestEdgeSqrd, facingTheCam, uv_coords1, uv_coords2, uv_coords3, center)));
1155  sortedVisibleFaces.insert(std::make_pair(distanceToCam, idx_face));
1156  visibilityIndices[oi] = idx_face;
1157  ++oi;
1158  }
1159  }
1160  visibilityIndices.resize(oi);
1161  projections->resize(oi*3);
1162  UASSERT(projections->size() == visibilityIndices.size()*3);
1163 
1164  //filter occluded polygons
1165  //create kdtree
1166  pcl::KdTreeFLANN<pcl::PointXY> kdtree;
1167  kdtree.setInputCloud (projections);
1168 
1169  std::vector<int> idxNeighbors;
1170  std::vector<float> neighborsSquaredDistance;
1171  // af first (idx_pcan < current_cam), check if some of the faces attached to previous cameras occlude the current faces
1172  // then (idx_pcam == current_cam), check for self occlusions. At this stage, we skip faces that were already marked as occluded
1173  // project all faces
1174  std::set<int> occludedFaces;
1175  for (std::map<float, int>::iterator jter=sortedVisibleFaces.begin(); jter!=sortedVisibleFaces.end(); ++jter)
1176  //for (unsigned int idx = 0; idx<visibilityIndices.size(); ++idx)
1177  {
1178  int idx_face = jter->second;
1179  //int idx_face = visibilityIndices[idx];
1180  std::map<int, FaceInfo>::iterator iter= visibleFaces[current_cam].find(idx_face);
1181  UASSERT(iter != visibleFaces[current_cam].end());
1182 
1183  FaceInfo & info = iter->second;
1184 
1185  // face is in the camera's FOV
1186  //get its circumsribed circle
1187  double radius;
1188  pcl::PointXY center;
1189  // getTriangleCircumcenterAndSize (info.uv_coord1, info.uv_coord2, info.uv_coord3, center, radius);
1190  getTriangleCircumcscribedCircleCentroid(info.uv_coord1, info.uv_coord2, info.uv_coord3, center, radius); // this function yields faster results than getTriangleCircumcenterAndSize
1191 
1192  // get points inside circ.circle
1193  if (kdtree.radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
1194  {
1195  // for each neighbor
1196  for (size_t i = 0; i < idxNeighbors.size (); ++i)
1197  {
1198  int neighborFaceIndex = idxNeighbors[i]/3;
1199  //std::map<int, FaceInfo>::iterator jter= visibleFaces[current_cam].find(visibilityIndices[neighborFaceIndex]);
1200  //if(jter != visibleFaces[current_cam].end())
1201  {
1202  if (std::max(camera_cloud->points[faces[idx_face].vertices[0]].z,
1203  std::max (camera_cloud->points[faces[idx_face].vertices[1]].z,
1204  camera_cloud->points[faces[idx_face].vertices[2]].z))
1205  < camera_cloud->points[faces[visibilityIndices[neighborFaceIndex]].vertices[idxNeighbors[i]%3]].z)
1206  //if (info.distance < jter->second.distance)
1207  {
1208  // neighbor is farther than all the face's points. Check if it falls into the triangle
1209  if (checkPointInsideTriangle(info.uv_coord1, info.uv_coord2, info.uv_coord3, projections->at(idxNeighbors[i])))
1210  {
1211  // current neighbor is inside triangle and is closer => the corresponding face
1212  occludedFaces.insert(visibilityIndices[neighborFaceIndex]);
1213  //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
1214  }
1215  }
1216  }
1217  }
1218  }
1219  }
1220 
1221  // remove occluded faces
1222  for(std::set<int>::iterator iter= occludedFaces.begin(); iter!=occludedFaces.end(); ++iter)
1223  {
1224  visibleFaces[current_cam].erase(*iter);
1225  }
1226 
1227  // filter clusters
1228  int clusterFaces = 0;
1229 
1230  std::vector<pcl::Vertices> polygons(visibleFaces[current_cam].size());
1231  std::vector<int> polygon_to_face_index(visibleFaces[current_cam].size());
1232  oi =0;
1233  for(std::map<int, FaceInfo>::iterator iter=visibleFaces[current_cam].begin(); iter!=visibleFaces[current_cam].end(); ++iter)
1234  {
1235  polygons[oi].vertices.resize(3);
1236  polygons[oi].vertices[0] = faces[iter->first].vertices[0];
1237  polygons[oi].vertices[1] = faces[iter->first].vertices[1];
1238  polygons[oi].vertices[2] = faces[iter->first].vertices[2];
1239  polygon_to_face_index[oi] = iter->first;
1240  ++oi;
1241  }
1242 
1243  std::vector<std::set<int> > neighbors;
1244  std::vector<std::set<int> > vertexToPolygons;
1246  (int)camera_cloud->size(),
1247  neighbors,
1248  vertexToPolygons);
1249  std::list<std::list<int> > clusters = rtabmap::util3d::clusterPolygons(
1250  neighbors,
1251  min_cluster_size_);
1252  std::set<int> polygonsKept;
1253  for(std::list<std::list<int> >::iterator iter=clusters.begin(); iter!=clusters.end(); ++iter)
1254  {
1255  for(std::list<int>::iterator jter=iter->begin(); jter!=iter->end(); ++jter)
1256  {
1257  polygonsKept.insert(polygon_to_face_index[*jter]);
1258  faceCameras[polygon_to_face_index[*jter]].push_back(current_cam);
1259  }
1260  }
1261 
1262  for(std::map<int, FaceInfo>::iterator iter=visibleFaces[current_cam].begin(); iter!=visibleFaces[current_cam].end();)
1263  {
1264  if(polygonsKept.find(iter->first) == polygonsKept.end())
1265  {
1266  visibleFaces[current_cam].erase(iter++);
1267  ++clusterFaces;
1268  }
1269  else
1270  {
1271  ++iter;
1272  }
1273  }
1274 
1275  std::string msg = uFormat("Processed camera %d/%d: %d occluded and %d spurious polygons out of %d", (int)current_cam+1, (int)cameras.size(), (int)occludedFaces.size(), clusterFaces, (int)visibilityIndices.size());
1276  UINFO(msg.c_str());
1277  if(state && !state->callback(msg))
1278  {
1279  //cancelled!
1280  UWARN("Texturing cancelled!");
1281  return false;
1282  }
1283  }
1284 
1285  std::string msg = uFormat("Texturing %d polygons...", (int)faces.size());
1286  UINFO(msg.c_str());
1287  if(state && !state->callback(msg))
1288  {
1289  //cancelled!
1290  UWARN("Texturing cancelled!");
1291  return false;
1292  }
1293  int textured = 0;
1294  if(vertexToPixels)
1295  {
1296  *vertexToPixels = std::vector<std::map<int, pcl::PointXY> >(mesh_cloud->size());
1297  }
1298  for(unsigned int idx_face=0; idx_face<faces.size(); ++idx_face)
1299  {
1300  if((idx_face+1)%10000 == 0)
1301  {
1302  UDEBUG("face %d/%d", idx_face+1, (int)faces.size());
1303  if(state && !state->callback(uFormat("Textured %d/%d of %d polygons", textured, idx_face+1, (int)faces.size())))
1304  {
1305  //cancelled!
1306  UWARN("Texturing cancelled!");
1307  return false;
1308  }
1309  }
1310  pcl::Vertices & face = faces[idx_face];
1311 
1312  int cameraIndex = -1;
1313  float smallestWeight = std::numeric_limits<float>::max();
1314  bool depthSet = false;
1315  pcl::PointXY uv_coords[3];
1316  for (std::list<int>::iterator camIter = faceCameras[idx_face].begin(); camIter!=faceCameras[idx_face].end(); ++camIter)
1317  {
1318  int current_cam = *camIter;
1319  std::map<int, FaceInfo>::iterator iter = visibleFaces[current_cam].find(idx_face);
1320  UASSERT(iter != visibleFaces[current_cam].end());
1321  if (iter->second.facingTheCam && (max_angle_ <=0.0f || iter->second.angle <= max_angle_))
1322  {
1323  float distanceToCam = iter->second.distance;
1324  float vx = (iter->second.uv_coord1.x+iter->second.uv_coord2.x+ iter->second.uv_coord3.x)/3.0f-0.5f;
1325  float vy = (iter->second.uv_coord1.y+iter->second.uv_coord2.y+ iter->second.uv_coord3.y)/3.0f-0.5f;
1326  float distanceToCenter = vx*vx+vy*vy;
1327 
1328  cv::Mat depth = cameras[current_cam].depth;
1329  bool currentDepthSet = false;
1330  float maxDepthError = max_depth_error_==0.0f?std::sqrt(iter->second.longestEdgeSqrd)*2.0f : max_depth_error_;
1331  if(!cameras[current_cam].depth.empty() && maxDepthError > 0.0f)
1332  {
1333  float d1 = depth.type() == CV_32FC1?
1334  depth.at<float>((1.0f-iter->second.uv_coord1.y)*depth.rows, iter->second.uv_coord1.x*depth.cols):
1335  float(depth.at<unsigned short>((1.0f-iter->second.uv_coord1.y)*depth.rows, iter->second.uv_coord1.x*depth.cols))/1000.0f;
1336  float d2 = depth.type() == CV_32FC1?
1337  depth.at<float>((1.0f-iter->second.uv_coord2.y)*depth.rows, iter->second.uv_coord2.x*depth.cols):
1338  float(depth.at<unsigned short>((1.0f-iter->second.uv_coord2.y)*depth.rows, iter->second.uv_coord2.x*depth.cols))/1000.0f;
1339  float d3 = depth.type() == CV_32FC1?
1340  depth.at<float>((1.0f-iter->second.uv_coord3.y)*depth.rows, iter->second.uv_coord3.x*depth.cols):
1341  float(depth.at<unsigned short>((1.0f-iter->second.uv_coord3.y)*depth.rows, iter->second.uv_coord3.x*depth.cols))/1000.0f;
1342  if(d1 <= 0.0f || !std::isfinite(d1) || d2 <= 0.0f || !std::isfinite(d2) || d3 <= 0.0f || !std::isfinite(d3))
1343  {
1344  if(depthSet)
1345  {
1346  // ignore pixels with no depth
1347  continue;
1348  }
1349  else if(d1 > 0.0f && std::isfinite(d1) && fabs(d1 - distanceToCam) > maxDepthError)
1350  {
1351  // ignore pixels with too much depth error
1352  continue;
1353  }
1354  else if(d2 > 0.0f && std::isfinite(d2) && fabs(d2 - distanceToCam) > maxDepthError)
1355  {
1356  // ignore pixels with too much depth error
1357  continue;
1358  }
1359  else if(d3 > 0.0f && std::isfinite(d3) && fabs(d3 - distanceToCam) > maxDepthError)
1360  {
1361  // ignore pixels with too much depth error
1362  continue;
1363  }
1364  //else it could be a window for which no depth is available on any cameras
1365  }
1366  else
1367  {
1368  if(fabs(d1 - distanceToCam) > maxDepthError ||
1369  fabs(d2 - distanceToCam) > maxDepthError ||
1370  fabs(d3 - distanceToCam) > maxDepthError)
1371  {
1372  // ignore pixels with too much depth error
1373  continue;
1374  }
1375  currentDepthSet = true;
1376  }
1377  }
1378 
1379  if(vertexToPixels)
1380  {
1381  vertexToPixels->at(face.vertices[0]).insert(std::make_pair(current_cam, iter->second.uv_coord1));
1382  vertexToPixels->at(face.vertices[1]).insert(std::make_pair(current_cam, iter->second.uv_coord2));
1383  vertexToPixels->at(face.vertices[2]).insert(std::make_pair(current_cam, iter->second.uv_coord3));
1384  }
1385 
1386  //UDEBUG("Process polygon %d cam =%d distanceToCam=%f", idx_face, current_cam, distanceToCam);
1387 
1388  if(distanceToCenter <= smallestWeight || (!depthSet && currentDepthSet))
1389  {
1390  cameraIndex = current_cam;
1391  smallestWeight = distanceToCenter;
1392  uv_coords[0] = iter->second.uv_coord1;
1393  uv_coords[1] = iter->second.uv_coord2;
1394  uv_coords[2] = iter->second.uv_coord3;
1395  if(!depthSet && currentDepthSet)
1396  {
1397  depthSet = true;
1398  }
1399  }
1400  }
1401  }
1402 
1403  if(cameraIndex >= 0)
1404  {
1405  ++textured;
1406  mesh.tex_polygons[cameraIndex].push_back(face);
1407  mesh.tex_coordinates[cameraIndex].push_back(Eigen::Vector2f(uv_coords[0].x, uv_coords[0].y));
1408  mesh.tex_coordinates[cameraIndex].push_back(Eigen::Vector2f(uv_coords[1].x, uv_coords[1].y));
1409  mesh.tex_coordinates[cameraIndex].push_back(Eigen::Vector2f(uv_coords[2].x, uv_coords[2].y));
1410  }
1411  else
1412  {
1413  mesh.tex_polygons[cameras.size()].push_back(face);
1414  mesh.tex_coordinates[cameras.size()].push_back(Eigen::Vector2f(-1.0,-1.0));
1415  mesh.tex_coordinates[cameras.size()].push_back(Eigen::Vector2f(-1.0,-1.0));
1416  mesh.tex_coordinates[cameras.size()].push_back(Eigen::Vector2f(-1.0,-1.0));
1417  }
1418  }
1419  UINFO("Process %d polygons...done! (%d textured)", (int)faces.size(), textured);
1420 
1421  return true;
1422 }
1423 
1425 template<typename PointInT> inline void
1426 pcl::TextureMapping<PointInT>::getTriangleCircumcenterAndSize(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circomcenter, double &radius)
1427 {
1428  // we simplify the problem by translating the triangle's origin to its first point
1429  pcl::PointXY ptB, ptC;
1430  ptB.x = p2.x - p1.x; ptB.y = p2.y - p1.y; // B'=B-A
1431  ptC.x = p3.x - p1.x; ptC.y = p3.y - p1.y; // C'=C-A
1432 
1433  double D = 2.0*(ptB.x*ptC.y - ptB.y*ptC.x); // D'=2(B'x*C'y - B'y*C'x)
1434 
1435  // Safety check to avoid division by zero
1436  if(D == 0)
1437  {
1438  circomcenter.x = p1.x;
1439  circomcenter.y = p1.y;
1440  }
1441  else
1442  {
1443  // compute squares once
1444  double bx2 = ptB.x * ptB.x; // B'x^2
1445  double by2 = ptB.y * ptB.y; // B'y^2
1446  double cx2 = ptC.x * ptC.x; // C'x^2
1447  double cy2 = ptC.y * ptC.y; // C'y^2
1448 
1449  // compute circomcenter's coordinates (translate back to original coordinates)
1450  circomcenter.x = static_cast<float> (p1.x + (ptC.y*(bx2 + by2) - ptB.y*(cx2 + cy2)) / D);
1451  circomcenter.y = static_cast<float> (p1.y + (ptB.x*(cx2 + cy2) - ptC.x*(bx2 + by2)) / D);
1452  }
1453 
1454  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));
1455 }
1456 
1458 template<typename PointInT> inline void
1459 pcl::TextureMapping<PointInT>::getTriangleCircumcscribedCircleCentroid ( const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circumcenter, double &radius)
1460 {
1461  // compute centroid's coordinates (translate back to original coordinates)
1462  circumcenter.x = static_cast<float> (p1.x + p2.x + p3.x ) / 3;
1463  circumcenter.y = static_cast<float> (p1.y + p2.y + p3.y ) / 3;
1464  double r1 = (circumcenter.x - p1.x) * (circumcenter.x - p1.x) + (circumcenter.y - p1.y) * (circumcenter.y - p1.y) ;
1465  double r2 = (circumcenter.x - p2.x) * (circumcenter.x - p2.x) + (circumcenter.y - p2.y) * (circumcenter.y - p2.y) ;
1466  double r3 = (circumcenter.x - p3.x) * (circumcenter.x - p3.x) + (circumcenter.y - p3.y) * (circumcenter.y - p3.y) ;
1467 
1468  // radius
1469  radius = std::sqrt( std::max( r1, std::max( r2, r3) )) ;
1470 }
1471 
1472 
1474 template<typename PointInT> inline bool
1475 pcl::TextureMapping<PointInT>::getPointUVCoordinates(const PointInT &pt, const Camera &cam, pcl::PointXY &UV_coordinates)
1476 {
1477  if (pt.z > 0 && (max_distance_<=0.0f || pt.z<max_distance_))
1478  {
1479  // compute image center and dimension
1480  double sizeX = cam.width;
1481  double sizeY = cam.height;
1482  double cx, cy;
1483  if (cam.center_w > 0)
1484  cx = cam.center_w;
1485  else
1486  cx = sizeX / 2.0;
1487  if (cam.center_h > 0)
1488  cy = cam.center_h;
1489  else
1490  cy = sizeY / 2.0;
1491 
1492  double focal_x, focal_y;
1493  if (cam.focal_length_w > 0)
1494  focal_x = cam.focal_length_w;
1495  else
1496  focal_x = cam.focal_length;
1497  if (cam.focal_length_h > 0)
1498  focal_y = cam.focal_length_h;
1499  else
1500  focal_y = cam.focal_length;
1501 
1502  // project point on camera's image plane
1503  UV_coordinates.x = static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX); //horizontal
1504  UV_coordinates.y = static_cast<float> ((focal_y * (pt.y / pt.z) + cy) / sizeY); //vertical
1505 
1506  if(cam.roi.size() == 4)
1507  {
1508  if( UV_coordinates.x < cam.roi[0]/sizeX ||
1509  UV_coordinates.y < cam.roi[1]/sizeY ||
1510  UV_coordinates.x > (cam.roi[0]+cam.roi[2])/sizeX ||
1511  UV_coordinates.y > (cam.roi[1]+cam.roi[3])/sizeY)
1512  {
1513  // point is NOT in region of interest of the camera
1514  UV_coordinates.x = -1.0f;
1515  UV_coordinates.y = -1.0f;
1516  return false;
1517  }
1518  }
1519 
1520  // point is visible!
1521  if (UV_coordinates.x >= 0.0 && UV_coordinates.x <= 1.0 && UV_coordinates.y >= 0.0 && UV_coordinates.y <= 1.0)
1522  {
1523  // point is visible by the camera
1524  // original code of PCL inverted y
1525  UV_coordinates.y = 1.0f - UV_coordinates.y;
1526  return (true);
1527  }
1528  }
1529 
1530  // point is NOT visible by the camera
1531  UV_coordinates.x = -1.0f;
1532  UV_coordinates.y = -1.0f;
1533  return (false); // point was not visible by the camera
1534 }
1535 
1537 template<typename PointInT> inline bool
1538 pcl::TextureMapping<PointInT>::checkPointInsideTriangle(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, const pcl::PointXY &pt)
1539 {
1540  // Compute vectors
1541  Eigen::Vector2d v0, v1, v2;
1542  v0(0) = p3.x - p1.x; v0(1) = p3.y - p1.y; // v0= C - A
1543  v1(0) = p2.x - p1.x; v1(1) = p2.y - p1.y; // v1= B - A
1544  v2(0) = pt.x - p1.x; v2(1) = pt.y - p1.y; // v2= P - A
1545 
1546  // Compute dot products
1547  double dot00 = v0.dot(v0); // dot00 = dot(v0, v0)
1548  double dot01 = v0.dot(v1); // dot01 = dot(v0, v1)
1549  double dot02 = v0.dot(v2); // dot02 = dot(v0, v2)
1550  double dot11 = v1.dot(v1); // dot11 = dot(v1, v1)
1551  double dot12 = v1.dot(v2); // dot12 = dot(v1, v2)
1552 
1553  // Compute barycentric coordinates
1554  double invDenom = 1.0 / (dot00*dot11 - dot01*dot01);
1555  double u = (dot11*dot02 - dot01*dot12) * invDenom;
1556  double v = (dot00*dot12 - dot01*dot02) * invDenom;
1557 
1558  // Check if point is in triangle
1559  return ((u >= 0) && (v >= 0) && (u + v < 1));
1560 }
1561 
1563 template<typename PointInT> inline bool
1564 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)
1565 {
1566  return getPointUVCoordinates(p1, camera, proj1)
1567  &&
1568  getPointUVCoordinates(p2, camera, proj2)
1569  &&
1570  getPointUVCoordinates(p3, camera, proj3);
1571 }
1572 
1573 #define PCL_INSTANTIATE_TextureMapping(T) \
1574  template class PCL_EXPORTS pcl::TextureMapping<T>;
1575 
1576 #endif /* TEXTURE_MAPPING_HPP_ */
1577 
rtabmap::CameraThread * cam
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. Point-based segmentation.
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.
GLM_FUNC_DECL bool isfinite(genType const &x)
Test whether or not a scalar or each vector component is a finite value. (From GLM_GTX_compatibility)...
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP transformPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const Transform &transform)
f
pcl::PointXY uv_coord3
bool textureMeshwithMultipleCameras2(pcl::TextureMesh &mesh, const pcl::texture_mapping::CameraVector &cameras, const rtabmap::ProgressState *callback=0, std::vector< std::map< int, pcl::PointXY > > *vertexToPixels=0)
std::vector< Camera, Eigen::aligned_allocator< Camera > > CameraVector
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
pcl::PointXY uv_coord2
const float maxDepthError
Definition: CameraTango.cpp:42
bool isPointOccluded(const PointInT &pt, const OctreePtr octree)
Check if a point is occluded using raycasting on octree.
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.
FaceInfo(float d, float a, float edge, bool facingCam, const pcl::PointXY &uv1, const pcl::PointXY &uv2, const pcl::PointXY &uv3, const pcl::PointXY &center)
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.
pcl::octree::OctreePointCloudSearch< PointInT > Octree
GLM_FUNC_DECL genType sign(genType const &x)
std::vector< double > roi
#define UASSERT(condition)
GLM_FUNC_DECL genType cos(genType const &angle)
bool ptInTriangle(const pcl::PointXY &p0, const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p)
Structure that links a uv coordinate to its 3D point and face.
Structure to store camera pose and focal length.
virtual bool callback(const std::string &msg) const
Definition: ProgressState.h:39
pcl::PointXY uv_center
GLM_FUNC_DECL genType sin(genType const &angle)
std::list< std::list< int > > RTABMAP_EXP clusterPolygons(const std::vector< std::set< int > > &neighborPolygons, int minClusterSize=0)
pcl::PointCloud< PointInT > PointCloud
void mapTexture2MeshUV(pcl::TextureMesh &tex_mesh)
Map texture to a mesh UV mapping.
PointCloud::Ptr PointCloudPtr
void textureMeshwithMultipleCameras(pcl::TextureMesh &mesh, const pcl::texture_mapping::CameraVector &cameras)
Segment and texture faces by camera visibility. Face-based segmentation.
void mapMultipleTexturesToMeshUV(pcl::TextureMesh &tex_mesh, pcl::texture_mapping::CameraVector &cams)
Map textures acquired from a set of cameras onto a mesh.
void mapTexture2Mesh(pcl::TextureMesh &tex_mesh)
Map texture to a mesh synthesis algorithm.
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.
RecoveryProgressState state
pcl::PointXY uv_coord1
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.
#define UDEBUG(...)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
float longestEdgeSqrd
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.
void RTABMAP_EXP createPolygonIndexes(const std::vector< pcl::Vertices > &polygons, int cloudSize, std::vector< std::set< int > > &neighborPolygons, std::vector< std::set< int > > &vertexPolygons)
Given a set of polygons, create two indexes: polygons to neighbor polygons and vertices to polygons...
GLM_FUNC_DECL genType acos(genType const &x)
#define UWARN(...)
bool getPointUVCoordinates(const PointInT &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
computes UV coordinates of point, observed by one particular camera
PointCloud::ConstPtr PointCloudConstPtr
std::string UTILITE_EXP uFormat(const char *fmt,...)
#define UINFO(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:40