STIR 6.4.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*/
22
25#include "stir/Array.h"
26
27START_NAMESPACE_STIR
28
39
40template <class elemT>
41int
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
68template <class elemT>
69BasicCoordinate<3, int>
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
101END_NAMESPACE_STIR
defines the stir::Array class for multi-dimensional (numeric) arrays
This file declares class stir::BasicCoordinate and some functions acting on stir::BasicCoordinate obj...
defines the stir::VectorWithOffset class
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
elemT find_max() const
return maximum of all the elements
Definition Array.inl:387
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition BasicCoordinate.h:57
A templated class for vectors, but with indices starting not from 0.
Definition VectorWithOffset.h:65
int get_max_index() const
get value of last valid index
Definition VectorWithOffset.inl:131
int get_min_index() const
get value of first valid index
Definition VectorWithOffset.inl:124
size_t size() const
return number of elements in this vector
Definition VectorWithOffset.inl:546
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
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