~ugocupcic/sr-ros-interface/manipulation

« back to all changes in this revision

Viewing changes to shadow_robot/dataglove/dataglove_processing/src/particle.cpp

  • Committer: Ugo Cupcic
  • Date: 2011-05-23 15:44:05 UTC
  • mfrom: (119.1.67 sr-ros-interface)
  • Revision ID: ugo@shadowrobot.com-20110523154405-kwvv543sy9wxehzi
Huge merge from trunk. Lots of changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * @file particle.cpp
3
 
 * @author Ugo Cupcic <ugo@shadowrobot.com>, Contact <contact@shadowrobot.com>
4
 
 * @date 9 Nov 2010
5
 
 *
6
 
 * @brief 
7
 
 *
8
 
 *
9
 
 */
10
 
 
11
 
#include "particle.hpp"
12
 
#include <ros/ros.h>
13
 
 
14
 
namespace dataglove
15
 
{
16
 
Particle::Particle()
17
 
{
18
 
    init_weight(1);
19
 
}
20
 
 
21
 
Particle::Particle( int population_size )
22
 
{
23
 
    init_weight(population_size);
24
 
}
25
 
 
26
 
Particle::Particle( boost::ptr_vector<Particle>::iterator particle, bool reset_weight, float average_weight )
27
 
{
28
 
    if( reset_weight )
29
 
        weight = average_weight;
30
 
    else
31
 
        weight = particle->weight;
32
 
 
33
 
    squared_weight = weight * weight;
34
 
}
35
 
 
36
 
Particle::~Particle()
37
 
{
38
 
 
39
 
}
40
 
 
41
 
void Particle::init_weight( int population_size )
42
 
{
43
 
    weight = 1.0f / ((float)population_size);
44
 
    squared_weight = weight * weight;
45
 
}
46
 
 
47
 
float Particle::get_weight() const
48
 
{
49
 
    return weight;
50
 
}
51
 
 
52
 
float Particle::set_weight( float new_weight )
53
 
{
54
 
    weight = new_weight;
55
 
    squared_weight = weight * weight;
56
 
 
57
 
    return squared_weight;
58
 
}
59
 
 
60
 
}//end namespace