Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gsoc2024 basic viewer glfw tgrillon #8444

Open
wants to merge 70 commits into
base: master
Choose a base branch
from

Conversation

tgrillon
Copy link
Member

Summary of Changes

GLFW Basic viewer

Features

The main addition of this pull request is a new basic viewer based on GLFW. Its purpose is to provide the same features as the Qt viewer while using a lighter API.

Here is a summary of the main features that both viewers offer:

Camera features
  • Two type of camera: Orbiter & Free-fly (FPS).
  • Two camera mode: Perspective view (3D) & Orthographic view (2D).
  • FOV modification (40-90).
  • Translate/rotate the visualized structure.
  • Rotation/translation speed modification.
  • Zoom in/out.
  • Align camera to world axis.
  • Align camera to clipping plane.
  • Recenter the scene.
  • Reset position/orientation.
  • Rotation constraint axis (up, right and forward axis).
Clipping plane features
  • Four modes:
    • CLIPPING_PLANE_OFF: Disables the clipping plane.
    • CLIPPING_PLANE_SOLID_HALF_TRANSPARENT_HALF: Renders half of the clipped object as solid and half as transparent.
    • CLIPPING_PLANE_SOLID_HALF_WIRE_HALF: Renders half of the clipped object as solid and half with wireframe.
    • CLIPPING_PLANE_SOLID_HALF_ONLY: Only renders the positive side of the clipped object.
  • Align clipping plane to camera.
  • Rotate/Translate clipping plane.
  • Translate clipping plane along its normal.
  • Translate clipping plane along camera forward direction.
  • Rotation constraint axis (up and right axis).
  • Show/Hide clipping plane rendering.
Scene features
  • Show/Hide edges/vertices/faces/lines/rays/mesh triangles.
  • Single color mode:
    • Draw primitives using their default color defined in the graphics scene.
  • Multiple color mode:
    • Draw primitives using their defined color.
  • Draw edge as cylinder.
  • Draw vertex as sphere.
  • Draw vertex or face normal.
  • Inverse normal.
  • Use mono or direction based color for normal.
  • Show/Hide XY grid.
  • Show/Hide world axis.
  • Take a screenshot.
Feature only in GLFW viewer

Check out the wiki page where some of these features are presented.

Documentation

A file that provide documentation for public methods of the basic viewer class has been added in Basic_viewer/doc/Basic_viewer/CGAL/GLFW.

Project structure

All GLFW viewer components are located in Basic_viewer/include/CGAL/GLFW, with the following folders/files:

  • internal: Headers where classes used by the viewer are declared and implemented, such as Camera, ClippingPlane, Input, etc.
  • vendor: Contains the dependencies described in the next section.
  • Basic_viewer_impl.h: Contains the implementations of the basic viewer methods (this file is included in Basic_viewer.h).
  • Basic_viewer.h: Basic viewer class declaration.
  • bv_settings.h: Settings file containing tweakable viewer parameters such as window height and width, window samples, size of vertices/edges, etc.
Dependencies and build system

Here are the libraries used for this viewer:

The two viewers requires CGAL_Qt6 or CGAL_GLFW depending on which basic viewer the user wants to use. If both components are used, the Qt viewer will be the default. The viewers are only available if the macros CGAL_USE_BASIC_VIEWER/CGAL_USE_BASIC_VIEWER_QT (Qt viewer) or CGAL_USE_BASIC_VIEWER_GLFW (GLFW viewer) are defined.

The file CGAL_SetupCGAL_GLFWDependencies.cmake was added to manage GLFW/GLAD compilation and library linkage.

In CGALConfig.cmake, two new targets are generated:

  • CGAL::CGAL_Basic_viewer_Qt: target to which the Qt library will be linked.
  • CGAL::CGAL_Basic_viewer_GLFW: target to which the GLFW/GLAD libraries will be linked.

Note: Previously, only one target was defined for the Qt viewer: CGAL::CGAL_Basic_viewer. This target has not been removed yet. For the Qt viewer, both of CGAL::CGAL_Basic_viewer_Qt and CGAL::CGAL_Basic_viewer work.

  • Linking with the cmake target CGAL::CGAL_Basic_viewer/CGAL::CGAL_Basic_viewer_Qt will link with CGAL_Qt6 and add the definition CGAL_USE_BASIC_VIEWER/CGAL_USE_BASIC_VIEWER_QT.
  • Linking with the cmake target CGAL::CGAL_Basic_viewer_GLFW will link with CGAL_GLFW and add the definition CGAL_USE_BASIC_VIEWER_GLFW.

