PCL apply filter on octree without cloud copy










0














I have huge point cloud, and I want to apply voxelGrid on it. But since the point cloud is too big, I have error such as "[pcl::VoxelGrid::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow". So I wanted to build an octree first from my pointcloud, and then apply the filter on each leaf (i.e apply the filter on the pointcloud with the good index)

The problem occurs here, when I apply the filter, PCL wants me to chose a PointCloud in which it will be saved, and the original point cloud is substituted with the result of the filter. I would like to know if it is possible to modify the filter so that it doesn't remove the points, but only put to (0,0,0) the points at the index in the pointcloud that must be removed?



My code :



void Octree::applyExample(float x, float y, float z) 
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

// Fill in the cloud data
cloud->width = 100000;
cloud->height = 1;
cloud->is_dense = false;
cloud->points.resize(cloud->width * cloud->height);

for (size_t i = 0; i < cloud->points.size(); ++i)

cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);

octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it;
pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it_end = octree.leaf_end();
for (it = octree.leaf_begin(); it != it_end; ++it)


pcl::IndicesPtr indexVector(new vector<int>);
pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

container.getPointIndices(*indexVector);
FILTREexample(cloud, indexVector, x, y, z);




and filter :



void FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(pointcloud);
sor.setIndices(indices);
sor.setLeafSize(x, y, z);
sor.filter(*pointcloud); //The problem occurs here
//Everytime, the pointcloud is substituted with the result of the filter, but I'd like to still have my "entire" pointcloud, but either with the filtered point deleted, or the filtered point put to 0,0,0.




Would it be possible to do such a thing?










