1 #ifndef _BBTKSIMPLEUTILITIES_H_
2 #define _BBTKSIMPLEUTILITIES_H_
6 #include <vtkImageData.h>
39 void init(int x, int y, int z)
41 //Se pregunta al OS el tamanio de la palabra de un apuntador
42 int palabra = sizeof(T);
43 db = vtkImageData::New();
44 db->SetScalarType(Memcache::darTipo(palabra));
45 db->SetDimensions(x,y,z);
46 db->SetOrigin(0, 0, 0);
47 db->AllocateScalars();
50 void* get(int x, int y, int z)
52 T* apap = (T*)db->GetScalarPointer(x,y,z);
53 void* ap = (void*)*apap;
57 void* pop(int x, int y, int z)
59 T* apap = (T*)db->GetScalarPointer(x,y,z);
60 void* ap = (void*)*apap;
65 void put(int x, int y, int z, void* apt)
67 T* punto = (T*)db->GetScalarPointer(x,y,z);
75 for (int i=ext[0]; i<=ext[1]; i++)
77 for (int j=ext[2]; j<=ext[3]; j++)
79 for (int k=ext[4]; k<=ext[5]; k++)
81 ap1 = (T*)db->GetScalarPointer(i,j,k);
87 static int darTipo(int tamanio)
89 if (tamanio == sizeof(char))
91 if (tamanio == sizeof(unsigned char))
92 return VTK_UNSIGNED_CHAR;
93 if (tamanio == sizeof(short))
95 if (tamanio == sizeof(unsigned short))
96 return VTK_UNSIGNED_SHORT;
97 if (tamanio == sizeof(int))
99 if (tamanio == sizeof(unsigned int))
100 return VTK_UNSIGNED_INT;
101 if (tamanio == sizeof(long))
103 if (tamanio == sizeof(unsigned long))
104 return VTK_UNSIGNED_LONG;
105 if (tamanio == sizeof(float))
107 if (tamanio == sizeof(double))
118 static time_t first, second;
120 static void tic(vtkImageData* img)
122 tiempo::bytes = VTK_SIZE(img);
123 tiempo::first = time (NULL);
125 static void tic(int bytes_=0)
127 tiempo::bytes = bytes_;
128 tiempo::first = time (NULL);
133 tiempo::second = time (NULL);
134 double diferencia = difftime (tiempo::second,tiempo::first);
135 printf ("Total time for %f Bytes is %f (%f Bytes/s)\n", tiempo::bytes, diferencia, tiempo::bytes/diferencia);
138 static int VTK_SIZE(vtkImageData* img)
141 img->GetDimensions(dims);
142 int tamanio = VTK_SIZE_T(img->GetScalarType());
143 std::cout << "[" << dims[0] << "x" << dims[1] << "x" << dims[2] << "x" << tamanio << "]" << std::endl;
144 return dims[0]*dims[1]*dims[2]*tamanio;
146 static int VTK_SIZE_T(int tipo)
153 case VTK_UNSIGNED_CHAR:
154 return sizeof(unsigned char);
157 return sizeof(short);
159 case VTK_UNSIGNED_SHORT:
160 return sizeof(unsigned short);
165 case VTK_UNSIGNED_INT:
166 return sizeof(unsigned int);
171 case VTK_UNSIGNED_LONG:
172 return sizeof(unsigned long);
175 return sizeof(float);
178 return sizeof(double);
190 std::string kind(int*);
191 std::string is(int*, bool withkind=false);
192 std::string kind(double* a);
193 std::string is(double* a, bool withkind=false);
194 std::string kind(float* a);
195 std::string is(float* a, bool withkind=false);
196 std::string kind(char* a);
197 std::string is(char* a, bool withkind=false);
198 std::string kind(long* a);
199 std::string is(long* a, bool withkind=false);
200 std::string kind(short* a);
201 std::string is(short* a, bool withkind=false);
202 std::string kind(bool* a);
203 std::string is(bool* a, bool withkind=false);
204 std::string kind(void* a);
205 std::string is(void* a, bool withkind=false);
207 std::string kind(unsigned int* a);
208 std::string is(unsigned int* a, bool withkind=false);
209 std::string kind(unsigned char* a);
210 std::string is(unsigned char* a, bool withkind=false);
211 std::string kind(unsigned long* a);
212 std::string is(unsigned long* a, bool withkind=false);
213 std::string kind(unsigned short* a);
214 std::string is(unsigned short* a, bool withkind=false);
215 std::string kind(__int64* a);
216 std::string is(__int64* a, bool withkind=false);
217 std::string kind(unsigned __int64* a);
218 std::string is(unsigned __int64* a, bool withkind=false);
219 std::string kind(long double* a);
220 std::string is(long double* a, bool withkind=false);
222 std::string kind(int a);
223 std::string is(int a, bool withkind=false);
224 std::string kind(double a);
225 std::string is(double a, bool withkind=false);
226 std::string kind(float a);
227 std::string is(float a, bool withkind=false);
228 std::string kind(short a);
229 std::string is(short a, bool withkind=false);
230 std::string kind(char a);
231 std::string is(char a, bool withkind=false);
232 std::string kind(long a);
233 std::string is(long a, bool withkind=false);
234 std::string kind(bool a);
235 std::string is(bool a, bool withkind=false);
236 std::string kind(unsigned int a);
237 std::string is(unsigned int a, bool withkind=false);
238 std::string kind(unsigned char a);
239 std::string is(unsigned char a, bool withkind=false);
240 std::string kind(unsigned long a);
241 std::string is(unsigned long a, bool withkind=false);
242 std::string kind(unsigned short a);
243 std::string is(unsigned short a, bool withkind=false);
244 std::string kind(__int64 a);
245 std::string is(__int64 a, bool withkind=false);
246 std::string kind(unsigned __int64 a);
247 std::string is(unsigned __int64 a, bool withkind=false);
248 std::string kind(long double a);
249 std::string is(long double a, bool withkind=false);
251 std::string kind(std::vector<int> a);
252 std::string is(std::vector<int> a, bool withkind=false);
253 std::string kind(std::vector<double> a);
254 std::string is(std::vector<double> a, bool withkind=false);
255 std::string kind(std::vector<float> a);
256 std::string is(std::vector<float> a, bool withkind=false);
257 std::string kind(std::vector<short> a);
258 std::string is(std::vector<short> a, bool withkind=false);
259 std::string kind(std::vector<char> a);
260 std::string is(std::vector<char> a, bool withkind=false);
261 std::string kind(std::vector<long> a);
262 std::string is(std::vector<long> a, bool withkind=false);
263 std::string kind(std::vector<bool> a);
264 std::string is(std::vector<bool> a, bool withkind=false);
265 std::string kind(std::vector<__int64> a);
266 std::string is(std::vector<__int64> a, bool withkind=false);
267 std::string kind(std::vector<unsigned int> a);
268 std::string is(std::vector<unsigned int> a, bool withkind=false);
269 std::string kind(std::vector<unsigned char> a);
270 std::string is(std::vector<unsigned char> a, bool withkind=false);
271 std::string kind(std::vector<unsigned long> a);
272 std::string is(std::vector<unsigned long> a, bool withkind=false);
273 std::string kind(std::vector<unsigned short> a);
274 std::string is(std::vector<unsigned short> a, bool withkind=false);
275 std::string kind(std::vector<long double> a);
276 std::string is(std::vector<long double> a, bool withkind=false);
278 std::string is(double* a,int len=1, bool withkind=false);
279 std::string is(int* a,int len=1, bool withkind=false);
280 std::string is(float* a,int len=1, bool withkind=false);
281 std::string is(char* a,int len=1, bool withkind=false);
289 bool writeFile(std::string stm, std::string content);
290 std::string readFile(std::string stm);
297 void out(std::string texto);
305 el texto debe ser de la forma [12,45.6] y retorna un vector con la informacion esperada
307 std::vector<double> stringTovector(std::string, std::string start="[", std::string end="]");
309 Ayuda a parsear una linea de texto que contiene numeros
311 std::vector<double> stringTovectorDelimited(std::string, std::string);
313 std::string vectorToStringDelimited(std::vector<double> a, std::string delim);
314 std::vector<double*> stringToVectorArray(std::string);
316 StringSplit toma str y lo parte por el delimitador delim y retorna el vector de partes
318 std::vector<std::string> StringSplit(std::string, std::string);
320 Lo mismo que stringTovector, pero retornando un arreglo en vez de un vector
322 double* stringToArray(std::string);
323 std::string getInnerInfo(std::string);
324 // std::vector<double*> stringToVectorArray(std::string);
330 //Recorre el vector de manera ciclica
331 double vectorInfinite(std::vector<double> in, int index);
337 void bubble(std::vector<double> &array);