Samplers - Dev

This page contains useful information for developers who want to modify / add content to the samplers module.

First of all, two points of advice:

  • Use the existing samplers as guideline.
  • Follow the general CONTRIBUTING GUIDELINES.

The Big Picture

Filters are used by the method:


Take a look at the source code in order to get a general overview of how samplers are being used. All samplers are classes and all have the same methods.

The sections below will guide you trough the samplers module explaining how you can create your own samplers or where you need to look in order to modify existing ones.

Base Class

All samplers must inherit from the base class Sampler and implement its abstract methods.

The base class is located at pyntcloud/filters/

class pyntcloud.samplers.base.Sampler(*, pyntcloud)[source]

Base class for sampling methods.

At the very least, all samplers receive a PyntCloud when they are instantiated.

The Sampler.extract_info method must be overridden in order to extract and save the information required to generate the sample in a attribute.

See SUBMODULE BASE CLASS below for more information.

Sampler.compute is where the sample is generated and returned. It should use the information extracted by the above method in order to generate the sample.


Submodule Base Class

Samplers are grouped into submodules according to which kind of information they require to be computed.

For example, samplers that require a VoxelGrid to be computed are in pyntcloud/samplers/

As the information required by all the filters in each submodule is the same, we create a submodule base class overriding the __init__ and extract_info methods of the Sampler base class.

For example, in the s_voxelgrid submodule there is a Sampler_Voxelgrid class from which all the samplers that require a Voxelgrid inherit.

If you don’t find a submodule that extracts the information that your new sampler needs, create a new one using as guideline one of the existing ones.

Specific Sampler Class

Once you have a submodule base class that extracts the right information, you have to actually create the specific class for your sampler, inheriting from the submodule base class and overriding the Sampler.compute method.

If the computation of your sample requires some parameters from the user, you should override the __init__ method in order to accept those parameters.

For example, the RandomMesh sampler requires the user to specify if the sample will use RGB and/or normal information:

Let PyntCloud know about your sampler

In order to do so, you have to do some things:

  • Add tests at test/
  • Import your new sampler(s) and/or submodule(s) at pyntcloud/samplers/
  • Include them in the ALL_SAMPLERS dictionary, giving them a string alias, at pyntcloud/samplers/
  • Document them in the PyntCloud.get_sample docstring at pyntcloud/
  • Document them at docs/samplers.rst.