Class Segment

java.lang.Object
  |
  +--Segment

public class Segment
extends java.lang.Object

Author:
Erhan Oztop, 2001-2002

Source code by Erhan Oztop (erhan@atr.co.jp)
Copyright August 2002 via
University of Southern California Ph.D. publication copyright
This class is the basis for joint connected objects. Even though the class hierarcy doesn't show the connection, Object3d is intimately connected to Segment. Currently Object3d can have only one segment but in future implementations Object3d may contain multiple segments. The Segment structure is highly recursive. Most of the functions operate in a recursive fashion. The main idea is a segment is limb attached to a parent via a joint. All the children will affected if a movement occurs in that joint. see the sample .seg file used for constructing segments.
See Also:
Object3d, Point3d, VA

Field Summary
 double beta
           
(package private)  java.awt.Button beta_bt
           
(package private)  java.awt.Label beta_lb
           
(package private)  java.awt.Scrollbar beta_sb
           
(package private)  java.awt.Label beta_txt
           
 boolean blocked
          When the joint cant turn, e.g.
 Segment[] child
          Array of child segments.
(package private)  int dbeta
           
 double force
           
 int id
          unique number for this segment
 Point3d joint_axis
          The rotation axis of this segment.
 java.awt.Point joint_axis2d
          The projected position of the joint axis.
 Point3d joint_pos
          The 3d location of the joint.
 java.awt.Point joint_pos2d
          The projected position of the joint.
 boolean jointconstraint
           
 java.lang.String label
          The label of the segment.
 Point3d limb_pos
          The 3d location of the end of the segment.
 java.awt.Point limb_pos2d
          The projected position of the end of the segment.
 double linForce
          the following two are the components of the force when acting on a rigid body
(package private)  int lwid
           
 double maxbeta
           
 double minbeta
           
 int noch
          number of children this segment has.
 int nochSave
          used for truncating the kinematics chain and pasting on later.
(package private)  boolean nodraw
          The segments which will not be draw are marked with this one.
private static int PAR
          Field number for parent in .seg file
 Segment parent
          parent segment.
 Plane[] plane
          Array of planes.
(package private)  int planec
          # of planes in this segment.
 Point3d[] pool
          Array of 3d points for this segment
 java.awt.Point[] pool2d
          Array of (projected) 2d points for this segment
(package private)  int poolc
          number of points in the pool[]
 double Rad
          The is the radius used to extend the skeletal joint system into solid cylindirical system.
 double rotForce
           
(package private)  java.awt.Panel savePan
           
 Segment[] seg
          All the segments under the topmost.
(package private)  java.awt.Panel seg_pan
           
(package private)  int segc
           
 double segmentdepth
          The view depth of this segment (no effect of children) imposed.
private  java.awt.Shape shape
          This must be redundant.
 int sidec
          The is the # of sides used to extend the skeletal joint system into solid cylindirical system.
 double suggested_F
          .seg file suggested Eye parameters
 double suggested_Fz
          .seg file suggested Eye parameters
 double suggested_scale
          .seg file suggested Eye parameters
 double torque
          The force the joint receives.
(package private)  int totalplanec
          # of total planes as itself+descendants -not sure of validity-
 int userTag
           
 Point3d X
          The total angle the joint rotated in radians.
 Point3d Y
          The total angle the joint rotated in radians.
 Point3d Z
          The total angle the joint rotated in radians.
 
Constructor Summary
Segment(java.lang.String s)
          This is the constructor used to create a segment (and its descendants!) from a .seg file.
Segment(java.lang.String s, int extrapool, int extraplane)
           
Segment(java.lang.String lb, int ident, int MAXchild, Point3d jpos, Point3d lpos, Point3d ax, int axistype)
          Create the specified Segment.
Segment(java.lang.String lb, int ident, int MAXchild, Point3d jpos, Point3d lpos, Point3d ax, int axistype, int pointcount, int planecount)
          Create the specified Segment
 
Method Summary
private  void _list(java.util.Vector v, Segment seg)
          Used by list() to fetch the segments and its descendants.
private  int _outputOBJ(Segment parent, int parentlwid, int lwidfromup)
           
 void _rotateJoint(Point3d place, Point3d around, double T)
          This method is called to rotate a JOINT because of a parent segment rotation.
 void _rotateLimb(Point3d place, Point3d around, double T)
          This method rotates the limb (limb_pos) around the joint.
