Fixed a bug where camera facing polygons were not textured

This commit is contained in:
matlabbe
2017-03-03 15:22:20 -05:00
parent fd55828c42
commit 3cf8ea63d8
5 changed files with 19 additions and 17 deletions

View File

@@ -1103,17 +1103,16 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras2 (
{
// check if the polygon is facing the camera, assuming counterclockwise normal
Eigen::Vector3f v0(
pt1.x - pt0.x,
pt1.y - pt0.y,
pt1.z - pt0.z);
uv_coords2.x - uv_coords1.x,
uv_coords2.y - uv_coords1.y,
0);
Eigen::Vector3f v1(
pt2.x - pt0.x,
pt2.y - pt0.y,
pt2.z - pt0.z);
uv_coords3.x - uv_coords1.x,
uv_coords3.y - uv_coords1.y,
0);
Eigen::Vector3f normal = v0.cross(v1);
float angle = normal.dot(Eigen::Vector3f(0.0f,0.0f,-1.0f));
float angle = normal.dot(Eigen::Vector3f(0.0f,0.0f,1.0f));
bool facingTheCam = angle>0.0f;
float distanceToCam = std::min(std::min(pt0.z, pt1.z), pt2.z);
pcl::PointXY center;
center.x = (uv_coords1.x+uv_coords2.x+uv_coords3.x)/3.0f;
@@ -1254,12 +1253,13 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras2 (
UWARN("Texturing cancelled!");
return false;
}
int textured = 0;
for(unsigned int idx_face=0; idx_face<faces.size(); ++idx_face)
{
if((idx_face+1)%10000 == 0)
{
UDEBUG("face %d/%d", idx_face+1, (int)faces.size());
if(state && !state->callback(uFormat("Textured %d/%d polygons", (int)idx_face+1, (int)faces.size())))
if(state && !state->callback(uFormat("Textured %d/%d of %d polygons", textured, idx_face+1, (int)faces.size())))
{
//cancelled!
UWARN("Texturing cancelled!");
@@ -1293,6 +1293,7 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras2 (
if(cameraIndex >= 0)
{
++textured;
mesh.tex_polygons[cameraIndex].push_back(face);
mesh.tex_coordinates[cameraIndex].push_back(Eigen::Vector2f(uv_coords[0].x, uv_coords[0].y));
mesh.tex_coordinates[cameraIndex].push_back(Eigen::Vector2f(uv_coords[1].x, uv_coords[1].y));
@@ -1306,7 +1307,7 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras2 (
mesh.tex_coordinates[cameras.size()].push_back(Eigen::Vector2f(-1.0,-1.0));
}
}
UINFO("Process %d polygons...done!", (int)faces.size());
UINFO("Process %d polygons...done! (%d textured)", (int)faces.size(), textured);
return true;
}

View File

@@ -63,7 +63,7 @@ protected:
public slots:
void appendText(const QString & text ,const QColor & color = Qt::black);
void incrementStep();
void incrementStep(int steps = 1);
void clear();
void resetProgress();

View File

@@ -889,7 +889,6 @@ bool ExportCloudsDialog::getExportedClouds(
{
mul+=1;
}
mul+=1; // normals
if(_ui->checkBox_textureMapping->isChecked())
{
mul+=1;
@@ -1720,7 +1719,7 @@ bool ExportCloudsDialog::getExportedClouds(
meshes.insert(std::make_pair(iter->first, mesh));
_progressDialog->incrementStep();
_progressDialog->incrementStep(_ui->checkBox_assemble->isChecked()?poses.size():1);
QApplication::processEvents();
if(_canceled)
{
@@ -1877,6 +1876,7 @@ bool ExportCloudsDialog::getExportedClouds(
}
TexturingState texturingState(_progressDialog);
_progressDialog->setMaximumSteps(_progressDialog->maximumSteps()+iter->second->polygons.size()/10000+1);
textureMesh = util3d::createTextureMesh(
iter->second,
cameraPoses,

View File

@@ -133,14 +133,14 @@ void ProgressDialog::setMaximumSteps(int steps)
_progressBar->setMaximum(steps);
}
void ProgressDialog::incrementStep()
void ProgressDialog::incrementStep(int steps)
{
//incremental progress bar (if we don't know how many items will be added)
if(_progressBar->value() == _progressBar->maximum()-1)
if(_progressBar->value() >= _progressBar->maximum()-steps)
{
_progressBar->setMaximum(_progressBar->maximum()+1);
_progressBar->setMaximum(_progressBar->maximum()+steps+1);
}
_progressBar->setValue(_progressBar->value()+1);
_progressBar->setValue(_progressBar->value()+steps);
}
void ProgressDialog::clear()

View File

@@ -50,6 +50,7 @@ public:
if(!msg.empty())
{
dialog_->appendText(msg.c_str());
dialog_->incrementStep();
}
QApplication::processEvents();
return !canceled_;