Qt viewer fixes

Some fixes and improvements have been made to the Qt viewer:

  • Fixing line width modification (using a geometry shader instead of deprecated glLineWidth method).
  • Improved mono color display performance (use uniform instead of vertex attribute).

TODO

  • Check cmake configuration (for @lrineau)
  • Remove CGAL::CGAL_Basic_viewer target and CGAL_USE_BASIC_VIEWER (?) (for @lrineau)

tgrillon and others added 30 commits June 17, 2024 11:32
- Object rotation using quaternions
- Object translation (with keys and mouse)
- Zoom in/out
- Reset camera (lctrl + r)
- Center camera (right double click)
(new) Installation/cmake/modules/CGAL_setupCGAL_GLFWDependencies.cmake :
- setup dependancies and target for GLFW (with glad and stb_image) -> work in progress
- build GLFW GLAD libs and link them to the target

(modif) Installation/lib/cmake/CGAL/CGALConfig.cmake :
- creation of new targets : CGAL_Basic_viewer_Qt and CGAL_Basic_viewer_GLFW
…/cgal-public-dev into gsoc2024-basic_viewer_glfw-tgrillon
This commit add the free-fly type camera which can be toggle pressing [LCTRL+V].
- [left mouse button] : rotate the camera orientation
- [scroll] : zoom
- [UP DOWN LEFT RIGHT] : move up/down/left/right
- [LSHIFT+UP LSHIFT+DOWN] : move forward/backward

Here some additional fixtures :

- Fixing the FOV modification. Now the FOV can be increased/decreased using [LCTRL+SCROLL]
- Smooth camera translation/rotation/zoom, smooth factors can be inc/dec :
  - ['+/-' numpad] : inc/dec rotation smooth factor
  - [LCTRL+'+/-' numpad] : inc/dec translation smooth factor
  - [LCTRL+scroll] : inc/dec zoom smooth factor
- Align camera orientation to nearest axis [mouse double left click]
- All change can be reset [LCTRL+R]
- Improvement of align-to-nearest-axis system
- Rework of Line_renderer to avoid multiple calls to glDraw function
- Now, we use Line_renderer to render the clipping plane

Things that need to be done :
- Rework the load_scene method to only reload the required buffers, not all of them.
A class Clipping_plane is used to manage the computation of rotation and translation and to return the 4x4 transformation
matrix used as Model in ModelViewProjection Matrix. The implementation that follows is similar to the camera's transformation
implementation.

Clipping plane interactions :
- Rotate using [LCTRL+LEFT MOUSE BUTTON]
- Translate using [LCTRL+RIGHT MOUSE BUTTON]
- Translate along camera forward direction using [LCTRL+MOUSE WHEEL]
- Translate along clipping plane normal vector using [LCTRL+SCROLL]
- Save keyframe using [LALT+F1]
- Run/Stop the animation using [F1]

Still work to be done.
However this controller can be triggered and used only if you are using the
orbiter-type camera.
+ Refactoring of Input.h file
  + New file 'key_code.h' is use to define key code macros based on glfw3.h file : I chose to use the same key codes as glfw because lots of them are based on ASCII code which ease int/char conversion.
  + The right key mapping can be achieved by setting a keyboard layout with set_keyboard_layout(Keyboard Layout: AZERTY).
+ upgrade of 'Terminal Help' with sections and application state informations like FPS, translation/rotation speed, light color...
- Remove key_code.h because it's useless. We direclty use CGLFW macros for key codes.
+ Shortcuts modifications to match Basic viewer Qt's ones
+ Adding position/direction/center to basic viewer setter methods, allowing user to set camera position/orientation and focus point.
…he camera orientation by providing forward direction and up angle
@afabri
Copy link
Member

afabri commented Sep 17, 2024

We have to remove the files of GLFW/vendor
This should be a third party software that we just link with. Or do I miss something?

@gdamiand
Copy link
Member

We have to remove the files of GLFW/vendor This should be a third party software that we just link with. Or do I miss something?

The idea is maybe to ship these files in cgal to simplify user life avoiding installing many external libraries; this is maybe possible because the files are small.

Of course, this will be discussed and validated with Laurent, Sébastien, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants