Go to the documentation of this file.
8 #ifndef NUKLEI_KERNELCOLLECTION_H
9 #define NUKLEI_KERNELCOLLECTION_H
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>
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>
156 void assertConsistency()
const;
172 Container::reference
at(Container::size_type n)
173 { invalidateHelperStructures();
return kernels_.at(n); }
175 Container::const_reference
at(Container::size_type n)
const
176 {
return kernels_.at(n); }
180 { invalidateHelperStructures();
return kernels_.front(); }
182 Container::const_reference
front()
const
183 {
return kernels_.front(); }
187 { invalidateHelperStructures();
return kernels_.back(); }
189 Container::const_reference
back()
const
190 {
return kernels_.back(); }
193 Container::size_type
size()
const
194 {
return kernels_.size(); }
198 {
return kernels_.empty(); }
202 { invalidateHelperStructures();
return kernels_.begin(); }
204 Container::const_iterator
begin()
const
205 {
return kernels_.begin(); }
208 { invalidateHelperStructures();
return kernels_.end(); }
210 Container::const_iterator
end()
const
211 {
return kernels_.end(); }
215 { invalidateHelperStructures();
return kernels_.rbegin(); }
217 Container::const_reverse_iterator
rbegin()
const
218 {
return kernels_.rbegin(); }
220 Container::reverse_iterator
rend()
221 { invalidateHelperStructures();
return kernels_.rend(); }
223 Container::const_reverse_iterator
rend()
const
224 {
return kernels_.rend(); }
241 typedef nuklei_trsl::is_picked_systematic<
248 typedef nuklei_trsl::ppfilter_iterator<
255 typedef nuklei_trsl::ppfilter_iterator<
329 coord_t maxLocCutPoint()
const;
360 const Quaternion &rotation);
374 boost::tuple<Matrix3, Vector3, coord_t>
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);
466 bool isVisibleFrom(
const Vector3& p,
const Vector3& viewpoint,
467 const coord_t& tolerance = FLOATTOL)
const;
473 const coord_t& tolerance = FLOATTOL)
const;
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;
504 const coord_t& tolerance = FLOATTOL,
505 const bool useViewcache =
false,
506 const bool useRayToSurfacenormalAngle =
false)
const;
546 typedef enum { SUM_EVAL, MAX_EVAL, WEIGHTED_SUM_EVAL } EvaluationStrategy;
556 const EvaluationStrategy strategy = WEIGHTED_SUM_EVAL)
const;
561 void clearDescriptors();
568 boost::optional<weight_t> totalWeight_;
569 boost::optional<coord_t> maxLocCutPoint_;
570 boost::optional<kernel::base::Type> kernelType_;
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;
580 void invalidateHelperStructures();
582 template<
class KernelType>
584 const EvaluationStrategy strategy)
const;
590 const bool useViewcache,
591 const bool useRayToSurfacenormalAngle)
const;
593 friend class NUKLEI_SERIALIZATION_FRIEND_CLASSNAME;
594 template<
class Archive>
595 void serialize(Archive &ar,
const unsigned int version)
597 ar & NUKLEI_SERIALIZATION_NVP(kernels_);
598 ar & NUKLEI_SERIALIZATION_NVP(kernelType_);
605 namespace nuklei_cereal
608 template<
class Archive>
609 void save(Archive& ar,
const boost::ptr_vector<nuklei::kernel::base>& pv)
612 for (
const auto& element : pv)
614 #ifdef NUKLEI_STUPID_AND_DANGEROUS
617 std::unique_ptr<const nuklei::kernel::base> ptr;
628 template<
class Archive>
629 void load(Archive& ar, boost::ptr_vector<nuklei::kernel::base>& pv)
635 for (
size_t i = 0; i < n; ++i) {
638 pv.push_back(NUKLEI_RELEASE(p));
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.
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.
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.
kernel::base::ptr moments() const
Returns a kernel holding the mean and standard deviation in position and orientation of the data.
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.
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.
Container::reference front()
Returns the kernel at index 0.
NUKLEI_UNIQUE_PTR< kernel::base > ptr
NUKLEI_UNIQUE_PTR for kernel::base.
double coord_t
Type for point coordinates.
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...
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.