ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvSelectionAlgebra.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // Protect against Windows macro conflicts - must be before any includes
11 // Note: Windows headers may define DIFFERENCE as a macro
12 #ifdef DIFFERENCE
13 #undef DIFFERENCE
14 #endif
15 
16 // clang-format off
17 // Qt - must be included before qPCL.h and cvSelectionData.h for MOC to work correctly
18 // QObject must be fully defined before Q_ENUM macro
19 #include <QtCore/QObject>
20 #include <QtCore/QSet>
21 #include <QtCore/QString>
22 // clang-format on
23 
24 // LOCAL
25 // Note: cvSelectionData.h includes qPCL.h, so we include it after Qt headers
26 #include "cvSelectionData.h"
27 
28 // VTK
29 #include <vtkType.h>
30 
31 // Forward declarations
32 class vtkPolyData;
33 
46 class QPCL_ENGINE_LIB_API cvSelectionAlgebra : public QObject {
47  Q_OBJECT
48 
49 public:
57  enum class Operation {
58  UNION,
59  INTERSECTION,
60  DIFFERENCE,
61  SYMMETRIC_DIFF,
62  COMPLEMENT
63  };
64  Q_ENUM(Operation)
65 
66  explicit cvSelectionAlgebra(QObject* parent = nullptr);
67 
74  static cvSelectionData unionOf(const cvSelectionData& a,
75  const cvSelectionData& b);
76 
83  static cvSelectionData intersectionOf(const cvSelectionData& a,
84  const cvSelectionData& b);
85 
92  static cvSelectionData differenceOf(const cvSelectionData& a,
93  const cvSelectionData& b);
94 
101  static cvSelectionData symmetricDifferenceOf(const cvSelectionData& a,
102  const cvSelectionData& b);
103 
110  static cvSelectionData complementOf(vtkPolyData* polyData,
111  const cvSelectionData& input);
112 
121  static cvSelectionData performOperation(Operation op,
122  const cvSelectionData& a,
123  const cvSelectionData& b,
124  vtkPolyData* polyData = nullptr);
125 
140  static cvSelectionData growSelection(vtkPolyData* polyData,
141  const cvSelectionData& input,
142  int layers = 1,
143  bool removeSeed = false,
144  bool removeIntermediateLayers = false);
145 
153  static cvSelectionData shrinkSelection(vtkPolyData* polyData,
154  const cvSelectionData& input,
155  int iterations = 1);
156 
170  static cvSelectionData expandSelection(
171  vtkPolyData* polyData,
172  const cvSelectionData& input,
173  int layers,
174  bool removeSeed = false,
175  bool removeIntermediateLayers = false);
176 
183  static cvSelectionData extractBoundary(vtkPolyData* polyData,
184  const cvSelectionData& input);
185 
190  static bool areCompatible(const cvSelectionData& a,
191  const cvSelectionData& b);
192 
204  static cvSelectionData growPointSelection(
205  vtkPolyData* polyData,
206  const cvSelectionData& input,
207  int layers = 1,
208  bool removeSeed = false,
209  bool removeIntermediateLayers = false);
210 
218  static cvSelectionData shrinkPointSelection(vtkPolyData* polyData,
219  const cvSelectionData& input,
220  int iterations = 1);
221 
222 signals:
227 
231  void progressChanged(int percentage);
232 
237 
238 private:
239  static QSet<vtkIdType> getCellNeighbors(vtkPolyData* polyData,
240  vtkIdType cellId);
241  static QSet<vtkIdType> getPointNeighbors(vtkPolyData* polyData,
242  vtkIdType pointId);
243  static bool isBoundaryCell(vtkPolyData* polyData,
244  vtkIdType cellId,
245  const QSet<vtkIdType>& selectedSet);
246  static bool isBoundaryPoint(vtkPolyData* polyData,
247  vtkIdType pointId,
248  const QSet<vtkIdType>& selectedSet);
249  double computeCellArea(vtkPolyData* polyData, vtkIdType cellId);
250  double computeAngleBetweenNormals(const double n1[3], const double n2[3]);
251  bool isPointInBounds(const double point[3], const double bounds[6]);
252  double computeDistance(const double p1[3], const double p2[3]);
253  int countCellNeighbors(vtkPolyData* polyData, vtkIdType cellId);
254 };
255 
256 //=============================================================================
257 // Selection Filter (merged from cvSelectionFilter.h)
258 //=============================================================================
259 
271 class QPCL_ENGINE_LIB_API cvSelectionFilter : public QObject {
272  Q_OBJECT
273 
274 public:
278  enum FilterType {
284  TOPOLOGY_NEIGHBORS
285  };
286 
298  OUTSIDE
299  };
300 
301  explicit cvSelectionFilter(QObject* parent = nullptr);
302  ~cvSelectionFilter() override;
303 
307  cvSelectionData filterByAttributeRange(vtkPolyData* polyData,
308  const cvSelectionData& input,
309  const QString& attributeName,
310  double minValue,
311  double maxValue);
312 
316  cvSelectionData filterByAttributeComparison(vtkPolyData* polyData,
317  const cvSelectionData& input,
318  const QString& attributeName,
319  ComparisonOp op,
320  double value);
321 
325  cvSelectionData filterByArea(vtkPolyData* polyData,
326  const cvSelectionData& input,
327  double minArea,
328  double maxArea);
329 
333  cvSelectionData filterByNormalAngle(vtkPolyData* polyData,
334  const cvSelectionData& input,
335  double refX,
336  double refY,
337  double refZ,
338  double minAngleDeg,
339  double maxAngleDeg);
340 
344  cvSelectionData filterByBoundingBox(vtkPolyData* polyData,
345  const cvSelectionData& input,
346  const double bounds[6]);
347 
351  cvSelectionData filterByDistanceFromPoint(vtkPolyData* polyData,
352  const cvSelectionData& input,
353  double x,
354  double y,
355  double z,
356  double minDistance,
357  double maxDistance);
358 
362  cvSelectionData filterByNeighborCount(vtkPolyData* polyData,
363  const cvSelectionData& input,
364  int minNeighbors,
365  int maxNeighbors);
366 
370  static cvSelectionData combineAND(const cvSelectionData& a,
371  const cvSelectionData& b);
372 
376  static cvSelectionData combineOR(const cvSelectionData& a,
377  const cvSelectionData& b);
378 
382  static cvSelectionData invert(vtkPolyData* polyData,
383  const cvSelectionData& input);
384 
388  static QStringList getAttributeNames(vtkPolyData* polyData,
389  bool pointData = true);
390 
391 signals:
395  void progressChanged(int percentage);
396 
401 
402 private:
403  double computeCellArea(vtkPolyData* polyData, vtkIdType cellId);
404  double computeAngleBetweenNormals(const double n1[3], const double n2[3]);
405  bool isPointInBounds(const double point[3], const double bounds[6]);
406  double computeDistance(const double p1[3], const double p2[3]);
407  int countCellNeighbors(vtkPolyData* polyData, vtkIdType cellId);
408 };
#define signals
core::Tensor result
Definition: VtkUtils.cpp:76
Selection algebra operations.
Operation
Algebra operations Using enum class to avoid macro conflicts (e.g., DIFFERENCE may be defined as a ma...
void progressChanged(int percentage)
Emitted when filtering progress changes.
void filteringComplete(const cvSelectionData &result)
Emitted when filtering is complete.
void operationComplete(const cvSelectionData &result)
Emitted when operation is complete.
Encapsulates selection data without exposing VTK types.
Advanced selection filtering system.
ComparisonOp
Comparison operators.
void filteringComplete(const cvSelectionData &result)
Emitted when filtering is complete.
void progressChanged(int percentage)
Emitted when filtering progress changes.
@ ATTRIBUTE_RANGE
Filter by attribute value range.
@ SPATIAL_DISTANCE
Filter by distance from point.
@ GEOMETRIC_AREA
Filter by cell area.
@ GEOMETRIC_ANGLE
Filter by normal angle.
@ SPATIAL_BBOX
Filter by bounding box.
a[190]
normal_z y
normal_z x
normal_z z
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15