AddContigRegionAsParticle

Declaration: TParticles.AddContigRegionAsParticle (ClassIdx: integer; Region: TInt2DArray): integer;
The function AddContigRegionAsParticle adds a single specified region to the particles assigning it to the particle class ClassIdx (valid range: 1 ... NClasses). Depending on the intersection of the new region with existing particles of the same class, one or more particles may be united to a single larger particle including the specified region. Please note that the region to be added (parameter Region) has to be specified as an array of integer, where all cells (pixels) of the region has to be marked by non-zero numbers, and all background pixels have to be marked by zeros:

Note: the region array must not contain more than one region. If the array contains several regions the resulting particle list will be corrupted.

The function returns the following error codes:

 0 ... everything is OK, the returned number is the particle index of the new particle
-1 ... invalid ClassIdx
-2 ... the size of the Region array does not match the size of the particle data

Hint: In order to access the particles currently loaded in the particle editor you can use the pre-declared global variable PEData.