Visual Computing Library  devel
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
28#include <vclib/space/core.h>
29
41namespace vcl {
42
56template<typename ScalarType = float, std::integral UintType = uint16_t>
57std::pair<std::vector<vcl::Point3<ScalarType>>, std::vector<UintType>>
58createTrackBall(ScalarType scale = 1.0, uint pointsPerCircle = 64)
59{
60 using PointType = vcl::Point3<ScalarType>;
61
62 std::vector<PointType> vertices;
63 std::vector<UintType> edges;
64
67
68 vertices.reserve(pointsPerCircle * 3);
69
70 // x
71 uint first = 0;
72 for (uint i = 0; i < circle.size(); ++i) {
73 const auto& p = circle.point(i);
74 vertices.push_back(PointType(0, p.x(), p.y()));
75 edges.push_back(i + first);
76 edges.push_back((i + 1) % circle.size() + first);
77 }
78
79 // y
80 first = circle.size();
81 for (uint i = 0; i < circle.size(); ++i) {
82 const auto& p = circle.point(i);
83 vertices.push_back(PointType(p.x(), 0, p.y()));
84 edges.push_back(i + first);
85 edges.push_back((i + 1) % circle.size() + first);
86 }
87
88 // z
89 first = 2 * circle.size();
90 for (uint i = 0; i < circle.size(); ++i) {
91 const auto& p = circle.point(i);
92 vertices.push_back(PointType(p.x(), p.y(), 0));
93 edges.push_back(i + first);
94 edges.push_back((i + 1) % circle.size() + first);
95 }
96
97 return std::make_pair(std::move(vertices), std::move(edges));
98}
99
110{
112
113 for (int y = 0; y < imageSize; ++y) {
114 for (int x = 0; x < imageSize; ++x) {
115 if (((x / checkNum) % 2) == ((y / checkNum) % 2)) {
116 img(x, y) = 0xFFFFFFFF;
117 }
118 else {
119 img(x, y) = 0xFF808080;
120 }
121 }
122 }
123
124 return Image(std::move(img));
125}
126
127} // namespace vcl
128
129#endif // VCL_ALGORITHMS_CORE_CREATE_H
A class representing a box in N-dimensional space.
Definition box.h:46
PointT size() const
Computes the size of the box.
Definition box.h:267
The Image class stores an Image in 4 bytes RGBA format.
Definition image.h:44
Image createCheckBoardImage(uint imageSize, uint checkNum=8)
Create a checkboard image.
Definition create.h:109
std::pair< std::vector< vcl::Point3< ScalarType > >, std::vector< UintType > > createTrackBall(ScalarType scale=1.0, uint pointsPerCircle=64)
Returns a pair of vectors containing the vertices and edges of a 3D Trackball, composed of three circ...
Definition create.h:58