1 #ifndef mbl_print_h_
2 #define mbl_print_h_
3 //:
4 // \file
5 // \brief Commands that MS debuggers can run easily on demand.
6 // \author Ian Scott
7 //
8 //=======================================================================
9
10 #ifndef NDEBUG // skip all this if not debugging
11
12 #include <iostream>
13 #include <vector>
14 #ifdef _MSC_VER
15 # include <vcl_msvc_warnings.h>
16 #endif
17 #include <vnl/vnl_vector.h>
18 #include <vnl/vnl_matrix.h>
19
20
21 //: Print the first entries of an array of doubles to std::cout.
22 // Print at most n entries
mbl_print_vcl_vector_double(const std::vector<double> & v,int n)23 void mbl_print_vcl_vector_double(const std::vector<double>& v, int n)
24 {
25 if (n>int(v.size())) n=v.size();
26 std::cout << "( ";
27 for (int i=0; i<n;++i) std::cout << v[i] << ' ';
28 if (n<int(v.size())) std::cout << "... ";
29 std::cout << ")\n";
30 }
31
32 //: Print the first entries of an array of doubles to std::cout.
33 // Print at most 5 entries
mbl_print_vcl_vector_double(const std::vector<double> & v)34 void mbl_print_vcl_vector_double(const std::vector<double>& v)
35 {
36 int n = 5;
37 if (n>int(v.size())) n=v.size();
38 std::cout << "( ";
39 for (int i=0; i<n ;++i) std::cout << v[i] << ' ';
40 if (n<int(v.size())) std::cout << "... ";
41 std::cout << ")\n";
42 }
43
44 //: Print the first entries of an array of unsigned to std::cout.
45 // Print at most n entries
mbl_print_vcl_vector_double(const std::vector<double> * v,int n)46 void mbl_print_vcl_vector_double(const std::vector<double>* v, int n)
47 {
48 if (n>int(v->size())) n=v->size();
49 std::cout << "( ";
50 for (int i=0; i<n ;++i) std::cout << (*v)[i] << ' ';
51 if (n<int(v->size())) std::cout << "... ";
52 std::cout << ")\n";
53 }
54
55 //: Print the first entries of an array of unsigned to std::cout.
56 // Print at most 5 entries
mbl_print_vcl_vector_double(const std::vector<double> * v)57 void mbl_print_vcl_vector_double(const std::vector<double>* v)
58 {
59 int n = 5;
60 if (n>int(v->size())) n=v->size();
61 std::cout << "( ";
62 for (int i=0; i<n ;++i) std::cout << (*v)[i] << ' ';
63 if (n<int(v->size())) std::cout << "... ";
64 std::cout << ")\n";
65 }
66
67 //: Print the first entries of an array of unsigned to std::cout.
68 // Print at most n entries
mbl_print_vcl_vector_unsigned(const std::vector<unsigned> & v,int n)69 void mbl_print_vcl_vector_unsigned(const std::vector<unsigned>& v, int n)
70 {
71 if (n>int(v.size())) n=v.size();
72 std::cout << "( ";
73 for (int i=0; i<n ;++i) std::cout << (v)[i] << ' ';
74 if (n<int(v.size())) std::cout << "... ";
75 std::cout << ")\n";
76 }
77
78 //: Print the first entries of an array of unsigned to std::cout.
79 // Print at most 5 entries
mbl_print_vcl_vector_unsigned(const std::vector<unsigned> & v)80 void mbl_print_vcl_vector_unsigned(const std::vector<unsigned>& v)
81 {
82 int n = 5;
83 if (n>int(v.size())) n=v.size();
84 std::cout << "( ";
85 for (int i=0; i<n ;++i) std::cout << (v)[i] << ' ';
86 if (n<int(v.size())) std::cout << "... ";
87 std::cout << ")\n";
88 }
89
90 //: Print the first entries of an array of unsigned to std::cout.
91 // Print at most n entries
mbl_print_vcl_vector_unsigned(const std::vector<unsigned> * v,int n)92 void mbl_print_vcl_vector_unsigned(const std::vector<unsigned>* v, int n)
93 {
94 if (n>int(v->size())) n=v->size();
95 std::cout << "( ";
96 for (int i=0; i<n ;++i) std::cout << (*v)[i] << ' ';
97 if (n<int(v->size())) std::cout << "... ";
98 std::cout << ")\n";
99 }
100
101 //: Print the first entries of an array of unsigned to std::cout.
102 // Print at most 5 entries
mbl_print_vcl_vector_unsigned(const std::vector<unsigned> * v)103 void mbl_print_vcl_vector_unsigned(const std::vector<unsigned>* v)
104 {
105 int n = 5;
106 if (n>int(v->size())) n=v->size();
107 std::cout << "( ";
108 for (int i=0; i<n ;++i) std::cout << (*v)[i] << ' ';
109 if (n<int(v->size())) std::cout << "... ";
110 std::cout << ")\n";
111 }
112
113 //: Print the first entries of an array of unsigned to std::cout.
114 // Print at most n entries
mbl_print_vcl_vector_int(const std::vector<int> & v,int n)115 void mbl_print_vcl_vector_int(const std::vector<int>& v, int n)
116 {
117 if (n>int(v.size())) n=v.size();
118 std::cout << "( ";
119 for (int i=0; i<n ;++i) std::cout << (v)[i] << ' ';
120 if (n<int(v.size())) std::cout << "... ";
121 std::cout << ")\n";
122 }
123
124 //: Print the first entries of an array of unsigned to std::cout.
125 // Print at most 5 entries
mbl_print_vcl_vector_int(const std::vector<int> & v)126 void mbl_print_vcl_vector_int(const std::vector<int>& v)
127 {
128 int n = 5;
129 if (n>int(v.size())) n=v.size();
130 std::cout << "( ";
131 for (int i=0; i<n ;++i) std::cout << (v)[i] << ' ';
132 if (n<int(v.size())) std::cout << "... ";
133 std::cout << ")\n";
134 }
135
136 //: Print the first entries of an array of unsigned to std::cout.
137 // Print at most n entries
mbl_print_vcl_vector_int(const std::vector<int> * v,int n)138 void mbl_print_vcl_vector_int(const std::vector<int>* v, int n)
139 {
140 if (n>int(v->size())) n=v->size();
141 std::cout << "( ";
142 for (int i=0; i<n ;++i) std::cout << (*v)[i] << ' ';
143 if (n<int(v->size())) std::cout << "... ";
144 std::cout << ")\n";
145 }
146
147 //: Print the first entries of an array of unsigned to std::cout.
148 // Print at most 5 entries
mbl_print_vcl_vector_int(const std::vector<int> * v)149 void mbl_print_vcl_vector_int(const std::vector<int>* v)
150 {
151 int n = 5;
152 if (n>int(v->size())) n=v->size();
153 std::cout << "( ";
154 for (int i=0; i<n ;++i) std::cout << (*v)[i] << ' ';
155 if (n<int(v->size())) std::cout << "... ";
156 std::cout << ")\n";
157 }
158
159 //: Print the first entries of the a vector to std::cout.
160 // Print at most n entries
mbl_print_vnl_vecd(const vnl_vector<double> * v,int n)161 void mbl_print_vnl_vecd(const vnl_vector<double>* v, int n)
162 {
163 if (n>int(v->size())) n=v->size();
164 std::cout << "( ";
165 for (int i=0;i<n;++i) std::cout << (*v)(i) << ' ';
166 if (n<int(v->size())) std::cout << "... ";
167 std::cout << ")\n";
168 }
169
170 //: Print the first entries of the a vector to std::cout.
171 // Print at most 5 entries
mbl_print_vnl_vecd(const vnl_vector<double> * v)172 void mbl_print_vnl_vecd(const vnl_vector<double>* v)
173 {
174 int n = 5;
175 if (n>int(v->size())) n=v->size();
176 std::cout << "( ";
177 for (int i=0;i<n;++i) std::cout << (*v)(i) << ' ';
178 if (n<int(v->size())) std::cout << "... ";
179 std::cout << ")\n";
180 }
181
182 //: Print the first entries of the a matrix to std::cout.
183 // Print at most m x n entries
mbl_print_vnl_matd(const vnl_matrix<double> * A,int m,int n)184 void mbl_print_vnl_matd(const vnl_matrix<double>* A, int m, int n)
185 {
186 std::cout << A->rows() << " by " << A->columns() << " Matrix\n";
187
188 if (m>int(A->rows())) m=A->rows();
189 if (n>int(A->columns())) n=A->columns();
190
191 for (int i=0;i<m;++i)
192 {
193 std::cout << "( ";
194
195 for (int j=0; j<n; ++j)
196 std::cout << (*A)(i,j) << ' ';
197 if (n<int(A->columns())) std::cout << "... ";
198 std::cout << ")\n";
199 }
200 if (m<int(A->rows())) std::cout << "( ... )\n";
201 }
202
203 //: Print the first entries of a matrix to std::cout.
204 // Print at most 5 x 5 entries
mbl_print_vnl_matd(const vnl_matrix<double> * A)205 void mbl_print_vnl_matd(const vnl_matrix<double>* A)
206 {
207 int m = 5; int n = 5;
208 std::cout << A->rows() << " by " << A->columns() << " Matrix\n";
209
210 if (m>int(A->rows())) m=A->rows();
211 if (n>int(A->columns())) n=A->columns();
212
213 for (int i=0;i<m;++i)
214 {
215 std::cout << "( ";
216
217 for ( int j=0; j<n; ++j)
218 std::cout << (*A)(i,j) << ' ';
219 if (n<int(A->columns())) std::cout << "... ";
220 std::cout << ")\n";
221 }
222 if (m<int(A->rows())) std::cout << "( ... )\n";
223 }
224
mbl_print_carray_double(const double * v,int n)225 void mbl_print_carray_double(const double* v, int n)
226 {
227 std::cout << "( ";
228 for (int i=0; i<n ;++i) std::cout << v[i] << ' ';
229 std::cout << ")\n";
230 }
231
232 #endif // NDEBUG // skip all this if not debugging
233
234 #endif // mbl_print_h_
235