Sim-LIT  2.0
 All Classes Namespaces Files Functions Variables Typedefs
main_b.cpp
1 
9 #include "header.h"
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 #include <cstring>
14 #include <cstdio>
15 #include <algorithm>
16 
17 
18 using namespace std;
19 
20 //Variables requeridas para que el sistema funcione
21 string url;
22 int amount_forward_processing;
23 
24 vector<ForwardProcessing*> forward_processing;
25 
26 
27  int main(int argc, char const *argv[])
28  {
29  if(argc<7){//No se cumple con la cantidad mínima de argumentos necesarios para el funcionamiento del Software
30  cout << "This tools required minimum six parameters to work\n"
31  << "-URL of Picture\n"
32  << "-Forward Processing Methods\n"
33  << "-Type of Packetizer\n"
34  << "-Size of Packages\n"
35  << "-Channel of Simulation\n"
36  << "-Rebuilder Methods\n";
37  return 0;
38  }
39  Images img(argv[1]);
40  img.save("images/img_readed.bmp");
41  /*
42  list contains the elements of images
43  */
44  vector<DataType *> list = img.toList();
45  string fm = argv[2];
46  int i=0;
47  if(!fm.compare(FORWARD_METHOD)){
48  amount_forward_processing=stoi(argv[3]);
49  int x=1;
50  i=4;
51  while(x<=amount_forward_processing){
52  int nArguments = stoi(argv[i+1]);
53  int args[nArguments];
54  for(int c=1;c<=nArguments;c++){
55  args[c-1]=stoi(argv[i+1+c]);
56  }
57  string fpname = argv[i];
58  ForwardProcessing* fp = ForwardProcessingCreator::create(fpname);
59  if(fp==NULL){
60  cout << "The Forward Processing Method are not created\n";
61  return 0;
62  }
63  int result = fp->make(&list,img.getWidth(),img.getHeight(),args,nArguments);
64  if(result==0){
65  forward_processing.push_back(fp);
66  Images mixed(list,img.getType(),img.getWidth(),img.getHeight());
67  replace( fpname.begin(), fpname.end(), '-', '_');
68  string saved = "images/img_mixed" + fpname+ ".bmp";
69  mixed.save(saved.c_str());
70  }
71  else{
72  if(result==1){
73  cout << "The numbers of Parameters are not valid\n";
74  }
75  if(result==2){
76  cout << "The Image need be squared (WxH)\n";
77  }
78  if(result==5){
79  cout << "the byteOffset or the packetOffset need be mayor than 0\n";
80  }
81  }
82  x=x+1;
83  i=i+nArguments+2;
84  }
85 
86  }
87  Packetizer* p = NULL;
88  vector<Package> pkgs;
89  if(i<argc){
90  string pkgname = argv[i];
91  p = PacketizerCreator::create(pkgname);
92  if(p!=NULL){
93  pkgs = p->imgToPackageList(list,stoi(argv[i+1]));//Tamaño de cada Paquete
94  cout << "N-PACKAGES: " << pkgs.size() << "\n";
95  }
96  else{
97  cout << "Packetizer are not created\n";
98  return 0;
99  }
100  }
101  else{
102  cout << "Packetizer are not defined\n";
103  return 0;
104  }
105  i=i+2;
106  RandomGenerator::generate(4,pkgs.size());//4000 Paquetes que se perderán
107 
108 
109 
110  vector<Package> rcved = Channel::lossFromFile("files/loss_random.loss", pkgs);
111  cout << "N-PACKAGES-RECEIVED: " << rcved.size() << "\n";
112  vector <DataType *> pkgs_rcved = p->packageListToImg(rcved);
113  Images rbefore(pkgs_rcved,img.getType(),img.getWidth(),img.getHeight());
114  rbefore.save("images/img_received_before_unmixed.bmp");
115 
116  for(int j=forward_processing.size()-1;j>=0;j--){
117  forward_processing[j]->unmake(&pkgs_rcved);
118  }
119 
120  Images received(pkgs_rcved,img.getType(),img.getWidth(),img.getHeight());
121  received.save("images/img_received.bmp");
122 
123 
124  if((i+1)<argc){
125  string rbd = argv[i];
126  if(rbd.compare(REBUILDER_METHOD)){
127  cout << "Rebuilder Method has not defined\n";
128  return 0;
129  }
130  rbd = argv[i+1];
131  Rebuilder* rbdr = RebuilderCreator::create(rbd);
132  if(rbdr!=NULL){
133  rbdr->hidden(&received);
134  received.save("images/img_received_rebuilded.bmp");
135  }
136  else{
137  cout << "Rebuilder isn't created\n";
138  return 0;
139  }
140  }
141  else{
142  cout << "Not Exists Rebuilder Method\n";
143  return 0;
144  }
145  i=i+2;
146  MetricPsnr* metric = new MetricPsnr();
147  cout << "PSNR: " << metric->calculate(img,received) << "\n";
148 
149  return 0;
150  }
Clase abstracta que representa la estructura que debe tener todo procesamiento de imagen...
Clase que representa una Imagen.
Definition: Images.h:22
Clase que define la estructuras que debe tener el paquetizador.
Definition: Packetizer.h:16
Clase que representa la Métrica PSNR.
Definition: MetricPsnr.h:15
Clase Abstracta que indica la forma que debe tener todo método de Ocultamiento de errores en Imágenes...
Definition: Rebuilder.h:15