JavaView® v2.00.008

jv.geom
Class PgPolygon

java.lang.Object
  |
  +--jv.object.PsObject
        |
        +--jv.project.PgGeometry
              |
              +--jv.geom.PgPointSet
                    |
                    +--jv.geom.PgPolygon
All Implemented Interfaces:
java.lang.Cloneable, PgGeometryIf, PsUpdateIf, java.io.Serializable
Direct Known Subclasses:
PgBezierCurve, PgBndPolygon

public class PgPolygon
extends PgPointSet

Base class for polygons given as consequtive list of polygon vertices. The class interprets the vertices in the vertex array of its superclass PgPointSet as consequtive points of a polygon. Therefore, this class mainly consists of polygon properties, for example, polygon color, additional to the geometric information contained in its superclass.

The dimension of all points is determined as argument of the constructor and cannot be changed later. See PgPointSet for details about allocation and access.

A good starting to obtain further insight are methods like computeEight(int) (if source code access to JavaView is available), or the tutorial applets of JavaView.

Version:
07.07.00, 2.50 revised (kp) Edge methods added and jvx exchange.
02.04.00, 2.00 revised (kp) PdColor replaced with Color in lists.
00.00.98, 1.00 created (kp)
Author:
Konrad Polthier
See Also:
PgPointSet, Serialized Form

Field Summary
protected  boolean m_bClosed
          Flag whether polygon is closed, i.e. last vertex is implicitly connected with an edge with the first vertex of the vertex array.
protected  boolean m_bShowEdgeColors
          Flag whether edge colors are shown in display.
protected  boolean m_bShowEdgeLabels
          Flag whether labels of edges are shown in display.
protected  boolean m_bShowEdgeNormals
          Flag whether edge normals are shown in display.
protected  boolean m_bShowEdges
          Flag whether polygon edges are shown in display.
protected  boolean m_bShowPolygonColors
          Flag if local color of edges used in display, applied if individual edge coloring is available.
protected  boolean m_bShowPolygonEndArrow
          Flag whether arrow is shown at last point of polygon.
protected  boolean m_bShowPolygonStartArrow
          Flag whether arrow is shown at first point of polygon.
protected  boolean m_bShowTaggedEdges
          Flag whether tagged polygon edges are shown in display.
protected  PdColor m_globalPolygonColor
          Global color of polygons used in display, applied if no individual polygon coloring available.
protected  PuDouble m_globalPolygonSize
          Flag if global size of edges used in display, applied if no individual edge sizes available.
protected  PdColor m_globalPolygonTagColor
          Global color of tagged polygons used in display.
protected  boolean m_useGlobalPolygonSize
          Flag if global size of edges used in display, applied if no individual edge sizes available.
 
Fields inherited from class jv.geom.PgPointSet
m_bDefaultLabelEnabled, m_bShowIndices, m_bShowTaggedVertices, m_bShowTransparency, m_bShowVectorArrow, m_bShowVectorColors, m_bShowVectorFields, m_bShowVertexColors, m_bShowVertexLabels, m_bShowVertexNormalArrow, m_bShowVertexNormals, m_bShowVertexTexture, m_bShowVertices, m_dimOfColors, m_dimOfTextures, m_dimOfVectors, m_globalVectorColor, m_globalVectorLength, m_globalVectorSize, m_globalVertexColor, m_globalVertexNormalColor, m_globalVertexNormalLength, m_globalVertexNormalSize, m_globalVertexSize, m_globalVertexTagColor, m_maxNumVertices, m_numVectorFields, m_numVertices, m_texture, m_transparency, m_vectorField, m_vertex, m_vertexColor, m_vertexNormal, m_vertexTexture
 
Fields inherited from class jv.project.PgGeometry
m_ambientProj, m_ambientSpace, m_authorInfo, m_bShowBndBox, m_bShowCenter, m_bShowing, m_bShowTitle, m_center, m_dim, m_dimOfSimplex, m_displayList, m_geometryInfo, m_labelAttribute, m_methodMenu, m_modelMatrix, m_title, m_version, m_versionType
 
