Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Feb 9, 2025
1 parent fc0bb60 commit 71b81f3
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 124 deletions.
231 changes: 174 additions & 57 deletions easy3d/renderer/drawable.h

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions easy3d/renderer/drawable_lines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ namespace easy3d {
}


Drawable::Type LinesDrawable::type() const {
return DT_LINES;
}


void LinesDrawable::draw(const Camera *camera) const {
if (update_needed_ || vertex_buffer_ == 0) {
const_cast<LinesDrawable *>(this)->update_buffers_internal();
Expand Down
46 changes: 38 additions & 8 deletions easy3d/renderer/drawable_lines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,59 @@
namespace easy3d {

/**
* \brief The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields
* \brief The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
* \class LinesDrawable easy3d/renderer/drawable_lines.h
* \see PointsDrawable, TrianglesDrawable
* \sa PointsDrawable, TrianglesDrawable
*/
class LinesDrawable : public Drawable {
public:
/**
* \brief Constructor that initializes the drawable with a name and an optional model.
* \param name The name of the drawable.
* \param model The model to which the drawable is attached (can be nullptr).
*/
explicit LinesDrawable(const std::string& name = "", Model* model = nullptr);

Type type() const override;
/**
* \brief Returns the type of the drawable.
* \return The type of the drawable, which is DT_LINES.
*/
Type type() const override { return DT_LINES; }

// a line poster can be a cylinder, or a cone
/**
* \brief The type of the line imposter.
*/
enum ImposterType {
PLAIN,
CYLINDER,
CONE
PLAIN, //!< Plain mode.
CYLINDER, //!< The lines will be drawn as cylinders.
CONE //!< The lines will be drawn as cons.
};
/**
* \brief Returns the type of the line imposter.
* \return The type of the line imposter.
*/
ImposterType impostor_type() const { return impostor_type_; }
/**
* \brief Sets the type of the line imposter.
* \param t The new type of the line imposter.
*/
void set_impostor_type(ImposterType t) { impostor_type_ = t; }

/**
* \brief Returns the width of the lines.
* \return The width of the lines.
*/
float line_width() const { return line_width_; }
/**
* \brief Sets the width of the lines.
* \param w The new width of the lines.
*/
void set_line_width(float w) { line_width_ = w; }

// Rendering.
/**
* \brief Draws the drawable.
* \param camera The camera used for rendering.
*/
void draw(const Camera* camera) const override;

protected:
Expand Down
5 changes: 0 additions & 5 deletions easy3d/renderer/drawable_lines_2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ namespace easy3d {
}


Drawable::Type LinesDrawable2D::type() const {
return DT_LINES;
}


void LinesDrawable2D::update_vertex_buffer(const std::vector<vec2> &vertices, int width, int height, bool dynamic) {
assert(vao_);

Expand Down
17 changes: 14 additions & 3 deletions easy3d/renderer/drawable_lines_2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,26 @@ namespace easy3d {
* Line width, imposter, texturing, per-element color, and scalar attributes are not implemented given
* the limited usage cases.
* \class LinesDrawable2D easy3d/renderer/drawable_lines_2D.h
* \see LinesDrawable the 3D version of lines drawables.
* \sa LinesDrawable the 3D version of lines drawables.
*/
class LinesDrawable2D : public Drawable {
public:
/**
* \brief Constructor that initializes the drawable with a name.
* \param name The name of the drawable.
*/
explicit LinesDrawable2D(const std::string& name = "");

Type type() const override;
/**
* \brief Returns the type of the drawable.
* \return The type of the drawable, which is DT_LINES.
*/
Type type() const override { return DT_LINES; }

// Rendering.
/**
* \brief Draws the drawable.
* \param camera The camera used for rendering.
*/
void draw(const Camera* camera) const override;

/**
Expand Down
5 changes: 0 additions & 5 deletions easy3d/renderer/drawable_points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ namespace easy3d {
}


Drawable::Type PointsDrawable::type() const {
return DT_POINTS;
}


void PointsDrawable::draw(const Camera *camera) const {
if (update_needed_ || vertex_buffer_ == 0) {
const_cast<PointsDrawable *>(this)->update_buffers_internal();
Expand Down
52 changes: 40 additions & 12 deletions easy3d/renderer/drawable_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,59 @@ namespace easy3d {
/**
* \brief The drawable for rendering a set of points, e.g., point clouds, vertices of a mesh.
* \class PointsDrawable easy3d/renderer/drawable_points.h
* \see LinesDrawable, TrianglesDrawable
* \sa LinesDrawable, TrianglesDrawable
*/

class PointsDrawable : public Drawable {
public:
explicit PointsDrawable(const std::string& name = "", Model* model = nullptr);

Type type() const override;

// a point imposter can be a sphere, or a surfel/disc
/**
* \brief Constructor that initializes the drawable with a name and an optional model.
* \param name The name of the drawable.
* \param model The model to which the drawable is attached (can be nullptr).
*/
explicit PointsDrawable(const std::string& name = "", Model* model = nullptr);

/**
* \brief Returns the type of the drawable.
* \return The type of the drawable, which is DT_POINTS.
*/
Type type() const override { return DT_POINTS; }

/**
* \brief The type of the point imposter.
*/
enum ImposterType {
PLAIN,
SPHERE,
SURFEL
PLAIN, //!< Plain mode.
SPHERE, //!< The points will be drawn as spheres.
SURFEL //!< The points will be drawn as surfels/discs.
};

/** Get/Set impostor type. */
/**
* \brief Returns the type of the point imposter.
* \return The type of the point imposter.
*/
ImposterType impostor_type() const { return impostor_type_; }
/**
* \brief Sets the type of the point imposter.
* \param t The new type of the point imposter.
*/
void set_impostor_type(ImposterType t) { impostor_type_ = t; }

/** Get/Set point size. */
/**
* \brief Returns the size of the points.
* \return The size of the points.
*/
float point_size() const { return point_size_; }
/**
* \brief Sets the size of the points.
* \param s The new size of the points.
*/
void set_point_size(float s) { point_size_ = s; }

// Rendering.
/**
* \brief Draws the drawable.
* \param camera The camera used for rendering.
*/
void draw(const Camera* camera) const override;

protected:
Expand Down
5 changes: 0 additions & 5 deletions easy3d/renderer/drawable_triangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ namespace easy3d {
}


Drawable::Type TrianglesDrawable::type() const {
return DT_TRIANGLES;
}


void TrianglesDrawable::draw(const Camera *camera) const {
if (update_needed_ || vertex_buffer_ == 0) {
const_cast<TrianglesDrawable *>(this)->update_buffers_internal();
Expand Down
70 changes: 46 additions & 24 deletions easy3d/renderer/drawable_triangles.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,64 @@ namespace easy3d {
/**
* \brief The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
* \class TrianglesDrawable easy3d/renderer/drawable_triangles.h
* \see LinesDrawable, PointsDrawable
* \sa LinesDrawable, PointsDrawable
*
* \note TrianglesDrawable supports triangles only. Visualizing general polygons typically requires tessellating
* the faces into a set of triangles (using Tessellator or any other methods). Vertex coordinates and properties
* (e.g., color, normal) must be provided as consecutive triplets in an array to be transferred to GPU.
* See Drawable::update_vertex_buffer().
* the faces into a set of triangles (using Tessellator or any other methods). Vertex coordinates and
* properties (e.g., color, normal) must be provided as consecutive triplets in an array to be transferred to
* GPU. See Drawable::update_vertex_buffer().
*/
class TrianglesDrawable : public Drawable {
public:
/**
* \brief Constructor that initializes the drawable with a name and an optional model.
* \param name The name of the drawable.
* \param model The model to which the drawable is attached (can be nullptr).
*/
explicit TrianglesDrawable(const std::string& name = "", Model* model = nullptr);

Type type() const override;
/**
* \brief Returns the type of the drawable.
* \return The type of the drawable, which is DT_TRIANGLES.
*/
Type type() const override { return DT_TRIANGLES; }

bool smooth_shading() const { return smooth_shading_; }
void set_smooth_shading(bool b) { smooth_shading_ = b; }
/**
* \brief Returns the type of the drawable.
* \return The type of the drawable.
*/
bool smooth_shading() const { return smooth_shading_; }
/**
* \brief Sets whether smooth shading is enabled.
* \param b True to enable smooth shading, false to disable.
*/
void set_smooth_shading(bool b) { smooth_shading_ = b; }

/**
* @brief Query the opacity of the drawable, in the range [0.0, 1.0].
* @return The opacity of the drawable.
* @note Opacity is effective only when transparency (e.g., DualDepthPeeling, AverageColorBlending) rendering is enabled.
*/
float opacity() const { return opacity_; }
/**
* \brief Query the opacity of the drawable, in the range [0.0, 1.0], with 0.0 being fully transparent and
* 1.0 being fully opaque.
* \return The opacity of the drawable.
* \note Opacity is effective only when transparency (e.g., DualDepthPeeling, AverageColorBlending) rendering
* is enabled.
*/
float opacity() const { return opacity_; }
/**
* \brief Set the opacity of the drawable.
* \param opacity The new opacity value, in the range [0.0, 1.0].
* \note Opacity is effective only when transparency (e.g., DualDepthPeeling, AverageColorBlending) rendering
* is enabled.
*/
void set_opacity(float opacity) { opacity_ = opacity; }

/**
* @brief Set the opacity of the drawable.
* @param opacity The new opacity value, in the range [0.0, 1.0].
* @note Opacity is effective only when transparency (e.g., DualDepthPeeling, AverageColorBlending) rendering is enabled.
*/
void set_opacity(float opacity) { opacity_ = opacity; }

// Rendering.
void draw(const Camera* camera) const override;
/**
* \brief Draws the drawable.
* \param camera The camera used for rendering.
*/
void draw(const Camera* camera) const override;

private:
bool smooth_shading_;
float opacity_;
bool smooth_shading_; //!< Whether smooth shading is enabled.
float opacity_; //!< The opacity of the drawable.
};

}
Expand Down

0 comments on commit 71b81f3

Please sign in to comment.