chemaxon.marvin.space
Class SurfaceComponent

java.lang.Object
  extended by chemaxon.marvin.space.GraphicComponent
      extended by chemaxon.marvin.space.SurfaceComponent
All Implemented Interfaces:
chemaxon.marvin.space.UsableObject

public class SurfaceComponent
extends GraphicComponent

Class that represents a surface defined by its vertices, normal vectors and polygons. Polygons can be triangles or any other shapes, but they are homogenous. Colors can be defined to each vertex. Normal vectors are not necessary to define, they can be computed automatically with manuallySetNormals(true); If primitives are not set, drawing is "direct drawing" of vertices as series of the given primitive type.
Accepted draw properties:
Surface.DrawType -- Dot, Mesh, Solid, Transparent Example of typical usage:

      MarchingCubes mc;
      SurfaceComponent surface = mc.generate(); 
       graphicScene.addComponent( surface );
 
 
      SurfaceComponent surface = new SurfaceComponent(vertexCount, triangleCount);
       surface.putVertex( -5, -5, 0 );
       surface.putVertex( -5, 5, 0 );
       surface.putVertex( 5, -5, 0 );
       surface.putVertex( 5, 5, 0 );
       
       surface.putNormal( 0, 0, 1 );
       surface.putNormal( 0, 0, 1 );
       surface.putNormal( 0, 0, 1 );
       surface.putNormal( 0, 0, 1 );
       
       surface.putTriangle( 0, 1, 2 );
       surface.putTriangle( 2, 1, 3 );
       graphicScene.addComponent( surface ); 
 

Since:
Marvin 4.0.2
Version:
MarvinSpace 1.0
Author:
Judit Papp

Field Summary
protected  java.awt.Color color
           
protected  byte[] color3
           
protected static java.awt.Color DEFAULT_COLOR
           
static int DOTTED_TYPE
           
static int FILLED_TYPE
           
static int MESH_TYPE
           
static int TRANSPARENT_TYPE
           
 
Fields inherited from class chemaxon.marvin.space.GraphicComponent
active, associatedComponents, boundingBox, COMPONENT_TYPE_ENTIRE, drawProperties, drawType, gl, glu, graphicCell, irm, modifiesOrigin, motionMode, mousex, mousey, name, pickedItem, RENDERING_QUALITY_HIGH, RENDERING_QUALITY_LOW, RENDERING_QUALITY_MEDIUM, renderingQuality, rm, uoid, visible
 
Constructor Summary
SurfaceComponent(int vertexCount)
          Creates a new instance of SurfaceComponent, sets its draw type to FILLED_TYPE.
SurfaceComponent(int vertexCount, int primitiveCount)
          Creates a new SurfaceComponent, sets its draw type to FILLED_TYPE.
SurfaceComponent(int vertexCount, int primitiveCount, int primitiveType, int primitiveNodeCount)
          Creates a new SurfaceComponent, sets its draw type to FILLED_TYPE.
 
Method Summary
 void clipSurface(BoundingBox bb)
          The bounding box of the surface can be used to determine 6 clipping planes and clip (do not draw) parts lying outside of the box.
 void coloring(boolean c)
           
 void draw()
          Draws the surface if drawtype was DOTTED_TYPE or FILLED_TYPE.
protected  void drawRawSurface()
           
protected  void drawSelection(int mode)
          Draws the component in the given mode (usually in selection mode), the rendering mode is for checking.
protected  void drawSurface()
           
 void drawTransparentPart()
          Draws the surface if drawtype was MESH_TYPE or TRANSPARENT_TYPE.