Fields inherited from class jv.object.PsObject
HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_MATERIAL_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_SELECTED, IS_USED, m_infoPanel, m_name, m_panelList, m_parent, m_tag, m_updateList, NUM_TAGS
 
Fields inherited from interface jv.project.PgGeometryIf
AMBIENT_H3_HYPERBOLIC, AMBIENT_PROJECTIONS, AMBIENT_R3_EUCLIDEAN, AMBIENT_R4_EUCLIDEAN, AMBIENT_S3_SPHERE, AMBIENT_SPACES, INSPECTOR_CONTROL, INSPECTOR_CONTROL_EXT, INSPECTOR_MATERIAL, INSPECTOR_MATERIAL_EXT, LABEL_BASE, LABEL_CENTER, LABEL_HEAD, LABEL_MIDDLE, LABEL_TAIL, LABEL_TOP, METHOD_EXT, PROJ_KLEIN_BALL, PROJ_PARALLEL, PROJ_POINCARE_BALL, PROJ_STEREOGRAPHIC, PROJ_UPPER_HALFSPACE
 
Constructor Summary
PgPolygon()
          Constructor of a polygon in three-dimensional space.
PgPolygon(int aVertexDim)
          Constructor of a polygon set in a space of given dimension.
 
Method Summary
 boolean blend(double s, PgPolygon a, double t, PgPolygon b)
          Blend between two Polygons using this = s*a + t*b
 boolean checkTriangleCut(int vertexInd, PdVector normal)
          Given a simple closed, nearly planar polygon, then the function tests whether three successive points of the polygon form a triangle which can be cut off the polygon, i.e. the triangle does not contain any other vertex of the polygon.
 java.lang.Object clone()
          Duplicate geometry by recursively cloning all instance variables except inspector panels and lists of registered listeners.
 void computeCircle(int numPoints, double radius)
          Compute circle centered at origin in xy-plane with given radius including vertex normals.
 void computeEight(int numPoints)
          Compute figure eight in xy-plane with given radius including vertex normals.
 void copy(PgGeometry aGeom)
          Copy instance variables by duplication, not by copying a reference.
 java.awt.Color getGlobalPolygonColor()
          Get global polygon color which is used if no local colors are available.
 double getGlobalPolygonSize()
          Get thickness in pixels of polygon when drawn in display.
 java.awt.Color getGlobalPolygonTagColor()
          Get global color of tagged polygons.
 PgJvxSrc getJvx()
          Fills a geometry object with data from this instance, for example, to print to file.
 double getLength()
          Compute geometric length of polygon as the sum of all edge lengths.
 PiVector getPolygon()
          Get indices of polygon as index vector.
 void init()
          Initialize and reset instance variables after call to super.init().
 PvPickEvent intersectionWithLine(PdVector rayBase, PdVector rayDir)
          Find intersection of polygon with a given ray.
 boolean isClosed()
          Check whether polygon is closed, i.e.if endpoints are connected by additional edge.
 boolean isShowingEdgeColors()
          Determine whether drawing of edge colorsis enabled.
 boolean isShowingEdgeLabels()
          Determine whether showing of edge labels is enabled.
 boolean isShowingEdgeNormals()
          Determine whether drawing of edge normalsis enabled.
 boolean isShowingEdges()
          Determine whether drawing of edges of polygonis enabled.
 boolean isShowingPolygonColors()
          Set flag to enable drawing of polygon colors.
 boolean isShowingPolygonEndArrow()
          Determine whether drawing of arrow at last point of polygon is enabled.
 boolean isShowingPolygonStartArrow()
          Determine whether drawing of arrow at first point of polygon is enabled.
 PdVector makeNormals()
          Compute normals at vertices and approximate normal of enclosed patch as the mean of all vertex normals.
 void paint(PvGeometryIf dc)
          Major rendering method fills an internal container class supplied by the display.
 void setClosed(boolean flag)
          Set flag that polygon is closed.
 void setGlobalPolygonColor(java.awt.Color color)
          Set global polygon color to be used if no local colors are available.
 void setGlobalPolygonSize(double size)
          Set thickness in pixels of polygon when drawn in display.
 void setGlobalPolygonTagColor(java.awt.Color color)
          Set global color of tagged polygons.
 void setJvx(PgJvxSrc src)
          Fill this instance with data from a geometry source, for example, previously read from file.
 void showEdgeColors(boolean flag)
          Set flag to enable drawing of edge colors.
 void showEdgeLabels(boolean flag)
          Set flag to enable drawing of edge labels in display.
 void showEdgeNormals(boolean flag)
          Set flag to enable drawing of edge normals.
 void showEdges(boolean flag)
          Set flag to enable drawing of edges of polygon.
 void showPolygonColors(boolean flag)
          Set flag to enable drawing of polygon colors.
 void showPolygonEndArrow(boolean flag)
          Set flag to enable drawing of arrow at last point of polygons.
 void showPolygonStartArrow(boolean flag)
          Set flag to enable drawing of arrow at first point of polygons.
 java.lang.String toString()
          Create a multi-line string representation with detailed information about all instance variables.
 PiVector[] triangulate()
          Given a simple closed, nearly planar polygon, then the method triangulates the patch by successively removing the vertex with the smallest interior angle.
 boolean update(java.lang.Object event)
          Update the class whenever a child has changed.
 void useGlobalPolygonColor(boolean flag)
          Deprecated. use showPolygonColors(boolean)
 void useGlobalPolygonSize(boolean flag)
          Use global polygon size instead of sizing each edge individually.
 
