KernelCollection.h
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 
8 #ifndef NUKLEI_KERNELCOLLECTION_H
9 #define NUKLEI_KERNELCOLLECTION_H
10 
11 #include <vector>
12 #include <string>
13 #include <iostream>
14 #include <list>
15 #include <boost/ptr_container/ptr_vector.hpp>
16 #include <boost/any.hpp>
17 #include <boost/optional.hpp>
18 #include <boost/none.hpp>
19 #include <boost/tuple/tuple.hpp>
20 
21 #include <nuklei/decoration.h>
23 #include <nuklei/Definitions.h>
24 #include <nuklei/Kernel.h>
25 #include <nuklei/nullable.h>
27 #include <nuklei/trsl/common.hpp>
28 #include <nuklei/trsl/ppfilter_iterator.hpp>
29 #include <nuklei/trsl/is_picked_systematic.hpp>
30 #include <nuklei/trsl/sort_iterator.hpp>
31 
32 
33 namespace nuklei {
34 
35  /**
36  * @ingroup kernels
37  * @brief This class acts as a vector-like container for kernels. It also
38  * provides methods related to kernel density estimation.
39  *
40  * The KDE-related functions of this class are discussed in @ref kernels_kde.
41  *
42  * Note: In Nuklei, the kernel classes (kernel::base and its
43  * descendants) play the double role of representing kernels and
44  * points. For instance, there is no class specifically designed for
45  * holding an @f$ SE(3) @f$ point, the class kernel::se3 is used for
46  * that purpose. A KernelCollection is thus often used to contain a
47  * set of points that are entirely unrelated to a density function.
48  *
49  * @section intermediary Intermediary Results
50  *
51  * Some of the methods of this class can benefit from caching intermediary
52  * results. For instance, the #evaluationAt() method requires a @f$k@f$d-tree
53  * of all kernel positions. @f$k@f$d-trees are expensive to construct, it is
54  * important to avoid reconstructing them in each call of #evaluationAt().
55  *
56  * KernelCollection provides methods for precomputing intermediary results,
57  * such as @f$k@f$d-trees. These structures are stored internally. For
58  * instance,
59  * @code
60  * using namespace nuklei;
61  * KernelCollection kc;
62  * readObservations("file.txt", kc);
63  *
64  * kc.computeKernelStatistics(); // kernel statistics stored internally
65  * kc.buildKdTree(); // position kd-tree stored internally
66  *
67  * kernel::se3 k;
68  * ... // choose a value for k
69  *
70  * double e = kc.evaluationAt(k); // evaluationAt makes use of intermediary
71  * // results
72  * @endcode
73  *
74  * The functions responsible for computing intermediary results are:
75  * - #computeKernelStatistics()
76  * - #buildKdTree()
77  * - #buildNeighborSearchTree()
78  * - #buildConvexHull()
79  *
80  * When a KernelCollection is modified, intermediary results become
81  * invalid. To avoid inconsistencies, each call to a KernelCollection method
82  * which can potentially allow one to modify the contained kernels (for
83  * instance, #add()) automatically destroys all intermediary results. In order
84  * to preserve intermediary results, one has to be careful to avoid calling
85  * these methods. In particular, several methods, such as #front() and
86  * #front()const, or #begin() and #begin()const, have a @p const and a @p
87  * non-const version. The @p const methods will always preserve intermediary
88  * results, while the @p non-const methods are likely to destroy them. One can
89  * force a call to the @p const version with as_const():
90  * @code
91  * using namespace nuklei;
92  * KernelCollection kc;
93  * readObservations("file.txt", kc);
94  *
95  * kc.computeKernelStatistics();
96  * kc.buildKdTree();
97  *
98  * kernel::se3 k;
99  * ... // choose a value for k
100  *
101  * double e = kc.evaluationAt(k); // ok!
102  *
103  * for (KernelCollection::const_iterator i = as_const(kc).begin();
104  * i != as_const(kc).end(); ++i)
105  * {
106  * i->setLocH(10);
107  * }
108  *
109  * double e = kc.evaluationAt(k); // ok!
110  *
111  * // In the following line, even though i is a const_iterator, kc.begin()
112  * // calls the non-const begin() method, which destroys intermediary results.
113  * for (KernelCollection::const_iterator i = kc.begin();
114  * i != kc.end(); ++i)
115  * {
116  * i->setLocH(10);
117  * }
118  *
119  * double e = kc.evaluationAt(k); // throws exception: no kernel statistics,
120  * // no kd-tree.
121  * @endcode
122  *
123  * If the intermediary results that a method requires have not been computed,
124  * the method throws an exception.
125  *
126  * @section iterators Sample Iterators, Sort Iterators
127  *
128  * KernelCollection provides iterators over a random permutation of its
129  * elements (#sampleBegin()), and over a sorted permutation of its elements
130  * (#sortBegin()). One will note that KernelCollection does not provide
131  * sampleEnd() or sortEnd() methods. Ends are provided by the iterators
132  * themselves, and should be accessed as follows:
133  * @code
134  * nuklei::KernelCollection kc = ...;
135  * for (nuklei::KernelCollection::const_sample_iterator i = as_const(kc).sampleBegin(5);
136  * i != i.end(); ++i) // note i.end() instead of kc.end()
137  * {
138  * // *i returns a reference to a datapoint/kernel of kc
139  * // i.index() returns the index (in kc) of that element.
140  * }
141  * for (nuklei::KernelCollection::const_sort_iterator i = as_const(kc).sortBegin(5);
142  * i != i.end(); ++i) // note i.end() instead of kc.end()
143  * {
144  * // *i returns a reference to a datapoint/kernel of kc
145  * // i.index() returns the index (in kc) of that element.
146  * }
147  * @endcode
148  *
149  * These iterators are implemented with <a
150  * href="http://trsl.sourceforge.net">the TRSL library</a>. Refer to the doc
151  * of TRSL for more information.
152  */
154  {
155  public:
156  void assertConsistency() const;
157 
158  // Forwarded container symbols
159 
160  /** @brief Kernel container type. */
161  typedef boost::ptr_vector<kernel::base> Container;
162  /** @brief KernelCollection iterator. */
163  typedef Container::iterator iterator;
164  /** @brief KernelCollection iterator. */
165  typedef Container::const_iterator const_iterator;
166  /** @brief KernelCollection iterator. */
167  typedef Container::reverse_iterator reverse_iterator;
168  /** @brief KernelCollection iterator. */
169  typedef Container::const_reverse_iterator const_reverse_iterator;
170 
171  /** @brief Returns the kernel at index @p n. */
172  Container::reference at(Container::size_type n)
173  { invalidateHelperStructures(); return kernels_.at(n); }
174  /** @brief Returns the kernel at index @p n. */
175  Container::const_reference at(Container::size_type n) const
176  { return kernels_.at(n); }
177 
178  /** @brief Returns the kernel at index @p 0. */
179  Container::reference front()
180  { invalidateHelperStructures(); return kernels_.front(); }
181  /** @brief Returns the kernel at index @p 0. */
182  Container::const_reference front() const
183  { return kernels_.front(); }
184 
185  /** @brief Returns the kernel at index #size()-1. */
186  Container::reference back()
187  { invalidateHelperStructures(); return kernels_.back(); }
188  /** @brief Returns the kernel at index #size()-1. */
189  Container::const_reference back() const
190  { return kernels_.back(); }
191 
192  /** @brief Returns the number of kernels. */
193  Container::size_type size() const
194  { return kernels_.size(); }
195 
196  /** @brief Returns true if empty. */
197  bool empty() const
198  { return kernels_.empty(); }
199 
200  /** @brief Returns an iterator pointing to the first kernel. */
201  Container::iterator begin()
202  { invalidateHelperStructures(); return kernels_.begin(); }
203  /** @brief Returns an iterator pointing to the first kernel. */
204  Container::const_iterator begin() const
205  { return kernels_.begin(); }
206  /** @brief Returns an iterator pointing to the last kernel. */
207  Container::iterator end()
208  { invalidateHelperStructures(); return kernels_.end(); }
209  /** @brief Returns an iterator pointing to the last kernel. */
210  Container::const_iterator end() const
211  { return kernels_.end(); }
212 
213  /** @brief Returns an reverse iterator pointing to the last kernel. */
214  Container::reverse_iterator rbegin()
215  { invalidateHelperStructures(); return kernels_.rbegin(); }
216  /** @brief Returns an reverse iterator pointing to the last kernel. */
217  Container::const_reverse_iterator rbegin() const
218  { return kernels_.rbegin(); }
219  /** @brief Returns an reverse iterator pointing to the first kernel. */
220  Container::reverse_iterator rend()
221  { invalidateHelperStructures(); return kernels_.rend(); }
222  /** @brief Returns an reverse iterator pointing to the first kernel. */
223  Container::const_reverse_iterator rend() const
224  { return kernels_.rend(); }
225 
226  // Container-related methods
227 
228  /** @brief Resets the class to its initial state. */
229  void clear();
230  /** @brief Adds a copy of @p f. */
231  void add(const kernel::base &f);
232  /** @brief Adds a copy of the kernels contained in @p kv. */
233  void add(const KernelCollection &kv);
234  /** @brief Replaces the @p idx'th kernel with a copy of @p k. */
235  void replace(const size_t idx, const kernel::base &k);
236  kernel::base::Type kernelType() const;
237 
238  // Iterators
239 
240  /** @brief Used internally. */
241  typedef nuklei_trsl::is_picked_systematic<
243  /**
244  * @brief Sample Iterator type.
245  *
246  * See #sampleBegin().
247  */
248  typedef nuklei_trsl::ppfilter_iterator<
250  /**
251  * @brief Sample Iterator type.
252  *
253  * See #sampleBegin().
254  */
255  typedef nuklei_trsl::ppfilter_iterator<
257 
258  /**
259  * @brief Returns an iterator that iterates through @p sampleSize kernels
260  * selected randomly.
261  *
262  * Iterates through @p sampleSize kernels. The probability that a kernel
263  * is selected is proportional to its weight: The probability that the @f$
264  * i^{th} @f$ kernel returned by the iterator is the @f$ l^{th} @f$ kernel
265  * of the KernelCollection is proportional to the weight of the @f$ l^{th}
266  * @f$ kernel, as @f[ P(i = \ell) \propto w_{\ell}. @f]
267  *
268  * <b>This iterator does not return samples of the density! It returns
269  * a random subset of the kernels. To get samples from the density, one
270  * needs to get exactly one sample from each kernel returned by the
271  * iterator.</b>
272  *
273  * See @ref iterators for more details.
274  *
275  * This method runs in @f$ O(n+\textrm{sampleSize}) @f$ time, where
276  * @f$ n @f$ is the number of kernels in the collection.
277  */
278  sample_iterator sampleBegin(size_t sampleSize);
279  /**
280  * @brief Returns an iterator that iterates through @p sampleSize kernels.
281  *
282  * This is the @c const version of #sampleBegin().
283  */
284  const_sample_iterator sampleBegin(size_t sampleSize) const;
285 
286  /**
287  * @brief Sort Iterator type.
288  *
289  * See #sortBegin().
290  */
291  typedef nuklei_trsl::reorder_iterator<iterator> sort_iterator;
292  /**
293  * @brief Sort Iterator type.
294  *
295  * See #sortBegin().
296  */
297  typedef nuklei_trsl::reorder_iterator<const_iterator> const_sort_iterator;
298 
299  /**
300  * @brief Returns an iterator that iterates through the @p sortSize
301  * kernels of highest weight, in order of decreasing weight.
302  *
303  * See @ref iterators for more details.
304  */
305  sort_iterator sortBegin(size_t sortSize);
306  /**
307  * @brief Returns an iterator that iterates through the @p sortSize
308  * kernels of highest weight, in order of decreasing weight.
309  *
310  * This is the @c const version of #sortBegin().
311  */
312  const_sort_iterator sortBegin(size_t sortSize) const;
313 
314  // Particle-related methods
315 
316  /**
317  * @brief Computes the sum of all kernel weights (total weight), and the
318  * maximum kernel cut point.
319  *
320  * See @ref kernels_kde for an explanation of "cut point".
321  */
323  /**
324  * @brief Returns the sum of kernel weights.
325  *
326  * Precede by a call to #computeKernelStatistics(). See @ref intermediary.
327  */
328  weight_t totalWeight() const;
329  coord_t maxLocCutPoint() const;
330  /** @brief Divides all weights by the total weight. */
331  void normalizeWeights();
332  /**
333  * @brief Sets all weights to @f$ 1 / t @f$, where @f$ t @f$ is
334  * the total weight of the collection.
335  */
336  void uniformizeWeights();
337 
338  // Statistical moments
339 
340  /**
341  * @brief Returns a kernel holding the mean position and orientation of
342  * the data.
343  */
344  kernel::base::ptr mean() const;
345  /**
346  * @brief Returns a kernel holding the mean and standard deviation in
347  * position and orientation of the data.
348  *
349  * Standard deviations for position and orientation are stored in the
350  * kernel bandwidths.
351  */
352  kernel::base::ptr moments() const;
353 
354  // Geometrical properties
355 
356  /** @brief Transforms the data with @p t. */
357  void transformWith(const kernel::se3& t);
358  /** @brief Transforms the data with the provided translation and rotation. */
359  void transformWith(const Vector3 &translation,
360  const Quaternion &rotation);
361 
362  /**
363  * @brief Computes the local differential properties of the nearest
364  * neighbors of @p k.
365  *
366  * This function requires a neighbor search tree. Its call must thus be
367  * preceded by a call to #buildNeighborSearchTree(). See @ref
368  * intermediary.
369  *
370  * This function uses the CGAL <a
371  * href="http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Jet_fitting_3/Chapter_main.html">Monge
372  * fit</a> functions.
373  */
374  boost::tuple<Matrix3, Vector3, coord_t>
375  localLocationDifferential(const Vector3& k) const;
376 
377  /**
378  * @brief Fits a plane to the positions of the kernels contained in @p
379  * *this.
380  *
381  * The location of the returned kernel is a point of the plane. The
382  * orientation of the returned kernel is such that its @f$ z @f$ axis is
383  * normal to the plane.
384  */
386  /**
387  * @brief Fits a plane to the positions of the kernels contained in @p
388  * *this.
389  *
390  * The location of the returned kernel is a point of the plane. The
391  * orientation of the returned kernel is such that its @f$ z @f$ axis is
392  * normal to the plane.
393  */
395  ransacPlaneFit(coord_t inlinerThreshold, unsigned nSeeds = 100) const;
396 
397  /**
398  * @brief Returns the locations of the contained kernels in an
399  * std::vector.
400  */
401  std::vector<Vector3> get3DPointCloud() const;
402 
403  /**
404  * @brief Computes surface normals at all points. After running this
405  * method, all kernels are nuklei::kernel::r3xs2p.
406  *
407  * The orientations/directions that may be associated to the kernels
408  * prior to calling this method are ignored and replaced with the normals
409  * computed from local neighbors.
410  *
411  * This function requires a neighbor search tree. Its call must thus be
412  * preceded by a call to #buildNeighborSearchTree(). See @ref
413  * intermediary.
414  */
415  void computeSurfaceNormals();
416 
417  /**
418  * @brief Builds a kd-tree of the kernel positions and stores the tree
419  * internally. See @ref intermediary.
420  */
421  void buildKdTree();
422  /**
423  * @brief Builds a neighbor search tree of the kernel positions and stores
424  * the tree internally. See @ref intermediary.
425  */
427  /**
428  * @brief Builds the convex hull of kernel positions and stores the hull
429  * internally. See @ref intermediary.
430  */
431  void buildConvexHull(unsigned n);
432  /**
433  * @brief Check if @p k is within the convex hull of contained kernel
434  * positions.
435  *
436  * Precede by a call to #buildConvexHull(). See @ref intermediary.
437  */
438  bool isWithinConvexHull(const kernel::base& k) const;
439  /**
440  * @brief Builds a mesh from kernel positions. See @ref intermediary.
441  */
442  void buildMesh();
443  void writeMeshToOffFile(const std::string& filename) const;
444  void readMeshFromOffFile(const std::string& filename);
445  void writeMeshToPlyFile(const std::string& filename) const;
446  void readMeshFromPlyFile(const std::string& filename);
447  /**
448  * @brief Builds set of partial views of the object. See @ref intermediary.
449  */
450  void buildPartialViewCache(const double meshTol, const bool useRayToSurfacenormalAngle = false);
451  /**
452  * @brief Assuming that the points in this collection form the surface of
453  * an object, this function computes whether a point @p p is visible from
454  * @p viewpoint, or if it is occluded by the object.
455  *
456  * This function requires prior computation of a surface mesh from the
457  * points of the collection. See buildMesh().
458  *
459  * This function computes whether a segment linking @p viewpoint to @p p
460  * intersects with the mesh.
461  *
462  * If @p tolerance is greater than 0, the function computes whether a
463  * segment linking @p viewpoint to \f[ viewpoint + (p - viewpoint)
464  * \frac{|p-viewpoint|-tolerance}{|p-viewpoint|} \f] intersects with the mesh.
465  */
466  bool isVisibleFrom(const Vector3& p, const Vector3& viewpoint,
467  const coord_t& tolerance = FLOATTOL) const;
468  /**
469  * @brief Same as isVisibleFrom(), but additionally checks that the
470  * ray-to-surfacenormal angle is small enough.
471  */
472  bool isVisibleFrom(const kernel::r3xs2p& p, const Vector3& viewpoint,
473  const coord_t& tolerance = FLOATTOL) const;
474 
475  /**
476  * @brief Assuming that the points in this collection form the surface of
477  * an object, this function returns the indices of points visible from
478  * @p viewpoint.
479  *
480  * See isVisibleFrom() for more details.
481  */
482  std::vector<int> partialView(const Vector3& viewpoint,
483  const coord_t& tolerance = FLOATTOL,
484  const bool useViewcache = false,
485  const bool useRayToSurfacenormalAngle = false) const;
486  /**
487  * @brief Partial View Iterator type.
488  *
489  * See #partialViewBegin().
490  */
491  typedef nuklei_trsl::reorder_iterator<const_iterator> const_partialview_iterator;
492 
493  /**
494  * @brief Assuming that the points in this collection form the surface of
495  * an object, this function returns an iterator that iterates through the
496  * kernels that are visible from @p viewpoint.
497  *
498  * See isVisibleFrom() for more details.
499  *
500  * See @ref iterators for more details.
501  */
503  partialViewBegin(const Vector3& viewpoint,
504  const coord_t& tolerance = FLOATTOL,
505  const bool useViewcache = false,
506  const bool useRayToSurfacenormalAngle = false) const;
507 
508  // Density-related methods
509 
510  /**
511  * @brief Returns @p sampleSize samples from the density modeled by *this.
512  *
513  * See @ref kernels_kde for a description of this method.
514  *
515  * Precede by a call to #computeKernelStatistics(). See
516  * @ref intermediary.
517  */
518  KernelCollection sample(int sampleSize) const;
519  /**
520  * @brief Deprecated. Use #sample() instead.
521  */
522  void resetWithSampleOf(const KernelCollection &kc,
523  int sampleSize);
524 
525  /**
526  * @brief Returns a kernel from the collection.
527  *
528  * The probability of returning the @f$ i^{\rm th} @f$ kernel is
529  * proportional to the weight of that kernel. This methods is @f$ O(n)
530  * @f$, where @f$ n @f$ is the number of kernels contained in the
531  * collection. To efficiently select multiple kernels randomly, use
532  * #sampleBegin().
533  */
534  const kernel::base& randomKernel() const;
535 
536  /** @brief Sets the location bandwidth of all kernels. */
537  void setKernelLocH(coord_t h);
538  /**
539  * @brief Sets the orientation bandwidth of all kernels.
540  *
541  * This method calls kernel::base::setOriH on all kernels. If the kernels
542  * do not have an orientation, this method does nothing.
543  */
544  void setKernelOriH(coord_t h);
545 
546  typedef enum { SUM_EVAL, MAX_EVAL, WEIGHTED_SUM_EVAL } EvaluationStrategy;
547  /**
548  * @brief Evaluates the density represented by @p *this at @p f.
549  *
550  * See @ref kernels_kde for a description of this method.
551  *
552  * Precede by a call to #computeKernelStatistics() and #buildKdTree(). See
553  * @ref intermediary.
554  */
556  const EvaluationStrategy strategy = WEIGHTED_SUM_EVAL) const;
557 
558 
559  // Misc
560 
561  void clearDescriptors();
562 
563  void setFlag(const bitfield_t flag);
564 
565  private:
566  Container kernels_;
567 
568  boost::optional<weight_t> totalWeight_;
569  boost::optional<coord_t> maxLocCutPoint_;
570  boost::optional<kernel::base::Type> kernelType_;
571 
572  decoration<int> deco_;
573  const static int HULL_KEY;
574  const static int KDTREE_KEY;
575  const static int NSTREE_KEY;
576  const static int MESH_KEY;
577  const static int AABBTREE_KEY;
578  const static int VIEWCACHE_KEY;
579 
580  void invalidateHelperStructures();
581 
582  template<class KernelType>
583  weight_t staticEvaluationAt(const kernel::base &k,
584  const EvaluationStrategy strategy) const;
585 
586  kernel::base::ptr deviation(const kernel::base &center) const;
587  template<typename C>
588  C partialView(const Vector3& viewpoint,
589  const coord_t& tolerance,
590  const bool useViewcache,
591  const bool useRayToSurfacenormalAngle) const;
592 
593  friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
594  template<class Archive>
595  void serialize(Archive &ar, const unsigned int version)
596  {
597  ar & NUKLEI_SERIALIZATION_NVP(kernels_);
598  ar & NUKLEI_SERIALIZATION_NVP(kernelType_);
599  }
600 
601  };
602 
603 }
604 
605 namespace nuklei_cereal
606 {
607  // External save function for boost::ptr_vector<T>.
608  template<class Archive>
609  void save(Archive& ar, const boost::ptr_vector<nuklei::kernel::base>& pv)
610  {
611  ar(pv.size());
612  for (const auto& element : pv)
613  {
614 #ifdef NUKLEI_STUPID_AND_DANGEROUS
615  // In the case of binary archives, this is 30% faster than the safe
616  // approach below. With binary compressed, compression dominates cost.
617  std::unique_ptr<const nuklei::kernel::base> ptr;
618  ptr.reset(&element);
619  ar(ptr);
620  ptr.release();
621 #else
622  ar(element.clone());
623 #endif
624  }
625  }
626 
627  // External load function for boost::ptr_vector<T>.
628  template<class Archive>
629  void load(Archive& ar, boost::ptr_vector<nuklei::kernel::base>& pv)
630  {
631  size_t n;
632  ar(n);
633 
634  pv.reserve(n);
635  for (size_t i = 0; i < n; ++i) {
637  ar(p);
638  pv.push_back(NUKLEI_RELEASE(p));
639  }
640  }
641 }
642 
643 #endif
kernel::se3 linearLeastSquarePlaneFit() const
Fits a plane to the positions of the kernels contained in *this.
nuklei_trsl::ppfilter_iterator< is_picked, const_iterator > const_sample_iterator
Sample Iterator type.
Type
Explicit query of a kernel's type. See Type Queries for more info.
Definition: Kernel.h:53
kernel::se3 ransacPlaneFit(coord_t inlinerThreshold, unsigned nSeeds=100) const
Fits a plane to the positions of the kernels contained in *this.
bool empty() const
Returns true if empty.
nuklei_trsl::reorder_iterator< const_iterator > const_sort_iterator
Sort Iterator type.
std::vector< Vector3 > get3DPointCloud() const
Returns the locations of the contained kernels in an std::vector.
void add(const kernel::base &f)
Adds a copy of f.
nuklei_trsl::ppfilter_iterator< is_picked, iterator > sample_iterator
Sample Iterator type.
Public namespace.
Definition: Color.cpp:9
Container::const_iterator const_iterator
KernelCollection iterator.
const_partialview_iterator partialViewBegin(const Vector3 &viewpoint, const coord_t &tolerance=FLOATTOL, const bool useViewcache=false, const bool useRayToSurfacenormalAngle=false) const
Assuming that the points in this collection form the surface of an object, this function returns an i...
double weight_t
Type for particle weights.
Definition: Definitions.h:31
kernel::base::ptr moments() const
Returns a kernel holding the mean and standard deviation in position and orientation of the data.
Definition: Kernel.h:404
void buildPartialViewCache(const double meshTol, const bool useRayToSurfacenormalAngle=false)
Builds set of partial views of the object. See Intermediary Results.
Container::const_iterator end() const
Returns an iterator pointing to the last kernel.
nuklei_trsl::is_picked_systematic< kernel::base, weight_t, kernel::base::WeightAccessor > is_picked
Used internally.
This class acts as a vector-like container for kernels. It also provides methods related to kernel de...
sort_iterator sortBegin(size_t sortSize)
Returns an iterator that iterates through the sortSize kernels of highest weight, in order of decreas...
void uniformizeWeights()
Sets all weights to , where is the total weight of the collection.
unsigned int bitfield_t
Type for bitfield.
Definition: Definitions.h:33
void buildConvexHull(unsigned n)
Builds the convex hull of kernel positions and stores the hull internally. See Intermediary Results.
Container::reverse_iterator rend()
Returns an reverse iterator pointing to the first kernel.
Container::reference back()
Returns the kernel at index size()-1.
bool isWithinConvexHull(const kernel::base &k) const
Check if k is within the convex hull of contained kernel positions.
void setKernelLocH(coord_t h)
Sets the location bandwidth of all kernels.
Container::reference at(Container::size_type n)
Returns the kernel at index n.
weight_t totalWeight() const
Returns the sum of kernel weights.
void setKernelOriH(coord_t h)
Sets the orientation bandwidth of all kernels.
Container::reverse_iterator reverse_iterator
KernelCollection iterator.
Polymorphic kernel class.
Definition: Kernel.h:45
Container::reference front()
Returns the kernel at index 0.
NUKLEI_UNIQUE_PTR< kernel::base > ptr
NUKLEI_UNIQUE_PTR for kernel::base.
Definition: Kernel.h:50
Definition: Kernel.h:505
double coord_t
Type for point coordinates.
Definition: Definitions.h:25
Container::const_reverse_iterator rbegin() const
Returns an reverse iterator pointing to the last kernel.
Container::iterator end()
Returns an iterator pointing to the last kernel.
KernelCollection sample(int sampleSize) const
Returns sampleSize samples from the density modeled by *this.
const kernel::base & randomKernel() const
Returns a kernel from the collection.
kernel::base::ptr mean() const
Returns a kernel holding the mean position and orientation of the data.
void transformWith(const kernel::se3 &t)
Transforms the data with t.
Container::iterator begin()
Returns an iterator pointing to the first kernel.
void replace(const size_t idx, const kernel::base &k)
Replaces the idx'th kernel with a copy of k.
nuklei_trsl::reorder_iterator< const_iterator > const_partialview_iterator
Partial View Iterator type.
sample_iterator sampleBegin(size_t sampleSize)
Returns an iterator that iterates through sampleSize kernels selected randomly.
bool isVisibleFrom(const Vector3 &p, const Vector3 &viewpoint, const coord_t &tolerance=FLOATTOL) const
Assuming that the points in this collection form the surface of an object, this function computes whe...
boost::tuple< Matrix3, Vector3, coord_t > localLocationDifferential(const Vector3 &k) const
Computes the local differential properties of the nearest neighbors of k.
void buildKdTree()
Builds a kd-tree of the kernel positions and stores the tree internally. See Intermediary Results.
weight_t evaluationAt(const kernel::base &f, const EvaluationStrategy strategy=WEIGHTED_SUM_EVAL) const
Evaluates the density represented by *this at f.
void normalizeWeights()
Divides all weights by the total weight.
Weight accessor for kernel::base. The accessor is used internally. Normal Nuklei users will generally...
Definition: Kernel.h:206
void resetWithSampleOf(const KernelCollection &kc, int sampleSize)
Deprecated. Use sample() instead.
Container::const_reference at(Container::size_type n) const
Returns the kernel at index n.
Container::size_type size() const
Returns the number of kernels.
nuklei_trsl::reorder_iterator< iterator > sort_iterator
Sort Iterator type.
std::vector< int > partialView(const Vector3 &viewpoint, const coord_t &tolerance=FLOATTOL, const bool useViewcache=false, const bool useRayToSurfacenormalAngle=false) const
Assuming that the points in this collection form the surface of an object, this function returns the ...
void computeKernelStatistics()
Computes the sum of all kernel weights (total weight), and the maximum kernel cut point.
boost::ptr_vector< kernel::base > Container
Kernel container type.
Container::const_reverse_iterator const_reverse_iterator
KernelCollection iterator.
Container::iterator iterator
KernelCollection iterator.
void clear()
Resets the class to its initial state.
Container::reverse_iterator rbegin()
Returns an reverse iterator pointing to the last kernel.
void buildNeighborSearchTree()
Builds a neighbor search tree of the kernel positions and stores the tree internally....
void buildMesh()
Builds a mesh from kernel positions. See Intermediary Results.
Container::const_reference front() const
Returns the kernel at index 0.
Container::const_reference back() const
Returns the kernel at index size()-1.
void computeSurfaceNormals()
Computes surface normals at all points. After running this method, all kernels are nuklei::kernel::r3...
Container::const_iterator begin() const
Returns an iterator pointing to the first kernel.
Container::const_reverse_iterator rend() const
Returns an reverse iterator pointing to the first kernel.
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.