PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.64k stars 4.59k forks source link

[field match]How to get whether a field is valid? #6041

Closed QiuYilin closed 1 month ago

QiuYilin commented 1 month ago

If I load a cloudxyz file as cloudxyzi, I want to explicitly warn at the software level.

I found that PCL will print this warning in the terminal but has removed this exception,and I didn't find a function to simply judge fields in pcl::io.

      FieldMapper (const std::vector<pcl::PCLPointField>& fields,
                   std::vector<FieldMapping>& map)
        : fields_ (fields), map_ (map)
      {
      }

      template<typename Tag> void
      operator () ()
      {
        for (const auto& field : fields_)
        {
          if (FieldMatches<PointT, Tag>()(field))
          {
            FieldMapping mapping;
            mapping.serialized_offset = field.offset;
            mapping.struct_offset = pcl::traits::offset<PointT, Tag>::value;
            mapping.size = sizeof (typename pcl::traits::datatype<PointT, Tag>::type);
            map_.push_back (mapping);
            return;
          }
        }
        // Disable thrown exception per #595: http://dev.pointclouds.org/issues/595
        PCL_WARN ("Failed to find match for field '%s'.\n", pcl::traits::name<PointT, Tag>::value);
        //throw pcl::InvalidConversionException (ss.str ());
      }

Is there any easy way to check the field, or redirect the content of pcl::console?

mvieth commented 1 month ago

One way could be to load the file as a pcl::PCLPointCloud2 instead, check its fields attribute, then convert to pcl::PointCloud<pcl::PointXYZ>. See: https://github.com/PointCloudLibrary/pcl/blob/master/io/include/pcl/io/pcd_io.h#L279 https://pointclouds.org/documentation/structpcl_1_1_p_c_l_point_cloud2.html

QiuYilin commented 1 month ago

I think that the memory structures of PointCloud2 and PointXYZ are different, and the conversion will cause unnecessary time consumption. It may be better to provide an additional tool function.

mvieth commented 1 month ago

The conversion happens anyway. If you load the file into a pcl::PointCloud<pcl::PointXYZ, the conversion just happens internally in PCDReader (see the first link I provided). What I described does not cause any additional time consumption, it only gives you access to the intermediate pcl::PCLPointCloud2.

QiuYilin commented 1 month ago

get