$search
00001 package edu.tum.cs.ias.knowrob.vis.applets; 00002 00003 import java.awt.Color; 00004 import java.awt.event.ActionEvent; 00005 import java.awt.event.ActionListener; 00006 import java.awt.event.KeyEvent; 00007 import java.awt.event.MouseEvent; 00008 import java.awt.event.MouseListener; 00009 import java.awt.event.MouseMotionListener; 00010 00011 import java.util.ArrayList; 00012 import java.util.HashMap; 00013 import java.util.Vector; 00014 00015 import javax.swing.JFrame; 00016 import javax.swing.JOptionPane; 00017 import javax.swing.Timer; 00018 import javax.vecmath.Matrix4d; 00019 import javax.vecmath.Vector3d; 00020 import javax.vecmath.Vector3f; 00021 00022 import peasy.PeasyCam; 00023 import peasy.CameraState; 00024 import peasy.org.apache.commons.math.geometry.*; 00025 00026 import processing.core.PFont; 00027 import processing.core.PGraphics3D; 00028 import processing.core.PMatrix; 00029 00030 00031 import edu.tum.cs.ias.knowrob.owl.OWLThing; 00032 import edu.tum.cs.ias.knowrob.prolog.PrologInterface; 00033 import edu.tum.cs.ias.knowrob.util.datastructures.Point; 00034 import edu.tum.cs.ias.knowrob.vis.AnimatedCanvas; 00035 import edu.tum.cs.ias.knowrob.vis.Canvas; 00036 import edu.tum.cs.ias.knowrob.vis.items.*; 00037 import edu.tum.cs.vis.model.ItemModel; 00038 import edu.tum.cs.vis.model.Properties; 00039 00040 public class SemanticMapVisApplet extends AnimatedCanvas implements MouseListener, MouseMotionListener { 00041 00042 static final long serialVersionUID=0; 00043 00044 public static final double ROTATE_Y_DELTA = 0.05; 00045 00047 // DISPLAY PROPERTIES (ROTATION, ZOOM, ...) 00048 //private float leftMouseX=-1.0f, leftMouseY=-1.0f, rightMouseX=-1.0f, rightMouseY=-1.0f, centerMouseY=-1.0f; 00049 //private float xRotDisplay=143.6f, yRotDisplay=-9.14f, xShiftDisplay=420.5f, yShiftDisplay=359.0f, zoomDisplay=1.19f; 00050 00052 // SETTINGS 00053 //private String meshFile = "/home/tenorth/work/kipm/meshdata/unclassified300p.vtk"; 00054 00055 00057 // MISC 00058 private PFont verdana; 00059 private PFont verdanaBold; 00060 private PFont dejavu; 00061 private ArrayList<int[]> colors = new ArrayList<int[]>(12); 00062 private MapObjClickListener objectClickListener = null; 00063 public MenuHuman menu_human = new MenuHuman(); 00064 00065 // private Publisher<ros.pkg.std_msgs.msg.String> clickPub = null; 00066 // private NodeHandle rosNode = null; 00067 // private Ros ros = null; 00068 00070 // COLOR STUFF / CLICK STUFF 00071 private int[] grayValues = new int[] {160,190,210,170,220,180,200,165,185,205,175,195,215}; 00072 private static int grayLevelCounter = 0; 00073 private EmptyCanvas buffer; 00074 private JFrame bufferFrame; 00075 //private PMatrix bufferMatrix; 00076 00077 00079 // BUFFERS, DATA 00080 00085 private HashMap<String,ItemBase> animatedItemsRef = new HashMap<String, ItemBase>(); 00086 private ArrayList<ItemBase> allItems = new ArrayList<ItemBase>(); 00087 private float[] framesToTimes; 00088 00089 00091 // INFO ABOUT CURRENT DISPLAY 00092 private int numberFrames = 1; 00093 private int currentFrame = 0; 00094 00095 PeasyCam cam; 00096 00097 00098 00100 // FLAGS 00101 public boolean isInitialized = false; 00102 private boolean playingForward = true; 00103 boolean record = false; 00104 00105 00109 // 00110 // INITIALIZATION FUNCTIONS 00111 // 00112 00117 public void setup() { 00118 00119 size(700, 600, PGraphics3D.P3D); 00120 00121 00122 // define camera parameters 00123 cam = new PeasyCam(this, 0,0,0, 50); 00124 00125 // values for zooming (min distance to which one can zoom in) 00126 cam.setMinimumDistance(0.01); 00127 cam.setMaximumDistance(500); 00128 00129 cam.setRightDragHandler(cam.getPanDragHandler()); 00130 cam.setLeftDragHandler(cam.getRotateDragHandler()); 00131 cam.setWheelScale(0.2); 00132 00133 // initialize camera view parameters 00134 cam.setRotations(1.808507, -0.46793357, 0.056346834); 00135 cam.setDistance(75.6322); 00136 cam.lookAt(10.443167, -4.4923606, -3.8713489); 00137 00138 frameRate(25); 00139 buffer = new EmptyCanvas(700,600,PGraphics3D.P3D); 00140 00141 verdana = createFont("Verdana", 11); 00142 verdanaBold = createFont("Verdana-Bold", 18); 00143 dejavu = createFont("DejaVu Sans",13); 00144 textFont(verdana); 00145 textFont(verdanaBold); 00146 textFont(dejavu); 00147 00148 ellipseMode(RADIUS); 00149 sphereDetail(10); 00150 setColors(); 00151 00152 hint(ENABLE_DEPTH_TEST); 00153 // hint(DISABLE_DEPTH_TEST); 00154 00155 // Don't enable, causes huge performance break 00156 // hint(ENABLE_DEPTH_SORT); 00157 // hint(DISABLE_DEPTH_SORT); 00158 00159 //drawBackground(); 00160 draw(); 00161 isInitialized = true; 00162 00163 00164 // // Generate a Publisher for the RDF Identifier that 00165 // // currently was clicked. 00166 // try { 00167 // ros = Ros.getInstance(); 00168 // if(!ros.isInitialized()) { 00169 // ros.init("mod_vis"); 00170 // } 00171 // rosNode = ros.createNodeHandle(); 00172 // clickPub = rosNode.advertise("/mod_vis/mod_vis_clicked", new ros.pkg.std_msgs.msg.String(), 100); 00173 // } 00174 // catch(RosException e) { 00175 // e.printStackTrace(); 00176 // ros.logError("Could not advertise /mod_vis_clicked topic."); 00177 // } 00178 00179 } 00180 00181 00182 00183 00187 // 00188 // DRAW FUNCTIONS 00189 // 00190 00191 private void setLights() 00192 { 00193 float camPos[] = cam.getPosition(); 00194 00195 lights(); 00196 pointLight(80f, 80f, 100f, camPos[0],camPos[1], camPos[2]); 00197 } 00198 00202 @Override 00203 public void draw() { 00204 PMatrix save = getMatrix(); 00205 try{ 00206 00207 //System.out.println(cam.getRotations()[0] + ", " + cam.getRotations()[1] + ", " + cam.getRotations()[2]); 00208 //System.out.println(cam.getDistance() + ", lookat " + cam.getLookAt()[0] + ", " + cam.getLookAt()[1] + ", " + cam.getLookAt()[2] ); 00209 00210 if (record) { 00211 beginRaw(PDF, "output.pdf"); 00212 } 00213 00214 scale(10); 00215 00216 background(40); 00217 00218 pushMatrix(); 00219 00220 applyMatrix( 1, 0, 0, 0, 00221 0, 1, 0, 0, 00222 0, 0, -1, 0, 00223 0, 0, 0, 1); 00224 //lights(); 00225 00226 setLights(); 00227 00228 00229 strokeWeight(1.5f); 00230 stroke(255, 0, 0); line(0, 0, 0, 500, 0, 0); 00231 stroke(0, 255, 0); line(0, 0, 0, 0, 500, 0); 00232 stroke(0, 0, 255); line(0, 0, 0, 0, 0, 500); 00233 stroke(0, 0, 0); 00234 00235 // draw the meshes 00236 //if(drawMeshes) 00237 // drawMeshes(); 00238 00239 // draw all Items 00240 for(int i=0;i<allItems.size();i++) { 00241 //hint(ENABLE_DEPTH_TEST); 00242 ItemBase it = allItems.get(i); 00243 it.draw(this, currentFrame); 00244 00245 } 00246 00247 popMatrix(); 00248 00249 if (record) { 00250 endRaw(); 00251 System.err.println("Writing PDF..."); 00252 record = false; 00253 } 00254 00255 } catch(ArrayIndexOutOfBoundsException e) { 00256 00257 System.out.println("Some Drawing error occured... "); 00258 resetMatrix(); 00259 record = false; 00260 applyMatrix(save); 00261 } 00262 } 00263 00264 private String getItemAt(int x, int y) { 00265 00266 String[] id = null; 00267 int clicked = -1; 00268 00269 try{ 00270 00271 00272 buffer.setSize(700, 600); 00273 00274 00275 buffer.resetMatrix(); 00276 cam.getState().apply(buffer); 00277 buffer.noLights(); 00278 buffer.scale(10); 00279 00280 buffer.pushMatrix(); 00281 //buffer.background(60, 60, 60); 00282 00283 00284 buffer.applyMatrix( 1, 0, 0, 0, 00285 0, 1, 0, 0, 00286 0, 0, -1, 0, 00287 0, 0, 0, 1); 00288 buffer.ellipseMode(RADIUS); 00289 buffer.pushMatrix(); 00290 00291 // draw all Items 00292 id = new String[allItems.size()]; 00293 for(int i=0;i<allItems.size();i++) { 00294 ItemBase itm = allItems.get(i); 00295 itm.colorOverride = new Color(0xff000000 | ( 1*i + 1)); 00296 allItems.get(i).draw(buffer, currentFrame); 00297 itm.colorOverride = null; 00298 id[i] = itm.name; 00299 } 00300 00301 // get color 00302 clicked = ((buffer.get(x,y)-1) & 0x00ffffff)/1; 00303 00304 buffer.freeze(); 00305 buffer.redraw(); 00306 00307 buffer.popMatrix(); 00308 buffer.popMatrix(); 00309 00310 }catch(Exception e){} 00311 00312 if(clicked >= 0 && clicked<id.length) 00313 return id[clicked]; 00314 else 00315 return null; 00316 } 00317 00321 /*private void drawTime(){ 00322 DecimalFormat df2 = new DecimalFormat( "##0.00" ); 00323 fill(0, 255, 0); 00324 textFont(verdana); 00325 textMode(SCREEN); 00326 textAlign(LEFT); 00327 text("Action: "+queryString,10,50); 00328 text("Duration: "+df2.format(startTime)+"-"+df2.format(endTime),10,62); 00329 text("Frame: "+currentFrame+" / "+(numberFrames-1),10,86); 00330 00331 if(framesToTimes != null) 00332 text("Time: "+df2.format(framesToTimes[currentFrame]), 10, 98); 00333 }*/ 00334 00339 private void displayMessage(String message){ 00340 System.out.println(message); 00341 return; 00342 } 00343 public void setMapObjClickListener(MapObjClickListener c){ 00344 objectClickListener = c; 00345 } 00346 00347 00351 // 00352 // METHODS FOR ADDING AND REMOVING OBJECTS 00353 // 00354 // 00355 00356 00357 public void addItem(ItemBase item) { 00358 this.allItems.add(item); 00359 animatedItemsRef.put(item.name, item); 00360 } 00361 00362 public void addObject(String identifier) { 00363 00364 ItemBase item = getItem(identifier); 00365 00366 if(item != null) { 00367 removeObject(identifier); 00368 addItem(item); 00369 } 00370 } 00371 00372 public void addObjectWithChildren(String identifier) { 00373 00374 identifier = OWLThing.addSingleQuotes(OWLThing.removeSingleQuotes(identifier)); 00375 00376 HashMap<String, Vector<String>> physicalParts = PrologInterface.executeQuery( 00377 "rdf_reachable("+identifier+", knowrob:properPhysicalParts, PART)"); 00378 00379 if(physicalParts!=null && physicalParts.get("PART") != null) 00380 for(int i=0;i<physicalParts.get("PART").size();i++) 00381 if(!physicalParts.get("PART").get(i).toString().equals(identifier)) 00382 addObject(physicalParts.get("PART").get(i)); 00383 00384 HashMap<String, Vector<String>> mapParts = PrologInterface.executeQuery( 00385 "rdf_reachable(PART, knowrob:describedInMap, "+identifier+")"); 00386 00387 00388 if(mapParts!=null && mapParts.get("PART") != null) 00389 for(int i=0;i<mapParts.get("PART").size();i++) 00390 if(!mapParts.get("PART").get(i).toString().equals(identifier)) 00391 { 00392 HashMap<String, Vector<String>> parts = PrologInterface.executeQuery( 00393 "rdf_reachable("+mapParts.get("PART").get(i).toString()+", knowrob:properPhysicalParts, P)"); 00394 00395 if(parts!=null) { 00396 Vector<String> p = parts.get("P"); 00397 00398 if(p != null) 00399 for(int j=0;j<p.size();j++) 00400 if(!p.get(j).toString().equals(mapParts.get("PART").get(i))) 00401 addObject(p.get(j).toString()); 00402 00403 addObject(mapParts.get("PART").get(i).toString()); 00404 } 00405 } 00406 addObject(identifier); 00407 00408 } 00409 00410 00411 public void removeItem(ItemBase item) { 00412 allItems.remove(item); 00413 animatedItemsRef.remove(item.name); 00414 } 00415 00416 00417 public void removeObject(String identifier) { 00418 00419 ItemBase item = animatedItemsRef.get(PrologInterface.addSingleQuotes(identifier)); 00420 if(item == null) { 00421 return; 00422 } 00423 removeItem(item); 00424 } 00425 00426 00427 public void removeObjectWithChildren(String identifier) { 00428 HashMap<String, Vector<String>> physicalParts = PrologInterface.executeQuery( 00429 "rdf_reachable("+identifier+", knowrob:properPhysicalParts, PART)"); 00430 00431 if(physicalParts!=null && physicalParts.get("PART") != null) 00432 for(int i=0;i<physicalParts.get("PART").size();i++) 00433 if(!physicalParts.get("PART").get(i).equals(identifier)) 00434 removeObject(physicalParts.get("PART").get(i)); 00435 00436 HashMap<String, Vector<String>> mapParts = PrologInterface.executeQuery( 00437 "rdf_reachable(PART, knowrob:describedInMap, "+identifier+")"); 00438 00439 if(mapParts != null && mapParts.get("PART") != null) 00440 for(int i=0;i<mapParts.get("PART").size();i++) 00441 if(!mapParts.get("PART").get(i).equals(identifier)) 00442 { 00443 HashMap<String, Vector<String>> parts = PrologInterface.executeQuery( 00444 "rdf_reachable("+mapParts.get("PART").get(i)+", knowrob:properPhysicalParts, P)"); 00445 00446 if(parts != null) { 00447 Vector<String> p = parts.get("P"); 00448 00449 if(p != null) 00450 for(int j=0;j<p.size();j++) 00451 if(!p.get(j).toString().equals(mapParts.get("PART").get(i))) 00452 addObject(p.get(j)); 00453 00454 removeObject(mapParts.get("PART").get(i)); 00455 } 00456 } 00457 removeObject(identifier); 00458 00459 } 00460 00461 00465 // 00466 // METHODS FOR HIGHLIGHTING OBJECTS 00467 // 00468 // 00469 00470 00471 00476 public void highlightItem(String identifier, boolean highlight, int color) { 00477 ItemBase itm = animatedItemsRef.get(identifier); 00478 if(itm == null) { 00479 displayMessage("item "+identifier+" not in scene"); 00480 return; 00481 } 00482 00483 if(highlight) 00484 itm.setColor(color); 00485 else 00486 itm.setColor(itm.defaultColor); 00487 } 00488 00489 public void highlightItem(String identifier, boolean highlight) { 00490 highlightItem(identifier, highlight, convertColor(255, 0, 0, 255)); 00491 } 00492 00496 public void highlightReachable(String identifier, boolean highlight) { 00497 highlightItem(identifier, highlight); 00498 00499 HashMap<String, Vector<String>> others = PrologInterface.executeQuery( 00500 "rdf_reachable("+identifier+", knowrob:properPhysicalParts, I)"); 00501 00502 if(others == null) return; 00503 00504 Vector<String> itms = others.get("I"); 00505 if(itms == null) return; 00506 00507 for(String o : itms) 00508 highlightItem(o, highlight); 00509 00510 } 00511 00512 public void clearHighlights() { 00513 // draw all Items 00514 for(String j : animatedItemsRef.keySet()) { 00515 animatedItemsRef.get(j).setColor(animatedItemsRef.get(j).defaultColor); 00516 } 00517 } 00518 00519 00520 00521 00522 00526 // 00527 // METHODS FOR ADDING AND REMOVING ACTION AND TRAJECTORY INFORMATION 00528 // 00529 // 00530 00531 00538 public void displayAction(String identifier) 00539 { 00540 // reset everything 00541 clear(); 00542 addObjectWithChildren("'http://ias.cs.tum.edu/kb/ccrl2_semantic_map.owl#SemanticEnvironmentMap0'"); 00543 addObjectWithChildren("'http://ias.cs.tum.edu/kb/ias_map_addons.owl#table0'"); 00544 00545 00546 addObject("'http://ias.cs.tum.edu/kb/knowrob.owl#placemat1'"); 00547 addObject("'http://ias.cs.tum.edu/kb/ias_entities.owl#napkin1'"); 00548 addObject("'http://ias.cs.tum.edu/kb/ias_entities.owl#spoon1'"); 00549 addObject("'http://ias.cs.tum.edu/kb/ias_entities.owl#plate1'"); 00550 addObject("'http://ias.cs.tum.edu/kb/ias_entities.owl#fork1'"); 00551 addObject("'http://ias.cs.tum.edu/kb/ias_entities.owl#knife1'"); 00552 00553 try{ 00554 HashMap<String, Vector<String>> c = PrologInterface.executeQuery( 00555 "rdf_has("+identifier+", 'http://ias.cs.tum.edu/kb/knowrob.owl#startTime', S), " 00556 +"rdf_has("+identifier+", 'http://ias.cs.tum.edu/kb/knowrob.owl#endTime', E)"); 00557 00558 if(c==null) return; 00559 00560 String startTimeStr = (String)c.get("S").get(0); 00561 startTimeStr = startTimeStr.substring(1,startTimeStr.length()-1); 00562 00563 if(startTimeStr.contains("#")) { 00564 startTimeStr=startTimeStr.split("#")[1]; 00565 startTimeStr=startTimeStr.split("_")[1]; 00566 } 00567 System.out.println(startTimeStr); 00568 00569 float startTime = Float.parseFloat(startTimeStr); 00570 00571 00572 String endTimeStr = (String)c.get("E").get(0); 00573 endTimeStr = endTimeStr.substring(1,endTimeStr.length()-1); 00574 if(endTimeStr.contains("#")) { 00575 endTimeStr=endTimeStr.split("#")[1]; 00576 endTimeStr=endTimeStr.split("_")[1]; 00577 } 00578 float endTime = Float.parseFloat(endTimeStr); 00579 00580 00581 c = PrologInterface.executeQuery( 00582 "rdf_has(A, rdf:type, knowrob:'Posture-Configuration'), rdf_has(A, knowrob:bodyPartsUsed, 'left'), rdf_triple(knowrob:startTime, A, T)"); 00583 00584 if(c==null) return; 00585 00586 Vector<String> allTimePoints = c.get("T"); 00587 BodyPoseSequence skeleton = new BodyPoseSequence(); 00588 float[] poses = null; 00589 int totalFrames = 0; 00590 00591 // System.out.println("total timepoints: "+allTimePoints.size()+", start: "+startTime+", end: "+endTime); 00592 00593 for(String s : allTimePoints) { 00594 00595 00596 String timePointStr = s.substring(1, s.length()-1); 00597 timePointStr = timePointStr.substring(1,timePointStr.length()-1); 00598 if(timePointStr.contains("#")) { 00599 timePointStr=timePointStr.split("#")[1]; 00600 timePointStr=timePointStr.split("_")[1]; 00601 } 00602 float timePoint = Float.parseFloat(timePointStr); 00603 00604 if(timePoint >= startTime && timePoint <= endTime) { 00605 try{ 00606 HashMap<String, Vector<String>> frameInfo = PrologInterface.executeQuery( 00607 "rdf_triple(ias_human:postureAtTimePoint, "+s.toString()+", P)"); 00608 00609 if(frameInfo!=null) { 00610 if(frameInfo.get("P") == null || frameInfo.get("P").size() == 0){ 00611 if(poses != null){ 00612 skeleton.addPose(0, timePoint, "", poses); 00613 System.out.println("pose at point "+s.toString()+" not found; re-added previous pose."); 00614 } 00615 else 00616 { 00617 System.out.println("pose at point "+s.toString()+" not found."); 00618 } 00619 continue; 00620 } 00621 00622 String[] split = frameInfo.get("P").get(0).split("\\)-\\("); 00623 00624 poses = new float[84]; 00625 00626 for(int j=0;j<83;j++) { 00627 poses[j] = Float.parseFloat(split[j+4]); 00628 } 00629 poses[83] = Float.parseFloat(split[87].substring(0,split[87].length()-2)); 00630 skeleton.addPose(0, timePoint, "", poses); 00631 totalFrames++; 00632 //System.out.println("added pose at point: "+s.toString()); 00633 } 00634 }catch (Exception e) { 00635 e.printStackTrace(); 00636 System.out.println("ERROR adding point: "+s.toString()); 00637 } 00638 } 00639 00640 } 00641 00642 allItems.add(skeleton); 00643 animatedItemsRef.put("skeleton", skeleton); 00644 00645 numberFrames = totalFrames; 00646 00647 // add fromLocation and toLocation as colored spheres, if they are present 00648 c = PrologInterface.executeQuery( 00649 "rdf_triple('http://ias.cs.tum.edu/kb/knowrob.owl#fromLocation', "+identifier+", From)"); 00650 if(c!=null && c.get("From")!= null) { 00651 String fromLoc = (String)c.get("From").get(0); 00652 if(fromLoc!=null) { 00653 addObject(fromLoc); 00654 } 00655 } 00656 00657 c = PrologInterface.executeQuery( 00658 "rdf_triple('http://ias.cs.tum.edu/kb/knowrob.owl#toLocation', "+identifier+", To)"); 00659 if(c!=null && c.get("To")!=null) { 00660 String toLoc = (String)c.get("To").get(0); 00661 if(toLoc!=null) { 00662 addObject(toLoc); 00663 } 00664 } 00665 00666 } 00667 catch(NullPointerException e) 00668 { 00669 displayMessage("Action "+identifier+" not found."); 00670 drawBackground(); 00671 } 00672 catch(Exception e) 00673 { 00674 displayMessage("Error displaying Action "+identifier+"."); 00675 e.printStackTrace(); 00676 drawBackground(); 00677 } 00678 } 00679 00686 public void displayHumanTrajectory(String identifier, String handUsed) { 00687 Integer Occ=0, auxOcc=0; 00688 boolean band=true; 00689 int row=0, contP=0, col=0; 00690 float[][] Xp=new float[80][19]; 00691 float[][] Yp=new float[80][19]; 00692 float[][] Zp=new float[80][19]; 00693 00694 Trajectories traj = new Trajectories(); 00695 00696 HashMap<String, Vector<String>> o= PrologInterface.executeQuery(""+"handTrajectory("+handUsed+", "+identifier+", T, P, X, Y, Z)"); 00697 if(o==null) return; 00698 00699 Vector<String> pointID = o.get("P"); 00700 Vector<String> Xc = o.get("X"); 00701 Vector<String> Yc = o.get("Y"); 00702 Vector<String> Zc = o.get("Z"); 00703 00704 for (Object p: pointID){ 00705 String s_p=p.toString(); //example s_p=p_1_2_36 (Ep, Occ, Inst) 00706 String[] tokenP=s_p.split("_"); 00707 if (Occ.equals(Integer.parseInt(tokenP[2])) && band==true){ 00708 Xp[row][col]=Float.parseFloat(Xc.get(contP)); 00709 Yp[row][col]=Float.parseFloat(Yc.get(contP)); 00710 Zp[row][col]=Float.parseFloat(Zc.get(contP)); 00711 row=row+1; 00712 //System.out.println("Xp ="+Float.parseFloat(Xc.get(contP).toString())); 00713 } else { 00714 Occ=Integer.parseInt(tokenP[2]); 00715 if (Occ > auxOcc) { 00716 col=col+1; row=0; band=true; auxOcc=Occ; 00717 System.out.println("Occ=" +Occ); 00718 } else {band=false;} 00719 00720 } 00721 contP=contP+1; 00722 } 00723 System.out.println("columnas"+Xp[0].length); 00724 00725 for (int j=0;j<Xp[0].length;j++ ){ //number of columns from Xp 00726 //System.out.println("New traj"); 00727 for (int i=0;i<(Xp.length)-1; i++) { 00728 if (Xp[i][j]!=0.0 && Yp[i][j]!=0){ 00729 traj.addTraj(Xp[i][j], Yp[i][j], Zp[i][j]); 00730 //System.out.println("traj= "+Xp[i][j]); 00731 } 00732 } 00733 traj.addTraj(0, 0, 0); 00734 00735 } 00736 allItems.add(traj); 00737 animatedItemsRef.put("traj", traj); 00738 } 00739 00744 public void displayEyeTrajectory (String identifier) { 00745 Integer Occ=1, auxOcc=1; 00746 int col=0, contP=0 ; 00747 int[][] Xc, Yc; 00748 boolean band=true; 00749 00750 Trajectories traj = new Trajectories(); 00751 00752 HashMap<String, Vector<String>> o= PrologInterface.executeQuery(""+ "readEyeTrajectory("+identifier+", T, P, XCoor, YCoor)"); 00753 if(o==null) return; 00754 00755 Vector<String> pointId = o.get("P"); 00756 Vector<String> XCoor = o.get("XCoor"); 00757 Vector<String> YCoor = o.get("YCoor"); 00758 Xc= new int[35][4]; 00759 Yc= new int[35][4]; 00760 for (String p: pointId){ 00761 String s_p=p.toString(); //example s_p=p_1_0 00762 String[] tokenP=s_p.split("_"); 00763 // example: tokenP[0]=p, tokenP[1]=1 (occurrence), tokenP[2]=0 (instance) 00764 if (Occ.equals(Integer.parseInt(tokenP[1])) && band==true) { 00765 //Save the values of the coordinates in 2 vectors 00766 //displayMessage("instance_nr: "+ Integer.parseInt(tokenP[2])); 00767 Xc[Integer.parseInt(tokenP[2])][col] = Integer.parseInt(XCoor.get(contP)); 00768 Yc[Integer.parseInt(tokenP[2])][col] = Integer.parseInt(YCoor.get(contP)); 00769 //displayMessage("Xc["+Integer.parseInt(tokenP[2])+"]["+col+"]= "+Xc[Integer.parseInt(tokenP[2])][col]); 00770 00771 00772 } else { 00773 Occ=Integer.parseInt(tokenP[1]); //new occurrence_nr 00774 if (Occ>auxOcc) { 00775 col=Occ-1; band=true; auxOcc=Occ; //displayMessage("auxOcc: "+auxOcc); 00776 Xc[Integer.parseInt(tokenP[2])][col] = Integer.parseInt(XCoor.get(contP)); 00777 Yc[Integer.parseInt(tokenP[2])][col] = Integer.parseInt(YCoor.get(contP)); 00778 }else{ band=false;} 00779 } 00780 contP=contP+1; 00781 } 00782 00783 for (int j=0;j<Xc[0].length;j++ ){ 00784 for (int i=0;i<(Xc.length)-1; i++) { 00785 traj.addTraj(Xc[i][j], Yc[i][j], 0); 00786 00787 } 00788 } 00789 allItems.add(traj); 00790 animatedItemsRef.put("traj", traj); 00791 00792 } 00793 00800 public void displayActionFixedIdent(String identifier) 00801 { 00802 HashMap<String, Vector<String>> c = PrologInterface.executeQuery(""+ 00803 "readPostureSeqForAction("+identifier+", P, EPISODENR, INSTANCENR, TIME, BECX, BECY, BECZ, ULWX, ULWY, ULWZ, OLWX, OLWY, OLWZ, UBWX, UBWY, UBWZ, OBWX, OBWY, OBWZ, UHWX, UHWY, UHWZ, BRKX, BRKY, BRKZ, OHWX, OHWY, OHWZ, KOX, KOY, KOZ, SEHX, SEHY, SEHZ, OSLX, OSLY, OSLZ, USLX, USLY, USLZ, FULX, FULY, FULZ, FBLX, FBLY, FBLZ, OSRX, OSRY, OSRZ, USRX, USRY, USRZ, FURX, FURY, FURZ, FBRX, FBRY, FBRZ, SBLX, SBLY, SBLZ, OALX, OALY, OALZ, UALX, UALY, UALZ, HALX, HALY, HALZ, FILX, FILY, FILZ, SBRX, SBRY, SBRZ, OARX, OARY, OARZ, UARX, UARY, UARZ, HARX, HARY, HARZ, FIRX, FIRY, FIRZ)"); 00804 00805 if(c==null || c.get("TIME") == null) 00806 { 00807 drawBackground(); 00808 displayMessage("could not find Action "+identifier+""); 00809 numberFrames = 1; 00810 return; 00811 } 00812 00813 00814 Vector<String> times = c.get("TIME"); 00815 framesToTimes = new float[times.size()]; 00816 for(int i=0;i<framesToTimes.length;i++) framesToTimes[i] = Float.parseFloat(times.get(i)); 00817 00818 BodyPoseSequence skeleton = new BodyPoseSequence(); 00819 00820 float[][] poses = new float[times.size()][]; 00821 for(int i=0;i<poses.length;i++) poses[i] = new float[84]; 00822 String[] posIdents = "BECX, BECY, BECZ, ULWX, ULWY, ULWZ, OLWX, OLWY, OLWZ, UBWX, UBWY, UBWZ, OBWX, OBWY, OBWZ, UHWX, UHWY, UHWZ, BRKX, BRKY, BRKZ, OHWX, OHWY, OHWZ, KOX, KOY, KOZ, SEHX, SEHY, SEHZ, OSLX, OSLY, OSLZ, USLX, USLY, USLZ, FULX, FULY, FULZ, FBLX, FBLY, FBLZ, OSRX, OSRY, OSRZ, USRX, USRY, USRZ, FURX, FURY, FURZ, FBRX, FBRY, FBRZ, SBLX, SBLY, SBLZ, OALX, OALY, OALZ, UALX, UALY, UALZ, HALX, HALY, HALZ, FILX, FILY, FILZ, SBRX, SBRY, SBRZ, OARX, OARY, OARZ, UARX, UARY, UARZ, HARX, HARY, HARZ, FIRX, FIRY, FIRZ".split(", "); 00823 00824 for(int j=0;j<84;j++) { 00825 Vector<String> d = c.get(posIdents[j]); 00826 for(int i=0;i<d.size() && i<poses.length;i++) { 00827 poses[i][j] = Float.parseFloat(d.get(i)); 00828 } 00829 } 00830 00831 for(int i=0;i<poses.length;i++) 00832 skeleton.addPose(0, Float.parseFloat(times.get(i).toString()), "", poses[i]); 00833 00834 allItems.add(skeleton); 00835 animatedItemsRef.put("skeleton", skeleton); 00836 00837 //startTime = Double.parseDouble(times.get(0).toString()); 00838 //endTime = Double.parseDouble(times.get(times.size()-1).toString()); 00839 numberFrames = times.size(); 00840 00841 System.out.print("ALL DONE"); 00842 } 00843 00844 00845 00846 00847 00854 public void drawBackground() { 00855 clear(); 00856 // get the current semantic map 00857 HashMap<String, Vector<String>> tpe = PrologInterface.executeQuery( 00858 "rdf_has(SUBJECT, rdf:type, knowrob:'SemanticEnvironmentMap')"); 00859 String type = null; 00860 00861 // check if exists 00862 try{ 00863 type = tpe.get("SUBJECT").get(0); 00864 00865 } catch(Exception e) { 00866 displayMessage("Semantic map not found"); 00867 } 00868 addObjectWithChildren(type); 00869 } 00870 00871 00875 public void clear() { 00876 allItems.clear(); 00877 animatedItemsRef.clear(); 00878 numberFrames = 1; 00879 currentFrame = 0; 00880 grayLevelCounter = 0; 00881 } 00882 00883 00884 00885 00886 00887 00888 00892 // 00893 // INTERNAL HELPERS 00894 // 00895 00896 00897 private ItemBase getItem(String identifier) { 00898 00899 // make sure identifier is surrounded with single quotes: 00900 identifier = PrologInterface.addSingleQuotes(PrologInterface.removeSingleQuotes(identifier)); 00901 00902 // get type 00903 HashMap<String, Vector<String>> tpe = PrologInterface.executeQuery( 00904 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 00905 "OBJECTCLASS\\='http://www.w3.org/2002/07/owl#NamedIndividual'"); 00906 String type = null; 00907 00908 00909 // check if exists 00910 try{ 00911 type = tpe.get("OBJECTCLASS").get(0); 00912 } catch(Exception e) { 00913 displayMessage("item "+identifier+" not found"); 00914 return null; 00915 } 00916 00917 // ignore list (not displayable): 00918 if(type.equals("'http://ias.cs.tum.edu/kb/knowrob.owl#SemanticEnvironmentMap'") 00919 || type.equals("'http://ias.cs.tum.edu/kb/knowrob.owl#Vector'") 00920 || type.equals("'http://ias.cs.tum.edu/kb/knowrob.owl#WallOfAConstruction'") 00921 ) { 00922 return null; 00923 00924 } 00925 00926 if(type.endsWith("#OccupancyGridMap'")) { 00927 return new OccupancyGridMap(identifier); 00928 } 00929 00930 Matrix4d pose = null; 00931 Vector3d dim = null; 00932 00933 00934 double[] p = getOrientationOfItem(identifier); 00935 if(p!=null) { 00936 pose = new Matrix4d(p); 00937 } 00938 00939 double[] v = getDimensionsOfItem(identifier); 00940 if(v!=null) { 00941 dim = new Vector3d(v); 00942 } 00943 00944 // check whether CAD model is specified: 00945 ItemModel model = Properties.getModelOfItem(identifier); 00946 00947 00948 if (model != null && model.getParser()!=null) { 00949 CadModelItem it = new CadModelItem(pose, dim); 00950 it.name = identifier; 00951 it.setModel(model); 00952 return it; 00953 } 00954 00955 00956 // else: check if one of the simple types 00957 ItemBase it = itemForObjType(type); 00958 00959 if(it!=null) { 00960 00961 it.name = identifier; 00962 if(pose!=null) 00963 it.setPose(pose); 00964 00965 if(dim!=null) 00966 it.setDimensions((float)dim.x, (float)dim.y, (float)dim.z); 00967 00968 return it; 00969 00970 00971 } else { 00972 00973 // check if it is a storage facility, if it is: create; WITHOUT handles 00974 HashMap<String, Vector<String>> storage = PrologInterface.executeQuery( 00975 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 00976 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'StorageConstruct')"); 00977 if (storage !=null && storage.get("OBJECTCLASS") != null && storage.get("OBJECTCLASS").size() > 0) { 00978 00979 if(storage.get("OBJECTCLASS").get(0).endsWith("Cupboard'")) { 00980 it = new Cupboard(pose, dim); 00981 } else { 00982 it = new Drawer(pose, dim); 00983 } 00984 00985 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 00986 00987 it.defaultColor = convertColor(col, col, col, 170); 00988 it.setColor(it.defaultColor); 00989 it.name = identifier; 00990 00991 return it; 00992 } 00993 00994 00995 00996 // check if Table 00997 HashMap<String, Vector<String>> tables = PrologInterface.executeQuery( 00998 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 00999 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'Table-PieceOfFurniture')"); 01000 01001 if (tables !=null && tables.get("OBJECTCLASS") != null && tables.get("OBJECTCLASS").size() > 0) 01002 { 01003 it = new Table(pose, dim); 01004 01005 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01006 it.defaultColor = convertColor(col, col, col, 255); 01007 it.setColor(it.defaultColor); 01008 it.name = identifier; 01009 return it; 01010 } 01011 01012 01013 // check if it is a CounterTop 01014 HashMap<String, Vector<String>> counter = PrologInterface.executeQuery( 01015 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01016 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'CounterTop')"); 01017 01018 if (counter !=null && counter.get("OBJECTCLASS") != null && counter.get("OBJECTCLASS").size() > 0) { 01019 01020 it = new CounterTop(pose, dim); 01021 01022 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01023 it.defaultColor = convertColor(col, col, col, 170); 01024 it.setColor(it.defaultColor); 01025 it.name = identifier; 01026 01027 return it; 01028 } 01029 01030 01031 01032 HashMap<String, Vector<String>> building = PrologInterface.executeQuery( 01033 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01034 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'Building')"); 01035 01036 if(building !=null && building.get("OBJECTCLASS") != null && building.get("OBJECTCLASS").size() > 0) { 01037 01038 it = new Building(pose, dim); 01039 01040 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01041 it.defaultColor = convertColor(col, col, col, 255); 01042 it.setColor(it.defaultColor); 01043 it.name = identifier; 01044 01045 return it; 01046 } 01047 01048 01049 HashMap<String, Vector<String>> level = PrologInterface.executeQuery( 01050 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01051 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'LevelOfAConstruction')"); 01052 01053 if(level !=null && level.get("OBJECTCLASS") != null && level.get("OBJECTCLASS").size() > 0) { 01054 01055 it = new LevelOfAConstruction(pose, dim); 01056 01057 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01058 it.defaultColor = convertColor(col, col, col, 255); 01059 it.setColor(it.defaultColor); 01060 it.name = identifier; 01061 01062 return it; 01063 } 01064 01065 01066 01067 HashMap<String, Vector<String>> room = PrologInterface.executeQuery( 01068 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01069 "( rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'RoomInAConstruction');" + 01070 " rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'MultiRoomUnit') )"); 01071 01072 if(room !=null && room.get("OBJECTCLASS") != null && room.get("OBJECTCLASS").size() > 0) { 01073 01074 it = new RoomInAConstruction(pose, dim); 01075 01076 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01077 it.defaultColor = convertColor(col, col, col, 255); 01078 it.setColor(it.defaultColor); 01079 it.name = identifier; 01080 01081 return it; 01082 } 01083 01084 01085 01086 // HashMap<String, Vector<String>> place = PrologInterface.executeQuery( 01087 // "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01088 // "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'Place')"); 01089 // 01090 // if(place !=null && place.get("OBJECTCLASS") != null && place.get("OBJECTCLASS").size() > 0) { 01091 // 01092 // it = new Pose(new Matrix4d(pose), new Vector3d(0.35f,0.35f,0.0f)); 01093 // 01094 // int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01095 // it.defaultColor = convertColor(col, col, col, 255); 01096 // it.setColor(it.defaultColor); 01097 // it.name = identifier; 01098 // 01099 // return it; 01100 // } 01101 01102 01103 // check if it is some kind of box (e.g. Bed) 01104 HashMap<String, Vector<String>> box = PrologInterface.executeQuery( 01105 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01106 "( rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'ConstructionArtifact');" + 01107 " rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'Box-Container');" + 01108 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'FurniturePiece'))"); 01109 01110 if(box !=null && box.get("OBJECTCLASS") != null && box.get("OBJECTCLASS").size() > 0) { 01111 01112 it = new Box(pose, dim); 01113 01114 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01115 it.defaultColor = convertColor(col, col, col, 255); 01116 it.setColor(it.defaultColor); 01117 it.name = identifier; 01118 01119 return it; 01120 } 01121 01122 // check if it is a Door 01123 HashMap<String, Vector<String>> door = PrologInterface.executeQuery( 01124 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01125 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'Door')"); 01126 01127 if(door !=null && door.get("OBJECTCLASS") != null && door.get("OBJECTCLASS").size() > 0) { 01128 01129 it = new Door(pose, dim); 01130 it.defaultColor = convertColor(255, 175, 0, 255); 01131 it.setColor(it.defaultColor); 01132 it.name = identifier; 01133 01134 return it; 01135 } 01136 01137 // check if it is a cylinder 01138 HashMap<String, Vector<String>> cyl = PrologInterface.executeQuery( 01139 "rdf_has("+identifier+", rdf:type, OBJECTCLASS)," + 01140 "rdf_reachable(OBJECTCLASS, rdfs:subClassOf, knowrob:'Cylinder')," + 01141 "rdf_triple(knowrob:longitudinalDirection, C, Dir)," + 01142 "rdf_has(Dir, knowrob:vectorX, literal(type(xsd:'float',DirX)))," + 01143 "rdf_has(Dir, knowrob:vectorY, literal(type(xsd:'float',DirY)))," + 01144 "rdf_has(Dir, knowrob:vectorZ, literal(type(xsd:'float',DirZ)))"); 01145 01146 if(cyl !=null && cyl.get("OBJECTCLASS") != null && cyl.get("OBJECTCLASS").size() > 0) { 01147 01148 Vector3d dir = new Vector3d(Double.valueOf(cyl.get("DirX").get(0)), 01149 Double.valueOf(cyl.get("DirY").get(0)), 01150 Double.valueOf(cyl.get("DirZ").get(0))); 01151 01152 it = new Cone(pose, new Vector3d(), dir, 0.01f,0.01f,0.04f); 01153 it.defaultColor = convertColor(255, 225, 0, 255); 01154 it.setColor(it.defaultColor); 01155 it.name = identifier; 01156 01157 return it; 01158 } 01159 01160 } 01161 displayMessage("could not find how to add Item "+identifier+"\nType was: "+type); 01162 return null; 01163 01164 } 01165 01166 private double[] getDimensionsOfItem(String identifier) { 01167 try{ 01168 HashMap<String, Vector<String>> nfo = PrologInterface.executeQuery( 01169 "rdf_has("+identifier+",knowrob:widthOfObject,literal(type(_,_W)))," + 01170 "rdf_has("+identifier+",knowrob:heightOfObject,literal(type(_,_H))), " + 01171 "rdf_has("+identifier+",knowrob:depthOfObject,literal(type(_,_D))), " + 01172 "atom_to_term(_W,W,_), atom_to_term(_H,H,_), atom_to_term(_D,D,_)"); 01173 01174 return new double[] { 01175 Double.valueOf(nfo.get("D").get(0)), 01176 Double.valueOf(nfo.get("W").get(0)), 01177 Double.valueOf(nfo.get("H").get(0))}; 01178 01179 } catch(Exception e) { 01180 return null; 01181 } 01182 } 01183 01184 01185 private double[] getOrientationOfItem(String identifier) { 01186 try{ 01187 01188 // get orientation 01189 HashMap<String, Vector<String>> nfo = PrologInterface.executeQuery( 01190 "rdf_triple(knowrob:orientation,"+identifier+",Or), " + 01191 01192 "rdf_triple(knowrob:m00,Or,_M00l), util:strip_literal_type(_M00l, _M00), term_to_atom(M00,_M00)," + 01193 "rdf_triple(knowrob:m01,Or,_M01l), util:strip_literal_type(_M01l, _M01), term_to_atom(M01,_M01)," + 01194 "rdf_triple(knowrob:m02,Or,_M02l), util:strip_literal_type(_M02l, _M02), term_to_atom(M02,_M02)," + 01195 "rdf_triple(knowrob:m03,Or,_M03l), util:strip_literal_type(_M03l, _M03), term_to_atom(M03,_M03)," + 01196 01197 "rdf_triple(knowrob:m10,Or,_M10l), util:strip_literal_type(_M10l, _M10), term_to_atom(M10,_M10)," + 01198 "rdf_triple(knowrob:m11,Or,_M11l), util:strip_literal_type(_M11l, _M11), term_to_atom(M11,_M11)," + 01199 "rdf_triple(knowrob:m12,Or,_M12l), util:strip_literal_type(_M12l, _M12), term_to_atom(M12,_M12)," + 01200 "rdf_triple(knowrob:m13,Or,_M13l), util:strip_literal_type(_M13l, _M13), term_to_atom(M13,_M13)," + 01201 01202 "rdf_triple(knowrob:m20,Or,_M20l), util:strip_literal_type(_M20l, _M20), term_to_atom(M20,_M20)," + 01203 "rdf_triple(knowrob:m21,Or,_M21l), util:strip_literal_type(_M21l, _M21), term_to_atom(M21,_M21)," + 01204 "rdf_triple(knowrob:m22,Or,_M22l), util:strip_literal_type(_M22l, _M22), term_to_atom(M22,_M22)," + 01205 "rdf_triple(knowrob:m23,Or,_M23l), util:strip_literal_type(_M23l, _M23), term_to_atom(M23,_M23)," + 01206 01207 "rdf_triple(knowrob:m30,Or,_M30l), util:strip_literal_type(_M30l, _M30), term_to_atom(M30,_M30)," + 01208 "rdf_triple(knowrob:m31,Or,_M31l), util:strip_literal_type(_M31l, _M31), term_to_atom(M31,_M31)," + 01209 "rdf_triple(knowrob:m32,Or,_M32l), util:strip_literal_type(_M32l, _M32), term_to_atom(M32,_M32)," + 01210 "rdf_triple(knowrob:m33,Or,_M33l), util:strip_literal_type(_M33l, _M33), term_to_atom(M33,_M33)"); 01211 return new double[] { 01212 Double.valueOf(nfo.get("M00").get(0)), 01213 Double.valueOf(nfo.get("M01").get(0)), 01214 Double.valueOf(nfo.get("M02").get(0)), 01215 Double.valueOf(nfo.get("M03").get(0)), 01216 Double.valueOf(nfo.get("M10").get(0)), 01217 Double.valueOf(nfo.get("M11").get(0)), 01218 Double.valueOf(nfo.get("M12").get(0)), 01219 Double.valueOf(nfo.get("M13").get(0)), 01220 Double.valueOf(nfo.get("M20").get(0)), 01221 Double.valueOf(nfo.get("M21").get(0)), 01222 Double.valueOf(nfo.get("M22").get(0)), 01223 Double.valueOf(nfo.get("M23").get(0)), 01224 Double.valueOf(nfo.get("M30").get(0)), 01225 Double.valueOf(nfo.get("M31").get(0)), 01226 Double.valueOf(nfo.get("M32").get(0)), 01227 Double.valueOf(nfo.get("M33").get(0))}; 01228 } catch(Exception e) { 01229 displayMessage("No orientation found for: " + identifier); 01230 //e.printStackTrace(); 01231 return null; 01232 } 01233 } 01234 01235 01236 01237 01241 // 01242 // EVENT HANDLER 01243 // 01244 // 01245 // public void mousePressed(MouseEvent e) { 01246 // 01247 // // general: save mouse positions for calculating rotation and translation 01248 // if(e.getButton()==MouseEvent.BUTTON1) { 01249 // leftMouseX = e.getX(); 01250 // leftMouseY = e.getY(); 01251 // } else if(e.getButton()==MouseEvent.BUTTON3) { 01252 // rightMouseX = e.getX(); 01253 // rightMouseY = e.getY(); 01254 // } else if (e.getButton()==MouseEvent.BUTTON2) { 01255 // centerMouseY = e.getY(); 01256 // } 01257 // 01258 // 01259 // 01260 // // // ------------- menu stuff -------------- 01261 // // // play forward 01262 // // if(menu_human.mouseInTriangle(e.getX(), e.getY(), menu_human.xpl1, menu_human.ypl1, menu_human.xpl2, menu_human.ypl2, menu_human.xpl3, menu_human.ypl3)){ 01263 // // playingForward = true; 01264 // // timer.start(); 01265 // // } 01266 // // 01267 // // // pause 01268 // // else if(menu_human.mouseInRectangle(e.getX(), e.getY(), menu_human.xps, menu_human.yps, menu_human.widthps, menu_human.heightps)){ 01269 // // timer.stop(); 01270 // // } 01271 // // 01272 // // // play backward 01273 // // else if(menu_human.mouseInTriangle(e.getX(), e.getY(), menu_human.xrew1, menu_human.yrew1, menu_human.xrew2, menu_human.yrew2, menu_human.xrew3, menu_human.yrew3)){ 01274 // // playingForward = false; 01275 // // timer.start(); 01276 // // } 01277 // // 01278 // // // stop button 01279 // // else if(menu_human.mouseInRectangle(e.getX(), e.getY(), menu_human.xstop, menu_human.ystop, menu_human.widthstop, menu_human.heightstop)){ 01280 // // timer.stop(); 01281 // // currentFrame = 0; 01282 // // } 01283 // // 01284 // // // step forward 01285 // // else if(menu_human.mouseInRectangle(e.getX(), e.getY(), menu_human.xpls, menu_human.ypls, menu_human.widthpls, menu_human.heightpls)){ 01286 // // timer.stop(); 01287 // // currentFrame++; 01288 // // } 01289 // // 01290 // // // step backward 01291 // // else if(menu_human.mouseInRectangle(e.getX(), e.getY(), menu_human.xrews, menu_human.yrews, menu_human.widthrews, menu_human.heightrews)){ 01292 // // timer.stop(); 01293 // // currentFrame--; 01294 // // } 01295 // 01296 // 01297 // 01298 // 01299 // 01300 // if(currentFrame < 0) currentFrame = 0; 01301 // if(currentFrame>= numberFrames) currentFrame = numberFrames-1; 01302 // 01303 // 01304 // 01305 // 01306 // 01307 // 01308 // 01309 // redraw(); 01310 // } 01311 01312 public void delay(int millis) 01313 { 01314 01315 try { 01316 Thread.sleep(100); 01317 } catch (InterruptedException e) { 01318 } 01319 } 01320 01321 public void mouseClicked(MouseEvent e) { 01322 String clickedOn = getItemAt(e.getX(), e.getY()); 01323 displayMessage(clickedOn+""); 01324 if(clickedOn != null) { 01325 objectClickListener.mapObjectClicked(clickedOn); 01326 } 01327 01328 // code for on-click publisher 01329 // ros.pkg.std_msgs.msg.String m = new ros.pkg.std_msgs.msg.String(); 01330 // m.data = clickedOn; 01331 // clickPub.publish(m); 01332 01333 delay(100); 01334 redraw(); 01335 } 01336 01337 01338 // 01339 // 01340 // public void mouseReleased(MouseEvent e) { 01341 // 01342 // if(e.getButton()==MouseEvent.BUTTON1) { // reset the buffers 01343 // leftMouseX = -1.0f; 01344 // leftMouseY = -1.0f; 01345 // } else if(e.getButton()==MouseEvent.BUTTON3) { // reset the buffers 01346 // rightMouseX = -1.0f; 01347 // rightMouseY = -1.0f; 01348 // } else if (e.getButton()==MouseEvent.BUTTON2) { 01349 // centerMouseY = -1.0f; 01350 // } 01351 // redraw(); 01352 // } 01353 // 01354 // public void mouseDragged(MouseEvent e) { 01355 // 01356 // 01357 // if(leftMouseX != -1.0f) { // change rotation 01358 // yRotDisplay-= (e.getY()-leftMouseY) * 0.05; 01359 // xRotDisplay+= (e.getX()-leftMouseX) * 0.05; 01360 // leftMouseX = e.getX(); 01361 // leftMouseY = e.getY(); 01362 // 01363 // }else if(rightMouseX != -1.0f) { // change translation 01364 // yShiftDisplay+= (e.getY()-rightMouseY) * 0.5; 01365 // xShiftDisplay+= (e.getX()-rightMouseX) * 0.5; 01366 // rightMouseX = e.getX(); 01367 // rightMouseY = e.getY(); 01368 // 01369 // } else if (centerMouseY != -1.0f) { // zoom 01370 // zoomDisplay+= (e.getY()-centerMouseY) * 0.02; 01371 // if(zoomDisplay<0.01){zoomDisplay=0.01f;} 01372 // centerMouseY = e.getY(); 01373 // } 01374 // 01375 // redraw(); 01376 // } 01377 01378 01379 public void keyPressed(){ 01380 01381 switch(keyCode) { 01382 case RIGHT: 01383 currentFrame++; 01384 break; 01385 case LEFT: 01386 currentFrame--; 01387 break; 01388 case java.awt.event.KeyEvent.VK_PAGE_UP: 01389 currentFrame+=10; 01390 break; 01391 case java.awt.event.KeyEvent.VK_PAGE_DOWN: 01392 currentFrame-=10; 01393 timer.stop(); 01394 break; 01395 case java.awt.event.KeyEvent.VK_SPACE: 01396 if(timer.isRunning()) 01397 timer.stop(); 01398 else 01399 timer.start(); 01400 break; 01401 case KeyEvent.VK_C: 01402 clear(); 01403 break; 01404 case KeyEvent.VK_B: 01405 drawBackground(); 01406 break; 01407 case KeyEvent.VK_X: 01408 bufferFrame.setVisible(!bufferFrame.isVisible()); 01409 break; 01410 case KeyEvent.VK_Y: 01411 buffer.resetMatrix(); 01412 this.resetMatrix(); 01413 case KeyEvent.VK_P: 01414 this.record = true; 01415 break; 01416 case KeyEvent.VK_Q: 01417 cam.setRotations(-Math.PI/2,Math.PI/4,-Math.PI); 01418 cam.lookAt(0.0,0.0,0.0,cam.getDistance()); 01419 break; 01420 case KeyEvent.VK_E: 01421 cam.setRotations(-Math.PI,0.0,0.0); 01422 cam.lookAt(0.0,0.0,0.0,cam.getDistance()); 01423 break; 01424 case KeyEvent.VK_A: 01425 cam.rotateY(-ROTATE_Y_DELTA); 01426 break; 01427 case KeyEvent.VK_D: 01428 cam.rotateY(ROTATE_Y_DELTA); 01429 break; 01430 case KeyEvent.VK_W: 01431 float[] rpy = cam.getRotations(); 01432 float[] lat = cam.getLookAt(); 01433 //float[] pos = cam.getPosition(); 01434 double dist = cam.getDistance(); 01435 CameraState state = new CameraState(new Rotation(RotationOrder.XYZ, 01436 rpy[0], 01437 rpy[1], 01438 rpy[2]), 01439 new Vector3D((lat[0])* 0.75, 01440 (lat[1])* 0.75, 01441 (lat[2])* 0.75), 01442 dist); 01443 state.apply(this); 01444 cam.setState(state); 01445 break; 01446 case KeyEvent.VK_S: 01447 float[] rpy2 = cam.getRotations(); 01448 float[] lat2 = cam.getLookAt(); 01449 float[] pos2 = cam.getPosition(); 01450 double dist2 = cam.getDistance(); 01451 CameraState state2 = new CameraState(new Rotation(RotationOrder.XYZ, 01452 rpy2[0], 01453 rpy2[1], 01454 rpy2[2]), 01455 new Vector3D((lat2[0] + pos2[0])/2, 01456 (lat2[1] + pos2[1])/2, 01457 (lat2[2] + pos2[2])/2), 01458 dist2); 01459 state2.apply(this); 01460 cam.setState(state2); 01461 01462 break; 01463 case KeyEvent.VK_J: 01464 hint(DISABLE_DEPTH_SORT); 01465 break; 01466 case KeyEvent.VK_K: 01467 hint(ENABLE_DEPTH_SORT); 01468 break; 01469 01470 } 01471 if(currentFrame < 0) currentFrame = 0; 01472 if(currentFrame>= numberFrames) currentFrame = numberFrames-1; 01473 delay(100); 01474 redraw(); 01475 } 01476 01477 01478 01479 // //////////////////////////////////////////////////////////////////////////////////////////// 01480 // //////////////////////////////////////////////////////////////////////////////////////////// 01482 // 01483 // HELPER FUNCTIONS 01484 // 01485 01486 public void setViewParameters(float xShift, float yShift, float xRot, float yRot, float zoom) { 01487 this.xShiftDisplay = xShift; 01488 this.yShiftDisplay = yShift; 01489 this.xRotDisplay = xRot; 01490 this.yRotDisplay = yRot; 01491 this.zoomDisplay = zoom; 01492 } 01493 01494 // sort the array jointTrajectoriesData by time 01495 public ArrayList<Point[]> sortArray(ArrayList<Point[]> actionsArray){ 01496 01497 for(int i = 0; i < actionsArray.size()-1; i++){ 01498 for(int j = i+1; j < actionsArray.size(); j++){ 01499 if(actionsArray.get(i)[0].time > actionsArray.get(j)[0].time){ 01500 Point aux = new Point(); 01501 for (int l = 0; l < 28; l++){ 01502 aux = actionsArray.get(j)[l]; 01503 actionsArray.get(j)[l] = actionsArray.get(i)[l]; 01504 actionsArray.get(i)[l] = aux; 01505 } 01506 } 01507 } 01508 } 01509 return actionsArray; 01510 } 01511 01512 01513 public int[] makeColor(int r,int g,int b){ 01514 int[] color = new int[3]; 01515 color[0] = r; color[1] = g; color[2] = b; 01516 return color; 01517 } 01518 01519 01520 //fills the array colors with two colors for each action, one for the trajectory and one for the human pose 01521 public void setColors(){ 01522 01523 colors.add(makeColor(0,0,255)); 01524 colors.add(makeColor(30,144,255)); 01525 01526 colors.add(makeColor(0,255,255)); 01527 colors.add(makeColor(180,255,255)); 01528 01529 colors.add(makeColor(255,215,0)); 01530 colors.add(makeColor(238,221,130)); 01531 01532 colors.add(makeColor(250,128,114)); 01533 colors.add(makeColor(255,160,122)); 01534 01535 colors.add(makeColor(255,105,180)); 01536 colors.add(makeColor(255,228,225)); 01537 01538 colors.add(makeColor(186,85,211)); 01539 colors.add(makeColor(221,160,221)); 01540 } 01541 01542 final Timer timer = new Timer(40, new ActionListener() { 01543 public void actionPerformed(ActionEvent event) { 01544 int frameBefore = currentFrame; 01545 if(playingForward == true) currentFrame++; 01546 if(playingForward == false) currentFrame--; 01547 if(currentFrame < 0) currentFrame = 0; 01548 if(currentFrame>= numberFrames) currentFrame = numberFrames-1; 01549 if(currentFrame != frameBefore) redraw(); 01550 } 01551 }); 01552 01553 // menu for the visualization jointTrajectories 01554 public class MenuHuman{ 01555 01556 // tracking button 01557 int xtr = 10; int ytr = 10; 01558 int widthtr = 70; int heighttr = 20; 01559 int xtxt = 15; int ytxt = 15; 01560 int widthtxt = 60; int heighttxt = 10; 01561 01562 // rewind button 01563 int xrew1 = 90; int xrew2 = 115; int xrew3 = 115; 01564 int yrew1 = 20; int yrew2 = 10; int yrew3 = 30; 01565 01566 // pause button 01567 int xps = 125; int xps1 = 128; int xps2 = 137; 01568 int yps = 10; int yps1 = 10; int yps2 = 10; 01569 int widthps = 20; int widthps1 = 5; int widthps2 = 5; 01570 int heightps = 20; int heightps1 = 20; int heightps2 = 20; 01571 01572 01573 // play button 01574 int xpl1 = 155; int xpl2 = 155; int xpl3 = 180; 01575 int ypl1 = 10; int ypl2 = 30; int ypl3 = 20; 01576 01577 // stop button 01578 int xstop = 190; int ystop = 10; 01579 int widthstop = 20; int heightstop = 20; 01580 01581 // rewind stepwise 01582 int xrews = 220; int yrews = 10; 01583 int widthrews = 25; int heightrews = 20; 01584 01585 int xrews1 = 220; int xrews2 = 235; int xrews3 = 235; int xrews4 = 239; 01586 int yrews1 = 20; int yrews2 = 10; int yrews3 = 30; int yrews4 = 10; 01587 int widthrews4 = 5; int heightrews4 = 20; 01588 01589 // play stepwise 01590 int widthpls = 25; int heightpls = 20; int widthpls4 = 5; int heightpls4 = 20; 01591 01592 int xpls = 255; int xpls1 = 264; int xpls2 = 264; int xpls3 = 279; int xpls4 = 255; 01593 int ypls = 10; int ypls1 = 10; int ypls2 = 30; int ypls3 = 20; int ypls4 = 10; 01594 01595 01596 public void drawMenu(){ 01597 noStroke(); 01598 01599 fill(238,238,224); 01600 rect(xtr, ytr, widthtr, heighttr); 01601 fill(238,238,224); 01602 triangle(xrew1, yrew1, xrew2, yrew2, xrew3, yrew3); 01603 rect(xps1, yps1, widthps1, heightps1); 01604 rect(xps2, yps2, widthps2, heightps2); 01605 triangle(xpl1, ypl1, xpl2, ypl2, xpl3, ypl3); 01606 rect(xstop, ystop, widthstop, heightstop); 01607 triangle(xpls1, ypls1, xpls2, ypls2, xpls3, ypls3); 01608 rect(xpls4, ypls4, widthpls4, heightpls4); 01609 triangle(xrews1, yrews1, xrews2, yrews2, xrews3, yrews3); 01610 rect(xrews4, yrews4, widthrews4, heightrews4); 01611 01612 01613 fill(0,0,0);stroke(0); 01614 textFont(verdanaBold); 01615 textMode(SCREEN); 01616 textAlign(LEFT); 01617 String s = "Trajectory"; 01618 text(s, xtxt, ytxt, widthtxt, heighttxt); 01619 } 01620 01621 public boolean mouseInTriangle(int xm, int ym, int x1, int y1, int x2, int y2, int x3, int y3){ 01622 int fAB = (ym-y1)*(x2-x1) - (xm-x1)*(y2-y1); 01623 int fCA = (ym-y3)*(x1-x3) - (xm-x3)*(y1-y3); 01624 int fBC = (ym-y2)*(x3-x2) - (xm-x2)*(y3-y2); 01625 01626 if ((fAB*fBC > 0) && (fBC*fCA>0)) 01627 return true; 01628 return false; 01629 } 01630 01631 public boolean mouseInRectangle(int xm, int ym, int xr, int yr, int width, int height){ 01632 if ((xm >= xr) && (xm <= xr+width) && (ym >= yr) && (ym <= yr+height)) { 01633 return true; 01634 } else { 01635 return false; 01636 } 01637 } 01638 01639 public int trackingDialog(){ 01640 01641 String[] possibilities = {"BEC", "ULW", "OLW", "UBW", "OBW", "UHW", "BRK", "OHW", "KO", "SEH", "OSL", "USL", "FUL", "FBL", 01642 "OST", "USR", "FUR", "FBR", "SBL", "OAL", "UAL", "HAL", "FIL", "SBR", "OAR", "UAR", "HAR", "FIR"}; 01643 01644 01645 for(int i = 0; i < possibilities.length; i++){ 01646 for (int j = i+1; j < 28; j++){ 01647 if (possibilities[i].compareTo(possibilities[j]) > 0){ 01648 String aux = possibilities[i]; 01649 possibilities[i] = possibilities[j]; 01650 possibilities[j] = aux; 01651 } 01652 } 01653 } 01654 JOptionPane.showInputDialog(null, "Select the body part you want to track:\n","Customized Dialog", 01655 JOptionPane.PLAIN_MESSAGE, null, possibilities, ""); 01656 // TOFIX 01657 // ArrayList<Point[]> jointPositions = bodyPoseSeq.getSequence(); 01658 // if ((s != null) && (s.length() > 0)) 01659 // for (int i = 0 ; i < 28; i++){ 01660 // if (jointPositions.get(0)[i].name == s) 01661 // return i; 01662 // } 01663 return -1; 01664 } 01665 01666 } 01667 01668 public static int convertColor(int red, int green, int blue, int alpha) { 01669 return (((((alpha << 8) + red) << 8) + green) << 8) + blue; 01670 } 01671 01672 ItemBase itemForObjType(String type) { 01673 01675 // tableware 01676 01677 if(type.endsWith("#Cup'")) { 01678 return new Cup(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01679 01680 } else if(type.endsWith("#DrinkingMug'")) { // todo: make drinking mug item 01681 return new Cup(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01682 01683 } else if(type.endsWith("#DinnerPlate'")) { 01684 return new Plate(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01685 01686 } else if(type.endsWith("#Saucer'")) { 01687 return new Plate(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01688 01689 } else if (type.endsWith("#DrinkingGlass'")) { 01690 return new DrinkingGlass(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01691 01692 } else if (type.endsWith("#Bowl-Eating'")) { 01693 return new BowlEating(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01694 01695 } else if (type.endsWith("#DrinkingBottle'")) { 01696 return new Bottle(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.05f,0.05f,0.15f); 01697 01698 } else if (type.endsWith("#Kettle'")) { 01699 return new Kettle(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01700 01702 // silverware 01703 01704 } else if(type.endsWith("#DinnerFork'")) { 01705 return new Fork(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01706 01707 } else if(type.endsWith("#TableKnife'")) { 01708 return new Knife(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01709 01710 } else if(type.endsWith("#Knife'")) { // toso: make general knife item? 01711 return new Knife(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01712 01713 } else if(type.endsWith("#SoupSpoon'")) { 01714 return new Spoon(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01715 01716 01718 // serving and cooking 01719 01720 } else if(type.endsWith("#Sponge-CleaningImplement'")) { 01721 return new Box(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.05f,0.10f,0.05f); 01722 01723 } else if(type.endsWith("#Napkin'")) { 01724 return new Napkin(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01725 01726 } else if(type.endsWith("#PlaceMat'")) { 01727 return new PlaceMat(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01728 01729 } else if(type.endsWith("#Tray'")) { //todo: make Tray item 01730 return new PlaceMat(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01731 01732 } else if (type.endsWith("#Platter'")) { 01733 return new Platter(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01734 01735 } else if(type.endsWith("#CookingPot'")) { 01736 return new CookingPot(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01737 01738 } else if(type.endsWith("#Spatula'")) { 01739 return new Spatula(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01740 01741 } else if(type.endsWith("#PancakeMaker'")) { 01742 return new PancakeMaker(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01743 01744 01746 // breakfast consumables 01747 01748 } else if (type.endsWith("#Bread'")) { 01749 return new Bread(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01750 01751 } else if (type.endsWith("#Cheese'")) { 01752 return new Cheese(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01753 01754 } else if (type.endsWith("#Butter'")) { 01755 return new Cheese(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01756 01757 } else if (type.endsWith("#Sausage'")) { 01758 return new Sausage(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01759 01760 } else if (type.endsWith("#Cake'")) { 01761 return new Cake(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01762 01763 } else if (type.endsWith("#BreakfastCereal'")) { 01764 return new CerealBox(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01765 01766 } else if (type.endsWith("#PancakeMix'")) { 01767 return new PancakeMix(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01768 01769 } else if (type.endsWith("#Pancake'")) { 01770 return new Pancake(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01771 01772 } else if (type.endsWith("#Yogurt'")) { 01773 return new DrinkingGlass(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01774 01775 01777 // lunch/dinner consumables 01778 01779 } else if (type.endsWith("#Pizza'")) { 01780 return new Pizza(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01781 01782 } else if (type.endsWith("#Salad'")) { 01783 return new SaladBowl(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01784 01785 } else if (type.endsWith("#Pasta'")) { 01786 return new SaladBowl(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01787 01788 } else if (type.endsWith("#Soup'")) { 01789 return new SoupPlate(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01790 01791 01792 01794 // drinks 01795 01796 } else if (type.endsWith("#Water'")) { 01797 return new Bottle(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01798 01799 } else if (type.endsWith("#Pitcher'")) { 01800 return new Thermos(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01801 01802 } else if (type.endsWith("#Tea-Beverage'")) { 01803 return new Bread(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01804 01805 } else if (type.endsWith("#Coffee-Beverage'")) { 01806 return new Thermos(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01807 01808 } else if (type.endsWith("#Juice'")) { 01809 return new Tetrapak(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01810 01811 } else if (type.endsWith("#Tea-Iced'")) { 01812 return new Tetrapak(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01813 01814 } else if(type.endsWith("#Tetrapak'")) { 01815 return new Tetrapak(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01816 01817 } else if (type.endsWith("#CardboardBox'")) { 01818 return new Bread(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01819 01820 } else if (type.endsWith("#CowsMilk-Product'")) { 01821 return new Tetrapak(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01822 01823 } else if (type.endsWith("#Buttermilk'")) { 01824 return new Tetrapak(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01825 01826 01828 // furniture 01829 01830 } else if(type.endsWith("#Chair-PieceOfFurniture'")) { 01831 return new Chair(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01832 01833 } else if(type.endsWith("#Handle'")) { 01834 return new BoxHandle(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.03f,0.03f,0.03f); 01835 01836 } else if(type.endsWith("#ControlKnob'")) { 01837 return new Sphere(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.03f,0.03f,0.03f); 01838 01839 01840 } else if(type.endsWith("#HingedJoint'")) { 01841 HingedJoint h = new HingedJoint(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.03f,0.03f,0.03f); 01842 h.setColor(SemanticMapVisApplet.convertColor(70, 120, 255, 255)); 01843 return h; 01844 01845 } else if(type.endsWith("#PrismaticJoint'")) { 01846 PrismaticJoint h = new PrismaticJoint(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.03f,0.03f,0.03f); 01847 h.setColor(SemanticMapVisApplet.convertColor(70, 255, 120, 255)); 01848 return h; 01849 01851 // dummies 01852 01853 } else if(type.endsWith("#SpatialThing-Localized'")) { 01854 return new Ellipse(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0); 01855 01856 // } else if(type.endsWith("#Place'")) { 01857 // return new Ellipse(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.0f,0.0f,0f); 01858 01859 } else if(type.endsWith("#Point3D'")) { 01860 return new Sphere(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0.03f,0.03f,0.03f); 01861 } 01862 return null; 01863 01864 } 01865 01866 01867 01868 01869 } 01870 01871 01872 class EmptyCanvas extends Canvas { 01873 private int[] snapshot; 01874 public boolean drawSelf = false; 01875 private static final long serialVersionUID = 1L; 01876 public EmptyCanvas(int width, int height, String renderer) { 01877 super(); 01878 this.width = width; 01879 this.height = height; 01880 init(); 01881 snapshot = new int[width*height]; 01882 // noLoop(); 01883 try{super.size(width, height, PGraphics3D.P3D);}catch(RendererChangeException e) {}; 01884 noLoop(); 01885 //this.resize(width, height); 01886 } 01887 01888 01889 @Override 01890 public void draw() { 01891 if(drawSelf) 01892 for(int i=0;i<width;i++) 01893 for(int j=0;j<height;j++) 01894 set(i, j, snapshot[i*height+j]); 01895 }; 01896 // @Override 01897 // public void keyPressed() {}; 01898 // @Override 01899 // public void mousePressed(MouseEvent e) {}; 01900 // @Override 01901 // public void mouseReleased(MouseEvent e) {}; 01902 // @Override 01903 // public void mouseDragged(MouseEvent e) {}; 01906 @Override 01907 public void runMain() {}; 01908 @Override 01909 public void size(int width, int height, String renderer) {}; 01910 01911 01912 public void freeze() { 01913 for(int i=0;i<width;i++) 01914 for(int j=0;j<height;j++) 01915 snapshot[i*height+j] = get(i, j); 01916 drawSelf = true; 01917 }; 01918 01919 public void unFreeze() { 01920 drawSelf = false; 01921 } 01922 } 01923