Visual Computing Library  devel
Loading...
Searching...
No Matches
abstract_drawable_mesh.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_RENDER_DRAWABLE_ABSTRACT_DRAWABLE_MESH_H
24#define VCL_RENDER_DRAWABLE_ABSTRACT_DRAWABLE_MESH_H
25
26#include "drawable_object.h"
27#include "mesh/mesh_render_settings.h"
28
29#include <vclib/space/core/matrix.h>
30
31namespace vcl {
32
41{
42 inline static const Image EMPTY_IMAGE;
43
44protected:
46
47 Box3d mBoundingBox;
48
49public:
50 using MatIt = std::vector<Material>::const_iterator;
51
52 AbstractDrawableMesh() = default;
53
55
56 template<MeshConcept MeshType>
57 AbstractDrawableMesh(const MeshType& m) : mMRS(m)
58 {
59 }
60
61 const MeshRenderSettings& renderSettings() const { return mMRS; }
62
63 virtual void updateBuffers(
65 MeshRenderInfo::BUFFERS_ALL) = 0;
66
67 virtual void setRenderSettings(const MeshRenderSettings& rs) { mMRS = rs; }
68
69 virtual uint vertexNumber() const = 0;
70
71 virtual uint faceNumber() const = 0;
72
73 virtual uint edgeNumber() const = 0;
74
75 virtual vcl::Matrix44d transformMatrix() const = 0;
76
77 virtual View<MatIt> materials() const { return View<MatIt>(); }
78
79 virtual const Image& textureImage(const std::string& path) const
80 {
81 return EMPTY_IMAGE;
82 }
83
84 // DrawableObject implementation
85
86 Box3d boundingBox() const override { return mBoundingBox; }
87
88 inline bool isVisible() const override { return mMRS.isVisible(); }
89
90 inline void setVisibility(bool vis) override { mMRS.setVisibility(vis); }
91
92protected:
93 void swap(AbstractDrawableMesh& other)
94 {
95 using std::swap;
97 swap(mMRS, other.mMRS);
98 swap(mBoundingBox, other.mBoundingBox);
99 }
100
101 // if the mesh does not have a bounding box, or if it has it but it is
102 // null, compute it from the vertex positions. If the mesh has a
103 // transformation matrix, apply it to the bounding box.
104 // The DrawableMesh must return the *transformed* bounding box.
105 template<MeshConcept MeshType>
106 void computeBoundingBox(const MeshType& m)
107 {
108 bool bbToInitialize = !vcl::HasBoundingBox<MeshType>;
109 if constexpr (vcl::HasBoundingBox<MeshType>) {
110 if (m.boundingBox().isNull()) {
111 bbToInitialize = true;
112 }
113 else {
114 mBoundingBox =
115 m.MeshType::boundingBox().template cast<double>();
116 }
117 }
118
119 if (bbToInitialize) {
120 mBoundingBox = vcl::boundingBox(m);
121 }
122
123 if constexpr (HasTransformMatrix<MeshType>) {
124 mBoundingBox = transformBox(mBoundingBox, m.transformMatrix());
125 }
126 }
127};
128
129} // namespace vcl
130
131#endif // VCL_RENDER_DRAWABLE_ABSTRACT_DRAWABLE_MESH_H
The AbstractDrawableMesh class is the base class for all the drawable meshes in the VCLib render syst...
Definition abstract_drawable_mesh.h:41
Box3d boundingBox() const override
This member function is used to find a good camera position to render object. It should return the th...
Definition abstract_drawable_mesh.h:86
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition abstract_drawable_mesh.h:90
bool isVisible() const override
This member function is used to check if the object is visible.
Definition abstract_drawable_mesh.h:88
The BitSet class allows to treat an integral type as an array of booleans of a guaranteed size.
Definition bit_set.h:52
The DrawableObject class is the base class for all the objects that can be drawn in a 3D viewer.
Definition drawable_object.h:57
void swap(DrawableObject &other)
Utility swap function that allows to swap the content of two DrawableObject instances.
Definition drawable_object.h:195
A class for representing and manipulating 2D images.
Definition image.h:48
The MeshRenderSettings class allows an easy management of render settings of a Mesh....
Definition mesh_render_settings.h:70
bool isVisible() const
Returns whether the mesh is visible.
Definition mesh_render_settings.h:199
bool setVisibility(bool b)
Sets the visibility of the mesh.
Definition mesh_render_settings.h:321
Concept that is evaluated true if a Mesh has the BoundingBox component.
Definition mesh_requirements.h:53
auto boundingBox(const PointType &p)
Compute the bounding box of a single point.
Definition bounding_box.h:59