Skip to content

Commit 1a2a951

Browse files
Use clang-tidy and address all the issues that it raised
1 parent 137945c commit 1a2a951

32 files changed

+332
-325
lines changed

cmake/Scripts/wrap_opencl.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333

3434
# Work out what our define will be
3535
define = os.path.basename(input_path)[:-3].replace(os.sep, "_").upper()
36-
output = [l.rstrip("\n").replace("\\", "\\\\").replace('"', '\\"') for l in input_file]
37-
output.append("")
3836

39-
output = '#define {}_CL "{}"'.format(define, "\\n\\\n".join(output))
40-
output_file.write(output)
37+
output_file.write('constexpr const char* {}_CL = R"({})";'.format(define, input_file.read()))
4138
output_file.write("\n")

cpp/visualmesh/engine/cpu/bayer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace engine {
104104
int y_s = px[1] - 2;
105105

106106
// Read the image patch into a flat array
107-
std::array<int32_t, 5 * 5> patch;
107+
std::array<int32_t, 5 * 5> patch{};
108108
for (int y = 0; y < 5; ++y) {
109109
int y_c = std::min(std::max(y_s + y, 0), dimensions[1] - 1);
110110
for (int x = 0; x < 5; ++x) {

cpp/visualmesh/engine/cpu/engine.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ namespace engine {
196196
input.reserve(n_points * 4);
197197

198198
for (const auto& px : projected.pixel_coordinates) {
199-
const uint8_t* const im = reinterpret_cast<const uint8_t*>(image);
199+
const auto* const im = reinterpret_cast<const uint8_t*>(image);
200200

201201
const vec4<Scalar> p = interpolate(px, im, lens.dimensions, format);
202202
input.insert(input.end(), p.begin(), p.end());
@@ -264,10 +264,12 @@ namespace engine {
264264
}
265265
}
266266

267+
// Move all the things we made into the classified mesh except the input
268+
// We copy the input instead of moving it as we reuse the input buffer
267269
return ClassifiedMesh<Scalar, N_NEIGHBOURS>{std::move(projected.pixel_coordinates),
268270
std::move(projected.neighbourhood),
269271
std::move(projected.global_indices),
270-
std::move(input)};
272+
input};
271273
}
272274

273275
/**

cpp/visualmesh/engine/opencl/engine.hpp

Lines changed: 90 additions & 86 deletions
Large diffs are not rendered by default.

cpp/visualmesh/engine/opencl/operation/make_context.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ namespace engine {
6969
}
7070

7171
// Print information about our selected device
72-
if (!best_device) {
72+
if (best_device == nullptr) {
7373
throw std::system_error(
7474
CL_INVALID_DEVICE, opencl_error_category(), "Error selecting an OpenCL device");
7575
}
7676

7777
// Make context
78-
cl_int error;
78+
cl_int error = 0;
7979
cl::context context = cl::context(::clCreateContext(nullptr, 1, &best_device, nullptr, nullptr, &error),
8080
::clReleaseContext);
81-
if (error) {
81+
if (error != 0) {
8282
throw std::system_error(error, opencl_error_category(), "Error creating the OpenCL context");
8383
}
8484
return std::make_pair(context, best_device);

cpp/visualmesh/engine/opencl/operation/make_queue.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace engine {
3434
* @return a reference counted tracker of a command queue
3535
*/
3636
inline cl::command_queue make_queue(cl_context context, cl_device_id device) {
37-
cl_command_queue queue;
38-
cl_int error;
37+
cl_command_queue queue = nullptr;
38+
cl_int error = 0;
3939
// Use out of order execution if we can
4040
queue = ::clCreateCommandQueue(context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &error);
4141
if (error == CL_INVALID_VALUE) { queue = ::clCreateCommandQueue(context, device, 0, &error); }

cpp/visualmesh/engine/opencl/operation/opencl_error_category.hpp

Lines changed: 65 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -110,91 +110,83 @@ namespace engine {
110110

111111
class opencl_error_category_t : public std::error_category {
112112
public:
113-
inline virtual const char* name() const noexcept {
113+
inline const char* name() const noexcept override {
114114
return "opencl_error_category";
115115
}
116116

117-
inline virtual std::error_condition default_error_condition(int code) const noexcept {
117+
inline std::error_condition default_error_condition(int code) const noexcept override {
118118
using cle = opencl_error_code;
119119
switch (code) {
120-
case CL_SUCCESS: return std::error_condition(cle::SUCCESS);
121-
case CL_DEVICE_NOT_FOUND: return std::error_condition(cle::DEVICE_NOT_FOUND);
122-
case CL_DEVICE_NOT_AVAILABLE: return std::error_condition(cle::DEVICE_NOT_AVAILABLE);
123-
case CL_COMPILER_NOT_AVAILABLE: return std::error_condition(cle::COMPILER_NOT_AVAILABLE);
124-
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
125-
return std::error_condition(cle::MEM_OBJECT_ALLOCATION_FAILURE);
126-
case CL_OUT_OF_RESOURCES: return std::error_condition(cle::OUT_OF_RESOURCES);
127-
case CL_OUT_OF_HOST_MEMORY: return std::error_condition(cle::OUT_OF_HOST_MEMORY);
128-
case CL_PROFILING_INFO_NOT_AVAILABLE:
129-
return std::error_condition(cle::PROFILING_INFO_NOT_AVAILABLE);
130-
case CL_MEM_COPY_OVERLAP: return std::error_condition(cle::MEM_COPY_OVERLAP);
131-
case CL_IMAGE_FORMAT_MISMATCH: return std::error_condition(cle::IMAGE_FORMAT_MISMATCH);
132-
case CL_IMAGE_FORMAT_NOT_SUPPORTED:
133-
return std::error_condition(cle::IMAGE_FORMAT_NOT_SUPPORTED);
134-
case CL_BUILD_PROGRAM_FAILURE: return std::error_condition(cle::BUILD_PROGRAM_FAILURE);
135-
case CL_MAP_FAILURE: return std::error_condition(cle::MAP_FAILURE);
136-
case CL_MISALIGNED_SUB_BUFFER_OFFSET:
137-
return std::error_condition(cle::MISALIGNED_SUB_BUFFER_OFFSET);
120+
case CL_SUCCESS: return {cle::SUCCESS};
121+
case CL_DEVICE_NOT_FOUND: return {cle::DEVICE_NOT_FOUND};
122+
case CL_DEVICE_NOT_AVAILABLE: return {cle::DEVICE_NOT_AVAILABLE};
123+
case CL_COMPILER_NOT_AVAILABLE: return {cle::COMPILER_NOT_AVAILABLE};
124+
case CL_MEM_OBJECT_ALLOCATION_FAILURE: return {cle::MEM_OBJECT_ALLOCATION_FAILURE};
125+
case CL_OUT_OF_RESOURCES: return {cle::OUT_OF_RESOURCES};
126+
case CL_OUT_OF_HOST_MEMORY: return {cle::OUT_OF_HOST_MEMORY};
127+
case CL_PROFILING_INFO_NOT_AVAILABLE: return {cle::PROFILING_INFO_NOT_AVAILABLE};
128+
case CL_MEM_COPY_OVERLAP: return {cle::MEM_COPY_OVERLAP};
129+
case CL_IMAGE_FORMAT_MISMATCH: return {cle::IMAGE_FORMAT_MISMATCH};
130+
case CL_IMAGE_FORMAT_NOT_SUPPORTED: return {cle::IMAGE_FORMAT_NOT_SUPPORTED};
131+
case CL_BUILD_PROGRAM_FAILURE: return {cle::BUILD_PROGRAM_FAILURE};
132+
case CL_MAP_FAILURE: return {cle::MAP_FAILURE};
133+
case CL_MISALIGNED_SUB_BUFFER_OFFSET: return {cle::MISALIGNED_SUB_BUFFER_OFFSET};
138134
case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:
139-
return std::error_condition(cle::EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
140-
case CL_COMPILE_PROGRAM_FAILURE: return std::error_condition(cle::COMPILE_PROGRAM_FAILURE);
141-
case CL_LINKER_NOT_AVAILABLE: return std::error_condition(cle::LINKER_NOT_AVAILABLE);
142-
case CL_LINK_PROGRAM_FAILURE: return std::error_condition(cle::LINK_PROGRAM_FAILURE);
143-
case CL_DEVICE_PARTITION_FAILED: return std::error_condition(cle::DEVICE_PARTITION_FAILED);
144-
case CL_KERNEL_ARG_INFO_NOT_AVAILABLE:
145-
return std::error_condition(cle::KERNEL_ARG_INFO_NOT_AVAILABLE);
146-
case CL_INVALID_VALUE: return std::error_condition(cle::INVALID_VALUE);
147-
case CL_INVALID_DEVICE_TYPE: return std::error_condition(cle::INVALID_DEVICE_TYPE);
148-
case CL_INVALID_PLATFORM: return std::error_condition(cle::INVALID_PLATFORM);
149-
case CL_INVALID_DEVICE: return std::error_condition(cle::INVALID_DEVICE);
150-
case CL_INVALID_CONTEXT: return std::error_condition(cle::INVALID_CONTEXT);
151-
case CL_INVALID_QUEUE_PROPERTIES: return std::error_condition(cle::INVALID_QUEUE_PROPERTIES);
152-
case CL_INVALID_COMMAND_QUEUE: return std::error_condition(cle::INVALID_COMMAND_QUEUE);
153-
case CL_INVALID_HOST_PTR: return std::error_condition(cle::INVALID_HOST_PTR);
154-
case CL_INVALID_MEM_OBJECT: return std::error_condition(cle::INVALID_MEM_OBJECT);
155-
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
156-
return std::error_condition(cle::INVALID_IMAGE_FORMAT_DESCRIPTOR);
157-
case CL_INVALID_IMAGE_SIZE: return std::error_condition(cle::INVALID_IMAGE_SIZE);
158-
case CL_INVALID_SAMPLER: return std::error_condition(cle::INVALID_SAMPLER);
159-
case CL_INVALID_BINARY: return std::error_condition(cle::INVALID_BINARY);
160-
case CL_INVALID_BUILD_OPTIONS: return std::error_condition(cle::INVALID_BUILD_OPTIONS);
161-
case CL_INVALID_PROGRAM: return std::error_condition(cle::INVALID_PROGRAM);
162-
case CL_INVALID_PROGRAM_EXECUTABLE:
163-
return std::error_condition(cle::INVALID_PROGRAM_EXECUTABLE);
164-
case CL_INVALID_KERNEL_NAME: return std::error_condition(cle::INVALID_KERNEL_NAME);
165-
case CL_INVALID_KERNEL_DEFINITION: return std::error_condition(cle::INVALID_KERNEL_DEFINITION);
166-
case CL_INVALID_KERNEL: return std::error_condition(cle::INVALID_KERNEL);
167-
case CL_INVALID_ARG_INDEX: return std::error_condition(cle::INVALID_ARG_INDEX);
168-
case CL_INVALID_ARG_VALUE: return std::error_condition(cle::INVALID_ARG_VALUE);
169-
case CL_INVALID_ARG_SIZE: return std::error_condition(cle::INVALID_ARG_SIZE);
170-
case CL_INVALID_KERNEL_ARGS: return std::error_condition(cle::INVALID_KERNEL_ARGS);
171-
case CL_INVALID_WORK_DIMENSION: return std::error_condition(cle::INVALID_WORK_DIMENSION);
172-
case CL_INVALID_WORK_GROUP_SIZE: return std::error_condition(cle::INVALID_WORK_GROUP_SIZE);
173-
case CL_INVALID_WORK_ITEM_SIZE: return std::error_condition(cle::INVALID_WORK_ITEM_SIZE);
174-
case CL_INVALID_GLOBAL_OFFSET: return std::error_condition(cle::INVALID_GLOBAL_OFFSET);
175-
case CL_INVALID_EVENT_WAIT_LIST: return std::error_condition(cle::INVALID_EVENT_WAIT_LIST);
176-
case CL_INVALID_EVENT: return std::error_condition(cle::INVALID_EVENT);
177-
case CL_INVALID_OPERATION: return std::error_condition(cle::INVALID_OPERATION);
178-
case CL_INVALID_GL_OBJECT: return std::error_condition(cle::INVALID_GL_OBJECT);
179-
case CL_INVALID_BUFFER_SIZE: return std::error_condition(cle::INVALID_BUFFER_SIZE);
180-
case CL_INVALID_MIP_LEVEL: return std::error_condition(cle::INVALID_MIP_LEVEL);
181-
case CL_INVALID_GLOBAL_WORK_SIZE: return std::error_condition(cle::INVALID_GLOBAL_WORK_SIZE);
182-
case CL_INVALID_PROPERTY: return std::error_condition(cle::INVALID_PROPERTY);
183-
case CL_INVALID_IMAGE_DESCRIPTOR: return std::error_condition(cle::INVALID_IMAGE_DESCRIPTOR);
184-
case CL_INVALID_COMPILER_OPTIONS: return std::error_condition(cle::INVALID_COMPILER_OPTIONS);
185-
case CL_INVALID_LINKER_OPTIONS: return std::error_condition(cle::INVALID_LINKER_OPTIONS);
186-
case CL_INVALID_DEVICE_PARTITION_COUNT:
187-
return std::error_condition(cle::INVALID_DEVICE_PARTITION_COUNT);
188-
default: return std::error_condition(cle::UNKNOWN);
135+
return {cle::EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST};
136+
case CL_COMPILE_PROGRAM_FAILURE: return {cle::COMPILE_PROGRAM_FAILURE};
137+
case CL_LINKER_NOT_AVAILABLE: return {cle::LINKER_NOT_AVAILABLE};
138+
case CL_LINK_PROGRAM_FAILURE: return {cle::LINK_PROGRAM_FAILURE};
139+
case CL_DEVICE_PARTITION_FAILED: return {cle::DEVICE_PARTITION_FAILED};
140+
case CL_KERNEL_ARG_INFO_NOT_AVAILABLE: return {cle::KERNEL_ARG_INFO_NOT_AVAILABLE};
141+
case CL_INVALID_VALUE: return {cle::INVALID_VALUE};
142+
case CL_INVALID_DEVICE_TYPE: return {cle::INVALID_DEVICE_TYPE};
143+
case CL_INVALID_PLATFORM: return {cle::INVALID_PLATFORM};
144+
case CL_INVALID_DEVICE: return {cle::INVALID_DEVICE};
145+
case CL_INVALID_CONTEXT: return {cle::INVALID_CONTEXT};
146+
case CL_INVALID_QUEUE_PROPERTIES: return {cle::INVALID_QUEUE_PROPERTIES};
147+
case CL_INVALID_COMMAND_QUEUE: return {cle::INVALID_COMMAND_QUEUE};
148+
case CL_INVALID_HOST_PTR: return {cle::INVALID_HOST_PTR};
149+
case CL_INVALID_MEM_OBJECT: return {cle::INVALID_MEM_OBJECT};
150+
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return {cle::INVALID_IMAGE_FORMAT_DESCRIPTOR};
151+
case CL_INVALID_IMAGE_SIZE: return {cle::INVALID_IMAGE_SIZE};
152+
case CL_INVALID_SAMPLER: return {cle::INVALID_SAMPLER};
153+
case CL_INVALID_BINARY: return {cle::INVALID_BINARY};
154+
case CL_INVALID_BUILD_OPTIONS: return {cle::INVALID_BUILD_OPTIONS};
155+
case CL_INVALID_PROGRAM: return {cle::INVALID_PROGRAM};
156+
case CL_INVALID_PROGRAM_EXECUTABLE: return {cle::INVALID_PROGRAM_EXECUTABLE};
157+
case CL_INVALID_KERNEL_NAME: return {cle::INVALID_KERNEL_NAME};
158+
case CL_INVALID_KERNEL_DEFINITION: return {cle::INVALID_KERNEL_DEFINITION};
159+
case CL_INVALID_KERNEL: return {cle::INVALID_KERNEL};
160+
case CL_INVALID_ARG_INDEX: return {cle::INVALID_ARG_INDEX};
161+
case CL_INVALID_ARG_VALUE: return {cle::INVALID_ARG_VALUE};
162+
case CL_INVALID_ARG_SIZE: return {cle::INVALID_ARG_SIZE};
163+
case CL_INVALID_KERNEL_ARGS: return {cle::INVALID_KERNEL_ARGS};
164+
case CL_INVALID_WORK_DIMENSION: return {cle::INVALID_WORK_DIMENSION};
165+
case CL_INVALID_WORK_GROUP_SIZE: return {cle::INVALID_WORK_GROUP_SIZE};
166+
case CL_INVALID_WORK_ITEM_SIZE: return {cle::INVALID_WORK_ITEM_SIZE};
167+
case CL_INVALID_GLOBAL_OFFSET: return {cle::INVALID_GLOBAL_OFFSET};
168+
case CL_INVALID_EVENT_WAIT_LIST: return {cle::INVALID_EVENT_WAIT_LIST};
169+
case CL_INVALID_EVENT: return {cle::INVALID_EVENT};
170+
case CL_INVALID_OPERATION: return {cle::INVALID_OPERATION};
171+
case CL_INVALID_GL_OBJECT: return {cle::INVALID_GL_OBJECT};
172+
case CL_INVALID_BUFFER_SIZE: return {cle::INVALID_BUFFER_SIZE};
173+
case CL_INVALID_MIP_LEVEL: return {cle::INVALID_MIP_LEVEL};
174+
case CL_INVALID_GLOBAL_WORK_SIZE: return {cle::INVALID_GLOBAL_WORK_SIZE};
175+
case CL_INVALID_PROPERTY: return {cle::INVALID_PROPERTY};
176+
case CL_INVALID_IMAGE_DESCRIPTOR: return {cle::INVALID_IMAGE_DESCRIPTOR};
177+
case CL_INVALID_COMPILER_OPTIONS: return {cle::INVALID_COMPILER_OPTIONS};
178+
case CL_INVALID_LINKER_OPTIONS: return {cle::INVALID_LINKER_OPTIONS};
179+
case CL_INVALID_DEVICE_PARTITION_COUNT: return {cle::INVALID_DEVICE_PARTITION_COUNT};
180+
default: return {cle::UNKNOWN};
189181
}
190182
}
191183

192-
inline virtual bool equivalent(const std::error_code& code, int condition) const noexcept {
184+
inline bool equivalent(const std::error_code& code, int condition) const noexcept override {
193185
return *this == code.category()
194186
&& static_cast<int>(default_error_condition(code.value()).value()) == condition;
195187
}
196188

197-
inline virtual std::string message(int code) const noexcept {
189+
inline std::string message(int code) const noexcept override {
198190
switch (code) {
199191
case CL_SUCCESS: return "Success";
200192
case CL_DEVICE_NOT_FOUND: return "Device not found";
@@ -267,7 +259,7 @@ namespace engine {
267259
}
268260

269261
inline std::error_condition make_error_condition(opencl_error_code e) {
270-
return std::error_condition(static_cast<int>(e), opencl_error_category());
262+
return {static_cast<int>(e), opencl_error_category()};
271263
}
272264

273265
} // namespace operation

cpp/visualmesh/engine/opencl/operation/scalar_defines.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace engine {
3030
*
3131
* @return a string containing the defines that are needed if the Scalar type is float
3232
*/
33-
inline constexpr auto get_scalar_defines(float) {
33+
inline constexpr auto get_scalar_defines(float /*scalar_type*/) {
3434
return "#define Scalar float\n"
3535
"#define Scalar2 float2\n"
3636
"#define Scalar3 float3\n"
@@ -44,7 +44,7 @@ namespace engine {
4444
*
4545
* @return a string containing the defines that are needed if the Scalar type is double
4646
*/
47-
inline constexpr auto get_scalar_defines(double) {
47+
inline constexpr auto get_scalar_defines(double /*scalar_type*/) {
4848
return "#define Scalar double\n"
4949
"#define Scalar2 double2\n"
5050
"#define Scalar3 double3\n"

cpp/visualmesh/engine/opencl/operation/wrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace engine {
4141
* @param code the error code to check and throw
4242
* @param msg the message to attach to the exception if it is thrown
4343
*/
44-
void throw_cl_error(const cl_int& code, const std::string& msg) {
44+
inline void throw_cl_error(const cl_int& code, const std::string& msg) {
4545
if (code != CL_SUCCESS) { throw std::system_error(code, operation::opencl_error_category(), msg); }
4646
}
4747

cpp/visualmesh/geometry/Circle.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,8 @@ namespace geometry {
133133
Scalar theta(const Scalar& n, const Scalar& h) const {
134134

135135
// If n is < 0.5 then theta doesn't make sense, we interpolate from 2π to π to get a sensible approximation
136-
if (n <= 0.5) { //
137-
return Scalar(2.0 * M_PI) / (1.0 + n * Scalar(2.0));
138-
}
139-
else {
140-
return Scalar(2.0) * std::asin(r / ((h - r) * std::tan(phi(n, h))));
141-
}
136+
return n <= 0.5 ? Scalar(2.0 * M_PI) / (1.0 + n * Scalar(2.0))
137+
: Scalar(2.0) * std::asin(r / ((h - r) * std::tan(phi(n, h))));
142138
}
143139

144140
// The radius of the circle

0 commit comments

Comments
 (0)