private  void _rotateSolid(Point3d place, Point3d around, double T)
          This method rotates the solid system (pool[]).
 void _translate(double dx, double dy, double dz)
          Translates the segment and its descendant by dx,dy,dz.
 void _translate(Point3d delta)
           
 void _updateFrame()
           
 int add2pool(Point3d p, java.awt.Point pp)
          Add 3d and corresponding 2d point to the point pool.
 void addChild(Segment kid)
          Add the kid segment to this segment
 int addPlane(Point3d P0, Point3d P1, Point3d P2, Point3d P3, java.awt.Point r0, java.awt.Point r1, java.awt.Point r2, java.awt.Point r3)
          Add the plane given by pointer (from pool[]) with default color.
 int addPlane(Point3d P0, Point3d P1, Point3d P2, Point3d P3, java.awt.Point r0, java.awt.Point r1, java.awt.Point r2, java.awt.Point r3, int fillcol, int linecol)
          Add the plane given by by pointer (from pool[]) with given fill and line color.
 int addPlane(Point3d P0, Point3d P1, Point3d P2, Point3d P3, java.awt.Point r0, java.awt.Point r1, java.awt.Point r2, java.awt.Point r3, int fillcol, int linecol, int side, int texture)
           
 int addPlane(java.util.Vector v)
          Add the plane defined by vector of 3d,2d pairs
 int addPlane(java.util.Vector v, int fillcol, int linecol)
          Add the plane defined by vector of 3d,2d pairs
 int addPlane(java.util.Vector v, int fillcol, int linecol, int side, int texture)
          Add the plane defined by vector of 3d,2d pairs
 void applyForce(Point3d F)
           
 void constructSegment(java.lang.String lb, int ident, int MAXchild, Point3d jpos, Point3d lpos, Point3d ax, int axistype)
          calls constructSegment with 40 points and 20 planes.
 void constructSegment(java.lang.String lb, int ident, int MAXchild, Point3d jpos, Point3d lpos, Point3d ax, int MAXpoint, int MAXplane, int axistype)
          Sets up the variables and the arrays required to hold this segment.
 double cosineTo(Segment other)
          returns the cosine of the angle between this limb and the other
 double cosineTo2d(Segment other)
          returns the cosine of the angle between this projected limb and the other
 void disablePanel()
           
private  boolean easy_num(java.lang.String u)
           
 void enablePanel()
           
 Segment getJoint(java.lang.String lb)
          Searches the segment for the labeled segment and returns the refrence.
 int getuserTaget()
           
(package private)  double limblen()
          returns the length of this segment |limb_pos-joint_pos|.
 void limbpoints2pool(java.util.Vector v)
           
 void limbpoints2pool(java.util.Vector v, Point3d orig)
          Adds the points defined in the segment file into the point pool.
 java.util.Vector list()
          Returns a vector of segments including this and its descendants.
(package private)  java.awt.Panel makePanel(java.lang.String s)
           
 void mirror()
           
 void moveSegment(double rate)
           
 void movetoy(Point3d newposition)
          Moves the segment (and descendants) to a new position
static java.io.DataInputStream openfileREAD(java.lang.String fn)
          open file for read.
static java.io.DataOutputStream openfileWRITE(java.lang.String fn)
          open file for write.
private  void outlineOBJ(int son, int par)
           
private  int outpointOBJ()
           
 void outputOBJ()
           
 void print()
          Recersively prints the segment.
 void printJointAngles()
          Recersively prints the joint angles.
 void project(Eye eye)
          Project limb_pos, joint_pos (the skeletal system) using eye.
 void projectaxis(Eye eye)
          project the joint_axis using eye.
 void projectSolid(Eye eye)
          Project the pool/plane system points to pool2d.
 void pullTo(Point3d target)
           
 Segment readSegment(java.lang.String fn, int extrapool, int extraplane)
          Reads a .seg file and creates and returns a segment build from the file.
private  void recprint(Segment seg)
          Recersively prints the segment.
 void resetJoints()
          Recursively reset the joint angles to zero.
private  int resolve(java.lang.String u, java.util.Vector vlimbs, java.util.Vector labels)
           
 void restoreChildren()
           
 void rotateEachJoint(double T)
          This method rotates this+descendant segments joints by T radians.
 void rotateJoint(double T)
           
 void scale(double sc)
          Scales the segment and its descendant by sc.
 void scale(Point3d place, double sc)
          Scales the segment and its descendant by sc taking place as the origin.
 int setTotalplanec()
          Returns and SETS the totalplanec of the segments
 void setupPlane(int nplane)
           
 void setupPlane(int nplane, int extra)
           
 void setupPool(java.util.Vector pnts)
           
 void setupPool(java.util.Vector pnts, int extra)
           
 void setupSolid(int c, double R, boolean recursive)
           
 void setupSolid(Segment root, int c, double R, boolean recursive)
          This method extends the skeletal system (joint_pos-limb_pos) to a cylinderical form.
 void setuserTag(int what, boolean recursive)
           
 java.lang.String str()
          Returns a string describing the segment.
 void truncateChildren()
           
 void unBlock()
           