Methods inherited from class jv.geom.PgPointSet
addVectorField, addVertex, assureVertexColors, assureVertexNormals, assureVertexTextures, blend, clearTagVertex, computeCylinder, computeDisk, computePlane, computeRotation, computeSnail, computeSphere, computeTorus, flipOrientation, getBounds, getCenterOfBndBox, getCenterOfGravity, getDimOfColors, getDimOfTextures, getDimOfVectors, getGlobalVectorColor, getGlobalVectorLength, getGlobalVectorSize, getGlobalVertexColor, getGlobalVertexNormalColor, getGlobalVertexNormalLength, getGlobalVertexNormalSize, getGlobalVertexSize, getGlobalVertexTagColor, getIndexOfVectorField, getMaxNumVertices, getNumVectorFields, getNumVertices, getTexture, getTextureImage, getTextureImageName, getVectorField, getVectorField, getVectorField, getVertex, getVertexColor, getVertexColors, getVertexNormal, getVertexNormals, getVertexTextures, getVertices, hasTagVertex, hasVertex, hasVertex, hasVertexColors, hasVertexNormals, hasVertexTextures, isDefaultLabelEnabled, isShowingIndices, isShowingTaggedVertices, isShowingVectorArrow, isShowingVectorColors, isShowingVectorField, isShowingVertexColors, isShowingVertexLabels, isShowingVertexNormalArrow, isShowingVertexNormals, isShowingVertexTexture, isShowingVertices, makeColorFromVectorLength, makeVertexColorsFromXYZ, makeVertexColorsFromZ, makeVertexColorsFromZHue, makeVertexNormals, makeVertexTextureFromBndBox, merge, projectToSphere, reflect, removeAllVectorFields, removeMarkedVertices, removeVectorField, removeVertex, scale, scale, setCenterOfBndBox, setDefaultLabelEnabled, setDimOfColors, setDimOfTextures, setDimOfVectors, setGlobalVectorColor, setGlobalVectorLength, setGlobalVectorSize, setGlobalVertexColor, setGlobalVertexNormalColor, setGlobalVertexNormalLength, setGlobalVertexNormalSize, setGlobalVertexSize, setGlobalVertexTagColor, setMaxNumVertices, setNumVertices, setTagVertex, setTexture, setTextureImage, setTextureImageName, setTransparency, setVertex, setVertex, setVertex, setVertex, setVertexColor, setVertexColors, setVertexNormal, setVertexNormals, setVertexTextures, setVertices, showIndices, showTaggedVertices, showVectorArrow, showVectorColors, showVectorField, showVertexColors, showVertexLabels, showVertexNormalArrow, showVertexNormals, showVertexTexture, showVertices, translate
 
