Displacer.java :  » 6.0-JDK-Modules » java-3d » com » db » hanim » Java Open Source

Java Open Source » 6.0 JDK Modules » java 3d 
java 3d » com » db » hanim » Displacer.java
/*
 * Copyright (c) 2000-2001 Silvere Martin-Michiellot All Rights Reserved.
 *
 * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
 * royalty free, license to use, but not to modify or redistribute this
 * software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Silvere Martin-Michiellot.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
 * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 *
 * @Author: Silvere Martin-Michiellot for Digital Biosphere
 * @Version: 1.1 (to stay in touch with h-anim)
 *
 */


package com.db.hanim;

import javax.vecmath.*;

/**
 * This class is to implement the H-Anim proposed Displacer. It's implementation for Java3D has been mimicked on the VRML97 field description.
 *
 * A displacer should be added to one and only one segment in a humanoid hierarchy. This condition is up to be checked by user but should be fairly rare that's why there is no reference to corresponding segment.
 *
 * @author Silvere Martin-Michiellot
 * @version 1.1
 */

public class Displacer {

  public static final int viseme = 1;
  public static final int expression = 2;
  public static final int open_jaw = 3;
  public static final int lower_t_midlip = 4;
  public static final int raise_b_midlip = 5;
  public static final int stretch_l_cornerlip = 6;
  public static final int stretch_r_cornerlip = 7;
  public static final int lower_t_lip_lm = 8;
  public static final int lower_t_lip_rm = 9;
  public static final int raise_b_lip_lm = 10;
  public static final int raise_b_lip_rm = 11;
  public static final int raise_l_cornerlip = 12;
  public static final int raise_r_cornerlip = 13;
  public static final int thrust_jaw = 14;
  public static final int shift_jaw = 15;
  public static final int push_b_lip = 16;
  public static final int push_t_lip = 17;
  public static final int depress_chin = 18;
  public static final int close_t_l_eyelid = 19;
  public static final int close_t_r_eyelid = 20;
  public static final int close_b_l_eyelid = 21;
  public static final int close_b_r_eyelid = 22;
  public static final int yaw_l_eyeball = 23;
  public static final int yaw_r_eyeball = 24;
  public static final int pitch_l_eyeball = 25;
  public static final int pitch_r_eyeball = 26;
  public static final int thrust_l_eyeball = 27;
  public static final int thrust_r_eyeball = 28;
  public static final int dilate_l_pupil = 29;
  public static final int dilate_r_pupil = 30;
  public static final int raise_l_i_eyebrow = 31;
  public static final int raise_r_i_eyebrow = 32;
  public static final int raise_l_m_eyebrow = 33;
  public static final int raise_r_m_eyebrow = 34;
  public static final int raise_l_o_eyebrow = 35;
  public static final int raise_r_o_eyebrow = 36;
  public static final int squeeze_l_eyebrow = 37;
  public static final int squeeze_r_eyebrow = 38;
  public static final int puff_l_cheek = 39;
  public static final int puff_r_cheek = 40;
  public static final int lift_l_cheek = 41;
  public static final int lift_r_cheek = 42;
  public static final int shift_tongue_tip = 43;
  public static final int raise_tongue_tip = 44;
  public static final int thrust_tongue_tip = 45;
  public static final int raise_tongue = 46;
  public static final int tongue_roll = 47;
  public static final int head_pitch = 48;
  public static final int head_yaw = 49;
  public static final int head_roll = 50;
  public static final int lower_t_midlip_o = 51;
  public static final int raise_b_midlip_o = 52;
  public static final int stretch_l_cornerlip_o = 53;
  public static final int stretch_r_cornerlip_o = 54;
  public static final int lower_t_lip_lm_o = 55;
  public static final int lower_t_lip_rm_o = 56;
  public static final int raise_b_lip_lm_o = 57;
  public static final int raise_b_lip_rm_o = 58;
  public static final int raise_l_cornerlip_o = 59;
  public static final int raise_r_cornerlip_o = 60;
  public static final int stretch_l_nose = 61;
  public static final int stretch_r_nose = 62;
  public static final int raise_nose = 63;
  public static final int bend_nose = 64;
  public static final int raise_l_ear = 65;
  public static final int raise_r_ear = 66;
  public static final int pull_l_ear = 67;
  public static final int pull_r_ear = 68;
  public static final int NonStandard = 69;

