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

feature/view-setting-config #208

Merged
merged 17 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `view_port` and `camera` in the config

### Changed

### Removed


## [0.10.1] 2023-12-12

### Added


### Changed


### Removed

* Removed dependency on `cython`.


## [0.10.0] 2023-11-27

### Added
Expand Down
Binary file added docs/_images/example_camera_config.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/example_camera_config_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions docs/examples/control/example_camera_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from compas.geometry import Box
from compas.geometry import Frame
from compas_view2.app import App

# If you input incomplete configuration, the rest will be filled by the default values.

config = {
"view": {
"show_grid": True,
"view_mode": "shaded",
"background_color": [1, 1, 1, 1],
"selection_color": [1.0, 1.0, 0.0],
"view_port": "CUSTOM",
"camera": {
"fov": 45,
"near": 0.1,
"far": 1000,
"position": [-15, -15, 15],
"target": [0, 0, 0],
"scale": 1,
},
}
}

viewer_default = App()
viewer_custom = App(config=config)


box = Box(Frame([0, 0, 0], [1, 0, 0], [0, 1, 0]), 1, 1, 1)

viewer_default.add(box)
viewer_custom.add(box)


viewer_default.run()
viewer_custom.run()
31 changes: 31 additions & 0 deletions docs/examples/control/example_camera_config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
*******************************************************************************
Camera Config
*******************************************************************************

.. autosummary::
:toctree:
:nosignatures:

Default Camera Config
====================
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved
tomvanmele marked this conversation as resolved.
Show resolved Hide resolved

By default, the camera is configed 45 dregees perspective:

.. figure:: /_images/example_camera_config.jpg
:figclass: figure
:class: figure-img img-fluid



Custom Camera Config
====================

You can customize the camera configreation by passing the dictionary to the viewer: fov, near, fac 100, position, target, scale.


.. figure:: /_images/example_camera_config_2.jpg
:figclass: figure
:class: figure-img img-fluid

.. literalinclude:: example_camera_config.py
:language: python
4 changes: 2 additions & 2 deletions docs/examples/control/example_custom_keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Custom Keys
:nosignatures:

Default Keys
===========
=============

By default, the keys are like:

Expand All @@ -18,7 +18,7 @@ By default, the keys are like:


Custom Keys
===========
=============

You can customize the keys by modifying the ``keys`` parameter of the configuration.

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/tutorial_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ use the "on" decorator (:meth:`compas_view2.app.App.on`) on a callback function.


Zoom, Pan, Rotate, and Select
=================
===========================
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved
tomvanmele marked this conversation as resolved.
Show resolved Hide resolved

