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_
32 #include "vtkVersion.h"
36 #include <vtkImageData.h>
69 void init(int x, int y, int z)
71 //Se pregunta al OS el tamanio de la palabra de un apuntador
72 int palabra = sizeof(T);
73 db = vtkImageData::New();
74 db->SetDimensions(x,y,z);
75 db->SetOrigin(0, 0, 0);
77 //EED 2017-01-01 Migration VTK7
78 #if (VTK_MAJOR_VERSION <= 5)
79 db->SetScalarType(Memcache::darTipo(palabra));
80 db->AllocateScalars();
83 #if (VTK_MAJOR_VERSION >= 6)
84 db->AllocateScalars(Memcache::darTipo(palabra),1);
89 void* get(int x, int y, int z)
91 T* apap = (T*)db->GetScalarPointer(x,y,z);
92 void* ap = (void*)*apap;
96 void* pop(int x, int y, int z)
98 T* apap = (T*)db->GetScalarPointer(x,y,z);
99 void* ap = (void*)*apap;
104 void put(int x, int y, int z, void* apt)
106 T* punto = (T*)db->GetScalarPointer(x,y,z);
114 for (int i=ext[0]; i<=ext[1]; i++)
116 for (int j=ext[2]; j<=ext[3]; j++)
118 for (int k=ext[4]; k<=ext[5]; k++)
120 ap1 = (T*)db->GetScalarPointer(i,j,k);
126 static int darTipo(int tamanio)
128 if (tamanio == sizeof(char))
130 if (tamanio == sizeof(unsigned char))
131 return VTK_UNSIGNED_CHAR;
132 if (tamanio == sizeof(short))
134 if (tamanio == sizeof(unsigned short))
135 return VTK_UNSIGNED_SHORT;
136 if (tamanio == sizeof(int))
138 if (tamanio == sizeof(unsigned int))
139 return VTK_UNSIGNED_INT;
140 if (tamanio == sizeof(long))
142 if (tamanio == sizeof(unsigned long))
143 return VTK_UNSIGNED_LONG;
144 if (tamanio == sizeof(float))
146 if (tamanio == sizeof(double))
157 static time_t first, second;
159 static void tic(vtkImageData* img)
161 tiempo::bytes = VTK_SIZE(img);
162 tiempo::first = time (NULL);
164 static void tic(int bytes_=0)
166 tiempo::bytes = bytes_;
167 tiempo::first = time (NULL);
172 tiempo::second = time (NULL);
173 double diferencia = difftime (tiempo::second,tiempo::first);
174 printf ("Total time for %f Bytes is %f (%f Bytes/s)\n", tiempo::bytes, diferencia, tiempo::bytes/diferencia);
177 static int VTK_SIZE(vtkImageData* img)
180 img->GetDimensions(dims);
181 int tamanio = VTK_SIZE_T(img->GetScalarType());
182 std::cout << "[" << dims[0] << "x" << dims[1] << "x" << dims[2] << "x" << tamanio << "]" << std::endl;
183 return dims[0]*dims[1]*dims[2]*tamanio;
185 static int VTK_SIZE_T(int tipo)
192 case VTK_UNSIGNED_CHAR:
193 return sizeof(unsigned char);
196 return sizeof(short);
198 case VTK_UNSIGNED_SHORT:
199 return sizeof(unsigned short);
204 case VTK_UNSIGNED_INT:
205 return sizeof(unsigned int);
210 case VTK_UNSIGNED_LONG:
211 return sizeof(unsigned long);
214 return sizeof(float);
217 return sizeof(double);
229 std::string kind(int*);
230 std::string is(int*, bool withkind=false);
231 std::string kind(double* a);
232 std::string is(double* a, bool withkind=false);
233 std::string kind(float* a);
234 std::string is(float* a, bool withkind=false);
235 std::string kind(char* a);
236 std::string is(char* a, bool withkind=false);
237 std::string kind(long* a);
238 std::string is(long* a, bool withkind=false);
239 std::string kind(short* a);
240 std::string is(short* a, bool withkind=false);
241 std::string kind(bool* a);
242 std::string is(bool* a, bool withkind=false);
243 std::string kind(void* a);
244 std::string is(void* a, bool withkind=false);
246 std::string kind(unsigned int* a);
247 std::string is(unsigned int* a, bool withkind=false);
248 std::string kind(unsigned char* a);
249 std::string is(unsigned char* a, bool withkind=false);
250 std::string kind(unsigned long* a);
251 std::string is(unsigned long* a, bool withkind=false);
252 std::string kind(unsigned short* a);
253 std::string is(unsigned short* a, bool withkind=false);
254 std::string kind(__int64* a);
255 std::string is(__int64* a, bool withkind=false);
256 std::string kind(unsigned __int64* a);
257 std::string is(unsigned __int64* a, bool withkind=false);
258 std::string kind(long double* a);
259 std::string is(long double* a, bool withkind=false);
261 std::string kind(int a);
262 std::string is(int a, bool withkind=false);
263 std::string kind(double a);
264 std::string is(double a, bool withkind=false);
265 std::string kind(float a);
266 std::string is(float a, bool withkind=false);
267 std::string kind(short a);
268 std::string is(short a, bool withkind=false);
269 std::string kind(char a);
270 std::string is(char a, bool withkind=false);
271 std::string kind(long a);
272 std::string is(long a, bool withkind=false);
273 std::string kind(bool a);
274 std::string is(bool a, bool withkind=false);
275 std::string kind(unsigned int a);
276 std::string is(unsigned int a, bool withkind=false);
277 std::string kind(unsigned char a);
278 std::string is(unsigned char a, bool withkind=false);
279 std::string kind(unsigned long a);
280 std::string is(unsigned long a, bool withkind=false);
281 std::string kind(unsigned short a);
282 std::string is(unsigned short a, bool withkind=false);
283 std::string kind(__int64 a);
284 std::string is(__int64 a, bool withkind=false);
285 std::string kind(unsigned __int64 a);
286 std::string is(unsigned __int64 a, bool withkind=false);
287 std::string kind(long double a);
288 std::string is(long double a, bool withkind=false);
290 std::string kind(std::vector<int> a);
291 std::string is(std::vector<int> a, bool withkind=false);
292 std::string kind(std::vector<double> a);
293 std::string is(std::vector<double> a, bool withkind=false);
294 std::string kind(std::vector<float> a);
295 std::string is(std::vector<float> a, bool withkind=false);
296 std::string kind(std::vector<short> a);
297 std::string is(std::vector<short> a, bool withkind=false);
298 std::string kind(std::vector<char> a);
299 std::string is(std::vector<char> a, bool withkind=false);
300 std::string kind(std::vector<long> a);
301 std::string is(std::vector<long> a, bool withkind=false);
302 std::string kind(std::vector<bool> a);
303 std::string is(std::vector<bool> a, bool withkind=false);
304 std::string kind(std::vector<__int64> a);
305 std::string is(std::vector<__int64> a, bool withkind=false);
306 std::string kind(std::vector<unsigned int> a);
307 std::string is(std::vector<unsigned int> a, bool withkind=false);
308 std::string kind(std::vector<unsigned char> a);
309 std::string is(std::vector<unsigned char> a, bool withkind=false);
310 std::string kind(std::vector<unsigned long> a);
311 std::string is(std::vector<unsigned long> a, bool withkind=false);
312 std::string kind(std::vector<unsigned short> a);
313 std::string is(std::vector<unsigned short> a, bool withkind=false);
314 std::string kind(std::vector<long double> a);
315 std::string is(std::vector<long double> a, bool withkind=false);
317 std::string is(double* a,int len=1, bool withkind=false);
318 std::string is(int* a,int len=1, bool withkind=false);
319 std::string is(float* a,int len=1, bool withkind=false);
320 std::string is(char* a,int len=1, bool withkind=false);
328 bool writeFile(std::string stm, std::string content);
329 std::string readFile(std::string stm);
336 void out(std::string texto);
344 el texto debe ser de la forma [12,45.6] y retorna un vector con la informacion esperada
346 std::vector<double> stringTovector(std::string, std::string start="[", std::string end="]");
348 Ayuda a parsear una linea de texto que contiene numeros
350 std::vector<double> stringTovectorDelimited(std::string, std::string);
352 std::string vectorToStringDelimited(std::vector<double> a, std::string delim);
353 std::vector<double*> stringToVectorArray(std::string);
355 StringSplit toma str y lo parte por el delimitador delim y retorna el vector de partes
357 std::vector<std::string> StringSplit(std::string, std::string);
359 Lo mismo que stringTovector, pero retornando un arreglo en vez de un vector
361 double* stringToArray(std::string);
362 std::string getInnerInfo(std::string);
363 // std::vector<double*> stringToVectorArray(std::string);
369 //Recorre el vector de manera ciclica
370 double vectorInfinite(std::vector<double> in, int index);
376 void bubble(std::vector<double> &array);
381 #endif // _BBTKSIMPLEUTILITIES_H_