#!/usr/local/bin/perl -w # Visibility check use DBI; use CGI; $database = '***'; $hostname = '***'; $user = '***'; $password = '***'; $TITLE="Visibility Form"; $query = new CGI; $path_info = $query->path_info; if ($query->param ('Get the VRML document')){ print $query->header('x-world/x-vrml'); &print_VRML; } else { print $query->header; # If no path information is provided, then we create # a side-by-side frame set if (!$path_info) { &print_frameset; exit 0; } #Start HTML page &print_html_header; &print_query if $path_info=~/query/; &print_response if $path_info=~/response/; &print_html_end; } exit; #---------------------------------------- # Subroutines #----------------------------------------- sub print_html_header { print $query->start_html($TITLE); } #----------------------------------------- sub print_html_end { print $query->end_html; } #----------------------------------------- sub print_frameset { $script_name = $query->script_name; print <$TITLE EOF ; exit 0; } #------------------------------------------ sub print_query{ $script_name = $query->script_name; print "

Visibility

\n"; print $query->startform(-action=>"$script_name/response", -TARGET=>"response"); print "

Type the coordinates of the points you what to check the visibily between:

"; print "

POINT1:
(coordinates)
", $query->textfield(-name=>'X1', -default=>'115.81', -size=>20, -maxlength=>20); print "
", $query->textfield(-name=>'Y1', -default=>'55.16', -size=>20, -maxlength=>20); print "
", $query->textfield(-name=>'Z1', -default=>'4.91', -size=>20, -maxlength=>20); print "

POINT2:
(coordinates)
", $query->textfield(-name=>'X2', -default=>'235.30', -size=>20, -maxlength=>20); print "
", $query->textfield(-name=>'Y2', -default=>'268.94', -size=>20, -maxlength=>20); print "
", $query->textfield(-name=>'Z2', -default=>'17.95', -size=>20, -maxlength=>20); print "

",$query->submit (' Submit '); print $query->endform; print qq{

back}; } #-------------------------------------------- sub print_response { $script_name= $query->script_name; print "

Result

\n"; unless ($query->param) { print "No points submitted yet."; return; } $x1 = $query->param('X1'); $y1 = $query->param('Y1'); $z1 = $query->param('Z1'); $x2 = $query->param('X2'); $y2 = $query->param('Y2'); $z2 = $query->param('Z2'); print "

POINT1:
x1: $x1
y1: $y1
z1: $z1

"; print "

POINT2:
x2: $x2
y2: $y2
z2: $z2

"; print $query->startform; print $query->hidden(-name=>'X1', -default=>$x1); print $query->hidden(-name=>'Y1', -default=>$y1); print $query->hidden(-name=>'Z1', -default=>$z1); print $query->hidden(-name=>'X2', -default=>$x2); print $query->hidden(-name=>'Y2', -default=>$y2); print $query->hidden(-name=>'Z2', -default=>$z2); print "

Note: The points will be represented by small spheres respectively in red and yellow. The VRML document will be created faster without DTM.

"; print $query->checkbox (-name=>'grid', -checked=>'checked', -value =>'ON', -label =>'Grid'); print "
"; print $query->checkbox (-name=>'dtm', -checked =>'', -value =>'ON', -label =>'DTM'); print "

