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 () {}
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 
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 
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
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  {
184  }
185 
186  inline void
187  setMaxAngle(float maxAngle)
188  {
189  max_angle_ = maxAngle;
190  }
191 
192  inline void
194  {
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:
472  };
473 }
474 
476 
477 #endif /* TEXTURE_MAPPING_H_ */
478 
octree
pcl
Definition: CameraOpenni.h:47
cy
const double cy
pcl::TextureMapping::setTextureFiles
void setTextureFiles(std::vector< std::string > tex_files)
Set texture files.
Definition: texture_mapping.h:160
pcl::TextureMapping::isPointOccluded
bool isPointOccluded(const PointInT &pt, const OctreePtr octree)
Check if a point is occluded using raycasting on octree.
Definition: texture_mapping.hpp:395
pcl::TextureMapping::setMaxDepthError
void setMaxDepthError(float maxDepthError)
Definition: texture_mapping.h:181
Eigen::Transform
boost::shared_ptr
pcl::texture_mapping::Camera::center_w
double center_w
Definition: texture_mapping.h:76
pcl::texture_mapping::Camera::focal_length
double focal_length
Definition: texture_mapping.h:73
pcl::TextureMapping::mapTexture2Mesh
void mapTexture2Mesh(pcl::TextureMesh &tex_mesh)
Map texture to a mesh synthesis algorithm.
Definition: texture_mapping.hpp:146
pcl::texture_mapping::UvIndex::idx_face
int idx_face
Definition: texture_mapping.h:93
size
Index size
pcl::TextureMapping::setMaxDistance
void setMaxDistance(float maxDistance)
Definition: texture_mapping.h:175
pcl::texture_mapping::Camera::texture_file
std::string texture_file
Definition: texture_mapping.h:80
pcl::TextureMapping::tex_files_
std::vector< std::string > tex_files_
list of texture files
Definition: texture_mapping.h:381
pcl::TextureMapping::removeOccludedPoints
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.
Definition: texture_mapping.hpp:437
y
Matrix3f y
ProgressState.h
pcl::TextureMapping::getTriangleCircumcscribedCircleCentroid
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's radius.
Definition: texture_mapping.hpp:1468
pcl::TextureMapping::Octree
pcl::octree::OctreePointCloudSearch< PointInT > Octree
Definition: texture_mapping.h:116
rtabmap::maxDepthError
const float maxDepthError
Definition: CameraTango.cpp:43
cam
rtabmap::SensorCaptureThread * cam
Definition: tools/DataRecorder/main.cpp:58
pcl::TextureMapping::min_cluster_size_
int min_cluster_size_
Remove texture from small polygon clusters.
Definition: texture_mapping.h:396
pcl::texture_mapping::Camera::roi
std::vector< double > roi
Definition: texture_mapping.h:81
pcl::TextureMapping
The texture mapping algorithm.
Definition: texture_mapping.h:105
pcl::texture_mapping::Camera::center_h
double center_h
Definition: texture_mapping.h:77
pcl::TextureMapping::PointCloud
pcl::PointCloud< PointInT > PointCloud
Definition: texture_mapping.h:112
pcl::TextureMapping::f_
float f_
mesh scale control.
Definition: texture_mapping.h:375
pcl::TextureMapping::PointCloudConstPtr
PointCloud::ConstPtr PointCloudConstPtr
Definition: texture_mapping.h:114
pcl::TextureMapping::mapTexture2MeshUV
void mapTexture2MeshUV(pcl::TextureMesh &tex_mesh)
Map texture to a mesh UV mapping.
Definition: texture_mapping.hpp:206
pcl::TextureMapping::setTextureMaterials
void setTextureMaterials(TexMaterial tex_material)
Set texture materials.
Definition: texture_mapping.h:169
UConversion.h
Some conversion functions.
glm::sqrt
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
pcl::TextureMapping::UvIndex
pcl::texture_mapping::UvIndex UvIndex
Definition: texture_mapping.h:121
pcl::TextureMapping::Ptr
boost::shared_ptr< TextureMapping< PointInT > > Ptr
Definition: texture_mapping.h:109
pcl::TextureMapping::OctreePtr
Octree::Ptr OctreePtr
Definition: texture_mapping.h:117
pcl::TextureMapping::ConstPtr
boost::shared_ptr< const TextureMapping< PointInT > > ConstPtr
Definition: texture_mapping.h:110
pcl::texture_mapping::UvIndex::UvIndex
UvIndex()
Definition: texture_mapping.h:91
pcl::TextureMapping::vector_field_
Eigen::Vector3f vector_field_
vector field
Definition: texture_mapping.h:378
pcl::TextureMapping::setVectorField
void setVectorField(float x, float y, float z)
Set vector field.
Definition: texture_mapping.h:149
rtabmap::ProgressState
Definition: ProgressState.h:35
z
z
x
x
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
pcl::TextureMapping::isFaceProjected
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's image plane.
Definition: texture_mapping.hpp:1573
pcl::TextureMapping::checkPointInsideTriangle
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.
Definition: texture_mapping.hpp:1547
pcl::TextureMapping::tex_material_
TexMaterial tex_material_
list of texture materials
Definition: texture_mapping.h:384
pcl::texture_mapping::Camera::focal_length_w
double focal_length_w
Definition: texture_mapping.h:74
pcl::TextureMapping::OctreeConstPtr
Octree::ConstPtr OctreeConstPtr
Definition: texture_mapping.h:118
pcl::texture_mapping::UvIndex::idx_cloud
int idx_cloud
Definition: texture_mapping.h:92
pcl::TextureMapping::textureMeshwithMultipleCameras2
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, bool distanceToCamPolicy=false)
Definition: texture_mapping.hpp:1049
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
pcl::TextureMapping::PointCloudPtr
PointCloud::Ptr PointCloudPtr
Definition: texture_mapping.h:113
pcl::texture_mapping::Camera::depth
cv::Mat depth
Definition: texture_mapping.h:82
ULogger.h
ULogger class and convenient macros.
pcl::TextureMapping::max_distance_
float max_distance_
maximum distance between camera and polygon to apply a texture
Definition: texture_mapping.h:387
pcl::texture_mapping::UvIndex
Structure that links a uv coordinate to its 3D point and face.
Definition: texture_mapping.h:89
pcl::TextureMapping::mapTexture2Face
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.
Definition: texture_mapping.hpp:48
pcl::texture_mapping::Camera::height
double height
Definition: texture_mapping.h:78
pcl::TextureMapping::getClassName
std::string getClassName() const
Class get name method.
Definition: texture_mapping.h:465
pcl::texture_mapping::Camera::Camera
Camera()
Definition: texture_mapping.h:70
pcl::TextureMapping::setMinClusterSize
void setMinClusterSize(int size)
Definition: texture_mapping.h:193
pcl::TextureMapping::max_depth_error_
float max_depth_error_
maximum depth error between projected point and corresponding depth of the camera to apply a texture
Definition: texture_mapping.h:390
pcl::texture_mapping::Camera
Structure to store camera pose and focal length.
Definition: texture_mapping.h:68
pcl::TextureMapping::mapMultipleTexturesToMeshUV
void mapMultipleTexturesToMeshUV(pcl::TextureMesh &tex_mesh, pcl::texture_mapping::CameraVector &cams)
Map textures acquired from a set of cameras onto a mesh.
Definition: texture_mapping.hpp:297
UStl.h
Wrappers of STL for convenient functions.
pcl::TextureMapping::getTriangleCircumcenterAndSize
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's radius.
Definition: texture_mapping.hpp:1435
pcl::TextureMapping::showOcclusions
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.
Definition: texture_mapping.hpp:669
pcl::TextureMapping::TextureMapping
TextureMapping()
Constructor.
Definition: texture_mapping.h:124
pcl::TextureMapping::textureMeshwithMultipleCameras
void textureMeshwithMultipleCameras(pcl::TextureMesh &mesh, const pcl::texture_mapping::CameraVector &cameras)
Segment and texture faces by camera visibility. Face-based segmentation.
Definition: texture_mapping.hpp:761
cx
const double cx
pcl::texture_mapping::Camera::width
double width
Definition: texture_mapping.h:79
texture_mapping.hpp
pcl::TextureMapping::setMaxAngle
void setMaxAngle(float maxAngle)
Definition: texture_mapping.h:187
pcl::texture_mapping::Camera::focal_length_h
double focal_length_h
Definition: texture_mapping.h:75
pcl::texture_mapping::CameraVector
std::vector< Camera, Eigen::aligned_allocator< Camera > > CameraVector
Definition: texture_mapping.h:96
pcl::TextureMapping::Camera
pcl::texture_mapping::Camera Camera
Definition: texture_mapping.h:120
pcl::TextureMapping::sortFacesByCamera
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.
Definition: texture_mapping.hpp:572
pcl::TextureMapping::max_angle_
float max_angle_
maximum angle (rad) between camera and polygon to apply a texture
Definition: texture_mapping.h:393
pcl::TextureMapping::getPointUVCoordinates
bool getPointUVCoordinates(const PointInT &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
computes UV coordinates of point, observed by one particular camera
Definition: texture_mapping.h:227
pcl::TextureMapping::~TextureMapping
~TextureMapping()
Destructor.
Definition: texture_mapping.h:130
pcl::texture_mapping::Camera::pose
Eigen::Affine3f pose
Definition: texture_mapping.h:72
pcl::TextureMapping::setF
void setF(float f)
Set mesh scale control.
Definition: texture_mapping.h:138


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:22