18 #include <QApplication>
19 #include <QElapsedTimer>
20 #include <QMainWindow>
28 #include <unordered_set>
58 double lineWidth = 1.0;
60 int subdivisions = 10;
61 bool showLabels =
true;
65 bool showGrid =
false;
66 QString xTitle =
"X-Axis";
67 QString yTitle =
"Y-Axis";
68 QString zTitle =
"Z-Axis";
69 bool xUseCustomLabels =
false;
70 bool yUseCustomLabels =
false;
71 bool zUseCustomLabels =
false;
72 bool useCustomBounds =
false;
80 double xMin = 0.0, xMax = 1.0;
81 double yMin = 0.0, yMax = 1.0;
82 double zMin = 0.0, zMax = 1.0;
97 bool stereoMode =
false);
100 static void ReleaseInstance();
110 void scheduleFullRedraw(
unsigned maxDelay_ms);
113 void cancelScheduledRedraw();
139 INTERACT_CTRL_PAN = 4,
140 INTERACT_ZOOM_CAMERA = 8,
141 INTERACT_2D_ITEMS = 16,
142 INTERACT_CLICKABLE_ITEMS = 32,
145 INTERACT_TRANSFORM_ENTITIES = 64,
148 INTERACT_SIG_RB_CLICKED = 128,
149 INTERACT_SIG_LB_CLICKED = 256,
150 INTERACT_SIG_MOUSE_MOVED =
152 INTERACT_SIG_BUTTON_RELEASED = 1024,
153 INTERACT_SIG_MB_CLICKED = 2048,
154 INTERACT_SEND_ALL_SIGNALS =
155 INTERACT_SIG_RB_CLICKED | INTERACT_SIG_LB_CLICKED |
156 INTERACT_SIG_MB_CLICKED | INTERACT_SIG_MOUSE_MOVED |
157 INTERACT_SIG_BUTTON_RELEASED,
160 MODE_PAN_ONLY = INTERACT_PAN | INTERACT_ZOOM_CAMERA |
161 INTERACT_2D_ITEMS | INTERACT_CLICKABLE_ITEMS,
162 MODE_TRANSFORM_CAMERA = INTERACT_ROTATE | MODE_PAN_ONLY,
163 MODE_TRANSFORM_ENTITIES =
164 INTERACT_ROTATE | INTERACT_PAN | INTERACT_ZOOM_CAMERA |
165 INTERACT_TRANSFORM_ENTITIES | INTERACT_CLICKABLE_ITEMS,
167 Q_DECLARE_FLAGS(INTERACTION_FLAGS, INTERACTION_FLAG)
170 static INTERACTION_FLAGS PAN_ONLY();
171 static INTERACTION_FLAGS TRANSFORM_CAMERA();
172 static INTERACTION_FLAGS TRANSFORM_ENTITIES();
204 : messageValidity_sec(0),
206 type(CUSTOM_MESSAGE) {}
226 cameraToBBCenterDist(0.0),
281 yTextBottomLineShift(0),
282 bbv_label(
"bubble-view mode"),
283 fs_label(
"fullscreen mode"),
284 psi_label(
"default point size"),
285 lsi_label(
"default line width"),
291 pixelDeviceRatio(1.0) {
296 updateInternalVariables(win);
299 void updateInternalVariables(QWidget* win) {
302 pixelDeviceRatio = GetPlatformAwareDPIScale();
303 int fontSize = GetOptimizedFontSize(12);
304 if (fontSize != pixelDeviceRatio) {
305 font.setPointSize(fontSize);
307 font.setPointSize(12 * pixelDeviceRatio);
309 CVLog::Print(QString(
"pixelDeviceRatio: %1 and fontSize %2")
310 .arg(pixelDeviceRatio)
312 margin *= pixelDeviceRatio;
313 iconSize *= pixelDeviceRatio;
317 QFontMetrics metrics(font);
318 bbv_labelRect = metrics.boundingRect(bbv_label);
319 fs_labelRect = metrics.boundingRect(fs_label);
320 psi_labelRect = metrics.boundingRect(psi_label);
321 lsi_labelRect = metrics.boundingRect(lsi_label);
323 psi_totalWidth = psi_labelRect.width() + margin +
324 iconSize + margin + iconSize ;
325 lsi_totalWidth = lsi_labelRect.width() + margin +
326 iconSize + margin + iconSize ;
327 bbv_totalWidth = bbv_labelRect.width() + margin +
329 fs_totalWidth = fs_labelRect.width() + margin +
333 std::max(psi_labelRect.height(), bbv_labelRect.height());
334 textHeight = std::max(lsi_labelRect.height(), textHeight);
335 textHeight = std::max(fs_labelRect.height(), textHeight);
336 textHeight = (3 * textHeight) /
338 yTextBottomLineShift = (iconSize / 2) + (textHeight / 2);
341 QRect
rect(
bool clickableItemsVisible,
342 bool bubbleViewModeEnabled,
343 bool fullScreenEnabled)
const {
346 if (clickableItemsVisible)
347 totalWidth = std::max(psi_totalWidth, lsi_totalWidth);
348 if (bubbleViewModeEnabled)
349 totalWidth = std::max(totalWidth, bbv_totalWidth);
350 if (fullScreenEnabled)
351 totalWidth = std::max(totalWidth, fs_totalWidth);
355 totalWidth = totalWidth + 3 * (margin + iconSize);
357 QPoint minAreaCorner(
358 0, std::min(0, yTextBottomLineShift - textHeight));
359 QPoint maxAreaCorner(totalWidth,
360 std::max(iconSize, yTextBottomLineShift));
361 int rowCount = clickableItemsVisible ? 2 : 0;
362 rowCount += bubbleViewModeEnabled ? 1 : 0;
363 rowCount += fullScreenEnabled ? 1 : 0;
364 maxAreaCorner.setY(maxAreaCorner.y() +
365 (iconSize + margin) * (rowCount - 1));
367 QRect areaRect(minAreaCorner - QPoint(margin, margin) / 2,
368 maxAreaCorner + QPoint(margin, margin) / 2);
383 static void DisplayText(
const QString& text,
386 unsigned char align = ALIGN_DEFAULT,
387 float bkgAlpha = 0.0f,
388 const unsigned char* rgbColor =
nullptr,
389 const QFont* font =
nullptr,
390 const QString&
id =
"");
404 static void Display3DLabel(
const QString& str,
407 const QFont& font = QFont());
410 static void SetFocusToScreen();
411 static void ToBeRefreshed();
412 static void RefreshDisplay(
bool only2D =
false,
bool forceRedraw =
true);
413 static void RedrawDisplay(
bool only2D =
false,
bool forceRedraw =
true);
414 static void CheckIfRemove();
446 static void RemoveBB(
const QString& viewId);
448 bool autoUpdate =
true);
452 bool update =
false);
456 bool update =
false);
457 static void RemoveAllWidgets(
bool update =
true);
458 static void Remove3DLabel(
const QString& view_id);
461 const std::string&
id =
"reference",
467 const std::string&
id =
"reference",
468 int viewport = 0) { }
487 int viewport = 0) { }
494 bool state =
true) { }
519 const QString& viewID,
531 const QString& viewID,
533 int viewport = 0) { }
554 int viewport = 0)
const {
565 bool visible,
int viewport = 0) { }
577 spacing, subdivisions,
578 showLabels, opacity, viewport);
589 int viewport = 0) { }
599 int viewport = 0)
const {
616 bool visible,
int viewport = 0) { }
667 if (!TheInstance())
return nullptr;
670 static void SetCurrentScreen(QWidget* widget);
672 if (!TheInstance())
return nullptr;
681 TheInstance()->
m_win = win;
684 static QPointF ToCenteredGLCoordinates(
int x,
int y);
695 static void AddToOwnDB(
ccHObject* obj,
bool noDependency =
true);
698 static void RemoveFromOwnDB(
ccHObject* obj);
705 static void UpdateNamePoseRecursive();
707 static void SetRedrawRecursive(
bool redraw =
false);
708 static void SetRedrawRecursive(
ccHObject* obj,
bool redraw =
false);
711 static void GetVisibleObjectsBB(
ccBBox& box);
719 static void RotateBaseViewMat(
const ccGLMatrixd& rotMat);
726 static void SetRemoveViewIDs(std::vector<removeInfo>& removeinfos);
744 return GetMainWindow()->devicePixelRatio();
749 QWidget* win = GetMainWindow();
754 int dpiScale = win->devicePixelRatio();
755 QScreen* screen = QApplication::primaryScreen();
761 QSize screenSize = screen->size();
762 int screenWidth = screenSize.width();
763 int screenHeight = screenSize.height();
764 int screenDPI = screen->physicalDotsPerInch();
767 int platformBaseSize = baseFontSize;
771 platformBaseSize = baseFontSize;
774 platformBaseSize = std::max(8, baseFontSize - (dpiScale - 1) * 2);
776 #elif defined(Q_OS_WIN)
778 if (screenDPI > 120) {
780 platformBaseSize = std::max(8, baseFontSize - 1);
781 }
else if (screenDPI < 96) {
783 platformBaseSize = baseFontSize + 1;
785 #elif defined(Q_OS_LINUX)
787 if (screenWidth >= 1920 && screenHeight >= 1080) {
789 platformBaseSize = std::max(8, baseFontSize - 1);
790 }
else if (screenWidth < 1366) {
792 platformBaseSize = baseFontSize + 1;
797 int resolutionFactor = 1;
798 if (screenWidth >= 2560 && screenHeight >= 1440) {
800 resolutionFactor = 0;
801 }
else if (screenWidth >= 1920 && screenHeight >= 1080) {
803 resolutionFactor = 0;
804 }
else if (screenWidth < 1366) {
806 resolutionFactor = 1;
810 int finalSize = platformBaseSize + resolutionFactor;
813 finalSize = std::max(6, std::min(24, finalSize));
820 QWidget* win = GetMainWindow();
825 int dpiScale = win->devicePixelRatio();
826 QScreen* screen = QApplication::primaryScreen();
828 return static_cast<double>(dpiScale);
832 QSize screenSize = screen->size();
833 int screenWidth = screenSize.width();
834 int screenHeight = screenSize.height();
835 int screenDPI = screen->physicalDotsPerInch();
838 double adjustedScale =
static_cast<double>(dpiScale);
844 adjustedScale = 1.0 + (dpiScale - 1.0) * 0.5;
846 #elif defined(Q_OS_WIN)
848 if (screenDPI > 120) {
850 adjustedScale = std::min(adjustedScale, 1.5);
851 }
else if (screenDPI < 96) {
853 adjustedScale = std::max(adjustedScale, 1.0);
855 #elif defined(Q_OS_LINUX)
857 if (screenWidth >= 2560 && screenHeight >= 1440) {
859 adjustedScale = std::min(adjustedScale, 1.3);
860 }
else if (screenWidth < 1366) {
862 adjustedScale = std::max(adjustedScale, 1.0);
867 adjustedScale = std::max(0.5, std::min(2.0, adjustedScale));
869 return adjustedScale;
873 QRect screenRect = GetCurrentScreen()->geometry();
874 QPoint globalPosition =
875 GetCurrentScreen()->mapToGlobal(screenRect.topLeft());
876 screenRect.setTopLeft(globalPosition);
880 GetCurrentScreen()->resize(QSize(xw, yw));
882 inline static void DoResize(
int xw,
int yw) { SetScreenSize(xw, yw); }
884 SetScreenSize(
size.width(),
size.height());
898 static void ZoomCamera(
double zoomFactor,
int viewport = 0);
899 inline virtual void zoomCamera(
double zoomFactor,
int viewport = 0) {}
912 double focal_distance,
int viewport = 0) { }
918 int viewport = 0) { }
923 int viewport = 0) { }
934 int viewport = 0) { }
944 int viewport = 0) { }
952 int viewport = 0) { }
964 view_z, up_x, up_y, up_z, viewport);
975 int viewport = 0) { }
982 int viewport = 0) { }
992 int viewport = 0) { }
998 int viewport = 0) { }
1013 int viewport = 0) { }
1018 viewPos[2] = Width();
1019 viewPos[3] = Height();
1029 const std::string& file) { }
1038 const std::string& file) { }
1044 const std::string& file) { }
1063 int viewport = 0) { }
1082 const std::string& viewID) { }
1095 int viewport = 0) { }
1102 int viewport = 0) { }
1104 static bool HideShowEntities(
const ccHObject* obj,
bool visible);
1111 static void HideShowEntities(
const QStringList& viewIDs,
1113 bool visibility =
false);
1115 static void RemoveEntities(
const ccHObject* obj);
1116 static void RemoveEntities(
const QStringList& viewIDs,
1126 static void Update2DLabel(
bool immediateUpdate =
false);
1127 static void Pick2DLabel(
int x,
int y);
1131 static void Redraw2DLabel();
1165 double xmin,
double ymin,
double xmax,
double ymax,
int& viewport) {
1178 const std::string& viewID) { }
1180 static void SetPointSize(
float size,
bool silent =
false,
int viewport = 0);
1181 static void SetPointSizeRecursive(
int size);
1186 static void SetLineWidth(
float width,
1187 bool silent =
false,
1206 static void DisplayNewMessage(
const QString& message,
1207 MessagePosition pos,
1208 bool append =
false,
1209 int displayMaxDelay_sec = 2,
1210 MessageType
type = CUSTOM_MESSAGE);
1220 static void UpdateDisplayParameters();
1222 static void SetupProjectiveViewport(
const ccGLMatrixd& cameraMatrix,
1223 float fov_deg = 0.0f,
1225 bool viewerBasedPerspective =
true,
1226 bool bubbleViewMode =
false);
1231 static void SetAspectRatio(
float ar);
1236 static void ResizeGL(
int w,
int h);
1237 static void UpdateScreenSize();
1239 GetCurrentScreen()->update();
1243 GetCurrentScreen()->update();
1290 int viewport = 0) { }
1306 SetCenterOfRotation(xyz[0], xyz[1], xyz[2]);
1310 SetCenterOfRotation(center.
u);
1321 const std::string& viewID,
1327 const std::string& viewID,
1335 static CCVector3d ConvertMousePositionToOrientation(
int x,
int y);
1341 static void UpdateActiveItemsList(
int x,
1343 bool extendToSelectedLabels =
false);
1347 SetGLViewport(QRect(
x,
y, w, h));
1350 static void SetGLViewport(
const QRect& rect);
1353 static void drawCross();
1354 static void drawTrihedron();
1357 static bool RenderToFile(QString
filename,
1358 float zoomFactor = 1.0f,
1359 bool dontScaleFeatures =
false,
1360 bool renderOverlayItems =
false);
1363 bool renderOverlayItems =
false,
1364 bool silent =
false,
1366 return TheInstance()->
renderToImage(zoomFactor, renderOverlayItems,
1370 bool renderOverlayItems =
false,
1371 bool silent =
false,
1381 static void DisplayTexture2DPosition(QImage
image,
1387 unsigned char alpha = 255);
1390 static void DrawClickableItems(
int xStart,
int& yStart);
1391 static void RenderText(
1395 const QFont& font = QFont(),
1397 const QString&
id =
"");
1398 static void RenderText(
1403 const QFont& font = QFont(),
1405 const QString&
id =
"");
1425 static void SetPixelSize(
float pixelSize);
1431 static void UpdateConstellationCenterAndZoom(
const ccBBox* aBox =
nullptr,
1432 bool redraw =
true);
1440 static void SetInteractionMode(INTERACTION_FLAGS flags);
1442 static INTERACTION_FLAGS GetInteractionMode();
1446 bool forceRedraw =
false);
1465 static void SetPerspectiveState(
bool state,
bool objectCenteredView);
1475 static bool ObjectPerspectiveEnabled();
1477 static bool ViewerPerspectiveEnabled();
1481 static float ComputePerspectiveZoom();
1486 static void SetFov(
float fov);
1488 static float GetFov();
1490 inline static void ZoomGlobal() { UpdateConstellationCenterAndZoom(); }
1507 static void SetCameraPos(
const CCVector3d& P);
1516 static void MoveCamera(
float dx,
float dy,
float dz);
1526 MoveCamera(v.
x, v.
y, v.
z);
1529 static void SetPickingMode(PICKING_MODE mode = DEFAULT_PICKING);
1530 static PICKING_MODE GetPickingMode();
1535 static void LockPickingMode(
bool state);
1538 static bool IsPickingModeLocked();
1543 static void SetZoom(
float value);
1548 static void UpdateZoom(
float zoomFactor);
1553 static void SetPivotPoint(
const CCVector3d& P,
1554 bool autoUpdateCameraPos =
false,
1555 bool verbose =
false);
1558 static void SetPivotVisibility(PivotVisibility vis);
1575 static void ShowPivotSymbol(
bool state);
1597 static void UpdateModelViewMatrix();
1598 static void UpdateProjectionMatrix();
1609 bool withGLfeatures,
1610 ProjectionMetrics* metrics =
nullptr,
1611 double* eyeOffset =
nullptr);
1627 static double ComputeActualPixelSize();
1630 static bool IsRectangularPickingAllowed();
1633 static void SetRectangularPickingAllowed(
bool state);
1643 static void SetBubbleViewMode(
bool state);
1649 static void SetBubbleViewFov(
float fov_deg);
1664 static void SetAutoPickPivotAtCenter(
bool state);
1666 emit TheInstance() -> autoPickPivot(state);
1674 static void LockRotationAxis(
bool state,
const CCVector3d& axis);
1682 static bool GetClick3DPos(
int x,
int y,
CCVector3d& P3D);
1684 static void DrawPivot();
1704 int _pickHeight = 5,
1705 bool _pickInSceneDB =
true,
1706 bool _pickInLocalDB =
true)
1710 pickWidth(_pickWidth),
1711 pickHeight(_pickHeight),
1712 pickInSceneDB(_pickInSceneDB),
1713 pickInLocalDB(_pickInLocalDB) {}
1727 static bool ProcessClickableItems(
int x,
int y);
1732 static void SetZNearCoef(
double coef);
1748 static void ProcessPickingResult(
1751 int pickedItemIndex,
1752 const CCVector3* nearestPoint =
nullptr,
1753 const std::unordered_set<int>* selectedIDs =
nullptr);
1760 TheInstance()->
m_font.setPointSize(pixelSize);
1763 static int GetFontPointSize();
1765 static int GetLabelFontPointSize();
1775 static QFont GetLabelDisplayFont();
1782 static const int DefaultPickRadius = 5;
1793 static void DisplayOverlayEntities(
bool state);
1810 bool stereoMode =
false) = 0;
1955 float m_sunLightPos[4];
1963 float m_customLightPos[4];
1987 : enabled(false), zoomFactor(1.0f), renderOverlayItems(false) {}
2005 int m_last_point_index = -1;
2006 QString m_last_picked_id = QString();
2035 static QSize
size() {
return GetScreenSize(); }
2044 static void ClearBubbleView();
2049 void onItemPickedFast(
ccHObject* pickedEntity,
2050 int pickedItemIndex,
2054 void onPointPicking(
const CCVector3& p,
int index,
const std::string&
id);
2057 void checkScheduledRedraw();
2064 void onWheelEvent(
float wheelDelta_deg);
2081 unsigned subEntityID,
CC_VIEW_ORIENTATION
View orientation.
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
std::shared_ptr< core::Tensor > image
static bool Print(const char *format,...)
Prints out a formatted message in console.
Double version of ccGLMatrixTpl.
Hierarchical CLOUDVIEWER Object.
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Interactor interface (entity that can be dragged or clicked in a 3D view)
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Generic visualizer 2D interface.
Generic visualizer 3D interface.
Generic visualizer interface.
Standard parameters for GL displays/viewports.
bool perspectiveView
Perspective view state.
float fov_deg
Camera F.O.V. (field of view) in degrees.
double zFar
Actual perspective 'zFar' value.
ccGLMatrixd viewMat
Visualization matrix (rotation only)
double zNear
Actual perspective 'zNear' value.
Generic file read and write utility for python interface.
float DegreesToRadians(int degrees)
Convert degrees to radians.
constexpr Rgbub defaultLabelBkgColor(MAX, MAX, MAX)
Data Axes Grid properties structure Encapsulates all properties for vtkCubeAxesActor configuration.
QList< QPair< double, QString > > xCustomLabels
QList< QPair< double, QString > > yCustomLabels
QList< QPair< double, QString > > zCustomLabels
AxesGridProperties()=default
OpenGL camera parameters.