17 return (
int)(max*(rand()/(RAND_MAX+1.0)));
22 return min + (rand() / (double)RAND_MAX) * (max -
min);
39 do { r = drand48(); }
while (r == 0.0);
41 do { r = drand48(); }
while (r == 0.0);
42 x2 = 2.0 * drand48() - 1.0;
44 }
while(w > 1.0 || w==0.0);
46 return(sigma * x2 * sqrt(-2.0*log(w)/w));
72 return exp(-.5*delta*delta/sigmaSquare)/sqrt(2*M_PI*sigmaSquare);
79 return -.5*delta*delta/sigmaSquare-.5*log(2*M_PI*sigmaSquare);
100 static gsl_eigen_symmv_workspace * m_eigenspace=NULL;
101 static gsl_matrix * m_cmat=NULL;
102 static gsl_matrix * m_evec=NULL;
103 static gsl_vector * m_eval=NULL;
104 static gsl_vector * m_noise=NULL;
105 static gsl_vector * m_pnoise=NULL;
107 if (m_eigenspace==NULL){
108 m_eigenspace=gsl_eigen_symmv_alloc(3);
109 m_cmat=gsl_matrix_alloc(3,3);
110 m_evec=gsl_matrix_alloc(3,3);
111 m_eval=gsl_vector_alloc(3);
112 m_noise=gsl_vector_alloc(3);
113 m_pnoise=gsl_vector_alloc(3);
116 gsl_matrix_set(m_cmat,0,0,cov.
xx); gsl_matrix_set(m_cmat,0,1,cov.
xy); gsl_matrix_set(m_cmat,0,2,cov.
xt);
117 gsl_matrix_set(m_cmat,1,0,cov.
xy); gsl_matrix_set(m_cmat,1,1,cov.
yy); gsl_matrix_set(m_cmat,1,2,cov.
yt);
118 gsl_matrix_set(m_cmat,2,0,cov.
xt); gsl_matrix_set(m_cmat,2,1,cov.
yt); gsl_matrix_set(m_cmat,2,2,cov.
tt);
119 gsl_eigen_symmv (m_cmat, m_eval, m_evec, m_eigenspace);
120 for (
int i=0; i<3; i++){
121 eval[i]=gsl_vector_get(m_eval,i);
122 for (
int j=0; j<3; j++)
123 evec[i][j]=gsl_matrix_get(m_evec,i,j);
128 static gsl_matrix * m_rmat=NULL;
129 static gsl_matrix * m_vmat=NULL;
130 static gsl_matrix * m_result=NULL;
132 m_rmat=gsl_matrix_alloc(3,3);
133 m_vmat=gsl_matrix_alloc(3,3);
134 m_result=gsl_matrix_alloc(3,3);
139 gsl_matrix_set(m_rmat,0,0, c ); gsl_matrix_set(m_rmat,0,1, -s); gsl_matrix_set(m_rmat,0,2, 0.);
140 gsl_matrix_set(m_rmat,1,0, s ); gsl_matrix_set(m_rmat,1,1, c); gsl_matrix_set(m_rmat,1,2, 0.);
141 gsl_matrix_set(m_rmat,2,0, 0.); gsl_matrix_set(m_rmat,2,1, 0.); gsl_matrix_set(m_rmat,2,2, 1.);
143 for (
unsigned int i=0; i<3; i++)
144 for (
unsigned int j=0; j<3; j++)
145 gsl_matrix_set(m_vmat,i,j,evec[i][j]);
146 gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1., m_rmat, m_vmat, 0., m_result);
148 for (
int i=0; i<3; i++){
149 for (
int j=0; j<3; j++)
150 ecov.
evec[i][j]=gsl_matrix_get(m_result,i,j);
156 static gsl_matrix * m_evec=NULL;
157 static gsl_vector * m_noise=NULL;
158 static gsl_vector * m_pnoise=NULL;
160 m_evec=gsl_matrix_alloc(3,3);
161 m_noise=gsl_vector_alloc(3);
162 m_pnoise=gsl_vector_alloc(3);
164 for (
int i=0; i<3; i++){
165 for (
int j=0; j<3; j++)
166 gsl_matrix_set(m_evec,i,j, evec[i][j]);
168 for (
int i=0; i<3; i++){
172 gsl_vector_set(m_pnoise,i, v);
174 gsl_blas_dgemv (CblasNoTrans, 1., m_evec, m_pnoise, 0, m_noise);
175 OrientedPoint ret(gsl_vector_get(m_noise,0),gsl_vector_get(m_noise,1),gsl_vector_get(m_noise,2));
186 v1 = covariance.evec[0][0]*q.
x+covariance.evec[1][0]*q.
y+covariance.evec[2][0]*q.
theta;
187 v2 = covariance.evec[0][1]*q.
x+covariance.evec[1][1]*q.
y+covariance.evec[2][1]*q.
theta;
188 v3 = covariance.evec[0][2]*q.
x+covariance.evec[1][2]*q.
y+covariance.evec[2][2]*q.
theta;
197 std::vector<double>::const_iterator w=weights.begin();
198 for (std::vector<OrientedPoint>::const_iterator p=poses.begin(); p!=poses.end(); p++){
214 for (std::vector<OrientedPoint>::const_iterator p=poses.begin(); p!=poses.end(); p++){
217 cov.
xx+=*w*delta.
x*delta.
x;
218 cov.
yy+=*w*delta.
y*delta.
y;
220 cov.
xy+=*w*delta.
x*delta.
y;
233 this->covariance=ecov;
241 for (std::vector<OrientedPoint>::const_iterator p=poses.begin(); p!=poses.end(); p++){
255 for (std::vector<OrientedPoint>::const_iterator p=poses.begin(); p!=poses.end(); p++){
258 cov.
xx+=delta.
x*delta.
x;
259 cov.
yy+=delta.
y*delta.
y;
261 cov.
xy+=delta.
x*delta.
y;
273 this->covariance=ecov;
const char *const *argv double delta
EigenCovariance3 rotate(double angle) const
point< T > min(const point< T > &p1, const point< T > &p2)
double sampleUniformDouble(double min, double max)
double evalGaussian(double sigmaSquare, double delta)
double sampleGaussian(double sigma, unsigned int S=0)
point< T > max(const point< T > &p1, const point< T > &p2)
OrientedPoint sample() const
void computeFromSamples(const std::vector< OrientedPoint > &poses)
Covariance3 operator+(const Covariance3 &cov) const
double eval(const OrientedPoint &p) const
int sampleUniformInt(int max)
double evalLogGaussian(double sigmaSquare, double delta)
double pf_ran_gaussian(double sigma)
orientedpoint< double, double > OrientedPoint