PartSegCore-compiled-backend 0.15.13__tar.gz → 0.15.14__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/.pre-commit-config.yaml +3 -3
  2. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/PKG-INFO +2 -1
  3. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/pyproject.toml +2 -0
  4. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/mso.h +136 -97
  5. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/debug_util.hpp +7 -7
  6. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/intersection.hpp +22 -22
  7. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/point.hpp +23 -23
  8. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulation/triangulate.hpp +82 -82
  9. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/version.py +16 -3
  10. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_triangulate.py +1 -2
  11. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/.gitignore +0 -0
  12. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/CMakeLists.txt +0 -0
  13. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/LICENSE.txt +0 -0
  14. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/MANIFEST.in +0 -0
  15. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/Readme.md +0 -0
  16. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/Makefile +0 -0
  17. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/calc_bounds.rst +0 -0
  18. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/conf.py +0 -0
  19. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/fast_unique.rst +0 -0
  20. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/index.rst +0 -0
  21. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/make.bat +0 -0
  22. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/napari_mapping.rst +0 -0
  23. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/docs/sprawl_utils.rst +0 -0
  24. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/__init__.py +0 -0
  25. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/_fast_unique.pyi +0 -0
  26. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/_fast_unique.pyx +0 -0
  27. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/_napari_mapping.pyx +0 -0
  28. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/calc_bounds.pyi +0 -0
  29. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/calc_bounds.pyx +0 -0
  30. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/color_image_cython.pyi +0 -0
  31. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/color_image_cython.pyx +0 -0
  32. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/fast_unique.py +0 -0
  33. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/__init__.py +0 -0
  34. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/mso_bind.pyi +0 -0
  35. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/mso_bind.pyx +0 -0
  36. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/multiscale_opening/my_queue.h +0 -0
  37. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/napari_mapping.py +0 -0
  38. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/__init__.py +0 -0
  39. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/distance_utils.pxd +0 -0
  40. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/euclidean_cython.pyi +0 -0
  41. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/euclidean_cython.pyx +0 -0
  42. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/find_split.py +0 -0
  43. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/find_split.pyi +0 -0
  44. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/fuzzy_distance.pyx +0 -0
  45. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/global_consts.h +0 -0
  46. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/my_queue.h +0 -0
  47. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/path_sprawl_cython.pyi +0 -0
  48. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/path_sprawl_cython.pyx +0 -0
  49. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/put_borders_in_queue.pyx +0 -0
  50. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/sprawl_utils.pyi +0 -0
  51. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/sprawl_utils/sprawl_utils.pyx +0 -0
  52. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/triangulate.pyx +0 -0
  53. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/PartSegCore_compiled_backend/utils.py +0 -0
  54. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_calc_bounds.py +0 -0
  55. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_coloring.py +0 -0
  56. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_fast_unique.py +0 -0
  57. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_napari_mapping.py +0 -0
  58. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_sprawl_utils/__init__.py +0 -0
  59. {partsegcore_compiled_backend-0.15.13 → partsegcore_compiled_backend-0.15.14}/src/tests/test_sprawl_utils/test_euclidean.py +0 -0
@@ -1,14 +1,14 @@
1
1
  repos:
2
2
  - repo: https://github.com/astral-sh/ruff-pre-commit
3
3
  # Ruff version.
4
- rev: v0.12.0
4
+ rev: v0.13.1
5
5
  hooks:
6
6
  # Run the linter.
7
7
  - id: ruff
8
8
  # Run the formatter.
9
9
  - id: ruff-format
10
10
  - repo: https://github.com/pre-commit/pre-commit-hooks
11
- rev: v5.0.0
11
+ rev: v6.0.0
12
12
  hooks:
13
13
  - id: check-json
14
14
  - id: check-yaml
@@ -33,7 +33,7 @@ repos:
33
33
  additional_dependencies:
34
34
  - tomli
35
35
  - repo: https://github.com/pre-commit/mirrors-clang-format
36
- rev: v20.1.6 # Use the sha / tag you want to point at
36
+ rev: v21.1.1 # Use the sha / tag you want to point at
37
37
  hooks:
38
38
  - id: clang-format