(package private)  void unmakePanel()
           
(package private)  void update_panel()
           
 void updateAllPanel()
          This method rotates this segment's joint by T radians.
 void updateDepth(Eye eye, int mode)
           
 void updateFrame()
           
 void updateGeom()
           
 void vplanes2plane(java.util.Vector v)
           
 void Xrot(double t)
          rotate segment tree around X axis.
 void Yrot(double t)
          rotate segment tree around Y axis.
 void Zrot(double t)
          rotate segment tree around Z axis.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

id

public int id
unique number for this segment

noch

public int noch
number of children this segment has.

child

public Segment[] child
Array of child segments.

parent

public Segment parent
parent segment. It is null for the root segment.

nochSave

public int nochSave
used for truncating the kinematics chain and pasting on later.

joint_axis

public Point3d joint_axis
The rotation axis of this segment. null means the joint is fixed.

limb_pos

public Point3d limb_pos
The 3d location of the end of the segment.

joint_pos

public Point3d joint_pos
The 3d location of the joint.

joint_axis2d

public java.awt.Point joint_axis2d
The projected position of the joint axis. This is for display purposes.

limb_pos2d

public java.awt.Point limb_pos2d
The projected position of the end of the segment.

userTag

public int userTag

joint_pos2d

public java.awt.Point joint_pos2d
The projected position of the joint.

X

public Point3d X
The total angle the joint rotated in radians. It always reflects the the angle of the joint from the inital created orientation. note that Segment itself does not check the limits. An upper module like Object3d or Hand should check it.

Y

public Point3d Y
The total angle the joint rotated in radians. It always reflects the the angle of the joint from the inital created orientation. note that Segment itself does not check the limits. An upper module like Object3d or Hand should check it.

Z

public Point3d Z
The total angle the joint rotated in radians. It always reflects the the angle of the joint from the inital created orientation. note that Segment itself does not check the limits. An upper module like Object3d or Hand should check it.

beta

public double beta

minbeta

public double minbeta

maxbeta

public double maxbeta

jointconstraint

public boolean jointconstraint

blocked

public boolean blocked
When the joint cant turn, e.g. hit to object

torque

public double torque
The force the joint receives. Force system not implemented yet.

force

public double force

linForce

public double linForce
the following two are the components of the force when acting on a rigid body

rotForce

public double rotForce

label

public java.lang.String label
The label of the segment. This label will be filled form the .seg file and can be used to get refrence to the segment.

Rad

public double Rad
The is the radius used to extend the skeletal joint system into solid cylindirical system.

segmentdepth

public double segmentdepth
The view depth of this segment (no effect of children) imposed.

sidec

public int sidec
The is the # of sides used to extend the skeletal joint system into solid cylindirical system. 4 will make extend the skeletal system into rectangular prisims.

seg

public Segment[] seg
All the segments under the topmost. Valid only for the topmost segment. The list also includes the topmost as the 0th element. The order in seg[] correspondances to the ID's of the segments. Also this is the appearance order in .seg file

segc

int segc

plane

public Plane[] plane
Array of planes. Only the topmost of a segment should use this field.

planec

int planec
# of planes in this segment.

totalplanec

int totalplanec
# of total planes as itself+descendants -not sure of validity-

pool

public Point3d[] pool
Array of 3d points for this segment

pool2d

public java.awt.Point[] pool2d
Array of (projected) 2d points for this segment

poolc

int poolc
number of points in the pool[]

nodraw

boolean nodraw
The segments which will not be draw are marked with this one. This happnes when you need multiple axis on one point (like the wrist). You just want the rotations not to draw the joint. It is a nice trick to simulate ball joints. By default all the limb-joint will be drawn.

shape

private java.awt.Shape shape
This must be redundant. It used to be used to hold non-joint simple 3d objects. Even though when the segment file is read the shape parsing is done, the created shape never gets attached to segment. In the future, either it will be removed from segment or be part of segment system.
See Also:
Shape

lwid

int lwid

suggested_scale

public double suggested_scale
.seg file suggested Eye parameters

suggested_F

public double suggested_F
.seg file suggested Eye parameters

suggested_Fz

public double suggested_Fz
.seg file suggested Eye parameters

PAR

private static final int PAR
Field number for parent in .seg file

seg_pan

java.awt.Panel seg_pan