Methods inherited from class jv.project.PgGeometry
addDisplay, addElement, addPolygon, clearTagElement, clearTagPolygon, fillMethodMenu, getAmbientProjection, getAmbientSpace, getAuthorInfo, getAuthors, getCenter, getCenterOfElement, getControlPanel, getDiameter, getDimOfSimplex, getDimOfVertices, getDisplays, getElement, getGeometryInfo, getLabelAttribute, getMaterialPanel, getModelMatrix, getPolygon, getTitle, getVersion, getVersionType, hasDisplay, hasModelMatrix, hasTagElement, hasTagPolygon, isConfigurable, isShowingBndBox, isShowingCenter, isShowingTitle, isVisible, removeDisplay, removeElement, removePolygon, setAmbientProjection, setAmbientSpace, setAuthorInfo, setAuthors, setCenter, setDimOfSimplex, setElement, setGeometryInfo, setLabelAttribute, setLabelAttribute, setModelMatrix, setPolygon, setTagElement, setTagPolygon, setTitle, setVersion, setVersionType, setVisible, showBndBox, showCenter, showTitle
 
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, clearTag, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, removeInspector, removeUpdateListener, setName, setParent, setTag, updatePanels
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jv.project.PgGeometryIf
getInfoPanel, getName, setName
 
Methods inherited from interface jv.object.PsUpdateIf
getFather, setParent
 

Field Detail

m_bShowEdgeLabels

protected boolean m_bShowEdgeLabels
Flag whether labels of edges are shown in display.

m_bClosed

protected boolean m_bClosed
Flag whether polygon is closed, i.e. last vertex is implicitly connected with an edge with the first vertex of the vertex array.
See Also:
isClosed(), setClosed(boolean)

m_bShowEdges

protected boolean m_bShowEdges
Flag whether polygon edges are shown in display.

m_bShowTaggedEdges

protected boolean m_bShowTaggedEdges
Flag whether tagged polygon edges are shown in display.

m_bShowPolygonStartArrow

protected boolean m_bShowPolygonStartArrow
Flag whether arrow is shown at first point of polygon.

m_bShowPolygonEndArrow

protected boolean m_bShowPolygonEndArrow
Flag whether arrow is shown at last point of polygon.

m_bShowEdgeNormals

protected boolean m_bShowEdgeNormals
Flag whether edge normals are shown in display.

m_bShowEdgeColors

protected boolean m_bShowEdgeColors
Flag whether edge colors are shown in display.

m_bShowPolygonColors

protected boolean m_bShowPolygonColors
Flag if local color of edges used in display, applied if individual edge coloring is available.

m_useGlobalPolygonSize

protected boolean m_useGlobalPolygonSize
Flag if global size of edges used in display, applied if no individual edge sizes available.

m_globalPolygonColor

protected PdColor m_globalPolygonColor
Global color of polygons used in display, applied if no individual polygon coloring available.

m_globalPolygonTagColor

protected PdColor m_globalPolygonTagColor
Global color of tagged polygons used in display.

m_globalPolygonSize

protected PuDouble m_globalPolygonSize
Flag if global size of edges used in display, applied if no individual edge sizes available.
Constructor Detail

PgPolygon

public PgPolygon()
Constructor of a polygon in three-dimensional space.

PgPolygon

public PgPolygon(int aVertexDim)
Constructor of a polygon set in a space of given dimension.
Method Detail

init

public void init()
Initialize and reset instance variables after call to super.init().
Overrides:
init in class PgPointSet

getJvx

public PgJvxSrc getJvx()
Fills a geometry object with data from this instance, for example, to print to file.
Overrides:
getJvx in class PgPointSet
Returns:
src a geometry source to be filled with data from this instance.

