Find out whether a cloud is colored or not

classic Classic list List threaded Threaded
7 messages Options
yli
Reply | Threaded
Open this post in threaded view
|

Find out whether a cloud is colored or not

yli
Hi everyone,

Given a .pcd file, I'm trying to figure out whether the cloud is
colored or not, i.e., whether there's a RGB field in its header.

Here's what I'm currently doing:

bool isColored(std::string &fileName)
{
    sensor_msgs::PointCloud2 cloud2;
    pcl::PCDReader reader;
    reader.read(fileName, cloud2);
    std::vector< sensor_msgs::PointField > fs = cloud2.fields;
    for(int i = 0; i < fs.size(); ++i)
    {
        if (fs[i].name == "rgb")
            return true;
    }
    return false;
}

I don't like the current way as it needs to read the whole cloud in
using the read function. I'm wondering is there a better way for doing
this? Or is there a function which just reads the header? Thanks!

Best,

Yue
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Find out whether a cloud is colored or not

Radu B Rusu
Administrator
Yue,

I hope this helps: http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_d_reader.html#a71c1f9ad47af414734b4f3bef90aa271

Cheers,
Radu.

On 06/11/2012 04:41 PM, Yue Li wrote:

> Hi everyone,
>
> Given a .pcd file, I'm trying to figure out whether the cloud is
> colored or not, i.e., whether there's a RGB field in its header.
>
> Here's what I'm currently doing:
>
> bool isColored(std::string&fileName)
> {
>      sensor_msgs::PointCloud2 cloud2;
>      pcl::PCDReader reader;
>      reader.read(fileName, cloud2);
>      std::vector<  sensor_msgs::PointField>  fs = cloud2.fields;
>      for(int i = 0; i<  fs.size(); ++i)
>      {
>          if (fs[i].name == "rgb")
>              return true;
>      }
>      return false;
> }
>
> I don't like the current way as it needs to read the whole cloud in
> using the read function. I'm wondering is there a better way for doing
> this? Or is there a function which just reads the header? Thanks!
>
> Best,
>
> Yue
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Find out whether a cloud is colored or not

Adam Stambler
In reply to this post by yli
pcl::PCDReader has a read header function http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_d_reader.html#a71c1f9ad47af414734b4f3bef90aa271

You can use to just read the header.

Cheers,
Adam

On Mon, Jun 11, 2012 at 7:41 PM, Yue Li <[hidden email]> wrote:
Hi everyone,

Given a .pcd file, I'm trying to figure out whether the cloud is
colored or not, i.e., whether there's a RGB field in its header.

Here's what I'm currently doing:

bool isColored(std::string &fileName)
{
   sensor_msgs::PointCloud2 cloud2;
   pcl::PCDReader reader;
   reader.read(fileName, cloud2);
   std::vector< sensor_msgs::PointField > fs = cloud2.fields;
   for(int i = 0; i < fs.size(); ++i)
   {
       if (fs[i].name == "rgb")
           return true;
   }
   return false;
}

I don't like the current way as it needs to read the whole cloud in
using the read function. I'm wondering is there a better way for doing
this? Or is there a function which just reads the header? Thanks!

Best,

Yue
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
yli
Reply | Threaded
Open this post in threaded view
|

Re: Find out whether a cloud is colored or not

yli
In reply to this post by Radu B Rusu
On Mon, Jun 11, 2012 at 6:42 PM, Radu B. Rusu <[hidden email]> wrote:
> Yue,
>
> I hope this helps:
> http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_d_reader.html#a71c1f9ad47af414734b4f3bef90aa271
>

Thanks a lot! This function works for me.

    In my case, I only need to use the cloud computed by the
readHeader function to obtain the fields. However, I still have to
declare and pass the variables for pcd_version, data_type, data_idx
and others. Would you think it is better to have another readHeader
function which has the same signature as the read function does?

Best,

Yue