share|improve this question


























    0














    I have huge point cloud, and I want to apply voxelGrid on it. But since the point cloud is too big, I have error such as "[pcl::VoxelGrid::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow". So I wanted to build an octree first from my pointcloud, and then apply the filter on each leaf (i.e apply the filter on the pointcloud with the good index)

    The problem occurs here, when I apply the filter, PCL wants me to chose a PointCloud in which it will be saved, and the original point cloud is substituted with the result of the filter. I would like to know if it is possible to modify the filter so that it doesn't remove the points, but only put to (0,0,0) the points at the index in the pointcloud that must be removed?



    My code :



    void Octree::applyExample(float x, float y, float z) 
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

    // Fill in the cloud data
    cloud->width = 100000;
    cloud->height = 1;
    cloud->is_dense = false;
    cloud->points.resize(cloud->width * cloud->height);

    for (size_t i = 0; i < cloud->points.size(); ++i)

    cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
    cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
    cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);

    octree.setInputCloud(cloud);
    octree.addPointsFromInputCloud();
    pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it;
    pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it_end = octree.leaf_end();
    for (it = octree.leaf_begin(); it != it_end; ++it)


    pcl::IndicesPtr indexVector(new vector<int>);
    pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

    container.getPointIndices(*indexVector);
    FILTREexample(cloud, indexVector, x, y, z);




    and filter :



    void FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
    pcl::VoxelGrid<pcl::PointXYZ> sor;
    sor.setInputCloud(pointcloud);
    sor.setIndices(indices);
    sor.setLeafSize(x, y, z);
    sor.filter(*pointcloud); //The problem occurs here
    //Everytime, the pointcloud is substituted with the result of the filter, but I'd like to still have my "entire" pointcloud, but either with the filtered point deleted, or the filtered point put to 0,0,0.




    Would it be possible to do such a thing?










    share|improve this question
























      0












      0








      0







      I have huge point cloud, and I want to apply voxelGrid on it. But since the point cloud is too big, I have error such as "[pcl::VoxelGrid::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow". So I wanted to build an octree first from my pointcloud, and then apply the filter on each leaf (i.e apply the filter on the pointcloud with the good index)

      The problem occurs here, when I apply the filter, PCL wants me to chose a PointCloud in which it will be saved, and the original point cloud is substituted with the result of the filter. I would like to know if it is possible to modify the filter so that it doesn't remove the points, but only put to (0,0,0) the points at the index in the pointcloud that must be removed?



      My code :



      void Octree::applyExample(float x, float y, float z) 
      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

      // Fill in the cloud data
      cloud->width = 100000;
      cloud->height = 1;
      cloud->is_dense = false;
      cloud->points.resize(cloud->width * cloud->height);

      for (size_t i = 0; i < cloud->points.size(); ++i)

      cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
      cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
      cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);

      octree.setInputCloud(cloud);
      octree.addPointsFromInputCloud();
      pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it;
      pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it_end = octree.leaf_end();
      for (it = octree.leaf_begin(); it != it_end; ++it)


      pcl::IndicesPtr indexVector(new vector<int>);
      pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

      container.getPointIndices(*indexVector);
      FILTREexample(cloud, indexVector, x, y, z);




      and filter :



      void FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
      pcl::VoxelGrid<pcl::PointXYZ> sor;
      sor.setInputCloud(pointcloud);
      sor.setIndices(indices);
      sor.setLeafSize(x, y, z);
      sor.filter(*pointcloud); //The problem occurs here
      //Everytime, the pointcloud is substituted with the result of the filter, but I'd like to still have my "entire" pointcloud, but either with the filtered point deleted, or the filtered point put to 0,0,0.




      Would it be possible to do such a thing?










      share|improve this question













      I have huge point cloud, and I want to apply voxelGrid on it. But since the point cloud is too big, I have error such as "[pcl::VoxelGrid::applyFilter] Leaf size is too small for the input dataset. Integer indices would overflow". So I wanted to build an octree first from my pointcloud, and then apply the filter on each leaf (i.e apply the filter on the pointcloud with the good index)

      The problem occurs here, when I apply the filter, PCL wants me to chose a PointCloud in which it will be saved, and the original point cloud is substituted with the result of the filter. I would like to know if it is possible to modify the filter so that it doesn't remove the points, but only put to (0,0,0) the points at the index in the pointcloud that must be removed?



      My code :



      void Octree::applyExample(float x, float y, float z) 
      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

      // Fill in the cloud data
      cloud->width = 100000;
      cloud->height = 1;
      cloud->is_dense = false;
      cloud->points.resize(cloud->width * cloud->height);

      for (size_t i = 0; i < cloud->points.size(); ++i)

      cloud->points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
      cloud->points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
      cloud->points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);

      octree.setInputCloud(cloud);
      octree.addPointsFromInputCloud();
      pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it;
      pcl::octree::OctreePointCloud<pcl::PointXYZRGB>::LeafNodeIterator it_end = octree.leaf_end();
      for (it = octree.leaf_begin(); it != it_end; ++it)


      pcl::IndicesPtr indexVector(new vector<int>);
      pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

      container.getPointIndices(*indexVector);
      FILTREexample(cloud, indexVector, x, y, z);




      and filter :



      void FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
      pcl::VoxelGrid<pcl::PointXYZ> sor;
      sor.setInputCloud(pointcloud);
      sor.setIndices(indices);
      sor.setLeafSize(x, y, z);
      sor.filter(*pointcloud); //The problem occurs here
      //Everytime, the pointcloud is substituted with the result of the filter, but I'd like to still have my "entire" pointcloud, but either with the filtered point deleted, or the filtered point put to 0,0,0.




      Would it be possible to do such a thing?







      c++ point-cloud-library






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 16:02









      Raph Schim

      19115




      19115






















          2 Answers
          2






          active

          oldest

          votes


















          1














          To my knowledge, there is no "pcl" way of doing this. You should do some coding yourself to get the results you expect. One alternative that comes to mind is : You can add the resultant (filtered) point cloud from the voxel filter into the input argument pointcloud as below. This will basically inflate your original point cloud and may cause slow down since points of a point cloud is stored in a std::vector<T> and it is expensive to resize this container.



          ...
          typedef pcl::PointCloud<pcl::PointXYZ> PC_t;
          PC_t::Ptr temp_pc(new PC_t());
          // Your voxel grid filter code ...
          // ...
          sor.filter(temp_pc);
          for(auto& p : temp_pc->points)
          pointcloud->push_back(p);


          Once the loop in your applyExample(...) function completes, you will have all the initial points and voxel-filtered points. You can then use pcl::ExtractIndices<T> filter to remove all the points in the original point cloud (i.e. cloud). Please note that you know how many points you had at the very beginning hence you know which indices to pass to ExtractIndices. You should also note that removing the points within the loop will invalidate your octree, which is why removal of points has to be deferred. Please check [1] to see how pcl::ExtractIndices<T> is used.



          This is just one way, and possibly one of the least efficient ways, of getting the result you want. Passing another point cloud to your FILTREexample() function onto which you will accumulate the points in temp_pc might help speeding-up a bit. However, the main point here is that there is no method in PCL like filterAndAppend(...).



          [1] http://pointclouds.org/documentation/tutorials/extract_indices.php






          share|improve this answer




















          • Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
            – Raph Schim
            Nov 27 at 8:25


















          1














          Your original point cloud is being substituted because it is exactly what you "told" PCL to do by writing: sor.filter(*pointcloud); The argument to the filter method is the "output cloud". You can pass an empty cloud and the filter result will be saved into it. (the input was already defined via setInputCloud)



          So you can rewrite your FILTERExamples as:



          pcl::PointCloud<pcl::PointXYZ>::Ptr FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
          pcl::VoxelGrid<pcl::PointXYZ> sor;
          sor.setInputCloud(pointcloud);
          sor.setIndices(indices);
          sor.setLeafSize(x, y, z);
          sor.filter(*filtered_pointcloud); // No problem :)
          return filtered_pointcloud;



          And applyExample will just concatenate the clouds:



          void Octree::applyExample(float x, float y, float z) 

          ... // no change

          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
          for (it = octree.leaf_begin(); it != it_end; ++it)


          pcl::IndicesPtr indexVector(new vector<int>);
          pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

          container.getPointIndices(*indexVector);
          *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z);







          share|improve this answer






















          • Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
            – Raph Schim
            Nov 27 at 8:25






          • 1




            Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
            – Raph Schim
            Nov 27 at 9:14










          • Updated. Thanks for the correction!
            – Mark Loyman
            Nov 27 at 11:07










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265873%2fpcl-apply-filter-on-octree-without-cloud-copy%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          To my knowledge, there is no "pcl" way of doing this. You should do some coding yourself to get the results you expect. One alternative that comes to mind is : You can add the resultant (filtered) point cloud from the voxel filter into the input argument pointcloud as below. This will basically inflate your original point cloud and may cause slow down since points of a point cloud is stored in a std::vector<T> and it is expensive to resize this container.



          ...
          typedef pcl::PointCloud<pcl::PointXYZ> PC_t;
          PC_t::Ptr temp_pc(new PC_t());
          // Your voxel grid filter code ...
          // ...
          sor.filter(temp_pc);
          for(auto& p : temp_pc->points)
          pointcloud->push_back(p);


          Once the loop in your applyExample(...) function completes, you will have all the initial points and voxel-filtered points. You can then use pcl::ExtractIndices<T> filter to remove all the points in the original point cloud (i.e. cloud). Please note that you know how many points you had at the very beginning hence you know which indices to pass to ExtractIndices. You should also note that removing the points within the loop will invalidate your octree, which is why removal of points has to be deferred. Please check [1] to see how pcl::ExtractIndices<T> is used.



          This is just one way, and possibly one of the least efficient ways, of getting the result you want. Passing another point cloud to your FILTREexample() function onto which you will accumulate the points in temp_pc might help speeding-up a bit. However, the main point here is that there is no method in PCL like filterAndAppend(...).



          [1] http://pointclouds.org/documentation/tutorials/extract_indices.php






          share|improve this answer




















          • Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
            – Raph Schim
            Nov 27 at 8:25















          1














          To my knowledge, there is no "pcl" way of doing this. You should do some coding yourself to get the results you expect. One alternative that comes to mind is : You can add the resultant (filtered) point cloud from the voxel filter into the input argument pointcloud as below. This will basically inflate your original point cloud and may cause slow down since points of a point cloud is stored in a std::vector<T> and it is expensive to resize this container.



          ...
          typedef pcl::PointCloud<pcl::PointXYZ> PC_t;
          PC_t::Ptr temp_pc(new PC_t());
          // Your voxel grid filter code ...
          // ...
          sor.filter(temp_pc);
          for(auto& p : temp_pc->points)
          pointcloud->push_back(p);


          Once the loop in your applyExample(...) function completes, you will have all the initial points and voxel-filtered points. You can then use pcl::ExtractIndices<T> filter to remove all the points in the original point cloud (i.e. cloud). Please note that you know how many points you had at the very beginning hence you know which indices to pass to ExtractIndices. You should also note that removing the points within the loop will invalidate your octree, which is why removal of points has to be deferred. Please check [1] to see how pcl::ExtractIndices<T> is used.



          This is just one way, and possibly one of the least efficient ways, of getting the result you want. Passing another point cloud to your FILTREexample() function onto which you will accumulate the points in temp_pc might help speeding-up a bit. However, the main point here is that there is no method in PCL like filterAndAppend(...).



          [1] http://pointclouds.org/documentation/tutorials/extract_indices.php






          share|improve this answer




















          • Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
            – Raph Schim
            Nov 27 at 8:25













          1












          1








          1






          To my knowledge, there is no "pcl" way of doing this. You should do some coding yourself to get the results you expect. One alternative that comes to mind is : You can add the resultant (filtered) point cloud from the voxel filter into the input argument pointcloud as below. This will basically inflate your original point cloud and may cause slow down since points of a point cloud is stored in a std::vector<T> and it is expensive to resize this container.



          ...
          typedef pcl::PointCloud<pcl::PointXYZ> PC_t;
          PC_t::Ptr temp_pc(new PC_t());
          // Your voxel grid filter code ...
          // ...
          sor.filter(temp_pc);
          for(auto& p : temp_pc->points)
          pointcloud->push_back(p);


          Once the loop in your applyExample(...) function completes, you will have all the initial points and voxel-filtered points. You can then use pcl::ExtractIndices<T> filter to remove all the points in the original point cloud (i.e. cloud). Please note that you know how many points you had at the very beginning hence you know which indices to pass to ExtractIndices. You should also note that removing the points within the loop will invalidate your octree, which is why removal of points has to be deferred. Please check [1] to see how pcl::ExtractIndices<T> is used.



          This is just one way, and possibly one of the least efficient ways, of getting the result you want. Passing another point cloud to your FILTREexample() function onto which you will accumulate the points in temp_pc might help speeding-up a bit. However, the main point here is that there is no method in PCL like filterAndAppend(...).



          [1] http://pointclouds.org/documentation/tutorials/extract_indices.php






          share|improve this answer












          To my knowledge, there is no "pcl" way of doing this. You should do some coding yourself to get the results you expect. One alternative that comes to mind is : You can add the resultant (filtered) point cloud from the voxel filter into the input argument pointcloud as below. This will basically inflate your original point cloud and may cause slow down since points of a point cloud is stored in a std::vector<T> and it is expensive to resize this container.



          ...
          typedef pcl::PointCloud<pcl::PointXYZ> PC_t;
          PC_t::Ptr temp_pc(new PC_t());
          // Your voxel grid filter code ...
          // ...
          sor.filter(temp_pc);
          for(auto& p : temp_pc->points)
          pointcloud->push_back(p);


          Once the loop in your applyExample(...) function completes, you will have all the initial points and voxel-filtered points. You can then use pcl::ExtractIndices<T> filter to remove all the points in the original point cloud (i.e. cloud). Please note that you know how many points you had at the very beginning hence you know which indices to pass to ExtractIndices. You should also note that removing the points within the loop will invalidate your octree, which is why removal of points has to be deferred. Please check [1] to see how pcl::ExtractIndices<T> is used.



          This is just one way, and possibly one of the least efficient ways, of getting the result you want. Passing another point cloud to your FILTREexample() function onto which you will accumulate the points in temp_pc might help speeding-up a bit. However, the main point here is that there is no method in PCL like filterAndAppend(...).



          [1] http://pointclouds.org/documentation/tutorials/extract_indices.php







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 at 23:20









          ozlsn

          662




          662











          • Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
            – Raph Schim
            Nov 27 at 8:25
















          • Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
            – Raph Schim
            Nov 27 at 8:25















          Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
          – Raph Schim
          Nov 27 at 8:25




          Thanks a lot for your answer. I understand now that it is not possible to achieve what I want. I'll probably have to find another way :(
          – Raph Schim
          Nov 27 at 8:25













          1














          Your original point cloud is being substituted because it is exactly what you "told" PCL to do by writing: sor.filter(*pointcloud); The argument to the filter method is the "output cloud". You can pass an empty cloud and the filter result will be saved into it. (the input was already defined via setInputCloud)



          So you can rewrite your FILTERExamples as:



          pcl::PointCloud<pcl::PointXYZ>::Ptr FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
          pcl::VoxelGrid<pcl::PointXYZ> sor;
          sor.setInputCloud(pointcloud);
          sor.setIndices(indices);
          sor.setLeafSize(x, y, z);
          sor.filter(*filtered_pointcloud); // No problem :)
          return filtered_pointcloud;



          And applyExample will just concatenate the clouds:



          void Octree::applyExample(float x, float y, float z) 

          ... // no change

          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
          for (it = octree.leaf_begin(); it != it_end; ++it)


          pcl::IndicesPtr indexVector(new vector<int>);
          pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

          container.getPointIndices(*indexVector);
          *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z);







          share|improve this answer






















          • Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
            – Raph Schim
            Nov 27 at 8:25






          • 1




            Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
            – Raph Schim
            Nov 27 at 9:14










          • Updated. Thanks for the correction!
            – Mark Loyman
            Nov 27 at 11:07















          1














          Your original point cloud is being substituted because it is exactly what you "told" PCL to do by writing: sor.filter(*pointcloud); The argument to the filter method is the "output cloud". You can pass an empty cloud and the filter result will be saved into it. (the input was already defined via setInputCloud)



          So you can rewrite your FILTERExamples as:



          pcl::PointCloud<pcl::PointXYZ>::Ptr FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
          pcl::VoxelGrid<pcl::PointXYZ> sor;
          sor.setInputCloud(pointcloud);
          sor.setIndices(indices);
          sor.setLeafSize(x, y, z);
          sor.filter(*filtered_pointcloud); // No problem :)
          return filtered_pointcloud;



          And applyExample will just concatenate the clouds:



          void Octree::applyExample(float x, float y, float z) 

          ... // no change

          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
          for (it = octree.leaf_begin(); it != it_end; ++it)


          pcl::IndicesPtr indexVector(new vector<int>);
          pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

          container.getPointIndices(*indexVector);
          *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z);







          share|improve this answer






















          • Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
            – Raph Schim
            Nov 27 at 8:25






          • 1




            Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
            – Raph Schim
            Nov 27 at 9:14










          • Updated. Thanks for the correction!
            – Mark Loyman
            Nov 27 at 11:07













          1












          1








          1






          Your original point cloud is being substituted because it is exactly what you "told" PCL to do by writing: sor.filter(*pointcloud); The argument to the filter method is the "output cloud". You can pass an empty cloud and the filter result will be saved into it. (the input was already defined via setInputCloud)



          So you can rewrite your FILTERExamples as:



          pcl::PointCloud<pcl::PointXYZ>::Ptr FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
          pcl::VoxelGrid<pcl::PointXYZ> sor;
          sor.setInputCloud(pointcloud);
          sor.setIndices(indices);
          sor.setLeafSize(x, y, z);
          sor.filter(*filtered_pointcloud); // No problem :)
          return filtered_pointcloud;



          And applyExample will just concatenate the clouds:



          void Octree::applyExample(float x, float y, float z) 

          ... // no change

          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
          for (it = octree.leaf_begin(); it != it_end; ++it)


          pcl::IndicesPtr indexVector(new vector<int>);
          pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

          container.getPointIndices(*indexVector);
          *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z);







          share|improve this answer














          Your original point cloud is being substituted because it is exactly what you "told" PCL to do by writing: sor.filter(*pointcloud); The argument to the filter method is the "output cloud". You can pass an empty cloud and the filter result will be saved into it. (the input was already defined via setInputCloud)



          So you can rewrite your FILTERExamples as:



          pcl::PointCloud<pcl::PointXYZ>::Ptr FILTREexample(pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, pcl::IndicesPtr indices, float x, float y, float z) 
          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
          pcl::VoxelGrid<pcl::PointXYZ> sor;
          sor.setInputCloud(pointcloud);
          sor.setIndices(indices);
          sor.setLeafSize(x, y, z);
          sor.filter(*filtered_pointcloud); // No problem :)
          return filtered_pointcloud;



          And applyExample will just concatenate the clouds:



          void Octree::applyExample(float x, float y, float z) 

          ... // no change

          pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
          for (it = octree.leaf_begin(); it != it_end; ++it)


          pcl::IndicesPtr indexVector(new vector<int>);
          pcl::octree::OctreeContainerPointIndices& container = it.getLeafContainer();

          container.getPointIndices(*indexVector);
          *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z);








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 27 at 11:06

























          answered Nov 18 at 18:49









          Mark Loyman

          42337




          42337











          • Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
            – Raph Schim
            Nov 27 at 8:25






          • 1




            Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
            – Raph Schim
            Nov 27 at 9:14










          • Updated. Thanks for the correction!
            – Mark Loyman
            Nov 27 at 11:07
















          • Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
            – Raph Schim
            Nov 27 at 8:25






          • 1




            Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
            – Raph Schim
            Nov 27 at 9:14










          • Updated. Thanks for the correction!
            – Mark Loyman
            Nov 27 at 11:07















          Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
          – Raph Schim
          Nov 27 at 8:25




          Thanks a lot! That confirms that I have to create a copy somewhere with filtered points. I'll have to find another way.
          – Raph Schim
          Nov 27 at 8:25




          1




          1




          Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
          – Raph Schim
          Nov 27 at 9:14




          Just a little error, it's *filtered_cloud += *FILTREexample(cloud, indexVector, x,y,z) :)
          – Raph Schim
          Nov 27 at 9:14












          Updated. Thanks for the correction!
          – Mark Loyman
          Nov 27 at 11:07




          Updated. Thanks for the correction!
          – Mark Loyman
          Nov 27 at 11:07

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265873%2fpcl-apply-filter-on-octree-without-cloud-copy%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3