Sim-LIT  2.0
 All Classes Namespaces Files Functions Variables Typedefs
DataBlock.h
Go to the documentation of this file.
1 
9 #ifndef CLASS_DATABLOCK
10 #define CLASS_DATABLOCK
11 
12 #include <iostream>
13 #include <vector>
14 #include "DataType.h"
15 #include "Pixel.h"
16 
17  using namespace std;
18 
19 class DataBlock: public DataType{
20 
21  vector<Pixel> block;
22  int width;
23  int height;
24  int amount_channels;
25 
26 public:
27 
28  DataBlock(vector<Pixel> nBlock, int w, int h, int nAmount){
37  block = nBlock;
38  width = w;
39  height = h;
40  amount_channels = nAmount;
41  this->setValid(true);
42  }
43 
44  DataBlock(int nAmount, vector<int> chns, int w, int h){
53  width = w;
54  height = h;
55  for (int i = 0; i < width*height; i=i+1)
56  {
57  Pixel aux(chns,nAmount);
58  block.push_back(aux);
59  }
60  this->setValid(true);
61  }
62 
67  width=1;
68  height=1;
69  amount_channels=0;
70  this->setValid(false);
71  }
72 
73  ~DataBlock(){}
74 
75  double getSize(){
76  /*
77  * @brief Método que devuelve el tamaño del Elemento
78  * @return result
79  */
80  double result = 0;
81  for (int i = 0; i < (width*height); i=i+1)
82  {
83  result+= block[i].getSize();
84  }
85  return result;
86  }
87 
88  int* getContent(){
93  int* array = (int*)malloc(sizeof(int)*3);
94  if(this->isValid()){
95  array[0]=0;
96  }
97  else{
98  array[0]=1;
99  }
100  array[1]=height;
101  array[2]=width;
102  /*for (int i = 0; i < (width*height); i++)
103  {
104  for (int j = 0; j < amount_channels; j++)
105  {
106  array[3+(i*amount_channels)+j]=block[i].getChannels()[j];
107  }
108  }*/
109  return array;
110  }
111 
117  int local_max = 0;
118  for (int i = 0; i < (width*height); ++i)
119  {
120  local_max = local_max + block[i].getIntensity();
121  }
122 
123  local_max = (int)(local_max/(width*height));
124  return local_max;
125  }
126 
127  void setAmountChannels(int aChannels){
131  amount_channels = aChannels;
132  for(int i=0;i<(height*width);i++){
133  block[i].setAmountChannels(amount_channels);
134  }
135  }
136 
137  void setChannels(vector<int> nChannels){
141  for(int i=0;i<(height*width);i++){
142  block[i].setChannels(nChannels);
143  }
144  }
145 
146  void* getExtras(){
150  return (void*)&block;
151  }
152 
153 };
154 
155 #endif
Clase que representa un Bloque de Píxeles.
Definition: DataBlock.h:19
int getIntensity()
Definition: DataBlock.h:112
Clase que representa un tipo de dato que será paquetizado.
Definition: DataType.h:18
int * getContent()
Definition: DataBlock.h:88
DataBlock(vector< Pixel > nBlock, int w, int h, int nAmount)
Definition: DataBlock.h:28
void setAmountChannels(int aChannels)
Definition: DataBlock.h:127
void * getExtras()
Definition: DataBlock.h:146
DataBlock()
Definition: DataBlock.h:63
void setChannels(vector< int > nChannels)
Definition: DataBlock.h:137
DataBlock(int nAmount, vector< int > chns, int w, int h)
Definition: DataBlock.h:44
Clase que representa un Pixel de una imagen.
Definition: Pixel.h:17