107 unsigned int double_step = 2 * aNumberOfSteps;
108 T single_step_length = aTotalLength / aNumberOfSteps;
109 T half_length = aTotalLength * 0.5;
110 unsigned int number_of_vertices = aNumberOfSteps * (aNumberOfSteps + 5) + 2;
111 unsigned int number_of_triangles = 2 * aNumberOfSteps * (aNumberOfSteps + 5);
114 std::vector<T> p_vertex_set;
115 p_vertex_set.reserve(3 * number_of_vertices);
119 if (anIndexDataType == GL_UNSIGNED_BYTE && number_of_vertices > 255)
121 LOGGER.
logWarning(
"The data type of the index set is UCHAR. The number of vertices (") <<
122 number_of_vertices <<
") is bigger than 255. We'll try using USHORT." << std::endl;
124 anIndexDataType = GL_UNSIGNED_SHORT;
129 if (anIndexDataType == GL_UNSIGNED_SHORT && number_of_vertices > 65536)
131 LOGGER.
logWarning(
"The data type of the index set is USHORT. The number of vertices (") <<
132 number_of_vertices <<
") is bigger than 255. We'll try using UINT." << std::endl;
134 anIndexDataType = GL_UNSIGNED_INT;
137 std::vector<unsigned int> p_uint_index_set;
138 p_uint_index_set.reserve(3 * number_of_triangles);
141 for (
int f = 0; f < aNumberOfSteps + 1; ++f) {
142 T floorX = f * single_step_length - half_length;
143 T floorY = aWidth * 0.5;
146 p_vertex_set.insert(p_vertex_set.end(), {floorX, +floorY, floorZ,
147 floorX, -floorY, floorZ});
152 for (
int i = 0; i < aNumberOfSteps; ++i) {
154 unsigned int stepLayer = aNumberOfSteps - i;
156 for (
int j = 0; j < stepLayer + 1; ++j) {
157 T stepX = j * single_step_length - half_length;
158 T stepY = aWidth * 0.5;
159 T stepZ = (i * anOtherStepHeight) + aFirstStepHeight;
161 p_vertex_set.insert(p_vertex_set.end(), {stepX, +stepY, stepZ,
162 stepX, -stepY, stepZ});
166 int iDoubled = i * 2;
167 int iSquared = i * i;
168 unsigned int iSwitch = (i > 0) ? 1 : 0;
176 unsigned int bottom1 = 1 + iDoubled;
177 unsigned int bottom2 = 0 + iDoubled;
178 unsigned int bottom3 = 2 + iDoubled;
179 unsigned int bottom4 = 3 + iDoubled;
182 unsigned int back1 = (double_step + 3) * (i + 1) - iSquared;
183 unsigned int back2 = back1 - 1;
184 unsigned int back3 = ((double_step + 5) * i - iSquared - 2) * iSwitch;
185 unsigned int back4 = back3 + 1;
188 unsigned int frontTop1 = (double_step + 1) * (i + 2) - iSquared;
189 unsigned int frontTop2 = frontTop1 - 2;
190 unsigned int frontTop3 = frontTop1 - 1;
191 unsigned int frontTop4 = frontTop1 + 1;
194 unsigned int forward1 = back2 - 2 * (iSwitch + 1);
195 unsigned int forward2 = frontTop1;
196 unsigned int forward3 = frontTop4;
197 unsigned int forward4 = forward1 + 1;
199 p_uint_index_set.insert(p_uint_index_set.end(), {bottom1, bottom2, bottom3,
200 bottom3, bottom4, bottom1,
205 frontTop1, frontTop2, frontTop3,
206 frontTop3, frontTop4, frontTop1,
208 forward1, forward2, forward3,
209 forward3, forward4, forward1});
210 int size = p_uint_index_set.size();
213 for (
int k = 0; k < stepLayer; ++k) {
214 int kSwitch = (k > 0) ? 1 : -1;
215 int kSquared = k * k;
217 unsigned int shiftValue = (double_step + 5) * k - kSquared - 1;
218 unsigned int lowerShift = iDoubled + (shiftValue * kSwitch);
219 unsigned int upperShift = iDoubled + shiftValue + double_step - 2 * (k - 2);
222 unsigned int negativeYSide4 = lowerShift;
223 unsigned int negativeYSide3 = upperShift;
224 unsigned int negativeYSide2 = negativeYSide3 + 2;
225 unsigned int negativeYSide1 = negativeYSide4 + 2;
228 unsigned int positiveYSide4 = negativeYSide1 - 1;
229 unsigned int positiveYSide3 = negativeYSide2 - 1;
230 unsigned int positiveYSide2 = negativeYSide3 - 1;
231 unsigned int positiveYSide1 = negativeYSide4 - 1;
233 p_uint_index_set.insert(p_uint_index_set.end(), {negativeYSide1, negativeYSide2, negativeYSide3,
234 negativeYSide3, negativeYSide4, negativeYSide1,
236 positiveYSide1, positiveYSide2, positiveYSide3,
237 positiveYSide3, positiveYSide4, positiveYSide1});
246 switch (anIndexDataType)
248 case GL_UNSIGNED_INT:
250 setInternalData(GL_TRIANGLES,
258 case GL_UNSIGNED_SHORT:
260 std::vector<GLushort> p_ushort_index_set;
262 for (std::vector<GLuint>::const_iterator ite(p_uint_index_set.begin());
263 ite != p_uint_index_set.end();
266 p_ushort_index_set.push_back(*ite);
269 setInternalData(GL_TRIANGLES,
277 case GL_UNSIGNED_BYTE:
279 std::vector<GLubyte> p_ubyte_index_set;
281 for (std::vector<GLuint>::const_iterator ite(p_uint_index_set.begin());
282 ite != p_uint_index_set.end();
285 p_ubyte_index_set.push_back(*ite);
288 setInternalData(GL_TRIANGLES,
297 throw Exception(__FILE__, __FUNCTION__, __LINE__,
298 "Invalid data type.");
304 std::vector<T> p_vertex_set2;
307 for (std::vector<unsigned int>::const_iterator ite = p_uint_index_set.begin();
308 ite != p_uint_index_set.end();
311 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 0]);
312 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 1]);
313 p_vertex_set2.push_back(p_vertex_set[*ite * 3 + 2]);
316 setInternalData(GL_TRIANGLES,
void create(unsigned int aNumberOfSteps=2, T aTotalLength=10.0 *cm, T aWidth=1.0 *cm, T aFirstStepHeight=1.0 *cm, T anOtherStepHeight=0.1 *cm, int anIndexDataType=0)
Create a new step wedge.
Exception is a class to handle exceptions.
PolygonMesh is a class to handle polygon (triangles) meshes.
std::ostream & logWarning(const std::string &aMessage="")
StepWedgeMesh(unsigned int aNumberOfSteps=2, T aTotalLength=10.0 *cm, T aWidth=1.0 *cm, T aFirstStepHeight=1.0 *cm, T anOtherStepHeight=0.1 *cm, int anIndexDataType=0)
Default constructor.