OpenMS
AveragePosition.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
13 namespace OpenMS
14 {
15 
16  namespace Math
17  {
29  template <UInt D>
31  {
32 public:
33 
35  enum
36  {
37  DIMENSION = D
38  };
39 
42 
45 
46 public:
47 
50  position_(),
52  weight_sum_()
53  {
54  }
55 
58  position_(rhs.position_),
61  {
62  }
63 
65  PositionType const & getPosition() const
66  {
67  return position_;
68  }
69 
71  CoordinateType const & getWeight() const
72  {
73  return weight_sum_;
74  }
75 
77  void clear()
78  {
79  position_.clear();
81  weight_sum_ = 0;
82  return;
83  }
84 
86  void add(PositionType position, CoordinateType const weight = 1)
87  {
88 
89  weight_sum_ += weight;
90  position *= weight;
91  position_weighted_sum_ += position;
92 
93  // if the sum of weights is 0, set all coordinates to zero as well
94  if (weight_sum_ == 0)
95  {
96  position_.clear();
97  }
98  else
99  {
102  }
103  return;
104  }
105 
106 protected:
107 
111 
112  };
113 
114  } // namespace Math
115 
116 } // namespace OpenMS
117 
double CoordinateType
Coordinate type.
Definition: DPosition.h:33
void clear()
Set all dimensions to zero.
Definition: DPosition.h:339
Maintain an average position by summing up positions with weights.
Definition: AveragePosition.h:31
AveragePosition()
Default constructor.
Definition: AveragePosition.h:49
PositionType const & getPosition() const
Returns the current average position.
Definition: AveragePosition.h:65
CoordinateType weight_sum_
Definition: AveragePosition.h:110
PositionType::CoordinateType CoordinateType
Weight type (for weighted average - a scalar type)
Definition: AveragePosition.h:44
PositionType position_
Definition: AveragePosition.h:108
AveragePosition(AveragePosition const &rhs)
Copy constructor.
Definition: AveragePosition.h:57
void add(PositionType position, CoordinateType const weight=1)
Add a position.
Definition: AveragePosition.h:86
@ DIMENSION
Definition: AveragePosition.h:37
DPosition< DIMENSION > PositionType
Position type (a D-dimensional position)
Definition: AveragePosition.h:41
CoordinateType const & getWeight() const
Returns the total weight.
Definition: AveragePosition.h:71
void clear()
Reset everything. (Note that update() will cause a division by zero after that.)
Definition: AveragePosition.h:77
PositionType position_weighted_sum_
Definition: AveragePosition.h:109
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22