@@ -115,23 +115,22 @@ pcl::PLYReader::appendScalarProperty (const std::string& name, const std::size_t
115
115
cloud_->point_step += static_cast <std::uint32_t > (pcl::getFieldSize (pcl::traits::asEnum<Scalar>::value) * size);
116
116
}
117
117
118
- void
118
+ bool
119
119
pcl::PLYReader::amendProperty (const std::string& old_name, const std::string& new_name, std::uint8_t new_datatype)
120
120
{
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 ;
131
124
}
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 ;
135
134
}
136
135
137
136
namespace pcl
@@ -213,7 +212,15 @@ namespace pcl
213
212
}
214
213
if (property_name == " alpha" )
215
214
{
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
+
217
224
return [this ] (pcl::io::ply::uint8 alpha) { vertexAlphaCallback (alpha); };
218
225
}
219
226
if (property_name == " intensity" )
0 commit comments