savePan

java.awt.Panel savePan

beta_sb

java.awt.Scrollbar beta_sb

beta_txt

java.awt.Label beta_txt

beta_lb

java.awt.Label beta_lb

beta_bt

java.awt.Button beta_bt

dbeta

int dbeta
Constructor Detail

Segment

public Segment(java.lang.String lb,
               int ident,
               int MAXchild,
               Point3d jpos,
               Point3d lpos,
               Point3d ax,
               int axistype,
               int pointcount,
               int planecount)
Create the specified Segment
See Also:
constructSegment

Segment

public Segment(java.lang.String lb,
               int ident,
               int MAXchild,
               Point3d jpos,
               Point3d lpos,
               Point3d ax,
               int axistype)
Create the specified Segment. Point and plane counts are loaded defaults.
See Also:
constructSegment

Segment

public Segment(java.lang.String s)
This is the constructor used to create a segment (and its descendants!) from a .seg file.
See Also:
readSegment

Segment

public Segment(java.lang.String s,
               int extrapool,
               int extraplane)
Method Detail

truncateChildren

public void truncateChildren()

restoreChildren

public void restoreChildren()

_updateFrame

public void _updateFrame()

updateFrame

public void updateFrame()

pullTo

public void pullTo(Point3d target)

applyForce

public void applyForce(Point3d F)

moveSegment

public void moveSegment(double rate)

outpointOBJ

private int outpointOBJ()

outlineOBJ

private void outlineOBJ(int son,
                        int par)

outputOBJ

public void outputOBJ()

_outputOBJ

private int _outputOBJ(Segment parent,
                       int parentlwid,
                       int lwidfromup)

unBlock

public void unBlock()

setupSolid

public void setupSolid(int c,
                       double R,
                       boolean recursive)

setupSolid

public void setupSolid(Segment root,
                       int c,
                       double R,
                       boolean recursive)
This method extends the skeletal system (joint_pos-limb_pos) to a cylinderical form. First argument specifies the number of sides, the next is the radius of the cylinder. The recursive option let's the function to descent into the children segments with same parameters

setupPool

public void setupPool(java.util.Vector pnts)

setupPool

public void setupPool(java.util.Vector pnts,
                      int extra)

setupPlane

public void setupPlane(int nplane,
                       int extra)

setupPlane

public void setupPlane(int nplane)

limbpoints2pool

public void limbpoints2pool(java.util.Vector v)

limbpoints2pool

public void limbpoints2pool(java.util.Vector v,
                            Point3d orig)
Adds the points defined in the segment file into the point pool.

updateGeom

public void updateGeom()

updateDepth

public void updateDepth(Eye eye,
                        int mode)

vplanes2plane

public void vplanes2plane(java.util.Vector v)

setTotalplanec

public int setTotalplanec()
Returns and SETS the totalplanec of the segments

constructSegment

public void constructSegment(java.lang.String lb,
                             int ident,
                             int MAXchild,
                             Point3d jpos,
                             Point3d lpos,
                             Point3d ax,
                             int axistype)
calls constructSegment with 40 points and 20 planes. -check code-

constructSegment

public void constructSegment(java.lang.String lb,
                             int ident,
                             int MAXchild,
                             Point3d jpos,
                             Point3d lpos,
                             Point3d ax,
                             int MAXpoint,
                             int MAXplane,
                             int axistype)
Sets up the variables and the arrays required to hold this segment.

addChild

public void addChild(Segment kid)
Add the kid segment to this segment

add2pool

public int add2pool(Point3d p,
                    java.awt.Point pp)
Add 3d and corresponding 2d point to the point pool.

addPlane

public int addPlane(java.util.Vector v)
Add the plane defined by vector of 3d,2d pairs

addPlane

public int addPlane(java.util.Vector v,
                    int fillcol,
                    int linecol)
Add the plane defined by vector of 3d,2d pairs

addPlane

public int addPlane(java.util.Vector v,
                    int fillcol,
                    int linecol,
                    int side,
                    int texture)
Add the plane defined by vector of 3d,2d pairs

addPlane

public int addPlane(Point3d P0,
                    Point3d P1,
                    Point3d P2,
                    Point3d P3,
                    java.awt.Point r0,
                    java.awt.Point r1,
                    java.awt.Point r2,
                    java.awt.Point r3)
Add the plane given by pointer (from pool[]) with default color.

addPlane

public int addPlane(Point3d P0,
                    Point3d P1,
                    Point3d P2,
                    Point3d P3,
                    java.awt.Point r0,
                    java.awt.Point r1,
                    java.awt.Point r2,
                    java.awt.Point r3,
                    int fillcol,
                    int linecol)