protected  void generateRawDisplayList()
           
 java.awt.Color getColor()
          Returns the constant color of the surface.
 byte[] getColor3()
          Returns the constant color of the surface.
 int getDrawType()
          Returns the actual drawing type.
 int getNormal(int i)
          Warning: for internal use only.
 int[] getPrimitives()
          Returns the primitives (for example triangles) of the surface.
 int getVertexCount()
          Returns the number of allocated vertices in the SurfaceComponent.
 float getVertexX(int i)
          Returns the x coordinate of the ith vertex.
 float getVertexY(int i)
          Returns the y coordinate of the ith vertex.
 float getVertexZ(int i)
          Returns the z coordinate of the ith vertex.
 boolean hasTransparentPart()
          Returns true if the drawing type is MESH_TYPE or TRANSPARENT_TYPE.
 boolean isClipped()
          Returns true if there are clipping planes enabled that will clip part of the surface during drawing.
 void manuallySetNormals(boolean flag)
          If this is set by true, we do not want to explicitly set normal vectors, but SurfaceComponent will compute them automatically.
 void onRemoveGraphicComponent()
           
 void putColor(byte[] c)
          Puts the given color to the next place.
 void putColorComponent(byte c)
          Puts the given component (red-green-blue) of a color to the next place.
 void putNormal(float[] n)
          Puts the given normal vector to the next place.
 void putNormal(float nx, float ny, float nz)
          Puts the given normal vector to the next place.
 void putPolygon(int[] polygon)
          Puts the given primitive to the next place.
 int putTriangle(int x, int y, int z)
          Puts the given triangle to the next place.
 int putVertex(float[] v)
          Puts the given vertex to the next place.
 int putVertex(float vx, float vy, float vz)
          Puts the given vertex to the next place.
 void setColor(java.awt.Color c)
          Sets the constant color of the surface.
 void setDrawing(boolean b)
           
 void setDrawingPrimitiveType(int primitiveType)
          Sets the type of drawn primitives.
 void setDrawingPrimitiveType(int primitiveType, int primitiveNodeCount)
          Sets the type of drawn primitives.
 void setDrawProperty(java.lang.String propertyName, java.lang.String propertyValue)
          This is the gate of draw properties from outside to the component.
 void setDrawType(java.lang.String type)
          Sets the drawing type of the surface.
 void setExclusiveColor(byte[] exclusiveColor)
          Vertices having the given color will not be drawn and also their neighbouring vertices belonging to the same primitive.
 void setExclusiveDrawing(boolean b)
          Enables/disables exclusive drawing, see setExclusiveColor(byte[]).
 
Methods inherited from class chemaxon.marvin.space.GraphicComponent
addDrawProperties, associate, draw2DPart, drawBoundingBox, drawCoordinateAxes, exclusiveSelection, exclusiveSelection, extendSelection, extendSelection, fadeSelected, fadeUnselected, getAssociatedComponents, getBoundingBox, getBoundingSphereRadius, getCell, getComponentElement, getCoordinates, getCoordinates, getDescription, getDescription, getDrawProperties, getDrawProperty, getGraphicComponent, getId, getLabelInformation, getLabelInformation, getName, getRenderingQuality, getUsableObject, getZCoordinateTo2DPart, glColor, has2DPart, hasSelectedElements, hideSelected, hideUnselected, invertSelection, invertSelection, isControllable, isGraphicComponent, isSelected, isSelected, isVisible, isVisible, locateObject, notifyCoordinateChange, notifyInvisibility, notifySelection, notifyUnSelection, notifyVisibility, pickObject, projectVector, receiveNotificationOnCoordinateChange, receiveNotificationOnInvisibility, receiveNotificationOnSelection, receiveNotificationOnUnSelection, receiveNotificationOnVisibility, removeAssociation, resize, rotate, rotate, rotate, select, select, selectComponentElementsInside, setColor, setColor, setDrawProperties, setGL, setMotionMode, setName, setProgressBar, setRenderingQuality, setRotateMatrix, setVisible, showFaded, storeDrawProperty, toString, touchObject, translate, unSelect, unSelect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DOTTED_TYPE

public static final int DOTTED_TYPE
See Also:
Constant Field Values

MESH_TYPE

public static final int MESH_TYPE
See Also:
Constant Field Values

FILLED_TYPE

public static final int FILLED_TYPE
See Also:
Constant Field Values

TRANSPARENT_TYPE

public static final int TRANSPARENT_TYPE
See Also:
Constant Field Values