After launching the viewer, the view can be transformed by zooming, panning, and rotating. Object selection is also possible.

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/tutorial_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Thinking of the ``options`` in :mod:`Rhino` , the ``preferences..`` in :mod:`Ble


Customize Your Viewer
===================
=====================

There are two ways to customize your viewer:

Expand Down Expand Up @@ -65,7 +65,7 @@ This is a quick way to customize your viewer. It is suitable for task-specific c


Configuration Structure
====================
======================
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved
The default configuration file can be downloaded here: :download:`Link <files/config_default.json>`,
or can be printed by the following code:

Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/tutorial_software_concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ to help you better the design concepts behind it.


Software Architecture
===========
===================
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved

.. figure:: /_images/software_concept.png
:figclass: figure
:class: figure-img img-fluid


UI Components
===========
===============
.. figure:: /_images/UI.PNG
:figclass: figure
:class: figure-img img-fluid

Configuration Structure
===========
=====================
.. figure:: /_images/config_structure.png
:figclass: figure
:class: figure-img img-fluid
2 changes: 1 addition & 1 deletion requirements-dev.txt
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pin the sphinx version, related to compas-dev/compas_invocations@067a873

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ m2r2
nbsphinx
pydocstyle
pytest
sphinx == 7.1.2
sphinx >=3.4, <=7.1.2
sphinx_compas_theme >=0.15.18
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved
twine
wheel
Expand Down
11 changes: 10 additions & 1 deletion src/compas_view2/app/config_default.json
Copy link
Collaborator Author

@ZacZhangzhuo ZacZhangzhuo Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think we should use a custom setting here in the default config. It should be something minimal and simple.

the default value is already custom.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
"view": {
"show_grid": true,
"view_mode": "shaded",
"view_port": "CUSTOM",
"background_color": [1, 1, 1, 1],
"selection_color": [1.0, 1.0, 0.0]
"selection_color": [1.0, 1.0, 0.0],
"camera": {
"fov": 45,
"near": 0.1,
"far": 1000,
"position":[-1.5, -1.5, 1.5],
"target": [0, 0, 0],
"scale": 1
}
},
"statusbar": {
"texts": "Ready",
Expand Down
8 changes: 4 additions & 4 deletions src/compas_view2/app/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def view_front(self):
None

"""
self.app.view.current = self.app.view.FRONT
self.app.view.current = self.app.view.VIEW_ANGLES["FRONT"]
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved
self.app.view.camera.reset_position()
self.app.view.update_projection()
self.app.view.update()
Expand All @@ -444,7 +444,7 @@ def view_right(self):
None

"""
self.app.view.current = self.app.view.RIGHT
self.app.view.current = self.app.view.VIEW_ANGLES["RIGHT"]
self.app.view.camera.reset_position()
self.app.view.update_projection()
self.app.view.update()
Expand All @@ -457,7 +457,7 @@ def view_top(self):
None

"""
self.app.view.current = self.app.view.TOP
self.app.view.current = self.app.view.VIEW_ANGLES["TOP"]
self.app.view.camera.reset_position()
self.app.view.update_projection()
self.app.view.update()
Expand All @@ -470,7 +470,7 @@ def view_perspective(self):
None

"""
self.app.view.current = self.app.view.PERSPECTIVE
self.app.view.current = self.app.view.VIEW_ANGLES["PERSPECTIVE"]
self.app.view.camera.reset_position()
self.app.view.update_projection()
self.app.view.update()
Expand Down
14 changes: 7 additions & 7 deletions src/compas_view2/scene/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ def _on_target_update(self, target):
def reset_position(self):
"""Reset the position of the camera based current view type."""
self.target.set(0, 0, 0)
if self.view.current == self.view.PERSPECTIVE:
if self.view.current == self.view.VIEW_ANGLES["PERSPECTIVE"] or self.view.current == self.view.VIEW_ANGLES["CUSTOM"]:
self.rotation.set(pi / 4, 0, -pi / 4)
if self.view.current == self.view.TOP:
if self.view.current == self.view.VIEW_ANGLES["TOP"]:
self.rotation.set(0, 0, 0)
if self.view.current == self.view.FRONT:
if self.view.current == self.view.VIEW_ANGLES["FRONT"]:
self.rotation.set(pi / 2, 0, 0)
if self.view.current == self.view.RIGHT:
if self.view.current == self.view.VIEW_ANGLES["RIGHT"]:
self.rotation.set(pi / 2, 0, pi / 2)

def rotate(self, dx, dy):
Expand All @@ -257,10 +257,10 @@ def rotate(self, dx, dy):

Notes
-----
Camera rotations are only available if the current view is a perspective view (``camera.view.current == camera.view.PERSPECTIVE``).
Camera rotations are only available if the current view is a perspective view (``camera.view.current == camera.view.VIEW_ANGLES["PERSPECTIVE"]``).

"""
if self.view.current == self.view.PERSPECTIVE:
if self.view.current == self.view.VIEW_ANGLES["PERSPECTIVE"] or self.view.current == self.view.VIEW_ANGLES["CUSTOM"]:
self.rotation += [-self.rotation_delta * dy, 0, -self.rotation_delta * dx]

def pan(self, dx, dy):
Expand Down Expand Up @@ -320,7 +320,7 @@ def projection(self, width, height):

"""
aspect = width / height
if self.view.current == self.view.PERSPECTIVE:
if self.view.current == self.view.VIEW_ANGLES["PERSPECTIVE"] or self.view.current == self.view.VIEW_ANGLES["CUSTOM"]:
P = perspective(self.fov, aspect, self.near * self.scale, self.far * self.scale)
else:
left = -self.distance
Expand Down
13 changes: 5 additions & 8 deletions src/compas_view2/views/view.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import time
from OpenGL import GL

from OpenGL import GL
from qtpy import QtCore
from qtpy import QtWidgets

from compas_view2.scene import Camera
from compas_view2.objects import GridObject
from compas_view2.scene import Camera


class View(QtWidgets.QOpenGLWidget):
Expand All @@ -19,23 +19,20 @@ class View(QtWidgets.QOpenGLWidget):
The view configuration.
"""

FRONT = 1
RIGHT = 2
TOP = 3
PERSPECTIVE = 4
VIEW_ANGLES = {"CUSTOM": 0, "FRONT": 1, "RIGHT": 2, "TOP": 3, "PERSPECTIVE": 4}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the benefit to change these numeration to dict?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

The reason is for the readability of the config file: the original version would only allow us to put numbers (i,e. "view_angle":1 ) in the config. While using dict would allow us to indicate the key: "view_angle": "TOP".


def __init__(self, app, view_config):
super().__init__()
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self._opacity = 1.0
self._current = View.PERSPECTIVE
self._current = self.VIEW_ANGLES[view_config["view_port"]]
ZacZhangzhuo marked this conversation as resolved.
Show resolved Hide resolved
self.shader_model = None
self.app = app
self.color = view_config["background_color"]
self.mode = view_config["view_mode"]
self.selection_color = view_config["selection_color"]
self.show_grid = view_config["show_grid"]
self.camera = Camera(self)
self.camera = Camera(self, **view_config["camera"]) if self._current == 0 else Camera(self)
self.grid = GridObject(1, 10, 10)
self.objects = {}
self.keys = {"shift": False, "control": False, "f": False}
Expand Down
2 changes: 1 addition & 1 deletion src/compas_view2/views/view120.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def sort_objects_from_viewworld(self, viewworld):

def paint(self):
viewworld = self.camera.viewworld()
if self.current != self.PERSPECTIVE:
if self.current != self.VIEW_ANGLES["PERSPECTIVE"] or self.current != self.VIEW_ANGLES["CUSTOM"]:
self.update_projection()

# Draw instance maps
Expand Down
Loading