  public static final int not_a_default_viseme = 0;
  public static final int viseme_pbm = 1;
  public static final int viseme_fv = 2;
  public static final int viseme_th = 3;
  public static final int viseme_td = 4;
  public static final int viseme_kg = 5;
  public static final int viseme_ts = 6;
  public static final int viseme_sz = 7;
  public static final int viseme_nl = 8;
  public static final int viseme_r = 9;
  public static final int viseme_a = 10;
  public static final int viseme_e = 11;
  public static final int viseme_i = 12;
  public static final int viseme_q = 13;
  public static final int viseme_u = 14;

  public static final int not_a_default_expression = 0;
  public static final int joy = 1;
  public static final int sadness = 2;
  public static final int anger = 3;
  public static final int fear = 4;
  public static final int disgust = 5;
  public static final int surprise = 6;

  protected String displacerName;
  protected int[] coordIndex;
  protected Point3d[] displacements;

  protected int visemeselect = Displacer.not_a_default_viseme;
  protected int expressionselect = Displacer.not_a_default_expression;

  /**
   * Constructs a new Displacer
   * @param displacerName the name of the Displacer that describes in a human readable manner the Displacer
   */

  public Displacer (String displacerName) {

    super();
    this.setName(displacerName);
    coordIndex = new int[0];
    displacements = new Point3d[0];

  }

  /**
   * Gets the Displacer name that describes in a human readable manner the Displacer
   * @return the String name of this Displacer
   */
  public String getName () {

    return this.displacerName;

  }

  /**
   * Sets the Displacer name that describes in a human readable manner the Displacer
   * @param displacerName the name of this Displacer
   */
  public void setName (String displacerName) {

    this.displacerName = displacerName;

  }

  /**
   * Gets the Displacer Double array of index coordinates. Please consult H-Anim for the official description of this field.
   * @return the index coordinates.
   */
  public int[] getCoordIndex () {

    return this.coordIndex;

  }

  /**
   * Sets the Displacer Double array of index coordinates. Please consult H-Anim for the official description of this field.
   * @param coordIndex index coordinates.
   */
  public void setCoordIndex (int[] coordIndex) {

    this.coordIndex = coordIndex;

  }

  /**
   * Gets the Displacer Point3D array of displacements. Please consult H-Anim for the official description of this field.
   * @return the displacements.
   */
  public Point3d[] getDisplacements () {

    return this.displacements;

  }

  /**
   * Sets the Displacer Point3D array of displacements. Please consult H-Anim for the official description of this field.
   * @param displacements the displacements.
   */
  public void setDisplacements (Point3d[] displacements) {

    this.displacements = displacements;

  }