DEFAULT_COLOR

protected static final java.awt.Color DEFAULT_COLOR

color

protected java.awt.Color color

color3

protected byte[] color3
Constructor Detail

SurfaceComponent

public SurfaceComponent(int vertexCount)
Creates a new instance of SurfaceComponent, sets its draw type to FILLED_TYPE.


SurfaceComponent

public SurfaceComponent(int vertexCount,
                        int primitiveCount)
Creates a new SurfaceComponent, sets its draw type to FILLED_TYPE.

Parameters:
vertexCount - SurfaceComponent will allocate memory for this number of vertices.
primitiveCount - SurfaceComponent will allocate memory for this number of primitives, which are triangles by default.

SurfaceComponent

public SurfaceComponent(int vertexCount,
                        int primitiveCount,
                        int primitiveType,
                        int primitiveNodeCount)
Creates a new SurfaceComponent, sets its draw type to FILLED_TYPE.

Parameters:
vertexCount - SurfaceComponent will allocate memory for this number of vertices.
primitiveCount - SurfaceComponent will allocate memory for this number of primitives.
primitiveType - Type of drawn primitives, see also GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_POLYGON, glDrawArrays(int, int, int) in the GL2 documentation.
primitiveNodeCount - Number of vertices in one primitive.
Method Detail

onRemoveGraphicComponent

public void onRemoveGraphicComponent()
Overrides:
onRemoveGraphicComponent in class GraphicComponent

setDrawing

public void setDrawing(boolean b)

setDrawingPrimitiveType

public void setDrawingPrimitiveType(int primitiveType)
Sets the type of drawn primitives. Every primitive of the SurfaceComponent will have this type. See also setDrawingPrimitiveType(int, int).

Parameters:
primitiveType - Type of drawn primitives, see also GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_POLYGON, glDrawArrays(int, int, int) in the GL2 documentation.

setDrawingPrimitiveType

public void setDrawingPrimitiveType(int primitiveType,
                                    int primitiveNodeCount)
Sets the type of drawn primitives. Every primitive of the SurfaceComponent will have this type.

Parameters:
primitiveType - Type of drawn primitives, see also GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_POLYGON, glDrawArrays(int, int, int) in the GL2 documentation.
primitiveNodeCount - Number of vertices in one primitive.

getVertexCount

public int getVertexCount()
Returns the number of allocated vertices in the SurfaceComponent.


getVertexX

public float getVertexX(int i)
Returns the x coordinate of the ith vertex.


getVertexY

public float getVertexY(int i)
Returns the y coordinate of the ith vertex.


getVertexZ

public float getVertexZ(int i)
Returns the z coordinate of the ith vertex.


putVertex

public int putVertex(float vx,
                     float vy,
                     float vz)
Puts the given vertex to the next place. Firstly the memory is allocated after giving the number of vertices, and after that values are set e.g. by this method one-by-one.


putVertex

public int putVertex(float[] v)
Puts the given vertex to the next place. Firstly the memory is allocated after giving the number of vertices, and after that values are set e.g. by this method one-by-one.


getNormal

public int getNormal(int i)
Warning: for internal use only. Returns the ith normal vector as a GeomCalc vector.


putNormal

public void putNormal(float nx,
                      float ny,
                      float nz)
Puts the given normal vector to the next place. Firstly the memory is allocated after giving the number of vertices, and after that values are set e.g. by this method one-by-one.


putNormal

public void putNormal(float[] n)
Puts the given normal vector to the next place. Firstly the memory is allocated after giving the number of vertices, and after that values are set e.g. by this method one-by-one.


putColorComponent

public void putColorComponent(byte c)
Puts the given component (red-green-blue) of a color to the next place. Color components should only be put in the above order.


putColor

public void putColor(byte[] c)
Puts the given color to the next place. Every vertex can have a color.

Parameters:
c - should be a byte[3] containing red-green-blue color components. Alpha value will be set to (byte)63 by default.

getPrimitives

public int[] getPrimitives()
Returns the primitives (for example triangles) of the surface.


