Added support for both threshold- and nearestNneighborhood.