Skip to content

Commit

Permalink
Texturing: ignore polygons not facing the camera
Browse files Browse the repository at this point in the history
  • Loading branch information
matlabbe committed Feb 1, 2017
1 parent bfb9fea commit a1ceff8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
22 changes: 17 additions & 5 deletions corelib/src/pcl18/surface/impl/texture_mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,23 @@ pcl::TextureMapping<PointInT>::checkPointInsideTriangle(const pcl::PointXY &p1,
template<typename PointInT> inline bool
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)
{
return (getPointUVCoordinates(p1, camera, proj1)
&&
getPointUVCoordinates(p2, camera, proj2)
&&
getPointUVCoordinates(p3, camera, proj3)
// check if the polygon is facing the camera, assuming counterclockwise normal
Eigen::Vector3f v0(
p2.x - p1.x,
p2.y - p1.y,
p2.z - p1.z);
Eigen::Vector3f v1(
p3.x - p1.x,
p3.y - p1.y,
p3.z - p1.z);
Eigen::Vector3f normal = v0.cross(v1);

return normal.dot(Eigen::Vector3f(0.0f,0.0f,-1.0f)) > 0.0f && // toward the camera
(getPointUVCoordinates(p1, camera, proj1)
&&
getPointUVCoordinates(p2, camera, proj2)
&&
getPointUVCoordinates(p3, camera, proj3)
);
}

Expand Down
48 changes: 28 additions & 20 deletions guilib/src/ExportCloudsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,33 +668,39 @@ void ExportCloudsDialog::viewClouds(
// be duplicated.
for (unsigned int t = 0; t < mesh->tex_coordinates.size(); ++t)
{
UASSERT(mesh->tex_polygons[t].size());

pcl::PointCloud<pcl::PointXYZ>::Ptr originalCloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(mesh->cloud, *originalCloud);
if(mesh->tex_polygons[t].size())
{

// make a cloud with as many points than polygon vertices
unsigned int nPoints = mesh->tex_coordinates[t].size();
UASSERT(nPoints == mesh->tex_polygons[t].size()*mesh->tex_polygons[t][0].vertices.size()); // assuming polygon size is constant!
pcl::PointCloud<pcl::PointXYZ>::Ptr originalCloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(mesh->cloud, *originalCloud);

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->resize(nPoints);
// make a cloud with as many points than polygon vertices
unsigned int nPoints = mesh->tex_coordinates[t].size();
UASSERT(nPoints == mesh->tex_polygons[t].size()*mesh->tex_polygons[t][0].vertices.size()); // assuming polygon size is constant!

unsigned int oi = 0;
for (unsigned int i = 0; i < mesh->tex_polygons[t].size(); ++i)
{
pcl::Vertices & vertices = mesh->tex_polygons[t][i];
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->resize(nPoints);

for(unsigned int j=0; j<vertices.vertices.size(); ++j)
unsigned int oi = 0;
for (unsigned int i = 0; i < mesh->tex_polygons[t].size(); ++i)
{
UASSERT(oi < cloud->size());
UASSERT(vertices.vertices[j] < originalCloud->size());
cloud->at(oi) = originalCloud->at(vertices.vertices[j]);
vertices.vertices[j] = oi; // new vertice index
++oi;
pcl::Vertices & vertices = mesh->tex_polygons[t][i];

for(unsigned int j=0; j<vertices.vertices.size(); ++j)
{
UASSERT(oi < cloud->size());
UASSERT(vertices.vertices[j] < originalCloud->size());
cloud->at(oi) = originalCloud->at(vertices.vertices[j]);
vertices.vertices[j] = oi; // new vertice index
++oi;
}
}
pcl::toPCLPointCloud2(*cloud, mesh->cloud);
}
else
{
UWARN("No polygons for texture %d of mesh %d?!", t, iter->first);
}
pcl::toPCLPointCloud2(*cloud, mesh->cloud);
}

if (globalTexture.empty())
Expand Down Expand Up @@ -898,6 +904,7 @@ bool ExportCloudsDialog::getExportedClouds(
_progressDialog->appendText(tr("Gain compensation of %1 clouds...").arg(clouds.size()));
}
QApplication::processEvents();
uSleep(100);
QApplication::processEvents();

if(!_ui->checkBox_gainLinkedLocationsOnly->isChecked())
Expand Down Expand Up @@ -1011,6 +1018,7 @@ bool ExportCloudsDialog::getExportedClouds(
_progressDialog->appendText(tr("Smoothing the surface using Moving Least Squares (MLS) algorithm... "
"[search radius=%1m voxel=%2m]").arg(_ui->doubleSpinBox_mlsRadius->value()).arg(_ui->doubleSpinBox_voxelSize_assembled->value()));
QApplication::processEvents();
uSleep(100);
QApplication::processEvents();

// Adjust view points with local transforms
Expand Down

0 comments on commit a1ceff8

Please sign in to comment.