Skip to content

Commit 57753ff

Browse files
authored
Return empty handler if rgb doesn't exist when trying to add alpha value (#5415)
* So error and return empty callback, as the ply header is illdefined (for pcl at least). * Return bool with true as succes for amendProperty.
1 parent 6c5b489 commit 57753ff

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

io/include/pcl/io/ply_io.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,13 @@ namespace pcl
448448

449449
/** Amend property from cloud fields identified by \a old_name renaming
450450
* it \a new_name.
451+
* * Returns:
452+
* * false on error
453+
* * true success
451454
* param[in] old_name property old name
452455
* param[in] new_name property new name
453456
*/
454-
void
457+
bool
455458
amendProperty (const std::string& old_name, const std::string& new_name, std::uint8_t datatype = 0);
456459

457460
/** Callback function for the begin of vertex line */

io/src/ply_io.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,22 @@ pcl::PLYReader::appendScalarProperty (const std::string& name, const std::size_t
115115
cloud_->point_step += static_cast<std::uint32_t> (pcl::getFieldSize (pcl::traits::asEnum<Scalar>::value) * size);
116116
}
117117

118-
void
118+
bool
119119
pcl::PLYReader::amendProperty (const std::string& old_name, const std::string& new_name, std::uint8_t new_datatype)
120120
{
121-
auto finder = cloud_->fields.rbegin ();
122-
for (; finder != cloud_->fields.rend (); ++finder)
123-
if (finder->name == old_name)
124-
break;
125-
if (finder == cloud_->fields.rend ())
126-
{
127-
PCL_ERROR("[pcl::PLYReader::amendProperty] old_name '%s' was not found in cloud_->fields!\n",
128-
old_name.c_str());
129-
assert (false);
130-
return;
121+
const auto fieldIndex = pcl::getFieldIndex(*cloud_, old_name);
122+
if (fieldIndex == -1) {
123+
return false;
131124
}
132-
finder->name = new_name;
133-
if (new_datatype > 0 && new_datatype != finder->datatype)
134-
finder->datatype = new_datatype;
125+
126+
auto& field = cloud_->fields[fieldIndex];
127+
128+
field.name = new_name;
129+
130+
if (new_datatype > 0 && new_datatype != field.datatype)
131+
field.datatype = new_datatype;
132+
133+
return true;
135134
}
136135

137136
namespace pcl
@@ -213,7 +212,15 @@ namespace pcl
213212
}
214213
if (property_name == "alpha")
215214
{
216-
amendProperty ("rgb", "rgba", pcl::PCLPointField::UINT32);
215+
if (!amendProperty("rgb", "rgba", pcl::PCLPointField::UINT32))
216+
{
217+
PCL_ERROR("[pcl::PLYReader::scalarPropertyDefinitionCallback] 'rgb' was not "
218+
"found in cloud_->fields!,"
219+
" can't amend property '%s' to get new type 'rgba' \n",
220+
property_name.c_str());
221+
return {};
222+
}
223+
217224
return [this] (pcl::io::ply::uint8 alpha) { vertexAlphaCallback (alpha); };
218225
}
219226
if (property_name == "intensity")

0 commit comments

Comments
 (0)