29 #include <vtkHardwareSelector.h>
30 #include <vtkIdTypeArray.h>
31 #include <vtkIntArray.h>
32 #include <vtkPolyData.h>
44 cvViewSelectionManager::cvViewSelectionManager(QObject* parent)
50 m_currentSelection(nullptr),
51 m_currentSelectionFieldAssociation(0),
55 m_annotations(nullptr),
56 m_highlighter(nullptr),
57 m_sourceObject(nullptr) {
68 "[cvViewSelectionManager] Initialized with utility modules");
72 cvViewSelectionManager::~cvViewSelectionManager() {
80 m_currentSelection =
nullptr;
84 m_highlighter =
nullptr;
140 m_currentMode = mode;
166 if (m_currentModifier == modifier) {
170 m_currentModifier = modifier;
181 m_numberOfLayers = 0;
202 bool removeIntermediateLayers) {
209 CVLog::Warning(
"[cvViewSelectionManager] No algebra module available");
215 "[cvViewSelectionManager] No selection to expand (grow/shrink "
216 "requires an existing selection)");
225 "[cvViewSelectionManager] No polyData available for expand "
226 "operation. Make sure you have data loaded in the viewer.");
231 int newNumberOfLayers = m_numberOfLayers + layers;
234 if (newNumberOfLayers < 0) {
235 newNumberOfLayers = 0;
242 : m_originalSelection;
246 if (newNumberOfLayers == 0) {
254 newNumberOfLayers, removeSeed,
255 removeIntermediateLayers);
258 if (!
result.isEmpty() || newNumberOfLayers == 0) {
263 m_numberOfLayers = newNumberOfLayers;
266 QString(
"[cvViewSelectionManager] Updated NumberOfLayers: %1")
267 .arg(m_numberOfLayers));
275 polyData,
result.vtkArray(),
276 static_cast<int>(
result.fieldAssociation()),
283 QString operationName =
284 layers > 0 ?
"Grow Selection" :
"Shrink Selection";
286 QString(
"[cvViewSelectionManager] %1: %2 -> %3 %4 (layers=%5)")
288 .arg(baseSelection.
count())
290 .arg(
result.fieldTypeString())
291 .arg(m_numberOfLayers));
295 "[cvViewSelectionManager] Expand resulted in empty selection");
301 m_growRemoveSeed = remove;
307 m_growRemoveIntermediateLayers = remove;
309 "GrowSelectionRemoveIntermediateLayers = %1")
317 if (mode1 == mode2) {
323 QSet<SelectionMode> cellModes = {
329 if (cellModes.contains(mode1) && cellModes.contains(mode2)) {
334 QSet<SelectionMode> pointModes = {
340 if (pointModes.contains(mode1) && pointModes.contains(mode2)) {
348 if (blockModes.contains(mode1) && blockModes.contains(mode2)) {
358 if (!m_currentSelection) {
359 return emptySelection;
365 m_currentSelectionFieldAssociation);
366 return cachedSelection;
381 m_originalSelection = selectionData;
382 m_numberOfLayers = 0;
385 .arg(selectionData.
count())
393 int fieldAssociation,
396 if (selection && selection.GetPointer() ==
nullptr) {
398 "[cvViewSelectionManager] Selection SmartPointer contains null "
404 vtkIdType newCount = 0;
408 newCount = selection->GetNumberOfTuples();
411 "[cvViewSelectionManager] Selection array has invalid "
417 "[cvViewSelectionManager] Selection array access failed - "
425 bool hasChanged =
false;
426 if (!m_currentSelection && newCount == 0) {
429 "[cvViewSelectionManager] Selection unchanged (both empty)");
431 }
else if (!m_currentSelection && newCount > 0) {
434 }
else if (m_currentSelection && newCount == 0) {
437 }
else if (m_currentSelection) {
439 vtkIdType oldCount = m_currentSelection->GetNumberOfTuples();
440 if (oldCount != newCount ||
441 m_currentSelectionFieldAssociation != fieldAssociation) {
445 bool idsMatch =
true;
446 for (vtkIdType i = 0; i < newCount; ++i) {
447 if (m_currentSelection->GetValue(i) != selection->GetValue(i)) {
452 hasChanged = !idsMatch;
458 "[cvViewSelectionManager] Selection unchanged, skipping "
465 m_currentSelection =
nullptr;
468 if (selection && newCount > 0) {
472 m_currentSelection->DeepCopy(selection);
473 m_currentSelectionFieldAssociation = fieldAssociation;
476 QString(
"[cvViewSelectionManager] Selection updated: %1 "
479 .arg(fieldAssociation == 0 ?
"cells" :
"points"));
480 }
catch (
const std::exception&
e) {
481 CVLog::Error(QString(
"[cvViewSelectionManager] DeepCopy failed: %1")
483 m_currentSelection =
nullptr;
484 m_currentSelectionFieldAssociation = 0;
488 "[cvViewSelectionManager] DeepCopy failed with unknown "
490 m_currentSelection =
nullptr;
491 m_currentSelectionFieldAssociation = 0;
495 m_currentSelectionFieldAssociation = 0;
500 m_currentSelectionFieldAssociation);
511 return m_currentSelection && m_currentSelection->GetNumberOfTuples() > 0;
522 CVLog::Warning(
"[cvViewSelectionManager] Algebra module not available");
530 selectionB, polyData);
545 vtkPolyData* polyData = vtkPolyData::SafeDownCast(
data);
548 "[cvViewSelectionManager::getPolyData] Got polyData "
549 "from last selection");
560 if (!actors.isEmpty()) {
563 vtkPolyData* polyData = vtkPolyData::SafeDownCast(
data);
566 "[cvViewSelectionManager::getPolyData] Got polyData "
567 "from first data actor");
606 "[cvViewSelectionManager] Clearing current selection (preventing "
607 "stale references)");
610 if (m_currentSelection) {
611 m_currentSelection =
nullptr;
614 m_currentSelectionFieldAssociation = -1;
617 m_sourceObject =
nullptr;
632 m_sourceObject = obj;
637 return m_sourceObject;
645 "[cvViewSelectionManager::getSourcePointCloud] No source "
659 QString(
"[cvViewSelectionManager::getSourcePointCloud] "
660 "Returning point cloud '%1' with %2 points")
662 .arg(cloud->
size()));
667 QString(
"[cvViewSelectionManager::getSourcePointCloud] "
668 "Source object '%1' is not a point cloud (type=%2)")
679 "[cvViewSelectionManager::getSourceMesh] No source object");
692 "Returning mesh '%1' with %2 triangles")
699 "Source object '%1' is not a mesh (type=%2)")
712 bool isValid = (m_sourceObject !=
nullptr);
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Print(const char *format,...)
Prints out a formatted message in console.
static bool PrintVerbose(const char *format,...)
Prints out a verbose formatted message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Hierarchical CLOUDVIEWER Object.
CV_CLASS_ENUM getClassID() const override
Returns class ID.
virtual unsigned size() const override
Returns the number of triangles.
virtual QString getName() const
Returns object name.
bool isA(CV_CLASS_ENUM type) const
bool isKindOf(CV_CLASS_ENUM type) const
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
unsigned size() const override
Selection algebra operations.
Operation
Algebra operations Using enum class to avoid macro conflicts (e.g., DIFFERENCE may be defined as a ma...
static cvSelectionData expandSelection(vtkPolyData *polyData, const cvSelectionData &input, int layers, bool removeSeed=false, bool removeIntermediateLayers=false)
Expand selection (ParaView-compatible)
static cvSelectionData performOperation(Operation op, const cvSelectionData &a, const cvSelectionData &b, vtkPolyData *polyData=nullptr)
Perform algebra operation on two selections.
Selection annotation manager.
void setVisualizer(PclUtils::PCLVis *viewer)
Set the visualizer.
PclUtils::PCLVis * getPCLVis() const
Get PCLVis instance (for VTK-specific operations)
vtkDataSet * getDataFromActor(vtkActor *actor)
Get data object from a specific actor (ParaView-style)
virtual void setVisualizer(ecvGenericVisualizer3D *viewer)
Set the visualizer instance.
QList< vtkActor * > getDataActors() const
Get all visible data actors from visualizer.
ecvGenericVisualizer3D * getVisualizer() const
Get the visualizer instance.
Encapsulates selection data without exposing VTK types.
FieldAssociation fieldAssociation() const
Get field association.
vtkSmartPointer< vtkIdTypeArray > vtkArray() const
Get the underlying VTK array (for internal use only)
QString fieldTypeString() const
Get human-readable field type string.
bool isEmpty() const
Check if selection is empty.
int count() const
Get number of selected items.
Advanced selection filtering system.
Helper class for highlighting selected elements in the visualizer.
bool highlightSelection(const vtkSmartPointer< vtkIdTypeArray > &selection, int fieldAssociation, HighlightMode mode=SELECTED)
Highlight selected elements (automatically gets polyData from visualizer)
void clearHighlights()
Clear all highlights.
Selection pipeline abstraction layer.
void setPointPickingRadius(unsigned int radius)
Point Picking Radius support (ParaView-aligned)
void invalidateCachedSelection()
Clear selection cache and invalidate cached buffers.
void setVisualizer(PclUtils::PCLVis *viewer)
Set the visualizer for selection operations.
static vtkDataSet * getPrimaryDataFromSelection(vtkSelection *selection)
Get the primary data object from selection.
vtkSmartPointer< vtkSelection > getLastSelection() const
Get the last selection result.
unsigned int getPointPickingRadius() const
Get the current point picking radius.
Central manager for all selection operations in the view.
void setGrowSelectionRemoveSeed(bool remove)
Grow/Shrink Selection Settings (ParaView-aligned)
ccPointCloud * getSourcePointCloud() const
Get the source object as ccPointCloud.
void setCurrentSelection(const cvSelectionData &selectionData, bool resetLayers=true)
Set the current selection data.
bool isSourceObjectValid() const
Check if the source object is still valid.
void setSelectionModifier(SelectionModifier modifier)
Set the selection modifier.
bool isCompatible(SelectionMode mode1, SelectionMode mode2) const
Check if a selection mode is compatible with the current mode.
void disableSelection()
Disable the current selection mode (legacy - state tracking only)
void notifyDataUpdated()
Notify that scene data has been updated.
vtkPolyData * getPolyData() const
Get the underlying polyData for selection operations.
bool isSelectionActive() const
Check if any selection mode is currently active.
cvSelectionData performAlgebraOperation(int op, const cvSelectionData &selectionA, const cvSelectionData &selectionB=cvSelectionData())
Perform algebra operation on selections.
void clearCurrentSelection()
Clear the current selection data (prevents crashes from stale references)
void shrinkSelection()
Shrink the current selection by one layer.
void modeChanged(SelectionMode mode)
Emitted when the selection mode changes.
void modifierChanged(SelectionModifier modifier)
Emitted when selection modifier changes.
bool hasSelection() const
Check if there is a current selection.
ccHObject * getSourceObject() const
Get the source object for the current selection.
void setPointPickingRadius(unsigned int radius)
Set the point picking radius for single-point selection.
void clearSelection()
Clear all selections.
static cvViewSelectionManager * instance()
Get the singleton instance.
void setVisualizer(ecvGenericVisualizer3D *viewer) override
Set the visualizer for all selection operations.
void setGrowSelectionRemoveIntermediateLayers(bool remove)
Set whether to remove intermediate layers when growing selection.
void growSelection()
Grow the current selection by one layer.
unsigned int getPointPickingRadius() const
Get the current point picking radius.
ccMesh * getSourceMesh() const
Get the source object as ccMesh.
void enableSelection(SelectionMode mode)
Enable a selection mode (legacy - state tracking only)
const cvSelectionData & currentSelection() const
Get the current selection data (VTK-independent)
void expandSelection(int layers, bool removeSeed=false, bool removeIntermediateLayers=false)
Expand selection by given number of layers.
void setSourceObject(ccHObject *obj)
Set the source object for selection operations.
void selectionChanged()
Emitted when the selection has changed (legacy - for backward compatibility)
Generic visualizer 3D interface.
SelectionMode
Selection modes matching ParaView's SelectionMode enum.
@ SELECT_BLOCKS
Select blocks (rectangle)
@ SELECT_FRUSTUM_BLOCKS
Select blocks in frustum.
@ SELECT_FRUSTUM_POINTS
Select points in frustum.
@ SELECT_SURFACE_POINTS
Select points on surface (rectangle)
@ SELECT_SURFACE_POINTS_POLYGON
Select points on surface (polygon)
@ GROW_SELECTION
Expand selection by one layer.
@ SHRINK_SELECTION
Shrink selection by one layer.
@ SELECT_SURFACE_POINTS_INTERACTIVELY
@ SELECT_SURFACE_CELLS
Select cells on surface (rectangle)
@ SELECT_SURFACE_CELLS_INTERACTIVELY
@ SELECT_SURFACE_CELLS_POLYGON
Select cells on surface (polygon)
@ SELECT_FRUSTUM_CELLS
Select cells in frustum.
@ CLEAR_SELECTION
Clear current selection.
SelectionModifier
Selection modifiers for combining selections.
@ SELECTION_DEFAULT
Replace selection (default)