Project: bml_lib License: BSD Dependencies: Used by: |
bml_lib/src/edu/wpi/hri/bml/behavior/FaceBehavior.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.bml.behavior; 00035 00036 import org.w3c.dom.Document; 00037 import org.w3c.dom.Element; 00038 00039 import edu.wpi.hri.bml.behavior.BehaviorEnums.BehaviorType; 00040 import edu.wpi.hri.bml.behavior.BehaviorEnums.EyebrowShape; 00041 import edu.wpi.hri.bml.behavior.BehaviorEnums.Eyelid; 00042 import edu.wpi.hri.bml.behavior.BehaviorEnums.FaceMovementType; 00043 import edu.wpi.hri.bml.behavior.BehaviorEnums.MouthShape; 00044 import edu.wpi.hri.bml.behavior.BehaviorEnums.Side; 00045 import edu.wpi.hri.log.Logger; 00046 import edu.wpi.hri.log.Logger.LoggerLevel; 00047 00053 public class FaceBehavior extends Behavior { 00054 00055 private static final String TYPE_ATTR = "type"; 00056 private static final String AMOUNT_ATTR = "amount"; 00057 private static final String SIDE_ATTR = "side"; 00058 private static final String AU_ATTR = "au"; 00059 private static final String EYEBROW_ATTR = "eyebrow-shape"; 00060 private static final String SEPARATION_ATTR = "separation"; 00061 private static final String LID_ATTR = "lid"; 00062 private static final String MOUTH_ATTR = "mouth-shape"; 00063 00064 private final FaceMovementType type; 00065 private final float amount; 00066 private final Side side; 00067 private final int au; 00068 private final EyebrowShape eyebrow; 00069 private final float separation; 00070 private final Eyelid eyelid; 00071 private final MouthShape mouth; 00072 00081 public FaceBehavior(Logger logger, Element elem) { 00082 super(logger, elem); 00083 00084 // ensure that the type is there 00085 if (elem.hasAttribute(TYPE_ATTR)) 00086 this.type = FaceMovementType.valueOf(elem.getAttribute(TYPE_ATTR)); 00087 else 00088 throw new IllegalArgumentException("Face requires a type"); 00089 00090 // then find the amount 00091 if (elem.hasAttribute(AMOUNT_ATTR)) 00092 this.amount = Float.parseFloat(elem.getAttribute(AMOUNT_ATTR)); 00093 else 00094 this.amount = 0.0f; 00095 00096 // then the side to use 00097 if (elem.hasAttribute(SIDE_ATTR)) 00098 this.side = Side.valueOf(elem.getAttribute(SIDE_ATTR)); 00099 else 00100 this.side = Side.BOTH; 00101 00102 // then the au 00103 if (elem.hasAttribute(AU_ATTR)) 00104 this.au = Integer.parseInt(elem.getAttribute(AU_ATTR)); 00105 else 00106 this.au = 0; 00107 00108 // then the eyebrows 00109 if (elem.hasAttribute(EYEBROW_ATTR)) 00110 this.eyebrow = EyebrowShape 00111 .valueOf(elem.getAttribute(EYEBROW_ATTR)); 00112 else 00113 this.eyebrow = EyebrowShape.FLAT; 00114 00115 // then the separation 00116 if (elem.hasAttribute(SEPARATION_ATTR)) 00117 this.separation = Float.parseFloat(elem 00118 .getAttribute(SEPARATION_ATTR)); 00119 else 00120 this.separation = 0.0f; 00121 00122 // then the eyelid 00123 if (elem.hasAttribute(LID_ATTR)) 00124 this.eyelid = Eyelid.valueOf(elem.getAttribute(LID_ATTR)); 00125 else 00126 this.eyelid = Eyelid.BOTH; 00127 00128 // finally the mouth 00129 if (elem.hasAttribute(MOUTH_ATTR)) 00130 this.mouth = MouthShape.valueOf(elem.getAttribute(MOUTH_ATTR)); 00131 else 00132 this.mouth = MouthShape.FLAT; 00133 00134 this.logger.debug(LoggerLevel.BEHAVIOR, "Created ... "); 00135 } 00136 00163 public FaceBehavior(Logger logger, String id, FaceMovementType type, 00164 float amount, Side side, int au, EyebrowShape eyebrow, 00165 int separation, Eyelid eyelid, MouthShape mouth, boolean required) { 00166 super(logger, id, required); 00167 this.type = type; 00168 this.amount = amount; 00169 this.side = side; 00170 this.au = au; 00171 this.eyebrow = eyebrow; 00172 this.separation = separation; 00173 this.eyelid = eyelid; 00174 this.mouth = mouth; 00175 this.logger.debug(LoggerLevel.BEHAVIOR, "Created ..."); 00176 } 00177 00190 public FaceBehavior(Logger logger, String id, FaceMovementType type, 00191 boolean required) { 00192 this(logger, id, type, 0.0f, null, 0, null, 0, null, null, required); 00193 } 00194 00198 public FaceMovementType getType() { 00199 return type; 00200 } 00201 00205 public float getAmount() { 00206 return amount; 00207 } 00208 00212 public Side getSide() { 00213 return side; 00214 } 00215 00219 public int getAu() { 00220 return au; 00221 } 00222 00226 public EyebrowShape getEyebrow() { 00227 return eyebrow; 00228 } 00229 00233 public float getSeparation() { 00234 return separation; 00235 } 00236 00240 public Eyelid getEyelid() { 00241 return eyelid; 00242 } 00243 00247 public MouthShape getMouth() { 00248 return mouth; 00249 } 00250 00251 @Override 00252 protected void appendAttributes(Document doc, Element elem) { 00253 // add in the type 00254 elem.setAttribute(TYPE_ATTR, this.type.toString()); 00255 00256 // add in the amount 00257 if (this.amount != 0.0f) 00258 elem.setAttribute(AMOUNT_ATTR, String.valueOf(this.amount)); 00259 00260 // add in the side 00261 if (this.side != null) 00262 elem.setAttribute(SIDE_ATTR, this.side.toString()); 00263 00264 // add in the au 00265 if (this.au != 0) 00266 elem.setAttribute(AU_ATTR, String.valueOf(this.au)); 00267 00268 // add in the eyebrow 00269 if (this.eyebrow != null) 00270 elem.setAttribute(EYEBROW_ATTR, this.eyebrow.toString()); 00271 00272 // add in the separation 00273 if (this.separation != 0.0f) 00274 elem.setAttribute(SEPARATION_ATTR, String.valueOf(this.separation)); 00275 00276 // add in the eyelid 00277 if (this.eyelid != null) 00278 elem.setAttribute(LID_ATTR, this.eyelid.toString()); 00279 00280 // add in the mouth 00281 if (this.mouth != null) 00282 elem.setAttribute(MOUTH_ATTR, this.mouth.toString()); 00283 } 00284 00285 @Override 00286 protected String getElementName() { 00287 return BehaviorType.FACE.elementName; 00288 } 00289 } |