38 #ifndef PCL_SURFACE_IMPL_TEXTURE_MAPPING_HPP_ 39 #define PCL_SURFACE_IMPL_TEXTURE_MAPPING_HPP_ 41 #include <pcl/common/distances.h> 42 #include <pcl/surface/texture_mapping.h> 45 template<
typename Po
intInT> std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >
47 const Eigen::Vector3f &p1,
48 const Eigen::Vector3f &p2,
49 const Eigen::Vector3f &p3)
51 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates;
53 Eigen::Vector3f p1p2 (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]);
54 Eigen::Vector3f p1p3 (p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]);
55 Eigen::Vector3f p2p3 (p3[0] - p2[0], p3[1] - p2[1], p3[2] - p2[2]);
58 p1p2 = p1p2 / std::sqrt (p1p2.dot (p1p2));
59 p1p3 = p1p3 / std::sqrt (p1p3.dot (p1p3));
60 p2p3 = p2p3 / std::sqrt (p2p3.dot (p2p3));
63 Eigen::Vector3f f_normal = p1p2.cross (p1p3);
64 f_normal = f_normal / std::sqrt (f_normal.dot (f_normal));
67 Eigen::Vector3f f_vector_field = vector_field_ - vector_field_.dot (f_normal) * f_normal;
70 f_vector_field = f_vector_field / std::sqrt (f_vector_field.dot (f_vector_field));
73 Eigen::Vector2f tp1, tp2, tp3;
75 double alpha = std::acos (f_vector_field.dot (p1p2));
78 double e1 = (p2 - p3).norm () / f_;
79 double e2 = (p1 - p3).norm () / f_;
80 double e3 = (p1 - p2).norm () / f_;
86 tp2[0] =
static_cast<float> (e3);
90 double cos_p1 = (e2 * e2 + e3 * e3 - e1 * e1) / (2 * e2 * e3);
91 double sin_p1 = sqrt (1 - (cos_p1 * cos_p1));
93 tp3[0] =
static_cast<float> (cos_p1 * e2);
94 tp3[1] =
static_cast<float> (sin_p1 * e2);
97 Eigen::Vector2f r_tp2, r_tp3;
98 r_tp2[0] =
static_cast<float> (tp2[0] * std::cos (alpha) - tp2[1] * std::sin (alpha));
99 r_tp2[1] =
static_cast<float> (tp2[0] * std::sin (alpha) + tp2[1] * std::cos (alpha));
101 r_tp3[0] =
static_cast<float> (tp3[0] * std::cos (alpha) - tp3[1] * std::sin (alpha));
102 r_tp3[1] =
static_cast<float> (tp3[0] * std::sin (alpha) + tp3[1] * std::cos (alpha));
112 float min_x = tp1[0];
113 float min_y = tp1[1];
125 tp1[0] = tp1[0] - min_x;
126 tp2[0] = tp2[0] - min_x;
127 tp3[0] = tp3[0] - min_x;
131 tp1[1] = tp1[1] - min_y;
132 tp2[1] = tp2[1] - min_y;
133 tp3[1] = tp3[1] - min_y;
136 tex_coordinates.push_back (tp1);
137 tex_coordinates.push_back (tp2);
138 tex_coordinates.push_back (tp3);
139 return (tex_coordinates);
143 template<
typename Po
intInT>
void 148 int point_size =
static_cast<int> (tex_mesh.
cloud.
data.size ()) / nr_points;
153 Eigen::Vector3f facet[3];
156 std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > >texture_map;
158 for (
size_t m = 0; m < tex_mesh.
tex_polygons.size (); ++m)
161 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
164 for (
size_t i = 0; i < tex_mesh.
tex_polygons[m].size (); ++i)
169 for (
size_t j = 0; j < tex_mesh.
tex_polygons[m][i].vertices.size (); ++j)
172 memcpy (&x, &tex_mesh.
cloud.
data[idx * point_size + tex_mesh.
cloud.
fields[0].offset],
sizeof(
float));
173 memcpy (&y, &tex_mesh.
cloud.
data[idx * point_size + tex_mesh.
cloud.
fields[1].offset],
sizeof(
float));
174 memcpy (&z, &tex_mesh.
cloud.
data[idx * point_size + tex_mesh.
cloud.
fields[2].offset],
sizeof(
float));
181 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > tex_coordinates = mapTexture2Face (facet[0], facet[1], facet[2]);
182 for (
size_t n = 0; n < tex_coordinates.size (); ++n)
183 texture_map_tmp.push_back (tex_coordinates[n]);
187 std::stringstream tex_name;
188 tex_name <<
"material_" << m;
189 tex_name >> tex_material_.tex_name;
190 tex_material_.tex_file = tex_files_[m];
199 template<
typename Po
intInT>
void 204 int point_size =
static_cast<int> (tex_mesh.
cloud.
data.size ()) / nr_points;
206 float x_lowest = 100000;
208 float y_lowest = 100000;
210 float z_lowest = 100000;
214 for (
int i = 0; i < nr_points; ++i)
216 memcpy (&x_, &tex_mesh.
cloud.
data[i * point_size + tex_mesh.
cloud.
fields[0].offset],
sizeof(
float));
217 memcpy (&y_, &tex_mesh.
cloud.
data[i * point_size + tex_mesh.
cloud.
fields[1].offset],
sizeof(
float));
218 memcpy (&z_, &tex_mesh.
cloud.
data[i * point_size + tex_mesh.
cloud.
fields[2].offset],
sizeof(
float));
237 float x_range = (x_lowest - x_highest) * -1;
238 float x_offset = 0 - x_lowest;
243 float z_range = (z_lowest - z_highest) * -1;
244 float z_offset = 0 - z_lowest;
247 std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > >texture_map;
249 for (
size_t m = 0; m < tex_mesh.
tex_polygons.size (); ++m)
252 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
255 for (
size_t i = 0; i < tex_mesh.
tex_polygons[m].size (); ++i)
258 Eigen::Vector2f tmp_VT;
259 for (
size_t j = 0; j < tex_mesh.
tex_polygons[m][i].vertices.size (); ++j)
262 memcpy (&x_, &tex_mesh.
cloud.
data[idx * point_size + tex_mesh.
cloud.
fields[0].offset],
sizeof(
float));
263 memcpy (&y_, &tex_mesh.
cloud.
data[idx * point_size + tex_mesh.
cloud.
fields[1].offset],
sizeof(
float));
264 memcpy (&z_, &tex_mesh.
cloud.
data[idx * point_size + tex_mesh.
cloud.
fields[2].offset],
sizeof(
float));
267 tmp_VT[0] = (x_ + x_offset) / x_range;
268 tmp_VT[1] = (z_ + z_offset) / z_range;
269 texture_map_tmp.push_back (tmp_VT);
274 std::stringstream tex_name;
275 tex_name <<
"material_" << m;
276 tex_name >> tex_material_.tex_name;
277 tex_material_.tex_file = tex_files_[m];
286 template<
typename Po
intInT>
void 292 PCL_ERROR (
"The mesh should be divided into nbCamera+1 sub-meshes.\n");
293 PCL_ERROR (
"You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.
tex_polygons.size ());
297 PCL_INFO (
"You provided %d cameras and a mesh containing %d sub-meshes.\n", cams.size (), tex_mesh.
tex_polygons.size ());
306 std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > texture_map;
308 for (
size_t m = 0; m < cams.size (); ++m)
311 Camera current_cam = cams[m];
314 Eigen::Affine3f cam_trans = current_cam.
pose;
320 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
325 for (
size_t i = 0; i < tex_mesh.
tex_polygons[m].size (); ++i)
327 Eigen::Vector2f tmp_VT;
329 for (
size_t j = 0; j < tex_mesh.
tex_polygons[m][i].vertices.size (); ++j)
333 pt = camera_transformed_cloud->
points[idx];
336 getPointUVCoordinates (pt, current_cam, tmp_VT);
337 texture_map_tmp.push_back (tmp_VT);
343 std::stringstream tex_name;
344 tex_name <<
"material_" << m;
345 tex_name >> tex_material_.tex_name;
354 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > texture_map_tmp;
355 for (
size_t i = 0; i < tex_mesh.
tex_polygons[cams.size ()].size (); ++i)
356 for (
size_t j = 0; j < tex_mesh.
tex_polygons[cams.size ()][i].vertices.size (); ++j)
358 Eigen::Vector2f tmp_VT;
361 texture_map_tmp.push_back (tmp_VT);
367 std::stringstream tex_name;
368 tex_name <<
"material_" << cams.size ();
369 tex_name >> tex_material_.tex_name;
370 tex_material_.tex_file =
"occluded.jpg";
376 template<
typename Po
intInT>
bool 379 Eigen::Vector3f direction;
380 direction (0) = pt.x;
381 direction (1) = pt.y;
382 direction (2) = pt.z;
384 std::vector<int> indices;
387 cloud = octree->getInputCloud();
389 double distance_threshold = octree->getResolution();
392 octree->getIntersectedVoxelIndices(direction, -direction, indices);
394 int nbocc =
static_cast<int> (indices.size ());
395 for (
size_t j = 0; j < indices.size (); j++)
398 if (pt.z * cloud->points[indices[j]].z < 0)
404 if (fabs (cloud->points[indices[j]].z - pt.z) <= distance_threshold)
418 template<
typename Po
intInT>
void 421 const double octree_voxel_size, std::vector<int> &visible_indices,
422 std::vector<int> &occluded_indices)
425 double maxDeltaZ = octree_voxel_size;
430 octree->setInputCloud (input_cloud);
432 octree->defineBoundingBox ();
434 octree->addPointsFromInputCloud ();
436 visible_indices.clear ();
439 Eigen::Vector3f direction;
440 std::vector<int> indices;
441 for (
size_t i = 0; i < input_cloud->points.size (); ++i)
443 direction (0) = input_cloud->points[i].x;
444 direction (1) = input_cloud->points[i].y;
445 direction (2) = input_cloud->points[i].z;
448 octree->getIntersectedVoxelIndices (direction, -direction, indices);
450 int nbocc =
static_cast<int> (indices.size ());
451 for (
size_t j = 0; j < indices.size (); j++)
454 if (input_cloud->points[i].z * input_cloud->points[indices[j]].z < 0)
460 if (fabs (input_cloud->points[indices[j]].z - input_cloud->points[i].z) <= maxDeltaZ)
470 filtered_cloud->points.push_back (input_cloud->points[i]);
471 visible_indices.push_back (static_cast<int> (i));
475 occluded_indices.push_back (static_cast<int> (i));
482 template<
typename Po
intInT>
void 486 cleaned_mesh = tex_mesh;
494 std::vector<int> visible, occluded;
495 removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
499 for (
size_t polygons = 0; polygons < cleaned_mesh.
tex_polygons.size (); ++polygons)
504 for (
size_t faces = 0; faces < tex_mesh.
tex_polygons[polygons].size (); ++faces)
507 bool faceIsVisible =
true;
508 std::vector<int>::iterator it;
511 for (
size_t points = 0; points < tex_mesh.
tex_polygons[polygons][faces].vertices.size (); ++points)
513 it = find (occluded.begin (), occluded.end (), tex_mesh.
tex_polygons[polygons][faces].vertices[points]);
515 if (it == occluded.end ())
524 faceIsVisible =
false;
538 template<
typename Po
intInT>
void 540 const double octree_voxel_size)
547 std::vector<int> visible, occluded;
548 removeOccludedPoints (cloud, filtered_cloud, octree_voxel_size, visible, occluded);
553 template<
typename Po
intInT>
int 560 PCL_ERROR (
"The mesh must contain only 1 sub-mesh!\n");
564 if (cameras.size () == 0)
566 PCL_ERROR (
"Must provide at least one camera info!\n");
571 sorted_mesh = tex_mesh;
583 for (
size_t cam = 0; cam < cameras.size (); ++cam)
586 Eigen::Affine3f cam_trans = cameras[cam].pose;
592 std::vector<int> visible, occluded;
593 removeOccludedPoints (transformed_cloud, filtered_cloud, octree_voxel_size, visible, occluded);
594 visible_pts = *filtered_cloud;
598 std::vector<pcl::Vertices> visibleFaces_currentCam;
600 for (
size_t faces = 0; faces < tex_mesh.
tex_polygons[0].size (); ++faces)
603 bool faceIsVisible =
true;
604 std::vector<int>::iterator it;
607 for (
size_t current_pt_indice = 0; faceIsVisible && current_pt_indice < tex_mesh.
tex_polygons[0][faces].vertices.size (); ++current_pt_indice)
610 it = find (occluded.begin (), occluded.end (), tex_mesh.
tex_polygons[0][faces].vertices[current_pt_indice]);
612 if (it == occluded.end ())
616 PointInT pt = transformed_cloud->
points[tex_mesh.
tex_polygons[0][faces].vertices[current_pt_indice]];
617 Eigen::Vector2f dummy_UV;
618 if (!getPointUVCoordinates (pt, cameras[cam], dummy_UV))
621 faceIsVisible =
false;
626 faceIsVisible =
false;
633 visibleFaces_currentCam.push_back (tex_mesh.
tex_polygons[0][faces]);
640 sorted_mesh.
tex_polygons.push_back (visibleFaces_currentCam);
650 template<
typename Po
intInT>
void 653 const double octree_voxel_size,
const bool show_nb_occlusions,
654 const int max_occlusions)
657 double maxDeltaZ = octree_voxel_size * 2.0;
670 Eigen::Vector3f direction;
672 std::vector<int> indices;
676 std::vector<double> zDist;
677 std::vector<double> ptDist;
679 for (
size_t i = 0; i < input_cloud->points.size (); ++i)
681 direction (0) = input_cloud->points[i].x;
682 pt.x = input_cloud->points[i].x;
683 direction (1) = input_cloud->points[i].y;
684 pt.y = input_cloud->points[i].y;
685 direction (2) = input_cloud->points[i].z;
686 pt.z = input_cloud->points[i].z;
692 nbocc =
static_cast<int> (indices.size ());
695 for (
size_t j = 0; j < indices.size (); j++)
698 if (pt.z * input_cloud->points[indices[j]].z < 0)
702 else if (fabs (input_cloud->points[indices[j]].z - pt.z) <= maxDeltaZ)
709 zDist.push_back (fabs (input_cloud->points[indices[j]].z - pt.z));
714 if (show_nb_occlusions)
715 (nbocc <= max_occlusions) ? (pt.
intensity = static_cast<float> (nbocc)) : (pt.
intensity = static_cast<float> (max_occlusions));
719 colored_cloud->
points.push_back (pt);
722 if (zDist.size () >= 2)
724 std::sort (zDist.begin (), zDist.end ());
725 std::sort (ptDist.begin (), ptDist.end ());
730 template<
typename Po
intInT>
void 732 double octree_voxel_size,
bool show_nb_occlusions,
int max_occlusions)
738 showOcclusions (cloud, colored_cloud, octree_voxel_size, show_nb_occlusions, max_occlusions);
742 template<
typename Po
intInT>
void 753 std::vector<pcl::Vertices> faces;
755 for (
int current_cam = 0; current_cam < static_cast<int> (cameras.size ()); ++current_cam)
757 PCL_INFO (
"Processing camera %d of %d.\n", current_cam+1, cameras.size ());
765 std::vector<pcl::Vertices>::iterator current_face;
766 std::vector<bool> visibility;
767 visibility.resize (mesh.
tex_polygons[current_cam].size ());
768 std::vector<UvIndex> indexes_uv_to_points;
773 nan_point.
x = std::numeric_limits<float>::quiet_NaN ();
774 nan_point.
y = std::numeric_limits<float>::quiet_NaN ();
780 for (
int idx_face = 0; idx_face < static_cast<int> (mesh.
tex_polygons[current_cam].size ()); ++idx_face)
787 if (isFaceProjected (cameras[current_cam],
788 camera_cloud->points[mesh.
tex_polygons[current_cam][idx_face].vertices[0]],
789 camera_cloud->points[mesh.
tex_polygons[current_cam][idx_face].vertices[1]],
790 camera_cloud->points[mesh.
tex_polygons[current_cam][idx_face].vertices[2]],
798 projections->points.push_back (uv_coord1);
799 projections->points.push_back (uv_coord2);
800 projections->points.push_back (uv_coord3);
808 indexes_uv_to_points.push_back (u1);
809 indexes_uv_to_points.push_back (u2);
810 indexes_uv_to_points.push_back (u3);
813 visibility[idx_face] =
true;
817 projections->points.push_back (nan_point);
818 projections->points.push_back (nan_point);
819 projections->points.push_back (nan_point);
820 indexes_uv_to_points.push_back (u_null);
821 indexes_uv_to_points.push_back (u_null);
822 indexes_uv_to_points.push_back (u_null);
824 visibility[idx_face] =
false;
834 if (visibility.size () - cpt_invisible !=0)
840 std::vector<int> idxNeighbors;
841 std::vector<float> neighborsSquaredDistance;
845 for (
int idx_pcam = 0 ; idx_pcam <= current_cam ; ++idx_pcam)
848 for (
int idx_face = 0; idx_face < static_cast<int> (mesh.
tex_polygons[idx_pcam].size ()); ++idx_face)
851 if (idx_pcam == current_cam && !visibility[idx_face])
864 if (isFaceProjected (cameras[current_cam],
865 camera_cloud->points[mesh.
tex_polygons[idx_pcam][idx_face].vertices[0]],
866 camera_cloud->points[mesh.
tex_polygons[idx_pcam][idx_face].vertices[1]],
867 camera_cloud->points[mesh.
tex_polygons[idx_pcam][idx_face].vertices[2]],
877 getTriangleCircumcscribedCircleCentroid(uv_coord1, uv_coord2, uv_coord3, center, radius);
880 if (kdtree.
radiusSearch (center, radius, idxNeighbors, neighborsSquaredDistance) > 0 )
883 for (
size_t i = 0; i < idxNeighbors.size (); ++i)
885 if (std::max (camera_cloud->points[mesh.
tex_polygons[idx_pcam][idx_face].vertices[0]].z,
886 std::max (camera_cloud->points[mesh.
tex_polygons[idx_pcam][idx_face].vertices[1]].z,
887 camera_cloud->points[mesh.
tex_polygons[idx_pcam][idx_face].vertices[2]].z))
888 < camera_cloud->points[indexes_uv_to_points[idxNeighbors[i]].idx_cloud].z)
891 if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbors[i]]))
894 visibility[indexes_uv_to_points[idxNeighbors[i]].idx_face] =
false;
911 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
916 std::vector<pcl::Vertices> occluded_faces;
917 occluded_faces.resize (visibility.size ());
918 std::vector<pcl::Vertices> visible_faces;
919 visible_faces.resize (visibility.size ());
921 int cpt_occluded_faces = 0;
922 int cpt_visible_faces = 0;
924 for (
size_t idx_face = 0 ; idx_face < visibility.size () ; ++idx_face)
926 if (visibility[idx_face])
929 mesh.
tex_coordinates[current_cam][cpt_visible_faces * 3](0) = projections->points[idx_face*3].x;
930 mesh.
tex_coordinates[current_cam][cpt_visible_faces * 3](1) = projections->points[idx_face*3].y;
932 mesh.
tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](0) = projections->points[idx_face*3 + 1].x;
933 mesh.
tex_coordinates[current_cam][cpt_visible_faces * 3 + 1](1) = projections->points[idx_face*3 + 1].y;
935 mesh.
tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](0) = projections->points[idx_face*3 + 2].x;
936 mesh.
tex_coordinates[current_cam][cpt_visible_faces * 3 + 2](1) = projections->points[idx_face*3 + 2].y;
938 visible_faces[cpt_visible_faces] = mesh.
tex_polygons[current_cam][idx_face];
945 occluded_faces[cpt_occluded_faces] = mesh.
tex_polygons[current_cam][idx_face];
946 cpt_occluded_faces++;
951 occluded_faces.resize (cpt_occluded_faces);
954 visible_faces.resize (cpt_visible_faces);
959 for (
int i = 0; i < static_cast<int> (mesh.
tex_polygons.size ()); i++)
960 nb_faces += static_cast<int> (mesh.
tex_polygons[i].size ());
969 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > dummy_container;
974 for(
size_t idx_face = 0 ; idx_face < mesh.
tex_polygons[cameras.size()].size() ; ++idx_face)
976 Eigen::Vector2f UV1, UV2, UV3;
977 UV1(0) = -1.0; UV1(1) = -1.0;
978 UV2(0) = -1.0; UV2(1) = -1.0;
979 UV3(0) = -1.0; UV3(1) = -1.0;
988 template<
typename Po
intInT>
inline void 993 ptB.
x = p2.
x - p1.
x; ptB.
y = p2.
y - p1.
y;
994 ptC.
x = p3.
x - p1.
x; ptC.
y = p3.
y - p1.
y;
996 double D = 2.0*(ptB.
x*ptC.
y - ptB.
y*ptC.
x);
1001 circomcenter.
x = p1.
x;
1002 circomcenter.
y = p1.
y;
1007 double bx2 = ptB.
x * ptB.
x;
1008 double by2 = ptB.
y * ptB.
y;
1009 double cx2 = ptC.
x * ptC.
x;
1010 double cy2 = ptC.
y * ptC.
y;
1013 circomcenter.
x =
static_cast<float> (p1.
x + (ptC.
y*(bx2 + by2) - ptB.
y*(cx2 + cy2)) / D);
1014 circomcenter.
y =
static_cast<float> (p1.
y + (ptB.
x*(cx2 + cy2) - ptC.
x*(bx2 + by2)) / D);
1017 radius = sqrt( (circomcenter.
x - p1.
x)*(circomcenter.
x - p1.
x) + (circomcenter.
y - p1.
y)*(circomcenter.
y - p1.
y));
1021 template<
typename Po
intInT>
inline void 1025 circumcenter.
x =
static_cast<float> (p1.
x + p2.
x + p3.
x ) / 3;
1026 circumcenter.
y =
static_cast<float> (p1.
y + p2.
y + p3.
y ) / 3;
1027 double r1 = (circumcenter.
x - p1.
x) * (circumcenter.
x - p1.
x) + (circumcenter.
y - p1.
y) * (circumcenter.
y - p1.
y) ;
1028 double r2 = (circumcenter.
x - p2.
x) * (circumcenter.
x - p2.
x) + (circumcenter.
y - p2.
y) * (circumcenter.
y - p2.
y) ;
1029 double r3 = (circumcenter.
x - p3.
x) * (circumcenter.
x - p3.
x) + (circumcenter.
y - p3.
y) * (circumcenter.
y - p3.
y) ;
1032 radius = std::sqrt( std::max( r1, std::max( r2, r3) )) ;
1037 template<
typename Po
intInT>
inline bool 1043 double sizeX = cam.
width;
1044 double sizeY = cam.
height;
1055 double focal_x, focal_y;
1066 UV_coordinates.
x =
static_cast<float> ((focal_x * (pt.x / pt.z) + cx) / sizeX);
1067 UV_coordinates.
y = 1.0f -
static_cast<float> ((focal_y * (pt.y / pt.z) + cy) / sizeY);
1070 if (UV_coordinates.
x >= 0.0 && UV_coordinates.
x <= 1.0 && UV_coordinates.
y >= 0.0 && UV_coordinates.
y <= 1.0)
1075 UV_coordinates.
x = -1.0f;
1076 UV_coordinates.
y = -1.0f;
1081 template<
typename Po
intInT>
inline bool 1085 Eigen::Vector2d v0, v1, v2;
1086 v0(0) = p3.
x - p1.
x; v0(1) = p3.
y - p1.
y;
1087 v1(0) = p2.
x - p1.
x; v1(1) = p2.
y - p1.
y;
1088 v2(0) = pt.
x - p1.
x; v2(1) = pt.
y - p1.
y;
1091 double dot00 = v0.dot(v0);
1092 double dot01 = v0.dot(v1);
1093 double dot02 = v0.dot(v2);
1094 double dot11 = v1.dot(v1);
1095 double dot12 = v1.dot(v2);
1098 double invDenom = 1.0 / (dot00*dot11 - dot01*dot01);
1099 double u = (dot11*dot02 - dot01*dot12) * invDenom;
1100 double v = (dot00*dot12 - dot01*dot02) * invDenom;
1103 return ((u >= 0) && (v >= 0) && (u + v < 1));
1107 template<
typename Po
intInT>
inline bool 1110 return (getPointUVCoordinates(p1, camera, proj1)
1112 getPointUVCoordinates(p2, camera, proj2)
1114 getPointUVCoordinates(p3, camera, proj3)
1118 #define PCL_INSTANTIATE_TextureMapping(T) \ 1119 template class PCL_EXPORTS pcl::TextureMapping<T>; int radiusSearch(const PointT &point, double radius, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
Search for all the nearest neighbors of the query point in a given radius.
void mapMultipleTexturesToMeshUV(pcl::TextureMesh &tex_mesh, pcl::texture_mapping::CameraVector &cams)
Map textures acquired from a set of cameras onto a mesh.
void getTriangleCircumcscribedCircleCentroid(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, pcl::PointXY &circumcenter, double &radius)
Returns the centroid of a triangle and the corresponding circumscribed circle's radius.
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map...
KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures.
std::vector< std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > > > tex_coordinates
void addPointsFromInputCloud()
Add points from input point cloud to octree.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Provide a pointer to the input dataset.
std::vector< Camera, Eigen::aligned_allocator< Camera > > CameraVector
void mapTexture2MeshUV(pcl::TextureMesh &tex_mesh)
Map texture to a mesh UV mapping.
PointCloud::ConstPtr PointCloudConstPtr
std::vector< pcl::TexMaterial > tex_materials
void setInputCloud(const PointCloudConstPtr &cloud_arg, const IndicesConstPtr &indices_arg=IndicesConstPtr())
Provide a pointer to the input data set.
bool getPointUVCoordinates(const PointInT &pt, const Camera &cam, Eigen::Vector2f &UV_coordinates)
computes UV coordinates of point, observed by one particular camera
void textureMeshwithMultipleCameras(pcl::TextureMesh &mesh, const pcl::texture_mapping::CameraVector &cameras)
Segment and texture faces by camera visibility.
void removeOccludedPoints(const PointCloudPtr &input_cloud, PointCloudPtr &filtered_cloud, const double octree_voxel_size, std::vector< int > &visible_indices, std::vector< int > &occluded_indices)
Remove occluded points from a point cloud.
A 2D point structure representing Euclidean xy coordinates.
float euclideanDistance(const PointType1 &p1, const PointType2 &p2)
Calculate the euclidean distance between the two given points.
boost::shared_ptr< PointCloud< PointT > > Ptr
void mapTexture2Mesh(pcl::TextureMesh &tex_mesh)
Map texture to a mesh synthesis algorithm.
void defineBoundingBox()
Investigate dimensions of pointcloud data set and define corresponding bounding box for octree...
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.
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields=true)
Apply an affine transform defined by an Eigen Transform.
bool isPointOccluded(const PointInT &pt, const OctreePtr octree)
Check if a point is occluded using raycasting on octree.
Structure to store camera pose and focal length.
Structure that links a uv coordinate to its 3D point and face.
int getIntersectedVoxelIndices(Eigen::Vector3f origin, Eigen::Vector3f direction, std::vector< int > &k_indices, int max_voxel_count=0) const
Get indices of all voxels that are intersected by a ray (origin, direction).
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > > mapTexture2Face(const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, const Eigen::Vector3f &p3)
Map texture to a face.
std::vector< ::pcl::PCLPointField > fields
Octree pointcloud search class
pcl::PCLPointCloud2 cloud
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.
PointCloud::Ptr PointCloudPtr
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.
int sortFacesByCamera(pcl::TextureMesh &tex_mesh, pcl::TextureMesh &sorted_mesh, const pcl::texture_mapping::CameraVector &cameras, const double octree_voxel_size, PointCloud &visible_pts)
Segment faces by camera visibility.
bool checkPointInsideTriangle(const pcl::PointXY &p1, const pcl::PointXY &p2, const pcl::PointXY &p3, const pcl::PointXY &pt)
Returns True if a point lays within a triangle.
std::vector< pcl::uint8_t > data
std::vector< std::vector< pcl::Vertices > > tex_polygons