ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvFilterTool.cpp
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 #include "ecvFilterTool.h"
9 
10 // LOCAL
11 #include "MainWindow.h"
13 
14 // ECV_CORE_LIB
15 #include <ecvGenericFiltersTool.h>
16 #include <ecvPointCloud.h>
17 #include <ecvProgressDialog.h>
18 
19 // CV_DB_LIB
20 #include <ecvPolyline.h>
21 
22 // QT
23 #include <QMessageBox>
24 
25 // Contour extraction parameters
26 static double s_maxEdgeLength = -1.0;
27 static bool s_splitContours = false;
28 static bool s_multiPass = false;
29 static double s_defaultGap = 0.0;
30 
31 // persistent map of the previous box used for each entity
35 };
36 static QMap<unsigned, ccClipBoxParams> s_lastBoxParams;
37 
39  : ccOverlayDialog(parent), Ui::FilterToolDlg(), m_filter(nullptr) {
40  setupUi(this);
41 
42  connect(exportButton, &QToolButton::clicked, this,
44  connect(resetButton, &QToolButton::clicked, this, &ecvFilterTool::reset);
45  connect(restoreToolButton, &QToolButton::clicked, this,
47  connect(closeButton, &QToolButton::clicked, this,
49 
50  connect(showBoxToolButton, &QToolButton::toggled, this,
52  connect(showInteractorsToolButton, &QToolButton::toggled, this,
54 
55  connect(minusXShiftToolButton, &QToolButton::clicked, this,
57  connect(plusXShiftToolButton, &QToolButton::clicked, this,
59  connect(minusYShiftToolButton, &QToolButton::clicked, this,
61  connect(plusYShiftToolButton, &QToolButton::clicked, this,
63  connect(minusZShiftToolButton, &QToolButton::clicked, this,
65  connect(plusZShiftToolButton, &QToolButton::clicked, this,
67 
68  viewButtonsFrame->setEnabled(true);
69  connect(viewUpToolButton, &QToolButton::clicked, this,
71  connect(viewDownToolButton, &QToolButton::clicked, this,
73  connect(viewFrontToolButton, &QToolButton::clicked, this,
75  connect(viewBackToolButton, &QToolButton::clicked, this,
77  connect(viewLeftToolButton, &QToolButton::clicked, this,
79  connect(viewRightToolButton, &QToolButton::clicked, this,
81 
82  s_maxEdgeLength = -1.0;
83 }
84 
86 
88  m_filter->showInteractor(state);
89 }
90 
91 void ecvFilterTool::toggleBox(bool state) {
92  if (m_filter) m_filter->showOutline(state);
93 }
94 
96  if (!entity) {
97  assert(false);
98  return false;
99  }
100 
101  // special case
102  if (entity->isGroup()) {
103  for (unsigned i = 0; i < entity->getChildrenNumber(); ++i) {
104  if (!addAssociatedEntity(entity->getChild(i))) {
105  return false;
106  }
107  }
108  return true;
109  }
110 
111  if (!m_filter) {
112  CVLog::Error(
113  QString("[ecvFilterTool::addAssociatedEntity] No associated "
114  "filter module!"));
115  return false;
116  }
117 
119  // error message already issued
120  CVLog::Error("An error occurred (see Console)");
121  return false;
122  }
123 
124  // force visibility
125  entity->setVisible(true);
126  entity->setEnabled(true);
127  return true;
128 }
129 
132 }
133 
134 bool ecvFilterTool::linkWith(QWidget* win) {
135  if (!ccOverlayDialog::linkWith(win)) {
136  return false;
137  }
138 
139  return true;
140 }
141 
143  assert(!m_processing);
144  if (!m_filter) return false;
145 
147  m_filter->start();
148  m_filter->showOutline(false);
149  m_out_entities.clear();
150 
151  return ccOverlayDialog::start();
152 }
153 
154 void ecvFilterTool::stop(bool state) {
155  if (m_filter) {
156  if (state && getNumberOfAssociatedEntity()) {
157  // save clip box parameters
159  m_filter->get(params.box, params.trans);
160  for (unsigned ci = 0; ci != getNumberOfAssociatedEntity(); ++ci) {
162  params;
163  }
164  }
165 
166  parametersLayout->removeWidget(m_filter->getFilterWidget());
167 
169  if (m_filter) {
170  delete m_filter;
171  m_filter = nullptr;
172  }
173 
175  }
176 
177  ccOverlayDialog::stop(state);
178 }
179 
181  if (!filter) return;
182  m_filter = filter;
183  m_filterType = filter->getFilterType();
184  parametersLayout->addWidget(filter->getFilterWidget());
185 }
186 
188  if (!m_filter) return nullptr;
189 
190  ccHObject* obj = m_filter->getOutput();
191  if (!obj) {
192  if (!silent) CVLog::Error("No output or Not enough memory!");
193  }
194 
195  return obj;
196 }
197 
199  if (!m_filter || !MainWindow::TheInstance()) return;
200 
201  for (unsigned ci = 0; ci != getNumberOfAssociatedEntity(); ++ci) {
203  if (!obj) {
204  assert(false);
205  continue;
206  }
207 
209  // save plot figure internally other than entity
210  ccHObject* result = getSlice(true);
212  // do nothing
213  CVLog::Warning("Glyph filter has no output, just for showing!");
214  return;
215  } else {
216  ccHObject* result = getSlice(false);
217  if (result) {
218  m_out_entities.push_back(result);
219  result->setEnabled(false);
220  result->setName(obj->getName() + QString(".section"));
221  if (obj->getParent()) obj->getParent()->addChild(result);
223  } else {
224  CVLog::Warning("failed to get filter result");
225  }
226  }
227  }
228 
229  // reset interactors or model if necessary
230  reset();
231 }
232 
235 }
236 
237 void ecvFilterTool::shiftBox(unsigned char dim, bool minus) {
238  if (!m_filter) return;
239  const ccBBox& bbox = m_filter->getBox();
240  if (!bbox.isValid()) return;
241 
242  assert(dim < 3);
243 
244  PointCoordinateType width = (bbox.maxCorner() - bbox.minCorner()).u[dim];
245  CCVector3 shiftVec(0, 0, 0);
246  shiftVec.u[dim] = (minus ? -width : width);
247  m_filter->shift(shiftVec);
248 }
249 
251  if (m_filter) m_filter->reset();
252 }
253 
255  if (m_filter) {
256  m_filter->restore();
257  }
258 }
259 
261 
263  ccBBox box;
264  if (getNumberOfAssociatedEntity() != 0) {
266  }
267  return box;
268 }
269 
271  // ccBBox* bbox = nullptr;
272  // ccBBox box = getSelectedEntityBbox();
273  // if (box.isValid()) {
274  // bbox = &box;
275  // }
276  ecvDisplayTools::SetView(orientation);
277 }
CC_VIEW_ORIENTATION
View orientation.
Definition: CVConst.h:102
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
int width
cmdLineReadable * params[]
core::Tensor result
Definition: VtkUtils.cpp:76
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
static MainWindow * TheInstance()
Returns the unique instance of this object.
void addToDB(const QStringList &filenames, QString fileFilter=QString(), bool displayDialog=true)
Type u[3]
Definition: CVGeom.h:139
Bounding box structure.
Definition: ecvBBox.h:25
virtual void setVisible(bool state)
Sets entity visibility.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
void removeAllChildren()
Removes all children.
virtual ccBBox getDisplayBB_recursive(bool relative)
Returns the bounding-box of this entity and it's children WHEN DISPLAYED.
ccHObject * getFirstChild() const
Shortcut: returns first child.
Definition: ecvHObject.h:396
unsigned getChildrenNumber() const
Returns the number of children.
Definition: ecvHObject.h:312
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccHObject * getParent() const
Returns parent object.
Definition: ecvHObject.h:245
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
Definition: ecvHObject.h:325
bool isGroup() const
Returns whether the instance is a group.
Definition: ecvHObject.h:237
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
virtual unsigned getUniqueID() const
Returns object unique ID.
Definition: ecvObject.h:86
virtual void setEnabled(bool state)
Sets the "enabled" property.
Definition: ecvObject.h:102
Generic overlay dialog interface.
virtual void stop(bool accepted)
Stops process/dialog.
virtual bool start()
Starts process.
bool m_processing
Running/processing state.
virtual bool linkWith(QWidget *win)
Links the overlay dialog with a MDI window.
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
Definition: BoundingBox.h:156
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
Definition: BoundingBox.h:154
bool isValid() const
Returns whether bounding box is valid or not.
Definition: BoundingBox.h:203
static void SetView(CC_VIEW_ORIENTATION orientation, ccBBox *bbox)
void shiftBox(unsigned char dim, bool minus)
Shift box.
ecvFilterTool(QWidget *parent)
Default constructor.
void setRightView()
Definition: ecvFilterTool.h:78
void shiftXPlus()
Definition: ecvFilterTool.h:67
void setBottomView()
Definition: ecvFilterTool.h:74
void setFilter(ecvGenericFiltersTool *filter)
void shiftYMinus()
Definition: ecvFilterTool.h:68
void shiftZMinus()
Definition: ecvFilterTool.h:70
ccHObject::Container m_out_entities
bool addAssociatedEntity(ccHObject *anObject)
Adds an entity.
unsigned getNumberOfAssociatedEntity() const
Returns the current number of associated entities.
void setTopView()
Definition: ecvFilterTool.h:73
void setBackView()
Definition: ecvFilterTool.h:76
void setLeftView()
Definition: ecvFilterTool.h:77
void releaseAssociatedEntities()
Releases all associated entities.
void shiftZPlus()
Definition: ecvFilterTool.h:71
ccHObject m_entityContainer
Associated entities container.
void shiftYPlus()
Definition: ecvFilterTool.h:69
ecvGenericFiltersTool::FilterType m_filterType
Definition: ecvFilterTool.h:99
void shiftXMinus()
Definition: ecvFilterTool.h:66
void toggleBox(bool)
void toggleInteractors(bool)
virtual bool start() override
Starts process.
ccBBox getSelectedEntityBbox()
ecvGenericFiltersTool * m_filter
filter tool
Definition: ecvFilterTool.h:97
virtual bool linkWith(QWidget *win) override
Links the overlay dialog with a MDI window.
virtual ~ecvFilterTool()
Default destructor.
virtual void stop(bool state) override
Stops process/dialog.
void setView(CC_VIEW_ORIENTATION orientation)
Sets predefined view.
ccHObject * getSlice(bool silent)
void setFrontView()
Definition: ecvFilterTool.h:75
Generic Filters Tool interface.
virtual void showOutline(bool state)=0
Whether to show the box or not.
virtual bool start()=0
virtual void unregisterFilter()=0
virtual void reset()=0
virtual const ccBBox & getBox()=0
Returns the box extents.
virtual bool setInputData(ccHObject *entity, int viewport=0)=0
virtual void restore()=0
virtual void getOutput(std::vector< ccHObject * > &outputSlices, std::vector< ccPolyline * > &outputContours) const =0
virtual QWidget * getFilterWidget()=0
virtual void shift(const CCVector3 &v)=0
Shifts the current box.
virtual void showInteractor(bool state)=0
virtual void get(ccBBox &extents, ccGLMatrix &transformation)=0
static QMap< unsigned, ccClipBoxParams > s_lastBoxParams
static double s_defaultGap
static bool s_splitContours
static bool s_multiPass
static double s_maxEdgeLength
ccGLMatrix trans