  /**
   * Gets the Displacer description for standard Displacers. See the methods setVisemeSelect() and setExpressionSelect() for special cases Displacer.viseme and Displacer.expression
   * @return the String official description for the corresponding Displacer
   */
  public static String getDisplacerIdentifierDescription(int value) {

    switch (value) {
      case Displacer.viseme:
      return new String("Set of values determining the mixture of two visemes for this frame (e.g. pbm, fv, th).");
      case Displacer.expression:
      return new String("A set of values determining the mixture of two facial expression.");
      case Displacer.open_jaw:
      return new String("Vertical jaw displacement (does not affect mouth opening).");
      case Displacer.lower_t_midlip:
      return new String("Vertical top middle inner lip displacement.");
      case Displacer.raise_b_midlip:
      return new String("Vertical bottom middle inner lip displacement.");
      case Displacer.stretch_l_cornerlip:
      return new String("Horizontal displacement of left inner lip corner.");
      case Displacer.stretch_r_cornerlip:
      return new String("Horizontal displacement of right inner lip corner.");
      case Displacer.lower_t_lip_lm:
      return new String("Vertical displacement of midpoint between left corner and middle of top inner lip.");
      case Displacer.lower_t_lip_rm:
      return new String("Vertical displacement of midpoint between right corner and middle of top inner lip.");
      case Displacer.raise_b_lip_lm:
      return new String("Vertical displacement of midpoint between left corner and middle of bottom inner lip.");
      case Displacer.raise_b_lip_rm:
      return new String("Vertical displacement of midpoint between right corner and middle of bottom inner lip.");
      case Displacer.raise_l_cornerlip:
      return new String("Vertical displacement of left inner lip corner.");
      case Displacer.raise_r_cornerlip:
      return new String("Vertical displacement of right inner lip corner.");
      case Displacer.thrust_jaw:
      return new String("Depth displacement of jaw.");
      case Displacer.shift_jaw:
      return new String("Side to side displacement of jaw.");
      case Displacer.push_b_lip:
      return new String("Depth displacement of bottom middle lip.");
      case Displacer.push_t_lip:
      return new String("Depth displacement of top middle lip.");
      case Displacer.depress_chin:
      return new String("Upward and compressing movement of the chin (like in sadness).");
      case Displacer.close_t_l_eyelid:
      return new String("Vertical displacement of top left eyelid.");
      case Displacer.close_t_r_eyelid:
      return new String("Vertical displacement of top right eyelid.");
      case Displacer.close_b_l_eyelid:
      return new String("Vertical displacement of bottom left eyelid.");
      case Displacer.close_b_r_eyelid:
      return new String("Vertical displacement of bottom right eyelid.");
      case Displacer.yaw_l_eyeball:
      return new String("Horizontal orientation of left eyeball.");
      case Displacer.yaw_r_eyeball:
      return new String("Horizontal orientation of right eyeball.");
      case Displacer.pitch_l_eyeball:
      return new String("Vertical orientation of left eyeball.");
      case Displacer.pitch_r_eyeball:
      return new String("Vertical orientation of right eyeball.");
      case Displacer.thrust_l_eyeball:
      return new String("Depth displacement of left eyeball.");
      case Displacer.thrust_r_eyeball:
      return new String("Depth displacement of right eyeball.");
      case Displacer.dilate_l_pupil:
      return new String("Dilation of left pupil.");
      case Displacer.dilate_r_pupil:
      return new String("Dilation of right pupil.");
      case Displacer.raise_l_i_eyebrow:
      return new String("Vertical displacement of left inner eyebrow.");
      case Displacer.raise_r_i_eyebrow:
      return new String("Vertical displacement of right inner eyebrow.");
      case Displacer.raise_l_m_eyebrow:
      return new String("Vertical displacement of left middle eyebrow.");
      case Displacer.raise_r_m_eyebrow:
      return new String("Vertical displacement of right middle eyebrow.");
      case Displacer.raise_l_o_eyebrow:
      return new String("Vertical displacement of left outer eyebrow.");
      case Displacer.raise_r_o_eyebrow:
      return new String("Vertical displacement of right outer eyebrow.");
      case Displacer.squeeze_l_eyebrow:
      return new String("Horizontal displacement of left eyebrow.");
      case Displacer.squeeze_r_eyebrow:
      return new String("Horizontal displacement of right eyebrow.");
      case Displacer.puff_l_cheek:
      return new String("Horizontal displacement of left cheek.");
      case Displacer.puff_r_cheek:
      return new String("Horizontal displacement of right cheek.");
      case Displacer.lift_l_cheek:
      return new String("Vertical displacement of left cheek.");
      case Displacer.lift_r_cheek:
      return new String("Vertical displacement of right cheek.");
      case Displacer.shift_tongue_tip:
      return new String("Horizontal displacement of tongue tip.");
      case Displacer.raise_tongue_tip:
      return new String("Vertical displacement of tongue tip.");
      case Displacer.thrust_tongue_tip:
      return new String("Depth displacement of tongue tip.");
      case Displacer.raise_tongue:
      return new String("Vertical displacement of tongue.");
      case Displacer.tongue_roll:
      return new String("Rolling of the tongue into U shape.");
      case Displacer.head_pitch:
      return new String("Head pitch angle from top of spine.");
      case Displacer.head_yaw:
      return new String("Head yaw angle from top of spine.");
      case Displacer.head_roll:
      return new String("Head roll angle from top of spine.");
      case Displacer.lower_t_midlip_o:
      return new String("Vertical top middle outer lip displacement.");
      case Displacer.raise_b_midlip_o:
      return new String("Vertical bottom middle outer lip displacement.");
      case Displacer.stretch_l_cornerlip_o:
      return new String("Horizontal displacement of left outer lip corner.");
      case Displacer.stretch_r_cornerlip_o:
      return new String("Horizontal displacement of right outer lip corner.");
      case Displacer.lower_t_lip_lm_o:
      return new String("Vertical displacement of midpoint between left corner and middle of top outer lip.");
      case Displacer.lower_t_lip_rm_o:
      return new String("Vertical displacement of midpoint between right corner and middle of top outer lip.");
      case Displacer.raise_b_lip_lm_o:
      return new String("Vertical displacement of midpoint between left corner and middle of bottom outer lip.");
      case Displacer.raise_b_lip_rm_o:
      return new String("Vertical displacement of midpoint between right corner and middle of bottom outer lip.");
      case Displacer.raise_l_cornerlip_o:
      return new String("Vertical displacement of left outer lip corner.");
      case Displacer.raise_r_cornerlip_o:
      return new String("Vertical displacement of right outer lip corner.");
      case Displacer.stretch_l_nose:
      return new String("Horizontal displacement of left side of nose.");
      case Displacer.stretch_r_nose:
      return new String("Horizontal displacement of right side of nose.");
      case Displacer.raise_nose:
      return new String("Vertical displacement of nose tip.");
      case Displacer.bend_nose:
      return new String("Horizontal displacement of nose tip.");
      case Displacer.raise_l_ear:
      return new String("Vertical displacement of left ear.");
      case Displacer.raise_r_ear:
      return new String("Vertical displacement of right ear.");
      case Displacer.pull_l_ear:
      return new String("Horizontal displacement of left ear.");
      case Displacer.pull_r_ear:
      return new String("Horizontal displacement of right ear.");
      default:
      return new String("");

    }

  }