Add the plane given by by pointer (from pool[]) with given fill and line color.

addPlane

public int addPlane(Point3d P0,
                    Point3d P1,
                    Point3d P2,
                    Point3d P3,
                    java.awt.Point r0,
                    java.awt.Point r1,
                    java.awt.Point r2,
                    java.awt.Point r3,
                    int fillcol,
                    int linecol,
                    int side,
                    int texture)

resetJoints

public void resetJoints()
Recursively reset the joint angles to zero. It does the required rotations to achive this.

list

public java.util.Vector list()
Returns a vector of segments including this and its descendants.

_list

private void _list(java.util.Vector v,
                   Segment seg)
Used by list() to fetch the segments and its descendants.

getJoint

public Segment getJoint(java.lang.String lb)
Searches the segment for the labeled segment and returns the refrence.

setuserTag

public void setuserTag(int what,
                       boolean recursive)

getuserTaget

public int getuserTaget()

recprint

private void recprint(Segment seg)
Recersively prints the segment.

printJointAngles

public void printJointAngles()
Recersively prints the joint angles. This way it gives the state of the joint object.

print

public void print()
Recersively prints the segment.
See Also:
recprint

cosineTo

public double cosineTo(Segment other)
returns the cosine of the angle between this limb and the other

cosineTo2d

public double cosineTo2d(Segment other)
returns the cosine of the angle between this projected limb and the other

str

public java.lang.String str()
Returns a string describing the segment. No child recursion is done.

projectaxis

public void projectaxis(Eye eye)
project the joint_axis using eye. Normally project_axis need not be projected.

projectSolid

public void projectSolid(Eye eye)
Project the pool/plane system points to pool2d. Note that the skeletal projection is seperate from this process.

project

public void project(Eye eye)
Project limb_pos, joint_pos (the skeletal system) using eye. Note that solid system is seperate.

rotateEachJoint

public void rotateEachJoint(double T)
This method rotates this+descendant segments joints by T radians.

updateAllPanel

public void updateAllPanel()
This method rotates this segment's joint by T radians. The descending segments are adjusted recursively using _rotateLimb and _rotateJoint.
See Also:
_rotateLimb, _rotateJoint

disablePanel

public void disablePanel()

enablePanel

public void enablePanel()

rotateJoint

public void rotateJoint(double T)

_rotateJoint

public void _rotateJoint(Point3d place,
                         Point3d around,
                         double T)
This method is called to rotate a JOINT because of a parent segment rotation. The method adjust the axis and position of the joint. the rotate command is recursivelt transmitted to children

_rotateSolid

private void _rotateSolid(Point3d place,
                          Point3d around,
                          double T)
This method rotates the solid system (pool[]). This is NOT recursive.

_rotateLimb

public void _rotateLimb(Point3d place,
                        Point3d around,
                        double T)
This method rotates the limb (limb_pos) around the joint. If there is any solid system a call to _rotateSolid is made. Then the method recurses down to the children.

movetoy

public void movetoy(Point3d newposition)
Moves the segment (and descendants) to a new position

_translate

public void _translate(Point3d delta)

_translate

public void _translate(double dx,
                       double dy,
                       double dz)
Translates the segment and its descendant by dx,dy,dz.

mirror

public void mirror()

scale

public void scale(double sc)
Scales the segment and its descendant by sc.

scale

public void scale(Point3d place,
                  double sc)
Scales the segment and its descendant by sc taking place as the origin.

limblen

double limblen()
returns the length of this segment |limb_pos-joint_pos|.

Xrot

public void Xrot(double t)
rotate segment tree around X axis.

Yrot

public void Yrot(double t)
rotate segment tree around Y axis.

Zrot

public void Zrot(double t)
rotate segment tree around Z axis.

easy_num

private boolean easy_num(java.lang.String u)

resolve

private int resolve(java.lang.String u,
                    java.util.Vector vlimbs,
                    java.util.Vector labels)

openfileREAD

public static java.io.DataInputStream openfileREAD(java.lang.String fn)
                                            throws java.io.IOException
open file for read. Should be moved to Elib.

openfileWRITE

public static java.io.DataOutputStream openfileWRITE(java.lang.String fn)
                                              throws java.io.IOException
open file for write. Should be moved to Elib.

readSegment

public Segment readSegment(java.lang.String fn,
                           int extrapool,
                           int extraplane)
Reads a .seg file and creates and returns a segment build from the file.

unmakePanel

void unmakePanel()

makePanel

java.awt.Panel makePanel(java.lang.String s)

update_panel

void update_panel()