medianFilter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
40 
41 namespace ar_track_alvar
42 {
43  using namespace alvar;
44 
46  median_n = n;
47  median_ind = 0;
48  median_init = false;
49  median_poses = new Pose[median_n];
50  }
51 
52  void MedianFilter::addPose(const Pose &new_pose){
53  median_poses[median_ind] = new_pose;
54  median_ind = (median_ind+1) % median_n;
55  }
56 
57  void MedianFilter::getMedian(Pose &ret_pose){
58  if(!median_init){
59  if(median_ind == median_n-1)
60  median_init = true;
61  ret_pose = median_poses[median_ind-1];
62  }
63 
64  else{
65  double min_dist = 0;
66  int min_ind = 0;
67  for(int i=0; i<median_n; i++){
68  double total_dist = 0;
69  for(int j=0; j<median_n; j++){
70  total_dist += pow(median_poses[i].translation[0] - median_poses[j].translation[0], 2);
71  total_dist += pow(median_poses[i].translation[1] - median_poses[j].translation[1], 2);
72  total_dist += pow(median_poses[i].translation[2] - median_poses[j].translation[2], 2);
73  total_dist += pow(median_poses[i].quaternion[0] - median_poses[j].quaternion[0], 2);
74  total_dist += pow(median_poses[i].quaternion[1] - median_poses[j].quaternion[1], 2);
75  total_dist += pow(median_poses[i].quaternion[2] - median_poses[j].quaternion[2], 2);
76  total_dist += pow(median_poses[i].quaternion[3] - median_poses[j].quaternion[3], 2);
77  }
78  if(i==0) min_dist = total_dist;
79  else{
80  if(total_dist < min_dist){
81  min_dist = total_dist;
82  min_ind = i;
83  }
84  }
85  }
86  ret_pose = median_poses[min_ind];
87  }
88  }
89 
90 } //namespace
Main ALVAR namespace.
Definition: Alvar.h:174
void getMedian(alvar::Pose &ret_pose)
Pose representation derived from the Rotation class
Definition: Pose.h:50
void addPose(const alvar::Pose &new_pose)


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04