]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorreyes <reyes>
Thu, 16 Jun 2011 12:28:38 +0000 (12:28 +0000)
committerreyes <reyes>
Thu, 16 Jun 2011 12:28:38 +0000 (12:28 +0000)
packages/vtk/src/bbtkSimpleUtilities.cxx [new file with mode: 0644]
packages/vtk/src/bbtkSimpleUtilities.h [new file with mode: 0755]
packages/vtk/src/bbtkStaticLecture.cxx [new file with mode: 0755]
packages/vtk/src/bbtkStaticLecture.h [new file with mode: 0755]
packages/vtk/src/names.cxx [new file with mode: 0755]
packages/vtk/src/names.h [new file with mode: 0755]

diff --git a/packages/vtk/src/bbtkSimpleUtilities.cxx b/packages/vtk/src/bbtkSimpleUtilities.cxx
new file mode 100644 (file)
index 0000000..549a56a
--- /dev/null
@@ -0,0 +1,369 @@
+
+#include "bbtkSimpleUtilities.h"
+#define LOG_FILE_NAME "log.txt"
+
+namespace bbtk
+{
+
+
+//template <typename T>
+
+
+
+
+
+/*
+namespace what
+{
+           std::string kind(int*);
+           std::string is(int*, bool withkind=false);
+           std::string kind(double* a);
+           std::string is(double* a, bool withkind=false);
+           std::string kind(float* a);
+           std::string is(float* a, bool withkind=false);
+           std::string kind(char* a);
+           std::string is(char* a, bool withkind=false);
+           std::string kind(long* a);
+           std::string is(long* a, bool withkind=false);
+           std::string kind(short* a);
+           std::string is(short* a, bool withkind=false);
+           std::string kind(bool* a);
+           std::string is(bool* a, bool withkind=false);
+           std::string kind(void* a);
+           std::string is(void* a, bool withkind=false);
+
+           std::string kind(unsigned int* a);
+           std::string is(unsigned int* a, bool withkind=false);
+           std::string kind(unsigned char* a);
+           std::string is(unsigned char* a, bool withkind=false);
+           std::string kind(unsigned long* a);
+           std::string is(unsigned long* a, bool withkind=false);
+           std::string kind(unsigned short* a);
+           std::string is(unsigned short* a, bool withkind=false);
+           std::string kind(__int64* a);
+           std::string is(__int64* a, bool withkind=false);
+           std::string kind(unsigned __int64* a);
+           std::string is(unsigned __int64* a, bool withkind=false);
+           std::string kind(long double* a);
+           std::string is(long double* a, bool withkind=false);
+
+           std::string kind(int a);
+           std::string is(int a, bool withkind=false);
+           std::string kind(double a);
+           std::string is(double a, bool withkind=false);
+           std::string kind(float a);
+           std::string is(float a, bool withkind=false);
+           std::string kind(short a);
+           std::string is(short a, bool withkind=false);
+           std::string kind(char a);
+           std::string is(char a, bool withkind=false);
+           std::string kind(long a);
+           std::string is(long a, bool withkind=false);
+           std::string kind(bool a);
+           std::string is(bool a, bool withkind=false);
+           std::string kind(unsigned int a);
+           std::string is(unsigned int a, bool withkind=false);
+           std::string kind(unsigned char a);
+           std::string is(unsigned char a, bool withkind=false);
+           std::string kind(unsigned long a);
+           std::string is(unsigned long a, bool withkind=false);
+           std::string kind(unsigned short a);
+           std::string is(unsigned short a, bool withkind=false);
+           std::string kind(__int64 a);
+           std::string is(__int64 a, bool withkind=false);
+           std::string kind(unsigned __int64 a);
+           std::string is(unsigned __int64 a, bool withkind=false);
+           std::string kind(long double a);
+           std::string is(long double a, bool withkind=false);
+
+           std::string kind(std::vector<int> a);
+           std::string is(std::vector<int> a, bool withkind=false);
+           std::string kind(std::vector<double> a);
+           std::string is(std::vector<double> a, bool withkind=false);
+           std::string kind(std::vector<float> a);
+           std::string is(std::vector<float> a, bool withkind=false);
+           std::string kind(std::vector<short> a);
+           std::string is(std::vector<short> a, bool withkind=false);
+           std::string kind(std::vector<char> a);
+           std::string is(std::vector<char> a, bool withkind=false);
+           std::string kind(std::vector<long> a);
+           std::string is(std::vector<long> a, bool withkind=false);
+           std::string kind(std::vector<bool> a);
+           std::string is(std::vector<bool> a, bool withkind=false);
+           std::string kind(std::vector<__int64> a);
+           std::string is(std::vector<__int64> a, bool withkind=false);
+           std::string kind(std::vector<unsigned int> a);
+           std::string is(std::vector<unsigned int> a, bool withkind=false);
+           std::string kind(std::vector<unsigned char> a);
+           std::string is(std::vector<unsigned char> a, bool withkind=false);
+           std::string kind(std::vector<unsigned long> a);
+           std::string is(std::vector<unsigned long> a, bool withkind=false);
+           std::string kind(std::vector<unsigned short> a);
+           std::string is(std::vector<unsigned short> a, bool withkind=false);
+           std::string kind(std::vector<long double> a);
+           std::string is(std::vector<long double> a, bool withkind=false);
+
+                  std::string is(double* a,int len=1, bool withkind=false);
+                  std::string is(int* a,int len=1, bool withkind=false);
+                  std::string is(float* a,int len=1, bool withkind=false);
+                  std::string is(char* a,int len=1, bool withkind=false);
+
+}
+*/
+
+
+
+       bool persistence::writeFile(std::string stm, std::string content)
+       {
+                       std::ofstream myfile (stm.c_str());
+                       if (myfile.is_open())
+                       {
+                               myfile << content;
+                               myfile.close();
+                               return true;
+                       }
+                       else
+                       {
+                               return false;
+                       }
+       }
+
+       std::string persistence::readFile(std::string path)
+       {
+               std::string line;
+               std::stringstream stm;
+               std::ifstream myfile (path.c_str());
+               if (myfile.is_open())
+               {
+                       while (! myfile.eof() )
+                       {
+                               getline (myfile,line);
+                               stm << line << std::endl;
+                       }
+                       myfile.close();
+               }
+               else
+               {
+
+               }
+               return stm.str();
+       }
+
+
+
+
+       std::string logging::fecha()
+       {
+               time_t seconds;
+               seconds = time (NULL);
+
+               //char timeStr [9];
+               std::stringstream out;
+                out << seconds;
+               std::string la_fecha = out.str();
+               //_strtime( timeStr );
+               //std::string la_fecha(timeStr);
+               return "["+la_fecha+"] ";
+       }
+
+       void logging::out(std::string texto)
+       {
+               std::ofstream outFile;
+               outFile.open(LOG_FILE_NAME, std::ios::app);
+               if (outFile)
+               {
+                       outFile << fecha() << texto << std::endl;
+               }
+       }
+
+       void logging::erase()
+       {
+               std::ofstream outFile;
+               outFile.open(LOG_FILE_NAME, std::ios::out);
+               if (outFile)
+               {
+                       outFile << fecha() << "INICIO" << std::endl;
+               }
+       }
+
+
+       std::vector<std::string> translate::StringSplit(std::string str, std::string delim)
+       {
+               std::vector<std::string> results;
+               int cutAt;
+               while( (cutAt = (int)str.find_first_of(delim)) != str.npos )
+               {
+                       if(cutAt > 0)
+                       {
+                               results.push_back(str.substr(0,cutAt));
+                       }
+                               str = str.substr(cutAt+1);
+                       }
+                       if(str.length() > 0)
+                       {
+                               results.push_back(str);
+                       }
+               return results;
+       }
+
+       std::vector<double> translate::stringTovector(std::string texto, std::string start, std::string end)
+       {
+               std::vector<double> el_vector;
+               std::vector<std::string> partes;
+
+
+               int inicial = (int)texto.find( start, 0 );
+               int final = (int)texto.find( end, 0 );
+
+               if (inicial == std::string::npos || final == std::string::npos)
+                       return el_vector;
+               if (final<=inicial)
+                       return el_vector;
+
+               std::string contenido = texto.substr(inicial+1, final-inicial-1);
+
+               partes = StringSplit(contenido, ",");
+               if (partes.size() != -1){
+                       for (int i=0; i<(int)partes.size(); i++)
+                       {
+                               if (partes.at(i).size() > 0)
+                               {
+                                       double uno = atof(partes.at(i).data());
+                                       el_vector.push_back(uno);
+                               }
+                       }
+               }
+               return el_vector;
+       }
+
+       std::vector<double> translate::stringTovectorDelimited(std::string texto, std::string delimitador)
+       {
+               std::vector<double> el_vector;
+               std::vector<std::string> partes;
+
+               std::string contenido = texto;
+
+               partes = StringSplit(contenido, delimitador);
+               if (partes.size() != -1){
+                       for (int i=0; i<(int)partes.size(); i++)
+                       {
+                               double uno = atof(partes.at(i).data());
+                               el_vector.push_back(uno);
+                       }
+               }
+               return el_vector;
+       }
+
+    double* translate::stringToArray(std::string texto)
+       {
+        std::vector<double> el_vector = stringTovector(texto);
+        double* array = new double[el_vector.size()];
+        for (int i=0; i<(int)el_vector.size(); i++)
+        {
+            array[i]=el_vector[i];
+        }
+               return array;
+       }
+
+       std::string translate::getInnerInfo(std::string texto)
+       {
+               int first_par = (int)texto.find("[", 0);
+               int last_par = (int)texto.rfind("]", texto.size());
+
+               return texto.substr(first_par+1,last_par-first_par-1);
+       }
+
+       std::vector<double*> translate::stringToVectorArray(std::string texto)
+       {
+               std::vector<double*> el_vector;
+               std::string innerInfo = getInnerInfo(texto);
+
+               int first_par = 0;
+               int last_par = 0;
+               int lastComma = 0;
+
+               while (lastComma != std::string::npos)
+               {
+                       first_par = (int)innerInfo.find("[", lastComma);
+                       last_par = (int)innerInfo.find("]", lastComma);
+                       lastComma = (int)innerInfo.find(",", last_par);
+                       if (first_par == std::string::npos || last_par == std::string::npos)
+                               break;
+                       std::string subArreglo = innerInfo.substr(first_par,last_par-first_par+1);
+                       double* subArray = stringToArray(subArreglo);
+                       el_vector.push_back(subArray);
+               }
+               return el_vector;
+       }
+
+       std::string translate::vectorToStringDelimited(std::vector<double> a, std::string delim)
+       {
+               std::stringstream out;
+
+        unsigned int i;
+        for (i = 0; i < a.size(); i++)
+        {
+            out << a.at(i);
+            if (i != a.size()-1)
+                out << delim;
+        }
+        return out.str();
+       }
+
+
+
+//Recorre el vector de manera ciclica
+double vectores::vectorInfinite(std::vector<double> in, int index)
+{
+    //std::cout << "index = " << index;
+    int value;
+       int tamanio = in.size();
+       bool inverso = false;
+       if (tamanio == 0)
+               return -1;
+
+       if (index < 0)
+       {
+               inverso = true;
+               index = abs(index);
+               value = tamanio - index%tamanio;
+               if (value == tamanio)
+                  value = 0;
+       }else{
+               value = index%tamanio;
+       }
+       //std::cout << ", value=" << value << std::endl;
+       //return 0;
+    return in.at(value);
+}
+
+
+
+       /**
+       Ordenamiento busbuja, array[0] es el maximo
+       http://mathbits.com/mathbits/compsci/Arrays/Bubble.htm
+       **/
+       void sorts::bubble(std::vector<double> &array)
+       {
+               double i, j, flag = 1;    // set flag to 1 to begin initial pass
+               double temp;             // holding variable
+               double arrayLength = array.size();
+               for(i = 1; (i <= arrayLength) && flag; i++)
+               {
+                       flag = 0;
+                       for (j=0; j < (arrayLength -1); j++)
+                       {
+                               if (array[(int)(j+1)] > array[(int)j])      // ascending order simply changes to <
+                               {
+                                               temp = array[(int)j];             // swap elements
+                                               array[(int)j] = array[(int)(j+1)];
+                                               array[(int)(j+1)] = temp;
+                                               flag = 1;               // indicates that a swap occurred.
+                               }
+                       }
+               }
+       }
+
+};
+
+
diff --git a/packages/vtk/src/bbtkSimpleUtilities.h b/packages/vtk/src/bbtkSimpleUtilities.h
new file mode 100755 (executable)
index 0000000..91d2d97
--- /dev/null
@@ -0,0 +1,342 @@
+#ifndef _BBTKSIMPLEUTILITIES_H_
+#define _BBTKSIMPLEUTILITIES_H_
+
+#include <time.h>
+#include <vtkType.h>
+#include <vtkImageData.h>
+#include <cstdlib>
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <string>
+#include <time.h>
+#include <fstream>
+
+
+
+namespace bbtk
+{
+
+
+
+template <typename T>
+class Memcache
+{
+public:
+       vtkImageData* db;
+
+       Memcache()
+       {
+               db = NULL;
+       }
+
+       ~Memcache()
+       {
+               if (db!=NULL)
+                       db->Delete();
+       }
+
+       void init(int x, int y, int z)
+       {
+               //Se pregunta al OS el tamanio de la palabra de un apuntador
+               int palabra = sizeof(T);
+               db = vtkImageData::New();
+               db->SetScalarType(Memcache::darTipo(palabra));
+               db->SetDimensions(x,y,z);
+               db->SetOrigin(0, 0, 0);
+               db->AllocateScalars();
+               db->Update();
+       }
+       void* get(int x, int y, int z)
+       {
+               T* apap = (T*)db->GetScalarPointer(x,y,z);
+               void* ap = (void*)*apap;
+               return ap;
+       }
+
+       void* pop(int x, int y, int z)
+       {
+               T* apap = (T*)db->GetScalarPointer(x,y,z);
+               void* ap = (void*)*apap;
+               *apap = NULL;
+               return ap;
+       }
+
+       void put(int x, int y, int z, void* apt)
+       {
+               T* punto = (T*)db->GetScalarPointer(x,y,z);
+               *punto = (T)apt;
+       }
+       void clear()
+       {
+               int ext[6];
+               db->GetExtent(ext);
+               T* ap1;
+               for (int i=ext[0]; i<=ext[1]; i++)
+               {
+                       for (int j=ext[2]; j<=ext[3]; j++)
+                       {
+                               for (int k=ext[4]; k<=ext[5]; k++)
+                               {
+                                       ap1 = (T*)db->GetScalarPointer(i,j,k);
+                                       *ap1 = NULL;
+                               }
+                       }
+               }
+       }
+       static int darTipo(int tamanio)
+       {
+               if (tamanio == sizeof(char))
+                       return VTK_CHAR;
+               if (tamanio == sizeof(unsigned char))
+                       return VTK_UNSIGNED_CHAR;
+               if (tamanio == sizeof(short))
+                       return VTK_SHORT;
+               if (tamanio == sizeof(unsigned short))
+                       return VTK_UNSIGNED_SHORT;
+               if (tamanio == sizeof(int))
+                       return VTK_INT;
+               if (tamanio == sizeof(unsigned int))
+                       return VTK_UNSIGNED_INT;
+               if (tamanio == sizeof(long))
+                       return VTK_LONG;
+               if (tamanio == sizeof(unsigned long))
+                       return VTK_UNSIGNED_LONG;
+               if (tamanio == sizeof(float))
+                       return VTK_FLOAT;
+               if (tamanio == sizeof(double))
+                       return VTK_DOUBLE;
+               return 0;
+       }
+
+};
+
+
+class tiempo
+{
+       public:
+       static time_t first, second;
+    static double bytes;
+static void tic(vtkImageData* img)
+       {
+               tiempo::bytes = VTK_SIZE(img);
+               tiempo::first = time (NULL);
+       }
+       static void tic(int bytes_=0)
+       {
+               tiempo::bytes = bytes_;
+               tiempo::first = time (NULL);
+       }
+
+       static void toc()
+       {
+               tiempo::second = time (NULL);
+               double diferencia = difftime (tiempo::second,tiempo::first);
+               printf ("Total time for %f Bytes is %f (%f Bytes/s)\n", tiempo::bytes, diferencia, tiempo::bytes/diferencia);
+       }
+
+       static int VTK_SIZE(vtkImageData* img)
+       {
+               int dims[3];
+               img->GetDimensions(dims);
+               int tamanio = VTK_SIZE_T(img->GetScalarType());
+               std::cout << "[" << dims[0] << "x" << dims[1] << "x" << dims[2] << "x" << tamanio << "]" << std::endl;
+               return dims[0]*dims[1]*dims[2]*tamanio;
+       }
+       static int VTK_SIZE_T(int tipo)
+       {
+               switch(tipo)
+               {
+                       case VTK_CHAR:
+                               return sizeof(char);
+                       break;
+                       case VTK_UNSIGNED_CHAR:
+                               return sizeof(unsigned char);
+                       break;
+                       case VTK_SHORT:
+                               return sizeof(short);
+                       break;
+                       case VTK_UNSIGNED_SHORT:
+                               return sizeof(unsigned short);
+                       break;
+                       case VTK_INT:
+                               return sizeof(int);
+                       break;
+                       case VTK_UNSIGNED_INT:
+                               return sizeof(unsigned int);
+                       break;
+                       case VTK_LONG:
+                               return sizeof(long);
+                       break;
+                       case VTK_UNSIGNED_LONG:
+                               return sizeof(unsigned long);
+                       break;
+                       case VTK_FLOAT:
+                               return sizeof(float);
+                       break;
+                       case VTK_DOUBLE:
+                               return sizeof(double);
+                       break;
+                       default:
+                               return 0;
+                       break;
+               }
+       }
+};
+
+/*
+namespace what
+{
+           std::string kind(int*);
+           std::string is(int*, bool withkind=false);
+           std::string kind(double* a);
+           std::string is(double* a, bool withkind=false);
+           std::string kind(float* a);
+           std::string is(float* a, bool withkind=false);
+           std::string kind(char* a);
+           std::string is(char* a, bool withkind=false);
+           std::string kind(long* a);
+           std::string is(long* a, bool withkind=false);
+           std::string kind(short* a);
+           std::string is(short* a, bool withkind=false);
+           std::string kind(bool* a);
+           std::string is(bool* a, bool withkind=false);
+           std::string kind(void* a);
+           std::string is(void* a, bool withkind=false);
+
+           std::string kind(unsigned int* a);
+           std::string is(unsigned int* a, bool withkind=false);
+           std::string kind(unsigned char* a);
+           std::string is(unsigned char* a, bool withkind=false);
+           std::string kind(unsigned long* a);
+           std::string is(unsigned long* a, bool withkind=false);
+           std::string kind(unsigned short* a);
+           std::string is(unsigned short* a, bool withkind=false);
+           std::string kind(__int64* a);
+           std::string is(__int64* a, bool withkind=false);
+           std::string kind(unsigned __int64* a);
+           std::string is(unsigned __int64* a, bool withkind=false);
+           std::string kind(long double* a);
+           std::string is(long double* a, bool withkind=false);
+
+           std::string kind(int a);
+           std::string is(int a, bool withkind=false);
+           std::string kind(double a);
+           std::string is(double a, bool withkind=false);
+           std::string kind(float a);
+           std::string is(float a, bool withkind=false);
+           std::string kind(short a);
+           std::string is(short a, bool withkind=false);
+           std::string kind(char a);
+           std::string is(char a, bool withkind=false);
+           std::string kind(long a);
+           std::string is(long a, bool withkind=false);
+           std::string kind(bool a);
+           std::string is(bool a, bool withkind=false);
+           std::string kind(unsigned int a);
+           std::string is(unsigned int a, bool withkind=false);
+           std::string kind(unsigned char a);
+           std::string is(unsigned char a, bool withkind=false);
+           std::string kind(unsigned long a);
+           std::string is(unsigned long a, bool withkind=false);
+           std::string kind(unsigned short a);
+           std::string is(unsigned short a, bool withkind=false);
+           std::string kind(__int64 a);
+           std::string is(__int64 a, bool withkind=false);
+           std::string kind(unsigned __int64 a);
+           std::string is(unsigned __int64 a, bool withkind=false);
+           std::string kind(long double a);
+           std::string is(long double a, bool withkind=false);
+
+           std::string kind(std::vector<int> a);
+           std::string is(std::vector<int> a, bool withkind=false);
+           std::string kind(std::vector<double> a);
+           std::string is(std::vector<double> a, bool withkind=false);
+           std::string kind(std::vector<float> a);
+           std::string is(std::vector<float> a, bool withkind=false);
+           std::string kind(std::vector<short> a);
+           std::string is(std::vector<short> a, bool withkind=false);
+           std::string kind(std::vector<char> a);
+           std::string is(std::vector<char> a, bool withkind=false);
+           std::string kind(std::vector<long> a);
+           std::string is(std::vector<long> a, bool withkind=false);
+           std::string kind(std::vector<bool> a);
+           std::string is(std::vector<bool> a, bool withkind=false);
+           std::string kind(std::vector<__int64> a);
+           std::string is(std::vector<__int64> a, bool withkind=false);
+           std::string kind(std::vector<unsigned int> a);
+           std::string is(std::vector<unsigned int> a, bool withkind=false);
+           std::string kind(std::vector<unsigned char> a);
+           std::string is(std::vector<unsigned char> a, bool withkind=false);
+           std::string kind(std::vector<unsigned long> a);
+           std::string is(std::vector<unsigned long> a, bool withkind=false);
+           std::string kind(std::vector<unsigned short> a);
+           std::string is(std::vector<unsigned short> a, bool withkind=false);
+           std::string kind(std::vector<long double> a);
+           std::string is(std::vector<long double> a, bool withkind=false);
+
+                  std::string is(double* a,int len=1, bool withkind=false);
+                  std::string is(int* a,int len=1, bool withkind=false);
+                  std::string is(float* a,int len=1, bool withkind=false);
+                  std::string is(char* a,int len=1, bool withkind=false);
+}
+
+*/
+
+class persistence
+{
+    public:
+       bool writeFile(std::string stm, std::string content);
+       std::string readFile(std::string stm);
+};
+
+class logging
+{
+    public:
+        std::string fecha();
+        void out(std::string texto);
+        void erase();
+};
+
+class translate
+{
+    public:
+       /**
+       el texto debe ser de la forma [12,45.6] y retorna un vector con la informacion esperada
+       **/
+        std::vector<double> stringTovector(std::string, std::string start="[", std::string end="]");
+        /**
+       Ayuda a parsear una linea de texto que contiene numeros
+        */
+        std::vector<double> stringTovectorDelimited(std::string, std::string);
+
+       std::string vectorToStringDelimited(std::vector<double> a, std::string delim);
+        std::vector<double*> stringToVectorArray(std::string);
+       /**
+       StringSplit toma str y lo parte por el delimitador delim y retorna el vector de partes
+       **/
+        std::vector<std::string> StringSplit(std::string, std::string);
+       /**
+       Lo mismo que stringTovector, pero retornando un arreglo en vez de un vector
+       **/
+        double* stringToArray(std::string);
+        std::string getInnerInfo(std::string);
+//      std::vector<double*> stringToVectorArray(std::string);
+};
+
+class vectores
+{
+    public:
+       //Recorre el vector de manera ciclica
+       double vectorInfinite(std::vector<double> in, int index);
+};
+
+class sorts
+{
+    public:
+        void bubble(std::vector<double> &array);
+};
+
+}
+
+#endif /* _DLL_H_ */
diff --git a/packages/vtk/src/bbtkStaticLecture.cxx b/packages/vtk/src/bbtkStaticLecture.cxx
new file mode 100755 (executable)
index 0000000..c1a9adc
--- /dev/null
@@ -0,0 +1,152 @@
+#include "bbtkStaticLecture.h"
+
+
+       void bbtkStaticLecture::setPixelValue(int i, int j, int k, vtkImageData* img, double value)
+       {
+               //double rta;
+               int scalar_type = img->GetScalarType();
+               int* ext = img->GetExtent();
+               if (i < ext[0])
+                       return;
+               if (i > ext[1])
+                       return;
+
+               if (j < ext[2])
+                       return;
+               if (j > ext[3])
+                       return;
+
+               if (k < ext[4])
+                       return;
+               if (k > ext[5])
+                       return;
+
+               switch (scalar_type)
+               {
+                       case VTK_CHAR:
+                               char * ap2;
+                               ap2 = (char *) img->GetScalarPointer(i,j,k);
+                               *ap2 = (char) value;
+                       break;
+                       case VTK_UNSIGNED_CHAR:
+                               unsigned char * ap3;
+                               ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
+                               *ap3 = (unsigned char) value;
+                       break;
+                       case VTK_SHORT:
+                               short * ap4;
+                               ap4 = (short *) img->GetScalarPointer(i,j,k);
+                               *ap4 = (short) value;
+                       break;
+                       case VTK_UNSIGNED_SHORT:
+                               unsigned short * ap5;
+                               ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
+                               *ap5 = (unsigned short) value;
+                       break;
+                       case VTK_INT:
+                               int * ap6;
+                               ap6 = (int *) img->GetScalarPointer(i,j,k);
+                               *ap6 = (int) value;
+                       break;
+                       case VTK_UNSIGNED_INT:
+                               unsigned int * ap7;
+                               ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
+                               *ap7 = (unsigned int) value;
+                       break;
+                       case VTK_LONG:
+                               long * ap8;
+                               ap8 = (long *) img->GetScalarPointer(i,j,k);
+                               *ap8 = (long) value;
+                       break;
+                       case VTK_UNSIGNED_LONG:
+                               unsigned long * ap9;
+                               ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
+                               *ap9 = (unsigned long) value;
+                       break;
+                       case VTK_FLOAT:
+                               float * ap10;
+                               ap10 = (float *) img->GetScalarPointer(i,j,k);
+                               *ap10 = (float) value;
+                       break;
+                       case VTK_DOUBLE:
+                               double * ap11;
+                               ap11 = (double *) img->GetScalarPointer(i,j,k);
+                               *ap11 = (double) value;
+                       break;
+               }
+       }
+       double bbtkStaticLecture::getPixelValue(int i, int j, int k, vtkImageData* img)
+       {
+               double rta;
+               int scalar_type = img->GetScalarType();
+               int* ext = img->GetExtent();
+               if (i < ext[0])
+                       i=ext[0];
+               if (i > ext[1])
+                       i=ext[1];
+
+               if (j < ext[2])
+                       j=ext[2];
+               if (j > ext[3])
+                       j=ext[3];
+
+               if (k < ext[4])
+                       k=ext[4];
+               if (k > ext[5])
+                       k=ext[5];
+
+               switch (scalar_type)
+               {
+                       case VTK_CHAR:
+                               char * ap2;
+                               ap2 = (char *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap2;
+                       break;
+                       case VTK_UNSIGNED_CHAR:
+                               unsigned char * ap3;
+                               ap3 = (unsigned char *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap3;
+                       break;
+                       case VTK_SHORT:
+                               short * ap4;
+                               ap4 = (short *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap4;
+                       break;
+                       case VTK_UNSIGNED_SHORT:
+                               unsigned short * ap5;
+                               ap5 = (unsigned short *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap5;
+                       break;
+                       case VTK_INT:
+                               int * ap6;
+                               ap6 = (int *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap6;
+                       break;
+                       case VTK_UNSIGNED_INT:
+                               unsigned int * ap7;
+                               ap7 = (unsigned int *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap7;
+                       break;
+                       case VTK_LONG:
+                               long * ap8;
+                               ap8 = (long *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap8;
+                       break;
+                       case VTK_UNSIGNED_LONG:
+                               unsigned long * ap9;
+                               ap9 = (unsigned long *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap9;
+                       break;
+                       case VTK_FLOAT:
+                               float * ap10;
+                               ap10 = (float *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap10;
+                       break;
+                       case VTK_DOUBLE:
+                               double * ap11;
+                               ap11 = (double *) img->GetScalarPointer(i,j,k);
+                               rta = (double) *ap11;
+                       break;
+               }
+               return rta;
+       }
diff --git a/packages/vtk/src/bbtkStaticLecture.h b/packages/vtk/src/bbtkStaticLecture.h
new file mode 100755 (executable)
index 0000000..1616921
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __bbtkStaticLecture__h__
+#define __bbtkStaticLecture__h__
+
+#include <vtkType.h>
+#include <vtkImageData.h>
+
+class bbtkStaticLecture
+{
+public:
+       void setPixelValue(int i, int j, int k, vtkImageData* img, double value);
+       double getPixelValue(int i, int j, int k, vtkImageData* img);
+};
+
+#endif
diff --git a/packages/vtk/src/names.cxx b/packages/vtk/src/names.cxx
new file mode 100755 (executable)
index 0000000..dfdb011
--- /dev/null
@@ -0,0 +1,193 @@
+#include "names.h"
+
+bool checknum(std::string s)
+{
+        std::istringstream iss(s);
+        std::ostringstream oss;
+        int x;
+        iss >> x;
+        oss << x;       
+        
+        if( s == oss.str())
+                return true;
+        
+        return false;
+}
+
+
+
+std::string StringClear(std::string in, std::vector<std::string> no)
+{
+  size_t found;
+  
+for (int i=0; i<no.size(); i++)
+{
+  std::string viejo = no.at(i);
+  found=in.find(viejo);
+  while (found!=std::string::npos)
+  {
+    //Mienstras halla
+    int inicio = int(found);
+    in.replace(found,viejo.length(),"");
+    found=in.find(viejo);
+  }
+}
+  return in;
+}
+
+std::string StringReplace(std::string in, std::string viejo, std::string nuevo)
+{
+  size_t found;
+
+  // different member versions of find in the same order as above:
+  found=in.find(viejo);
+  while (found!=std::string::npos)
+  {
+    //Mienstras halla
+    int inicio = int(found);
+    in.replace(found,viejo.length(),nuevo);
+    found=in.find(viejo);
+  }
+return in;
+}
+
+std::vector < std::string > StringSplit(std::string str, std::string delim)
+{
+       std::vector<std::string> results;
+       int cutAt;
+       while( (cutAt = (int)str.find_first_of(delim)) != str.npos )
+       {
+               if(cutAt > 0)
+               {
+                       results.push_back(str.substr(0,cutAt));
+               }
+                       str = str.substr(cutAt+1);
+               }
+               if(str.length() > 0)
+               {
+                       results.push_back(str);
+               }
+       return results;
+}
+
+std::string generateFileName(std::string input, int number, std::string prefix)
+{
+       //
+       int ceros = 6;
+       int position = input.find( "\\" ); // find first space 
+       while ( position != std::string::npos ) 
+       {
+               input.replace( position, 1, "/" );
+               position = input.find( "\\", position + 1 );
+       }
+       
+    bool comienza_con_slash = false;
+   
+    if (input.at(0) == '/')
+               comienza_con_slash = true;
+       //
+       std::vector< std::string > partes = StringSplit(input, "/");
+
+       std::stringstream number_str;
+       number_str << number;
+    std::string        number_str_texto = number_str.str();
+    
+    
+    int tamanio = number_str_texto.size();
+    int diferencia = ceros-tamanio;
+    for (int i=0; i<diferencia ; i++)
+        number_str_texto="0"+number_str_texto;
+
+       std::string rta = partes[0];
+
+       for (unsigned int i=1; i<partes.size(); i++)
+       {
+               if (i==partes.size()-1)
+               {
+                       std::vector<std::string> partes_punto;
+                       partes_punto = StringSplit(partes[i], ".");
+                       /*
+                       La extension es: partes_punto[partes_punto.size()-1]
+                       */
+                       std::string oldname = "";
+                       for (unsigned int h=0; h<partes_punto.size();h++)
+                       {
+                               oldname += partes_punto.at(h)+"_";
+                       }
+                       if (partes_punto.size() > 1)
+                               rta+="/"+prefix+"_"+oldname+"_"+number_str_texto+"."+partes_punto[partes_punto.size()-1];
+                       else
+                               rta+="/"+prefix+"_"+oldname+"_"+number_str_texto;
+               }
+               else
+               {
+                       rta+="/"+partes[i];
+               }
+       }
+       if (comienza_con_slash)
+               rta = "/"+rta;
+       return rta;
+}
+
+bool existFile(std::string myFileName)
+{
+       std::ifstream inp;
+inp.open(myFileName.c_str(), std::ifstream::in);
+inp.close();
+if (!inp.fail())
+{
+   return true;
+}else{
+   return false;
+}    
+}
+
+std::string guessName(std::string nombre)
+{
+   int iterador = 0;
+   int max_iter = 10000;
+   
+   while(iterador < max_iter)
+   {
+   std::string nuevo = generateFileName(nombre, iterador, "Data");
+   
+   if (existFile(nuevo))
+   {
+      iterador++;
+   }
+   else
+   {
+          std::cout << nuevo << std::endl;
+       return nuevo;
+   }
+   }
+   std::cout << nombre << std::endl;
+   return nombre;
+}
+
+std::string guessExistent(std::string nombre, int* actual, bool* hay)
+{
+       std::string nada = "";
+       if (actual == NULL || hay == NULL)
+               return nada;
+   int iterador = *actual;
+   int max_iter = 1000;
+   
+   while(iterador < max_iter)
+   {
+   std::string nuevo = generateFileName(nombre, iterador, "Data");
+   
+   if (existFile(nuevo))
+   {
+          *hay = true;
+          *actual = iterador;
+      return nuevo;
+   }
+   else
+   {
+          iterador++;
+   }
+   }
+   *hay = false;
+   return nada;
+}
diff --git a/packages/vtk/src/names.h b/packages/vtk/src/names.h
new file mode 100755 (executable)
index 0000000..c34a372
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <cstdlib>
+#include <iostream>
+#include <fstream>
+#include <time.h>
+#include <vector>
+#include <sstream>
+#include <math.h>
+
+#include <string>
+
+
+
+bool checknum(std::string s);
+
+std::string StringReplace(std::string in, std::string, std::string);
+
+/*
+Elimina todas las ocurrencias de las cadenas de texto
+*/
+std::string StringClear(std::string in, std::vector<std::string>);
+
+std::vector < std::string > StringSplit(std::string str, std::string delim);
+
+std::string generateFileName(std::string input, int number, std::string prefix);
+
+bool existFile(std::string myFileName);
+
+std::string guessName(std::string nombre);
+
+std::string guessExistent(std::string nombre, int* actual, bool* hay);