Class 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 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
    • Field Detail

      • 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 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

      • createGData

        public chemaxon.marvin.space.drawing.GData createGData()
      • 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.
      • 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 interface chemaxon.marvin.space.UsableObject
        Overrides:
        getColor in class GraphicComponent
      • 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 class GraphicComponent
      • setColor

        public void setColor​(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​(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 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
      • 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