iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests/test-PointCloud2Common.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 <array>
using namespace nrt;
int main( int argc, char ** argv )
{
typedef std::array<int,3> Arr;
PointCloud2 cloud2 = PointCloud2::create<int, bool, Arr>();
typedef PointCloud2::Geometry Geometry;
//TODO: allow this to work without the wrap up in pointcloud2data
// also add emplace
// also allow this to work with initializer lists
Arr xx = {{1,2,3}};
Arr yy = {{0,0,0}};
cloud2.insert( PT(Geometry(0), 3, true, xx ) );
cloud2.insert( PT(Geometry(1), 2, false, yy ) );
cloud2.insert( PT(Geometry(7), 7, false, yy ) );
// Test centroid and minmax
auto centroid = computeCentroid( cloud2 );
Geometry min, max;
computeMinMax( cloud2, min, max );
NRT_INFO( "centroid " << centroid );
NRT_INFO( "min " << min );
NRT_INFO( "max " << max );
// Test covariance
NRT_INFO( computeCovariance( cloud2, true ) );
// Test centroid on specific fields
auto centroidInt = computeCentroid<int>( cloud2 );
NRT_INFO( centroidInt );
//NRT_INFO( computeCentroid<Arr>( cloud2 ) ); // Should not compile since array does not support arithmetic ops
// TODO: throw some type traits magic in here to make this a nice compile time error
// Test minmax on specific fields
bool minB, maxB;
int minI, maxI;
computeMinMax<bool>( cloud2, minB, maxB );
computeMinMax<int>( cloud2, minI, maxI );
NRT_INFO( minB << " " << maxB << " " << minI << " " << maxI);
// Test transform
auto demeaned = demeanPointCloud( cloud2, centroid );
auto demeanedInt = demeanPointCloud<int>( demeaned, centroidInt );
auto iter1 = cloud2.begin<int>();
auto iter2 = demeanedInt.begin<int>();
for( ; iter1 != cloud2.end<int>(); ++iter1, ++iter2 )
{
NRT_INFO( "original " << *iter1 );
NRT_INFO( "demeaned " << *iter2 );
}
auto cloudIdent = transformPointCloud( cloud2, PointCloud2::AffineTransform::Identity() );
auto iter3 = cloud2.geometry_begin();
auto iter4 = cloudIdent.geometry_begin();
for( ; iter3 != cloud2.geometry_end(); ++iter3, ++iter4 )
NRT_INFO( "expect zeros " << *iter3 - *iter4 );
transformPointCloudInPlace( cloud2, PointCloud2::AffineTransform::Identity() );
for( auto i = cloud2.geometry_const_begin(); i != cloud2.geometry_const_end(); ++i )
NRT_INFO( *i );
return 0;
}
#else
int main( int argc, char ** argv )
{
return 1;
}
#endif // NRT_HAVE_CLOUD