setJvx

public void setJvx(PgJvxSrc src)
Fill this instance with data from a geometry source, for example, previously read from file.
Overrides:
setJvx in class PgPointSet
Parameters:
src - a geometry source used to fill this instance with data.

clone

public java.lang.Object clone()
Duplicate geometry by recursively cloning all instance variables except inspector panels and lists of registered listeners. The parent relationship is maintained only within this class but not to external classes. In general, all links of the clone to external objects are set to null. Tags of this object are not copied but maybe copied of subclasses.
Overrides:
clone in class PgPointSet
See Also:
#copy(PgPolygon)

copy

public void copy(PgGeometry aGeom)
Copy instance variables by duplication, not by copying a reference.
Overrides:
copy in class PgPointSet

toString

public java.lang.String toString()
Create a multi-line string representation with detailed information about all instance variables.
Overrides:
toString in class PgPointSet

getGlobalPolygonColor

public java.awt.Color getGlobalPolygonColor()
Get global polygon color which is used if no local colors are available.

getGlobalPolygonTagColor

public java.awt.Color getGlobalPolygonTagColor()
Get global color of tagged polygons.

getGlobalPolygonSize

public double getGlobalPolygonSize()
Get thickness in pixels of polygon when drawn in display.

setGlobalPolygonColor

public void setGlobalPolygonColor(java.awt.Color color)
Set global polygon color to be used if no local colors are available.

setGlobalPolygonTagColor

public void setGlobalPolygonTagColor(java.awt.Color color)
Set global color of tagged polygons.

setGlobalPolygonSize

public void setGlobalPolygonSize(double size)
Set thickness in pixels of polygon when drawn in display.

showPolygonColors

public void showPolygonColors(boolean flag)
Set flag to enable drawing of polygon colors.

useGlobalPolygonColor

public void useGlobalPolygonColor(boolean flag)
Deprecated. use showPolygonColors(boolean)

Set flag of using global polygon color instead of coloring each polygon individually.

useGlobalPolygonSize

public void useGlobalPolygonSize(boolean flag)
Use global polygon size instead of sizing each edge individually.

isShowingEdgeLabels

public boolean isShowingEdgeLabels()
Determine whether showing of edge labels is enabled.

isShowingEdges

public boolean isShowingEdges()
Determine whether drawing of edges of polygonis enabled.

isShowingEdgeNormals

public boolean isShowingEdgeNormals()
Determine whether drawing of edge normalsis enabled.

isShowingEdgeColors

public boolean isShowingEdgeColors()
Determine whether drawing of edge colorsis enabled.

isShowingPolygonStartArrow

public boolean isShowingPolygonStartArrow()
Determine whether drawing of arrow at first point of polygon is enabled.

isShowingPolygonEndArrow

public boolean isShowingPolygonEndArrow()
Determine whether drawing of arrow at last point of polygon is enabled.

isShowingPolygonColors

public boolean isShowingPolygonColors()
Set flag to enable drawing of polygon colors.

showEdgeLabels

public void showEdgeLabels(boolean flag)
Set flag to enable drawing of edge labels in display.

showEdges

public void showEdges(boolean flag)
Set flag to enable drawing of edges of polygon.

showEdgeNormals

public void showEdgeNormals(boolean flag)
Set flag to enable drawing of edge normals.

showEdgeColors

public void showEdgeColors(boolean flag)
Set flag to enable drawing of edge colors.

showPolygonStartArrow

public void showPolygonStartArrow(boolean flag)
Set flag to enable drawing of arrow at first point of polygons.

showPolygonEndArrow

public void showPolygonEndArrow(boolean flag)
Set flag to enable drawing of arrow at last point of polygons.

update

public boolean update(java.lang.Object event)
Update the class whenever a child has changed. Method is usually invoked from the children.
Overrides:
update in class PgPointSet
Following copied from interface: jv.object.PsUpdateIf
Parameters:
event - carries a lot of information
Returns:
true if event has been handled, otherwise false
See Also:
PsObject, PsUpdateIf.getFather(), PsUpdateIf.setParent(PsUpdateIf)

