Projet

Général

Profil

Révision 7096d2f9

Ajouté par Jocelyn Dealande il y a plus de 9 ans

Refacto of Tiles handling and simplified a bit file naming for tiles/params.
By the way, fixes #297

THIS COMMIT BREAKS FILE LAYOUT AND REQUIRES MIGRATION (SEE BELLOW).

To migrate data :

cd tiles
find . '*.jpg' -exec rename 's/[^\/]*_(([0-9]{3}_){2}([0-9]{3}))/$1/' {} \;
rename 's/(.*\/).*\.params/$1site.params/' */*.params

Voir les différences:

js/pano.js
264 264
    putImage(last.x, last.y);
265 265
}
266 266

  
267
/** Returns a 3-width zero-padded version of an int
268
 * ex: 3 -> "003"
269
 */
270
function zero_pad(number) {
271
	var temp = number.toString(10);
272
	while (temp.length < 3) {
273
		temp = '0' + temp;
274
	}
275
	return temp;
276
}
277

  
267 278
function get_file_name(x, y, z) { // recherche du fichier correspondant au zoom et à la position
268
    var prm = [z, x, y];
269
    var fname = img_prefix;
270
    for (var i = 0; i < prm.length; i++) {
271
	fname += '_';
272
	if (prm[i] < 10) fname += '00';
273
	else if (prm[i] < 100) fname += '0';
274
	fname += prm[i];
275
    }
276
    fname += '.jpg';
277
    return fname;
279
	return img_prefix+'/'+zero_pad(z)+'_'+zero_pad(x)+'_'+zero_pad(y)+'.jpg';
278 280
}
279 281

  
280 282
function get_base_name() {
......
483 485
    this.is_updated = false;
484 486

  
485 487
    this.refresh = function() {
486
	this.im.visible_width = this.tile.width*(this.ntiles.x-1)+this.last_tile.width;
487
	this.is_updated = true;
488

  
489
	this.im.width = this.im.visible_width;
490
	this.im.height = this.tile.height*(this.ntiles.y-1)+this.last_tile.height;
491
	if (this.last_tile.width > this.tile.width) this.max_tile.width = this.im.last_tile.width;
492
	else this.max_tile.width = this.tile.width;
493
	if (this.last_tile.height > this.tile.height) this.max_tile.height = this.im.last_tile.height;
494
	else this.max_tile.height = this.tile.height;
495

  
496
	var ord_pts = new Array();
497
	i=0;
498
	for(var label in ref_points) {
499
	    ord_pts[i++] = ref_points[label]
500
	}
501
	ord_pts = ord_pts.sort(tri_ref_points);
502
	is_located = i > 1 || image_loop && i > 0;
488
	    this.im.visible_width = this.tile.width*(this.ntiles.x-1)+this.last_tile.width;
489
	    this.is_updated = true;
503 490

  
504
	var alpha_domain = {start:0, end:360};
505
	this.pixel_y_ratio = this.im.width/360;
506
	if (is_located) {
507
	    this.ref_pixels = new Array;
508
	    this.ref_pixels[0] = new Array();    // Attention il faut compter un intervalle de plus !
509
	    for (var i=0; i < ord_pts.length; i++) { // premier parcours pour les paramètres cap/x
510
		this.ref_pixels[i+1] = new Array();
511
		this.ref_pixels[i+1].x = Math.floor(ord_pts[i].x*this.im.width);
512
		this.ref_pixels[i+1].cap = fmodulo(ord_pts[i].cap, 360);
513
		if (i != ord_pts.length-1) {
514
		    this.ref_pixels[i+1].ratio_x = (ord_pts[i+1].x - ord_pts[i].x)/fmodulo(ord_pts[i+1].cap - ord_pts[i].cap, 360)*this.im.width;
515
		}
516
	    }
517
	    if (image_loop == true) {
518
		var dpix = this.im.width;
519
		var dangle = 360;
520
		if (ord_pts.length > 1) {
521
		    dpix = this.im.width - this.ref_pixels[this.ref_pixels.length-1].x + this.ref_pixels[1].x;
522
		    dangle = fmodulo(this.ref_pixels[1].cap - this.ref_pixels[this.ref_pixels.length-1].cap, 360);
523
		}
524
		this.ref_pixels[0].ratio_x = dpix/dangle;
525
		this.ref_pixels[ord_pts.length].ratio_x = this.ref_pixels[0].ratio_x;
526
		dpix = this.im.width - this.ref_pixels[ord_pts.length].x;
527
		this.ref_pixels[0].cap = fmodulo(this.ref_pixels[ord_pts.length].cap + dpix / this.ref_pixels[0].ratio_x, 360);
491
	    this.im.width = this.im.visible_width;
492
	    this.im.height = this.tile.height*(this.ntiles.y-1)+this.last_tile.height;
493
	    if (this.last_tile.width > this.tile.width) {
494
		    this.max_tile.width = this.im.last_tile.width;
528 495
	    } else {
529
		this.ref_pixels[0].ratio_x = this.ref_pixels[1].ratio_x;
530
		this.ref_pixels[ord_pts.length].ratio_x = this.ref_pixels[ord_pts.length-1].ratio_x;
531
		this.ref_pixels[0].cap = fmodulo(this.ref_pixels[1].cap - this.ref_pixels[1].x / this.ref_pixels[1].ratio_x, 360);
532
		alpha_domain.start = this.ref_pixels[0].cap;
533
		alpha_domain.end = fmodulo(this.ref_pixels[ord_pts.length].cap+(this.im.width-this.ref_pixels[ord_pts.length].x)/this.ref_pixels[ord_pts.length].ratio_x, 360);
534
		this.pixel_y_ratio = this.im.width/fmodulo(alpha_domain.end-alpha_domain.start, 360);
496
		    this.max_tile.width = this.tile.width;
535 497
	    }
536
	    this.ref_pixels[0].x = 0;
537

  
538
	    for (var i=0; i < ord_pts.length; i++) { // second parcours pour les paramètres elevation/y
539
		this.ref_pixels[i+1].shift_y = Math.floor(this.pixel_y_ratio*ord_pts[i].ele - ord_pts[i].y*this.im.height);
540
		if (i != ord_pts.length-1) {
541
		    var next_shift = Math.floor(this.pixel_y_ratio*ord_pts[i+1].ele - ord_pts[i+1].y*this.im.height);
542
		    this.ref_pixels[i+1].dshft_y = (next_shift - this.ref_pixels[i+1].shift_y)/(this.ref_pixels[i+2].x - this.ref_pixels[i+1].x);
543
		}
498
	    if (this.last_tile.height > this.tile.height) {
499
		    this.max_tile.height = this.im.last_tile.height;
500
	    } else {
501
		    this.max_tile.height = this.tile.height;
544 502
	    }
545 503

  
546
	    if (image_loop == true) {
547
		var dpix  = this.im.width;
548
		var delt = 0;
549
		if (ord_pts.length > 1) {
550
		    dpix  = this.im.width - this.ref_pixels[this.ref_pixels.length-1].x + this.ref_pixels[1].x;
551
		    delt = this.ref_pixels[this.ref_pixels.length-1].shift_y - this.ref_pixels[1].shift_y;
552
		}
553
		this.ref_pixels[0].dshft_y = -delt/dpix;
554
		this.ref_pixels[ord_pts.length].dshft_y = this.ref_pixels[0].dshft_y;
555
		dpix = this.im.width - this.ref_pixels[ord_pts.length].x;
556
		this.ref_pixels[0].shift_y = this.ref_pixels[ord_pts.length].shift_y + dpix*this.ref_pixels[0].dshft_y;
557
	    } else {
558
		this.ref_pixels[0].shift_y = this.ref_pixels[1].shift_y;
559
		this.ref_pixels[0].dshft_y = 0;
560
		this.ref_pixels[ord_pts.length].dshft_y = 0;
504
	    var ord_pts = new Array();
505
	    for(var label in ref_points) {
506
		    ord_pts.push(ref_points[label]);
561 507
	    }
508
	    ord_pts = ord_pts.sort(tri_ref_points);
509
	    is_located = i > 1 || image_loop && i > 0;
510

  
511
	    var alpha_domain = {start:0, end:360};
512
	    this.pixel_y_ratio = this.im.width/360;
513
	    if (is_located) {
514
		    this.ref_pixels = new Array;
515
		    this.ref_pixels[0] = new Array();    // Attention il faut compter un intervalle de plus !
516
		    for (var i=0; i < ord_pts.length; i++) { // premier parcours pour les paramètres cap/x
517
			    this.ref_pixels[i+1] = new Array();
518
			    this.ref_pixels[i+1].x = Math.floor(ord_pts[i].x*this.im.width);
519
			    this.ref_pixels[i+1].cap = fmodulo(ord_pts[i].cap, 360);
520
			    if (i != ord_pts.length-1) {
521
				    this.ref_pixels[i+1].ratio_x = (ord_pts[i+1].x - ord_pts[i].x) /
522
					    fmodulo(ord_pts[i+1].cap - ord_pts[i].cap, 360)*this.im.width;
523
			    }
524
		    }
525
		    if (image_loop == true) {
526
			    var dpix = this.im.width;
527
			    var dangle = 360;
528
			    if (ord_pts.length > 1) {
529
				    dpix = this.im.width - this.ref_pixels[this.ref_pixels.length-1].x + this.ref_pixels[1].x;
530
				    dangle = fmodulo(this.ref_pixels[1].cap - this.ref_pixels[this.ref_pixels.length-1].cap, 360);
531
			    }
532
			    this.ref_pixels[0].ratio_x = dpix/dangle;
533
			    this.ref_pixels[ord_pts.length].ratio_x = this.ref_pixels[0].ratio_x;
534
			    dpix = this.im.width - this.ref_pixels[ord_pts.length].x;
535
			    this.ref_pixels[0].cap = fmodulo(this.ref_pixels[ord_pts.length].cap + dpix / this.ref_pixels[0].ratio_x, 360);
536
		    } else {
537
			    this.ref_pixels[0].ratio_x = this.ref_pixels[1].ratio_x;
538
			    this.ref_pixels[ord_pts.length].ratio_x = this.ref_pixels[ord_pts.length-1].ratio_x;
539
			    this.ref_pixels[0].cap = fmodulo(this.ref_pixels[1].cap - this.ref_pixels[1].x / this.ref_pixels[1].ratio_x, 360);
540
			    alpha_domain.start = this.ref_pixels[0].cap;
541
			    alpha_domain.end = fmodulo(this.ref_pixels[ord_pts.length].cap+(this.im.width-this.ref_pixels[ord_pts.length].x)/this.ref_pixels[ord_pts.length].ratio_x, 360);
542
			    this.pixel_y_ratio = this.im.width/fmodulo(alpha_domain.end-alpha_domain.start, 360);
543
		    }
544
		    this.ref_pixels[0].x = 0;
562 545

  
563
	    if (debug_mode) {
564
		var res = document.getElementById('res');
565
		res.innerHTML = 'liste des '+this.ref_pixels.length+' valeurs de correction (image = '+this.im.width+'x'+this.im.height+') zoom = '+this.value+':<br/>';
566
		for (var i=0; i < this.ref_pixels.length; i++) { // pour le debug
567
		    res.innerHTML += '<p>point '+i+' :</p><ul>';
568
		    for (var key in this.ref_pixels[i]) { // pour le debug
569
			res.innerHTML += '<li>'+key + '['+i+'] = '+this.ref_pixels[i][key]+'</li>';
546
		    for (var i=0; i < ord_pts.length; i++) { // second parcours pour les paramètres elevation/y
547
			    this.ref_pixels[i+1].shift_y = Math.floor(this.pixel_y_ratio*ord_pts[i].ele - ord_pts[i].y*this.im.height);
548
			    if (i != ord_pts.length-1) {
549
				    var next_shift = Math.floor(this.pixel_y_ratio*ord_pts[i+1].ele - ord_pts[i+1].y*this.im.height);
550
				    this.ref_pixels[i+1].dshft_y = (next_shift - this.ref_pixels[i+1].shift_y)/(this.ref_pixels[i+2].x - this.ref_pixels[i+1].x);
551
			    }
570 552
		    }
571
		    if (i != this.ref_pixels.length-1) {
572
			var tx0 = this.ref_pixels[i+1].x-1;
573
			//var ty0 = this.ref_pixels[i+1].shift_y;
574
			var ty0 = 0;
553

  
554
		    if (image_loop == true) {
555
			    var dpix  = this.im.width;
556
			    var delt = 0;
557
			    if (ord_pts.length > 1) {
558
				    dpix  = this.im.width - this.ref_pixels[this.ref_pixels.length-1].x + this.ref_pixels[1].x;
559
				    delt = this.ref_pixels[this.ref_pixels.length-1].shift_y - this.ref_pixels[1].shift_y;
560
			    }
561
			    this.ref_pixels[0].dshft_y = -delt/dpix;
562
			    this.ref_pixels[ord_pts.length].dshft_y = this.ref_pixels[0].dshft_y;
563
			    dpix = this.im.width - this.ref_pixels[ord_pts.length].x;
564
			    this.ref_pixels[0].shift_y = this.ref_pixels[ord_pts.length].shift_y + dpix*this.ref_pixels[0].dshft_y;
575 565
		    } else {
576
			var tx0 = this.im.width-1;
577
			var ty0 = 0;
566
			    this.ref_pixels[0].shift_y = this.ref_pixels[1].shift_y;
567
			    this.ref_pixels[0].dshft_y = 0;
568
			    this.ref_pixels[ord_pts.length].dshft_y = 0;
569
		    }
570

  
571
		    if (debug_mode) {
572
			    var res = document.getElementById('res');
573
			    res.innerHTML = 'liste des '+this.ref_pixels.length+' valeurs de correction (image = '+this.im.width+'x'+this.im.height+') zoom = '+this.value+':<br/>';
574
			    for (var i=0; i < this.ref_pixels.length; i++) { // pour le debug
575
				    res.innerHTML += '<p>point '+i+' :</p><ul>';
576
				    for (var key in this.ref_pixels[i]) { // pour le debug
577
					    res.innerHTML += '<li>'+key + '['+i+'] = '+this.ref_pixels[i][key]+'</li>';
578
				    }
579
				    if (i != this.ref_pixels.length-1) {
580
					    var tx0 = this.ref_pixels[i+1].x-1;
581
					    //var ty0 = this.ref_pixels[i+1].shift_y;
582
					    var ty0 = 0;
583
				    } else {
584
					    var tx0 = this.im.width-1;
585
					    var ty0 = 0;
586
				    }
587
				    res.innerHTML += '</ul><p>test sur : '+tx0+','+ty0+'</p>';
588
				    var tst = this.get_cap_ele(tx0, ty0);
589
				    res.innerHTML += '<p>cap:'+tst.cap+', ele:'+tst.ele+'</p>';
590
				    var tst2 = this.get_pos_xy(tst.cap, tst.ele);
591
				    res.innerHTML += '</ul><p>x:'+tst2.x+', y:'+tst2.y+'</p>';
592
			    }
578 593
		    }
579
		    res.innerHTML += '</ul><p>test sur : '+tx0+','+ty0+'</p>';
580
		    var tst = this.get_cap_ele(tx0, ty0);
581
		    res.innerHTML += '<p>cap:'+tst.cap+', ele:'+tst.ele+'</p>';
582
		    var tst2 = this.get_pos_xy(tst.cap, tst.ele);
583
		    res.innerHTML += '</ul><p>x:'+tst2.x+', y:'+tst2.y+'</p>';
584
		}
585 594
	    }
586
	}
587 595

  
588
	this.pt_list = new Array();
589
	for (var i=0; i<point_list.length; i++) {
590
	    var lbl = point_list[i][0];
591
	    var dst = point_list[i][1];
592
	    var cap = point_list[i][2];
593
	    var ele = point_list[i][3];
594
	    var lnk = point_list[i][4];
595
	    var typ = 'unlocated';
596
	    var rxy = this.get_pos_xy(cap, ele);
597
	    var is_visible = fmodulo(cap - alpha_domain.start, 360) <= fmodulo(alpha_domain.end - alpha_domain.start -0.0001, 360)+0.0001 && is_located;
598

  
599
	    this.pt_list[i] = new Array();
600
	    if (ref_points[lbl] != undefined) {
601
		typ = 'ref_point';
602
		if (!is_located) rxy = {x:ref_points[lbl].x*this.im.width, y:ref_points[lbl].y*this.im.height}
603
	    } else if(lnk == '' && is_visible && lbl != 'point temporaire') {
604
		typ = 'loc_point';
605
	    }else if(is_visible && lbl =='point temporaire') {
606
	    typ = 'temporary';
607

  
608
	    } else if(is_visible) {
609
		typ = 'pano_point';
610
		lnk += '&to_zoom='+this.value;
596
	    this.pt_list = new Array();
597
	    for (var i=0; i<point_list.length; i++) {
598
		    var lbl = point_list[i][0];
599
		    var dst = point_list[i][1];
600
		    var cap = point_list[i][2];
601
		    var ele = point_list[i][3];
602
		    var lnk = point_list[i][4];
603
		    var typ = 'unlocated';
604
		    var rxy = this.get_pos_xy(cap, ele);
605
		    var is_visible = fmodulo(cap - alpha_domain.start, 360) <= fmodulo(alpha_domain.end - alpha_domain.start -0.0001, 360)+0.0001 && is_located;
606

  
607
		    this.pt_list[i] = new Array();
608
		    if (ref_points[lbl] != undefined) {
609
			    typ = 'ref_point';
610
			    if (!is_located) rxy = {x:ref_points[lbl].x*this.im.width, y:ref_points[lbl].y*this.im.height}
611
		    } else if(lnk == '' && is_visible && lbl != 'point temporaire') {
612
			    typ = 'loc_point';
613
		    }else if(is_visible && lbl =='point temporaire') {
614
			    typ = 'temporary';
615

  
616
		    } else if(is_visible) {
617
			    typ = 'pano_point';
618
			    lnk += '&to_zoom='+this.value;
619
		    }
620
		    this.pt_list[i]['type'] = typ;
621
		    this.pt_list[i]['cap'] = cap;
622
		    this.pt_list[i]['ele'] = ele;
623
		    this.pt_list[i]['dist'] = dst;
624
		    this.pt_list[i]['label'] = lbl;
625
		    this.pt_list[i]['lnk'] = lnk;
626
		    this.pt_list[i]['xc'] = rxy.x;
627
		    this.pt_list[i]['yc'] = Math.floor(this.im.height/2 - rxy.y);
611 628
	    }
612
	    this.pt_list[i]['type'] = typ;
613
	    this.pt_list[i]['cap'] = cap;
614
	    this.pt_list[i]['ele'] = ele;
615
	    this.pt_list[i]['dist'] = dst;
616
	    this.pt_list[i]['label'] = lbl;
617
	    this.pt_list[i]['lnk'] = lnk;
618
	    this.pt_list[i]['xc'] = rxy.x;
619
	    this.pt_list[i]['yc'] = Math.floor(this.im.height/2 - rxy.y);
620
	}
621
    }
629
    },
622 630

  
623 631
    this.get_tile_size = function(nx, ny) {
624 632
	var res = {width:0, height:0};

Formats disponibles : Unified diff