"; print $query->submit('Get the VRML document'); print $query->endform; } #--------------------------------------------------------- sub query_database{ $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); if ($order ne '') { $sth = $dbh->prepare("select $fields from $tables where $condition order by $order"); } else { $sth = $dbh->prepare("select $fields from $tables where $condition "); } $sth->execute; $num=0; while (@field = $sth->fetchrow) { $all[$num]=[@field]; $num_rec[$num]=@field; $num++; } $sth->finish; $dbh->disconnect; } #-------------------------------------------------------- sub print_VRML { $x1 = $query->param('X1'); $y1 = $query->param('Y1'); $z1 = $query->param('Z1'); $x2 = $query->param('X2'); $y2 = $query->param('Y2'); $z2 = $query->param('Z2'); $g = $query->param('grid'); $dt = $query->param('dtm'); &print_vrml_header; $fields = "fid,enoseqf,nid,xc,yc,zc,bidg"; $tables = "bodyg,face,node"; $condition = "fidb=fid and nidf=nid"; $order = "fid, enoseqf"; &query_database; &print_vrml_surface; $fields = "fid,enoseqf,nid,xc,yc,zc,sidg"; $tables = "surfg,face,node"; if ($dt ne 'ON'){ $condition = "sidg<19 and fids=fid and nidf=nid"; } else { $condition = "fids=fid and nidf=nid"; } $order = "fid, enoseqf"; &query_database; &print_vrml_surface; &print_line; &print_north; if($g eq 'ON'){ &print_grid; } &print_vrml_end; return; } #---------------------------------------------------------- sub print_vrml_surface { $k=0; $surface = $all[$k]->[6]; while (($k<$num) && ($surface == ($all[$k]->[6]))) {#-start surface print <[6])== $surface)) { $fid = $all[$k]->[0]; $nodeinface=0; while ($fid==$all[$k]->[0]) { #------------------existing coordinates ?????------------- $exist = -1; $p=$n_crd; $i=0; while ($i<$p){ if ($all[$k]->[1]==$n[$i]) { $exist=$i; } $i++; } #----------------------------------------------------------- if ($exist == -1) { $x[$n_crd] = $all[$k]->[3]; $y[$n_crd] = $all[$k]->[4]; $z[$n_crd] = $all[$k]->[5]; $n[$n_crd] = $all[$k]->[2]; $descr[$nodeinface]=$n_crd; $n_crd++; } else { $descr[$nodeinface]=$exist; } $nodeinface++; $k++; } $facedescr[$n_face]=[@descr]; $nodedescr[$n_face]=$nodeinface; $n_face++; } #all the faces in a surface #--------print coordinates---------------------- $i=0; while ($i<$n_crd) { print " $x[$i] $y[$i] $z[$i] \n"; $i++; } print <[$j], "; $j++; } $i++; print " -1, \n"; } print " ]\n"; $surface = $all[$k]->[6]; print <connect ("DBI:mysql:$database:$hostname", $user,$password); $sth = $dbh->prepare("select min(xc) from node"); $sth->execute; $xmin=$sth->fetchrow; $sth->finish; $sth = $dbh->prepare("select min(yc) from node"); $sth->execute; $ymin=$sth->fetchrow; $sth->finish; $sth = $dbh->prepare("select min(zc) from node"); $sth->execute; $zmin=$sth->fetchrow; $sth->finish; $dbh->disconnect; print "Transform {\n"; print " translation $xmin $ymin $zmin\n"; print " children[\n"; print " Shape {\n "; print " appearance Appearance{\n"; print " material Material {\n"; print " diffuseColor 0.0 0.0 1.0\n"; print " }\n"; print " }\n"; print " geometry Cylinder {\n"; print " height 60.0\n"; print " radius 1.0\n"; print " }\n"; print " }\n"; print "Transform {\n"; print " rotation 0 0 1 -1.571\n"; print " translation 30 -30 0\n"; print " children[\n"; print " Shape {\n "; print " appearance Appearance{\n"; print " material Material {\n"; print " diffuseColor 0.0 1.0 0.0\n"; print " }\n"; print " }\n"; print " geometry Cylinder {\n"; print " height 60.0\n"; print " radius 1.0\n"; print " }\n"; print " }\n"; print "]}\n"; print "]}\n"; } #--------------------------------------------------------- sub print_grid { $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); $sth = $dbh->prepare("select max(xc) from node"); $sth->execute; $xmax=$sth->fetchrow; $sth->finish; $sth = $dbh->prepare("select max(yc) from node"); $sth->execute; $ymax=$sth->fetchrow; $sth->finish; $sth = $dbh->prepare("select max(zc) from surfg, face, node where sidg=19 and fids=fid and nidf=nid"); $sth->execute; $zmax=$sth->fetchrow; $sth->finish; $dbh->disconnect; $i=-400; while ($i<$xmax) { if ($i>$xmin) { print " Shape {\n "; print " appearance Appearance{\n"; print " material Material {\n"; print " emissiveColor 0.0 0.0 1.0\n"; print " }\n"; print " }\n"; print " geometry IndexedLineSet {\n"; print " coord Coordinate {\n"; print " point [\n"; print " $i $ymin $zmax,\n"; print " $i $ymax $zmax,\n"; print " ]\n"; print " }\n"; print " coordIndex [\n"; print " 0, 1, -1\n"; print " ]\n"; print " }\n"; print " }\n"; } $i=$i+100; } $i= -400; while ($i<$ymax) { if ($i>$ymin) { print " Shape {\n "; print " appearance Appearance{\n"; print " material Material {\n"; print " emissiveColor 0.0 1.0 0.0\n"; print " }\n"; print " }\n"; print " geometry IndexedLineSet {\n"; print " coord Coordinate {\n"; print " point [\n"; print " $xmin $i $zmax,\n"; print " $xmax $i $zmax,\n"; print " ]\n"; print " }\n"; print " coordIndex [\n"; print " 0, 1, -1\n"; print " ]\n"; print " }\n"; print " }\n"; } $i=$i+100; } } #--------------------------------------------------------- sub print_vrml_header { print <