texture_mapping.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #ifndef PCL_SURFACE_TEXTURE_MAPPING_H_
41 #define PCL_SURFACE_TEXTURE_MAPPING_H_
42 
43 #include <pcl/surface/reconstruction.h>
44 #include <pcl/common/transforms.h>
45 #include <pcl/TextureMesh.h>
46 #include <pcl/octree/octree.h>
49 #include <rtabmap/utilite/UStl.h>
51 
52 
53 namespace pcl
54 {
55  namespace texture_mapping
56  {
57 
68  struct Camera
69  {
71  center_w (-1), center_h (-1), height (), width (), texture_file () {}
72  Eigen::Affine3f pose;
73  double focal_length;
74  double focal_length_w; // optional
75  double focal_length_h; // optinoal
76  double center_w; // optional
77  double center_h; // optional
78  double height;
79  double width;
80  std::string texture_file;
81  std::vector<double> roi; // [x, y, width, height]
82  cv::Mat depth;
83 
84  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
85  };
86 
89  struct UvIndex
90  {
91  UvIndex () : idx_cloud (), idx_face () {}
92  int idx_cloud; // Index of the PointXYZ in the camera's cloud
93  int idx_face; // Face corresponding to that projection
94  };
95 
96  typedef std::vector<Camera, Eigen::aligned_allocator<Camera> > CameraVector;
97 
98  }
99 
104  template<typename PointInT>
106  {
107  public:
108 
111 
112  typedef pcl::PointCloud<PointInT> PointCloud;
113  typedef typename PointCloud::Ptr PointCloudPtr;
114  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
115 
116  typedef pcl::octree::OctreePointCloudSearch<PointInT> Octree;
117  typedef typename Octree::Ptr OctreePtr;
118  typedef typename Octree::ConstPtr OctreeConstPtr;
119 
122 
125  f_ (), vector_field_ (), tex_files_ (), tex_material_ (), max_distance_(0.0f), max_depth_error_(0.0f), max_angle_(0.0f), min_cluster_size_(50)
126  {
127  }
128 
131  {
132  }
133 
137  inline void
138  setF (float f)
139  {
140  f_ = f;
141  }
142 
148  inline void
149  setVectorField (float x, float y, float z)
150  {
151  vector_field_ = Eigen::Vector3f (x, y, z);
152  // normalize vector field
153  vector_field_ = vector_field_ / std::sqrt (vector_field_.dot (vector_field_));
154  }
155 
159  inline void
160  setTextureFiles (std::vector<std::string> tex_files)
161  {
162  tex_files_ = tex_files;
163  }
164 
168  inline void
169  setTextureMaterials (TexMaterial tex_material)
170  {
171  tex_material_ = tex_material;
172  }
173 
174  inline void
175  setMaxDistance(float maxDistance)
176  {
177  max_distance_ = maxDistance;
178  }
179 
180  inline void
182  {
183  max_depth_error_ = maxDepthError;
184  }
185 
186  inline void
187  setMaxAngle(float maxAngle)
188  {
189  max_angle_ = maxAngle;
190  }
191 
192  inline void
194  {
195  min_cluster_size_ = size;
196  }
197 
201  void
202  mapTexture2Mesh (pcl::TextureMesh &tex_mesh);
203 
207  void
208  mapTexture2MeshUV (pcl::TextureMesh &tex_mesh);
209 
216  void
217  mapMultipleTexturesToMeshUV (pcl::TextureMesh &tex_mesh,
219 
226  inline bool
227  getPointUVCoordinates (const PointInT &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
228  {
229  // if the point is in front of the camera
230  if (pt.z > 0 && (max_distance_ <= 0.0f || pt.z < max_distance_))
231  {
232  // compute image center and dimension
233  double sizeX = cam.width;
234  double sizeY = cam.height;
235  double cx, cy;
236  if (cam.center_w > 0)
237  cx = cam.center_w;
238  else
239  cx = (sizeX) / 2.0;
240  if (cam.center_h > 0)
241  cy = cam.center_h;
242  else
243  cy = (sizeY) / 2.0;
244 
245  double focal_x, focal_y;
246  if (cam.focal_length_w > 0)
247  focal_x = cam.focal_length_w;
248  else
249  focal_x = cam.focal_length;
250  if (cam.focal_length_h>0)
251  focal_y = cam.focal_length_h;
252  else
253  focal_y = cam.focal_length;
254 
255  // project point on image frame
256  UV_coordinates[0] = static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX); //horizontal
257  UV_coordinates[1] = 1.0f - static_cast<float> (((focal_y * (pt.y / pt.z) + cy) / sizeY)); //vertical
258 
259  // point is visible!
260  if (UV_coordinates[0] >= 0.0 && UV_coordinates[0] <= 1.0 && UV_coordinates[1] >= 0.0 && UV_coordinates[1]
261  <= 1.0)
262  return (true);
263  }
264 
265  // point is NOT visible by the camera
266  UV_coordinates[0] = -1.0;
267  UV_coordinates[1] = -1.0;
268  return (false);
269  }
270 
276  inline bool
277  isPointOccluded (const PointInT &pt, const OctreePtr octree);
278 
286  void
287  removeOccludedPoints (const PointCloudPtr &input_cloud,
288  PointCloudPtr &filtered_cloud, const double octree_voxel_size,
289  std::vector<int> &visible_indices, std::vector<int> &occluded_indices);
290 
296  void
297  removeOccludedPoints (const pcl::TextureMesh &tex_mesh, pcl::TextureMesh &cleaned_mesh, const double octree_voxel_size);
298 
299 
305  void
306  removeOccludedPoints (const pcl::TextureMesh &tex_mesh, PointCloudPtr &filtered_cloud, const double octree_voxel_size);
307 
308 
317  int
318  sortFacesByCamera (pcl::TextureMesh &tex_mesh,
319  pcl::TextureMesh &sorted_mesh,
320  const pcl::texture_mapping::CameraVector &cameras,
321  const double octree_voxel_size, PointCloud &visible_pts);
322 
333  void
334  showOcclusions (const PointCloudPtr &input_cloud,
335  pcl::PointCloud<pcl::PointXYZI>::Ptr &colored_cloud,
336  const double octree_voxel_size,
337  const bool show_nb_occlusions = true,
338  const int max_occlusions = 4);
339 
350  void
351  showOcclusions (pcl::TextureMesh &tex_mesh,
352  pcl::PointCloud<pcl::PointXYZI>::Ptr &colored_cloud,
353  double octree_voxel_size,
354  bool show_nb_occlusions = true,
355  int max_occlusions = 4);
356 
363  void
364  textureMeshwithMultipleCameras (pcl::TextureMesh &mesh,
365  const pcl::texture_mapping::CameraVector &cameras);
366  bool
367  textureMeshwithMultipleCameras2 (pcl::TextureMesh &mesh,
368  const pcl::texture_mapping::CameraVector &cameras,
369  const rtabmap::ProgressState * callback = 0,
370  std::vector<std::map<int, pcl::PointXY> > * vertexToPixels = 0,
371  bool distanceToCamPolicy = false);
372 
373  protected:
375  float f_;
376 
378  Eigen::Vector3f vector_field_;
379 
381  std::vector<std::string> tex_files_;
382 
384  TexMaterial tex_material_;
385 
388 
391 
393  float max_angle_;
394 
397 
403  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >
404  mapTexture2Face (const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, const Eigen::Vector3f &p3);
405 
414  inline void
415  getTriangleCircumcenterAndSize (const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circumcenter, double &radius);
416 
417 
426  inline void
427  getTriangleCircumcscribedCircleCentroid ( const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circumcenter, double &radius);
428 
429 
436  inline bool
437  getPointUVCoordinates (const PointInT &pt, const Camera &cam, pcl::PointXY &UV_coordinates);
438 
448  inline bool
449  isFaceProjected (const Camera &camera,
450  const PointInT &p1, const PointInT &p2, const PointInT &p3,
451  pcl::PointXY &proj1, pcl::PointXY &proj2, pcl::PointXY &proj3);
452 
460  inline bool
461  checkPointInsideTriangle (const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, const pcl::PointXY &pt);
462 
464  std::string
465  getClassName () const
466  {
467  return ("TextureMapping");
468  }
469 
470  public:
471  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
472  };
473 }
474 
476 
477 #endif /* TEXTURE_MAPPING_H_ */
478 
boost::shared_ptr< const TextureMapping< PointInT > > ConstPtr
float max_distance_
maximum distance between camera and polygon to apply a texture
void setVectorField(float x, float y, float z)
Set vector field.
rtabmap::CameraThread * cam
void setTextureMaterials(TexMaterial tex_material)
Set texture materials.
f
std::vector< Camera, Eigen::aligned_allocator< Camera > > CameraVector
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
TextureMapping()
Constructor.
const float maxDepthError
Definition: CameraTango.cpp:43
The texture mapping algorithm.
float max_depth_error_
maximum depth error between projected point and corresponding depth of the camera to apply a texture ...
void setMinClusterSize(int size)
Some conversion functions.
pcl::octree::OctreePointCloudSearch< PointInT > Octree
std::vector< double > roi
void setTextureFiles(std::vector< std::string > tex_files)
Set texture files.
int min_cluster_size_
Remove texture from small polygon clusters.
Wrappers of STL for convenient functions.
Structure that links a uv coordinate to its 3D point and face.
Structure to store camera pose and focal length.
~TextureMapping()
Destructor.
Octree::ConstPtr OctreeConstPtr
pcl::PointCloud< PointInT > PointCloud
PointCloud::Ptr PointCloudPtr
void setMaxDepthError(float maxDepthError)
std::string getClassName() const
Class get name method.
float max_angle_
maximum angle (rad) between camera and polygon to apply a texture
float f_
mesh scale control.
TexMaterial tex_material_
list of texture materials
std::vector< std::string > tex_files_
list of texture files
ULogger class and convenient macros.
pcl::texture_mapping::Camera Camera
void setMaxAngle(float maxAngle)
Eigen::Vector3f vector_field_
vector field
bool getPointUVCoordinates(const PointInT &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
computes UV coordinates of point, observed by one particular camera
void setMaxDistance(float maxDistance)
void setF(float f)
Set mesh scale control.
PointCloud::ConstPtr PointCloudConstPtr
pcl::texture_mapping::UvIndex UvIndex
boost::shared_ptr< TextureMapping< PointInT > > Ptr


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:38:57