Visual Computing Library
Loading...
Searching...
No Matches
create.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_ALGORITHMS_CORE_CREATE_H
24#define VCL_ALGORITHMS_CORE_CREATE_H
25
26#include "polygon/create.h"
27
28namespace vcl {
29
41template<typename ScalarType = float, std::integral UintType = uint16_t>
42std::pair<std::vector<vcl::Point3<ScalarType>>, std::vector<UintType>>
43createTrackBall(ScalarType scale = 1.0, uint pointsPerCircle = 64)
44{
45 using PointType = vcl::Point3<ScalarType>;
46
47 std::vector<PointType> vertices;
48 std::vector<UintType> edges;
49
52
53 vertices.reserve(pointsPerCircle * 3);
54
55 // x
56 uint first = 0;
57 for (uint i = 0; i < circle.size(); ++i) {
58 const auto& p = circle.point(i);
59 vertices.push_back(PointType(0, p.x(), p.y()));
60 edges.push_back(i + first);
61 edges.push_back((i + 1) % circle.size() + first);
62 }
63
64 // y
65 first = circle.size();
66 for (uint i = 0; i < circle.size(); ++i) {
67 const auto& p = circle.point(i);
68 vertices.push_back(PointType(p.x(), 0, p.y()));
69 edges.push_back(i + first);
70 edges.push_back((i + 1) % circle.size() + first);
71 }
72
73 // z
74 first = 2 * circle.size();
75 for (uint i = 0; i < circle.size(); ++i) {
76 const auto& p = circle.point(i);
77 vertices.push_back(PointType(p.x(), p.y(), 0));
78 edges.push_back(i + first);
79 edges.push_back((i + 1) % circle.size() + first);
80 }
81
82 return std::make_pair(std::move(vertices), std::move(edges));
83}
84
85} // namespace vcl
86
87#endif // VCL_ALGORITHMS_CORE_CREATE_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
constexpr detail::EdgesView edges
A view that allows to iterate overt the Edge elements of an object.
Definition edge.h:52
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:60