Package chemaxon.marvin.space
Class SurfaceComponent
- java.lang.Object
-
- chemaxon.marvin.space.GraphicComponent
-
- chemaxon.marvin.space.SurfaceComponent
-
- All Implemented Interfaces:
chemaxon.marvin.space.UsableObject
@PublicAPI 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 withmanuallySetNormals(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
-
-
Field Summary
Fields Modifier and Type Field Description protected float[]
color
protected float[]
color3
protected static float[]
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
Constructors Constructor Description SurfaceComponent(int vertexCount)
Creates a new instance of SurfaceComponent, sets its draw type toFILLED_TYPE
.SurfaceComponent(int vertexCount, int primitiveCount)
Creates a new SurfaceComponent, sets its draw type toFILLED_TYPE
.SurfaceComponent(int vertexCount, int primitiveCount, int primitiveType, int primitiveNodeCount)
Creates a new SurfaceComponent, sets its draw type toFILLED_TYPE
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
chemaxon.marvin.space.drawing.GData
createGData()
void
draw()
Draws the surface if drawtype wasDOTTED_TYPE
orFILLED_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 wasMESH_TYPE
orTRANSPARENT_TYPE
.protected void
generateRawDisplayList()
Color
getColor()
Returns the constant color of the surface.byte[]
getColor3()
Returns the constant color of the surface.float[]
getColor3F()
Returns the constant color of the surface.float[]
getColorF()
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 isMESH_TYPE
orTRANSPARENT_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(float[] c)
Sets the constant color of the surface.void
setColor(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(String propertyName, String propertyValue)
This is the gate of draw properties from outside to the component.void
setDrawType(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, seesetExclusiveColor(byte[])
.-
Methods inherited from class chemaxon.marvin.space.GraphicComponent
addDrawProperties, associate, cleanup, 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
-
-
-
-
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 float[] DEFAULT_COLOR
-
color
protected float[] color
-
color3
protected float[] color3
-
-
Constructor Detail
-
SurfaceComponent
public SurfaceComponent(int vertexCount)
Creates a new instance of SurfaceComponent, sets its draw type toFILLED_TYPE
.
-
SurfaceComponent
public SurfaceComponent(int vertexCount, int primitiveCount)
Creates a new SurfaceComponent, sets its draw type toFILLED_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 toFILLED_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 alsoGL_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
-
createGData
public chemaxon.marvin.space.drawing.GData createGData()
-
onRemoveGraphicComponent
public void onRemoveGraphicComponent()
- Overrides:
onRemoveGraphicComponent
in classGraphicComponent
-
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 alsosetDrawingPrimitiveType(int, int)
.- Parameters:
primitiveType
- Type of drawn primitives, see alsoGL_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 alsoGL_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 abyte[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.
-
getColor3F
public float[] getColor3F()
Returns the constant color of the surface.
-
getColor3
public byte[] getColor3()
Returns the constant color of the surface.
-
getColor
public Color getColor()
Returns the constant color of the surface.- Specified by:
getColor
in interfacechemaxon.marvin.space.UsableObject
- Overrides:
getColor
in classGraphicComponent
-
getColorF
public float[] getColorF()
Returns the constant color of the surface.
-
setColor
public void setColor(float[] c)
Sets the constant color of the surface.- Overrides:
setColor
in classGraphicComponent
-
setColor
public void setColor(Color c)
Sets the constant color of the surface.- Specified by:
setColor
in interfacechemaxon.marvin.space.UsableObject
- Overrides:
setColor
in classGraphicComponent
-
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, seesetExclusiveColor(byte[])
.- Parameters:
b
-
-
drawTransparentPart
public void drawTransparentPart()
Draws the surface if drawtype wasMESH_TYPE
orTRANSPARENT_TYPE
.- Overrides:
drawTransparentPart
in classGraphicComponent
-
draw
public void draw()
Draws the surface if drawtype wasDOTTED_TYPE
orFILLED_TYPE
.- Overrides:
draw
in classGraphicComponent
-
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 classGraphicComponent
- Parameters:
mode
-GL_RENDER
orGL_SELECT
-
coloring
public void coloring(boolean c)
-
setDrawType
public void setDrawType(String type)
Sets the drawing type of the surface.- Parameters:
type
- can be "Dot", "Mesh", "Solid", "Transparent".
-
setDrawProperty
public void setDrawProperty(String propertyName, String propertyValue)
This is the gate of draw properties from outside to the component. See alsoGraphicComponent.setDrawProperty(String, String)
. Accepts "Surface.DrawType" -- "Dot", "Mesh", "Solid", "Transparent"- Specified by:
setDrawProperty
in interfacechemaxon.marvin.space.UsableObject
- Overrides:
setDrawProperty
in classGraphicComponent
- Parameters:
propertyName
- identifier of the draw propertypropertyValue
- value of the draw property as aString
-
hasTransparentPart
public boolean hasTransparentPart()
Returns true if the drawing type isMESH_TYPE
orTRANSPARENT_TYPE
.- Overrides:
hasTransparentPart
in classGraphicComponent
- Returns:
- will the component draw with transparency
-
getDrawType
public int getDrawType()
-
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 oneBoundingBox
-
-