View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d; 21 22 23 24 import org.jdom.*; 25 import javax.media.j3d.Transform3D; 26 import java.util.List; 27 28 /*** 29 * 30 * @author Fábio Roberto de Miranda e Carlos da Silva dos Santos 31 * @version 1.0 32 */ 33 final class VcViewXMLHandler extends VcObjectXMLHandler { 34 35 private static final String BackClipAttrib = "BackClipDistance"; 36 private static final String FrontClipAttrib = "FrontClipDistance"; 37 private static final String FOVAttrib = "FieldOfView"; 38 private static final String ProjectionAttrib = "ProjectionPolicy"; 39 private static final String WindowMoveAttrib = "WindowMovementPolicy"; 40 private static final String WindowResizeAttrib = "WindowResizePolicy"; 41 42 private VcView view; 43 44 VcViewXMLHandler() { 45 super(); 46 this.type = "VcView"; 47 } 48 49 Element createElement(VcObject obj){ 50 if(!(obj instanceof VcView)) return null; 51 element = super.createElement(obj); 52 view = (VcView) obj; 53 element.setAttribute(BackClipAttrib,Double.toString(view.getBackClipDistance())); 54 element.setAttribute(FrontClipAttrib,Double.toString(view.getFrontClipDistance())); 55 element.setAttribute(FOVAttrib,Double.toString(view.getFieldOfView())); 56 element.setAttribute(ProjectionAttrib,Integer.toString(view.getProjectionPolicy())); 57 element.setAttribute(WindowMoveAttrib,Integer.toString(view.getWindowMovementPolicy())); 58 element.setAttribute(WindowResizeAttrib,Integer.toString(view.getWindowResizePolicy())); 59 //element.setName(type); 60 return element; 61 } 62 63 VcObject createObject(Element el){ 64 if(!type.equals(el.getName())) return null; 65 view = new VcView(); 66 initializeObject(el,view); 67 double bcd,fcd,fov; 68 int pp,wmp,wrp; 69 try{ 70 bcd = el.getAttribute(BackClipAttrib).getDoubleValue(); 71 fcd = el.getAttribute(FrontClipAttrib).getDoubleValue(); 72 fov = el.getAttribute(FOVAttrib).getDoubleValue(); 73 pp = el.getAttribute(ProjectionAttrib).getIntValue(); 74 wmp = el.getAttribute(WindowMoveAttrib).getIntValue(); 75 wrp = el.getAttribute(WindowResizeAttrib).getIntValue(); 76 77 view.setBackClipDistance(bcd); 78 view.setFrontClipDistance(fcd); 79 view.setFieldOfView(fov); 80 view.setProjectionPolicy(pp); 81 view.setWindowMovementPolicy(wmp); 82 view.setWindowResizePolicy(wrp); 83 }catch(org.jdom.DataConversionException dce){ 84 dce.printStackTrace(); 85 } 86 return (VcObject) view; 87 } 88 89 void addObject(VcObject vcObject, J3DBase base){ 90 boolean defaultFlag = false; 91 if(!(vcObject instanceof VcView))return; 92 // checks whether the scene already constains an object 93 // by the same name 94 VcObject obj = base.getByLabel(vcObject.getLabel()); 95 if(obj!=null){ 96 if(obj instanceof VcView){ 97 // Default View cannot be deleted, so we just copy the transform 98 // from one object to another 99 if(obj.getLabel().equals("Default View")){ 100 defaultFlag = true; 101 Transform3D tempT3D = new Transform3D(); 102 vcObject.getTransforms(tempT3D); 103 obj.setTransform(tempT3D); 104 } 105 // if the camera is not default view 106 // we will remove it 107 else base.removeVcObject(obj); 108 } 109 // if object is not a camera we will change its name to 110 // avoid ambiguity 111 else obj.setLabel("_"+obj.getLabel()); 112 } 113 if(!defaultFlag) base.addView((VcView)vcObject); 114 } 115 116 }

This page was automatically generated by Maven