#!/usr/local/bin/perl -w # Query for common faces use DBI; use CGI; $database = '***'; $hostname = '***'; $user = '***'; $password = '***'; $TITLE="Query 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 "

Query
common faces

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


ID BUILDING 1:
(identifier 1) ", $query->textfield(-name=>'id1', -default=>'10', -size=>10, -maxlength=>120),"

"; print "


ID BUILDING 2:
(identifier 2) ", $query->textfield(-name=>'id2', -default=>'11', -size=>10, -maxlength=>120),"

"; print "

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

Note: an asterisk(*) initiates a search among all the object

"; print qq{

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

Result

\n"; unless ($query->param) { print "No query submitted yet."; return; } $id1 = $query->param('id1'); $id2 = $query->param('id2'); print "

BUILDING1: $id1
BUILDING2: $id2

"; &qdb_check_nodes; print "
object1 object2 face
"; for ($jj=0; $jj<$n_com; $jj++) { # if ($b1[$jj] != $b2[$jj]) { print "$b1[$jj] $b2[$jj] $cn[$jj]"; print "
"; # } } print $query->startform; print $query->hidden(-name=>'id1', -default=>$id1); print $query->hidden(-name=>'id2', -default=>$id1); print $query->submit('Get the VRML document'); print $query->endform; } #--------------------------------------------------------- sub qdb_check_nodes { $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); $n_body=$dbh->do ("select * from bodyt"); $n_com=0; if ($id1 eq "*") {$begi=1; $endi=$n_body+1;} else {$begi=$id1; $endi=$id1+1;} for ($i=$begi; $i<$endi; $i++){ $sth = $dbh->prepare("select fidb from bodyg where bidg=$i"); $sth->execute; $num_n1=0; while ($field = $sth->fetchrow) { $all[$num_n1]=$field; $num_n1++; } $sth->finish; $body_1[$i]=[@all]; if ($id2 eq "*") {$begj=1; $endj=$n_body+1;} else {$begj=$id2; $endj=$id2+1;} for ($j=$begj; $j<$endj;$j++){ if ($i != $j) { for ($kk=0;$kk<$num_n1;$kk++){ $sth = $dbh->prepare("select fidb from bodyg where bidg=$j and fidb=$body_1[$i]->[$kk] "); $sth->execute; if ($field = $sth->fetchrow) { $b1[$n_com] = $i; $b2[$n_com] = $j; $cn[$n_com] = $field; $n_com++; } $sth->finish; } # comparison faces body1/body2 } # avoid duplications } #one and more body2 }#one and more body1 $dbh->disconnect; } #-------------------------------------------------------- sub print_VRML { $id1 = $query->param('id1'); $id2 = $query->param('id2'); &print_vrml_header; &qdb_check_nodes; $obj=0; for ($jj=0; $jj<$n_com; $jj++) { if ($b1[$jj] != $obj) { $obj=$b1[$jj]; &query_database_VRML; &print_vrml_surface; } } $obj=0; for ($jj=0; $jj<$n_com; $jj++) { if ($b2[$jj] != $obj) { $obj=$b2[$jj]; &query_database_VRML; &print_vrml_surface; } } &print_vrml_end; return; } #---------------------------------------------------------- sub query_database_VRML{ $fields = 'fid,enoseqf,nid,xc,yc,zc,bidg'; $tables = 'bodyg,face,node'; $condition = 'fid=fidb and nid=nidf'; $order = 'bidg,fid,enoseqf'; $dbh = DBI->connect ("DBI:mysql:$database:$hostname", $user,$password); $sth = $dbh->prepare("select $fields from $tables where bidg=$obj and $condition order by $order"); $sth->execute; $num=0; while (@field = $sth->fetchrow) { $all[$num]=[@field]; #$num_rec[$num]=@field; $num++; } $sth->finish; $dbh->disconnect; } #-------------------------------------------------------- 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 <