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);
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);
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 =
"");
393 TheInstance()->displayText(CONTEXT);
407 const QFont& font = QFont());
417 TheInstance()->draw(
context, obj);
424 TheInstance()->updateMeshTextures(
context, mesh);
432 TheInstance()->drawBBox(
context, bbox);
439 TheInstance()->drawOrientedBBox(
context, obb);
448 bool autoUpdate =
true);
452 bool update =
false);
456 bool update =
false);
461 const std::string&
id =
"reference",
463 TheInstance()->drawCoordinates(scale,
id, viewport);
467 const std::string&
id =
"reference",
468 int viewport = 0) { }
481 TheInstance()->rotateWithAxis(pos, axis, angle, viewport);
487 int viewport = 0) { }
490 TheInstance()->toggleOrientationMarker(state);
494 bool state =
true) { }
497 return TheInstance()->orientationMarkerShown();
519 const QString& viewID,
522 TheInstance()->setDataAxesGridProperties(viewID, props, viewport);
531 const QString& viewID,
533 int viewport = 0) { }
545 TheInstance()->getDataAxesGridProperties(viewID, props, viewport);
554 int viewport = 0)
const {
561 TheInstance()->setViewAxesGridVisible(visible, viewport);
565 bool visible,
int viewport = 0) { }
576 TheInstance()->setViewAxesGridProperties(visible,
color, lineWidth,
577 spacing, subdivisions,
578 showLabels, opacity, viewport);
589 int viewport = 0) { }
599 int viewport = 0)
const {
612 TheInstance()->setCenterAxesVisible(visible, viewport);
616 bool visible,
int viewport = 0) { }
621 TheInstance()->toggleCameraOrientationWidget(show);
629 return TheInstance()->isCameraOrientationWidgetShown();
637 TheInstance()->setLightIntensity(intensity);
645 return TheInstance()->getLightIntensity();
654 return TheInstance()->getVisualizer3D();
660 return TheInstance()->getVisualizer2D();
667 if (!TheInstance())
return nullptr;
668 return TheInstance()->m_currentScreen;
672 if (!TheInstance())
return nullptr;
673 return TheInstance()->m_mainScreen;
676 TheInstance()->m_mainScreen = widget;
681 TheInstance()->m_win = win;
702 return TheInstance()->m_globalDBRoot;
722 return TheInstance()->m_viewportParams.viewMat;
728 TheInstance()->m_removeAllFlag = state;
732 TheInstance()->transformCameraView(viewMat);
737 TheInstance()->transformCameraProjection(projMat);
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;
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);
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());
889 TheInstance()->setRenderWindowSize(xw, yw);
894 TheInstance()->fullScreen(state);
899 inline virtual void zoomCamera(
double zoomFactor,
int viewport = 0) {}
901 return TheInstance()->getCameraFocalDistance(viewport);
909 TheInstance()->setCameraFocalDistance(focal_distance, viewport);
912 double focal_distance,
int viewport = 0) { }
915 TheInstance()->getCameraPos(pos, viewport);
918 int viewport = 0) { }
920 TheInstance()->getCameraFocal(focal, viewport);
923 int viewport = 0) { }
925 TheInstance()->getCameraUp(up, viewport);
931 TheInstance()->setCameraPosition(pos, viewport);
934 int viewport = 0) { }
939 TheInstance()->setCameraPosition(pos, focal, up, viewport);
944 int viewport = 0) { }
948 TheInstance()->setCameraPosition(pos, up, viewport);
952 int viewport = 0) { }
963 TheInstance()->setCameraPosition(pos_x, pos_y, pos_z, view_x, view_y,
964 view_z, up_x, up_y, up_z, viewport);
975 int viewport = 0) { }
979 TheInstance()->getCameraClip(clipPlanes, viewport);
982 int viewport = 0) { }
986 TheInstance()->m_viewportParams.zNear = znear;
987 TheInstance()->m_viewportParams.zFar = zfar;
988 TheInstance()->setCameraClip(znear, zfar, viewport);
992 int viewport = 0) { }
995 TheInstance()->resetCameraClippingRange(viewport);
998 int viewport = 0) { }
1002 return TheInstance()->getCameraFovy(viewport);
1008 TheInstance()->m_viewportParams.fov_deg =
static_cast<float>(fovy);
1013 int viewport = 0) { }
1018 viewPos[2] = Width();
1019 viewPos[3] = Height();
1026 TheInstance()->saveScreenshot(file);
1029 const std::string& file) { }
1035 TheInstance()->saveCameraParameters(file);
1038 const std::string& file) { }
1041 TheInstance()->loadCameraParameters(file);
1044 const std::string& file) { }
1047 TheInstance()->showOrientationMarker();
1053 TheInstance()->setOrthoProjection(viewport);
1059 TheInstance()->setPerspectiveProjection(viewport);
1063 int viewport = 0) { }
1071 TheInstance()->setUseVbos(useVbos);
1079 TheInstance()->setLookUpTableID(viewID);
1082 const std::string& viewID) { }
1086 TheInstance()->getProjectionMatrix(projArray, viewport);
1092 TheInstance()->getViewMatrix(viewArray, viewport);
1095 int viewport = 0) { }
1099 TheInstance()->setViewMatrix(viewMat, viewport);
1102 int viewport = 0) { }
1106 return TheInstance()->hideShowEntities(CONTEXT);
1113 bool visibility =
false);
1119 TheInstance()->removeEntities(CONTEXT);
1134 return TheInstance()->pick3DItem(x, y);
1140 return TheInstance()->pickObject(x, y);
1165 double xmin,
double ymin,
double xmax,
double ymax,
int& viewport) {
1166 TheInstance()->createViewPort(xmin, ymin, xmax, ymax, viewport);
1175 TheInstance()->resetCameraViewpoint(viewID);
1178 const std::string& viewID) { }
1187 bool silent =
false,
1192 TheInstance()->toggle2Dviewer(state);
1208 bool append =
false,
1209 int displayMaxDelay_sec = 2,
1223 float fov_deg = 0.0f,
1225 bool viewerBasedPerspective =
true,
1226 bool bubbleViewMode =
false);
1239 GetCurrentScreen()->update();
1243 GetCurrentScreen()->update();
1247 TheInstance()->resetCamera(bbox);
1252 TheInstance()->resetCamera();
1257 TheInstance()->updateCamera();
1266 TheInstance()->setAutoUpateCameraPos(state);
1274 TheInstance()->getCenterOfRotation(center);
1277 TheInstance()->getCenterOfRotation(center.
u);
1286 TheInstance()->resetCenterOfRotation(viewport);
1290 int viewport = 0) { }
1299 TheInstance()->setCenterOfRotation(x, y, z);
1306 SetCenterOfRotation(xyz[0], xyz[1], xyz[2]);
1310 SetCenterOfRotation(center.
u);
1314 return TheInstance()->getGLDepth(x, y);
1321 const std::string& viewID,
1323 TheInstance()->changeOpacity(opacity, viewID, viewport);
1327 const std::string& viewID,
1343 bool extendToSelectedLabels =
false);
1347 SetGLViewport(QRect(x, y, w, h));
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,
1377 return TheInstance()->setScaleBarVisible(visible);
1387 unsigned char alpha = 255);
1395 const QFont& font = QFont(),
1397 const QString&
id =
"");
1403 const QFont& font = QFont(),
1405 const QString&
id =
"");
1409 TheInstance()->toggleExclusiveFullScreen(state);
1416 return TheInstance()->m_exclusiveFullscreen;
1419 TheInstance()->m_exclusiveFullscreen = state;
1432 bool redraw =
true);
1446 bool forceRedraw =
false);
1468 return TheInstance()->getPerspectiveState(viewport);
1471 return TheInstance()->m_viewportParams.perspectiveView;
1490 inline static void ZoomGlobal() { UpdateConstellationCenterAndZoom(); }
1526 MoveCamera(v.
x, v.
y, v.
z);
1554 bool autoUpdateCameraPos =
false,
1555 bool verbose =
false);
1560 TheInstance()->setPivotVisibility(state);
1566 return TheInstance()->m_pivotVisibility;
1582 return TheInstance()->getParallelScale(viewport);
1588 TheInstance()->setParallelScale(scale, viewport);
1609 bool withGLfeatures,
1611 double* eyeOffset =
nullptr);
1615 TheInstance()->m_validProjectionMatrix =
false;
1618 TheInstance()->m_validModelviewMatrix =
false;
1646 return TheInstance()->m_bubbleViewModeEnabled;
1654 TheInstance()->m_showCursorCoordinates = state;
1659 return TheInstance()->m_showCursorCoordinates;
1666 emit TheInstance() -> autoPickPivot(state);
1670 return TheInstance()->m_autoPickPivotAtCenter;
1678 return TheInstance()->m_rotationAxisLocked;
1689 TheInstance()->m_showDebugTraces = state;
1694 TheInstance()->m_showDebugTraces = !TheInstance()->m_showDebugTraces;
1704 int _pickHeight = 5,
1705 bool _pickInSceneDB =
true,
1706 bool _pickInLocalDB =
true)
1710 pickWidth(_pickWidth),
1711 pickHeight(_pickHeight),
1712 pickInSceneDB(_pickInSceneDB),
1713 pickInLocalDB(_pickInLocalDB) {}
1751 int pickedItemIndex,
1752 const CCVector3* nearestPoint =
nullptr,
1753 const std::unordered_set<int>* selectedIDs =
nullptr);
1760 TheInstance()->m_font.setPointSize(pixelSize);
1768 TheInstance()->m_clickableItemsVisible = state;
1771 return TheInstance()->m_clickableItemsVisible;
1782 static const int DefaultPickRadius = 5;
1786 TheInstance()->m_pickRadius = radius;
1798 return TheInstance()->m_displayOverlayEntities;
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(); }
2038 static int GlWidth() {
return TheInstance()->m_glViewport.width(); }
2040 static int GlHeight() {
return TheInstance()->m_glViewport.height(); }
2042 static QSize
GlSize() {
return TheInstance()->m_glViewport.size(); }
2050 int pickedItemIndex,
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
cmdLineReadable * params[]
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.
Generic file read and write utility for python interface.
float DegreesToRadians(int degrees)
Convert degrees to radians.
constexpr Rgbub defaultLabelBkgColor(MAX, MAX, MAX)
void UpdateCamera(int ncam, const avec< Float > &camera, const avec< Float > &delta, avec< Float > &new_camera)
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.