Commit b72fe097e8f37c960538e19ed50bcc2a768469df

Authored by Edmar Moretti
1 parent 122762fc

Correção na visualização em 3d, modificando-se a forma de sobreposição da imagem…

… do mapa ao modelo do relevo
Showing 1 changed file with 50 additions and 22 deletions   Show diff stats
ferramentas/3d/3d.php
... ... @@ -21,7 +21,9 @@ Free Software Foundation, Inc., no endereço
21 21 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
22 22 */
23 23 require_once("../../classesphp/pega_variaveis.php");
  24 +require_once("../../classesphp/carrega_ext.php");
24 25 error_reporting(0);
  26 +set_time_limit(120);
25 27 if (isset($g_sid))
26 28 {session_id($g_sid);}
27 29 session_name("i3GeoPHP");
... ... @@ -35,7 +37,7 @@ require_once("../../classesphp/funcoes_gerais.php");
35 37 //
36 38 //carrega o phpmapscript
37 39 //
38   -if (!function_exists(ms_GetVersion))
  40 +if (!function_exists('ms_GetVersion'))
39 41 {
40 42 $exts = get_loaded_extensions();
41 43 if (array_search( "MapScript", $exts) != TRUE)
... ... @@ -64,10 +66,12 @@ if ($temaz=="")
64 66 if ($maptemp == ""){echo "Arquivo com o relevo não foi encontrado";return;}
65 67 }
66 68 $mapa = ms_newMapObj($map_file);
67   -if ($mapa->width > 400)
  69 +if ($mapa->width > 500)
68 70 {
69   - $mapa->setsize(400,400);
  71 + $mapa->setsize(500,500);
70 72 }
  73 +$of = $mapa->outputformat;
  74 +$of->set("imagemode",MS_IMAGEMODE_RGB);
71 75 $imgo = $mapa->draw();
72 76 $nome = ($imgo->imagepath).nomeRandomico().".png";
73 77 $nomefinal = ($imgo->imagepath).nomeRandomico().".wrl";
... ... @@ -106,9 +110,12 @@ $imgo->saveImage($nome);
106 110 $arquivoalt = $nome;
107 111  
108 112 $imgcor = imagecreatefrompng($arquivocor);
  113 +$imgcor = flipImage($imgcor, true, false);
  114 +imagepng($imgcor,$arquivocor);
  115 +
109 116 $imgalt = imagecreatefrompng($arquivoalt);
110   -$sx = imagesx($imgcor);
111   -$sy = imagesy($imgcor);
  117 +$sx = imagesx($imgalt);
  118 +$sy = imagesy($imgalt);
112 119 $fp = fopen($nomefinal,"w");
113 120  
114 121  
... ... @@ -116,7 +123,12 @@ $texto = "#VRML V2.0 utf8
116 123 Group {
117 124 children [DirectionalLight { direction 0 -1 0 }
118 125 Shape {
119   -appearance Appearance { material Material { diffuseColor .2 .2 .2}}
  126 +appearance Appearance {
  127 + material Material { diffuseColor .2 .2 .2 }";
  128 +$texto .= "texture ImageTexture { url ".'"'.basename($arquivocor).'"';
  129 +$texto .= "}
  130 +}
  131 +
120 132 geometry ElevationGrid {
121 133 xDimension $sx
122 134 xSpacing 1
... ... @@ -135,26 +147,12 @@ for ($y = 0; $y < $sy; $y++)
135 147 $alt = imagecolorat($imgalt, $x, $y);
136 148 $z = ($alt >> 16) & 0xFF;
137 149 fwrite($fp,($z/$fz)." ");
  150 + //fwrite($fp,($alt)." ");
138 151 }
139 152 }
140 153  
141   -$texto = "]
142   -color Color { color [\n";
143   -fwrite($fp,$texto);
144   -
145   -for ($y = 0; $y < $sy; $y++)
146   -{
147   - for ($x = 0; $x < $sx; $x++)
148   - {
149   - $cor = imagecolorat($imgcor, $x, $y);
150   - $r = ($cor >> 16) & 0xFF;
151   - $g = ($cor >> 8) & 0xFF;
152   - $b = $cor & 0xFF;
153   - fwrite($fp,($r/500)." ".($g/500)." ".($b/500)." ");
154   - }
155   -}
156 154  
157   -$texto = '] }
  155 +$texto = ']
158 156 }
159 157 }
160 158 ]
... ... @@ -170,4 +168,34 @@ echo &quot;&lt;br&gt;&lt;a id=abre href=&#39;&#39; &gt;Clique aqui&lt;/a&gt;&quot;;
170 168 echo "<br><br>x:$x y:$y";
171 169  
172 170 echo "<script>document.getElementById('abre').href=".$h."</script>";
  171 +
  172 +
  173 + function flipImage($image, $vertical, $horizontal) {
  174 + $w = imagesx($image);
  175 + $h = imagesy($image);
  176 +
  177 + if (!$vertical && !$horizontal) return $image;
  178 +
  179 + $flipped = imagecreatetruecolor($w, $h);
  180 +
  181 + if ($vertical) {
  182 + for ($y=0; $y<$h; $y++) {
  183 + imagecopy($flipped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
  184 + }
  185 + }
  186 +
  187 + if ($horizontal) {
  188 + if ($vertical) {
  189 + $image = $flipped;
  190 + $flipped = imagecreatetruecolor($w, $h);
  191 + }
  192 +
  193 + for ($x=0; $x<$w; $x++) {
  194 + imagecopy($flipped, $image, $x, 0, $w - $x - 1, 0, 1, $h);
  195 + }
  196 + }
  197 +
  198 + return $flipped;
  199 + }
  200 +
173 201 ?>
... ...