39
39
  args: ["-style=Google"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PartSegCore_compiled_backend
3
- Version: 0.15.13
3
+ Version: 0.15.14
4
4
  Summary: PartSegCore compiled backend,
5
5
  Keywords: bioimaging
6
6
  Author-Email: Grzegorz Bokota <g.bokota@cent.uw.edu.pl>
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
17
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
18
19
  Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
19
20
  Project-URL: Homepage, https://4dnucleome.cent.uw.edu.pl/PartSeg/
@@ -34,6 +34,7 @@ classifiers = [
34
34
  "Programming Language :: Python :: 3.10",
35
35
  "Programming Language :: Python :: 3.11",
36
36
  "Programming Language :: Python :: 3.12",
37
+ "Programming Language :: Python :: 3.13",
37
38
  "Programming Language :: Python :: Implementation :: CPython",
38
39
  "Topic :: Scientific/Engineering :: Bio-Informatics",
39
40
  ]
@@ -129,6 +130,7 @@ test-command = "pytest {project}/src/tests"
129
130
  test-extras = ["test"]
130
131
  skip = "pp*macos* pp31* pp39-manylinux*"
131
132
  build = "*64"
133
+ enable = ["pypy", "cpython-freethreading"]
132
134
 
133
135
  [tool.cibuildwheel.macos]
134
136
  before-all = [
@@ -1,3 +1,7 @@
1
+
2
+ #ifndef MSO_H
3
+ #define MSO_H
4
+
1
5
  #include <array>
2
6
  #include <cmath>
3
7
  #include <cstdint>
@@ -44,8 +48,9 @@ template <size_t K>
44
48
  std::ostream& operator<<(std::ostream& stream,
45
49
  const std::array<char, K>& array) {
46
50
  stream << "array(";
47
- for (size_t i = 0; i < K - 1; i++) stream << (int)array[i] << ", ";
48
- stream << (int)array[K - 1] << ")";
51
+ for (size_t i = 0; i < K - 1; i++)
52
+ stream << static_cast<int>(array[i]) << ", ";
53
+ stream << static_cast<int>(array[K - 1]) << ")";
49
54
  return stream;
50
55
  }
51
56
 
@@ -62,15 +67,26 @@ template <>
62
67
  std::ostream& operator<<(std::ostream& stream,
63
68
  const std::vector<unsigned char>& array) {
64
69
  stream << "vector(";
65
- for (size_t i = 0; i < array.size(); i++) stream << (int)array[i] << ", ";
66
- stream << (int)array.back() << ")";
70
+ if (!array.empty()) {
71
+ for (size_t i = 0; i < array.size() - 1; i++) {
72
+ stream << static_cast<int>(array[i]) << ", ";
73
+ }
74
+ stream << static_cast<int>(array.back());
75
+ }
76
+ stream << ")";
67
77
  return stream;
68
78
  }
79
+
69
80
  std::ostream& operator<<(std::ostream& stream,
70
81
  const std::vector<signed char>& array) {
71
82
  stream << "vector(";
72
- for (size_t i = 0; i < array.size(); i++) stream << (int)array[i] << ", ";
73
- stream << (int)array.back() << ")";
83
+ if (!array.empty()) {
84
+ for (size_t i = 0; i < array.size() - 1; i++) {
85
+ stream << static_cast<int>(array[i]) << ", ";
86
+ }
87
+ stream << static_cast<int>(array.back());
88
+ }
89
+ stream << ")";
74
90
  return stream;
75
91
  }
76
92
  #pragma GCC diagnostic pop
@@ -95,7 +111,7 @@ template <typename T, size_t K>
95
111
  std::array<size_t, K> calculate_dimension_size(const std::array<T, K>& size) {
96
112
  std::array<size_t, K> res;
97
113
  res[K - 1] = 1;
98
- for (size_t i = K - 1; i > 0; i--) {
114
+ for (size_t i = K - 1; i > 0; --i) {
99
115
  res[i - 1] = res[i] * size[i];
100
116
  }
101
117
  return res;
@@ -120,7 +136,9 @@ class ArrayLimits {
120
136
  };
121
137
  ArrayLimits(std::array<T, K> lower_bound_, std::array<T, K> upper_bound_)
122
138
  : lower_bound(lower_bound_), upper_bound(upper_bound_) {};
123
- ArrayLimits(std::array<T, K> upper_bound_) : upper_bound(upper_bound_) {
139
+
140
+ explicit ArrayLimits(std::array<T, K> upper_bound_)
141
+ : upper_bound(upper_bound_) {
124
142
  this->lower_bound.fill(0);
125
143
  };
126
144
  void set_bounds(std::array<T, K> lower_bound, std::array<T, K> upper_bound) {
@@ -161,10 +179,11 @@ class ArrayLimits {
161
179
  this->state = state;
162
180
  }
163
181
  std::array<T, K> operator++() {
164
- for (size_t i = K - 1; i >= 0; i--) {
165
- this->state[i]++;
166
- if (this->state[i] >= this->upper_bound[i])
167
- this->state[i] = this->lower_bound[i];
182
+ for (size_t i = K; i > 0; --i) {
183
+ const size_t idx = i - 1;
184
+ ++this->state[idx];
185
+ if (this->state[idx] >= this->upper_bound[idx])
186
+ this->state[idx] = this->lower_bound[idx];
168
187
  else
169
188
  break;
170
189
  }
@@ -172,23 +191,24 @@ class ArrayLimits {
172
191
  }
173
192
  std::array<T, K> operator++(int) {
174
193
  const auto res = this->state;
175
- ++this;
194
+ ++(*this);
176
195
  return res;
177
196
  }
178
197
  std::array<T, K> operator--() {
179
- for (size_t i = K - 1; i >= 0; i--) {
180
- if (this->state[i] > this->lower_bound[i]) {
181
- this->state[i]--;
198
+ for (size_t i = K; i > 0; --i) {
199
+ const size_t idx = i - 1;
200
+ if (this->state[idx] > this->lower_bound[idx]) {
201
+ --this->state[idx];
182
202
  break;
183
203
  } else {
184
- this->state[i] = this->upper_bound[i] - 1;
204
+ this->state[idx] = this->upper_bound[idx] - 1;
185
205
  }
186
206
  }
187
207
  return this->state;
188
208
  }
189
209
  std::array<T, K> operator--(int) {
190
210
  const auto res = this->state;
191
- --this;
211
+ --(*this);
192
212
  return res;
193
213
  }
194
214
  std::array<T, K> operator*() { return this->state; };
@@ -214,13 +234,16 @@ class ArrayLimits {
214
234
 
215
235
  namespace MSO {
216
236
  struct BadInitialization : public std::runtime_error {
217
- BadInitialization(char const* const message) : std::runtime_error(message) {};
218
- BadInitialization(const std::string& message)
237
+ explicit BadInitialization(char const* const message)
238
+ : std::runtime_error(message) {};
239
+ explicit BadInitialization(const std::string& message)
219
240
  : std::runtime_error(message) {};
220
241
  };
221
242
  struct BadArgumentSize : public std::runtime_error {
222
- BadArgumentSize(char const* const message) : std::runtime_error(message) {};
223
- BadArgumentSize(const std::string& message) : std::runtime_error(message) {};
243
+ explicit BadArgumentSize(char const* const message)
244
+ : std::runtime_error(message) {};
245
+ explicit BadArgumentSize(const std::string& message)
246
+ : std::runtime_error(message) {};
224
247
  };
225
248
 
226
249
  template <typename T, typename M = double, size_t N = 3>
@@ -255,8 +278,8 @@ class MSO {
255
278
 
256
279
  void set_use_background(bool val) { this->use_background = val; }
257
280
 
258
- void set_components_num(T components_num) {
259
- this->components_num = components_num;
281
+ void set_components_num(T components_num_) {
282
+ this->components_num = components_num_;
260
283
  }
261
284
 
262
285
  void erase_data() {
@@ -265,18 +288,20 @@ class MSO {
265
288
  this->size.fill(0);
266
289
  }
267
290
 
268
- inline size_t get_length() const { return calculate_area_size(this->size); }
291
+ [[nodiscard]] inline size_t get_length() const {
292
+ return calculate_area_size(this->size);
293
+ }
269
294
 
270
295
  inline std::array<size_t, ndim> dimension_size() const {
271
296
  return calculate_dimension_size(this->size);
272
297
  }
273
298
 
274
299
  template <typename W>
275
- void set_data(T* components, W size) {
276
- this->components = components;
300
+ void set_data(T* components_, W size_) {
301
+ this->components = components_;
277
302
  for (size_t i = 0; i < ndim; i++) {
278
- this->size[i] = size[i];
279
- this->upper_bound[i] = size[i];
303
+ this->size[i] = size_[i];
304
+ this->upper_bound[i] = size_[i];
280
305
  this->lower_bound[i] = 0;
281
306
  }
282
307
  if (this->get_length() != this->mu_array.size()) this->mu_array.clear();
@@ -284,10 +309,15 @@ class MSO {
284
309
  }
285
310
 
286
311
  template <typename W>
287
- void set_bounding_box(W lower_bound, W upper_bound) {
312
+ void set_bounding_box(W lower_bound_, W upper_bound_) {
288
313
  for (size_t i = 0; i < ndim; i++) {
289
- this->lower_bound[i] = lower_bound[i];
290
- this->upper_bound[i] = upper_bound[i];
314
+ if (lower_bound_[i] > upper_bound_[i])
315
+ throw std::runtime_error(
316
+ "In index " + std::to_string(i) + "the lower bound " +
317
+ std::to_string(lower_bound_[i]) + " is greater than upper bound " +
318
+ std::to_string(upper_bound_[i]));
319
+ this->lower_bound[i] = lower_bound_[i];
320
+ this->upper_bound[i] = upper_bound_[i];
291
321
  }
292
322
  }
293
323
 
@@ -320,22 +350,22 @@ class MSO {
320
350
  this->steps = 0;
321
351
  }
322
352
 
323
- void set_neighbourhood(std::vector<int8_t> neighbourhood,
324
- std::vector<mu_type> distances) {
325
- if (neighbourhood.size() != ndim * distances.size()) {
326
- throw std::length_error(
327
- "Size of neighbourhood need to be 3* Size of distances");
353
+ void set_neighbourhood(const std::vector<int8_t>& neighbourhood_,
354
+ std::vector<mu_type> distances_) {
355
+ if (neighbourhood_.size() != ndim * distances_.size()) {
356
+ throw std::length_error("Size of neighbourhood need to be " +
357
+ std::to_string(ndim) + "* Size of distances");
328
358
  }
329
- this->neighbourhood = neighbourhood;
330
- this->distances = distances;
359
+ this->neighbourhood = neighbourhood_;
360
+ this->distances = distances_;
331
361
  this->steps = 0;
332
362
  }
333
363
 
334
- void set_neighbourhood(int8_t* neighbourhood, mu_type* distances,
364
+ void set_neighbourhood(int8_t* neighbourhood_, mu_type* distances_,
335
365
  size_t neigh_size) {
336
366
  this->neighbourhood =
337
- std::vector<int8_t>(neighbourhood, neighbourhood + 3 * neigh_size);
338
- this->distances = std::vector<double>(distances, distances + neigh_size);
367
+ std::vector<int8_t>(neighbourhood_, neighbourhood_ + ndim * neigh_size);
368
+ this->distances = std::vector<mu_type>(distances_, distances_ + neigh_size);
339
369
  this->steps = 0;
340
370
  }
341
371
 
@@ -372,23 +402,23 @@ class MSO {
372
402
  // "Distances: " << this->distances << std::endl;
373
403
  auto bounds =
374
404
  ArrayLimits<coord_type, ndim>(this->lower_bound, this->upper_bound);
375
- for (auto coord : bounds) {
376
- position = calculate_position(coord, global_dimension_size);
405
+ for (auto coord_ : bounds) {
406
+ position = calculate_position(coord_, global_dimension_size);
377
407
  array_position =
378
- calculate_position(coord - this->lower_bound, global_dimension_size);
408
+ calculate_position(coord_ - this->lower_bound, dimension_size);
379
409
  array[array_position] = std::numeric_limits<mu_type>::max();
380
410
  if (this->components[position] == this->background_component) {
381
- array[position] = 0;
382
- for (size_t i = 0; i < 3 * this->distances.size(); i += 3) {
411
+ array[array_position] = 0;
412
+ for (size_t i = 0; i < ndim * this->distances.size(); i += ndim) {
383
413
  for (size_t j = 0; j < ndim; j++)
384
- coord2[j] = coord[j] + this->neighbourhood[i + j];
414
+ coord2[j] = coord_[j] + this->neighbourhood[i + j];
385
415
  if (outside_bounds(coord2, lower_bound, upper_bound)) {
386
416
  continue;
387
417
  }
388
418
  if (components[calculate_position(coord2, global_dimension_size)] ==
389
419
  0) {
390
- queue.push(coord);
391
- coord_in_queue[calculate_position(coord, global_dimension_size)] =
420
+ queue.push(coord_);
421
+ coord_in_queue[calculate_position(coord_, global_dimension_size)] =
392
422
  true;
393
423
  break;
394
424
  }
@@ -408,7 +438,7 @@ class MSO {
408
438
  fdt_value = array[array_position];
409
439
  for (size_t i = 0; i < this->distances.size(); i++) {
410
440
  for (size_t j = 0; j < ndim; j++)
411
- coord2[j] = coord[j] + this->neighbourhood[3 * i + j];
441
+ coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
412
442
  if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
413
443
  neigh_position = calculate_position(coord2, global_dimension_size);
414
444
  array_neigh_position =
@@ -429,14 +459,14 @@ class MSO {
429
459
  // std::cout << "Count " << count << std::endl;
430
460
  };
431
461
 
432
- size_t optimum_erosion_calculate(const std::vector<mu_type>& fdt_array,
462
+ size_t optimum_erosion_calculate(const std::vector<mu_type>& fdt_array_,
433
463
  std::vector<T>& components_arr,
434
464
  std::vector<bool>& sprawl_area,
435
465
  size_t count_steps_factor = 3) {
436
466
  Point coord, coord2;
437
467
  size_t position, neigh_position;
438
468
  mu_type val, val2;
439
- std::vector<mu_type> distances_from_components(fdt_array.size(), 0);
469
+ std::vector<mu_type> distances_from_components(fdt_array_.size(), 0);
440
470
  std::vector<my_queue<Point>> queues(this->components_num + 1);
441
471
  std::vector<bool> coord_in_queue(this->get_length(), false);
442
472
  auto bounds =
@@ -445,17 +475,17 @@ class MSO {
445
475
  calculate_dimension_size(this->upper_bound - this->lower_bound);
446
476
  const size_t area_size = bounds.size();
447
477
 
448
- for (auto coord : bounds) {
449
- position = calculate_position(coord, dimension_size);
478
+ for (auto coord_ : bounds) {
479
+ position = calculate_position(coord_, dimension_size);
450
480
  if (components_arr[position] != 0) {
451
- distances_from_components[position] = fdt_array[position];
452
- for (size_t i = 0; i < 3 * this->distances.size(); i += 3) {
481
+ distances_from_components[position] = fdt_array_[position];
482
+ for (size_t i = 0; i < ndim * this->distances.size(); i += ndim) {
453
483
  for (size_t j = 0; j < ndim; j++)
454
- coord2[j] = coord[j] + this->neighbourhood[i + j];
484
+ coord2[j] = coord_[j] + this->neighbourhood[i + j];
455
485
  if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
456
486
  if (sprawl_area[calculate_position(coord2, dimension_size)] == true) {
457
- queues[components_arr[position]].push(coord);
458
- coord_in_queue[calculate_position(coord, dimension_size)] = true;
487
+ queues[components_arr[position]].push(coord_);
488
+ coord_in_queue[calculate_position(coord_, dimension_size)] = true;
459
489
  break;
460
490
  }
461
491
  }
@@ -476,11 +506,11 @@ class MSO {
476
506
  val = distances_from_components[position];
477
507
  for (size_t i = 0; i < this->distances.size(); i++) {
478
508
  for (size_t j = 0; j < ndim; j++)
479
- coord2[j] = coord[j] + this->neighbourhood[3 * i + j];
509
+ coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
480
510
  if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
481
511
  neigh_position = calculate_position(coord2, dimension_size);
482
512
  if (sprawl_area[neigh_position] == false) continue;
483
- val2 = std::min(val, fdt_array[neigh_position]);
513
+ val2 = std::min(val, fdt_array_[neigh_position]);
484
514
  if (val2 < distances_from_components[neigh_position] -
485
515
  std::numeric_limits<mu_type>::epsilon())
486
516
  continue;
@@ -505,7 +535,7 @@ class MSO {
505
535
  }
506
536
 
507
537
  if (count_steps > count_steps_factor * area_size) {
508
- throw std::runtime_error("to many steps: constrained dilation");
538
+ throw std::runtime_error("too many steps: constrained dilation");
509
539
  }
510
540
  coord_in_queue[position] = false;
511
541
  }
@@ -526,7 +556,7 @@ class MSO {
526
556
  return count;
527
557
  };
528
558
 
529
- size_t constrained_dilation(const std::vector<mu_type>& fdt_array,
559
+ size_t constrained_dilation(const std::vector<mu_type>& fdt_array_,
530
560
  std::vector<T>& components_arr,
531
561
  std::vector<bool>& sprawl_area) const {
532
562
  if (this->get_length() == 0) throw BadInitialization("Zero sized array");
@@ -539,7 +569,7 @@ class MSO {
539
569
  size_t position, neigh_position, position_global;
540
570
  mu_type val, val2, dist_val;
541
571
  std::vector<mu_type> distances_from_components(
542
- fdt_array.size(), std::numeric_limits<mu_type>::max());
572
+ fdt_array_.size(), std::numeric_limits<mu_type>::max());
543
573
  std::vector<my_queue<Point>> queues(this->components_num + 1);
544
574
  my_queue<Point> queue_copy;
545
575
  std::vector<bool> coord_in_queue(this->get_length(), false);
@@ -554,15 +584,15 @@ class MSO {
554
584
  const size_t area_size = bounds.size();
555
585
 
556
586
  // Put borders of components to queue
557
- for (auto coord : bounds) {
558
- position = calculate_position(coord, dimension_size);
587
+ for (auto coord_ : bounds) {
588
+ position = calculate_position(coord_, dimension_size);
559
589
  if (components_arr[position] != 0) {
560
- for (size_t i = 0; i < 3 * this->distances.size(); i += 3) {
590
+ for (size_t i = 0; i < ndim * this->distances.size(); i += ndim) {
561
591
  for (size_t j = 0; j < ndim; j++)
562
- coord2[j] = coord[j] + this->neighbourhood[i + j];
592
+ coord2[j] = coord_[j] + this->neighbourhood[i + j];
563
593
  if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
564
594
  if (sprawl_area[calculate_position(coord2, dimension_size)] == true) {
565
- queues[components_arr[position]].push(coord);
595
+ queues[components_arr[position]].push(coord_);
566
596
  distances_from_components[position] =
567
597
  0; // this->mu_array[calculate_position(coord +
568
598
  // this->lower_bound, global_dimension_size)];
@@ -586,14 +616,14 @@ class MSO {
586
616
  coord = queue.front();
587
617
  queue.pop();
588
618
  position = calculate_position(coord, dimension_size);
589
- val = fdt_array[position];
619
+ val = fdt_array_[position];
590
620
  for (size_t i = 0; i < this->distances.size(); i++) {
591
621
  for (size_t j = 0; j < ndim; j++)
592
- coord2[j] = coord[j] + this->neighbourhood[3 * i + j];
622
+ coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
593
623
  if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
594
624
  neigh_position = calculate_position(coord2, dimension_size);
595
625
  if (sprawl_area[neigh_position] == false) continue;
596
- if (fdt_array[neigh_position] <= val &&
626
+ if (fdt_array_[neigh_position] <= val &&
597
627
  morphological_neighbourhood[neigh_position] != comp_num &&
598
628
  morphological_neighbourhood[neigh_position] !=
599
629
  std::numeric_limits<T>::max()) {
@@ -619,7 +649,7 @@ class MSO {
619
649
  // std::cerr << "Coord " << coord << " val " << val << std::endl;
620
650
  for (size_t i = 0; i < this->distances.size(); i++) {
621
651
  for (size_t j = 0; j < ndim; j++)
622
- coord2[j] = coord[j] + this->neighbourhood[3 * i + j];
652
+ coord2[j] = coord[j] + this->neighbourhood[ndim * i + j];
623
653
  if (outside_bounds(coord2, lower_bound, upper_bound)) continue;
624
654
  neigh_position = calculate_position(coord2, dimension_size);
625
655
  if (sprawl_area[neigh_position] == false ||
@@ -631,7 +661,7 @@ class MSO {
631
661
  this->distances[i] / 2;
632
662
  val2 = dist_val + val2;
633
663
  if (val2 + std::numeric_limits<mu_type>::epsilon() >=
634
- fdt_array[neigh_position]) {
664
+ fdt_array_[neigh_position]) {
635
665
  // std::cerr << " coord(fdt) " << coord2 << " " << val2 << " - "
636
666
  // << fdt_array[neigh_position] << std::endl;
637
667
  continue;
@@ -642,14 +672,14 @@ class MSO {
642
672
  // << distances_from_components[neigh_position] << std::endl;
643
673
  continue;
644
674
  }
645
- if (fabs(val2 - fdt_array[neigh_position]) <
675
+ if (fabs(val2 - fdt_array_[neigh_position]) <
646
676
  std::numeric_limits<mu_type>::epsilon()) {
647
677
  if (components_arr[neigh_position] == std::numeric_limits<T>::max())
648
678
  continue;
649
679
  else
650
680
  components_arr[neigh_position] = std::numeric_limits<T>::max();
651
681
  }
652
- if (val2 < fdt_array[neigh_position]) {
682
+ if (val2 < fdt_array_[neigh_position]) {
653
683
  components_arr[neigh_position] = components_arr[position];
654
684
  distances_from_components[neigh_position] = val2;
655
685
  }
@@ -659,8 +689,8 @@ class MSO {
659
689
  coord_in_queue[neigh_position] = true;
660
690
  }
661
691
  }
662
- if (count_steps > 3 * area_size) {
663
- throw std::runtime_error("two many steps: constrained dilation");
692
+ if (count_steps > ndim * area_size) {
693
+ throw std::runtime_error("too many steps: constrained dilation");
664
694
  }
665
695
 
666
696
  coord_in_queue[position] = false;
@@ -671,7 +701,7 @@ class MSO {
671
701
  // std::endl; std::cerr << " component change " << count3 << " ";
672
702
  // std::cerr << "Queue1 " << queue.get_size() << " Queue2 " <<
673
703
  // queue_copy.get_size() << std::endl;
674
- comp_num++;
704
+ ++comp_num;
675
705
  }
676
706
  size_t count = 0;
677
707
  for (auto& el : components_arr) {
@@ -732,7 +762,7 @@ class MSO {
732
762
 
733
763
  size_t run_MSO(size_t steps_limits = 1, size_t count_steps_factor = 3) {
734
764
  if (this->components_num == 0)
735
- throw BadInitialization("Wrong number of components seted");
765
+ throw BadInitialization("Wrong number of components set");
736
766
  size_t total_changes = 0;
737
767
  if (steps_limits == 0) steps_limits = 1;
738
768
  if (steps_limits < this->steps) this->steps = 0;
@@ -756,16 +786,16 @@ class MSO {
756
786
  this->fdt_array, this->res_components_array, this->sprawl_area_array);
757
787
  total_changes += count_changes;
758
788
  // std::cerr << "loop3\n";
759
- this->steps++;
789
+ ++this->steps;
760
790
  }
761
791
  // std::cerr << "end\n";
762
792
  if (count_changes == 0) {
763
- this->steps--;
793
+ --this->steps;
764
794
  }
765
795
  return total_changes;
766
796
  }
767
797
 
768
- size_t steps_done() { return this->steps; }
798
+ [[nodiscard]] size_t steps_done() const { return this->steps; }
769
799
 
770
800
  std::vector<T> get_result_catted() const {
771
801
  return this->res_components_array;
@@ -790,7 +820,7 @@ class MuCalc {
790
820
  std::vector<R> result(length, 0);
791
821
  R mu;
792
822
  for (size_t i = 0; i < length; i++) {
793
- mu = (R)(array[i] - lower_bound) / (upper_bound - lower_bound);
823
+ mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
794
824
  shrink(mu);
795
825
  result[i] = mu;
796
826
  }
@@ -803,7 +833,7 @@ class MuCalc {
803
833
  std::vector<R> result(length, 0);
804
834
  R mu;
805
835
  for (size_t i = 0; i < length; i++) {
806
- mu = (R)(array[i] - lower_bound) / (upper_bound - lower_bound);
836
+ mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
807
837
  shrink(mu);
808
838
  if (mu < 0.5) mu = 1 - mu;
809
839
  result[i] = mu;
@@ -820,13 +850,16 @@ class MuCalc {
820
850
  T pixel_val;
821
851
  for (size_t i = 0; i < length; i++) {
822
852
  pixel_val = array[i];
823
- mu = (R)(pixel_val - lower_bound) / (upper_bound - lower_bound);
853
+ mu =
854
+ static_cast<R>(pixel_val - lower_bound) / (upper_bound - lower_bound);
824
855
  if (((lower_bound - lower_mid_bound) > 0) &&
825
856
  (pixel_val >= lower_mid_bound) && (pixel_val <= lower_bound))
826
- mu = (R)(pixel_val - lower_mid_bound) / (lower_bound - lower_mid_bound);
857
+ mu = static_cast<R>(pixel_val - lower_mid_bound) /
858
+ (lower_bound - lower_mid_bound);
827
859
  else if (((upper_bound - lower_bound) > 0) && (lower_bound < pixel_val) &&
828
860
  (pixel_val <= upper_bound))
829
- mu = (R)(upper_bound - pixel_val) / (upper_bound - lower_bound);
861
+ mu = static_cast<R>(upper_bound - pixel_val) /
862
+ (upper_bound - lower_bound);
830
863
  shrink(mu);
831
864
  result[i] = mu;
832
865
  }
@@ -835,12 +868,12 @@ class MuCalc {
835
868
 
836
869
  static std::vector<R> calculate_mu_array_masked(T* array, size_t length,
837
870
  T lower_bound, T upper_bound,
838
- uint8_t* mask) {
871
+ const uint8_t* mask) {
839
872
  std::vector<R> result(length, 0);
840
873
  R mu;
841
874
  for (size_t i = 0; i < length; i++) {
842
875
  if (mask[i] == 0) continue;
843
- mu = (R)(array[i] - lower_bound) / (upper_bound - lower_bound);
876
+ mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
844
877
  shrink(mu);
845
878
  result[i] = mu;
846
879
  }
@@ -848,12 +881,13 @@ class MuCalc {
848
881
  }
849
882
 
850
883
  static std::vector<R> calculate_reflection_mu_array_masked(
851
- T* array, size_t length, T lower_bound, T upper_bound, uint8_t* mask) {
884
+ T* array, size_t length, T lower_bound, T upper_bound,
885
+ const uint8_t* mask) {
852
886
  std::vector<R> result(length, 0);
853
887
  R mu;
854
888
  for (size_t i = 0; i < length; i++) {
855
889
  if (mask[i] == 0) continue;
856
- mu = (R)(array[i] - lower_bound) / (upper_bound - lower_bound);
890
+ mu = static_cast<R>(array[i] - lower_bound) / (upper_bound - lower_bound);
857
891
  shrink(mu);
858
892
  if (mu < 0.5) mu = 1 - mu;
859
893
  result[i] = mu;
@@ -862,20 +896,23 @@ class MuCalc {
862
896
  }
863
897
  static std::vector<R> calculate_two_object_mu_masked(
864
898
  T* array, size_t length, T lower_bound, T upper_bound, T lower_mid_bound,
865
- T upper_mid_bound, uint8_t* mask) {
899
+ T upper_mid_bound, const uint8_t* mask) {
866
900
  std::vector<R> result(length, 0);
867
901
  R mu;
868
902
  T pixel_val;
869
903
  for (size_t i = 0; i < length; i++) {
870
904
  if (mask[i] == 0) continue;
871
905
  pixel_val = array[i];
872
- mu = (R)(pixel_val - lower_bound) / (upper_bound - lower_bound);
906
+ mu =
907
+ static_cast<R>(pixel_val - lower_bound) / (upper_bound - lower_bound);
873
908
  if (((lower_bound - lower_mid_bound) > 0) &&
874
909
  (pixel_val >= lower_mid_bound) && (pixel_val <= lower_bound))
875
- mu = (R)(pixel_val - lower_mid_bound) / (lower_bound - lower_mid_bound);
910
+ mu = static_cast<R>(pixel_val - lower_mid_bound) /
911
+ (lower_bound - lower_mid_bound);
876
912
  else if (((upper_bound - lower_bound) > 0) && (lower_bound < pixel_val) &&
877
913
  (pixel_val <= upper_bound))
878
- mu = (R)(upper_bound - pixel_val) / (upper_bound - lower_bound);
914
+ mu = static_cast<R>(upper_bound - pixel_val) /
915
+ (upper_bound - lower_bound);
879
916
  shrink(mu);
880
917
  result[i] = mu;
881
918
  }
@@ -883,3 +920,5 @@ class MuCalc {
883
920
  }
884
921
  };
885
922
  } // namespace MSO
923
+
924
+ #endif