putTriangle

public int putTriangle(int x,
                       int y,
                       int z)
Puts the given triangle to the next place.

Parameters:
x - Index of the first vertex of the triangle in the vertex array.
y - Index of the second vertex of the triangle in the vertex array.
z - Index of the third vertex of the triangle in the vertex array.

putPolygon

public void putPolygon(int[] polygon)
Puts the given primitive to the next place.

Parameters:
polygon - Elements of the array are indices in the vertex array.

manuallySetNormals

public void manuallySetNormals(boolean flag)
If this is set by true, we do not want to explicitly set normal vectors, but SurfaceComponent will compute them automatically.


getColor3

public byte[] getColor3()
Returns the constant color of the surface.


getColor

public java.awt.Color getColor()
Returns the constant color of the surface.

Specified by:
getColor in interface chemaxon.marvin.space.UsableObject
Overrides:
getColor in class GraphicComponent

setColor

public void setColor(java.awt.Color c)
Sets the constant color of the surface.

Specified by:
setColor in interface chemaxon.marvin.space.UsableObject
Overrides:
setColor in class GraphicComponent

setExclusiveColor

public void setExclusiveColor(byte[] exclusiveColor)
Vertices having the given color will not be drawn and also their neighbouring vertices belonging to the same primitive.

Parameters:
exclusiveColor - rgb components of the forbidden color

setExclusiveDrawing

public void setExclusiveDrawing(boolean b)
Enables/disables exclusive drawing, see setExclusiveColor(byte[]).

Parameters:
b -

drawTransparentPart

public void drawTransparentPart()
Draws the surface if drawtype was MESH_TYPE or TRANSPARENT_TYPE.

Overrides:
drawTransparentPart in class GraphicComponent

draw

public void draw()
Draws the surface if drawtype was DOTTED_TYPE or FILLED_TYPE.

Overrides:
draw in class GraphicComponent

drawSurface

protected void drawSurface()

drawRawSurface

protected void drawRawSurface()

generateRawDisplayList

protected void generateRawDisplayList()

drawSelection

protected void drawSelection(int mode)
Description copied from class: GraphicComponent
Draws the component in the given mode (usually in selection mode), the rendering mode is for checking.

Overrides:
drawSelection in class GraphicComponent
Parameters:
mode - GL_RENDER or GL_SELECT

coloring

public void coloring(boolean c)

setDrawType

public void setDrawType(java.lang.String type)
Sets the drawing type of the surface.

Parameters:
type - can be "Dot", "Mesh", "Solid", "Transparent".

setDrawProperty

public void setDrawProperty(java.lang.String propertyName,
                            java.lang.String propertyValue)
This is the gate of draw properties from outside to the component. See also GraphicComponent.setDrawProperty(String, String). Accepts "Surface.DrawType" -- "Dot", "Mesh", "Solid", "Transparent"

Specified by:
setDrawProperty in interface chemaxon.marvin.space.UsableObject
Overrides:
setDrawProperty in class GraphicComponent
Parameters:
propertyName - identifier of the draw property
propertyValue - value of the draw property as a String

hasTransparentPart

public boolean hasTransparentPart()
Returns true if the drawing type is MESH_TYPE or TRANSPARENT_TYPE.

Overrides:
hasTransparentPart in class GraphicComponent
Returns:
will the component draw with transparency

getDrawType

public int getDrawType()
Returns the actual drawing type. See DOTTED_TYPE, MESH_TYPE, FILLED_TYPE, TRANSPARENT_TYPE.


isClipped

public boolean isClipped()
Returns true if there are clipping planes enabled that will clip part of the surface during drawing.

Returns:
surface drawing is restricted to the bounding box or not

clipSurface

public void clipSurface(BoundingBox bb)
The bounding box of the surface can be used to determine 6 clipping planes and clip (do not draw) parts lying outside of the box. Translating and resizing the box is defined, this is an interactive way to modify the location of the clipping planes.

Parameters:
bb - clipping planes to be used given by one BoundingBox