Debian Codegraph @

avogadro/core/mesh.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CORE_MESH_H
7 #define AVOGADRO_CORE_MESH_H
8
9 #include "avogadrocoreexport.h"
10
11 #include "array.h"
12 #include "color3f.h"
13 #include "vector.h"
14
15 namespace Avogadro::Core {
16
17 class Molecule;
18 class Mutex;
19
20 /**
21 * @class Mesh mesh.h <avogadro/core/mesh.h>
22 * @brief Encapsulation of a triangular mesh that makes up a surface.
23 * @author Marcus D. Hanwell
24 *
25 * The Mesh class is a data container that provides a Mesh object. All
26 * meshes should be owned by a Molecule. It should also be removed by the
27 * Molecule that owns it. Meshes encapsulate triangular meshes that can also
28 * have colors associated with each vertex.
29 */
30
31 class MeshPrivate;
32 class AVOGADROCORE_EXPORT Mesh
33 {
34 public:
35 /**
36 * Constructor.
37 */
38 Mesh();
39
40 /**
41 * Copy constructor
42 */
43 Mesh(const Mesh& other);
44
45 /**
46 * Destructor.
47 */
48 ~Mesh();
49
50 /**
51 * Reserve the expected space for the mesh. This causes all member array
52 * storage to call the reserve function with the number specified.
53 * @param size Expected size of the mesh.
54 * @param colors Should the colors array reserve this space too? Defaults
55 * to false.
56 * @return True on success.
57 */
58 bool reserve(unsigned int size, bool colors = false);
59
60 /**
61 * This function allows long running calculations to mark the mesh as in
62 * progress.
63 * @param stable Indicate that the Mesh is currently being modified.
64 */
65 void setStable(bool stable);
66
67 /**
68 * Indicate whether the Mesh is complete or currently being modified. In
69 * general using Mesh values from an unstable Mesh is not advisable.
70 * @return True if the Mesh is complete, false if it is being modified.
71 */
72 bool stable();
73
74 /**
75 * Set the iso value that was used to generate the Mesh.
76 */
77 void setIsoValue(float value) { m_isoValue = value; }
78
79 /**
80 * @return The iso value used to generate the Mesh.
81 */
82 float isoValue() const { return m_isoValue; }
83
84 /**
85 * Set the unique id of the other Mesh if this Mesh is part of a pair.
86 */
87 void setOtherMesh(unsigned int other) { m_other = other; }
88
89 /**
90 * @return The unique id of the other Mesh if this is part of a pair.
91 */
92 unsigned int otherMesh() const { return m_other; }
93
94 /**
95 * Set the unique id of the Cube the Mesh was generated from.
96 */
97 void setCube(unsigned int cube_) { m_cube = cube_; }
98
99 /**
100 * @return The unique id of the Cube the Mesh was generated from.
101 */
102 unsigned int cube() const { return m_cube; }
103
104 /**
105 * @return Array containing all of the vertices in a one dimensional array.
106 */
107 const Core::Array<Vector3f>& vertices() const;
108
109 /**
110 * @return The number of vertices.
111 */
112 unsigned int numVertices() const
113 {
114 return static_cast<unsigned int>(m_vertices.size());
115 }
116
117 /**
118 * @return Pointer to the first vertex of the specified triangle.
119 */
120 const Vector3f* vertex(int n) const;
121
122 bool setTriangles(const Core::Array<Vector3f>& values);
123 const Core::Array<Vector3f>& triangles() const;
124
125 /**
126 * Clear the vertices vector and assign new values.
127 */
128 bool setVertices(const Core::Array<Vector3f>& values);
129
130 /**
131 * Add one or more vertices, i.e., the array is expected to be of length
132 * 3 x n where n is an integer.
133 */
134 bool addVertices(const Core::Array<Vector3f>& values);
135
136 /**
137 * @return Array containing all of the normals in a one-dimensional array.
138 */
139 const Core::Array<Vector3f>& normals() const;
140
141 /**
142 * @return The number of normals.
143 */
144 unsigned int numNormals() const
145 {
146 return static_cast<unsigned int>(m_normals.size());
147 }
148
149 /**
150 * @return Pointer to the first normal of the specified triangle.
151 */
152 const Vector3f* normal(int n) const;
153
154 /**
155 * Clear the normals array and assign new values.
156 */
157 bool setNormals(const Core::Array<Vector3f>& values);
158
159 /**
160 * Add one or more normals, i.e., the array is expected to be of length
161 * 3 x n where n is an integer.
162 */
163 bool addNormals(const Core::Array<Vector3f>& values);
164
165 /**
166 * @return Array containing all of the colors in a one-dimensional array.
167 */
168 const Core::Array<Color3f>& colors() const;
169
170 /**
171 * @return Pointer to the first color of the specified triangle.
172 */
173 const Color3f* color(int n) const;
174
175 /**
176 * Clear the colors array and assign new values.
177 */
178 bool setColors(const Core::Array<Color3f>& values);
179
180 /**
181 * Add one or more normals, i.e., the array is expected to be of length
182 * 3 x n where n is an integer.
183 */
184 bool addColors(const Core::Array<Color3f>& values);
185
186 /**
187 * Sanity checking function - is the mesh sane?
188 * @return True if the Mesh object is sane and composed of the right number
189 * of elements.
190 */
191 bool valid() const;
192
193 /**
194 * Clear all mesh data.
195 * @return True on success.
196 */
197 bool clear();
198
199 /**
200 * Overloaded operator.
201 */
202 Mesh& operator=(const Mesh& other);
203
204 /**
205 * Set the name of the Mesh.
206 */
207 void setName(const std::string& name_) { m_name = name_; }
208
209 /**
210 * @return The name of the Mesh.
211 */
212 std::string name() const { return m_name; }
213
214 /**
215 * Provides locking.
216 */
217 Mutex* lock() const { return m_lock; }
218
219 /**
220 * Applies Laplacian smoothing.
221 * @param iterationCount number of smoothing passes to make.
222 */
223 void smooth(int iterationCount = 6);
224
225 friend class Molecule;
226
227 private:
228 Core::Array<Vector3f> m_vertices;
229 Core::Array<Vector3f> m_normals;
230 Core::Array<Color3f> m_colors;
231 Core::Array<Vector3f> m_triangles;
232 std::string m_name;
233 bool m_stable;
234 float m_isoValue;
235 unsigned int m_other; // Unique id of the other mesh if this is part of a pair
236 unsigned int m_cube; // Unique id of the cube this mesh was generated from
237 Mutex* m_lock;
238 };
239
240 } // End namespace Avogadro::Core
241
242 #endif // AVOGADRO_CORE_MESH_H