  /**
   * Gets the Displacer description for expression Displacers. (there is no corresponding official description for viseme displacers that are phonemes in essence)
   * @return the String official description for the corresponding Displacer
   */
  public static String getDisplacerExpressionDescription(int value) {

    switch (value) {
      case Displacer.not_a_default_expression:
      return new String("");
      case Displacer.joy:
      return new String("The eyebrows are relaxed. The mouth is open and the mouth corners pulled back toward the ears.");
      case Displacer.sadness:
      return new String("The inner eyebrows are bent upward. The eyes are slightly closed. The mouth is relaxed.");
      case Displacer.anger:
      return new String("The inner eyebrows are pulled downward and together. The eyes are wide open. The lips are pressed against each other or opened to expose the teeth.");
      case Displacer.fear:
      return new String("The eyebrows are raised and pulled together. The inner eyebrows are bent upward. The eyes are tense and alert.");
      case Displacer.disgust:
      return new String("The eyebrows and eyelids are relaxed. The upper lip is raised and curled, often asymmetrically.");
      case Displacer.surprise:
      return new String("The eyebrows are raised. The upper eyelids are wide open, the lower relaxed. The jaw is opened.");
      default:
      return new String("");
    }

  }

  /**
   * When the Displacer is a viseme, and setVisemeSelect() has been applied, the corresponding viseme is retrieved.
   * @return the viseme that precisely defines this displacer (if you are using this Diplacer as a viseme)
   */
  public int getVisemeSelect() {
    //name of the displacer must contain expression otherwise returns Displacer.not_a_default_viseme

    if (contains(this.getName(),"viseme")) {
      return visemeselect;
    } else
    return Displacer.not_a_default_viseme;

  }

  /**
   * If you are using this Diplacer as a viseme use this method to describe the precise viseme you want to use.
   * @param value the viseme that precisely defines this displacer
   */
  public void setVisemeSelect(int value) {
    //name of the displacer must contain viseme otherwise nothing happens

    if (contains(this.getName(),"viseme")) {
      visemeselect = value;
    }

  }

  /**
   * When the Displacer is an expression, and setVisemeSelect() has been applied, the corresponding expression is retrieved.
   * @return the expression that precisely defines this displacer (if you are using this Diplacer as an expression)
   */
  public int getExpressionSelect() {
    //name of the displacer must contain expression otherwise returns Displacer.not_a_default_expression

    if (contains(this.getName(),"expression")) {
      return expressionselect;
    } else
    return Displacer.not_a_default_expression;

  }

  /**
   * If you are using this Diplacer as an expression use this method to describe the precise expression you want to use.
   * @param value the expression that precisely defines this displacer
   */
  public void setExpressionSelect(int value) {
    //name of the displacer must contain expression otherwise nothing happens

    if (contains(this.getName(),"expression")) {
      expressionselect = value;
    }

  }

  private boolean contains (String string1, String string2) {
    //returns true if string1 contains string2 (ex: orbite contains or) otherwise false

    boolean found;
    int i;
    int margin;

    found = false;
    i=0;
    margin = string1.length()-string2.length();
    while (((margin-i)>=0) && (!found)) {
      found = string1.regionMatches(i, string2, 0, string2.length());
      i++;
    }

    return found;

  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.