[pdal] How to add filters (with C++ API)

Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[pdal] How to add filters (with C++ API)

Odd Ragnar Lydersen

I’m writing code to add filters when reading las files.

All examples are in json format, and I’m wondering what is the best way to do this in C++.

 

I’ve been looking at the tests from the source code, to get examples, but I can’t find any that combine different kinds of filters.

 

Code example (Semi Pseudo):

 

if (useFilters)

  {

    bool filterInputIsSet = false;

 

    LasReader filterReader;

    prepareLasReader(filterReader, fileName);

 

   if (useCropFilter)

    {     

      cropOptions.add("bounds", someBounds);

 

      if (!filterInputIsSet)

      {

        crpFilter.setInput(filterReader);

        filterInputIsSet = true;

      }

      cropFilter.addOptions(cropOptions);

    }

 

    if (useClassFilter)

    {

      std::string classFilterString;

      for (int i=0; i <= ClassificationType::eOverlapPoints; i++)

      {

        addClassToString(classFilterString);

      }

      rangeOptions.add("limits", classFilterString);

 

      if (!filterInputIsSet) // Only rangeFilter is used

      {

        rangeFilter.setInput(filterReader);

        filterInputIsSet = true;

      }

      else // Both filters are used

      {

        rngFilter.setInput(cropFilter);

      }

 

      rangeFilter.setOptions(rangeOptions);

      rangeFilter.prepare(table);

      point_view_set = rangeFilter.execute(table);

      point_view = *point_view_set.begin();

    }

    else // Only cropFilter is used

    {

      cropFilter.prepare(table);

      point_view_set = cropFilter.execute(table);

      point_view = *point_view_set.begin();

    }

 }

  else // No filters are used

  {

    LasReader.prepare(table);

    point_view_set = LasReader.execute(table);

    point_view = *point_view_set.begin();

  }

 

Is there a better, and more elegant way to do this?

 


_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal
Reply | Threaded
Open this post in threaded view
|

Re: [pdal] How to add filters (with C++ API)

andrew.bell.ia@gmail.com
I'm not exactly sure what your goal is.  If you're trying to write some kind of a UI that builds a pipeline based on some options (or some such), then what you're doing is pretty much it.  You might want to look at the source code for some of the kernels.  The info kernel is a bit of a mess, but does this kind of thing.  You might also have a look at PipelineManager, which is what we use internally to build pipelines from a specification.

That said, no matter what you're doing, the general procedure is to build a pipeline, then prepare and execute it.

Hope that helps,

On Wed, May 16, 2018 at 9:06 AM, Odd Ragnar Lydersen <[hidden email]> wrote:

I’m writing code to add filters when reading las files.

All examples are in json format, and I’m wondering what is the best way to do this in C++.

 

I’ve been looking at the tests from the source code, to get examples, but I can’t find any that combine different kinds of filters.

 

Code example (Semi Pseudo):

 

if (useFilters)

  {

    bool filterInputIsSet = false;

 

    LasReader filterReader;

    prepareLasReader(filterReader, fileName);

 

   if (useCropFilter)

    {     

      cropOptions.add("bounds", someBounds);

 

      if (!filterInputIsSet)

      {

        crpFilter.setInput(filterReader);

        filterInputIsSet = true;

      }

      cropFilter.addOptions(cropOptions);

    }

 

    if (useClassFilter)

    {

      std::string classFilterString;

      for (int i=0; i <= ClassificationType::eOverlapPoints; i++)

      {

        addClassToString(classFilterString);

      }

      rangeOptions.add("limits", classFilterString);

 

      if (!filterInputIsSet) // Only rangeFilter is used

      {

        rangeFilter.setInput(filterReader);

        filterInputIsSet = true;

      }

      else // Both filters are used

      {

        rngFilter.setInput(cropFilter);

      }

 

      rangeFilter.setOptions(rangeOptions);

      rangeFilter.prepare(table);

      point_view_set = rangeFilter.execute(table);

      point_view = *point_view_set.begin();

    }

    else // Only cropFilter is used

    {

      cropFilter.prepare(table);

      point_view_set = cropFilter.execute(table);

      point_view = *point_view_set.begin();

    }

 }

  else // No filters are used

  {

    LasReader.prepare(table);

    point_view_set = LasReader.execute(table);

    point_view = *point_view_set.begin();

  }

 

Is there a better, and more elegant way to do this?

 


_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal



--
Andrew Bell
[hidden email]

_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal
Reply | Threaded
Open this post in threaded view
|

Re: [pdal] How to add filters (with C++ API)

Odd Ragnar Lydersen

You’re quite right, I’m trying to write some UI, where filters are applied to the input file.

It’s just that it’s so easy to set up in Json format, where you set the input file first, then apply filters, then writes to output.

Like this sample: https://pdal.io/tutorial/las.html#header-fields-example

 

I would like to do it in a similar way in C++.

The way I have done it feels wrong, since I cannot specify the input file right away, and then move on to the next stage in the pipeline.

 

I’ve had a look at the classes which you referred to.

Studying the code it seems like what I should really do, is to build a pipeline in C++.

It should probably be similar to the Json sample I refer to above in this message.

 

The guide “https://pdal.io/api/transition/index.html “ which I based my initial code upon didn’t mention the pipeline.

 

I’ll try to use the PipelineManager and see how it goes.

 

>Odd-Ragnar<


_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal
Reply | Threaded
Open this post in threaded view
|

Re: [pdal] How to add filters (with C++ API)

Howard Butler-3


On 5/23/18 3:06 AM, Odd Ragnar Lydersen wrote:
> I’ll try to use the PipelineManager and see how it goes.
Both the Python and Java extensions exclusively use the PipelineManager
rather than directly interacting with Stages. It is much easier to
manipulate PDAL pipeline in JSON than directly touching the objects.
Additionally, we are unlikely to break the Pipeline JSON syntax going
forward, but the C++ API might change a little bit which would cause you
to adapt.

If you workflow is to simply get at data and drive PDAL's stages, using
pipelines as JSON with PipelineManager is going to be the easiest and
most convenient way to program things.

Howard



_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal

signature.asc (540 bytes) Download Attachment