00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef PCL_SURFACE_TEXTURE_MAPPING_H_
00041 #define PCL_SURFACE_TEXTURE_MAPPING_H_
00042
00043 #include <pcl/surface/reconstruction.h>
00044 #include <pcl/common/transforms.h>
00045 #include <pcl/TextureMesh.h>
00046
00047
00048 namespace pcl
00049 {
00050 namespace texture_mapping
00051 {
00052
00054 struct Camera
00055 {
00056 Camera () : pose (), focal_length (), height (), width (), texture_file () {}
00057 Eigen::Affine3f pose;
00058 double focal_length;
00059 double height;
00060 double width;
00061 std::string texture_file;
00062
00063 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00064 };
00065
00068 struct UvIndex
00069 {
00070 UvIndex () : idx_cloud (), idx_face () {}
00071 int idx_cloud;
00072 int idx_face;
00073 };
00074
00075 typedef std::vector<Camera, Eigen::aligned_allocator<Camera> > CameraVector;
00076
00077 }
00078
00083 template<typename PointInT>
00084 class TextureMapping
00085 {
00086 public:
00087
00088 typedef boost::shared_ptr< PointInT > Ptr;
00089 typedef boost::shared_ptr< const PointInT > ConstPtr;
00090
00091 typedef pcl::PointCloud<PointInT> PointCloud;
00092 typedef typename PointCloud::Ptr PointCloudPtr;
00093 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00094
00095 typedef pcl::octree::OctreePointCloudSearch<PointInT> Octree;
00096 typedef typename Octree::Ptr OctreePtr;
00097 typedef typename Octree::ConstPtr OctreeConstPtr;
00098
00099 typedef pcl::texture_mapping::Camera Camera;
00100 typedef pcl::texture_mapping::UvIndex UvIndex;
00101
00103 TextureMapping () :
00104 f_ (), vector_field_ (), tex_files_ (), tex_material_ ()
00105 {
00106 }
00107
00109 ~TextureMapping ()
00110 {
00111 }
00112
00116 inline void
00117 setF (float f)
00118 {
00119 f_ = f;
00120 }
00121
00127 inline void
00128 setVectorField (float x, float y, float z)
00129 {
00130 vector_field_ = Eigen::Vector3f (x, y, z);
00131
00132 vector_field_ = vector_field_ / std::sqrt (vector_field_.dot (vector_field_));
00133 }
00134
00138 inline void
00139 setTextureFiles (std::vector<std::string> tex_files)
00140 {
00141 tex_files_ = tex_files;
00142 }
00143
00147 inline void
00148 setTextureMaterials (TexMaterial tex_material)
00149 {
00150 tex_material_ = tex_material;
00151 }
00152
00156 void
00157 mapTexture2Mesh (pcl::TextureMesh &tex_mesh);
00158
00162 void
00163 mapTexture2MeshUV (pcl::TextureMesh &tex_mesh);
00164
00171 void
00172 mapMultipleTexturesToMeshUV (pcl::TextureMesh &tex_mesh,
00173 pcl::texture_mapping::CameraVector &cams);
00174
00181 inline bool
00182 getPointUVCoordinates (const pcl::PointXYZ &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
00183 {
00184
00185 if (pt.z > 0)
00186 {
00187
00188 double sizeX = cam.width;
00189 double sizeY = cam.height;
00190 double cx = (sizeX) / 2.0;
00191 double cy = (sizeY) / 2.0;
00192
00193 double focal_x = cam.focal_length;
00194 double focal_y = cam.focal_length;
00195
00196
00197 UV_coordinates[0] = static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX);
00198 UV_coordinates[1] = 1.0f - static_cast<float> (((focal_y * (pt.y / pt.z) + cy) / sizeY));
00199
00200
00201 if (UV_coordinates[0] >= 0.0 && UV_coordinates[0] <= 1.0 && UV_coordinates[1] >= 0.0 && UV_coordinates[1]
00202 <= 1.0)
00203 return (true);
00204 }
00205
00206
00207 UV_coordinates[0] = -1.0;
00208 UV_coordinates[1] = -1.0;
00209 return (false);
00210 }
00211
00217 inline bool
00218 isPointOccluded (const pcl::PointXYZ &pt, const OctreePtr octree);
00219
00227 void
00228 removeOccludedPoints (const PointCloudPtr &input_cloud,
00229 PointCloudPtr &filtered_cloud, const double octree_voxel_size,
00230 std::vector<int> &visible_indices, std::vector<int> &occluded_indices);
00231
00237 void
00238 removeOccludedPoints (const pcl::TextureMesh &tex_mesh, pcl::TextureMesh &cleaned_mesh, const double octree_voxel_size);
00239
00240
00246 void
00247 removeOccludedPoints (const pcl::TextureMesh &tex_mesh, PointCloudPtr &filtered_cloud, const double octree_voxel_size);
00248
00249
00258 int
00259 sortFacesByCamera (pcl::TextureMesh &tex_mesh,
00260 pcl::TextureMesh &sorted_mesh,
00261 const pcl::texture_mapping::CameraVector &cameras,
00262 const double octree_voxel_size, PointCloud &visible_pts);
00263
00274 void
00275 showOcclusions (const PointCloudPtr &input_cloud,
00276 pcl::PointCloud<pcl::PointXYZI>::Ptr &colored_cloud,
00277 const double octree_voxel_size,
00278 const bool show_nb_occlusions = true,
00279 const int max_occlusions = 4);
00280
00291 void
00292 showOcclusions (pcl::TextureMesh &tex_mesh,
00293 pcl::PointCloud<pcl::PointXYZI>::Ptr &colored_cloud,
00294 double octree_voxel_size,
00295 bool show_nb_occlusions = true,
00296 int max_occlusions = 4);
00297
00304 void
00305 textureMeshwithMultipleCameras (pcl::TextureMesh &mesh,
00306 const pcl::texture_mapping::CameraVector &cameras);
00307
00308 protected:
00310 float f_;
00311
00313 Eigen::Vector3f vector_field_;
00314
00316 std::vector<std::string> tex_files_;
00317
00319 TexMaterial tex_material_;
00320
00326 std::vector<Eigen::Vector2f>
00327 mapTexture2Face (const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, const Eigen::Vector3f &p3);
00328
00337 inline void
00338 getTriangleCircumcenterAndSize (const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circomcenter, double &radius);
00339
00346 inline bool
00347 getPointUVCoordinates (const pcl::PointXYZ &pt, const Camera &cam, pcl::PointXY &UV_coordinates);
00348
00358 inline bool
00359 isFaceProjected (const Camera &camera,
00360 const pcl::PointXYZ &p1, const pcl::PointXYZ &p2, const pcl::PointXYZ &p3,
00361 pcl::PointXY &proj1, pcl::PointXY &proj2, pcl::PointXY &proj3);
00362
00370 inline bool
00371 checkPointInsideTriangle (const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, const pcl::PointXY &pt);
00372
00374 std::string
00375 getClassName () const
00376 {
00377 return ("TextureMapping");
00378 }
00379
00380 public:
00381 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00382 };
00383 }
00384
00385 #endif
00386