> Cheers,
> Radu.
>
>
> On 06/11/2012 04:41 PM, Yue Li wrote:
>>
>> Hi everyone,
>>
>> Given a .pcd file, I'm trying to figure out whether the cloud is
>> colored or not, i.e., whether there's a RGB field in its header.
>>
>> Here's what I'm currently doing:
>>
>> bool isColored(std::string&fileName)
>> {
>>     sensor_msgs::PointCloud2 cloud2;
>>     pcl::PCDReader reader;
>>     reader.read(fileName, cloud2);
>>     std::vector<  sensor_msgs::PointField>  fs = cloud2.fields;
>>     for(int i = 0; i<  fs.size(); ++i)
>>     {
>>         if (fs[i].name == "rgb")
>>             return true;
>>     }
>>     return false;
>> }
>>
>> I don't like the current way as it needs to read the whole cloud in
>> using the read function. I'm wondering is there a better way for doing
>> this? Or is there a function which just reads the header? Thanks!
>>
>> Best,
>>
>> Yue
>> _______________________________________________
>> [hidden email] / http://pointclouds.org
>> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Find out whether a cloud is colored or not

Radu B Rusu
Administrator
Yue,

This makes sense. Can you prepare a simple patch against trunk? We can include it in 1.6.

Cheers,
Radu.

On 06/11/2012 05:04 PM, Yue Li wrote:

> On Mon, Jun 11, 2012 at 6:42 PM, Radu B. Rusu<[hidden email]>  wrote:
>> Yue,
>>
>> I hope this helps:
>> http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_d_reader.html#a71c1f9ad47af414734b4f3bef90aa271
>>
>
> Thanks a lot! This function works for me.
>
>      In my case, I only need to use the cloud computed by the
> readHeader function to obtain the fields. However, I still have to
> declare and pass the variables for pcd_version, data_type, data_idx
> and others. Would you think it is better to have another readHeader
> function which has the same signature as the read function does?
>
> Best,
>
> Yue
>
>> Cheers,
>> Radu.
>>
>>
>> On 06/11/2012 04:41 PM, Yue Li wrote:
>>>
>>> Hi everyone,
>>>
>>> Given a .pcd file, I'm trying to figure out whether the cloud is
>>> colored or not, i.e., whether there's a RGB field in its header.
>>>
>>> Here's what I'm currently doing:
>>>
>>> bool isColored(std::string&fileName)
>>> {
>>>      sensor_msgs::PointCloud2 cloud2;
>>>      pcl::PCDReader reader;
>>>      reader.read(fileName, cloud2);
>>>      std::vector<    sensor_msgs::PointField>    fs = cloud2.fields;
>>>      for(int i = 0; i<    fs.size(); ++i)
>>>      {
>>>          if (fs[i].name == "rgb")
>>>              return true;
>>>      }
>>>      return false;
>>> }
>>>
>>> I don't like the current way as it needs to read the whole cloud in
>>> using the read function. I'm wondering is there a better way for doing
>>> this? Or is there a function which just reads the header? Thanks!
>>>
>>> Best,
>>>
>>> Yue
>>> _______________________________________________
>>> [hidden email] / http://pointclouds.org
>>> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
yli
Reply | Threaded
Open this post in threaded view
|

Re: Find out whether a cloud is colored or not

yli
Dear Radu,

Attached is the patch created against r5904. This patch adds another
readHeader function which has the same signature as the read function
does. The implementation is modified from the original implementation
of readHeader function which requires several input parameters. Tested
on my local MacOS desktop. Thanks!

Best,

Yue

On Mon, Jun 11, 2012 at 7:05 PM, Radu B. Rusu <[hidden email]> wrote:

