20 #ifndef MIRTK_PointLocator_H 21 #define MIRTK_PointLocator_H 23 #include "mirtk/Object.h" 25 #include "mirtk/Array.h" 26 #include "mirtk/Point.h" 27 #include "mirtk/Memory.h" 29 #include "vtkSmartPointer.h" 30 #include "vtkPointSet.h" 31 #include "vtkPointData.h" 32 #include "vtkDataArray.h" 36 class vtkOctreePointLocator;
43 class FlannPointLocator;
87 FeatureInfo(
int index = -2,
double weight = 1.0,
double slope = 1.0,
double intercept = .0)
89 _Name(
""), _Index(index), _Weight(weight), _Slope(slope), _Intercept(intercept)
93 FeatureInfo(
const char *name,
double weight = 1.0,
double slope = 1.0,
double intercept = .0)
95 _Name(name), _Index(-2), _Weight(weight), _Slope(slope), _Intercept(intercept)
99 FeatureInfo(
const string &name,
double weight = 1.0,
double slope = 1.0,
double intercept = .0)
101 _Name(name), _Index(-2), _Weight(weight), _Slope(slope), _Intercept(intercept)
105 FeatureInfo(
const char *name,
int index,
double weight = 1.0,
double slope = 1.0,
double intercept = .0)
107 _Name(name), _Index(index), _Weight(weight), _Slope(slope), _Intercept(intercept)
111 FeatureInfo(
const string &name,
int index,
double weight = 1.0,
double slope = 1.0,
double intercept = .0)
113 _Name(name), _Index(index), _Weight(weight), _Slope(slope), _Intercept(intercept)
134 static int GetNumberOfPoints(vtkPointSet *dataset,
const Array<int> *sample = NULL);
149 static int GetPointIndex(vtkPointSet *dataset,
const Array<int> *sample,
int index);
157 static void GetPoint(
Point &point, vtkPointSet *dataset,
const Array<int> *sample,
int index);
166 static void GetPoint(
double *point, vtkPointSet *dataset,
const Array<int> *sample,
167 int index,
const FeatureList *feature = NULL);
175 static void GetPoint(
double *point, vtkPointSet *dataset,
int index,
const FeatureList *feature = NULL);
242 const Array<int> *sample = NULL,
243 const FeatureList *feature = NULL);
269 const Array<int> *sample,
271 const FeatureList *features,
272 double *dist2 = NULL);
284 const FeatureList *features,
285 double *dist2 = NULL);
296 const Array<int> *sample,
298 double *dist2 = NULL);
309 double *dist2 = NULL);
320 const Array<int> *sample,
321 const FeatureList *features,
322 Array<double> *dist2 = NULL);
332 const FeatureList *features,
333 Array<double> *dist2 = NULL);
343 const Array<int> *sample,
344 Array<double> *dist2 = NULL);
353 Array<double> *dist2 = NULL);
367 const Array<int> *sample1,
368 const FeatureList *features1,
369 vtkPointSet *dataset2,
370 const Array<int> *sample2,
371 const FeatureList *features2,
372 Array<double> *dist2 = NULL);
397 const Array<int> *sample,
399 const FeatureList *features,
400 Array<double> *dist2 = NULL);
412 const Array<int> *sample,
414 Array<double> *dist2 = NULL);
427 const FeatureList *features,
428 Array<double> *dist2 = NULL);
439 Array<double> *dist2 = NULL);
451 const Array<int> *sample,
452 const FeatureList *features,
453 Array<Array<double> > *dist2 = NULL);
464 const Array<int> *sample,
465 Array<Array<double> > *dist2 = NULL);
476 const FeatureList *features,
477 Array<Array<double> > *dist2 = NULL);
487 Array<Array<double> > *dist2 = NULL);
502 vtkPointSet *dataset1,
503 const Array<int> *sample1,
504 const FeatureList *features1,
505 vtkPointSet *dataset2,
506 const Array<int> *sample2,
507 const FeatureList *features2,
508 Array<Array<double> > *dist2 = NULL);
533 const Array<int> *sample,
535 const FeatureList *features,
536 Array<double> *dist2 = NULL);
548 const Array<int> *sample,
550 Array<double> *dist2 = NULL);
563 const FeatureList *features,
564 Array<double> *dist2 = NULL);
575 Array<double> *dist2 = NULL);
587 const Array<int> *sample,
588 const FeatureList *features,
589 Array<Array<double> > *dist2 = NULL);
600 const Array<int> *sample,
601 Array<Array<double> > *dist2 = NULL);
612 const FeatureList *features,
613 Array<Array<double> > *dist2 = NULL);
623 Array<Array<double> > *dist2 = NULL);
638 vtkPointSet *dataset1,
639 const Array<int> *sample1,
640 const FeatureList *features1,
641 vtkPointSet *dataset2,
642 const Array<int> *sample2,
643 const FeatureList *features2,
644 Array<Array<double> > *dist2 = NULL);
659 vtkPointData *
const pd = dataset->GetPointData();
660 if (feature.
_Index >= 0)
return pd->GetArray(feature.
_Index);
661 return pd->GetArray(feature.
_Name.c_str());
667 return (sample && sample->size() > 0 ?
static_cast<int>(sample->size()) : dataset->GetNumberOfPoints());
674 if (features && features->size() > 0) {
676 vtkDataArray *feature_array;
677 for (FeatureList::const_iterator feature = features->begin(); feature != features->end(); ++feature) {
678 if (feature->_Weight != .0) {
679 if (feature->_Index == -1) {
683 dim += feature_array->GetNumberOfComponents();
696 return (sample && sample->size() > 0 ? (*sample)[index] : index);
705 dataset->GetPoint(i, pt);
706 point.
_x = pt[0], point.
_y = pt[1], point.
_z = pt[2];
714 if (features && features->size() > 0) {
715 vtkDataArray *feature_array;
716 for (FeatureList::const_iterator feature = features->begin(); feature != features->end(); ++feature) {
717 if (feature->_Weight != .0) {
718 if (feature->_Index == -1) {
719 dataset->GetPoint(i, point);
720 for (
int d = 0; d < 3; ++d, ++point) {
721 (*point) = feature->_Weight * (feature->_Slope * (*point) + feature->_Intercept);
725 feature_array->GetTuple(i, point);
726 for (
int d = 0; d < feature_array->GetNumberOfComponents(); ++d, ++point) {
727 (*point) = feature->_Weight * (feature->_Slope * (*point) + feature->_Intercept);
733 dataset->GetPoint(i, point);
741 GetPoint(point, dataset, NULL, index, features);
748 double dx, dist2 = .0;
749 for (
int i = 0; i < d; ++i) {
765 double *point =
new double[_PointDimension];
766 GetPoint(point, dataset, sample, index, features);
783 int index,
double *dist2)
819 vtkPointSet *dataset2,
const Array<int> *sample2,
const FeatureList *features2,
820 Array<double> *dist2)
822 UniquePtr<PointLocator> locator(
PointLocator::New(dataset2, sample2, features2));
823 return locator->FindClosestPoint(dataset1, sample1, features1, dist2);
835 double *point =
new double[_PointDimension];
836 GetPoint(point, dataset, sample, index, features);
853 int index, Array<double> *dist2)
889 vtkPointSet *dataset2,
const Array<int> *sample2,
const FeatureList *features2,
890 Array<Array<double> > *dist2)
892 UniquePtr<PointLocator> locator(
PointLocator::New(dataset2, sample2, features2));
893 return locator->FindClosestNPoints(k, dataset1, sample1, features1, dist2);
903 int index,
const FeatureList *features, Array<double> *dist2)
905 double *point =
new double[_PointDimension];
906 GetPoint(point, dataset, sample, index, features);
923 int index, Array<double> *dist2)
938 const FeatureList *features, Array<Array<double> > *dist2)
960 vtkPointSet *dataset2,
const Array<int> *sample2,
const FeatureList *features2,
961 Array<Array<double> > *dist2)
963 UniquePtr<PointLocator> locator(
PointLocator::New(dataset2, sample2, features2));
964 return locator->FindPointsWithinRadius(radius, dataset1, sample1, features1, dist2);
970 #endif // MIRTK_PointLocator_H PointLocator()
Constructor.
double _Slope
Rescaling slope of feature/point data.
int FindClosestPoint(double *point, double *dist2=NULL)
FeatureInfo(const char *name, int index, double weight=1.0, double slope=1.0, double intercept=.0)
Constructor.
FeatureInfo(const string &name, double weight=1.0, double slope=1.0, double intercept=.0)
Constructor.
SharedPtr< FlannPointLocator > _FlannLocator
FLANN point locator used for higher-dimensional feature spaces when available.
double _Weight
Weight of feature/point data.
mirtkPublicAttributeMacro(FeatureList, Features)
Indices/names and rescaling parameters of point data arrays.
static int GetPointDimension(vtkPointSet *dataset, const FeatureList *feature)
double _x
x coordinate of Point
int _Index
Index of feature/point data array.
static int GetNumberOfPoints(vtkPointSet *dataset, const Array< int > *sample=NULL)
FeatureInfo(const string &name, int index, double weight=1.0, double slope=1.0, double intercept=.0)
Constructor.
static double Distance2BetweenPoints(const double *a, const double *b, int d=3)
Array< FeatureInfo > FeatureList
List of point features to use for nearest neighbor search.
static vtkDataArray * GetDataArray(vtkPointSet *dataset, const FeatureInfo &feature)
virtual ~PointLocator()
Destructor.
Array< int > FindPointsWithinRadius(double radius, double *point, Array< double > *dist2=NULL)
mirtkReadOnlyAttributeMacro(int, NumberOfPoints)
Number of points in search structure.
void Initialize()
Initialize point locator.
static int GetPointIndex(vtkPointSet *dataset, const Array< int > *sample, int index)
mirtkPublicAggregateMacro(vtkPointSet, DataSet)
Dataset for which search structure is build.
static void GetPoint(Point &point, vtkPointSet *dataset, const Array< int > *sample, int index)
FeatureInfo(const char *name, double weight=1.0, double slope=1.0, double intercept=.0)
Constructor.
double _z
z coordinate of Point
FeatureInfo(int index=-2, double weight=1.0, double slope=1.0, double intercept=.0)
Constructor.
double _y
y coordinate of Point
static PointLocator * New(vtkPointSet *dataset, const Array< int > *sample=NULL, const FeatureList *feature=NULL)
int NumberOfPoints(vtkDataSet *)
Number of points.
Array< int > FindClosestNPoints(int k, double *point, Array< double > *dist2=NULL)
double _Intercept
Rescaling intercept of feature/point data.
vtkSmartPointer< vtkOctreePointLocator > _VtkLocator
VTK point locator used for three-dimensional feature spaces.
string _Name
Name of feature/point data array.