1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
| package info;
//import info.Cadre1.*;
import java.awt.*;
import java.awt.image.*;
import javax.swing.table.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import info.Cadre1.*;
import info.FiltreSobel.*;
import info.AvancementEvent.*;
import java.util.Vector;
public class Snake extends FiltreAvancement{
Point tab_point[]=new Point[100];
Point tab_vois[]=new Point[100];
public void greedy(int Xs,int Ys,int taille_filtre,int Nb_Point,double Rayon,int criter_arret,float p_s,float coef_eng_cont,float coef_eng_cour,float coef_eng_bal,float coef_eng_gra,int seuil) {
int Nb_vois=taille_filtre*taille_filtre;
float energ_cont[]=new float[1000];
float ener_cour[]=new float[1000];
int ener_grad[][]=new int[1000][1000];
float ener_ballon[]=new float[1000];
float ener_total[]=new float[1000];
//BufferedImage imagee[];
File b1[]=null;
int im=0;
int w = Cadre1.imageF[0].getWidth(null);
int h = Cadre1.imageF[0].getHeight(null);
//imagee=new BufferedImage [100];
Object [][]col=new Object[100][100];
//String[] titreColonnes = { "Image","nb iteration", "Temps execution La Methode1"};
//table.jTable1 = new JTable(col,titreColonnes);
File fr=new File("Resultat Snake");
if(fr.exists())
{
b1=fr.listFiles();
for(int i=0;i < b1.length ;i++)
{
b1[i].delete();
}//fr.delete();
}
//
else fr.mkdir();
im=0;{
//Calendar now = Calendar.getInstance();
//int mm = now.get(Calendar.MINUTE);
//int hh = now.get(Calendar.SECOND);
//int ss = now.get(Calendar.MILLISECOND);
///////////////////////////////////////////////////////////////////////////////////////////
FiltreSobel s = new FiltreSobel();
s.filtrerImage(Cadre1.image[0],true,seuil);
for (int i = 0; i <Cadre1.image[im].getWidth(null); i++) {
for (int j = 0; j < Cadre1.image[im].getHeight(null); j++) {
ener_grad[i][j] =s.pf[i][j];
}
}
//////////////Normalisation de gradient/////////////////////////////////////////////////////
/* int w = Cadre1.imagee[im].getWidth(null);
int h = Cadre1.imageFiltre_sobel[im].getHeight(null);*/
int min_ene_grd = minimum1(ener_grad, w, h);
int max_ene_grd = calcMaximum1(ener_grad, w, h);
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
ener_grad[i][j] = (ener_grad[i][j] - min_ene_grd)/(max_ene_grd - min_ene_grd);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
int i, v;
Graphics g = ContourActif.paneauImage[im].getGraphics();
double alpha = 2 * (Math.PI) / Nb_Point;
for (int nb = 0; nb < Nb_Point; nb++) {
tab_point[nb] = new Point( (int) (Xs - Math.sin(alpha * (nb)) * Rayon),(int) (Ys - Math.cos(alpha * (nb)) * Rayon));
}
boolean check=ContourActif.jCheckBox2.isSelected();
if(check)
{
for (int nb = 0; nb < Nb_Point; nb++) {
//if (nb % 2 == 0)
//{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.RED.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.RED.getRGB());
}//}
//else
/*{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.RED.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.RED.getRGB());
}}*/
}
g.drawImage(Cadre1.imageF[im], 0, 0, null);}
////////////////////////////debut algo greedy1111111111111/////////////////////////////////////////////////////////////////////////////////////
int iteration = 0;
int nb1;int ps=0;
while (iteration < criter_arret && ps<p_s/100) {
ps=0;
for (nb1 = 0; nb1 < Nb_Point; nb1++) {
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb1, taille_filtre);
/* for (int nb=0; nb<taille_filtre*taille_filtre; nb++) {
System.out.println("vois"+tab_vois[nb1]);
}*/
// System.out.println("////////////////////////////////////////////////");
///////////////////////////////distance moyenne///////////////////////////////////////////////////////////////////////////////////
double D_M = 0;
int indexD, point, point_1;
double d_m = 0;
for (indexD = 0; indexD < Nb_Point; indexD++) {
if (indexD == Nb_Point - 1) {
point = Nb_Point - 1;
point_1 = 0;
}
else {
point = indexD;
point_1 = indexD + 1;
}
d_m = d_m +Math.sqrt(Math.pow( (tab_point[point].x -tab_point[point_1].x), 2) +Math.pow( (tab_point[point].y -tab_point[point_1].y), 2));
}
d_m = d_m / Nb_Point;
/////////////////////////////////////Calcul des energies/////////////////////////////////////////////////////////////////////////
//////////////////////////////////energie de continuite///////////////////////////////////////////////////////////////////////////
for (v = 0; v < taille_filtre * taille_filtre; v++) {
int point_AR; //int d=taille*taille;
if (nb1 == 0) {
point_AR = Nb_Point - 1;
}
else {
if (nb1 == Nb_Point - 1) {
point_AR = nb1 - 1;
}
else {
point_AR = nb1 - 1;
}
}
//**** 0.5 (distance moyenne -la racine de [(Xi-Xi-1)2 + (Yi-Yi-1)]) *********
energ_cont[v] = (float) (0.5 *Math.abs(d_m -(Math.sqrt(Math.pow( (tab_point[point_AR].x - tab_vois[v].x), 2) +Math.pow( (tab_point[point_AR].y - tab_vois[v].y), 2)))));
//System.out.println("energie continuite"+" "+energ_cont[v]);
///////////////////// ///////////////////////energie courbure///////////////////////////////////////////////////////////////////////
int point_AV;
if (nb1 == 0) {
point_AR = Nb_Point - 1;
point_AV = nb1 + 1;
}
else {
if (nb1 == Nb_Point - 1) {
point_AR = nb1 - 1;
point_AV = 0;
}
else {
if (nb1 == Nb_Point - 2) {
point_AR = nb1 - 1;
point_AV = nb1 + 1;
}
else {
if (nb1 == 1) {
point_AR = nb1 - 1;
point_AV = nb1 + 1;
}
else {
point_AR = nb1 - 1;
point_AV = nb1 + 1;
}
}
}
}
//****0.5[(Xi-1 -2Xi +Xi+1) + (Yi-1 -2Yi +Yi+1)]****
ener_cour[v] = (float) (0.5 *(Math.pow( (tab_point[point_AR].x -2 * (tab_vois[v].x) + tab_point[point_AV].x), 2) +Math.pow(tab_point[point_AR].y -2 * tab_vois[v].y +tab_point[point_AV].y, 2)));
//System.out.println("energie courbure"+" "+ener_cour[v]);
//////////////////////////////////////////energie de ballon////////////////////////////////////////////////////////////////////////
ener_ballon[v] = (tab_vois[v].x - Xs) *(tab_vois[v].x - tab_point[nb1].x) +(tab_vois[v].y - Ys) * (tab_vois[v].y - tab_point[nb1].y);
//System.out.println("energie ballon"+" "+ener_ballon[v]);?????????????????????
} //vois
//System.out.println("//////////////////////////");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////Normalisation des energies/////////////////////////
float min_eng_cont = minimum(energ_cont,taille_filtre * taille_filtre);
float max_eng_cont = calcMaximum(energ_cont);
float min_eng_cour = minimum(ener_cour,taille_filtre * taille_filtre);
float max_eng_cour = calcMaximum(ener_cour);
float min_eng_bal = minimum(ener_ballon,taille_filtre * taille_filtre);
float max_eng_bal = calcMaximum(ener_ballon);
for (v = 0; v < taille_filtre * taille_filtre; v++) {
energ_cont[v] = ( (energ_cont[v] - min_eng_cont) /(max_eng_cont - min_eng_cont));
ener_cour[v] = (ener_cour[v] - min_eng_cour) /(max_eng_cour - min_eng_cour);
ener_ballon[v] = (ener_ballon[v] - min_eng_bal) /(max_eng_bal - min_eng_bal);
//ener_total[v] = (coef_eng_cont * energ_cont[v]) +(coef_eng_cour * ener_cour[v]) +( (coef_eng_bal) * ener_ballon[v]) +(coef_eng_gra * ener_grad[tab_vois[v].x][tab_vois[v].y]);
}
///////////////////////////////////////////////////////////////////////
for (int v1 = 0; v1 < taille_filtre * taille_filtre; v1++) {
ener_total[v1] = (coef_eng_cont * energ_cont[v1]) +(coef_eng_cour * ener_cour[v1]) +( (coef_eng_bal) * ener_ballon[v1]) +(coef_eng_gra * ener_grad[tab_vois[v1].x][tab_vois[v1].y]);
}
int min = minimum2(ener_total, taille_filtre * taille_filtre);
int r = (tab_vois[min].x);
int f = (tab_vois[min].y);
if (r ==tab_point[nb1].x && f ==tab_point[nb1].y ) {
ps=ps+1;
}else tab_point[nb1] = new Point(r, f);
} //nb1
ps=ps/Nb_Point;
check=ContourActif.jCheckBox1.isSelected();
if(check)
{
for (int nb = 0; nb < Nb_Point; nb++)
{
if (nb % 2 == 0)
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.red.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.red.getRGB());
}}
else
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.GREEN.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.GREEN.getRGB());
}}
}
g.drawImage(Cadre1.imageF[im], 0, 0, null);}
else
{
if(ps >=p_s/100 || iteration==criter_arret-1)
{
for (int nb = 0; nb < Nb_Point; nb++)
{
if (nb % 2 == 0)
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.red.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.red.getRGB());
}}
else
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.GREEN.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.GREEN.getRGB());
}}}}
g.drawImage(Cadre1.imageF[im], 0, 0, null);}
iteration++;
} //iteration
table.jTable1.setValueAt(im,im,0);
table.jTable1.setValueAt(iteration,im,1);
Calendar dateDepart = Calendar.getInstance();
int m = dateDepart.get (Calendar.MINUTE);
int h1 = dateDepart.get(Calendar.SECOND);
int s1 = dateDepart.get(Calendar.MILLISECOND);
//String tims=Integer.toString(s1-ss);
//String timh=Integer.toString(h1-hh);
//String timm=Integer.toString(m-mm);
//table.jTable1.setValueAt(timm+"M"+" - "+timh+"S"+" - "+tims+"MS",im,2);
Enregistrement e=new Enregistrement();
File t=new File("Resultat methode1\\"+"image"+im+".png");
e.enregistrer(1,Cadre1.imageF[im],t);
}//tr2ai_image0
int sumX=0,sumY=0;
for (int i = 0; i < Nb_Point; i++)
{
sumX=sumX+tab_point[i].x;
sumY=sumY+tab_point[i].y;
}
//Xs=sumX/Nb_Point;
//Ys=sumY/Nb_Point;
/*for ( im = 1; im < (Cadre1.b.length)-1; im++)
{
Calendar now = Calendar.getInstance();
int mm = now.get(Calendar.MINUTE);
int hh = now.get(Calendar.SECOND);
int ss = now.get(Calendar.MILLISECOND);
//imagee[im] = Cadre1.imageF[im];
FiltreSobel s=new FiltreSobel();
s.filtrerImage(Cadre1.imageF[im],true,seuil);
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
ener_grad[i][j] = s.pf[i][j];
//System.out.print(ener_grad1[i][j]);
}}
//////////////Normalisation de gradient/////////////////////////////////////////////////////
int min_ene_grd = minimum1(ener_grad, w, h);
int max_ene_grd = calcMaximum1(ener_grad, w, h);
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
ener_grad[i][j] = (ener_grad[i][j] - min_ene_grd) /
(max_ene_grd - min_ene_grd);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
int i, v;
Graphics g1 = Cadre1.panneauImage[im].getGraphics();
double alpha = 2 * (Math.PI) / Nb_Point;
for (int nb = 0; nb < Nb_Point; nb++) {
tab_point[nb] = new Point( (int) (Xs - Math.sin(alpha * (nb)) * Rayon),(int) (Ys - Math.cos(alpha * (nb)) * Rayon));
}
boolean check=ContourActif.jCheckBox2.isSelected();
if(check && im!=0)
{
for (int nb = 0; nb < Nb_Point; nb++) {
if (nb % 2 == 0)
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.BLUE.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.BLUE.getRGB());
}}
else
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.BLUE.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.BLUE.getRGB());
}}
}
g1.drawImage(Cadre1.imageF[im], 0, 0, null);}
////////////////////////////debut algo greedy22222/////////////////////////////////////////////////////////////////////////////////////
/*int iteration = 0;int nb1, ps=0;
while (iteration < criter_arret && ps < p_s/100) {
ps=0;
for (nb1 = 0; nb1 < Nb_Point; nb1++) {
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb1, taille_filtre);
/* for (int nb=0; nb<taille_filtre*taille_filtre; nb++) {
System.out.println("vois"+tab_vois[nb1]);
}*/
// System.out.println("////////////////////////////////////////////////");
///////////////////////////////distance moyenne///////////////////////////////////////////////////////////////////////////////////
/*double D_M = 0;
int indexD, point, point_1;
double d_m = 0;
for (indexD = 0; indexD < Nb_Point; indexD++) {
if (indexD == Nb_Point - 1) {
point = Nb_Point - 1;
point_1 = 0;
}
else {
point = indexD;
point_1 = indexD + 1;
}
d_m = d_m +
Math.sqrt(Math.pow( (tab_point[point].x-tab_point[point_1].x), 2) +Math.pow( (tab_point[point].y -tab_point[point_1].y), 2));
}
d_m = d_m / Nb_Point;
/////////////////////////////////////Calcul des energies/////////////////////////////////////////////////////////////////////////
//////////////////////////////////energie de continuite///////////////////////////////////////////////////////////////////////////
for (v = 0; v < taille_filtre * taille_filtre; v++) {
int point_AR;
if (nb1 == 0) {
point_AR = Nb_Point - 1;
}
else {
if (nb1 == Nb_Point - 1) {
point_AR = nb1 - 1;
}
else {
point_AR = nb1 - 1;
}
}
//**** 0.5 (distance moyenne -la racine de [(Xi-Xi-1)2 + (Yi-Yi-1)]) *********
energ_cont[v] = (float) (0.5 *Math.abs(d_m -(Math.sqrt(Math.pow( (tab_point[point_AR].x - tab_vois[v].x), 2) +Math.pow( (tab_point[point_AR].y - tab_vois[v].y), 2)))));
//System.out.println("energie continuite"+" "+energ_cont[v]);
///////////////////// ///////////////////////energie courbure///////////////////////////////////////////////////////////////////////
int point_AV;
if (nb1 == 0) {
point_AR = Nb_Point - 1;
point_AV = nb1 + 1;
}
else {
if (nb1 == Nb_Point - 1) {
point_AR = nb1 - 1;
point_AV = 0;
}
else {
if (nb1 == Nb_Point - 2) {
point_AR = nb1 - 1;
point_AV = nb1 + 1;
}
else {
if (nb1 == 1) {
point_AR = nb1 - 1;
point_AV = nb1 + 1;
}
else {
point_AR = nb1 - 1;
point_AV = nb1 + 1;
}}}}
//****0.5[(Xi-1 -2Xi +Xi+1) + (Yi-1 -2Yi +Yi+1)]****
ener_cour[v] = (float) (0.5*(Math.pow((tab_point[point_AR].x -2*(tab_vois[v].x) + tab_point[point_AV].x), 2) +Math.pow(tab_point[point_AR].y -2 * tab_vois[v].y +tab_point[point_AV].y, 2)));
//System.out.println("energie courbure"+" "+ener_cour[v]);
//////////////////////////////////////////energie de ballon////////////////////////////////////////////////////////////////////////
ener_ballon[v] = (tab_vois[v].x - Xs) *(tab_vois[v].x - tab_point[nb1].x) +(tab_vois[v].y - Ys) * (tab_vois[v].y - tab_point[nb1].y);
//System.out.println("energie ballon"+" "+ener_ballon[v]);
} //vois
//System.out.println("//////////////////////////");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////Normalisation des energies/////////////////////////
float min_eng_cont = minimum(energ_cont,taille_filtre * taille_filtre);
float max_eng_cont = calcMaximum(energ_cont);
float min_eng_cour = minimum(ener_cour,taille_filtre * taille_filtre);
float max_eng_cour = calcMaximum(ener_cour);
float min_eng_bal = minimum(ener_ballon,taille_filtre * taille_filtre);
float max_eng_bal = calcMaximum(ener_ballon);
for (v = 0; v < taille_filtre * taille_filtre; v++) {
energ_cont[v] = ( (energ_cont[v] - min_eng_cont) /(max_eng_cont - min_eng_cont));
ener_cour[v] = (ener_cour[v] - min_eng_cour) /(max_eng_cour - min_eng_cour);
ener_ballon[v] = (ener_ballon[v] - min_eng_bal) /(max_eng_bal - min_eng_bal);
ener_total[v] = (coef_eng_cont * energ_cont[v]) +(coef_eng_cour * ener_cour[v]) +( (coef_eng_bal) * ener_ballon[v]) +(coef_eng_gra * ener_grad[tab_vois[v].x][tab_vois[v].y]);
}
///////////////////////////////////////////////////////////////////////
int min = minimum2(ener_total, taille_filtre * taille_filtre);
int r = (tab_vois[min].x);
int f = (tab_vois[min].y);
if (r ==tab_point[nb1].x && f ==tab_point[nb1].y ) {
ps=ps+1;
}else
{
if(r!=0 && f!=0 && r!=w && f!=h)
tab_point[nb1] = new Point(r, f);}
} //nb1
ps=ps/Nb_Point;
check=ContourActif.jCheckBox1.isSelected();
if(check)
{
for (int nb = 0; nb < Nb_Point; nb++)
{
if (nb % 2 == 0)
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.red.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.red.getRGB());
}}
else
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.GREEN.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.GREEN.getRGB());
}}
}
g1.drawImage(Cadre1.imageF[im], 0, 0, null);}
else
{
if(ps >=p_s/100 || iteration==criter_arret-1)
{
for (int nb = 0; nb < Nb_Point; nb++)
{
if (nb % 2 == 0)
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.red.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.red.getRGB());
}}
else
{
Cadre1.imageF[im].setRGB(tab_point[nb].x, tab_point[nb].y,Color.GREEN.getRGB());
tab_vois=new Point[Nb_vois+1];
tab_vois = voisinage(nb, 3);
for (v = 0; v < 9; v++) {
Cadre1.imageF[im].setRGB(tab_vois[v].x, tab_vois[v].y,Color.GREEN.getRGB());
}}}}
g1.drawImage(Cadre1.imageF[im], 0, 0, null);}
iteration++;
} //iteration*/
//table.jTable1.setValueAt(im,im,0);
//table.jTable1.setValueAt(iteration,im,1);
//Calendar dateDepart = Calendar.getInstance();
//int m = dateDepart.get (Calendar.MINUTE);
//int h1 = dateDepart.get(Calendar.SECOND);
//int s1 = dateDepart.get(Calendar.MILLISECOND);
//String tims=Integer.toString(s1-ss);
//String timh=Integer.toString(h1-hh);
//String timm=Integer.toString(m-mm);
//table.jTable1.setValueAt(timm+"M"+" - "+timh+"S"+" - "+tims+"MS",im,2);
// sumX=0;sumY=0;
//for ( i = 0; i < Nb_Point; i++)
//{
//sumX=sumX+tab_point[i].x;
//sumY=sumY+tab_point[i].y;
//}
//Xs=sumX/Nb_Point;
//Ys=sumY/Nb_Point;
//Cadre1.imagee[im]=imagee[im];
/*Enregistrement e=new Enregistrement();
File t=new File("Resultat methode1\\"+"image"+im+".png");
e.enregistrer(1,Cadre1.imageF[im],t);
} trai_image*/
}//fin void snake
/////////////////////////////// METHODE POUR INITIALISATION///////
public void initialise(int Nb_point,int xc,int yc,int R)
{Point tab_vois[]=new Point[9];
Graphics g1 = Cadre1.panneauImage[0].getGraphics();
double alpha = 2 * (Math.PI) / Nb_point;
for (int nb = 0; nb < Nb_point; nb++) {
tab_point[nb] = new Point( (int) (xc - Math.sin(alpha * (nb)) * R),(int) (yc - Math.cos(alpha * (nb)) * R));
}
for (int nb = 0; nb < Nb_point; nb++) {
if (nb % 2 == 0)
{
Cadre1.imageF[0].setRGB(tab_point[nb].x, tab_point[nb].y,Color.BLUE.getRGB());
tab_vois = voisinage(nb, 3);
for (int v = 0; v < 9; v++) {
Cadre1.imageF[0].setRGB(tab_vois[v].x, tab_vois[v].y,Color.BLUE.getRGB());
}}
else
{
Cadre1.imageF[0].setRGB(tab_point[nb].x, tab_point[nb].y,Color.BLUE.getRGB());
tab_vois = voisinage(nb, 3);
for (int v = 0; v < 9; v++) {
Cadre1.imageF[0].setRGB(tab_vois[v].x, tab_vois[v].y,Color.BLUE.getRGB());
}}
}
g1.drawImage(Cadre1.imageF[0], 0, 0, null);
}//////////////////////
/*public void TempsExecution()
{
table cadre2;
boolean packFrame = false;
cadre2=new table ();
if (packFrame) {
cadre2.pack();
}
else {cadre2.validate(); }
//Centrer la fentre
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = cadre2.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
cadre2.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
cadre2.setVisible(true);
}*/
public Point []voisinage(int point,int ta){//////METHODE DE VOISINAGE
int bix,biy,bsx,bsy,j,v = 0;
bix = tab_point[point].x -(int)(ta/2);
bsx = tab_point[point].x +(int) (ta/2) ;
Point tab_v[]=new Point[100];
biy = tab_point[point].y - (int)(ta/2);
bsy = tab_point[point].y +(int)(ta/2);
for(int i = bix ; i <= bsx ; i++)
{
for(j = biy ; j <= bsy ; j++)
{
tab_v[v]=new Point(i,j);v++;
}}return tab_v;}
/////////////////////////////////////////////METHODE PR CALCUL MAX
float calcMaximum(float mesnombres[])
{float maxvaleur = 0;
for (int ii = 0; ii < mesnombres.length; ii++)
{if (mesnombres[ii] > maxvaleur){maxvaleur = mesnombres[ii];}
}return maxvaleur;}
//////////////////////////////////////////////////////////////METHODE PR CALCUL MIN------------------------------------------------------
float minimum(float[] t,int taille) {
float minvaleur =t[0];
for (int i = 0; i < taille; i++)
{
if (t[i]<minvaleur){minvaleur = t[i];}
}return minvaleur;}
//////////////////////////////////////////////////////////////
int minimum2(float[] t,int taille) {
int indice=taille/2;;
float minvaleur =t[indice];
for (int i = 0; i < taille; i++)
{
if (t[i]<minvaleur){minvaleur = t[i];indice=i;}
}return indice;}
//////////////////////////////////////////////MAX DE MATRICE////////////////
int calcMaximum1(int mesnombres[][],int w,int h)
{int maxvaleur = 0;
for (int ii = 0; ii < w; ii++)
{ for (int jj = 0; jj < h; jj++)
{if (mesnombres[ii][jj] > maxvaleur){maxvaleur = mesnombres[ii][jj];}
}}return maxvaleur;}
///////////////////////////////MIN DE MAT///////////////////////////////
int minimum1(int[][] t,int taille,int taille1) {
int minvaleur =t[0][0];
for (int i = 0; i < taille; i++)
{for (int j = 0; j < taille1; j++){
if (t[i][j]<minvaleur){minvaleur = t[i][j];}
}}return minvaleur;}
//////////////////////////////////////////////////////////////
}//fin classe snake |
Partager