iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests/test-PointCloud2Filter.C
/*! @file
@author Shane Grant
@copyright GNU Public License (GPL v3)
@section License
@verbatim
// ////////////////////////////////////////////////////////////////////////
// The iLab Neuromorphic Robotics Toolkit (NRT) //
// Copyright 2010-2012 by the University of Southern California (USC) //
// and the iLab at USC. //
// //
// iLab - University of Southern California //
// Hedco Neurociences Building, Room HNB-10 //
// Los Angeles, Ca 90089-2520 - USA //
// //
// See http://ilab.usc.edu for information about this project. //
// ////////////////////////////////////////////////////////////////////////
// This file is part of The iLab Neuromorphic Robotics Toolkit. //
// //
// The iLab Neuromorphic Robotics Toolkit is free software: you can //
// redistribute it and/or modify it under the terms of the GNU General //
// Public License as published by the Free Software Foundation, either //
// version 3 of the License, or (at your option) any later version. //
// //
// The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
// that it will be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
// PURPOSE. See the GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with The iLab Neuromorphic Robotics Toolkit. If not, see //
// <http://www.gnu.org/licenses/>. //
// ////////////////////////////////////////////////////////////////////////
@endverbatim */
#include <nrt/config.h>
#ifdef NRT_HAVE_CLOUD
#include <boost/random.hpp>
using namespace nrt;
void createRandomCloud( PointCloud2 & cloud, int size )
{
boost::mt19937 rng;
boost::uniform_real<float> u(-3.0, 3.0);
boost::variate_generator< boost::mt19937&, boost::uniform_real<float> > gen(rng, u);
cloud.resize( size );
for( auto i = cloud.geometry_begin(); i != cloud.geometry_end(); ++i )
*i = {gen(), gen(), gen()};
}
int main( int argc, char ** argv )
{
PointCloud2 cloud1;
const size_t cloudsize = 10000;
const double filteramount = 0.75;
createRandomCloud( cloud1, cloudsize );
// Test RandomRemovalFilter
PointCloud2 filtered = filterPointCloud( cloud1, RandomRemovalFilter( filteramount ) );
NRT_INFO( "Filtered size (expect " << cloudsize * filteramount << "): " << filtered.size() );
// Test pass through, only letting through values in a small cube area range
filtered = filterPointCloud( cloud1, PassThroughFilter(),
[](PointCloud2::Geometry const & p)
{
return p.x() >= 0.0 && p.x() < 1 && p.y() >= 0.0 && p.y() < 1 &&
p.z() >= 0.0 && p.z() < 1;
} );
NRT_INFO( "And now a bunch of points in the cube [0,1) xyz: " );
for( auto i = filtered.begin(); i != filtered.end(); ++i )
NRT_INFO( *i );
PointCloud2 cloud2;
for( size_t i = 0; i < 1000; ++i )
cloud2.insert( {0.3f, 0.3f, 0.3f} );
filtered = filterPointCloud( cloud2, DuplicateRemovalFilter( 0.01 ) );
NRT_INFO( "Removing duplicates from a cloud of 1000 same point, should get one out: " );
for( auto i = filtered.begin(); i != filtered.end(); ++i )
NRT_INFO( *i );
}
#else
int main( int argc, char ** argv )
{
return 1;
}
#endif // NRT_HAVE_CLOUD