PoseEstimator.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 #ifndef NUKLEI_POSE_ESTIMATOR_H
8 #define NUKLEI_POSE_ESTIMATOR_H
9 
11 #include <nuklei/ObservationIO.h>
12 #include <nuklei/Types.h>
15 
16 #define NUKLEI_POSE_ESTIMATOR_POLYMORPHIC
17 
18 namespace nuklei {
19 
20  const bool WEIGHTED_SUM_EVIDENCE_EVAL = false;
21  const double WHITE_NOISE_POWER = 1e-4;
22 
23  /**
24  * @brief Allows to use an external integrand factor, or test reachability
25  *
26  */
28  {
29  virtual ~CustomIntegrandFactor() {}
30  /**
31  * @brief returns true if pose @p k is reachable by the robot */
32  virtual bool test(const kernel::se3& k) const = 0;
33  /**
34  * @brief returns the evaluation at @p k of an additional integrand factor */
35  virtual double factor(const kernel::se3& k) const = 0;
36  };
37 
39  {
40  PoseEstimator(const double locH = 0,
41  const double oriH = .2,
42  const int nChains = -1,
43  const int n = -1,
44  boost::shared_ptr<CustomIntegrandFactor> cif = boost::shared_ptr<CustomIntegrandFactor>(),
45  const bool partialview = false,
46  const bool progress = true);
47 
48  void load(const std::string& objectFilename,
49  const std::string& sceneFilename,
50  const std::string& meshfile = "",
51  const std::string& viewpointfile = "",
52  const bool light = true,
53  const bool computeNormals = true);
54 
55  void load(const KernelCollection& objectModel,
56  const KernelCollection& sceneModel,
57  const std::string& meshfile = "",
58  const Vector3& viewpoint = Vector3::ZERO,
59  const bool light = true,
60  const bool computeNormals = true);
61 
62  void usePartialViewEstimation(const Vector3& viewpoint)
63  {
64  viewpoint_ = viewpoint;
65  partialview_ = true;
66  }
67 
68  void setMeshToVisibilityTol(const double meshTol) { meshTol_ = meshTol; }
69 
70  void setParallelization(const parallelizer::Type t) { parallel_ = t; }
71  parallelizer::Type getParallelization() const { return parallel_; }
72 
73  void setCustomIntegrandFactor(boost::shared_ptr<CustomIntegrandFactor> cif);
74  boost::shared_ptr<CustomIntegrandFactor> getCustomIntegrandFactor() const;
75 
76  const KernelCollection& getObjectModel() const { return objectModel_; }
77  const KernelCollection& getSceneModel() const { return sceneModel_; }
78 
79  kernel::se3 modelToSceneTransformation(const boost::optional<kernel::se3>& gtTransfo = boost::none) const;
80 
81  double findMatchingScore(const kernel::se3& pose) const;
82 
83  void writeAlignedModel(const std::string& filename,
84  const kernel::se3& t) const;
85 
86  private:
87 
88  Vector3 viewpointInFrame(const kernel::se3& frame) const;
89 
90  // Temperature function (cooling factor)
91  static double Ti(const unsigned i, const unsigned F);
92 
93  /**
94  * This function implements the algorithm of Fig. 2: Simulated annealing
95  * algorithm of the ACCV paper.
96  * - T_j is given by @c temperature
97  * - u is given by Random::uniform()
98  * - w_j is @c currentPose
99  */
100  void
101  metropolisHastings(kernel::se3& currentPose,
102  weight_t &currentWeight,
103  const weight_t temperature,
104  const bool firstRun,
105  const int n) const;
106 
108  mcmc(const int n) const;
109  bool recomputeIndices(std::vector<int>& indices,
110  const kernel::se3& nextPose,
111  const int n) const;
112 
113  KernelCollection objectModel_;
114  double objectSize_;
115  KernelCollection sceneModel_;
116  Vector3 viewpoint_;
117  KernelCollection::EvaluationStrategy evaluationStrategy_;
118  double loc_h_;
119  double ori_h_;
120  int nChains_;
121  int n_;
122  boost::shared_ptr<CustomIntegrandFactor> cif_;
123  bool partialview_;
124  boost::shared_ptr<ProgressIndicator> pi_;
125  bool progress_;
126  parallelizer::Type parallel_;
127  double meshTol_;
128  };
129 
130 }
131 
132 #endif
Public namespace.
Definition: Color.cpp:9
double weight_t
Type for particle weights.
Definition: Definitions.h:31
Definition: Kernel.h:404
virtual double factor(const kernel::se3 &k) const =0
returns the evaluation at k of an additional integrand factor
Allows to use an external integrand factor, or test reachability.
Definition: PoseEstimator.h:27
This class acts as a vector-like container for kernels. It also provides methods related to kernel de...
Definition: PoseEstimator.h:38
virtual bool test(const kernel::se3 &k) const =0
returns true if pose k is reachable by the robot
© 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.