> Yue,
>
> This makes sense. Can you prepare a simple patch against trunk? We can
> include it in 1.6.
>
> Cheers,
> Radu.
>
>
> On 06/11/2012 05:04 PM, Yue Li wrote:
>>
>> On Mon, Jun 11, 2012 at 6:42 PM, Radu B. Rusu<[hidden email]>
>>  wrote:
>>>
>>> Yue,
>>>
>>> I hope this helps:
>>>
>>> http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_d_reader.html#a71c1f9ad47af414734b4f3bef90aa271
>>>
>>
>> Thanks a lot! This function works for me.
>>
>>     In my case, I only need to use the cloud computed by the
>> readHeader function to obtain the fields. However, I still have to
>> declare and pass the variables for pcd_version, data_type, data_idx
>> and others. Would you think it is better to have another readHeader
>> function which has the same signature as the read function does?
>>
>> Best,
>>
>> Yue
>>
>>> Cheers,
>>> Radu.
>>>
>>>
>>> On 06/11/2012 04:41 PM, Yue Li wrote:
>>>>
>>>>
>>>> Hi everyone,
>>>>
>>>> Given a .pcd file, I'm trying to figure out whether the cloud is
>>>> colored or not, i.e., whether there's a RGB field in its header.
>>>>
>>>> Here's what I'm currently doing:
>>>>
>>>> bool isColored(std::string&fileName)
>>>> {
>>>>     sensor_msgs::PointCloud2 cloud2;
>>>>     pcl::PCDReader reader;
>>>>     reader.read(fileName, cloud2);
>>>>     std::vector<    sensor_msgs::PointField>    fs = cloud2.fields;
>>>>     for(int i = 0; i<    fs.size(); ++i)
>>>>     {
>>>>         if (fs[i].name == "rgb")
>>>>             return true;
>>>>     }
>>>>     return false;
>>>> }
>>>>
>>>> I don't like the current way as it needs to read the whole cloud in
>>>> using the read function. I'm wondering is there a better way for doing
>>>> this? Or is there a function which just reads the header? Thanks!
>>>>
>>>> Best,
>>>>
>>>> Yue
>>>> _______________________________________________
>>>> [hidden email] / http://pointclouds.org
>>>> http://pointclouds.org/mailman/listinfo/pcl-users

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

add_another_readHeader.patch (15K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Find out whether a cloud is colored or not

Radu B Rusu
Administrator
Thanks Yue! Pushed in r5905.

Cheers,
Radu.

On 06/12/2012 04:15 PM, Yue Li wrote:

> Dear Radu,
>
> Attached is the patch created against r5904. This patch adds another
> readHeader function which has the same signature as the read function
> does. The implementation is modified from the original implementation
> of readHeader function which requires several input parameters. Tested
> on my local MacOS desktop. Thanks!
>
> Best,
>
> Yue
>
> On Mon, Jun 11, 2012 at 7:05 PM, Radu B. Rusu<[hidden email]>  wrote:
>> Yue,
>>
>> This makes sense. Can you prepare a simple patch against trunk? We can
>> include it in 1.6.
>>
>> Cheers,
>> Radu.
>>
>>
>> On 06/11/2012 05:04 PM, Yue Li wrote:
>>>
>>> On Mon, Jun 11, 2012 at 6:42 PM, Radu B. Rusu<[hidden email]>
>>>   wrote:
>>>>
>>>> Yue,
>>>>
>>>> I hope this helps:
>>>>
>>>> http://docs.pointclouds.org/trunk/classpcl_1_1_p_c_d_reader.html#a71c1f9ad47af414734b4f3bef90aa271
>>>>
>>>
>>> Thanks a lot! This function works for me.
>>>
>>>      In my case, I only need to use the cloud computed by the
>>> readHeader function to obtain the fields. However, I still have to
>>> declare and pass the variables for pcd_version, data_type, data_idx
>>> and others. Would you think it is better to have another readHeader
>>> function which has the same signature as the read function does?
>>>
>>> Best,
>>>
>>> Yue
>>>
>>>> Cheers,
>>>> Radu.
>>>>
>>>>
>>>> On 06/11/2012 04:41 PM, Yue Li wrote:
>>>>>
>>>>>
>>>>> Hi everyone,
>>>>>
>>>>> Given a .pcd file, I'm trying to figure out whether the cloud is
>>>>> colored or not, i.e., whether there's a RGB field in its header.
>>>>>
>>>>> Here's what I'm currently doing:
>>>>>
>>>>> bool isColored(std::string&fileName)
>>>>> {
>>>>>      sensor_msgs::PointCloud2 cloud2;
>>>>>      pcl::PCDReader reader;
>>>>>      reader.read(fileName, cloud2);
>>>>>      std::vector<      sensor_msgs::PointField>      fs = cloud2.fields;
>>>>>      for(int i = 0; i<      fs.size(); ++i)
>>>>>      {
>>>>>          if (fs[i].name == "rgb")
>>>>>              return true;
>>>>>      }
>>>>>      return false;
>>>>> }
>>>>>
>>>>> I don't like the current way as it needs to read the whole cloud in
>>>>> using the read function. I'm wondering is there a better way for doing
>>>>> this? Or is there a function which just reads the header? Thanks!
>>>>>
>>>>> Best,
>>>>>
>>>>> Yue
>>>>> _______________________________________________
>>>>> [hidden email] / http://pointclouds.org
>>>>> http://pointclouds.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users