paint

public void paint(PvGeometryIf dc)
Major rendering method fills an internal container class supplied by the display. See jv.project.PgGeometryIf for detailed information.
Overrides:
paint in class PgPointSet
See Also:
PgGeometryIf

getPolygon

public PiVector getPolygon()
Get indices of polygon as index vector.

getLength

public double getLength()
Compute geometric length of polygon as the sum of all edge lengths. If polygon is closed then the distance of the first and last vertex is added to the polygon length.
Returns:
length of polygon
See Also:
isClosed()

isClosed

public boolean isClosed()
Check whether polygon is closed, i.e.if endpoints are connected by additional edge.
Returns:
flag whether polygon is closed.
See Also:
setClosed(boolean)

setClosed

public void setClosed(boolean flag)
Set flag that polygon is closed. In the previous version 1.00 an additional vertex might have been allocated. This version just sets a flag.
Parameters:
flag - true closes polygons
See Also:
isClosed()

computeEight

public void computeEight(int numPoints)
Compute figure eight in xy-plane with given radius including vertex normals.
Parameters:
numPoints - Discretization of polygon

computeCircle

public void computeCircle(int numPoints,
                          double radius)
Compute circle centered at origin in xy-plane with given radius including vertex normals.
Parameters:
numPoints - Discretization of polygon
radius - Radius of circle

blend

public boolean blend(double s,
                     PgPolygon a,
                     double t,
                     PgPolygon b)
Blend between two Polygons using this = s*a + t*b
Parameters:
s, - t weights of vertices of each Polygon
a, - b two Polygons used for blending

makeNormals

public PdVector makeNormals()
Compute normals at vertices and approximate normal of enclosed patch as the mean of all vertex normals. All vertex normals are orthogonal to the span of the adjacent edges and all have the same orientation parallel to the patch normal.

The returned patch normal is orthogonal to the plane of the patch and oriented such that the boundary runs counter-clockwise around the normal. This is

Much faster than finding plane using least square fit.

Returns:
Normal of planar patch such that boundary is counter-clockwise.

checkTriangleCut

public boolean checkTriangleCut(int vertexInd,
                                PdVector normal)
Given a simple closed, nearly planar polygon, then the function tests whether three successive points of the polygon form a triangle which can be cut off the polygon, i.e. the triangle does not contain any other vertex of the polygon.

Remark: this condition is only valid of the projection of the polygon onto a plane orthogonal to the normal of the polygon is a simple closed curve with no self-intersections.

Fuer den Test wird abgefragt, ob die uebrigen Eckpunkte des Polygons im Innern des vom Dreieck p1,p2,p3 und der Normalen orient gebildeten Prismas liegt. Wenn alle Punkte ausserhalb liegen, so verlaeuft Linie im Innern d. Polygons.

Parameters:
vertexInd - index of middle vertex which might be cut off
normal - normal of polygon, used as orientation, i.e. polygon runs counter-clockwise around normal

triangulate

public PiVector[] triangulate()
Given a simple closed, nearly planar polygon, then the method triangulates the patch by successively removing the vertex with the smallest interior angle. The method can handle non-convex polygons.

ToDo: But until now it cannot handle situations where an edge introduced by removing a vertex may intersect the polygon somewhere else. To solve this problem the above method checkTriangleCut must be employed.

Returns:
Array of vectors each containing the vertex indices of a triangle.

intersectionWithLine

public PvPickEvent intersectionWithLine(PdVector rayBase,
                                        PdVector rayDir)
Find intersection of polygon with a given ray. Closest polygon edge is located. Method is used for interactive picking.
Overrides:
intersectionWithLine in class PgGeometry
Parameters:
rayBase - base point of ray eventually hitting the polygon set
rayDir - direction point of ray eventually hitting the polygon set
Returns:
full information about hit polygon, barycentric coordinates etc.

JavaView® v2.00.008

The software JavaView® is copyright protected. All Rights Reserved.