STIR 6.4.0
display.inl
Go to the documentation of this file.
1//
2//
15/*
16 Copyright (C) 2000 PARAPET partners
17 Copyright (C) 2000- 2009, Hammersmith Imanet Ltd
18 This file is part of STIR.
19
20 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
21
22 See STIR/LICENSE.txt for details
23*/
24
25#include "stir/IndexRange3D.h"
26
27START_NAMESPACE_STIR
37template <class elemT>
38void
39display(const Array<3, elemT>& plane_stack, double maxi, const char* const title, int zoom)
40
41{
42 VectorWithOffset<float> scale_factors(plane_stack.get_min_index(), plane_stack.get_max_index());
43 scale_factors.fill(1.);
44 VectorWithOffset<char*> text(plane_stack.get_min_index(), plane_stack.get_max_index());
45
46 constexpr std::size_t label_size = 10;
47 for (int i = plane_stack.get_min_index(); i <= plane_stack.get_max_index(); i++)
48 {
49 text[i] = new char[label_size];
50 snprintf(text[i], label_size, "%d", i);
51 }
52
53 display(plane_stack, scale_factors, text, maxi, title, zoom);
54 // clean up memory afterwards
55 for (int i = plane_stack.get_min_index(); i <= plane_stack.get_max_index(); i++)
56 delete[] text[i];
57}
58
66template <class elemT>
67void
68display(const Array<2, elemT>& plane, const char* const text, double maxi, int zoom)
69{
70
71 if (plane.get_length() == 0)
72 return;
73 // make a 3D array with arbitrary dimensions for its first and only plane
74 Array<3, elemT> stack(IndexRange3D(0, 0, 0, 0, 0, 0));
75 // this assignment sets correct dimensions for the 2 lowest dimensions
76 stack[0] = plane;
77 VectorWithOffset<float> scale_factors(1);
78 scale_factors[0] = 1.F;
80 texts[0] = "";
81
82 display(stack, scale_factors, texts, maxi, text, zoom);
83}
84
85#if defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
86// gcc 2.95.2 is the only compiler we've used that handles the defaults properly
87
88#else
89// VC and gcc 2.8.1 have problems with the defaults in the above declarations.
90// So, we have to do them by hand...
91
92template <class elemT, class scaleT, class CHARP>
93void
94display(const Array<3, elemT>& plane_stack,
95 const VectorWithOffset<scaleT>& scale_factors,
96 const VectorWithOffset<CHARP>& text,
97 double maxi,
98 const char* const title)
99{
100 display(plane_stack, scale_factors, text, maxi, title, 0);
101}
102
103template <class elemT, class scaleT, class CHARP>
104void
105display(const Array<3, elemT>& plane_stack,
106 const VectorWithOffset<scaleT>& scale_factors,
107 const VectorWithOffset<CHARP>& text,
108 double maxi)
109{
110 display(plane_stack, scale_factors, text, maxi, 0, 0);
111}
112
113template <class elemT, class scaleT, class CHARP>
114void
115display(const Array<3, elemT>& plane_stack, const VectorWithOffset<scaleT>& scale_factors, const VectorWithOffset<CHARP>& text)
116{
117 display(plane_stack, scale_factors, text, 0., 0, 0);
118}
119
120template <class elemT>
121void
122display(const Array<3, elemT>& plane_stack, double maxi, const char* const title)
123{
124 display(plane_stack, maxi, title, 0);
125}
126
127template <class elemT>
128void
129display(const Array<3, elemT>& plane_stack, double maxi)
130{
131 display(plane_stack, maxi, 0, 0);
132}
133
134template <class elemT>
135void
136display(const Array<3, elemT>& plane_stack)
137{
138 display(plane_stack, 0., 0, 0);
139}
140
141template <class elemT>
142void
143display(const Array<2, elemT>& plane, const char* const text, double maxi)
144{
145 display(plane, text, maxi, 0);
146}
147
148template <class elemT>
149void
150display(const Array<2, elemT>& plane, const char* const text)
151{
152 display(plane, text, 0., 0);
153}
154
155template <class elemT>
156void
157display(const Array<2, elemT>& plane)
158{
159 display(plane, 0, 0., 0);
160}
161
162#endif
163
164END_NAMESPACE_STIR
This file declares the class stir::IndexRange3D.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
a 'convenience' class for 3D index ranges. Provides an easier constructor for regular ranges.
Definition IndexRange3D.h:39
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
int get_length() const
return number of elements in this vector
Definition VectorWithOffset.inl:538
void fill(const T &n)
fill elements with value n
Definition VectorWithOffset.inl:571