Bonjour,
Je reviens vous voir car j'ai un petit soucis de référence...
Je mettrai les détails en dessous mais je vous explique d'abord le principe :
J'ai crée une classe polygon contenant les champs suivants :
-name : le nom du polygon
-points : un tableau contenant des petites tables de hachage à deux éléments (lat et long)
-rect : une table de hachage contenant 4 éléments : xmin xmax ymin ymax les 4 "coins" du rectangle dans lequel le polygone est inclus
-nghbr : une table de hachage contenant en clé les noms et en valeurs les références de chaque polygone voisin de celui-ci (deux polygones sont voisins si les rectangles dans lequel ils sont inclus ont des points ou une aire en commun)
Voici mon probleme :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 sub new { my $class = shift; my $name = shift; my $points = shift; #Points of the polygon my $rect = shift; #Rectangle which contain the polygon my $nghbr ={} ; #neighbours of the polygon my $self = { name => $name, points => $points, rect => $rect, nghbr => $nghbr }; bless ($self,$class); return $self; }
j'ai un point x,y et je veux en fait savoir dans quel polygone est ce point.
Pour ce faire, je fais un premier tri ou je regarde les xmin, xmax ymin ymax de chaque polygone. Car par exemple, si xmin est plus grand que x, pas la peine de regarder plus loins, x,y n'est pas dans ce polygone..
Les polygones sont contenus dans une table de hachage %Polyh.
Je copie cette table de hachage dans %Sort1 en me disant : comme ça, je fais les modif dans %Sort1 et %Polyh ne sera en aucun cas touché !
Mais apparement il semblerait que quand je supprime un élément de %Sort1, il est aussi supprimé dans %Polyh car en faisant tourner mon programme pour plusieurs x,y je perd les données au fur et à mesure... Mais ce qui est je trouve bizarre c'est que les clés restent, mais les valeurs sont supprimés..
Bref, trève de mots, place au code..
Voilà, qu'en pensez-vous ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 sub localisation1 { %Sort1=%Polyh; my @keys_of_poly = keys %Sort1; print "-Number of elements of sort1 = ".scalar(@keys_of_poly)."\n"; foreach my $k ( keys %Polyh ) { print" Polygon : $k \n"; #Test if the Polygons are defined if ( (scalar(keys %{$Polyh{$k}->{rect}}) == 0) || (scalar(keys %{$Polyh{$k}->{nghbr}}) == 0)) { # if ( (!exists $Polyh{$k}->{rect}) || (!exists $Polyh{$k}->{nghbr})) { print"Polygons are not defined for $k..\n"; &Debug("--- Error: Polygons are not defined for $k. Skipping to the next polygon\n",6); next; # return 1; } # # if ( ${$Sort1{$k}->{rect}}{xmin} > $x ) #We erase Polygons which xmin is greater than x { print" $Sort1{$k}->{name} Erased \n"; if ( exists($Sort1{$k}) ) { delete($Sort1{$k}); foreach my $v ( keys %Sort1 ) { if ( exists($Sort1{$v}->{nghbr}{$k}) ) { # print "- Deleting ".&Dumper($Sort1{$v}->{nghbr}{$k})."\n"; print "- Deleting $k, which is a neighbour of $v\n"; delete( $Sort1{$v}->{nghbr}{$k} ); } } } } else {print"xmin ok\n";} if ( exists($Sort1{$k}) ) { if ( ${$Sort1{$k}->{rect}}{xmax} < $x ) #We erase Polygons which xmax is smaller than x { print" $Sort1{$k}->{name} Erased \n"; delete($Sort1{$k}); foreach my $v ( keys %Sort1 ) { if ( exists($Sort1{$v}->{nghbr}{$k}) ) { # print "- Deleting ".&Dumper($Sort1{$v}->{nghbr}{$k})."\n"; # print "- Deleting $k\n"; print "- Deleting $k, which is a neighbour of $v\n"; delete( $Sort1{$v}->{nghbr}{$k} ); } } } else {print"xmax ok\n";} } if ( exists($Sort1{$k}) ) { if ( ${$Sort1{$k}->{rect}}{ymin} > $y ) #We erase Polygons which ymin is greater than y { print" $Sort1{$k}->{name} Erased \n"; delete($Sort1{$k}); foreach my $v ( keys %Sort1 ) { if ( exists($Sort1{$v}->{nghbr}{$k}) ) { # print "- Deleting ".&Dumper($Sort1{$v}->{nghbr}{$k})."\n"; # print "- Deleting $k\n"; print "- Deleting $k, which is a neighbour of $v\n"; delete( $Sort1{$v}->{nghbr}{$k} ); } } } else {print"ymin ok\n";} } if ( exists($Sort1{$k}) ) { if ( ${$Sort1{$k}->{rect}}{ymax} < $y ) #We erase Polygons which ymax is smaller than y { print" $Sort1{$k}->{name} Erased \n"; delete($Sort1{$k}); foreach my $v ( keys %Sort1 ) { if ( exists($Sort1{$v}->{nghbr}{$k}) ) { # print "- Deleting $k\n"; print "- Deleting $k, which is a neighbour of $v\n"; delete( $Sort1{$v}->{nghbr}{$k}); } } } else {print"ymax ok\n";} } } ########## #whatever is remaining print"Whatever is remaining :\n"; foreach my $j ( keys %Sort1 ) { print" key : $j \n"; } ########## }
Partager