STIR  6.2.0
index_at_maximum.h
Go to the documentation of this file.
1 //
2 //
3 /*
4  Copyright (C) 2005- 2005, Hammersmith Imanet Ltd
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
23 #include "stir/VectorWithOffset.h"
24 #include "stir/BasicCoordinate.h"
25 #include "stir/Array.h"
26 
27 START_NAMESPACE_STIR
28 
40 template <class elemT>
41 int
43 {
44  if (v.size() == 0)
45  return 0;
46 
47  int index_at_max = v.get_min_index();
48  elemT max_value = v[index_at_max];
49  for (int index = v.get_min_index(); index <= v.get_max_index(); ++index)
50  {
51  const elemT value = v[index];
52  if (value > max_value)
53  {
54  index_at_max = index;
55  max_value = value;
56  }
57  }
58  return index_at_max;
59 }
60 
68 template <class elemT>
71 {
72  const elemT current_maximum = input_array.find_max();
73  BasicCoordinate<3, int> max_location, min_index, max_index;
74 
75  bool found = false;
76  min_index[1] = input_array.get_min_index();
77  max_index[1] = input_array.get_max_index();
78  for (int k = min_index[1]; k <= max_index[1] && !found; ++k)
79  {
80  min_index[2] = input_array[k].get_min_index();
81  max_index[2] = input_array[k].get_max_index();
82  for (int j = min_index[2]; j <= max_index[2] && !found; ++j)
83  {
84  min_index[3] = input_array[k][j].get_min_index();
85  max_index[3] = input_array[k][j].get_max_index();
86  for (int i = min_index[3]; i <= max_index[3] && !found; ++i)
87  {
88  if (input_array[k][j][i] == current_maximum)
89  {
90  max_location[1] = k;
91  max_location[2] = j;
92  max_location[3] = i;
93  }
94  }
95  }
96  }
97  found = true;
98  return max_location;
99 }
100 
101 END_NAMESPACE_STIR
elemT find_max() const
return maximum of all the elements
Definition: Array.inl:364
int get_min_index() const
get value of first valid index
Definition: VectorWithOffset.inl:116
defines the Array class for multi-dimensional (numeric) arrays
This file declares class stir::BasicCoordinate and some functions acting on stir::BasicCoordinate obj...
int index_at_maximum(const VectorWithOffset< elemT > &v)
Finds the index where the maximum occurs in a (1-dimensional) vector.
Definition: index_at_maximum.h:42
defines the stir::VectorWithOffset class
size_t size() const
return number of elements in this vector
Definition: VectorWithOffset.inl:542
int get_max_index() const
get value of last valid index
Definition: VectorWithOffset.inl:123
BasicCoordinate< 3, int > indices_at_maximum(const Array< 3, elemT > &input_array)
Finds the first (3-dimensional) index where the maximum occurs in a (3-dimensional) array...
Definition: index_at_maximum.h:70