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:
226  void operationComplete(const cvSelectionData& result);
227 
231  void progressChanged(int percentage);
232 
236  void filteringComplete(const cvSelectionData& result);
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 
400  void filteringComplete(const cvSelectionData& result);
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 };
cvSelectionFilter::ComparisonOp
ComparisonOp
Comparison operators.
Definition: cvSelectionAlgebra.h:290
cvSelectionFilter::ATTRIBUTE_RANGE
@ ATTRIBUTE_RANGE
Filter by attribute value range.
Definition: cvSelectionAlgebra.h:279
QtCompat.h
x
normal_z x
Definition: my_point_types.h:165
cvSelectionData::hasActorInfo
bool hasActorInfo() const
Check if actor information is available.
Definition: cvSelectionData.h:253
cvSelectionFilter::BETWEEN
@ BETWEEN
Definition: cvSelectionAlgebra.h:297
normal
double normal[3]
Definition: FileIOFactory.cpp:53
cvSelectionFilter::SPATIAL_DISTANCE
@ SPATIAL_DISTANCE
Filter by distance from point.
Definition: cvSelectionAlgebra.h:283
cvSelectionFilter::filterByArea
cvSelectionData filterByArea(vtkPolyData *polyData, const cvSelectionData &input, double minArea, double maxArea)
Filter cells by area.
Definition: cvSelectionAlgebra.cpp:1175
cvSelectionData::fieldAssociation
FieldAssociation fieldAssociation() const
Get field association.
Definition: cvSelectionData.h:193
cvSelectionFilter::NOT_EQUAL
@ NOT_EQUAL
Definition: cvSelectionAlgebra.h:292
cvSelectionFilter::FilterType
FilterType
Filter types.
Definition: cvSelectionAlgebra.h:278
data
GraphType data
Definition: graph_cut.cc:138
cvSelectionAlgebra::shrinkPointSelection
static cvSelectionData shrinkPointSelection(vtkPolyData *polyData, const cvSelectionData &input, int iterations=1)
Shrink point selection by removing boundary points.
Definition: cvSelectionAlgebra.cpp:831
qSetFromVector
QSet< T > qSetFromVector(const QVector< T > &vec)
Definition: QtCompat.h:1073
cvSelectionFilter::filterByAttributeRange
cvSelectionData filterByAttributeRange(vtkPolyData *polyData, const cvSelectionData &input, const QString &attributeName, double minValue, double maxValue)
Filter by attribute value range.
Definition: cvSelectionAlgebra.cpp:1051
CVLog::PrintVerbose
static bool PrintVerbose(const char *format,...)
Prints out a verbose formatted message in console.
Definition: CVLog.cpp:103
signals
#define signals
Definition: PythonPlugin.cpp:26
cvSelectionFilter::combineAND
static cvSelectionData combineAND(const cvSelectionData &a, const cvSelectionData &b)
Combine two selections with AND operation.
Definition: cvSelectionAlgebra.cpp:1438
CVLog::Print
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
cvSelectionAlgebra::differenceOf
static cvSelectionData differenceOf(const cvSelectionData &a, const cvSelectionData &b)
Compute difference of two selections.
Definition: cvSelectionAlgebra.cpp:92
CVLog.h
cvSelectionAlgebra::unionOf
static cvSelectionData unionOf(const cvSelectionData &a, const cvSelectionData &b)
Compute union of two selections.
Definition: cvSelectionAlgebra.cpp:37
vtkSmartPointer
Definition: WidgetMap.h:20
cvSelectionAlgebra::shrinkSelection
static cvSelectionData shrinkSelection(vtkPolyData *polyData, const cvSelectionData &input, int iterations=1)
Shrink selection by removing boundary elements.
Definition: cvSelectionAlgebra.cpp:320
cvSelectionFilter::getAttributeNames
static QStringList getAttributeNames(vtkPolyData *polyData, bool pointData=true)
Get attribute names available in polyData.
Definition: cvSelectionAlgebra.cpp:1514
cvSelectionAlgebra::Operation::SYMMETRIC_DIFF
@ SYMMETRIC_DIFF
cvSelectionAlgebra
Selection algebra operations.
Definition: cvSelectionAlgebra.h:46
cvSelectionFilter::invert
static cvSelectionData invert(vtkPolyData *polyData, const cvSelectionData &input)
Invert selection (NOT operation)
Definition: cvSelectionAlgebra.cpp:1487
cvSelectionFilter::filterByNormalAngle
cvSelectionData filterByNormalAngle(vtkPolyData *polyData, const cvSelectionData &input, double refX, double refY, double refZ, double minAngleDeg, double maxAngleDeg)
Filter by normal angle relative to reference direction.
Definition: cvSelectionAlgebra.cpp:1213
normals
double normals[3]
Definition: TriangleMeshIO.cpp:54
result
core::Tensor result
Definition: VtkUtils.cpp:76
cvSelectionFilter
Advanced selection filtering system.
Definition: cvSelectionAlgebra.h:271
CVLog::Error
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
cvSelectionAlgebra::symmetricDifferenceOf
static cvSelectionData symmetricDifferenceOf(const cvSelectionData &a, const cvSelectionData &b)
Compute symmetric difference of two selections.
Definition: cvSelectionAlgebra.cpp:124
cvSelectionFilter::LESS_EQUAL
@ LESS_EQUAL
Definition: cvSelectionAlgebra.h:294
cvSelectionAlgebra::growPointSelection
static cvSelectionData growPointSelection(vtkPolyData *polyData, const cvSelectionData &input, int layers=1, bool removeSeed=false, bool removeIntermediateLayers=false)
Grow point selection by adding neighbor points.
Definition: cvSelectionAlgebra.cpp:739
y
normal_z y
Definition: my_point_types.h:168
cvSelectionFilter::GEOMETRIC_AREA
@ GEOMETRIC_AREA
Filter by cell area.
Definition: cvSelectionAlgebra.h:280
cvSelectionFilter::LESS_THAN
@ LESS_THAN
Definition: cvSelectionAlgebra.h:293
cvSelectionFilter::combineOR
static cvSelectionData combineOR(const cvSelectionData &a, const cvSelectionData &b)
Combine two selections with OR operation.
Definition: cvSelectionAlgebra.cpp:1463
cvSelectionAlgebra::cvSelectionAlgebra
cvSelectionAlgebra(QObject *parent=nullptr)
Definition: cvSelectionAlgebra.cpp:32
cvSelectionAlgebra.h
cvSelectionData::isEmpty
bool isEmpty() const
Check if selection is empty.
Definition: cvSelectionData.cpp:114
e
const double * e
Definition: essential_matrix_poly.h:10
cvSelectionFilter::SPATIAL_BBOX
@ SPATIAL_BBOX
Filter by bounding box.
Definition: cvSelectionAlgebra.h:282
cvSelectionFilter::cvSelectionFilter
cvSelectionFilter(QObject *parent=nullptr)
Definition: cvSelectionAlgebra.cpp:1043
cvSelectionAlgebra::Operation::DIFFERENCE
@ DIFFERENCE
cvSelectionData::CELLS
@ CELLS
Selection applies to cells.
Definition: cvSelectionData.h:142
cvSelectionAlgebra::Operation::INTERSECTION
@ INTERSECTION
cvSelectionData::primaryActor
vtkActor * primaryActor() const
Get the primary (front-most) actor.
Definition: cvSelectionData.cpp:181
cvSelectionFilter::filterByAttributeComparison
cvSelectionData filterByAttributeComparison(vtkPolyData *polyData, const cvSelectionData &input, const QString &attributeName, ComparisonOp op, double value)
Filter by attribute comparison.
Definition: cvSelectionAlgebra.cpp:1101
cvSelectionFilter::GREATER_EQUAL
@ GREATER_EQUAL
Definition: cvSelectionAlgebra.h:296
cvSelectionData::count
int count() const
Get number of selected items.
Definition: cvSelectionData.cpp:119
a
a[190]
Definition: essential_matrix_poly.h:19
cvSelectionData::ids
QVector< qint64 > ids() const
Get selected IDs as a vector (copy)
Definition: cvSelectionData.cpp:124
cvSelectionData::POINTS
@ POINTS
Selection applies to points.
Definition: cvSelectionData.h:143
cvSelectionFilter::filterByNeighborCount
cvSelectionData filterByNeighborCount(vtkPolyData *polyData, const cvSelectionData &input, int minNeighbors, int maxNeighbors)
Filter by neighbor count (topology)
Definition: cvSelectionAlgebra.cpp:1399
cvSelectionAlgebra::intersectionOf
static cvSelectionData intersectionOf(const cvSelectionData &a, const cvSelectionData &b)
Compute intersection of two selections.
Definition: cvSelectionAlgebra.cpp:63
cvSelectionAlgebra::Operation::UNION
@ UNION
cvSelectionAlgebra::expandSelection
static cvSelectionData expandSelection(vtkPolyData *polyData, const cvSelectionData &input, int layers, bool removeSeed=false, bool removeIntermediateLayers=false)
Expand selection (ParaView-compatible)
Definition: cvSelectionAlgebra.cpp:462
cvSelectionData
Encapsulates selection data without exposing VTK types.
Definition: cvSelectionData.h:136
CVLog::Warning
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
QPCL_ENGINE_LIB_API
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
cvSelectionAlgebra::extractBoundary
static cvSelectionData extractBoundary(vtkPolyData *polyData, const cvSelectionData &input)
Extract boundary elements of selection.
Definition: cvSelectionAlgebra.cpp:370
qVectorFromSet
QVector< T > qVectorFromSet(const QSet< T > &set)
Definition: QtCompat.h:1078
cvSelectionData.h
cvSelectionAlgebra::complementOf
static cvSelectionData complementOf(vtkPolyData *polyData, const cvSelectionData &input)
Compute complement of a selection.
Definition: cvSelectionAlgebra.cpp:165
cvSelectionFilter::EQUAL
@ EQUAL
Definition: cvSelectionAlgebra.h:291
z
normal_z z
Definition: my_point_types.h:165
cvSelectionFilter::GEOMETRIC_ANGLE
@ GEOMETRIC_ANGLE
Filter by normal angle.
Definition: cvSelectionAlgebra.h:281
cvSelectionData::primaryPolyData
vtkPolyData * primaryPolyData() const
Get the primary (front-most) polyData.
Definition: cvSelectionData.cpp:186
cvSelectionAlgebra::growSelection
static cvSelectionData growSelection(vtkPolyData *polyData, const cvSelectionData &input, int layers=1, bool removeSeed=false, bool removeIntermediateLayers=false)
Grow selection by adding neighbors.
Definition: cvSelectionAlgebra.cpp:240
cvSelectionData::setActorInfo
void setActorInfo(vtkActor *actor, vtkPolyData *polyData, double zValue=1.0)
Set actor information (single actor case)
Definition: cvSelectionData.cpp:159
cvSelectionAlgebra::Operation
Operation
Algebra operations Using enum class to avoid macro conflicts (e.g., DIFFERENCE may be defined as a ma...
Definition: cvSelectionAlgebra.h:57
cvSelectionAlgebra::performOperation
static cvSelectionData performOperation(Operation op, const cvSelectionData &a, const cvSelectionData &b, vtkPolyData *polyData=nullptr)
Perform algebra operation on two selections.
Definition: cvSelectionAlgebra.cpp:211
cvSelectionAlgebra::Operation::COMPLEMENT
@ COMPLEMENT
cvSelectionFilter::GREATER_THAN
@ GREATER_THAN
Definition: cvSelectionAlgebra.h:295
cvSelectionFilter::~cvSelectionFilter
~cvSelectionFilter() override
Definition: cvSelectionAlgebra.cpp:1048
cvSelectionFilter::filterByDistanceFromPoint
cvSelectionData filterByDistanceFromPoint(vtkPolyData *polyData, const cvSelectionData &input, double x, double y, double z, double minDistance, double maxDistance)
Filter by distance from point.
Definition: cvSelectionAlgebra.cpp:1329
cvSelectionFilter::filterByBoundingBox
cvSelectionData filterByBoundingBox(vtkPolyData *polyData, const cvSelectionData &input, const double bounds[6])
Filter by bounding box.
Definition: cvSelectionAlgebra.cpp:1266
cvSelectionAlgebra::areCompatible
static bool areCompatible(const cvSelectionData &a, const cvSelectionData &b)
Validate that two selections are compatible for operations.
Definition: cvSelectionAlgebra.cpp:405