2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 #ifndef _BBTKSIMPLEUTILITIES_H_
29 #define _BBTKSIMPLEUTILITIES_H_
33 #include <vtkImageData.h>
66 void init(int x, int y, int z)
68 //Se pregunta al OS el tamanio de la palabra de un apuntador
69 int palabra = sizeof(T);
70 db = vtkImageData::New();
71 db->SetDimensions(x,y,z);
72 db->SetOrigin(0, 0, 0);
74 //EED 2017-01-01 Migration VTK7
75 #if (VTK_MAJOR_VERSION <= 5)
76 db->SetScalarType(Memcache::darTipo(palabra));
77 db->AllocateScalars();
80 #if (VTK_MAJOR_VERSION >= 6)
81 db->AllocateScalars(Memcache::darTipo(palabra),1);
86 void* get(int x, int y, int z)
88 T* apap = (T*)db->GetScalarPointer(x,y,z);
89 void* ap = (void*)*apap;
93 void* pop(int x, int y, int z)
95 T* apap = (T*)db->GetScalarPointer(x,y,z);
96 void* ap = (void*)*apap;
101 void put(int x, int y, int z, void* apt)
103 T* punto = (T*)db->GetScalarPointer(x,y,z);
111 for (int i=ext[0]; i<=ext[1]; i++)
113 for (int j=ext[2]; j<=ext[3]; j++)
115 for (int k=ext[4]; k<=ext[5]; k++)
117 ap1 = (T*)db->GetScalarPointer(i,j,k);
123 static int darTipo(int tamanio)
125 if (tamanio == sizeof(char))
127 if (tamanio == sizeof(unsigned char))
128 return VTK_UNSIGNED_CHAR;
129 if (tamanio == sizeof(short))
131 if (tamanio == sizeof(unsigned short))
132 return VTK_UNSIGNED_SHORT;
133 if (tamanio == sizeof(int))
135 if (tamanio == sizeof(unsigned int))
136 return VTK_UNSIGNED_INT;
137 if (tamanio == sizeof(long))
139 if (tamanio == sizeof(unsigned long))
140 return VTK_UNSIGNED_LONG;
141 if (tamanio == sizeof(float))
143 if (tamanio == sizeof(double))
154 static time_t first, second;
156 static void tic(vtkImageData* img)
158 tiempo::bytes = VTK_SIZE(img);
159 tiempo::first = time (NULL);
161 static void tic(int bytes_=0)
163 tiempo::bytes = bytes_;
164 tiempo::first = time (NULL);
169 tiempo::second = time (NULL);
170 double diferencia = difftime (tiempo::second,tiempo::first);
171 printf ("Total time for %f Bytes is %f (%f Bytes/s)\n", tiempo::bytes, diferencia, tiempo::bytes/diferencia);
174 static int VTK_SIZE(vtkImageData* img)
177 img->GetDimensions(dims);
178 int tamanio = VTK_SIZE_T(img->GetScalarType());
179 std::cout << "[" << dims[0] << "x" << dims[1] << "x" << dims[2] << "x" << tamanio << "]" << std::endl;
180 return dims[0]*dims[1]*dims[2]*tamanio;
182 static int VTK_SIZE_T(int tipo)
189 case VTK_UNSIGNED_CHAR:
190 return sizeof(unsigned char);
193 return sizeof(short);
195 case VTK_UNSIGNED_SHORT:
196 return sizeof(unsigned short);
201 case VTK_UNSIGNED_INT:
202 return sizeof(unsigned int);
207 case VTK_UNSIGNED_LONG:
208 return sizeof(unsigned long);
211 return sizeof(float);
214 return sizeof(double);
226 std::string kind(int*);
227 std::string is(int*, bool withkind=false);
228 std::string kind(double* a);
229 std::string is(double* a, bool withkind=false);
230 std::string kind(float* a);
231 std::string is(float* a, bool withkind=false);
232 std::string kind(char* a);
233 std::string is(char* a, bool withkind=false);
234 std::string kind(long* a);
235 std::string is(long* a, bool withkind=false);
236 std::string kind(short* a);
237 std::string is(short* a, bool withkind=false);
238 std::string kind(bool* a);
239 std::string is(bool* a, bool withkind=false);
240 std::string kind(void* a);
241 std::string is(void* a, bool withkind=false);
243 std::string kind(unsigned int* a);
244 std::string is(unsigned int* a, bool withkind=false);
245 std::string kind(unsigned char* a);
246 std::string is(unsigned char* a, bool withkind=false);
247 std::string kind(unsigned long* a);
248 std::string is(unsigned long* a, bool withkind=false);
249 std::string kind(unsigned short* a);
250 std::string is(unsigned short* a, bool withkind=false);
251 std::string kind(__int64* a);
252 std::string is(__int64* a, bool withkind=false);
253 std::string kind(unsigned __int64* a);
254 std::string is(unsigned __int64* a, bool withkind=false);
255 std::string kind(long double* a);
256 std::string is(long double* a, bool withkind=false);
258 std::string kind(int a);
259 std::string is(int a, bool withkind=false);
260 std::string kind(double a);
261 std::string is(double a, bool withkind=false);
262 std::string kind(float a);
263 std::string is(float a, bool withkind=false);
264 std::string kind(short a);
265 std::string is(short a, bool withkind=false);
266 std::string kind(char a);
267 std::string is(char a, bool withkind=false);
268 std::string kind(long a);
269 std::string is(long a, bool withkind=false);
270 std::string kind(bool a);
271 std::string is(bool a, bool withkind=false);
272 std::string kind(unsigned int a);
273 std::string is(unsigned int a, bool withkind=false);
274 std::string kind(unsigned char a);
275 std::string is(unsigned char a, bool withkind=false);
276 std::string kind(unsigned long a);
277 std::string is(unsigned long a, bool withkind=false);
278 std::string kind(unsigned short a);
279 std::string is(unsigned short a, bool withkind=false);
280 std::string kind(__int64 a);
281 std::string is(__int64 a, bool withkind=false);
282 std::string kind(unsigned __int64 a);
283 std::string is(unsigned __int64 a, bool withkind=false);
284 std::string kind(long double a);
285 std::string is(long double a, bool withkind=false);
287 std::string kind(std::vector<int> a);
288 std::string is(std::vector<int> a, bool withkind=false);
289 std::string kind(std::vector<double> a);
290 std::string is(std::vector<double> a, bool withkind=false);
291 std::string kind(std::vector<float> a);
292 std::string is(std::vector<float> a, bool withkind=false);
293 std::string kind(std::vector<short> a);
294 std::string is(std::vector<short> a, bool withkind=false);
295 std::string kind(std::vector<char> a);
296 std::string is(std::vector<char> a, bool withkind=false);
297 std::string kind(std::vector<long> a);
298 std::string is(std::vector<long> a, bool withkind=false);
299 std::string kind(std::vector<bool> a);
300 std::string is(std::vector<bool> a, bool withkind=false);
301 std::string kind(std::vector<__int64> a);
302 std::string is(std::vector<__int64> a, bool withkind=false);
303 std::string kind(std::vector<unsigned int> a);
304 std::string is(std::vector<unsigned int> a, bool withkind=false);
305 std::string kind(std::vector<unsigned char> a);
306 std::string is(std::vector<unsigned char> a, bool withkind=false);
307 std::string kind(std::vector<unsigned long> a);
308 std::string is(std::vector<unsigned long> a, bool withkind=false);
309 std::string kind(std::vector<unsigned short> a);
310 std::string is(std::vector<unsigned short> a, bool withkind=false);
311 std::string kind(std::vector<long double> a);
312 std::string is(std::vector<long double> a, bool withkind=false);
314 std::string is(double* a,int len=1, bool withkind=false);
315 std::string is(int* a,int len=1, bool withkind=false);
316 std::string is(float* a,int len=1, bool withkind=false);
317 std::string is(char* a,int len=1, bool withkind=false);
325 bool writeFile(std::string stm, std::string content);
326 std::string readFile(std::string stm);
333 void out(std::string texto);
341 el texto debe ser de la forma [12,45.6] y retorna un vector con la informacion esperada
343 std::vector<double> stringTovector(std::string, std::string start="[", std::string end="]");
345 Ayuda a parsear una linea de texto que contiene numeros
347 std::vector<double> stringTovectorDelimited(std::string, std::string);
349 std::string vectorToStringDelimited(std::vector<double> a, std::string delim);
350 std::vector<double*> stringToVectorArray(std::string);
352 StringSplit toma str y lo parte por el delimitador delim y retorna el vector de partes
354 std::vector<std::string> StringSplit(std::string, std::string);
356 Lo mismo que stringTovector, pero retornando un arreglo en vez de un vector
358 double* stringToArray(std::string);
359 std::string getInnerInfo(std::string);
360 // std::vector<double*> stringToVectorArray(std::string);
366 //Recorre el vector de manera ciclica
367 double vectorInfinite(std::vector<double> in, int index);
373 void bubble(std::vector<double> &array);
378 #endif // _BBTKSIMPLEUTILITIES_H_