Commit a2dadea0 authored by Mike Rye's avatar Mike Rye

Added more optional K-d trees to filters that support them.

parent 8d9b1027
......@@ -6,6 +6,10 @@
* Consider how to improve the directory hierarchy.
* Add KdTree options to filters that support them (use PCLNormalEstimationFilter as template).
## Create a pcl::Feature Class
A number of PCL filter classes derive from [pcl::Feature](http://docs.pointclouds.org/trunk/classpcl_1_1_feature.html) and thus share several parameters. A common class and base proxy should be introduced to share these parameters across several filters. The main difficulty is the lack of support for multiple inheritance and templated inheritance in VTK. As only a linear hierarchy is possible, the possible solutions are not ideal. This is yet another reason to reconsider an approach that generates filters automatically from simple configuration files.
## OpenNi Source
* Expose all parameters via proxy (RGB & depth camera focal distances and modes).
......
......@@ -21,6 +21,7 @@
#define PCL_NO_PRECOMPILE 1
#include <pcl/surface/mls.h>
#include <pcl/search/kdtree.h>
//------------------------------------------------------------------------------
// The indices must correspond to the ones in the proxy.
......@@ -124,6 +125,8 @@ void vtkPCLMovingLeastSquaresFilter::PrintSelf(ostream & os, vtkIndent indent)
os << indent << "NumberOfThreads: " << this->NumberOfThreads << '\n';
os << indent << "UpsamplingMethod: " << getUpsamplingMethodString(this->UpsamplingMethod) << '\n';
os << indent << "ProjectionMethod: " << getProjectionMethodString(this->ProjectionMethod) << '\n';
os << indent << "UseKdtree: " << this->UseKdTree << "\n";
os << indent << "Epsilon: " << this->Epsilon << "\n";
}
//------------------------------------------------------------------------------
......@@ -177,6 +180,7 @@ int vtkPCLMovingLeastSquaresFilter::InternalInternalApplyPCLFilter(
typedef pcl::PointCloud<InPointType> InCloudT;
typedef pcl::PointCloud<OutPointType> OutCloudT;
// typedef pcl::PointCloud<NormalPointType> NormalCloudT;
typedef pcl::search::KdTree<InPointType> KdTreeT;
typename InCloudT::Ptr inputCloud(new InCloudT);
typename OutCloudT::Ptr outputCloud(new OutCloudT);
......@@ -195,6 +199,12 @@ int vtkPCLMovingLeastSquaresFilter::InternalInternalApplyPCLFilter(
mls.setInputCloud(inputCloud);
// mls.setOutputNormals(normalCloud);
if (this->UseKdTree)
{
typename KdTreeT::Ptr kdtree(new KdTreeT());
kdtree->setEpsilon(this->Epsilon);
mls.setSearchMethod(kdtree);
}
mls.setComputeNormals(this->ComputeNormals);
mls.setPolynomialOrder(this->PolynomialOrder);
......
......@@ -59,6 +59,10 @@ private:
unsigned int UpsamplingMethod = 0;
unsigned int ProjectionMethod = 1;
// KdTree attributes
bool UseKdTree {false};
float Epsilon {0};
public:
vtkSetMacro(ComputeNormals, bool);
vtkGetMacro(ComputeNormals, bool);
......@@ -102,6 +106,12 @@ public:
vtkSetMacro(ProjectionMethod, unsigned int);
vtkGetMacro(ProjectionMethod, unsigned int);
vtkSetMacro(UseKdTree, bool);
vtkGetMacro(UseKdTree, bool);
vtkSetMacro(Epsilon, float);
vtkGetMacro(Epsilon, float);
//------------------------------------------------------------------------------
private:
int ApplyPCLFilter(
......
......@@ -23,6 +23,9 @@
#include <pcl/features/normal_3d_omp.h>
#include <pcl/search/kdtree.h>
//------------------------------------------------------------------------------
vtkStandardNewMacro(vtkPCLNormalEstimationFilter);
//------------------------------------------------------------------------------
......@@ -103,7 +106,6 @@ int vtkPCLNormalEstimationFilter::EstimateNormals(
if (this->UseKdTree)
{
typename KdTreeT::Ptr kdtree(new KdTreeT());
std::cout << "Epsilon: " << kdtree->getEpsilon() << '\n';
kdtree->setEpsilon(this->Epsilon);
ne.setSearchMethod(kdtree);
}
......
......@@ -21,6 +21,7 @@
// #define PCL_NO_PRECOMPILE
#include <pcl/features/fpfh_omp.h>
#include <pcl/search/kdtree.h>
vtkStandardNewMacro(vtkPCLFPFHEstimationFilter2);
......@@ -40,6 +41,8 @@ void vtkPCLFPFHEstimationFilter2::PrintSelf(ostream & os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Radius: " << this->Radius << '\n';
os << indent << "UseKdtree: " << this->UseKdTree << "\n";
os << indent << "Epsilon: " << this->Epsilon << "\n";
}
//------------------------------------------------------------------------------
......@@ -124,6 +127,16 @@ int vtkPCLFPFHEstimationFilter2::ComputeFeatures(
vtkPolyData * features
)
{
typedef typename T::PointCloud::PointType PointInType;
typedef pcl::search::KdTree<PointInType> KdTreeT;
if (this->UseKdTree)
{
typename KdTreeT::Ptr kdtree(new KdTreeT());
kdtree->setEpsilon(this->Epsilon);
estimator.setSearchMethod(kdtree);
}
estimator.setRadiusSearch(this->Radius);
typename FeatureCloudT::Ptr featuresCloud(new FeatureCloudT);
estimator.compute((* featuresCloud));
......
......@@ -46,10 +46,20 @@ private:
typedef pcl::PointCloud<FeatureType> FeatureCloudT;
double Radius {0.07};
// KdTree attributes
bool UseKdTree {false};
float Epsilon {0};
public:
vtkSetMacro(Radius, double);
vtkGetMacro(Radius, double);
vtkSetMacro(UseKdTree, bool);
vtkGetMacro(UseKdTree, bool);
vtkSetMacro(Epsilon, float);
vtkGetMacro(Epsilon, float);
//------------------------------------------------------------------------------
private:
int ApplyPCLFilter2(
......
......@@ -22,6 +22,7 @@
#include "vtkObjectFactory.h"
#include <pcl/features/intensity_gradient.h>
#include <pcl/search/kdtree.h>
......@@ -43,6 +44,8 @@ void vtkPCLIntensityGradientEstimationFilter2::PrintSelf(ostream & os, vtkIndent
{
this->Superclass::PrintSelf(os, indent);
os << indent << "RadiusSearch: " << this->RadiusSearch << '\n';
os << indent << "UseKdtree: " << this->UseKdTree << "\n";
os << indent << "Epsilon: " << this->Epsilon << "\n";
}
//------------------------------------------------------------------------------
......@@ -93,6 +96,7 @@ int vtkPCLIntensityGradientEstimationFilter2::InternalInternalApplyPCLFilter2(
typedef pcl::PointCloud<IPointType> ICloudT;
typedef pcl::PointCloud<NPointType> NCloudT;
typedef pcl::PointCloud<pcl::IntensityGradient> IGCloudT;
typedef pcl::search::KdTree<IPointType> KdTreeT;
typename ICloudT::Ptr intensityCloud(new ICloudT);
typename NCloudT::Ptr normalCloud(new NCloudT);
......@@ -110,6 +114,12 @@ int vtkPCLIntensityGradientEstimationFilter2::InternalInternalApplyPCLFilter2(
ige.setInputCloud(intensityCloud);
ige.setInputNormals(normalCloud);
ige.setRadiusSearch(this->RadiusSearch);
if (this->UseKdTree)
{
typename KdTreeT::Ptr kdtree(new KdTreeT());
kdtree->setEpsilon(this->Epsilon);
ige.setSearchMethod(kdtree);
}
ige.compute((* outputCloud));
vtkPCLConversions::PolyDataFromPointCloud(outputCloud, output);
......
......@@ -44,10 +44,20 @@ private:
private:
float RadiusSearch {0.10};
// KdTree attributes
bool UseKdTree {false};
float Epsilon {0};
public:
vtkGetMacro(RadiusSearch, float);
vtkSetMacro(RadiusSearch, float);
vtkSetMacro(UseKdTree, bool);
vtkGetMacro(UseKdTree, bool);
vtkSetMacro(Epsilon, float);
vtkGetMacro(Epsilon, float);
//------------------------------------------------------------------------------
private:
int ApplyPCLFilter2(
......
......@@ -56,6 +56,11 @@ protected:
bool HasTransformation {false};
bool ReuseTransformation {false};
// KdTree attributes
bool UseKdTree {false};
float Epsilon {0};
public:
vtkGetMacro(MaxCorrespondenceDistance, double);
vtkSetMacro(MaxCorrespondenceDistance, double);
......@@ -75,6 +80,12 @@ public:
vtkGetMacro(ReuseTransformation, bool);
vtkSetMacro(ReuseTransformation, bool);
vtkSetMacro(UseKdTree, bool);
vtkGetMacro(UseKdTree, bool);
vtkSetMacro(Epsilon, float);
vtkGetMacro(Epsilon, float);
void Reset()
{
this->HasTransformation = false;
......
......@@ -19,6 +19,7 @@
#define vtkPCLRegistrationFilter2_txx
#include "vtkPCLRegistrationFilter2.h"
#include <pcl/search/kdtree.h>
//------------------------------------------------------------------------------
inline
......@@ -46,6 +47,8 @@ void vtkPCLRegistrationFilter2::PrintSelf(ostream & os, vtkIndent indent)
os << indent << "TransformationMatrix: " << this->TransformationMatrix << "\n";
os << indent << "HasTransformation: " << (this->HasTransformation ? "yes" : "no") << "\n";
os << indent << "ReuseTransformation: " << (this->ReuseTransformation ? "yes" : "no") << "\n";
os << indent << "UseKdtree: " << this->UseKdTree << "\n";
os << indent << "Epsilon: " << this->Epsilon << "\n";
}
//------------------------------------------------------------------------------
......@@ -73,6 +76,28 @@ void vtkPCLRegistrationFilter2::ConfigureAndAlign(
pcl::PointCloud<PointSource> & outputCloud
)
{
typedef pcl::search::KdTree<PointSource> KdTreeSourceT;
typedef pcl::search::KdTree<PointTarget> KdTreeTargetT;
if (this->UseKdTree)
{
// Do not override existing search methods.
auto kdtreeSourcePtr = reg.getSearchMethodSource();
if (kdtreeSourcePtr == nullptr)
{
typename KdTreeSourceT::Ptr kdtreeSource(new KdTreeSourceT());
kdtreeSource->setEpsilon(this->Epsilon);
reg.setSearchMethodSource(kdtreeSource);
}
auto kdtreeTargetPtr = reg.getSearchMethodTarget();
if (kdtreeTargetPtr == nullptr)
{
typename KdTreeTargetT::Ptr kdtreeTarget(new KdTreeTargetT());
kdtreeTarget->setEpsilon(this->Epsilon);
reg.setSearchMethodTarget(kdtreeTarget);
}
}
reg.setMaxCorrespondenceDistance(this->MaxCorrespondenceDistance);
reg.setMaximumIterations(this->MaximumIterations);
reg.setTransformationEpsilon(this->TransformationEpsilon);
......
......@@ -106,6 +106,36 @@
<Property name="Reset" />
</PropertyGroup>
<IntVectorProperty
name="UseKdTree"
label="Use KdTree"
command="SetUseKdTree"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<BooleanDomain name="bool" />
<Documentation>Configure the filter to explicitly use K-d trees.</Documentation>
</IntVectorProperty>
<DoubleVectorProperty
name="Epsilon"
command="SetEpsilon"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<Documentation>Search epsilon precision (error bound) for nearest neighbor searches.</Documentation>
</DoubleVectorProperty>
<PropertyGroup
label="K-d Tree Properties"
panel_visibility="advanced"
>
<Property name="UseKdTree" />
<Property name="Epsilon" />
</PropertyGroup>
<!-- End PCLRegistration -->
</SourceProxy>
</ProxyGroup>
......
......@@ -48,6 +48,36 @@
<Documentation>The radius within which neighboring points will be considered.</Documentation>
</DoubleVectorProperty>
<IntVectorProperty
name="UseKdTree"
label="Use KdTree"
command="SetUseKdTree"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<BooleanDomain name="bool" />
<Documentation>Configure the filter to explicitly use a K-d tree.</Documentation>
</IntVectorProperty>
<DoubleVectorProperty
name="Epsilon"
command="SetEpsilon"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<Documentation>Search epsilon precision (error bound) for nearest neighbor searches.</Documentation>
</DoubleVectorProperty>
<PropertyGroup
label="K-d Tree Properties"
panel_visibility="advanced"
>
<Property name="UseKdTree" />
<Property name="Epsilon" />
</PropertyGroup>
<Hints>
<ShowInMenu category="PCL" />
</Hints>
......
......@@ -18,6 +18,36 @@
<Documentation>The search radius.</Documentation>
</DoubleVectorProperty>
<IntVectorProperty
name="UseKdTree"
label="Use KdTree"
command="SetUseKdTree"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<BooleanDomain name="bool" />
<Documentation>Configure the filter to explicitly use a K-d tree.</Documentation>
</IntVectorProperty>
<DoubleVectorProperty
name="Epsilon"
command="SetEpsilon"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<Documentation>Search epsilon precision (error bound) for nearest neighbor searches.</Documentation>
</DoubleVectorProperty>
<PropertyGroup
label="K-d Tree Properties"
panel_visibility="advanced"
>
<Property name="UseKdTree" />
<Property name="Epsilon" />
</PropertyGroup>
<Hints>
<ShowInMenu category="PCL" />
</Hints>
......
......@@ -165,6 +165,36 @@
<IntVectorProperty
name="UseKdTree"
label="Use KdTree"
command="SetUseKdTree"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<BooleanDomain name="bool" />
<Documentation>Configure the filter to explicitly use a K-d tree.</Documentation>
</IntVectorProperty>
<DoubleVectorProperty
name="Epsilon"
command="SetEpsilon"
number_of_elements="1"
default_values="0"
panel_visibility="advanced"
>
<Documentation>Search epsilon precision (error bound) for nearest neighbor searches.</Documentation>
</DoubleVectorProperty>
<PropertyGroup
label="K-d Tree Properties"
panel_visibility="advanced"
>
<Property name="UseKdTree" />
<Property name="Epsilon" />
</PropertyGroup>
<Hints>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment