ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecv2.5DimEditor.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 "ecv2.5DimEditor.h"
9 
10 // LOCAL
11 #include "MainWindow.h"
13 #include "ecvPersistentSettings.h"
14 
15 // CV_DB_LIB
16 #include <ecvDisplayTools.h>
17 #include <ecvGenericPointCloud.h>
18 #include <ecvPointCloud.h>
19 #include <ecvProgressDialog.h>
20 #include <ecvScalarField.h>
21 
22 // Qt
23 #include <QCoreApplication>
24 #include <QFrame>
25 #include <QSettings>
26 
27 // System
28 #include <assert.h>
29 
30 cc2Point5DimEditor::cc2Point5DimEditor() : m_bbEditorDlg(0), m_rasterCloud(0) {}
31 
33  if (m_rasterCloud) {
36  delete m_rasterCloud;
37  m_rasterCloud = 0;
38  }
39 }
40 
42  if (m_bbEditorDlg) {
43  unsigned char projDim = getProjectionDimension();
44  assert(projDim < 3);
45  m_bbEditorDlg->set2DMode(true, projDim);
46  if (m_bbEditorDlg->exec()) {
47  gridIsUpToDate(false);
48  return true;
49  }
50  }
51 
52  return false;
53 }
54 
56  QWidget* parent) {
57  if (!m_bbEditorDlg) {
59  m_bbEditorDlg->setBaseBBox(gridBBox, false);
60  }
61 }
62 
63 void cc2Point5DimEditor::create2DView(QFrame* parentFrame) {
65  // black (text) & white (background) display by default
68  params.drawBackgroundGradient = false;
69  params.decimateMeshOnMove = false;
70  params.displayCross = false;
71  params.colorScaleUseShader = false;
80 
81  // add window to the input frame (if any)
82  if (parentFrame) {
83  auto layout = new QHBoxLayout;
84 
85  layout->setContentsMargins(0, 0, 0, 0);
86  // TODO
87  QWidget* widget = new QWidget();
88  layout->addWidget(widget);
89 
90  parentFrame->setLayout(layout);
91  }
92 }
93 
94 bool cc2Point5DimEditor::getGridSize(unsigned& gridWidth,
95  unsigned& gridHeight) const {
96  // vertical dimension
97  const unsigned char Z = getProjectionDimension();
98 
99  // cloud bounding-box --> grid size
100  ccBBox box = getCustomBBox();
101 
102  // grid step
103  double gridStep = getGridStep();
104 
105  return ccRasterGrid::ComputeGridSize(Z, box, gridStep, gridWidth,
106  gridHeight);
107 }
108 
110  unsigned gridWidth = 0, gridHeight = 0;
111  if (!getGridSize(gridWidth, gridHeight)) {
112  return QObject::tr("invalid grid box");
113  }
114 
115  return QString("%1 x %2").arg(gridWidth).arg(gridHeight);
116 }
117 
119  return (m_bbEditorDlg ? m_bbEditorDlg->getBox() : ccBBox());
120 }
121 
123  if (!ecvDisplayTools::GetMainWindow() || !m_grid.isValid()) return;
124 
125  // we compute the pixel size (in world coordinates)
126  {
128 
129  double realGridWidth = m_grid.width * m_grid.gridStep;
130  double realGridHeight = m_grid.height * m_grid.gridStep;
131 
132  static const int screnMargin = 20;
133  int screenWidth =
134  std::max(1, ecvDisplayTools::Width() - 2 * screnMargin);
135  int screenHeight =
136  std::max(1, ecvDisplayTools::Height() - 2 * screnMargin);
137 
138  int pointSize = 1;
139  if (static_cast<int>(m_grid.width) < screenWidth &&
140  static_cast<int>(m_grid.height) < screenHeight) {
141  int vPointSize = static_cast<int>(
142  ceil(static_cast<float>(screenWidth) / m_grid.width));
143  int hPointSize = static_cast<int>(
144  ceil(static_cast<float>(screenHeight) / m_grid.height));
145  pointSize = std::min(vPointSize, hPointSize);
146 
147  // if the grid is too small (i.e. necessary point size > 10)
148  if (pointSize > 10) {
149  pointSize = 10;
150  screenWidth = m_grid.width * pointSize;
151  screenHeight = m_grid.height * pointSize;
152  }
153  }
154 
155  params.pixelSize = static_cast<float>(std::max(
156  realGridWidth / screenWidth, realGridHeight / screenHeight));
157  params.zoom = 1.0f;
158 
161  }
162 
163  // we set the pivot point on the box center
164  CCVector3 P = box.getCenter();
167 
172 }
173 
175  const std::vector<ccRasterGrid::ExportableFields>& exportedFields,
176  bool interpolateSF,
177  bool interpolateColors,
178  bool resampleInputCloudXY,
179  bool resampleInputCloudZ,
180  ccGenericPointCloud* inputCloud,
181  bool fillEmptyCells,
182  double emptyCellsHeight,
183  bool exportToOriginalCS) const {
184  // projection dimension
185  const unsigned char Z = getProjectionDimension();
186  assert(Z <= 2);
187 
188  // cloud bounding-box
189  ccBBox box = getCustomBBox();
190  assert(box.isValid());
191 
192  return m_grid.convertToCloud(
193  exportedFields, interpolateSF, interpolateColors,
194  resampleInputCloudXY, resampleInputCloudZ, inputCloud, Z, box,
195  fillEmptyCells, emptyCellsHeight, exportToOriginalCS);
196 }
197 
199  QComboBox* comboBox) const {
200  if (!comboBox) {
201  assert(false);
203  }
204 
205  switch (comboBox->currentIndex()) {
206  case 0:
208  case 1:
210  case 2:
212  case 3:
214  case 4:
216  case 5:
218  default:
219  // shouldn't be possible for this option!
220  assert(false);
221  }
222 
224 }
Type u[3]
Definition: CVGeom.h:139
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
virtual ccBBox getCustomBBox() const
Returns custom bbox.
ccRasterGrid::EmptyCellFillOption getFillEmptyCellsStrategy(QComboBox *comboBox) const
Returns the empty cell strategy (for a given combo-box)
ccBoundingBoxEditorDlg * m_bbEditorDlg
Associated dialog.
void createBoundingBoxEditor(const ccBBox &gridBBox, QWidget *parent)
Creates the bounding-box editor.
virtual void gridIsUpToDate(bool state)=0
Declares whether the grid is up-to-date or not.
virtual unsigned char getProjectionDimension() const =0
Returns projection dimension.
ccPointCloud * convertGridToCloud(const std::vector< ccRasterGrid::ExportableFields > &exportedFields, bool interpolateSF, bool interpolateColors, bool resampleInputCloudXY, bool resampleInputCloudZ, ccGenericPointCloud *inputCloud, bool fillEmptyCells, double emptyCellsHeight, bool exportToOriginalCS) const
Shortcut to ccRasterGrid::convertToCloud.
ccRasterGrid m_grid
Raster grid.
virtual void update2DDisplayZoom(ccBBox &box)
Updates the 2D display zoom.
virtual double getGridStep() const =0
Returns projection grid step.
cc2Point5DimEditor()
Default constructor.
ccPointCloud * m_rasterCloud
'Raster' cloud
virtual bool showGridBoxEditor()
Show grid box editor and update.
virtual QString getGridSizeAsString() const
Returns the grid size as a string.
void create2DView(QFrame *parentFrame)
Creates the 2D view.
virtual bool getGridSize(unsigned &width, unsigned &height) const
Returns the grid size.
virtual ~cc2Point5DimEditor()
Destructor.
Bounding box structure.
Definition: ecvBBox.h:25
Dialog to define the extents of a 3D box.
const ccBBox & getBox() const
Returns bounding box.
void set2DMode(bool state, unsigned char dim)
Sets 2D mode (the line 'dim' will be hidden)
void setBaseBBox(const ccBBox &box, bool isMinimal=true)
Sets the (minimal) base box.
A 3D cloud interface with associated features (color, normals, octree, etc.)
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Vector3Tpl< T > getCenter() const
Returns center.
Definition: BoundingBox.h:164
bool isValid() const
Returns whether bounding box is valid or not.
Definition: BoundingBox.h:203
static void SetDisplayParameters(const ecvGui::ParamStruct &params)
Sets current parameters for this display.
static void RemoveFromOwnDB(ccHObject *obj)
Removes an entity from window own DB.
static void SetPointSize(float size, bool silent=false, int viewport=0)
static void SetPivotPoint(const CCVector3d &P, bool autoUpdateCameraPos=false, bool verbose=false)
Sets pivot point.
static void InvalidateViewport()
static void DisplayOverlayEntities(bool state)
static void SetViewportParameters(const ecvViewportParameters &params)
static int Height()
static QMainWindow * GetMainWindow()
static void SetPickingMode(PICKING_MODE mode=DEFAULT_PICKING)
static const ecvGui::ParamStruct & GetDisplayParameters()
Returns current parameters for this display (const version)
static int Width()
static void Deprecate3DLayer()
static void RedrawDisplay(bool only2D=false, bool forceRedraw=true)
static void SetCameraPos(const CCVector3d &P)
Sets camera position.
static void SetPerspectiveState(bool state, bool objectCenteredView)
Set perspective state/mode.
static const ecvViewportParameters & GetViewportParameters()
static void InvalidateVisualization()
static void SetInteractionMode(INTERACTION_FLAGS flags)
Standard parameters for GL displays/viewports.
float pixelSize
Current pixel size (in 'current unit'/pixel)
bool interpolateColors(const ccHObject::Container &selectedEntities, QWidget *parent)
Interpolate colors from on entity and transfer them to another one.
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
Definition: MiniVec.h:89
constexpr Rgb black(0, 0, 0)
constexpr Rgb white(MAX, MAX, MAX)
double gridStep
Grid step ('pixel' size)
unsigned height
Number of rows.
bool isValid() const
Returns whether the grid is 'valid' or not.
unsigned width
Number of columns.
ccPointCloud * convertToCloud(const std::vector< ExportableFields > &exportedFields, bool interpolateSF, bool interpolateColors, bool resampleInputCloudXY, bool resampleInputCloudZ, ccGenericPointCloud *inputCloud, unsigned char Z, const ccBBox &box, bool fillEmptyCells, double emptyCellsHeight, bool exportToOriginalCS) const
Converts the grid to a cloud with scalar field(s)
EmptyCellFillOption
Option for handling empty cells.
static bool ComputeGridSize(unsigned char Z, const ccBBox &box, double gridStep, unsigned &width, unsigned &height)
Computes the raster size for a given bounding-box.
GUI parameters.
ecvColor::Rgbub backgroundCol
Background color.
ecvColor::Rgbub textDefaultCol
Default text color.
bool displayCross
Display cross in the middle of the screen.
bool colorScaleUseShader
Whether to use shader for color scale display (if available) or not.
bool decimateMeshOnMove
Decimate meshes when moved.
bool drawBackgroundGradient
Use background gradient.