DrawTool
Utility class to perform debug drawing. Class which contains a set of methods to perform minimal debug drawing regardless of the graphics API used. Components receive a pointer to the DrawTool through the VisualParams parameter of their draw method. Sofa provides a default concrete implementation of this class for the OpenGL API with the DrawToolGL class. k
Provides utility functions for minimal debug drawing, including geometric shapes, text, transformations, and state management.
- module
- Sofa.framework.Helper
- namespace
- sofa::helper::visual
- include
- sofa/helper/visual/DrawTool.h
The DrawTool class in the SOFA framework is not directly involved with mathematical computations or physical simulations but rather serves as an interface for rendering and manipulating graphical elements within a 3D scene. The core functionalities provided by this class include various drawing operations, transformation methods, state management techniques, and overlay drawing functions.
Drawing Operations
The DrawTool class provides several member functions for drawing geometric shapes in the 3D space such as points, lines, triangles, quads, tetrahedra, hexahedra, spheres, ellipsoids, bounding boxes, and text. These functions allow setting vertices (points), normals, and colors to render these shapes.
- Drawing Points: Functions like
drawPointaccept a position vector (Vec3) and optionally a color (RGBAColor). -
Mathematically, drawing a point involves plotting its position in the coordinate system defined by the scene's camera.
-
Drawing Triangles and Quads: Methods such as
drawTriangleanddrawQuadtake vertices and normals (optional) to render filled polygons. These can include optional per-vertex colors for shading purposes. - Mathematically, these operations involve transforming vertex coordinates through the current model-view-projection matrix and interpolating colors across surfaces based on Gouraud or Phong shading models.
Transformation Methods
Transformation methods provided by DrawTool enable applying affine transformations (scale, translate, rotate) to objects being rendered. Functions like translate, scale, and multMatrix are used for modifying the model-view matrix which affects how objects appear on screen after projection.
- Mathematically, transformation matrices are applied sequentially in a stack-based manner with functions like pushMatrix and popMatrix. Matrix multiplication is performed to combine multiple transformations into one composite transformation.
State Management
State management involves saving and restoring rendering states through functions such as saveLastState and restoreLastState, which help maintain consistency across different drawing operations without needing to manually set up the same state repeatedly.
- Mathematically, this can involve copying current matrix stacks or other rendering settings like lighting modes into a stack and then reverting them when needed using standard LIFO (last-in-first-out) principles.
Overlay Methods and Color Buffer Operations
Overlay methods such as writeOverlayText enable drawing text directly on the screen at specified 2D coordinates. Additionally, functions like readPixels allow reading color data from the rendering buffer to retrieve RGB values or depth information (z-buffer).
- Mathematically, these operations involve memory reads and writes within the frame buffer, which is a two-dimensional array of pixels representing the final rendered image.
Lighting and Blending Operations
The class provides methods for enabling/disabling lighting and blending modes that affect how colors are combined in the final rendering process. Functions such as setLightingEnabled and enableBlending control whether lighting calculations or alpha-blending should be applied during drawing operations, respectively.
- Mathematically, these involve setting parameters in shaders used for fragment coloring based on light sources (for lighting) or combining colors using blend factors for transparency blending.
Methods
void
init
()
virtual
void
drawPoints
(const int & points, float size, const RGBAColor & color)
virtual
void
drawPoints
(const int & points, float size, const int & color)
virtual
void
drawLine
(const Vec3 & p1, const Vec3 & p2, const RGBAColor & color)
virtual
void
drawInfiniteLine
(const Vec3 & point, const Vec3 & direction, const RGBAColor & color, const bool & vanishing)
virtual
void
drawInfiniteLine
(const Vec3 & point, const Vec3 & direction, const float & size, const RGBAColor & color, const bool & vanishing)
virtual
void
drawLines
(const int & points, float size, const RGBAColor & color)
virtual
void
drawLines
(const int & points, float size, const int & colors)
virtual
void
drawLines
(const int & points, const int & index, float size, const RGBAColor & color)
virtual
void
drawLineStrip
(const int & points, float size, const RGBAColor & color)
virtual
void
drawLineLoop
(const int & points, float size, const RGBAColor & color)
virtual
void
drawDisk
(float radius, double from, double to, int resolution, const RGBAColor & color)
virtual
void
drawCircle
(float radius, float lineThickness, int resolution, const RGBAColor & color)
virtual
void
drawTriangles
(const int & points, const RGBAColor & color)
virtual
void
drawTriangles
(const int & points, const Vec3 & normal, const RGBAColor & color)
virtual
void
drawTriangles
(const int & points, const int & index, const int & normal, const RGBAColor & color)
virtual
void
drawTriangles
(const int & points, const int & index, const int & normal, const int & color)
virtual
void
drawTriangles
(const int & points, const int & color)
virtual
void
drawTriangles
(const int & points, const int & normal, const int & color)
virtual
void
drawTriangleStrip
(const int & points, const int & normal, const RGBAColor & color)
virtual
void
drawTriangleFan
(const int & points, const int & normal, const RGBAColor & color)
virtual
void
drawFrame
(const Vec3 & position, const Quaternion & orientation, const Vec3f & size)
virtual
void
drawFrame
(const Vec3 & position, const Quaternion & orientation, const Vec3f & size, const RGBAColor & color)
virtual
void
drawSpheres
(const int & points, const int & radius, const RGBAColor & color)
virtual
void
drawSpheres
(const int & points, float radius, const RGBAColor & color)
virtual
void
drawFakeSpheres
(const int & points, const int & radius, const RGBAColor & color)
virtual
void
drawFakeSpheres
(const int & points, float radius, const RGBAColor & color)
virtual
void
drawCone
(const Vec3 & p1, const Vec3 & p2, float radius1, float radius2, const RGBAColor & color, int subd)
virtual
void
drawCube
(const float & radius, const RGBAColor & color, const int & subd)
virtual
void
drawCylinder
(const Vec3 & p1, const Vec3 & p2, float radius, const RGBAColor & color, int subd)
virtual
void
drawCapsule
(const Vec3 & p1, const Vec3 & p2, float radius, const RGBAColor & color, int subd)
virtual
void
drawArrow
(const Vec3 & p1, const Vec3 & p2, float radius, const RGBAColor & color, int subd)
virtual
void
drawArrow
(const Vec3 & p1, const Vec3 & p2, float radius, float coneLength, const RGBAColor & color, int subd)
virtual
void
drawArrow
(const Vec3 & p1, const Vec3 & p2, float radius, float coneLength, float coneRadius, const RGBAColor & color, int subd)
virtual
void
drawCross
(const Vec3 & p, float length, const RGBAColor & color)
virtual
void
drawPlus
(const float & radius, const RGBAColor & color, const int & subd)
virtual
void
drawPoint
(const Vec3 & p, const RGBAColor & c)
virtual
void
drawPoint
(const Vec3 & p, const Vec3 & n, const RGBAColor & c)
virtual
void
drawTriangle
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & normal)
virtual
void
drawTriangle
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & normal, const RGBAColor & c)
virtual
void
drawTriangle
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & normal, const RGBAColor & c1, const RGBAColor & c2, const RGBAColor & c3)
virtual
void
drawTriangle
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & normal1, const Vec3 & normal2, const Vec3 & normal3, const RGBAColor & c1, const RGBAColor & c2, const RGBAColor & c3)
virtual
void
drawQuad
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & p4, const Vec3 & normal)
virtual
void
drawQuad
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & p4, const Vec3 & normal, const RGBAColor & c)
virtual
void
drawQuad
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & p4, const Vec3 & normal, const RGBAColor & c1, const RGBAColor & c2, const RGBAColor & c3, const RGBAColor & c4)
virtual
void
drawQuad
(const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & p4, const Vec3 & normal1, const Vec3 & normal2, const Vec3 & normal3, const Vec3 & normal4, const RGBAColor & c1, const RGBAColor & c2, const RGBAColor & c3, const RGBAColor & c4)
virtual
void
drawQuads
(const int & points, const RGBAColor & color)
virtual
void
drawQuads
(const int & points, const int & colors)
virtual
void
drawTetrahedron
(const Vec3 & p0, const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const RGBAColor & color)
virtual
void
drawScaledTetrahedron
(const Vec3 & p0, const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const RGBAColor & color, const float scale)
virtual
void
drawTetrahedra
(const int & points, const RGBAColor & color)
virtual
void
drawScaledTetrahedra
(const int & points, const RGBAColor & color, const float scale)
virtual
void
drawHexahedron
(const Vec3 & p0, const Vec3 & p1, const Vec3 & p2, const Vec3 & p3, const Vec3 & p4, const Vec3 & p5, const Vec3 & p6, const Vec3 & p7, const RGBAColor & color)
virtual
void
drawHexahedra
(const int & points, const RGBAColor & color)
virtual
void
drawScaledHexahedra
(const int & points, const RGBAColor & color, const float scale)
virtual
void
drawSphere
(const Vec3 & p, float radius)
virtual
void
drawSphere
(const Vec3 & p, float radius, const RGBAColor & color)
virtual
void
drawEllipsoid
(const Vec3 & p, const Vec3 & radii)
virtual
void
drawBoundingBox
(const Vec3 & min, const Vec3 & max, float size)
virtual
void
draw3DText
(const Vec3 & p, float scale, const RGBAColor & color, const char * text)
virtual
void
draw3DText_Indices
(const int & positions, float scale, const RGBAColor & color)
virtual
void
pushMatrix
()
virtual
void
popMatrix
()
virtual
void
multMatrix
(float * )
virtual
void
scale
(float )
virtual
void
translate
(float x, float y, float z)
virtual
void
setMaterial
(const RGBAColor & color)
virtual
void
resetMaterial
(const RGBAColor & color)
virtual
void
resetMaterial
()
virtual
void
setPolygonMode
(int _mode, bool _wireframe)
virtual
void
setLightingEnabled
(bool _isAnabled)
virtual
void
enableBlending
()
virtual
void
disableBlending
()
virtual
void
enableLighting
()
virtual
void
disableLighting
()
virtual
void
enableDepthTest
()
virtual
void
disableDepthTest
()
virtual
void
saveLastState
()
virtual
void
restoreLastState
()
virtual
StateLifeCycle
makeStateLifeCycle
()
void
writeOverlayText
(int x, int y, unsigned int fontSize, const RGBAColor & color, const char * text)
virtual
void
enablePolygonOffset
(float factor, float units)
virtual
void
disablePolygonOffset
()
virtual
void
readPixels
(int x, int y, int w, int h, float * rgb, float * z)
virtual
void
clear
()
virtual
{
"name": "DrawTool",
"namespace": "sofa::helper::visual",
"module": "Sofa.framework.Helper",
"include": "sofa/helper/visual/DrawTool.h",
"doc": "Utility class to perform debug drawing.\n Class which contains a set of methods to perform minimal debug drawing regardless of the graphics API used.\n Components receive a pointer to the DrawTool through the VisualParams parameter of their draw method.\n Sofa provides a default concrete implementation of this class for the OpenGL API with the DrawToolGL class.\nk",
"inherits": [],
"templates": [],
"data_fields": [],
"links": [],
"methods": [
{
"name": "init",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawPoints",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawPoints",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "color",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawLine",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawInfiniteLine",
"return_type": "void",
"params": [
{
"name": "point",
"type": "const Vec3 &"
},
{
"name": "direction",
"type": "const Vec3 &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "vanishing",
"type": "const bool &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawInfiniteLine",
"return_type": "void",
"params": [
{
"name": "point",
"type": "const Vec3 &"
},
{
"name": "direction",
"type": "const Vec3 &"
},
{
"name": "size",
"type": "const float &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "vanishing",
"type": "const bool &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawLines",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawLines",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "colors",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawLines",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "index",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawLineStrip",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawLineLoop",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "size",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawDisk",
"return_type": "void",
"params": [
{
"name": "radius",
"type": "float"
},
{
"name": "from",
"type": "double"
},
{
"name": "to",
"type": "double"
},
{
"name": "resolution",
"type": "int"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawCircle",
"return_type": "void",
"params": [
{
"name": "radius",
"type": "float"
},
{
"name": "lineThickness",
"type": "float"
},
{
"name": "resolution",
"type": "int"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangles",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangles",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "normal",
"type": "const Vec3 &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangles",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "index",
"type": "const int &"
},
{
"name": "normal",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangles",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "index",
"type": "const int &"
},
{
"name": "normal",
"type": "const int &"
},
{
"name": "color",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangles",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangles",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "normal",
"type": "const int &"
},
{
"name": "color",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangleStrip",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "normal",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangleFan",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "normal",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawFrame",
"return_type": "void",
"params": [
{
"name": "position",
"type": "const Vec3 &"
},
{
"name": "orientation",
"type": "const Quaternion &"
},
{
"name": "size",
"type": "const Vec3f &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawFrame",
"return_type": "void",
"params": [
{
"name": "position",
"type": "const Vec3 &"
},
{
"name": "orientation",
"type": "const Quaternion &"
},
{
"name": "size",
"type": "const Vec3f &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawSpheres",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "radius",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawSpheres",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawFakeSpheres",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "radius",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawFakeSpheres",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawCone",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "radius1",
"type": "float"
},
{
"name": "radius2",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawCube",
"return_type": "void",
"params": [
{
"name": "radius",
"type": "const float &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawCylinder",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawCapsule",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawArrow",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawArrow",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "coneLength",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawArrow",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "coneLength",
"type": "float"
},
{
"name": "coneRadius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawCross",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "length",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawPlus",
"return_type": "void",
"params": [
{
"name": "radius",
"type": "const float &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "subd",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawPoint",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "c",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawPoint",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "n",
"type": "const Vec3 &"
},
{
"name": "c",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangle",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "normal",
"type": "const Vec3 &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangle",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "normal",
"type": "const Vec3 &"
},
{
"name": "c",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangle",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "normal",
"type": "const Vec3 &"
},
{
"name": "c1",
"type": "const RGBAColor &"
},
{
"name": "c2",
"type": "const RGBAColor &"
},
{
"name": "c3",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTriangle",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "normal1",
"type": "const Vec3 &"
},
{
"name": "normal2",
"type": "const Vec3 &"
},
{
"name": "normal3",
"type": "const Vec3 &"
},
{
"name": "c1",
"type": "const RGBAColor &"
},
{
"name": "c2",
"type": "const RGBAColor &"
},
{
"name": "c3",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawQuad",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "p4",
"type": "const Vec3 &"
},
{
"name": "normal",
"type": "const Vec3 &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawQuad",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "p4",
"type": "const Vec3 &"
},
{
"name": "normal",
"type": "const Vec3 &"
},
{
"name": "c",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawQuad",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "p4",
"type": "const Vec3 &"
},
{
"name": "normal",
"type": "const Vec3 &"
},
{
"name": "c1",
"type": "const RGBAColor &"
},
{
"name": "c2",
"type": "const RGBAColor &"
},
{
"name": "c3",
"type": "const RGBAColor &"
},
{
"name": "c4",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawQuad",
"return_type": "void",
"params": [
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "p4",
"type": "const Vec3 &"
},
{
"name": "normal1",
"type": "const Vec3 &"
},
{
"name": "normal2",
"type": "const Vec3 &"
},
{
"name": "normal3",
"type": "const Vec3 &"
},
{
"name": "normal4",
"type": "const Vec3 &"
},
{
"name": "c1",
"type": "const RGBAColor &"
},
{
"name": "c2",
"type": "const RGBAColor &"
},
{
"name": "c3",
"type": "const RGBAColor &"
},
{
"name": "c4",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawQuads",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawQuads",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "colors",
"type": "const int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTetrahedron",
"return_type": "void",
"params": [
{
"name": "p0",
"type": "const Vec3 &"
},
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawScaledTetrahedron",
"return_type": "void",
"params": [
{
"name": "p0",
"type": "const Vec3 &"
},
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "scale",
"type": "const float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawTetrahedra",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawScaledTetrahedra",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "scale",
"type": "const float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawHexahedron",
"return_type": "void",
"params": [
{
"name": "p0",
"type": "const Vec3 &"
},
{
"name": "p1",
"type": "const Vec3 &"
},
{
"name": "p2",
"type": "const Vec3 &"
},
{
"name": "p3",
"type": "const Vec3 &"
},
{
"name": "p4",
"type": "const Vec3 &"
},
{
"name": "p5",
"type": "const Vec3 &"
},
{
"name": "p6",
"type": "const Vec3 &"
},
{
"name": "p7",
"type": "const Vec3 &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawHexahedra",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawScaledHexahedra",
"return_type": "void",
"params": [
{
"name": "points",
"type": "const int &"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "scale",
"type": "const float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawSphere",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawSphere",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "radius",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawEllipsoid",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "radii",
"type": "const Vec3 &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "drawBoundingBox",
"return_type": "void",
"params": [
{
"name": "min",
"type": "const Vec3 &"
},
{
"name": "max",
"type": "const Vec3 &"
},
{
"name": "size",
"type": "float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "draw3DText",
"return_type": "void",
"params": [
{
"name": "p",
"type": "const Vec3 &"
},
{
"name": "scale",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "text",
"type": "const char *"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "draw3DText_Indices",
"return_type": "void",
"params": [
{
"name": "positions",
"type": "const int &"
},
{
"name": "scale",
"type": "float"
},
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "pushMatrix",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "popMatrix",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "multMatrix",
"return_type": "void",
"params": [
{
"name": "",
"type": "float *"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "scale",
"return_type": "void",
"params": [
{
"name": "",
"type": "float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "translate",
"return_type": "void",
"params": [
{
"name": "x",
"type": "float"
},
{
"name": "y",
"type": "float"
},
{
"name": "z",
"type": "float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "setMaterial",
"return_type": "void",
"params": [
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "resetMaterial",
"return_type": "void",
"params": [
{
"name": "color",
"type": "const RGBAColor &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "resetMaterial",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "setPolygonMode",
"return_type": "void",
"params": [
{
"name": "_mode",
"type": "int"
},
{
"name": "_wireframe",
"type": "bool"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "setLightingEnabled",
"return_type": "void",
"params": [
{
"name": "_isAnabled",
"type": "bool"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "enableBlending",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "disableBlending",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "enableLighting",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "disableLighting",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "enableDepthTest",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "disableDepthTest",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "saveLastState",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "restoreLastState",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "makeStateLifeCycle",
"return_type": "StateLifeCycle",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "writeOverlayText",
"return_type": "void",
"params": [
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "int"
},
{
"name": "fontSize",
"type": "unsigned int"
},
{
"name": "color",
"type": "const RGBAColor &"
},
{
"name": "text",
"type": "const char *"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "enablePolygonOffset",
"return_type": "void",
"params": [
{
"name": "factor",
"type": "float"
},
{
"name": "units",
"type": "float"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "disablePolygonOffset",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "readPixels",
"return_type": "void",
"params": [
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "int"
},
{
"name": "w",
"type": "int"
},
{
"name": "h",
"type": "int"
},
{
"name": "rgb",
"type": "float *"
},
{
"name": "z",
"type": "float *"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "clear",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
}
],
"componentOverview": {
"name": "DrawTool",
"description": "The `DrawTool` class in the SOFA (Simulation Open-Framework Architecture) framework provides an abstract interface for rendering various graphical elements and managing drawing states within a 3D scene.",
"namespace": "sofa::helper::visual"
},
"keyFeatures": [
{
"name": "Rendering Capabilities",
"description": "The `DrawTool` class supports the rendering of various geometric shapes, including points, lines, triangles, quads, spheres, bounding boxes, and text. It also allows for drawing custom overlays with 2D text and managing polygon offsets."
},
{
"name": "State Management",
"description": "It provides methods to save and restore the state of the drawing context using RAII (Resource Acquisition Is Initialization) technique through `StateLifeCycle` struct. This ensures that drawing states are correctly managed and restored after operations, maintaining consistency in rendering pipelines."
},
{
"name": "Transformation Methods",
"description": "The class supports transformation operations like pushing and popping matrices from the stack, scaling, translating, and applying transformations with a matrix for complex scene manipulations."
},
{
"name": "Drawing Styles",
"description": "Users can set material properties, polygon modes (fill or wireframe), lighting conditions, and enable/disable various rendering features such as blending, depth testing, and lighting to control the appearance of rendered objects."
},
{
"name": "Color Buffer Methods",
"description": "It provides a method for reading pixel data from the color buffer (`readPixels`), which can be useful for implementing post-processing effects or performing screen-space operations like raytracing in software or capturing screenshots with depth information."
}
],
"componentDetails": {
"author": "The SOFA Team and external contributors",
"license": "GNU Lesser General Public License (LGPL) version 2.1 or later",
"dependencies": [
"sofa::type"
]
},
"usageInstructions": {
"overview": "To use the `DrawTool` class, instantiate a derived concrete implementation such as OpenGL-based renderer and call its methods to render graphical elements and manage drawing states.",
"exampleCode": "```cpp\n#include <sofa/helper/visual/DrawTool.h>\n\nusing namespace sofa::helper::visual;\n\n// Assuming drawTool is an instance of a specific DrawTool subclass like GLDrawTool\ndrawTool->drawSphere(Vec3(0.0, 0.0, 0.0), 1.0);\ndrawTool->pushMatrix();\ndrawTool->translate(2.0, 0.0, 0.0);\ndrawTool->drawTetrahedron(Vec3(0,0,0), Vec3(1,0,0), Vec3(0,1,0), Vec3(0,0,1));\ndrawTool->popMatrix();\n```"
},
"maths": "The `DrawTool` class in the SOFA framework is not directly involved with mathematical computations or physical simulations but rather serves as an interface for rendering and manipulating graphical elements within a 3D scene. The core functionalities provided by this class include various drawing operations, transformation methods, state management techniques, and overlay drawing functions.\n\n### Drawing Operations\nThe `DrawTool` class provides several member functions for drawing geometric shapes in the 3D space such as points, lines, triangles, quads, tetrahedra, hexahedra, spheres, ellipsoids, bounding boxes, and text. These functions allow setting vertices (points), normals, and colors to render these shapes.\n\n- **Drawing Points:** Functions like `drawPoint` accept a position vector (`Vec3`) and optionally a color (`RGBAColor`).\n - Mathematically, drawing a point involves plotting its position in the coordinate system defined by the scene's camera.\n\n- **Drawing Triangles and Quads:** Methods such as `drawTriangle` and `drawQuad` take vertices and normals (optional) to render filled polygons. These can include optional per-vertex colors for shading purposes.\n - Mathematically, these operations involve transforming vertex coordinates through the current model-view-projection matrix and interpolating colors across surfaces based on Gouraud or Phong shading models.\n\n### Transformation Methods\nTransformation methods provided by `DrawTool` enable applying affine transformations (scale, translate, rotate) to objects being rendered. Functions like `translate`, `scale`, and `multMatrix` are used for modifying the model-view matrix which affects how objects appear on screen after projection.\n - Mathematically, transformation matrices are applied sequentially in a stack-based manner with functions like `pushMatrix` and `popMatrix`. Matrix multiplication is performed to combine multiple transformations into one composite transformation.\n\n### State Management\nState management involves saving and restoring rendering states through functions such as `saveLastState` and `restoreLastState`, which help maintain consistency across different drawing operations without needing to manually set up the same state repeatedly.\n - Mathematically, this can involve copying current matrix stacks or other rendering settings like lighting modes into a stack and then reverting them when needed using standard LIFO (last-in-first-out) principles.\n\n### Overlay Methods and Color Buffer Operations\nOverlay methods such as `writeOverlayText` enable drawing text directly on the screen at specified 2D coordinates. Additionally, functions like `readPixels` allow reading color data from the rendering buffer to retrieve RGB values or depth information (`z-buffer`).\n - Mathematically, these operations involve memory reads and writes within the frame buffer, which is a two-dimensional array of pixels representing the final rendered image.\n\n### Lighting and Blending Operations\nThe class provides methods for enabling/disabling lighting and blending modes that affect how colors are combined in the final rendering process. Functions such as `setLightingEnabled` and `enableBlending` control whether lighting calculations or alpha-blending should be applied during drawing operations, respectively.\n - Mathematically, these involve setting parameters in shaders used for fragment coloring based on light sources (for lighting) or combining colors using blend factors for transparency blending.",
"abstract": "Provides utility functions for minimal debug drawing, including geometric shapes, text, transformations, and state management.",
"sheet": "# DrawTool\n\n**Overview**\nDrawTool is a utility class in SOFA that provides methods for performing minimal debug drawing. It supports various graphical elements such as points, lines, triangles, quads, spheres, ellipsoids, bounding boxes, text, and more. The class also includes transformation methods (translate, scale) and state management techniques to maintain rendering consistency.\n\n**Parameters and Data**\nThe `DrawTool` class does not expose any significant data fields; its functionality is primarily through method calls for drawing operations and transformations.\n\n**Dependencies and Connections**\nComponents in SOFA receive a pointer to the DrawTool instance via the VisualParams parameter of their draw methods. This allows them to perform debug drawings using the provided functions."
}