![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GL/GlMesh.h>
The GlMesh class renders Mesh instances in 2D and 3D. More...
Inheritance diagram for GlMesh:The GlMesh class renders Mesh instances in 2D and 3D.
You can specify different render modes for 2D and 3D views. By default, in 2D the cross-section between the mesh and the 2D slice is computed in a geometry shader and displayed as a line. The default 3D rendering mode uses a single material for all surfaces. If the mesh includes a color attribute for each vertex this can be used instead. If the mesh includes texture coordinates for all vertices and a texture is provided, the texture is used as a material. Additionally, different materials can be assigned to front- and back facing surfaces. This class also supports a wireframe mode that also supports different material modes.
Should a mode be incompatible with the mesh (e.g. lighting with no normals or color material mode with vertex colors), OpenGL will assume default values for them (which are usually 0).
This class uses only OpenGL 3.3 core functions.
Public Types | |
| enum | RenderMode2d { IntersectionOnly , FullProjective , ProjectiveColorGradient , ProjectiveWireframe , Render3D } |
| enum | RenderMode3d { Surface , SurfaceAndWireframe , Wireframe , Intersection } |
| enum | MaterialMode { Uniform = 0 , Color = 1 , Texture = 2 , Shader = 3 , FaceLabel = 4 , VertexLabel = 5 } |
| enum | Facing { Both = 0 , Front = 1 , Back = 2 } |
| enum class | PickingMode { None = 0 , Face = 1 , Vertex = 2 } |
| enum class | ClipMode { Discard = 0 , Wireframe = 1 , SolidButWireframeColor = 2 } |
Public Types inherited from GlObject | |
| enum | RenderingOrderGroup { RenderingGroupRest , RenderingGroupMesh , RenderingGroupManipulator } |
| Enumeration to determine rendering order of GlObjects in GlSliceView and GlVolumeView. More... | |
Public Member Functions | |
| GlMesh () | |
| Creates an empty object and initializes the shader program. | |
| GlMesh (Mesh *mesh) | |
| Initializes the shader program and creates and uploads the required GPU buffers for the mesh. | |
| void | setMatrix (const mat4 &m) override |
| Set the modelview matrix of this object. | |
| const mat4 & | matrix () const override |
| Return the modelview matrix. | |
| virtual void | setMesh (Mesh *mesh) |
| Attaches a Mesh to be rendered. | |
| virtual const Mesh * | getMesh () |
| void | draw (const GlView &view) override |
| Calls draw3D for SPACE3D views and draw2D for SLICE2D views. | |
| void | draw3D (const GL::ViewState &viewState, const Slice *slice=nullptr, const GL::OrderIndependentTransparency *oit=nullptr, const GL::ObjectPicking *objectPicking=nullptr) |
| Draws the mesh in 3D with Phong-Shading. | |
| virtual void | draw2D (const GL::ViewState &viewState, Slice slice) |
| Computes the cross-section with the slice and displays it with lines. | |
| void | applyMeshDisplayOptions (const MeshDisplayOptions &mdo, bool applyRenderModes=false) |
| Assign the applicable rendering settings in mdo to this GlMesh instance. | |
| virtual void | setRenderMode2d (RenderMode2d mode) |
| Sets the 2D render mode. | |
| virtual RenderMode2d | renderMode2d () const |
| Returns the current 2D render mode. | |
| virtual void | setRenderMode3d (RenderMode3d mode) |
| Sets the 3D render mode. | |
| virtual RenderMode3d | renderMode3d () const |
| Returns the current 3D render mode. | |
| void | setRenderingDepthOffset (bool useOffset, float offsetFactor=2.f, float offsetUnits=2.f) |
| Sets the depth offset (see OpenGL glPolygonOffset for more details) | |
| bool | renderingDepthOffset (float &offsetFactor, float &offsetUnits) |
| void | setColor (const vec3 &color) override |
| Sets the color of the front and back material (ambient, diffuse and specular) | |
| void | setColor (const std::vector< vec3f > &colors) |
| Sets individual color per vertex. | |
| std::vector< vec3f > | colors () const |
| Get individual colors of vertices. | |
| void | setAlpha (double alpha) override |
| Set alpha channel. | |
| virtual void | enableLighting (bool enable, Facing side=Both) |
| Enables/Disables lighting effects. | |
| virtual void | enableLighting (const vec2i &enable) |
| virtual bool | lighting (vec2i &out) const |
| virtual void | setShininess (float shininess) |
| Sets the strength of specular reflections on the front and back faces (0.0 to disable specular reflections) | |
| virtual void | setFrontShininess (float shininess) |
| Sets the strength of specular reflections on the front faces (0.0 to disable specular reflections) | |
| virtual void | setBackShininess (float shininess) |
| Sets the strength of specular reflections on the back faces (0.0 to disable specular reflections) | |
| virtual void | setMaterialMode (MaterialMode mode) |
| Sets the material mode for the front and back facing triangles during 3D rendering. | |
| virtual void | setFrontMaterialMode (MaterialMode mode) |
| Sets the material mode for the front facing triangles during 3D rendering. | |
| virtual void | setBackMaterialMode (MaterialMode mode) |
| Sets the material mode for the back facing triangles during 3D rendering. | |
| virtual MaterialMode | frontMaterialMode () const |
| Returns the material mode for the front facing triangles during 3D rendering. | |
| virtual MaterialMode | backMaterialMode () const |
| Returns the material mode for the back facing triangles during 3D rendering. | |
| virtual MaterialMode | wireframeMaterialMode () const |
| virtual void | setMaterial (vec3f ambient, vec3f diffuse, vec3f specular, float shininess) |
| Sets the material used for the front and back facing triangles during 3D rendering. | |
| virtual void | setFrontMaterial (vec3f ambient, vec3f diffuse, vec3f specular, float shininess) |
| Sets the material used for the front facing triangles during 3D rendering. | |
| virtual void | frontMaterial (vec3f &ambient, vec3f &diffuse, vec3f &specular, float &shininess) const |
| Returns the material used for the front facing triangles during 3D rendering. | |
| virtual void | setBackMaterial (vec3f ambient, vec3f diffuse, vec3f specular, float shininess) |
| Sets the material used for the back facing triangles during 3D rendering. | |
| virtual void | backMaterial (vec3f &ambient, vec3f &diffuse, vec3f &specular, float &shininess) const |
| Returns the material used for the back facing triangles during 3D rendering. | |
| virtual void | setWireframeWidth (float width) |
| Sets the line width in 2D rendering. | |
| virtual vec4f | wireframeColor () const |
| Returns the line color in 2D rendering. | |
| virtual void | setWireframeColor (vec4f color) |
| Sets the line color in 2D rendering. | |
| virtual void | setWireframeMaterialMode (MaterialMode mode) |
| Sets the material mode for the wireframe during 3D rendering. | |
| virtual void | setLineColor (vec4f color) |
| Sets the line color in 2D rendering. | |
| virtual vec4f | lineColor () const |
| Returns the line color in 2D rendering. | |
| float | lineWidth () const override |
| Return annotation line width. | |
| void | setLineWidth (float lineWidth) override |
| Set annotation line width. | |
| std::optional< Geometry::Plane > | clipPlane () const |
| Returns the optional clip plane used during 3D rendering. | |
| void | setClipPlane (std::optional< Geometry::Plane > plane) |
| Sets an optional clip plane so that parts on the back (opposite the direction of the normal vector) are clipped during 3D rendering. | |
| vec4f | projectiveFrontColor () const |
| Returns the color used for RenderMode2d::ProjectiveDepthEncoding rendering mode in MPR views if mesh is in front of the MPR plane. | |
| void | setProjectiveFrontColor (vec4f value) |
| Sets the color used for RenderMode2d::ProjectiveDepthEncoding rendering mode in MPR views if mesh is in front of the MPR plane. | |
| vec4f | projectiveBackColor () const |
| Returns the color used for RenderMode2d::ProjectiveDepthEncoding rendering mode in MPR views if mesh is behind the MPR plane. | |
| void | setProjectiveBackColor (vec4f value) |
| Sets the color used for RenderMode2d::ProjectiveDepthEncoding rendering mode in MPR views if mesh is behind the MPR plane. | |
| double | projectiveIntersectionTolerance () const |
| Returns the tolerance (mm) during the computation whether a mesh intersects the MPR plane in projective rendering. | |
| void | setProjectiveIntersectionTolerance (double value) |
| Sets the tolerance (mm) during the computation whether a mesh intersects the MPR plane in projective rendering. | |
| double | projectiveFadeoutRange () const |
| Returns the range (mm) during which the mesh is smoothly faded out in projective rendering if not intersecting. | |
| void | setProjectiveFadeoutRange (double value) |
| Sets the range (mm) during which the mesh is smoothly faded out in projective rendering if not intersecting. | |
| void | setLineStipplePattern (uint16_t pattern) |
| Sets the stipple pattern of the rendered mesh plane intersection lines. | |
| void | setLineStippleFactor (double factor) |
| Sets the factor determining the length of the stipple pattern of the mesh plane intersection lines. | |
| virtual void | setCustomShader (GL::Program *program) |
| Sets a custom shader to be used as a replacement for the default shader in 3D. | |
| Geometry::AlignedBox | bounds () const override |
| Get the axis-aligned bounding box of this GlObject in world space. | |
| Geometry::AlignedBox | boundsSpherical () const override |
| Computes a cheap approximation of the mesh bounds in world space The mesh bounds in local space are translated to the current mesh position in world space. | |
| std::string | typeName () const override |
| Return unique identifier for this object class used for serialization. | |
| Mesh * | mesh () |
| const Mesh * | mesh () const |
| const MeshGl * | meshGl () const |
| vec3 | center () const override |
| Return the center of the object in local coordinates without considering any matrix. | |
| vec3 | extent () const override |
| Return the extent of the object in local coordinates without considering any matrix. | |
| vec3 | centerOfMass () const |
| void | setDrawIn2D (bool draw) |
| bool | drawIn2D () const |
| void | setDrawCrossSection (bool draw) |
| Specify whether to draw a filled cross-section of the mesh in the slice views Note that this will only work with closed meshes. | |
| bool | drawCrossSection () const |
| void | setCrossSectionColor (vec4f color) |
| Specify the color of the cross section. | |
| vec4f | crossSectionColor () const |
| void | setDrawNormals (bool flag) |
| Specify whether the normals should be drawn as lines (if available) | |
| bool | drawNormals () const |
| void | configure (const Properties *p) override |
| Set one or multiple properties. | |
| void | configuration (Properties *p) const override |
| Retrieve the properties of this object. | |
| virtual bool | hasCustomShader () const |
| void | setFaceNormalsEnabled (bool v) |
| bool | faceNormalsEnabled () const |
| void | setPickingMode (PickingMode v) |
| Specify the type of index picking. | |
| PickingMode | pickingMode () const |
Public Member Functions inherited from GlAnnotation | |
| virtual void | setView (const GlView *view) |
| Set the view through which this annotation is currently being manipulated. | |
| virtual const GlView * | view () const |
| Get the view through which this annotation is currently being manipulated. | |
| virtual bool | hitTest (int, int, const GlView &) const |
| Perform hit test with points of underlying object. Return true if object is hit, false otherwise. | |
| virtual void | setEditable (bool editable) |
| When a GlAnnotation is editable it may alter its visualization and render UI elements for its manipulation. | |
| virtual bool | editable () const |
| When a GlAnnotation is editable it may alter its visualization and render UI elements for its manipulation. | |
| virtual vec3 | color () const |
| Return annotation color. | |
| virtual double | alpha () const |
| Get alpha channel. | |
| virtual void | setLabelVisible (bool visible) |
| Set annotation label visibility. | |
| virtual bool | labelVisible () const |
| Return annotation label visibility. | |
| virtual void | setLabelBackgroundVisible (bool visible) |
| Set annotation label background visibility. | |
| virtual bool | labelBackgroundVisible () const |
| Return annotation label background visibility. | |
| virtual void | setLabelBackgroundColor (vec4 color) |
| Set annotation label background color. | |
| virtual vec4 | labelBackgroundColor () const |
| Return annotation label background color. | |
| virtual void | setLabelBackgroundMargin (int margin) |
| Set annotation label background margin in pixels. | |
| virtual int | labelBackgroundMargin () const |
| Return annotation label background margin in pixels. | |
| virtual void | setLabelDepthTest (bool depthTest) |
| Set annotation label depth test flag. | |
| virtual bool | labelDepthTest () const |
| Return annotation label depth test flag. | |
| virtual void | setLabelColor (const vec3 &color) |
| Set annotation label color. | |
| virtual vec3 | labelColor () const |
| Return annotation label color. | |
| virtual void | setLabelText (const std::string &label) |
| Set annotation label text. | |
| virtual std::string | labelText () const |
| Return annotation label text. | |
| virtual void | setLabelTextPrefix (const std::string &labelPrefix) |
| Set annotation label text prefix. | |
| std::string | labelTextPrefix () const |
| Return annotation label text prefix. | |
| virtual void | setLabelTextSuffix (const std::string &labelSuffix) |
| Set annotation label text suffix. | |
| std::string | labelTextSuffix () const |
| Return annotation label text suffix. | |
| virtual void | setName (const std::string &name) |
| Set annotation name. | |
| virtual std::string | name () const |
| Return annotation name. | |
| virtual void | setSelected (bool m) |
| When a GlAnnotation is selected, it may be rendered differently to distinguish it from non-selected annotations. | |
| bool | selected () const |
| When a GlAnnotation is selected, it may be rendered differently to distinguish it from non-selected annotations. | |
| virtual void | setMatrixWithoutMoving (const mat4 &m) |
| Change the matrix without moving the annotation, e.g. for linking it with an image transformation. | |
| void | copyStyle (const GlAnnotation &other) |
| Copies the settable parameters from another GlAnnotation. | |
Public Member Functions inherited from GlObject | |
| virtual void | setVisible (bool visible) |
| Set object visibility. | |
| virtual bool | visible () const |
| Return object visibility. | |
| virtual void | setAlwaysVisible (bool alwaysVisible) |
| Set if object is always visible. | |
| virtual bool | alwaysVisible () const |
| Return if object is always visible. | |
| RenderingOrderGroup | renderingOrder () const |
| Return current rendering order value for this GlObject. | |
| void | setRenderingOrder (RenderingOrderGroup group) |
| Set rendering order value for this GlObject. | |
| void | setDraw3DIn2DView (bool draw3DIn2DView) |
| void | configure (const Properties *p) override |
| Configure this object instance by de-serializing the given Properties. | |
| void | configuration (Properties *p) const override |
| Serialize the current object configuration into the given Properties object. | |
Public Member Functions inherited from Configurable | |
| virtual void | configureDefaults () |
| Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
| void | registerParameter (ParameterBase *param) |
| Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
| void | unregisterParameter (const ParameterBase *param) |
| Remove the given Parameter or SubProperty from the list of registered parameters. | |
| Configurable (const Configurable &rhs) | |
| Configurable (Configurable &&rhs) noexcept | |
| Configurable & | operator= (const Configurable &) |
| Configurable & | operator= (Configurable &&) noexcept |
Public Member Functions inherited from SignalReceiver | |
| SignalReceiver ()=default | |
| Default constructor. | |
| SignalReceiver (const SignalReceiver &other) | |
| Copy constructor, does not copy any existing signal connections from other. | |
| SignalReceiver & | operator= (SignalReceiver rhs) |
| Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs. | |
| virtual | ~SignalReceiver () |
| Virtual destructor disconnects from all connected signals. | |
Protected Member Functions | |
| void | dataDeleted (const Data *d) |
| bool | needsSurfaceRenderer (const GlView::Type &viewType) const |
| bool | needsCustomSurfaceRenderer (const GlView::Type &viewType) const |
| bool | needsSliceRenderer (const GlView::Type &viewType) const |
| bool | needsNormalRenderer (const GlView::Type &viewType) const |
Protected Member Functions inherited from GlAnnotation | |
| void | renderLabel (const GlView &view, const vec3 &positionWorld) const |
| Render the label of the annotation at the given position. | |
| vec2i | labelSize () const |
Protected Member Functions inherited from SignalReceiver | |
| void | disconnectAll () |
| Disconnects all existing connections. | |
Protected Attributes | |
| Mesh * | m_mesh = nullptr |
| RenderMode2d | m_renderMode2d = IntersectionOnly |
| RenderMode3d | m_renderMode3d = Surface |
| double | m_projectiveIntersectionTolerance = 0.0 |
| double | m_projectiveFadeoutRange = 10.0 |
| bool | m_drawIn2D = false |
| bool | m_drawNormals = false |
| bool | m_useDepthOffset = false |
| float | m_depthOffsetFactor = 2.f |
| float | m_depthOffsetUnits = 2.f |
Protected Attributes inherited from GlAnnotation | |
| bool | m_editable = true |
| vec4 | m_color {1, 1, 0, 1} |
| float | m_lineWidth = 1 |
| bool | m_labelVisible = true |
| bool | m_labelBackgroundVisible = false |
| vec4 | m_labelBackgroundColor {0.3, 0.3, 0.3, 0.7} |
| int | m_labelBackgroundMargin = 3 |
| bool | m_labelDepthTest = true |
| bool | m_selected = false |
| vec3 | m_labelColor {0, 1, 1} |
| std::string | m_labelText |
| std::string | m_labelTextPrefix |
| std::string | m_labelTextSuffix |
| const GlView * | m_view = nullptr |
| std::string | m_name |
Protected Attributes inherited from GlObject | |
| mat4 | m_matrix = mat4::Identity() |
| Modelview transformation matrix of this object. | |
| bool | m_visible = true |
| Object visibility. | |
| bool | m_alwaysVisible = false |
| Object always visible. | |
| bool | m_draw3DIn2DView |
| Draw 3D objects in 2D views. This is to render 3D objects in projective 2D views. Property is not serialized. | |
| RenderingOrderGroup | m_renderingOrder = RenderingGroupRest |
Protected Attributes inherited from Configurable | |
| std::vector< Param > | m_params |
| List of all registered Parameter and SubProperty instances. | |
Additional Inherited Members | |
Public Attributes inherited from Configurable | |
| Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
| enum RenderMode2d |
| Enumerator | |
|---|---|
| IntersectionOnly | Render intersection with MPR plane only. |
| FullProjective | Render full mesh orthographically projected onto MPR plane using the normal mesh color. Will always be shown whether or not intersecting the plane. |
| ProjectiveColorGradient | Render full mesh orthographically projected onto MPR plane. Depth wrt. MPR plane will be color coded as gradient between projectiveFrontColor() and projectiveBackColor(). Will only be shown when intersecting the plane. |
| ProjectiveWireframe | Render full mesh orthographically projected onto MPR plane. Parts in front of the MPR plane are rendered solid, parts behind the MPR plane are rendered in wireframe mode. Will only be shown when intersecting the plane. |
| Render3D | Render the object in 3D without any special treatments and the original projection matrix. |
| enum RenderMode3d |
| enum MaterialMode |
| Enumerator | |
|---|---|
| Uniform | uses the colors from setMaterial or setColor(const vec3&) |
| Color | uses the colors from setColor(const std::vector&) or mesh vertex colors for ambient, diffuse and specular |
| Texture | uses the mesh vertex texture for ambient, diffuse and specular |
| Shader | uses the provided custom shader |
| FaceLabel | uses the labels of faces |
| VertexLabel | uses the labels of vertices |
|
strong |
|
overridevirtual |
Set the modelview matrix of this object.
Reimplemented from GlObject.
|
overridevirtual |
Return the modelview matrix.
Reimplemented from GlObject.
|
virtual |
Attaches a Mesh to be rendered.
Calls updateBuffers() to synchronize mesh data and OpenGL buffers.
|
overridevirtual |
Calls draw3D for SPACE3D views and draw2D for SLICE2D views.
Implements GlObject.
|
virtual |
Computes the cross-section with the slice and displays it with lines.
Reimplemented in GlBox.
| void setRenderingDepthOffset | ( | bool | useOffset, |
| float | offsetFactor = 2.f, | ||
| float | offsetUnits = 2.f ) |
Sets the depth offset (see OpenGL glPolygonOffset for more details)
| useOffset | flag specifying whether the offset should be used |
| offsetFactor | a scale factor that is used to create a variable depth offset for each polygon |
| offsetUnits | is multiplied by an implementation-specific value to create a constant depth offset |
|
overridevirtual |
Sets the color of the front and back material (ambient, diffuse and specular)
Reimplemented from GlAnnotation.
|
overridevirtual |
Set alpha channel.
Reimplemented from GlAnnotation.
|
virtual |
Sets the material mode for the front facing triangles during 3D rendering.
In case the material mode is being set to VertexLabel or FaceLabel, GlMesh will be marked as dirty
|
virtual |
Sets the material mode for the back facing triangles during 3D rendering.
In case the material mode is being set to VertexLabel or FaceLabel, GlMesh will be marked as dirty
|
virtual |
Sets the material used for the front and back facing triangles during 3D rendering.
This only has an effect if front material mode is set to Uniform.
|
virtual |
Sets the material used for the front facing triangles during 3D rendering.
This only has an effect if front material mode is set to Uniform.
|
virtual |
Sets the material used for the back facing triangles during 3D rendering.
This only has an effect if back material mode is set to Uniform.
|
overridevirtual |
Return annotation line width.
Reimplemented from GlAnnotation.
|
overridevirtual |
Set annotation line width.
Reimplemented from GlAnnotation.
| void setLineStipplePattern | ( | uint16_t | pattern | ) |
Sets the stipple pattern of the rendered mesh plane intersection lines.
The stippling pattern is not continuous because the stippled lines are generated as sections around the circle and not as a continuous line. This is an experimental feature and may yield mixed results depending on the triangle count and zoom factor
| pattern | The given uint16_t will be interpreted as bit field defining which pixels to render. |
| void setLineStippleFactor | ( | double | factor | ) |
Sets the factor determining the length of the stipple pattern of the mesh plane intersection lines.
The stippling pattern is not continuous because the stippled lines are generated as sections around the circle and not as a continuous line. This is an experimental feature and may yield mixed results depending on the triangle count and zoom factor
| stippleFactor | Length of each individual pattern, a factor of 1 will result in the stipple pattern to be repeated every 16 |
|
virtual |
Sets a custom shader to be used as a replacement for the default shader in 3D.
The shader will be used if either front or back face material mode is set to Shader. Therefore, it is the shader's task to implement the correct behaviour if front and back face material mode differ, if this functionality is desired.
The vertex shader will receive the following inputs:
And the fragment shader has one output:
Additionally there are several uniforms (see Mesh3D.vert and Mesh3D.frag).
|
overridevirtual |
|
overridevirtual |
Computes a cheap approximation of the mesh bounds in world space The mesh bounds in local space are translated to the current mesh position in world space.
A sphere is fitted to the translated bounds, and its bounds are returned. This function runs in constant time, after the tight mesh bounds have been computed at least once. So it can be used if approximated bounds for a fast moving mesh are needed.
Reimplemented from GlObject.
|
overridevirtual |
Return unique identifier for this object class used for serialization.
Implements GlObject.
|
overridevirtual |
Return the center of the object in local coordinates without considering any matrix.
Implements Gl3DObject.
|
overridevirtual |
Return the extent of the object in local coordinates without considering any matrix.
Implements Gl3DObject.
|
overridevirtual |
Set one or multiple properties.
Reimplemented from GlAnnotation.
|
overridevirtual |
Retrieve the properties of this object.
Reimplemented from GlAnnotation.