| 1 |
""" |
| 2 |
|
| 3 |
CamiTK Python Bindings |
| 4 |
======================== |
| 5 |
|
| 6 |
This module provides Python bindings for CamiTK core functionalities. |
| 7 |
It allows one to access core classes and methods from Action Python scripts. |
| 8 |
|
| 9 |
**NOTE** |
| 10 |
|
| 11 |
This module is intended to be used within CamiTK Application context. |
| 12 |
It is meant to be used in Action Python scripts from inside a CamiTK application Python interpreter, and not as a standalone library. |
| 13 |
|
| 14 |
**Available classes and functions** |
| 15 |
|
| 16 |
- Action: Action class is an abstract class that enables you to build a action (generally an algorithm that works on specific data, i. |
| 17 |
- Application: The generic/default application. |
| 18 |
- Component: A Component represents something that could be included in the explorer view, the interactive 3D viewer, and that could have or not a contextual popup menu (open by a right click in the explorer), a property dialog (to change some properties) Thus, a Component inherits from many abstract classes. |
| 19 |
- ComponentExtension: This class describes what is a generic Component extension. |
| 20 |
- Core: Core class specifies the basic static information for the CamiTK API. |
| 21 |
- ExtensionManager: This class is used to manage all plugins loaded by the application. |
| 22 |
- FrameOfReference: FrameOfReference is only a label for an abstract coordinate system. |
| 23 |
- HotPlugAction: An Action that can be created on the fly. |
| 24 |
- ImageComponent: The manager of the Image Volume data. |
| 25 |
- InterfaceBitMap: This class describes what are the methods to implement for a BitMap. |
| 26 |
- InterfaceFrame: This class describes the methods to implement in order to manage a Component position in space. |
| 27 |
- InterfaceGeometry: This class describes what are the methods to implement for a Geometry (rendering parameters, input/output, filters, picking parameters. |
| 28 |
- InterfaceNode: This class describe what are the methods to implement for a hierarchical tree node. |
| 29 |
- InterfacePersistence: Interface for all objects that should be serialized by the PersistenceManager. |
| 30 |
- InterfaceProperty: This class describes what are the methods to implement in order to manage dynamic properties. |
| 31 |
- Log: This class is a log utility. |
| 32 |
- MeshComponent: Basic component to manage any kind of mesh. |
| 33 |
- Property: This class describes a property that can be used in components and actions or any class that needs to be passed to ObjectController. |
| 34 |
- Transformation: Transformation represents a geometrical transformation between two FrameOfReferences It supports linear and non-linear transforms stored in a vtkTransform (linear) or any vtkAbstractTransform (non-linear) It has a direction (from a FrameOfReference to another FrameOfReference) Its constructor is private as Transformation objects must only be created through TransformationManager::getTransformationManager() (although it is possible to instantiate your own TransformationManager if you know what you're doing!) . |
| 35 |
- TransformationManager: TransformationManager manages frames of reference and transformations for a CamiTK Application This class is the entry point to using FrameOfReference and Transformation system. |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
""" |
| 40 |
from __future__ import annotations |
| 41 |
import numpy |
| 42 |
import typing |
| 43 |
__all__: list[str] = ['Action', 'Application', 'Component', 'ComponentExtension', 'Core', 'ExtensionManager', 'FrameOfReference', 'HotPlugAction', 'ImageComponent', 'InterfaceBitMap', 'InterfaceFrame', 'InterfaceGeometry', 'InterfaceNode', 'InterfacePersistence', 'InterfaceProperty', 'Log', 'MeshComponent', 'Property', 'PythonHotPlugAction', 'Transformation', 'TransformationManager', 'error', 'getDebugInfo', 'getPythonVersion', 'info', 'newImageComponentFromNumpy', 'newMeshComponentFromNumpy', 'pythonConsoleRedirect', 'redirectStandardStreams', 'refresh', 'show', 'startApplication', 'trace', 'warning'] |
| 44 |
class Action: |
| 45 |
""" |
| 46 |
Action class is an abstract class that enables you to build a action |
| 47 |
(generally an algorithm that works on specific data, i.e. a specific |
| 48 |
component). |
| 49 |
|
| 50 |
To write an new action extension, at least two classes have to be |
| 51 |
reimplemented to enable the action: ActionExtension + Action. All the |
| 52 |
plugin mechanism is simplified thanks to CamiTK extension files (a |
| 53 |
JSON file containing all the information to generate the glue between |
| 54 |
your code and CamiTK). |
| 55 |
|
| 56 |
## Overview |
| 57 |
|
| 58 |
This is the list of attributes you need to consider when creating a |
| 59 |
new action - name: name of the action; - description: tag used to |
| 60 |
describe the action (also used for tooltip and whatsThis of the |
| 61 |
corresponding QAction); - componentClassName: the name of the |
| 62 |
component class on which this action can be applied or "" (default) |
| 63 |
for generic actions. It determines on which type of component your |
| 64 |
action can be applied. Generic actions are action that have an empty |
| 65 |
component class name. Therefore generic actions can be called to |
| 66 |
generate/synthetize data or initialize resources. - family: families |
| 67 |
of actions allows one to group different actions of the same kind |
| 68 |
under one name; - tags: tags is a list of words used to define an |
| 69 |
action. These words can be used to find an action. - gui: either |
| 70 |
"Default Action GUI" (the action uses a default widget, instance of |
| 71 |
ActionWidget), "No GUI" or "Custom GUI" (you need to create the |
| 72 |
action's gui widget) - notEmbedded: this boolean defines if the gui |
| 73 |
widget is embedded in a given parent widget / action widget container |
| 74 |
(true by default) or not - icon: the icon used for the visually |
| 75 |
distinguish the action (used by the corresponding QAction) |
| 76 |
|
| 77 |
.. note:: |
| 78 |
An Action has a corresponding QAction, see getQAction(), that |
| 79 |
makes it easy to trigger an action from any Qt GUI (menus, |
| 80 |
toolbar, push buttons...). You can also call your action |
| 81 |
programmatically from any other code. |
| 82 |
|
| 83 |
If the component class name is not empty, the action is using the |
| 84 |
currently selected components of the given type (class name). If the |
| 85 |
component class name is empty, the action does not need any input. |
| 86 |
|
| 87 |
## Using CamiTK extension file |
| 88 |
|
| 89 |
Using CamiTK extension file simplifies the creation and modification |
| 90 |
of actions. When using a CamiTK extension file, the extension |
| 91 |
generator will generate a initial .cpp file that you just have to fill |
| 92 |
in with your source code. |
| 93 |
|
| 94 |
These are the five methods you need to consider for customization: - |
| 95 |
`init()` is called when the action is loaded by the extension manager |
| 96 |
(i.e., when the action is instantiated). This is where all instance |
| 97 |
wide initialization should be done - `process()` is called when the |
| 98 |
user presses the "Apply" button. This is the main code for the action, |
| 99 |
where things are done - `targetDefined()` is called when the target of |
| 100 |
the action are defined (i.e., when the action is triggered). It is |
| 101 |
generally used to update the action GUI - `parameterChanged()` is |
| 102 |
called when a parameter value has changed. Similarly to |
| 103 |
`targetDefined()` it can be used to update the action GUI - (optional) |
| 104 |
`getUI()` if the developer wants to have a custom GUI, this is where |
| 105 |
she/he should instantiate the corresponding widget(s) |
| 106 |
|
| 107 |
You can call refreshApplication() in order to force the viewers to |
| 108 |
refresh. |
| 109 |
|
| 110 |
## Action Parameters |
| 111 |
|
| 112 |
Action parameters are automatically created from the CamiTK extension |
| 113 |
files. Each parameter is defined as a Qt dynamic property. In your C++ |
| 114 |
code it is strongly recommended to use: - getParameterValue("My |
| 115 |
Parameter") to get the value as a QVariant (you can they use |
| 116 |
toString(), toBool(), toDouble()... depending on the type of "My |
| 117 |
Parameter") - setParameterValue("My Parameter", newValue) to set the |
| 118 |
value of a parameter programmatically (newValue must be a QVariant or |
| 119 |
of type that can be converted to a QVariant) - |
| 120 |
getParameterValueAsString("My Parameter") to get a string |
| 121 |
representation of the value of "My Parameter" |
| 122 |
|
| 123 |
## Default GUI, Custom GUI or no GUI? |
| 124 |
|
| 125 |
An Action generally is used to wrap an algorithm in CamiTK. If this |
| 126 |
algorithm has parameters, it is very easy to get these parameters |
| 127 |
accessible to the user through the ActionWidget. These parameters are |
| 128 |
in fact defined as Qt dynamic properties. |
| 129 |
|
| 130 |
The default widget is an instance of ActionWidget. If ActionWidget |
| 131 |
does not correspond to what you need, just declare your action as |
| 132 |
having a Custom Widget You will then need to create a new class |
| 133 |
inheriting from QWidget, or directly from ActionWidget. |
| 134 |
|
| 135 |
These are the use cases for using the default behaviour (i.e. an |
| 136 |
instance of ActionWidget): - your action has some parameters and you |
| 137 |
need the user to review the default or modify their values before the |
| 138 |
action is applied, - or your action has no parameters but you still |
| 139 |
want the user to be applied only if/when the user click on an apply |
| 140 |
button. |
| 141 |
|
| 142 |
ActionWidget should be good enough in most of the cases. The default |
| 143 |
widget contains a description, a reminder of the current target |
| 144 |
component names, and an ObjectController with an Apply/Revert buttons |
| 145 |
that allows you to edit/modify properties. Use |
| 146 |
setDefaultWidgetButtonVisibility() to change the visibility of the |
| 147 |
Apply/Revert buttons and setDefaultWidgetApplyButtonText() to change |
| 148 |
the apply button text. |
| 149 |
|
| 150 |
When an action has no GUI triggering the action will directly call |
| 151 |
process() |
| 152 |
|
| 153 |
.. note:: |
| 154 |
The recommended architecture is for the action widget to call the |
| 155 |
action's apply method. The widget should only manage user |
| 156 |
interaction. |
| 157 |
|
| 158 |
## Underlying triggering and applying an action mechanism |
| 159 |
|
| 160 |
Two steps have to be considered when using an action: - Step 1, |
| 161 |
trigger(): the action is either directly applied (if it does not have |
| 162 |
any GUI) or it's GUI is shown (using getWidget()) - Step 2, apply(): |
| 163 |
only the action algorithm is applied, i.e., the data are processed |
| 164 |
|
| 165 |
The targets can have changed between the time the action is first |
| 166 |
triggered and the time the action is applied. getWidget() is always |
| 167 |
called when the targets are updated. Therefore whenever getWidget() is |
| 168 |
called, you should make sure to update the the action GUI |
| 169 |
consequently. getTargets() is always updated in trigger() and |
| 170 |
available. |
| 171 |
|
| 172 |
.. note:: |
| 173 |
trigger() and apply() are public slots. They can be called either |
| 174 |
directly (classic C++ method invocation) or by connecting them to |
| 175 |
a QWidget signal. |
| 176 |
|
| 177 |
When an action is triggered (e.g., by right clicking in the context |
| 178 |
menu), the following algorithm applies, see trigger(): - 1. Prepare |
| 179 |
targetComponents (available with getTargets()): only select the |
| 180 |
compatible components from the selected components - 2. If the action |
| 181 |
is embedded, get the widget and show it in a parent/container (if |
| 182 |
parent is not specified, show it in the action viewer) - 3. If the |
| 183 |
action in not embedded, show it as a dialog - 4. If the action does |
| 184 |
not have any widget, directly call apply() |
| 185 |
|
| 186 |
This means that, if there is a widget, the action algorithm is |
| 187 |
controlled by the action widget, i.e. apply() is not called by |
| 188 |
trigger() but should be called by one of the action widget's button. |
| 189 |
|
| 190 |
If ActionWidget is not what your need, a typical getUI() method should |
| 191 |
use the lazy instantiation pattern to instantiate |
| 192 |
MyVerySpecialActionWidget the first time it is called, and call the |
| 193 |
MyVerySpecialActionWidget instance's updateTargets() method for any |
| 194 |
subsequent calls. Something like: |
| 195 |
|
| 196 |
``` |
| 197 |
QWidget *MyAction::getUI() { |
| 198 |
// build or update the widget |
| 199 |
if (!myWidget) |
| 200 |
myWidget = new MyVerySpecialActionWidget(this); |
| 201 |
else |
| 202 |
// MyVerySpecialActionWidget should have an update() method |
| 203 |
myWidget->update(); |
| 204 |
|
| 205 |
return myWidget; |
| 206 |
} |
| 207 |
``` |
| 208 |
|
| 209 |
But of course you can also use any kind of widget you like. |
| 210 |
ActionWidget is just defining a default widget for an action. If your |
| 211 |
action does not have any GUI/parameters, add a getWidget() and return |
| 212 |
nullptr. |
| 213 |
|
| 214 |
By default the properties/parameters are automatically updated when |
| 215 |
the user change the default widget, they are updated only when the |
| 216 |
user click on the apply button of the default widget. The |
| 217 |
setAutoUpdateProperties(true) to automatically called. Use |
| 218 |
parameterChanged() to perform some action when a parameter was changed |
| 219 |
byt the user. |
| 220 |
|
| 221 |
By default the action's widget is embedded. If you do not want to |
| 222 |
embed your action's widget, modify the "notEmbedded" parameter. When |
| 223 |
embedded, the parent widget has to be given at triggered time (i.e. |
| 224 |
getUI() is called during trigger). If there is no parent given for an |
| 225 |
embedded action, then the action is embedded in the ActionViewer by |
| 226 |
default. |
| 227 |
|
| 228 |
The method apply() must be implemented in your Action. |
| 229 |
|
| 230 |
.. note:: |
| 231 |
at any moment, the selected components on which the action needs |
| 232 |
to be applied are available by getTargets(). targetComponents is |
| 233 |
filtered so that it only contains compatible components (i.e., |
| 234 |
instances of getComponent()). |
| 235 |
|
| 236 |
.. note:: |
| 237 |
About registering your action in the history of the application. |
| 238 |
Consider registering your action within the application's history |
| 239 |
once applied. The history of action features a stack of processed |
| 240 |
action. The application's history of actions allows one to export |
| 241 |
the saved actions as an XML file for scripting or replaying it. To |
| 242 |
do so, implement the apply() method in your code, then launch the |
| 243 |
method applyAndRegister(), which simply wraps the apply() method |
| 244 |
with the preProcess() and postProcess() methods. You may also |
| 245 |
connect a SIGNAL to it, as the applyAndRegister() method is a Qt |
| 246 |
SLOT. |
| 247 |
|
| 248 |
## Creating a pipeline of actions |
| 249 |
|
| 250 |
A pipeline of actions is a state machine where each state stands for |
| 251 |
an action with inputs and output components. The transitions between |
| 252 |
the states are done by processing the state's action (i.e. by calling |
| 253 |
the corresponding action's apply() method). Interpreting an pipeline |
| 254 |
of action is simpler than simply executing the action since the user |
| 255 |
doesn't need to manually set the inputs and outputs of each action (it |
| 256 |
is done automatically). If you are willing to write such a pipeline, |
| 257 |
simply implements the apply() method of each of your action and called |
| 258 |
the applyInPipeline() (instead of simply apply()). The method |
| 259 |
applyInPipeline() performs some pre- and post-processing around the |
| 260 |
method apply(). It has to be used within a pipeline (a chain of |
| 261 |
actions) where setInputComponents() and getOutputComponents() are |
| 262 |
needed. preProcessInPipeline() only selects the right components, and |
| 263 |
postProcess() sets output components and record history. |
| 264 |
|
| 265 |
See also: |
| 266 |
RenderingOption For a simple example of an embedded action |
| 267 |
|
| 268 |
See also: |
| 269 |
RigidTransform For a simple example of a non-embedded action |
| 270 |
|
| 271 |
See also: |
| 272 |
ChangeColor For a simple example of an action with no widget (but |
| 273 |
with a GUI) |
| 274 |
""" |
| 275 |
class ApplyStatus: |
| 276 |
""" |
| 277 |
\\enum ApplyStatus describes what happened during the application of an |
| 278 |
algorithm (i.e. results of the apply method) |
| 279 |
|
| 280 |
Members: |
| 281 |
|
| 282 |
SUCCESS |
| 283 |
|
| 284 |
ERROR |
| 285 |
|
| 286 |
WARNING |
| 287 |
|
| 288 |
ABORTED |
| 289 |
|
| 290 |
TRIGGERED |
| 291 |
""" |
| 292 |
ABORTED: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.ABORTED: 3> |
| 293 |
ERROR: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.ERROR: 1> |
| 294 |
SUCCESS: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.SUCCESS: 0> |
| 295 |
TRIGGERED: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.TRIGGERED: 4> |
| 296 |
WARNING: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.WARNING: 2> |
| 297 |
__members__: typing.ClassVar[dict[str, Action.ApplyStatus]] # value = {'SUCCESS': <ApplyStatus.SUCCESS: 0>, 'ERROR': <ApplyStatus.ERROR: 1>, 'WARNING': <ApplyStatus.WARNING: 2>, 'ABORTED': <ApplyStatus.ABORTED: 3>, 'TRIGGERED': <ApplyStatus.TRIGGERED: 4>} |
| 298 |
def __eq__(self, other: typing.Any) -> bool: |
| 299 |
... |
| 300 |
def __getstate__(self) -> int: |
| 301 |
... |
| 302 |
def __hash__(self) -> int: |
| 303 |
... |
| 304 |
def __index__(self) -> int: |
| 305 |
... |
| 306 |
def __init__(self, value: int) -> None: |
| 307 |
... |
| 308 |
def __int__(self) -> int: |
| 309 |
... |
| 310 |
def __ne__(self, other: typing.Any) -> bool: |
| 311 |
... |
| 312 |
def __repr__(self) -> str: |
| 313 |
... |
| 314 |
def __setstate__(self, state: int) -> None: |
| 315 |
... |
| 316 |
def __str__(self) -> str: |
| 317 |
... |
| 318 |
@property |
| 319 |
def name(self) -> str: |
| 320 |
... |
| 321 |
@property |
| 322 |
def value(self) -> int: |
| 323 |
... |
| 324 |
ABORTED: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.ABORTED: 3> |
| 325 |
ERROR: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.ERROR: 1> |
| 326 |
SUCCESS: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.SUCCESS: 0> |
| 327 |
TRIGGERED: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.TRIGGERED: 4> |
| 328 |
WARNING: typing.ClassVar[Action.ApplyStatus] # value = <ApplyStatus.WARNING: 2> |
| 329 |
def addParameter(self, arg0: Property) -> None: |
| 330 |
""" |
| 331 |
Add a new parameter to the action, using the CamiTK property class. If |
| 332 |
the parameter already exist, it will just change its value. |
| 333 |
|
| 334 |
.. note:: |
| 335 |
The action takes ownership of the Property instance. |
| 336 |
|
| 337 |
Returns: |
| 338 |
false if the Qt Meta Object property was added by this method |
| 339 |
(otherwise the property was already defined and true is returned |
| 340 |
if it was successfully updated) |
| 341 |
""" |
| 342 |
def getName(self) -> str: |
| 343 |
""" |
| 344 |
get the name of the action |
| 345 |
""" |
| 346 |
def getOutputComponent(self) -> Component: |
| 347 |
""" |
| 348 |
Returns the top-level output Component of this Action, or None if there is no output. |
| 349 |
""" |
| 350 |
def getParameterValue(self, arg0: str) -> typing.Any: |
| 351 |
""" |
| 352 |
get the parameter QVariant (same as property(const char*)) but check |
| 353 |
if it exists first. If the parameter was not declared using |
| 354 |
addParameter, this methods prints an error message and returns an |
| 355 |
invalid QVariant |
| 356 |
""" |
| 357 |
def getProperty(self, arg0: str) -> Property: |
| 358 |
""" |
| 359 |
Get a Property given its name |
| 360 |
|
| 361 |
Parameter ``name``: |
| 362 |
the property name |
| 363 |
|
| 364 |
Returns: |
| 365 |
nullptr if the name does not match any property name |
| 366 |
|
| 367 |
See also: |
| 368 |
Property |
| 369 |
""" |
| 370 |
def getTargets(self) -> list[Component]: |
| 371 |
""" |
| 372 |
the currently selected and valid (regarding the component property) |
| 373 |
components, for which this action is called |
| 374 |
""" |
| 375 |
def refreshApplication(self) -> None: |
| 376 |
""" |
| 377 |
convenient method to call from the user code to refresh all the |
| 378 |
application This is equivalent to call Application::refresh() |
| 379 |
""" |
| 380 |
def saveState(self) -> None: |
| 381 |
""" |
| 382 |
Saves the current state of this Action, including its parameters. This will backup the current state of the __dict__ of the python object associated with the action |
| 383 |
""" |
| 384 |
def setApplyButtonText(self, arg0: str) -> None: |
| 385 |
""" |
| 386 |
modify the "Apply" button text |
| 387 |
""" |
| 388 |
def setInputComponent(self, arg0: Component) -> None: |
| 389 |
""" |
| 390 |
Assigns the given Component as input to this Action. Note that the Action's widget is also initialized upon this call. |
| 391 |
""" |
| 392 |
def setParameterValue(self, arg0: str, arg1: typing.Any) -> bool: |
| 393 |
""" |
| 394 |
set the parameter QVariant value (same as setProperty(const char*, |
| 395 |
newValue)) but check if it exists first. If the parameter was not |
| 396 |
declared using addParameter, this methods prints an error message and |
| 397 |
returns false |
| 398 |
""" |
| 399 |
def updateWidget(self) -> None: |
| 400 |
""" |
| 401 |
Updates the Action's default widget, if any. |
| 402 |
""" |
| 403 |
class Application: |
| 404 |
""" |
| 405 |
The generic/default application. Once this class is instantiated in |
| 406 |
the main, everything is setup. The constructor can take the command |
| 407 |
line arguments. It can also be asked not to load the extensions |
| 408 |
automatically,see Application(). |
| 409 |
|
| 410 |
If you do not have a specific MainWindow extension, then the default |
| 411 |
CamiTK MainWindow is used, see setMainWindow(). |
| 412 |
|
| 413 |
This class manages all application-level instances, structures and |
| 414 |
all. This explains the number of _static_ methods in this class. |
| 415 |
|
| 416 |
It manages: - the registered/loaded action extensions and all the |
| 417 |
actions - the registered/loaded component extensions and all the |
| 418 |
component instances - the registered/loaded viewer extensions and all |
| 419 |
the viewer instances - the refresh mechanism - the current selection |
| 420 |
(selected components) - the recently opened documents - the |
| 421 |
application language/internationalization settings - the |
| 422 |
opening/closing/saving of components - the main window - the history |
| 423 |
of applied actions (including saving it as a CamitK SCXML document) - |
| 424 |
some application level settings |
| 425 |
""" |
| 426 |
@staticmethod |
| 427 |
@typing.overload |
| 428 |
def applyAction(arg0: str) -> Component: |
| 429 |
""" |
| 430 |
Applies the action of the given name and returns the top-level output Component created by it if any or None if there is no output component. The given action must require no input component |
| 431 |
""" |
| 432 |
@staticmethod |
| 433 |
@typing.overload |
| 434 |
def applyAction(arg0: str, arg1: Component) -> Component: |
| 435 |
""" |
| 436 |
Applies the action of the given name that takes the given component as input and returns the top-level output Component created by it if any or None if there is no output component. The given action must require one and only one input component |
| 437 |
""" |
| 438 |
@staticmethod |
| 439 |
@typing.overload |
| 440 |
def applyAction(arg0: str, arg1: list[Component]) -> Component: |
| 441 |
""" |
| 442 |
Applies the action of the given name that takes the given list of components as input and returns the top-level output Component created by it if any or None if there is no output component. The given action must require a list of input components |
| 443 |
""" |
| 444 |
@staticmethod |
| 445 |
def close(arg0: Component, arg1: bool) -> None: |
| 446 |
""" |
| 447 |
Close a Component: if it has been changed, ask the user for more |
| 448 |
information, then if everything is ok, delete it. |
| 449 |
|
| 450 |
Parameter ``component``: |
| 451 |
the Component to close. |
| 452 |
|
| 453 |
Parameter ``blockRefresh``: |
| 454 |
do not refresh the main window after closing the component |
| 455 |
|
| 456 |
Returns: |
| 457 |
true if the closing was made, false if the user cancelled the |
| 458 |
operation or a saving problem occurs |
| 459 |
""" |
| 460 |
@staticmethod |
| 461 |
def closeAll() -> bool: |
| 462 |
""" |
| 463 |
Closes all opened Components, prompting the user to save modified ones. |
| 464 |
This method uses the 'Close All' Action to close all opened Components. |
| 465 |
""" |
| 466 |
@staticmethod |
| 467 |
def connectViewerSelectionChanged(viewerName: str, callback: typing.Callable) -> bool: |
| 468 |
""" |
| 469 |
Connects a Python callback to a Viewer's selectionChanged() signal by name (if not already connected). |
| 470 |
""" |
| 471 |
@staticmethod |
| 472 |
def disconnectViewerSelectionChanged(viewerName: str, callback: typing.Callable) -> bool: |
| 473 |
""" |
| 474 |
Disconnects a Python callback from a Viewer's selectionChanged() signal by name (if already connected). |
| 475 |
""" |
| 476 |
@staticmethod |
| 477 |
def getAction(arg0: str) -> Action: |
| 478 |
""" |
| 479 |
get a registered action given its name |
| 480 |
""" |
| 481 |
@staticmethod |
| 482 |
def getActions() -> list[Action]: |
| 483 |
""" |
| 484 |
get all the actions registered in the application (note: the returned |
| 485 |
ActionList is guaranteed to be sorted by action name and to contain no |
| 486 |
duplicates) |
| 487 |
""" |
| 488 |
@staticmethod |
| 489 |
def getTopLevelComponents() -> list[Component]: |
| 490 |
""" |
| 491 |
get the current application wide list of instantiated top-level |
| 492 |
Components. This is the public method (return a const, the top-level |
| 493 |
component list is private and cannot be modified externally). |
| 494 |
""" |
| 495 |
@staticmethod |
| 496 |
@typing.overload |
| 497 |
def isAlive(component: Component) -> bool: |
| 498 |
""" |
| 499 |
does this Component still exist? (components can be deleted) |
| 500 |
""" |
| 501 |
@staticmethod |
| 502 |
@typing.overload |
| 503 |
def isAlive(action: Action) -> bool: |
| 504 |
""" |
| 505 |
does this Action still exist? (HotPlugAction can be unloaded) |
| 506 |
""" |
| 507 |
@staticmethod |
| 508 |
def open(fileName: str, blockRefresh: bool = False) -> Component: |
| 509 |
""" |
| 510 |
load the filename and returns the corresponding top level Component |
| 511 |
(returns nullptr if an error occurs) |
| 512 |
|
| 513 |
.. note:: |
| 514 |
this method opens the filename and created the associated TOP |
| 515 |
LEVEL component If you wish to open a subcomponent (not top level |
| 516 |
then), prefer directly calling its public constructor. |
| 517 |
|
| 518 |
Parameter ``fileName``: |
| 519 |
file that contains the component |
| 520 |
|
| 521 |
Parameter ``blockRefresh``: |
| 522 |
do not refresh the main window after closing the component |
| 523 |
""" |
| 524 |
@staticmethod |
| 525 |
def save(arg0: Component) -> None: |
| 526 |
""" |
| 527 |
save a component to its file (as given by component->getFileName()). |
| 528 |
|
| 529 |
.. note:: |
| 530 |
the component's file name has to be set prior to call this method. |
| 531 |
|
| 532 |
This method look for the proper loaded ComponentExtension, and call |
| 533 |
its save(Component*) method |
| 534 |
""" |
| 535 |
@staticmethod |
| 536 |
def saveAs(arg0: Component) -> None: |
| 537 |
""" |
| 538 |
Saves the given Component by prompting the user for a file name. |
| 539 |
This method uses the 'Save As' Action to save the given Component, which will prompt the user for a file name. |
| 540 |
""" |
| 541 |
@staticmethod |
| 542 |
def update3DClippingPlanes() -> None: |
| 543 |
""" |
| 544 |
Updates the clipping planes of the default 3D Viewer. |
| 545 |
This might be required when the working space volume changes rapidly, for instance in navigation system where the tracker moves some mesh in real 3D space or for RV application). |
| 546 |
""" |
| 547 |
class Component(InterfaceProperty, InterfaceNode, InterfaceGeometry, InterfaceBitMap, InterfaceFrame, InterfacePersistence): |
| 548 |
""" |
| 549 |
A Component represents something that could be included in the |
| 550 |
explorer view, the interactive 3D viewer, and that could have or not a |
| 551 |
contextual popup menu (open by a right click in the explorer), a |
| 552 |
property dialog (to change some properties) Thus, a Component inherits |
| 553 |
from many abstract classes. A Component can only have one implemented |
| 554 |
representation. |
| 555 |
|
| 556 |
For CAMITK core developers: This class uses the Object Adapter Design |
| 557 |
Pattern (aka delegate pattern) to delegates all InterfaceGeometry and |
| 558 |
InterfaceBitMap to respectively myGeometry:Geometry and |
| 559 |
mySlice:InterfaceBitMap It handles the InterfaceNode without |
| 560 |
delegation. Considering this Design Pattern, Component is the Adaptor |
| 561 |
and Geometry and InterfaceBitMap are the Adaptee classes. |
| 562 |
|
| 563 |
This class has some static member to manage all the currently |
| 564 |
instantiated Components as well as the currently selected Components. |
| 565 |
|
| 566 |
Actions generally use setPointSet() (for InterfaceGeometry) and |
| 567 |
setOriginalVolume (for InterfaceBitMap) to do some data processing and |
| 568 |
directly modify the low-level Vtk data. It is thus very **important** |
| 569 |
to rewrite these methods in your Component subclass to takes the |
| 570 |
actions' modification into account in your low-level data. |
| 571 |
|
| 572 |
Dynamic properties: if your Component defines some dynamic properties, |
| 573 |
you might want to override propertyValueChanged() in order to update |
| 574 |
the internal state of your object when a dynamic property's value has |
| 575 |
been changed. |
| 576 |
|
| 577 |
See also: |
| 578 |
ObjComponent for a good example |
| 579 |
|
| 580 |
It extensively uses Qt Meta-Object system (concepts and |
| 581 |
implementation). see http://doc.qt.nokia.com/latest/metaobjects.html |
| 582 |
""" |
| 583 |
def __init__(self, arg0: str, arg1: str) -> None: |
| 584 |
""" |
| 585 |
Component constructor for top-level component (please use the other |
| 586 |
constructor for sub-level components). parentComponent is set to |
| 587 |
nullptr (=> isTopLevel() will return true). |
| 588 |
|
| 589 |
Parameter ``file``: |
| 590 |
the file to get the data from |
| 591 |
|
| 592 |
Parameter ``name``: |
| 593 |
the Component name |
| 594 |
|
| 595 |
Parameter ``rep``: |
| 596 |
the representation concretely implemented by this Component |
| 597 |
(default=NO_REPRESENTATION) |
| 598 |
|
| 599 |
Parameter ``createDefaultFrame``: |
| 600 |
Whether the component should create its frame (should be set to |
| 601 |
false only if the frame is created/set in another way) |
| 602 |
""" |
| 603 |
def addChild(self, arg0: InterfaceNode) -> None: |
| 604 |
""" |
| 605 |
add a child Component (sub item in the hierarchy), and modify the |
| 606 |
child's parent to be equal to this instance |
| 607 |
|
| 608 |
This is to be used with care. The preferred method to add a child |
| 609 |
component is to use the Component's constructor with the parent |
| 610 |
parameter: Component(Component *, const QString &, Representation rep) |
| 611 |
. |
| 612 |
|
| 613 |
See also: |
| 614 |
attachChild() |
| 615 |
""" |
| 616 |
def getChildren(self) -> list[Component]: |
| 617 |
""" |
| 618 |
get the list of the InterfaceNode children (sub items in the |
| 619 |
hierarchy) |
| 620 |
""" |
| 621 |
def getFileName(self) -> str: |
| 622 |
""" |
| 623 |
get the file name where the data have to be stored/were stored |
| 624 |
""" |
| 625 |
def getFrame(self) -> ...: |
| 626 |
""" |
| 627 |
Get the pointer to this object's FrameOfReference. \\note Please use |
| 628 |
TransformationManager::getFrameOfReferenceOwnership(FrameOfReference*) |
| 629 |
""" |
| 630 |
def getName(self) -> str: |
| 631 |
""" |
| 632 |
get the name to be displayed |
| 633 |
""" |
| 634 |
def getParent(self) -> InterfaceNode: |
| 635 |
""" |
| 636 |
get the parent Component |
| 637 |
""" |
| 638 |
def getPropertyValue(self, arg0: str) -> typing.Any: |
| 639 |
""" |
| 640 |
get the property QVariant (same as property(const char*)) but check if |
| 641 |
it exists first. If the property was not declared using addProperty, |
| 642 |
this methods prints an error message and returns an invalid QVariant |
| 643 |
""" |
| 644 |
def isSelected(self) -> bool: |
| 645 |
""" |
| 646 |
Check if this data component is selected |
| 647 |
""" |
| 648 |
def isTopLevel(self) -> bool: |
| 649 |
""" |
| 650 |
return true if this component is a top-level component |
| 651 |
""" |
| 652 |
def refresh(self) -> None: |
| 653 |
""" |
| 654 |
refresh all the viewer that are currently displaying this Component At |
| 655 |
the end the InterfaceNode modification flag is reset. |
| 656 |
""" |
| 657 |
def setFrame(self, arg0: ...) -> None: |
| 658 |
""" |
| 659 |
Set the FrameOfReference of this object. Note that this methods will |
| 660 |
take ownership of the given frame thanks to the shared_ptr. |
| 661 |
""" |
| 662 |
def setFrameFrom(self, arg0: InterfaceFrame) -> None: |
| 663 |
""" |
| 664 |
Modify this object's frame using the given object's frame. |
| 665 |
|
| 666 |
.. note:: |
| 667 |
you can reimplement this method if you need to manage more than |
| 668 |
this frame of reference ( |
| 669 |
|
| 670 |
See also: |
| 671 |
ImageComponent::setFrameFrom()) |
| 672 |
""" |
| 673 |
def setModified(self, arg0: bool) -> None: |
| 674 |
""" |
| 675 |
set the modified flag |
| 676 |
""" |
| 677 |
def setName(self, arg0: str) -> None: |
| 678 |
""" |
| 679 |
set the name to be displayed |
| 680 |
""" |
| 681 |
def setPropertyValue(self, arg0: str, arg1: typing.Any) -> bool: |
| 682 |
""" |
| 683 |
set the property QVariant value (same as setProperty(const char*, |
| 684 |
newValue)) but check if it exists first. If the property was not |
| 685 |
declared using addProperty, this methods prints an error message and |
| 686 |
returns false |
| 687 |
""" |
| 688 |
def setSelected(self, b: bool, recursive: bool = True) -> None: |
| 689 |
""" |
| 690 |
Update the selection flag. |
| 691 |
|
| 692 |
Parameter ``b``: |
| 693 |
the value of the flag (true means "is selected") |
| 694 |
|
| 695 |
Parameter ``recursive``: |
| 696 |
if true (default), also updates the children Component selection |
| 697 |
flags. |
| 698 |
""" |
| 699 |
class ComponentExtension: |
| 700 |
""" |
| 701 |
This class describes what is a generic Component extension. To add a |
| 702 |
ComponentExtension to CamiTK core, write a new class that inherits |
| 703 |
from this class. |
| 704 |
|
| 705 |
There are two types of component extension: the classical one manages |
| 706 |
(mime type) file extension, the other one manages all files in a given |
| 707 |
directory (e.g. Dicom images). For the latter you have to redefine |
| 708 |
hasDataDirectory(). |
| 709 |
|
| 710 |
The following methods HAVE to be redefined in your subclass: - getName |
| 711 |
- getDescription - getFileExtensions - open |
| 712 |
|
| 713 |
The following methods can be redefined: - save: saving from a |
| 714 |
Component to one of the managed format - hasDataDirectory: for |
| 715 |
directory type extension |
| 716 |
""" |
| 717 |
def __init__(self) -> None: |
| 718 |
""" |
| 719 |
protected constructor, \\note never directly instantiate a |
| 720 |
ComponentExtension, use loadExtension(...) instead! |
| 721 |
""" |
| 722 |
def getDescription(self) -> str: |
| 723 |
""" |
| 724 |
get the plugin description |
| 725 |
""" |
| 726 |
def getFileExtensions(self) -> list[str]: |
| 727 |
""" |
| 728 |
get the list of managed extensions (each file with an extension in the |
| 729 |
list can be loaded by this Component) |
| 730 |
""" |
| 731 |
def getName(self) -> str: |
| 732 |
""" |
| 733 |
@name ComponentExtension plugin interface methods @{ get the plugin |
| 734 |
name |
| 735 |
""" |
| 736 |
def hasDataDirectory(self) -> bool: |
| 737 |
""" |
| 738 |
return true if this component manages directory instead of individual |
| 739 |
files (e.g. Dicom series are stored in directories, not files) |
| 740 |
""" |
| 741 |
def open(self, arg0: str) -> Component: |
| 742 |
""" |
| 743 |
get a new instance from data stored in a file (this is the most |
| 744 |
important method to redefine in your subclass) |
| 745 |
|
| 746 |
This method may throw an AbortException if a problem occurs. |
| 747 |
|
| 748 |
.. note:: |
| 749 |
The parameter is a filename with an absolute path (from Qt's |
| 750 |
QFileInfo::absoluteFilePath method): On Unix (including Mac OS) |
| 751 |
this will always begin with the root, '/', directory. On Windows |
| 752 |
this will always begin 'D:/' where D is a drive letter, except for |
| 753 |
network shares that are not mapped to a drive letter, in which |
| 754 |
case the path will begin '//sharename/' |
| 755 |
""" |
| 756 |
def save(self, arg0: Component) -> bool: |
| 757 |
""" |
| 758 |
save a given Component (does not have to be top-level) into one of the |
| 759 |
currently managed format (check the component |
| 760 |
QFileInfo(component->getFileName()).completeSuffix(). |
| 761 |
|
| 762 |
Redefine this method to extract all needed data/information from the |
| 763 |
Geometry or BitMap representation in order to export a given component |
| 764 |
to one of the file extension managed by this component extension. |
| 765 |
|
| 766 |
.. note:: |
| 767 |
this will enable to export to one of the managed filename |
| 768 |
extension at the CamiTK level (i.e. if you write this method, any |
| 769 |
compatible component can be saved to your managed format! |
| 770 |
|
| 771 |
.. note:: |
| 772 |
this method is called by CamiTK only if the filename extension is |
| 773 |
managed by this component extension. There should be no need to |
| 774 |
check it in the method. |
| 775 |
|
| 776 |
The default behaviour is a "not implemented yet" message box. |
| 777 |
|
| 778 |
Returns: |
| 779 |
false if the operation was not performed properly or not performed |
| 780 |
at all. |
| 781 |
""" |
| 782 |
class Core: |
| 783 |
@staticmethod |
| 784 |
def getConfig() -> str: |
| 785 |
... |
| 786 |
@staticmethod |
| 787 |
def getPaths() -> str: |
| 788 |
... |
| 789 |
@staticmethod |
| 790 |
def getTestDataDir() -> str: |
| 791 |
... |
| 792 |
@staticmethod |
| 793 |
def shortVersion() -> str: |
| 794 |
... |
| 795 |
@staticmethod |
| 796 |
def version() -> str: |
| 797 |
... |
| 798 |
class ExtensionManager: |
| 799 |
""" |
| 800 |
This class is used to manage all plugins loaded by the application. |
| 801 |
|
| 802 |
The current version is able to load dynamic library for - |
| 803 |
ComponentExtension - ActionExtension |
| 804 |
|
| 805 |
This class is a contained for all the loaded extension. It contains |
| 806 |
only static members. |
| 807 |
""" |
| 808 |
@staticmethod |
| 809 |
def getDataDirectoryExtNames() -> list[str]: |
| 810 |
""" |
| 811 |
get the list of all the name of the registered Component data |
| 812 |
directory |
| 813 |
""" |
| 814 |
@staticmethod |
| 815 |
def getFileExtensions() -> list[str]: |
| 816 |
""" |
| 817 |
get the list of all the suffixes managed by registered component |
| 818 |
extensions (all possible file suffix) |
| 819 |
""" |
| 820 |
@staticmethod |
| 821 |
def registerNewComponentExtension(arg0: ..., arg1: str) -> bool: |
| 822 |
""" |
| 823 |
Register the given ComponentExtension. If the given ComponentExtension |
| 824 |
is managing file extensions that are already registered, it will not |
| 825 |
be registered, and this method will return false and a info message |
| 826 |
will be printed with more information. |
| 827 |
|
| 828 |
Parameter ``ce``: |
| 829 |
valid ComponentExtension pointer (loaded from a shared library |
| 830 |
plugin (.dll/.so/.dylib) or instantiated programmatically) |
| 831 |
|
| 832 |
Parameter ``filename``: |
| 833 |
(optional) if the extension was loaded from a shared library |
| 834 |
(.dll/.so/.dylib), path to this file |
| 835 |
|
| 836 |
Returns: |
| 837 |
true if the extension was registered without error |
| 838 |
""" |
| 839 |
class FrameOfReference: |
| 840 |
""" |
| 841 |
FrameOfReference is only a label for an abstract coordinate system. It |
| 842 |
is used as origins and destinations of transformations. |
| 843 |
|
| 844 |
There is no information stored in a FrameOfReference except - an ID, - |
| 845 |
a name and description - a number of dimensions (between 1 and 5, |
| 846 |
default is 3) and units ("mm" for the first 3 dimensions) - a |
| 847 |
AnatomicalOrientation that can describe whether there is a known |
| 848 |
anatomical orientation associated to each axis ( |
| 849 |
|
| 850 |
See also: |
| 851 |
AnatomicalOrientation) - a color (used in the transformation graph |
| 852 |
visualisation) |
| 853 |
|
| 854 |
All constructors are protected, use TransformationManager to create a |
| 855 |
new instance. |
| 856 |
|
| 857 |
See also: |
| 858 |
Transformation, TransformationManager, AnatomicalOrientation |
| 859 |
""" |
| 860 |
def getName(self) -> str: |
| 861 |
""" |
| 862 |
Get the FrameOfReference name |
| 863 |
""" |
| 864 |
def getUuid(self) -> QUuid: |
| 865 |
""" |
| 866 |
Get the unique identifier of the Frame |
| 867 |
""" |
| 868 |
class HotPlugAction(Action): |
| 869 |
""" |
| 870 |
An Action that can be created on the fly |
| 871 |
""" |
| 872 |
class ImageComponent(Component): |
| 873 |
""" |
| 874 |
The manager of the Image Volume data. An image volume data has no |
| 875 |
concrete 3D representation, as its representation is provided by its |
| 876 |
sub-components (axial, sagittal, coronal and arbitrary slices as well |
| 877 |
as volume rendering). |
| 878 |
|
| 879 |
It builds a complete/ready-to-use VTK pipeline: |
| 880 |
|
| 881 |
See also: |
| 882 |
Slice |
| 883 |
|
| 884 |
.. note:: |
| 885 |
You can use the following properties to change the visualization |
| 886 |
of an ImageComponent and children components: - "Display Image in |
| 887 |
3D Viewer" type boolean, controls what is displayed in the default |
| 888 |
3D viewer |
| 889 |
|
| 890 |
Every time a property is changed using setProperty(QString |
| 891 |
propertyName, QVariant value), the ImageComponent will automatically |
| 892 |
update, thanks to the propertyValueChanged(..) method. |
| 893 |
""" |
| 894 |
def __init__(self, arg0: str, arg1: str) -> None: |
| 895 |
""" |
| 896 |
Creates an ImageComponent from a file. This method is called from a |
| 897 |
ComponentExtension derived class that support the given file format. |
| 898 |
|
| 899 |
This method may throw an AbortException if a problem occurs. |
| 900 |
|
| 901 |
Parameter ``file``: |
| 902 |
the complete path to the image file |
| 903 |
|
| 904 |
Parameter ``name``: |
| 905 |
name to be given to the Component (this name will appear in the |
| 906 |
explorer) |
| 907 |
""" |
| 908 |
def clone(self) -> ImageComponent: |
| 909 |
""" |
| 910 |
Clone this original image. Note that the image data is not copied, only referenced from the clone, and that the frame of the clone is set to the original image component's frame. |
| 911 |
""" |
| 912 |
def getArbitrarySliceFrame(self) -> ...: |
| 913 |
""" |
| 914 |
Returns the FrameOfReference used for the arbitrary slice. |
| 915 |
""" |
| 916 |
def getDataFrame(self) -> ...: |
| 917 |
""" |
| 918 |
get the data FrameOfReference (i.e., the vtkImageData frame) |
| 919 |
""" |
| 920 |
def getDimensions(self) -> tuple: |
| 921 |
""" |
| 922 |
Returns the image dimensions as a tuple of 3 integers (dimX, dimY, dimZ). |
| 923 |
""" |
| 924 |
def getImageDataAsNumpy(self) -> numpy.ndarray: |
| 925 |
""" |
| 926 |
Returns the image data as a numpy ndarray. |
| 927 |
""" |
| 928 |
def getLastPixelPicked(self) -> tuple: |
| 929 |
""" |
| 930 |
Get the last pixel picked using CTRL + LEFT/RIGHT CLICK in voxel index |
| 931 |
(i, j, k) indicates the voxel index (no notion of voxel size) |
| 932 |
""" |
| 933 |
def getLastPointPickedDataFrame(self) -> tuple: |
| 934 |
""" |
| 935 |
Get the last point picked using CTRL + LEFT/RIGHT CLICK in the data |
| 936 |
frame coordinates (this takes into account voxel size) |
| 937 |
""" |
| 938 |
def getLastPointPickedWorldFrame(self) -> tuple: |
| 939 |
""" |
| 940 |
Get Get the last point picked using CTRL + LEFT/RIGHT CLICK in the |
| 941 |
world coordinates This takes into account voxel size and image origin |
| 942 |
(and possible image rigid transforms). |
| 943 |
""" |
| 944 |
def getSpacing(self) -> numpy.ndarray: |
| 945 |
""" |
| 946 |
Returns the image spacing as a tuple of 3 floats (spacingX, spacingY, spacingZ). |
| 947 |
""" |
| 948 |
def replaceImageData(self, arg0: numpy.ndarray) -> None: |
| 949 |
""" |
| 950 |
Replaces the image data with the given numpy ndarray. |
| 951 |
""" |
| 952 |
class InterfaceBitMap: |
| 953 |
""" |
| 954 |
This class describes what are the methods to implement for a BitMap. |
| 955 |
An InterfaceBitMap is a kind of simplifier/wrapper for vtkImageData. |
| 956 |
|
| 957 |
This class defines an "interface" (in the OOP/java meaning of the |
| 958 |
term). See the introduction of GoF: "Program to an interface, not an |
| 959 |
implementation." To see what Erich Gamma has to say about it: |
| 960 |
http://www.artima.com/lejava/articles/designprinciplesP.html To see |
| 961 |
what Bjarne Stroustrup has to say about it: |
| 962 |
http://www.artima.com/intv/modern.html |
| 963 |
|
| 964 |
See also: |
| 965 |
Slice |
| 966 |
""" |
| 967 |
class InterfaceFrame: |
| 968 |
""" |
| 969 |
This class describes the methods to implement in order to manage a |
| 970 |
Component position in space. |
| 971 |
|
| 972 |
Each Component has a frame of reference which is used to define its |
| 973 |
relation to other objects. You can define new frames and |
| 974 |
transformations between frames as required, but all FrameOfReference |
| 975 |
and Transformation objects must be managed by the |
| 976 |
TransformationManager. |
| 977 |
|
| 978 |
See also: |
| 979 |
TransformationManager |
| 980 |
""" |
| 981 |
class InterfaceGeometry: |
| 982 |
""" |
| 983 |
This class describes what are the methods to implement for a Geometry |
| 984 |
(rendering parameters, input/output, filters, picking parameters...) |
| 985 |
|
| 986 |
An InterfaceGeometry is a kind of simplifier/wrapper for vtkPointSet. |
| 987 |
|
| 988 |
This class defines an "interface" (in the OOP/java meaning of the |
| 989 |
term). See the introduction of GoF: "Program to an interface, not an |
| 990 |
implementation." To see what Erich Gamma has to say about it: |
| 991 |
http://www.artima.com/lejava/articles/designprinciplesP.html To see |
| 992 |
what Bjarne Stroustrup has to say about it: |
| 993 |
http://www.artima.com/intv/modern.html |
| 994 |
|
| 995 |
See also: |
| 996 |
Geometry |
| 997 |
""" |
| 998 |
class RenderingMode: |
| 999 |
""" |
| 1000 |
@enum RenderingMode (and QFlags RenderingModes) handle actor rendering |
| 1001 |
options (render this InterfaceGeometry as a surface, a wireframe and |
| 1002 |
set of points). |
| 1003 |
|
| 1004 |
Members: |
| 1005 |
|
| 1006 |
NoRenderingMode |
| 1007 |
|
| 1008 |
Surface |
| 1009 |
|
| 1010 |
Wireframe |
| 1011 |
|
| 1012 |
Points |
| 1013 |
""" |
| 1014 |
NoRenderingMode: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.NoRenderingMode: 0> |
| 1015 |
Points: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.Points: 4> |
| 1016 |
Surface: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.Surface: 1> |
| 1017 |
Wireframe: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.Wireframe: 2> |
| 1018 |
__members__: typing.ClassVar[dict[str, InterfaceGeometry.RenderingMode]] # value = {'NoRenderingMode': <RenderingMode.NoRenderingMode: 0>, 'Surface': <RenderingMode.Surface: 1>, 'Wireframe': <RenderingMode.Wireframe: 2>, 'Points': <RenderingMode.Points: 4>} |
| 1019 |
def __and__(self, other: typing.Any) -> typing.Any: |
| 1020 |
... |
| 1021 |
def __eq__(self, other: typing.Any) -> bool: |
| 1022 |
... |
| 1023 |
def __ge__(self, other: typing.Any) -> bool: |
| 1024 |
... |
| 1025 |
def __getstate__(self) -> int: |
| 1026 |
... |
| 1027 |
def __gt__(self, other: typing.Any) -> bool: |
| 1028 |
... |
| 1029 |
def __hash__(self) -> int: |
| 1030 |
... |
| 1031 |
def __index__(self) -> int: |
| 1032 |
... |
| 1033 |
def __init__(self, value: int) -> None: |
| 1034 |
... |
| 1035 |
def __int__(self) -> int: |
| 1036 |
... |
| 1037 |
def __invert__(self) -> typing.Any: |
| 1038 |
... |
| 1039 |
def __le__(self, other: typing.Any) -> bool: |
| 1040 |
... |
| 1041 |
def __lt__(self, other: typing.Any) -> bool: |
| 1042 |
... |
| 1043 |
def __ne__(self, other: typing.Any) -> bool: |
| 1044 |
... |
| 1045 |
def __or__(self, other: typing.Any) -> typing.Any: |
| 1046 |
... |
| 1047 |
def __rand__(self, other: typing.Any) -> typing.Any: |
| 1048 |
... |
| 1049 |
def __repr__(self) -> str: |
| 1050 |
... |
| 1051 |
def __ror__(self, other: typing.Any) -> typing.Any: |
| 1052 |
... |
| 1053 |
def __rxor__(self, other: typing.Any) -> typing.Any: |
| 1054 |
... |
| 1055 |
def __setstate__(self, state: int) -> None: |
| 1056 |
... |
| 1057 |
def __str__(self) -> str: |
| 1058 |
... |
| 1059 |
def __xor__(self, other: typing.Any) -> typing.Any: |
| 1060 |
... |
| 1061 |
@property |
| 1062 |
def name(self) -> str: |
| 1063 |
... |
| 1064 |
@property |
| 1065 |
def value(self) -> int: |
| 1066 |
... |
| 1067 |
NoRenderingMode: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.NoRenderingMode: 0> |
| 1068 |
Points: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.Points: 4> |
| 1069 |
Surface: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.Surface: 1> |
| 1070 |
Wireframe: typing.ClassVar[InterfaceGeometry.RenderingMode] # value = <RenderingMode.Wireframe: 2> |
| 1071 |
class InterfaceNode: |
| 1072 |
""" |
| 1073 |
This class describe what are the methods to implement for a |
| 1074 |
hierarchical tree node. |
| 1075 |
|
| 1076 |
An InterfaceNode can only have one parent, even if it is a child of |
| 1077 |
more than one InterfaceNodes. |
| 1078 |
|
| 1079 |
Consequence: an InterfaceNode can be present many times in the |
| 1080 |
hierarchy, but can only depends from one parent. To add an |
| 1081 |
InterfaceNode as a child and change its parent to this use addChild(). |
| 1082 |
To add an InterfaceNode as a child without modifying its parent, use |
| 1083 |
attachChild(). |
| 1084 |
|
| 1085 |
This class defines an "interface" (in the OOP/java meaning of the |
| 1086 |
term). See the introduction of GoF: "Program to an interface, not an |
| 1087 |
implementation." To see what Erich Gamma has to say about it: |
| 1088 |
http://www.artima.com/lejava/articles/designprinciplesP.html To see |
| 1089 |
what Bjarne Stroustrup has to say about it: |
| 1090 |
http://www.artima.com/intv/modern.html |
| 1091 |
""" |
| 1092 |
class InterfacePersistence: |
| 1093 |
""" |
| 1094 |
Interface for all objects that should be serialized by the |
| 1095 |
PersistenceManager |
| 1096 |
""" |
| 1097 |
class InterfaceProperty: |
| 1098 |
""" |
| 1099 |
This class describes what are the methods to implement in order to |
| 1100 |
manage dynamic properties. InterfaceProperty is one of the interfaces |
| 1101 |
implemented by the camitk::Component "Component" class. |
| 1102 |
""" |
| 1103 |
class Log: |
| 1104 |
class LogLevel: |
| 1105 |
""" |
| 1106 |
Members: |
| 1107 |
|
| 1108 |
NONE |
| 1109 |
|
| 1110 |
ERROR |
| 1111 |
|
| 1112 |
WARNING |
| 1113 |
|
| 1114 |
INFO |
| 1115 |
|
| 1116 |
TRACE |
| 1117 |
""" |
| 1118 |
ERROR: typing.ClassVar[Log.LogLevel] # value = <LogLevel.ERROR: 1> |
| 1119 |
INFO: typing.ClassVar[Log.LogLevel] # value = <LogLevel.INFO: 3> |
| 1120 |
NONE: typing.ClassVar[Log.LogLevel] # value = <LogLevel.NONE: 0> |
| 1121 |
TRACE: typing.ClassVar[Log.LogLevel] # value = <LogLevel.TRACE: 4> |
| 1122 |
WARNING: typing.ClassVar[Log.LogLevel] # value = <LogLevel.WARNING: 2> |
| 1123 |
__members__: typing.ClassVar[dict[str, Log.LogLevel]] # value = {'NONE': <LogLevel.NONE: 0>, 'ERROR': <LogLevel.ERROR: 1>, 'WARNING': <LogLevel.WARNING: 2>, 'INFO': <LogLevel.INFO: 3>, 'TRACE': <LogLevel.TRACE: 4>} |
| 1124 |
def __eq__(self, other: typing.Any) -> bool: |
| 1125 |
... |
| 1126 |
def __getstate__(self) -> int: |
| 1127 |
... |
| 1128 |
def __hash__(self) -> int: |
| 1129 |
... |
| 1130 |
def __index__(self) -> int: |
| 1131 |
... |
| 1132 |
def __init__(self, value: int) -> None: |
| 1133 |
... |
| 1134 |
def __int__(self) -> int: |
| 1135 |
... |
| 1136 |
def __ne__(self, other: typing.Any) -> bool: |
| 1137 |
... |
| 1138 |
def __repr__(self) -> str: |
| 1139 |
... |
| 1140 |
def __setstate__(self, state: int) -> None: |
| 1141 |
... |
| 1142 |
def __str__(self) -> str: |
| 1143 |
... |
| 1144 |
@property |
| 1145 |
def name(self) -> str: |
| 1146 |
... |
| 1147 |
@property |
| 1148 |
def value(self) -> int: |
| 1149 |
... |
| 1150 |
ERROR: typing.ClassVar[Log.LogLevel] # value = <LogLevel.ERROR: 1> |
| 1151 |
INFO: typing.ClassVar[Log.LogLevel] # value = <LogLevel.INFO: 3> |
| 1152 |
NONE: typing.ClassVar[Log.LogLevel] # value = <LogLevel.NONE: 0> |
| 1153 |
TRACE: typing.ClassVar[Log.LogLevel] # value = <LogLevel.TRACE: 4> |
| 1154 |
WARNING: typing.ClassVar[Log.LogLevel] # value = <LogLevel.WARNING: 2> |
| 1155 |
def setDebugInformation(self: bool) -> None: |
| 1156 |
... |
| 1157 |
def setLogLevel(self: Log.LogLevel) -> None: |
| 1158 |
... |
| 1159 |
def setMessageBoxLevel(self: Log.LogLevel) -> None: |
| 1160 |
... |
| 1161 |
def setTimeStampInformation(self: bool) -> None: |
| 1162 |
... |
| 1163 |
class MeshComponent(Component): |
| 1164 |
""" |
| 1165 |
Basic component to manage any kind of mesh. |
| 1166 |
""" |
| 1167 |
class FieldType: |
| 1168 |
""" |
| 1169 |
@enum FieldType Data fields can be applied to one of this |
| 1170 |
|
| 1171 |
Members: |
| 1172 |
|
| 1173 |
POINTS |
| 1174 |
|
| 1175 |
CELLS |
| 1176 |
|
| 1177 |
MESH |
| 1178 |
""" |
| 1179 |
CELLS: typing.ClassVar[MeshComponent.FieldType] # value = <FieldType.CELLS: 2> |
| 1180 |
MESH: typing.ClassVar[MeshComponent.FieldType] # value = <FieldType.MESH: 4> |
| 1181 |
POINTS: typing.ClassVar[MeshComponent.FieldType] # value = <FieldType.POINTS: 1> |
| 1182 |
__members__: typing.ClassVar[dict[str, MeshComponent.FieldType]] # value = {'POINTS': <FieldType.POINTS: 1>, 'CELLS': <FieldType.CELLS: 2>, 'MESH': <FieldType.MESH: 4>} |
| 1183 |
def __eq__(self, other: typing.Any) -> bool: |
| 1184 |
... |
| 1185 |
def __getstate__(self) -> int: |
| 1186 |
... |
| 1187 |
def __hash__(self) -> int: |
| 1188 |
... |
| 1189 |
def __index__(self) -> int: |
| 1190 |
... |
| 1191 |
def __init__(self, value: int) -> None: |
| 1192 |
... |
| 1193 |
def __int__(self) -> int: |
| 1194 |
... |
| 1195 |
def __ne__(self, other: typing.Any) -> bool: |
| 1196 |
... |
| 1197 |
def __repr__(self) -> str: |
| 1198 |
... |
| 1199 |
def __setstate__(self, state: int) -> None: |
| 1200 |
... |
| 1201 |
def __str__(self) -> str: |
| 1202 |
... |
| 1203 |
@property |
| 1204 |
def name(self) -> str: |
| 1205 |
... |
| 1206 |
@property |
| 1207 |
def value(self) -> int: |
| 1208 |
... |
| 1209 |
CELLS: typing.ClassVar[MeshComponent.FieldType] # value = <FieldType.CELLS: 2> |
| 1210 |
MESH: typing.ClassVar[MeshComponent.FieldType] # value = <FieldType.MESH: 4> |
| 1211 |
POINTS: typing.ClassVar[MeshComponent.FieldType] # value = <FieldType.POINTS: 1> |
| 1212 |
def addCellData(self, arg0: str, arg1: numpy.ndarray) -> None: |
| 1213 |
""" |
| 1214 |
Adds a cell data array using the given numpy ndarray. |
| 1215 |
""" |
| 1216 |
def addDataArray(self, arg0: MeshComponent.FieldType, arg1: str, arg2: numpy.ndarray) -> None: |
| 1217 |
""" |
| 1218 |
Add a data array using the given a numpy ndarray. |
| 1219 |
""" |
| 1220 |
def addPointData(self, arg0: str, arg1: numpy.ndarray) -> None: |
| 1221 |
""" |
| 1222 |
Adds a point data array using the given numpy ndarray. |
| 1223 |
""" |
| 1224 |
def clone(self) -> MeshComponent: |
| 1225 |
""" |
| 1226 |
Clone this original mesh. Note that the point set is not copied, only referenced from the clone, and that the frame of the clone is set to the original mesh component's frame. |
| 1227 |
""" |
| 1228 |
def getColor(self) -> tuple[float, ...] | list[float]: |
| 1229 |
""" |
| 1230 |
Get the color of given representation modes in the second parameter. |
| 1231 |
|
| 1232 |
Parameter ``color``: |
| 1233 |
the 4-sized double tab of color (r,g,b,a) of the actor. |
| 1234 |
|
| 1235 |
Parameter ``ignoreEnhancedModes``: |
| 1236 |
Return the color without considering the changes that may be due |
| 1237 |
to enhanced modes (highlight) @warning color must points a 4 |
| 1238 |
double-sized tab minimum. |
| 1239 |
""" |
| 1240 |
def getDataArray(self, arg0: MeshComponent.FieldType, arg1: int) -> numpy.ndarray: |
| 1241 |
""" |
| 1242 |
Get the data array of specified field type and index as a numpy ndarray. |
| 1243 |
""" |
| 1244 |
def getNumberOfDataArray(self, arg0: int) -> int: |
| 1245 |
""" |
| 1246 |
Get the number of data arrays of a given type without taking the |
| 1247 |
specific representation into account. |
| 1248 |
|
| 1249 |
This method does not take into account: - the field arrays - the |
| 1250 |
specific representation of 3D data (i.e., representation of 3D data as |
| 1251 |
norm or component#i values) |
| 1252 |
|
| 1253 |
Parameter ``fieldFlag``: |
| 1254 |
is a FieldType or a combinaison of field types. |
| 1255 |
|
| 1256 |
Returns: |
| 1257 |
the number of arrays corresponding to the field flag |
| 1258 |
""" |
| 1259 |
def getPickedCellId(self) -> int: |
| 1260 |
""" |
| 1261 |
get the last pick point id, |
| 1262 |
|
| 1263 |
Returns: |
| 1264 |
-1 if no point where picked |
| 1265 |
""" |
| 1266 |
def getPickedPointId(self) -> int: |
| 1267 |
""" |
| 1268 |
get the last pick point id, |
| 1269 |
|
| 1270 |
Returns: |
| 1271 |
-1 if no point where picked |
| 1272 |
""" |
| 1273 |
def getPickedPointPosition(self) -> tuple: |
| 1274 |
""" |
| 1275 |
Returns the position of the picked point as a tuple of 3 floats (x, y, z) in this mesh component frame. If no point is picked, returns (0.0, 0.0, 0.0). |
| 1276 |
""" |
| 1277 |
def getPointSetAsNumpy(self) -> numpy.ndarray: |
| 1278 |
""" |
| 1279 |
Returns the point set as a numpy ndarray of shape (N, 3) where N is the number of points. |
| 1280 |
""" |
| 1281 |
def removeDataArray(self, arg0: MeshComponent.FieldType, arg1: str) -> None: |
| 1282 |
""" |
| 1283 |
Remove a data array. |
| 1284 |
|
| 1285 |
Parameter ``fieldType``: |
| 1286 |
field type |
| 1287 |
|
| 1288 |
Parameter ``name``: |
| 1289 |
name of the array to remove |
| 1290 |
""" |
| 1291 |
def replacePointSet(self, arg0: numpy.ndarray) -> None: |
| 1292 |
""" |
| 1293 |
Replaces the point set with the given numpy ndarray of shape (N, 3) where N is the number of points. If there is no Cell/polygons, this will be interpreted as a point cloud (it will create one cell containing all the points). |
| 1294 |
""" |
| 1295 |
def setColor(self, arg0: tuple[float, ...] | list[float]) -> None: |
| 1296 |
""" |
| 1297 |
Set the color of given representation modes. |
| 1298 |
|
| 1299 |
Parameter ``color``: |
| 1300 |
the 4-sized double tab of color (r,g,b,a) of the actor. @warning |
| 1301 |
color must points a 4 double-sized tab minimum. |
| 1302 |
""" |
| 1303 |
def setDataRepresentationOff(self, dataType: int = 7, blockRefresh: bool = False) -> None: |
| 1304 |
""" |
| 1305 |
hide all the data representation of a given data type (hide all by |
| 1306 |
default) By default this->refresh() is called unless blockRefresh is |
| 1307 |
set to true |
| 1308 |
""" |
| 1309 |
def setLinesAsTubes(self, isTubes: bool = True, radiusFromLength: bool = True, radiusFactor: float = 0.025, numberOfSides: int = 5) -> None: |
| 1310 |
""" |
| 1311 |
Set the lines as tubes (**works only for vtkDataSet representation |
| 1312 |
that contains lines**) |
| 1313 |
|
| 1314 |
Parameter ``isTubes``: |
| 1315 |
activate tube representation of lines |
| 1316 |
|
| 1317 |
Parameter ``radiusFromLength``: |
| 1318 |
radius of tubes is computed as a proportion of line length |
| 1319 |
|
| 1320 |
Parameter ``radiusFactor``: |
| 1321 |
radius of tubes will be : radiusFactor*lineLength if |
| 1322 |
radiusFromLength is true, radiusFactor if it is false |
| 1323 |
|
| 1324 |
Parameter ``numberOfSides``: |
| 1325 |
Number of sides of the tubes |
| 1326 |
""" |
| 1327 |
def setRenderingModes(self, arg0: int) -> None: |
| 1328 |
""" |
| 1329 |
@name rendering mode settings @{ Set the actor associated to a |
| 1330 |
rendering mode visible or not. |
| 1331 |
""" |
| 1332 |
class Property: |
| 1333 |
""" |
| 1334 |
This class describes a property that can be used in components and |
| 1335 |
actions or any class that needs to be passed to ObjectController. A |
| 1336 |
property has a type, a description (to be displayed for example as a |
| 1337 |
tooltip, can be rich-text, see https://doc.qt.io/qt-5/richtext-html- |
| 1338 |
subset.html for supported html tags), a value, a unit of measurement |
| 1339 |
(SI unit if possible), and some specific attributes (that depends on |
| 1340 |
the type, e.g. minimal and maximal values, single steps, number of |
| 1341 |
decimals, regular expression...). An enum type can also be used for |
| 1342 |
properties. |
| 1343 |
|
| 1344 |
Properties can be grouped in subgroups, see Property::setGroupName(). |
| 1345 |
|
| 1346 |
Basically this is a way to overcome the Qt Meta Object properties |
| 1347 |
limitations. A camitk::Property enriches a Qt Meta Object property (a |
| 1348 |
very simplified Decorator Design Pattern). |
| 1349 |
|
| 1350 |
Using camitk::Property instead of directly using Qt Meta Object |
| 1351 |
property helps to build a better interactive GUI (in the property |
| 1352 |
explorer for components and in the ActionWidget for actions). Note |
| 1353 |
that a camitk::Property is represented as a regular Qt Meta Object |
| 1354 |
property as well (the value of the camitk::Property is in fact stored |
| 1355 |
by the Qt Meta Object property) |
| 1356 |
|
| 1357 |
Here are some examples to get started with: |
| 1358 |
|
| 1359 |
``` |
| 1360 |
Demonstrates how rich text can be used in description |
| 1361 |
addParameter(new Property("Bool Prop", false, "This a <i>normal</i> bool property.<br/>**Note:** Rich text description!<br/>See also: <a href=\\"http://camitk.imag.fr\\">CamiTK web page</a>", "")); |
| 1362 |
|
| 1363 |
beware: the action takes ownership of the Property pointer |
| 1364 |
This means that the line above does not generate memory leak. |
| 1365 |
|
| 1366 |
Demonstrates how properties can be set as read-only |
| 1367 |
Demonstrates how properties can be grouped. |
| 1368 |
Here all read-only properties are assemble in the same eponymic group |
| 1369 |
Property *readOnlyBool = new Property("Read Only Bool", true, "This a read-only boolean", ""); |
| 1370 |
readOnlyBool->setReadOnly(true); |
| 1371 |
readOnlyBool->setGroupName("Read Only Properties"); |
| 1372 |
addParameter(readOnlyBool); |
| 1373 |
|
| 1374 |
beware: the action takes ownership of the Property pointer |
| 1375 |
This means that you should NOT delete readOnlyBool in the action destructor |
| 1376 |
|
| 1377 |
Demonstrates how integer properties can be bounded |
| 1378 |
Property *boundedInt = new Property("Bounded Int", 12, "An integer bounded between 0 and 20", ""); |
| 1379 |
boundedInt->setAttribute("minimum", 0); |
| 1380 |
boundedInt->setAttribute("maximum", 20); |
| 1381 |
boundedInt->setGroupName("Numeric Properties"); |
| 1382 |
addParameter(boundedInt); |
| 1383 |
|
| 1384 |
Demonstrates how double properties can be half-bounded |
| 1385 |
Property *doubleWithMax = new Property("Double With Max", -10.0, "A double with a max value of -4.2", ""); |
| 1386 |
doubleWithMax->setAttribute("maximum", -4.2); |
| 1387 |
doubleWithMax->setGroupName("Numeric Properties"); |
| 1388 |
addParameter(doubleWithMax); |
| 1389 |
|
| 1390 |
Property *intWithSingleStep = new Property("Int With Single Step", -10, "An integer with a single step of <i>5</i>", ""); |
| 1391 |
intWithSingleStep->setAttribute("singleStep", 5); |
| 1392 |
intWithSingleStep->setGroupName("Numeric Properties"); |
| 1393 |
addParameter(intWithSingleStep); |
| 1394 |
|
| 1395 |
Property *doubleWithStepAndDecimal = new Property("Double With Single Step And Precision", 3.14159, "A double with 5 decimals and a single step of 1.10<sup>-5</sup>", ""); |
| 1396 |
doubleWithStepAndDecimal->setAttribute("singleStep", 10e-6); |
| 1397 |
doubleWithStepAndDecimal->setAttribute("decimals", 5); |
| 1398 |
doubleWithStepAndDecimal->setGroupName("Numeric Properties"); |
| 1399 |
addParameter(doubleWithStepAndDecimal); |
| 1400 |
|
| 1401 |
Property *intWithDecimal = new Property("Int With Precision", 4, "An integer with a precision set to 5 decimals: this should not affect it.", ""); |
| 1402 |
intWithDecimal->setAttribute("decimals", 5); |
| 1403 |
intWithDecimal->setGroupName("Numeric Properties"); |
| 1404 |
addParameter(intWithDecimal); |
| 1405 |
|
| 1406 |
Property *readOnlyQVector3D = new Property("Read Only QVector3D", QVector3D(-4.0, 2.0, 0.1), "A read-only QVector3D", ""); |
| 1407 |
readOnlyQVector3D->setReadOnly(true); |
| 1408 |
readOnlyQVector3D->setGroupName("Read Only Properties"); |
| 1409 |
addParameter(readOnlyQVector3D); |
| 1410 |
|
| 1411 |
Property *stringWithRegExp = new Property("QString Constrained by RegExp", QString("loweronly"), "A QString constrained to lowercase characters only (no separators, numbers...)", ""); |
| 1412 |
stringWithRegExp->setAttribute("regExp", QRegularExpression("[a-z]*")); |
| 1413 |
addParameter(stringWithRegExp); |
| 1414 |
|
| 1415 |
Property *constrainedQRect = new Property("Constrained QRect", QRect(10,10,20,20), "A QRect constrained to (0,0,50,50)", ""); |
| 1416 |
constrainedQRect->setAttribute("constraint", QRect(0,0,50,50)); |
| 1417 |
addParameter(constrainedQRect); |
| 1418 |
|
| 1419 |
Property *constrainedQVector3D = new Property("Constrained QVector3D", QVector3D(1.1, 2.2, 3.3), "A constrained QVector3D (not yet implemented)", ""); |
| 1420 |
constrainedQVector3D->setAttribute("constraint", QVector3D(10.0, 10.0, 10.0)); |
| 1421 |
addParameter(constrainedQVector3D); |
| 1422 |
``` |
| 1423 |
|
| 1424 |
.. note:: |
| 1425 |
To create a new Property, prefer using Property. To check if a |
| 1426 |
Property has been added to your Component / Action, use either |
| 1427 |
Component::getProperty() or Action::getProperty() methods. To |
| 1428 |
modify an existing Property's value, check if it exists: - if not, |
| 1429 |
create a new instance of Property - if yes, directly modify its |
| 1430 |
value by using QObject::setProperty() method.e |
| 1431 |
|
| 1432 |
The GUI interaction is automatically build and managed by the class |
| 1433 |
ObjectController. |
| 1434 |
|
| 1435 |
An example for adding properties to an action can be seen in |
| 1436 |
tutorials/actions/properties. More specifically see the |
| 1437 |
EnumPropertyExample action to learn about how to use enum properties. |
| 1438 |
|
| 1439 |
The class PropComponent and PropAction in the tutorials demonstrates |
| 1440 |
how to use camitk::Property instead of Qt Meta Object Property. |
| 1441 |
|
| 1442 |
The available property types are: |
| 1443 |
|
| 1444 |
Property Type | Property Type Id ------------- | ----------------- int |
| 1445 |
| QVariant::Int double | QVariant::Double bool | QVariant::Bool |
| 1446 |
QString | QVariant::String QVector3D | QVariant::QVector3D QColor | |
| 1447 |
QVariant::Color QDate | QVariant::Date QTime | QVariant::Time QChar | |
| 1448 |
QVariant::Char QDateTime | QVariant::DateTime QPoint | QVariant::Point |
| 1449 |
QPointF | QVariant::PointF QKeySequence | QVariant::KeySequence |
| 1450 |
QLocale | QVariant::Locale QSize | QVariant::Size QSizeF | |
| 1451 |
QVariant::SizeF QRect | QVariant::Rect QRectF | QVariant::RectF |
| 1452 |
QSizePolicy | QVariant::SizePolicy QFont | QVariant::Font QCursor | |
| 1453 |
QVariant::Cursor enum | enumTypeId() flag | flagTypeId() group | |
| 1454 |
groupTypeId() |
| 1455 |
|
| 1456 |
Possible attributes depends on the property type, mostly (see also |
| 1457 |
QtVariantPropertyManager API doc): Property Type | Attribute Name | |
| 1458 |
Attribute Type ------------- | :------------: | :------------: ``int`` |
| 1459 |
| minimum | QVariant::Int ``int`` | maximum | QVariant::Int ``int`` | |
| 1460 |
singleStep | QVariant::Int ``double`` | minimum | QVariant::Double |
| 1461 |
``double`` | maximum | QVariant::Double ``double`` | singleStep | |
| 1462 |
QVariant::Double ``double`` | decimals | QVariant::Int QString | |
| 1463 |
regExp | QVariant::RegExp QDate | minimum | QVariant::Date QDate | |
| 1464 |
maximum | QVariant::Date QPointF | decimals | QVariant::Int QSize | |
| 1465 |
minimum | QVariant::Size QSize | maximum | QVariant::Size QSizeF | |
| 1466 |
minimum | QVariant::SizeF QSizeF | maximum | QVariant::SizeF QSizeF | |
| 1467 |
decimals | QVariant::Int QRect | constraint | QVariant::Rect QRectF | |
| 1468 |
constraint | QVariant::RectF QRectF | decimals | QVariant::Int |
| 1469 |
``enum`` | enumNames | QVariant::StringList (note that this can be |
| 1470 |
build automatically) ``flag`` | flagNames (NOT IMPLEMENTED YET) | |
| 1471 |
QVariant::StringList |
| 1472 |
|
| 1473 |
.. note:: |
| 1474 |
Anywhere in your code use the property(..).toInt() method to get |
| 1475 |
the classical enum value of the property, and use |
| 1476 |
Property::getEnumValueAsString() to get the enum value as a |
| 1477 |
string. If you declared your enum using Q_ENUM (Qt>=5.5), you can |
| 1478 |
also use directly QMetaEnum::fromType to retrieve the enum value |
| 1479 |
as strings (see below). |
| 1480 |
|
| 1481 |
.. note:: |
| 1482 |
If your property is an action parameter, it is safer to use the |
| 1483 |
dedicated methods getParameterValue(..), setParameterValue(..), |
| 1484 |
getParameterValueAsString(..) as they will first check that the |
| 1485 |
given parameter name is a declared parameter. For component |
| 1486 |
properties, it is safer to use the dedicated methods |
| 1487 |
getPropertyValue(..) and setPropertyValue(..) as they will also |
| 1488 |
first check that the given property name is a declared property. |
| 1489 |
|
| 1490 |
.. note:: |
| 1491 |
For enums, you need to do few things in the C++ class that has a |
| 1492 |
enum typed property: - add Q_underscore_OBJECT macro in your class |
| 1493 |
declaration - either setup a new enum (option 1) or just fill in |
| 1494 |
strings in the enum names (option 2) |
| 1495 |
|
| 1496 |
For option 1, you need - add the enum type in your class declaration - |
| 1497 |
register your enum name using the Q_ENUM macro in your class |
| 1498 |
declaration - register the enum type name to the property using the |
| 1499 |
Property::setEnumTypeName (see example below) |
| 1500 |
|
| 1501 |
For option 2 (recommended), just - create a QStringList with the GUI |
| 1502 |
strings - use the Property::setAttribute("enumNames", yourQStringList) |
| 1503 |
|
| 1504 |
.. note:: |
| 1505 |
Using option 2 is recommended as it will allow you to dynamically |
| 1506 |
update the enum names at any time (for instance if you want to |
| 1507 |
select a component, you can update the enum names using the |
| 1508 |
currently opened components). |
| 1509 |
|
| 1510 |
You can change the enum value names in the GUI using the "enumNames" |
| 1511 |
attributes. There is also a way to automatically build nicer enumNames |
| 1512 |
(see below). |
| 1513 |
|
| 1514 |
Enum icons might be set using Property::setEnumIcons. |
| 1515 |
|
| 1516 |
For instance in the header: |
| 1517 |
|
| 1518 |
``` |
| 1519 |
class MyAction : public camitk::Action { |
| 1520 |
Really needed! (replace ‗ by _ in your code if you copy-paste this snippet) |
| 1521 |
Q‗OBJECT |
| 1522 |
|
| 1523 |
-- option 1 |
| 1524 |
declare the C++ enum |
| 1525 |
enum MyEnum { |
| 1526 |
PossibleValue1, |
| 1527 |
PossibleValue2 |
| 1528 |
}; |
| 1529 |
register the enum (Qt >= 5.5) |
| 1530 |
Q_ENUM(MyEnum) |
| 1531 |
|
| 1532 |
-- option 2 (recommended) |
| 1533 |
-> nothing to declare in the header |
| 1534 |
... |
| 1535 |
}; |
| 1536 |
``` |
| 1537 |
|
| 1538 |
And then in the code: |
| 1539 |
|
| 1540 |
``` |
| 1541 |
MyAction::MyAction(ActionExtension * extension) : Action(extension) { |
| 1542 |
... |
| 1543 |
-- option 1 |
| 1544 |
build the dynamic prop based on the enumeration |
| 1545 |
Property *enumProp = new Property("My Enumeration", MyAction::PossibleValue2, "Enumeration support example",""); |
| 1546 |
register the enum type name for automatically manage the enum as a popup list |
| 1547 |
enumProp->setEnumTypeName("MyEnum",this); |
| 1548 |
The Property class automatically build the enum names presented to the user in the GUI |
| 1549 |
(it will changed the enum literals to get a cleaner look, e.g. PossibleValue1 becomes "Possible Value 1") |
| 1550 |
|
| 1551 |
OR |
| 1552 |
|
| 1553 |
-- option 2 (recommended) |
| 1554 |
build the dynamic prop based on a custom string list |
| 1555 |
Property *enumProp = new Property("My Enumeration", 0 /-* index of the initial value in the string list *-/, "Enumeration support example",""); |
| 1556 |
Set the enum names of your choice, using the enumNames property: |
| 1557 |
enumProp->setEnumTypeName("MyEnum"); |
| 1558 |
add strings to populate the GUI |
| 1559 |
QStringList enumValues; |
| 1560 |
enumValues << "Possible Value #1" << "Possible Value #2"; |
| 1561 |
enumProp->setAttribute("enumNames", enumValues); |
| 1562 |
|
| 1563 |
-- after either option 1 or 2: register the new prop as an action parameter |
| 1564 |
addParameter(enumProp); |
| 1565 |
} |
| 1566 |
|
| 1567 |
... |
| 1568 |
|
| 1569 |
-- option 1 usage |
| 1570 |
option 1.1: get the value as classical C++ enum |
| 1571 |
MyEnum enumPropCurrentValue = (MyEnum) getParameterValue("My Enumeration").toInt(); |
| 1572 |
|
| 1573 |
option 1.2: get the value as a QString (either "PossibleValue1" or "PossibleValue2", beware: this is different from the GUI names), you need the enumProp pointer |
| 1574 |
QString enumPropAsString = enumProp->getEnumValueAsString(this); |
| 1575 |
|
| 1576 |
option 1.3: using the Q_ENUM declaration in the header, get the value using Qt meta object |
| 1577 |
QMetaEnum metaEnum = QMetaEnum::fromType<EnumerationExample>(); |
| 1578 |
QString enumPropAsStringDirect = metaEnum.valueToKey(enumPropCurrentValue); |
| 1579 |
|
| 1580 |
-- option 2 usage (recommended) |
| 1581 |
QString QString enumPropAsString = enumValues.value(getParameterValue("My Enumeration").toInt() |
| 1582 |
``` |
| 1583 |
|
| 1584 |
.. note:: |
| 1585 |
This is not exactly a decorator design pattern, as the Property |
| 1586 |
class is not abstract. The Qt Meta Object is still held by the |
| 1587 |
QtObject inherited class (e.g. Component or Action). The |
| 1588 |
camitk::Property class adds description, readOnly status and |
| 1589 |
specific attributes to a QObject dynamic property. |
| 1590 |
""" |
| 1591 |
@staticmethod |
| 1592 |
def setEnumTypeName(*args, **kwargs) -> None: |
| 1593 |
... |
| 1594 |
def __init__(self, name: str, value: typing.Any, description: str, unit: str) -> None: |
| 1595 |
""" |
| 1596 |
Constructor. The variant parameters also allows you to initialize the |
| 1597 |
value of the property. By default a Property is enabled and editable |
| 1598 |
(i.e. by default it is not read-only) |
| 1599 |
|
| 1600 |
Parameter ``name``: |
| 1601 |
property name (unique identifier of your class property |
| 1602 |
|
| 1603 |
Parameter ``variant``: |
| 1604 |
specify the property type (QVariant) and initial value |
| 1605 |
|
| 1606 |
Parameter ``description``: |
| 1607 |
a sentence or two to describe the property (and its unit if any), |
| 1608 |
can be Rich Text |
| 1609 |
|
| 1610 |
Parameter ``unit``: |
| 1611 |
a unit of measurement (in SI unit), use symbols from |
| 1612 |
https://en.wikipedia.org/wiki/SI_base_unit or |
| 1613 |
https://en.wikipedia.org/wiki/SI_derived_unit when possible |
| 1614 |
""" |
| 1615 |
def getAttribute(self, arg0: str) -> typing.Any: |
| 1616 |
... |
| 1617 |
def getDescription(self) -> str: |
| 1618 |
... |
| 1619 |
def getName(self) -> str: |
| 1620 |
... |
| 1621 |
def getReadOnly(self) -> bool: |
| 1622 |
... |
| 1623 |
def getUnit(self) -> str: |
| 1624 |
... |
| 1625 |
def setAttribute(self, attribute: str, value: typing.Any) -> None: |
| 1626 |
... |
| 1627 |
def setReadOnly(self, arg0: bool) -> None: |
| 1628 |
... |
| 1629 |
class PythonHotPlugAction(HotPlugAction): |
| 1630 |
""" |
| 1631 |
An Action that is implemented using a Python CamiTK script. |
| 1632 |
""" |
| 1633 |
class Transformation: |
| 1634 |
""" |
| 1635 |
Transformation represents a geometrical transformation between two |
| 1636 |
FrameOfReferences |
| 1637 |
|
| 1638 |
It supports linear and non-linear transforms stored in a vtkTransform |
| 1639 |
(linear) or any vtkAbstractTransform (non-linear) |
| 1640 |
|
| 1641 |
It has a direction (from a FrameOfReference to another |
| 1642 |
FrameOfReference) |
| 1643 |
|
| 1644 |
Its constructor is private as Transformation objects must only be |
| 1645 |
created through TransformationManager::getTransformationManager() |
| 1646 |
(although it is possible to instantiate your own TransformationManager |
| 1647 |
if you know what you're doing!) |
| 1648 |
|
| 1649 |
.. warning:: |
| 1650 |
Transformation are instantiated/stored/managed/destroyed by |
| 1651 |
TransformationManager::getTransformationManager(), therefore you |
| 1652 |
should not keep a pointer to any Transformation, just call |
| 1653 |
TransformationManager::getTransformationOwnership(..) when you |
| 1654 |
need to access it. This guarantees the coherence of the complete |
| 1655 |
reference system and avoid dangling pointers and memory leaks. |
| 1656 |
|
| 1657 |
``` |
| 1658 |
{.cpp} |
| 1659 |
... |
| 1660 |
FrameOfReference* from = TransformationManager::addFrameOfReference("Source Frame"); |
| 1661 |
FrameOfReference* to = TransformationManager::addFrameOfReference("Destination Frame"); |
| 1662 |
Transformation* t = TransformationManager::addTransformation(from, to); |
| 1663 |
... |
| 1664 |
t->setMatrix(...); |
| 1665 |
note: t MUST not be a member |
| 1666 |
call TransformationManager::getTransformationOwnership(from, to) to access it later on |
| 1667 |
``` |
| 1668 |
|
| 1669 |
See also: |
| 1670 |
TransformationManager |
| 1671 |
""" |
| 1672 |
def getFrom(self) -> FrameOfReference: |
| 1673 |
""" |
| 1674 |
Get the FrameOfReference the Transformation starts from (origin) |
| 1675 |
""" |
| 1676 |
def getName(self) -> str: |
| 1677 |
""" |
| 1678 |
Get the name of the Transformation |
| 1679 |
""" |
| 1680 |
def getTo(self) -> FrameOfReference: |
| 1681 |
""" |
| 1682 |
Get the FrameOfReference that the Transformation goes to (destination) |
| 1683 |
""" |
| 1684 |
def getTransform(self) -> numpy.ndarray: |
| 1685 |
""" |
| 1686 |
Get the internal vtkTransform (linear transformation) or a nullptr |
| 1687 |
|
| 1688 |
Note: this method should return a vtkSmartPointer to a const |
| 1689 |
vtkTransform Unfortunately, at some stage in some part of your VTK |
| 1690 |
pipeline, you might need a non-const vtkTransform. |
| 1691 |
|
| 1692 |
.. warning:: |
| 1693 |
You should only use this method to send the vtkTransform to a vtk |
| 1694 |
method. \\warning **NEVER** use this method to modify the content |
| 1695 |
of the matrix directly, as it might generate inconsistencies in |
| 1696 |
the transformation management. If you need to change the values |
| 1697 |
you **MUST** use TransformationManager::updateTransformation(..) |
| 1698 |
""" |
| 1699 |
class TransformationManager: |
| 1700 |
""" |
| 1701 |
TransformationManager manages frames of reference and transformations |
| 1702 |
for a CamiTK Application |
| 1703 |
|
| 1704 |
This class is the entry point to using FrameOfReference and |
| 1705 |
Transformation system. |
| 1706 |
|
| 1707 |
Every Component that is displayable contains data which are located in |
| 1708 |
space using coordinates. But two Components may not use the same |
| 1709 |
origin in space, or the same axes. |
| 1710 |
|
| 1711 |
To manage that, the notion of Frame specifies an origin and axes, this |
| 1712 |
is modeled by camitk::FrameOfReference. Each component has a |
| 1713 |
FrameOfReference accessed by Component::getFrame() |
| 1714 |
|
| 1715 |
Two Components may share a common Frame, for example two meshes of two |
| 1716 |
organs computed from the same image. In this case both components' |
| 1717 |
getFrame() should return the same FrameOfReference. |
| 1718 |
|
| 1719 |
TransformationManager stores and manages all the FrameOfReference |
| 1720 |
objects used in a CamiTK Application. |
| 1721 |
|
| 1722 |
When you need to display two Components, or to apply an Action that |
| 1723 |
uses multiple Components, it is necessary to be able to transform the |
| 1724 |
coordinates of one Component's data to another. |
| 1725 |
|
| 1726 |
These geometrical transformations are stored in the |
| 1727 |
camitk::Transformation class. A Transformation stores the frame of |
| 1728 |
origin, the frame of destination and the geometrical transformation |
| 1729 |
itself. Currently it supports linear transformations (represented in a |
| 1730 |
4x4 homogeneous matrices). |
| 1731 |
|
| 1732 |
All Transformation objects are also stored and managed in the |
| 1733 |
TransformationManager. The TransformationManager provides and manages |
| 1734 |
a specific and unique "world frame". This is the frame used by VTK and |
| 1735 |
the default for 3D viewers. Having a world frame simplifies the usage |
| 1736 |
of frames. |
| 1737 |
|
| 1738 |
Alongside Component, Viewers also have a FrameOfReference, which |
| 1739 |
determines the "point of view" they are using for the visualization. |
| 1740 |
More precisely, it is used to set the camera and orient the vtkActors. |
| 1741 |
The default frame of the 2D and 3D viewers is the world frame. |
| 1742 |
|
| 1743 |
Their is only one TransformationManager (all public methods are |
| 1744 |
static). |
| 1745 |
|
| 1746 |
.. note:: |
| 1747 |
on shared and raw pointers |
| 1748 |
|
| 1749 |
Transformation and Frames can be manipulated locally using their raw |
| 1750 |
pointer. Use the shared pointer only if you need to own the object as |
| 1751 |
well, that if the Transformation or Frame is part of your class |
| 1752 |
members and need to be kept alive for your code to work. Using a |
| 1753 |
shared pointer ensures that the Frame or Transformation won't be |
| 1754 |
removed from the system by the TransformationManager. If you only need |
| 1755 |
to access or modify information on a frame or transformation, only use |
| 1756 |
the raw pointer. |
| 1757 |
|
| 1758 |
\\section TransformationManager API |
| 1759 |
|
| 1760 |
The TransformationManager provides the following utilities: - |
| 1761 |
addFrameOfReference(...) methods add FrameOfReference objects - |
| 1762 |
addTransformation(...) methods add Transformation objects - |
| 1763 |
getTransformationOwnership(..) methods returns the shared_ptr to a |
| 1764 |
Transformation - getTransformation(...) method computes a |
| 1765 |
Transformation between two Frames, if any path exists between them - |
| 1766 |
updateTransformation(...) methods modify the transformation matrix |
| 1767 |
values |
| 1768 |
|
| 1769 |
Two methods are provided for the manipulation of world frame: - |
| 1770 |
getWorldFrame() returns the unique world frame, to which all frames |
| 1771 |
should have a path to (composed of 1 or more transformations). - |
| 1772 |
ensurePathToWorld() to add a default identity Transformation between |
| 1773 |
the provided Frame and the worldFrame if no Transformation was |
| 1774 |
defined. |
| 1775 |
|
| 1776 |
\\section Transformation |
| 1777 |
|
| 1778 |
A Transformation can either be: - directly defined by the user using |
| 1779 |
addTransformation() -> it holds a user defined 4x4 matrix. It has 0 |
| 1780 |
sources. - an inverse of another Transformation. Inverse |
| 1781 |
Transformation are automatically generated by the |
| 1782 |
TransformationManager. It therefore has 1 source (the direct |
| 1783 |
Transformation it is the inverse of). - a composite transformation |
| 1784 |
defined automatically by the TransformationManager to pass from one |
| 1785 |
source to another one over more than one frame. It is composed by a |
| 1786 |
list of other transformations. It therefore has more than one sources. |
| 1787 |
|
| 1788 |
Information about a Transformation t can be obtained from the |
| 1789 |
TransformationManager using: - hasSources(t) and getSources(t) - |
| 1790 |
isCompositeTransformation(t) - isInverseTransformation(t) - |
| 1791 |
isDefaultIdentityToWorld(t) |
| 1792 |
|
| 1793 |
There is three cases where TransformationManager will automatically |
| 1794 |
create a transformation: - when a linear transformation is added using |
| 1795 |
addTransformation(), the inverse transformation is automatically |
| 1796 |
generated and stored in the system. The new transformation will |
| 1797 |
therefore only have 1 source. - when getTransformation() is called and |
| 1798 |
finds a new path of transformations between the two given frames, it |
| 1799 |
will generate a new composed transformation (for optimization) from |
| 1800 |
those transformations. The new transformation will therefore have all |
| 1801 |
those transformations as sources. - when ensurePathToWorld(f) is |
| 1802 |
called, and no path can be found between f and the world frame, then a |
| 1803 |
new identity transformation from f to world frame is created. This new |
| 1804 |
transformation has no source (note that TransformationManager will |
| 1805 |
also create its inverse, which has 1 source). Use |
| 1806 |
isDefaultIdentityToWorld() to check if a transformation was generated |
| 1807 |
this way. |
| 1808 |
|
| 1809 |
Note that TransformationManager always generates an inverse |
| 1810 |
transformation for any existing linear transformation if it does not |
| 1811 |
exist already. |
| 1812 |
|
| 1813 |
\\section Transformation Sources |
| 1814 |
|
| 1815 |
The lists of Transformation sources are managed by the |
| 1816 |
TransformationManager. Sources are the transformations that are used |
| 1817 |
(composed) to compute a Transformation t. If any of the sources are |
| 1818 |
modified, t is guaranteed to reflect this update, i.e., it is |
| 1819 |
recomputed from its sources. If t has only one source, this means t is |
| 1820 |
the inverse of this source. |
| 1821 |
|
| 1822 |
See also: |
| 1823 |
hasSources() getSources() |
| 1824 |
|
| 1825 |
\\section FrameOfReference A FrameOfReference represents a specific |
| 1826 |
system of coordinates in which component data's coordinates are |
| 1827 |
expressed. |
| 1828 |
|
| 1829 |
It can have a name, a description, and anatomical labels associated to |
| 1830 |
its axes: for example, the X axis may have label L on the lower |
| 1831 |
values, and R on the higher values (for Left/Right anatomical |
| 1832 |
orientation). You can add new Frames of reference using |
| 1833 |
addFrameOfReference methods when creating a new Component (even though |
| 1834 |
Component constructor creates a default one for you), or if you need |
| 1835 |
to manage multiple frames in your component (e.g. for an articulated |
| 1836 |
robot). |
| 1837 |
|
| 1838 |
If you need to get ownership of a specific FrameOfReference (e.g. you |
| 1839 |
want your Component to store the same Frame as another Component), use |
| 1840 |
getFrameOfReferenceOwnership() |
| 1841 |
|
| 1842 |
To edit anatomical information, name or description, refer to |
| 1843 |
FrameOfReference class. |
| 1844 |
|
| 1845 |
\\section Path management |
| 1846 |
|
| 1847 |
When you need a Transformation from one Frame to another, the method |
| 1848 |
to call is getTransformation() |
| 1849 |
|
| 1850 |
This method first looks if a Transformation was added using |
| 1851 |
addTransformation between those Frames, then if there is already a |
| 1852 |
cached composite Transformation linking both Frames, and finally, it |
| 1853 |
checks whether there is a path in the graph of Frames and |
| 1854 |
Transformations linking those Frames using intermediary Frames. |
| 1855 |
|
| 1856 |
Private methods hasPath() and getPath() are used to search the graph |
| 1857 |
for a suitable path. If there is one, a new cached composite |
| 1858 |
Transformation is stored (it combines the path of Transformations into |
| 1859 |
one). If there is no path, these methods return nullptr. |
| 1860 |
|
| 1861 |
When the user wants to ensure that a specific Frame has a |
| 1862 |
Transformation to the WorldFrame, she/he should call |
| 1863 |
ensurePathToWorld(). This will create a default identity |
| 1864 |
Transformation to the WorldFrame if there is no existing path between |
| 1865 |
the Frame and the WorldFrame. |
| 1866 |
|
| 1867 |
All default identity Transformations are marked, so that if a new |
| 1868 |
Transformation is added using addTransformation, these Transformations |
| 1869 |
can be automatically removed. This is needed to avoid creation of |
| 1870 |
multiple path between Frames (there will therefore never be any cycle |
| 1871 |
in the Frame/Transformation graph). |
| 1872 |
|
| 1873 |
\\section Memory management and cleaning up |
| 1874 |
|
| 1875 |
As FrameOfReference and Transformation constructors are private, all |
| 1876 |
Frames and Transformations must be created through the |
| 1877 |
TransformationManager. |
| 1878 |
|
| 1879 |
Internally, Transformation and FrameOfReference objects are stored |
| 1880 |
using std::shared_ptr |
| 1881 |
|
| 1882 |
This means that ownership of these objects is shared between the |
| 1883 |
TransformationManager and custom objects used in CamiTK such as |
| 1884 |
Component (which owns its FrameOfReference), ImageComponent (which |
| 1885 |
also owns its internal Transformation from raw to main). |
| 1886 |
|
| 1887 |
Most methods of this class return or use raw pointers, meaning they do |
| 1888 |
not return or get ownership of the FrameOfReference or Transformation |
| 1889 |
object. The raw pointers are meant to be used for immediate processing |
| 1890 |
(e.g. getting the name of a Frame, transforming the coordinates of a |
| 1891 |
point using a Transformation) but not to store the pointer. If you |
| 1892 |
need to store the object, you must use getFrameOfReferenceOwnership() |
| 1893 |
and getTransformationOwnership() This makes explicit who is owning |
| 1894 |
Transformations and Frames. |
| 1895 |
|
| 1896 |
Note that you may not get ownership of a composite Transformation |
| 1897 |
(computed from others) or a default Transformation, as those must be |
| 1898 |
removable at all times. |
| 1899 |
|
| 1900 |
TransformationManager may delete any Transformation that is not owned |
| 1901 |
outside its internal data structure (which mean they are not used |
| 1902 |
anymore apart from internally). |
| 1903 |
|
| 1904 |
See also: |
| 1905 |
cleanupFramesAndTransformation(), removeDefaultPaths(), |
| 1906 |
removeTransformation(). |
| 1907 |
|
| 1908 |
To determine whether a Transformation or Frame is owned outside the |
| 1909 |
TransformationManager, std::shared_ptr usage counter is used. |
| 1910 |
|
| 1911 |
\\section Using TransformationManager in your extensions: |
| 1912 |
TransformationManager use cases |
| 1913 |
|
| 1914 |
Most common use cases for CamiTK extension developers: - adding a new |
| 1915 |
Component: use the default Component constructor which creates a new |
| 1916 |
default FrameOfReference for the Component - adding a new Component |
| 1917 |
created from another one: - if the new Component is using the same |
| 1918 |
Frame, just set its Frame to the original component's frame using |
| 1919 |
InterfaceFrame::setFrameFrom() - if you need to ensure a Component has |
| 1920 |
its own independent frame, use InterfaceFrame::resetFrame() - Special |
| 1921 |
cases for ImageComponent: ImageComponents have a data frame and a main |
| 1922 |
transformation (from their data to their main frame) that needs to be |
| 1923 |
taken care of. Be aware that ImageComponent::setFrameFrom() and |
| 1924 |
ImageComponent::resetFrame() are reimplemented to take care of the |
| 1925 |
data frame and main transformation. For instance: - your action |
| 1926 |
creates an image outImage from an image inImage, just call |
| 1927 |
`out->setFrameFrom(in)` - your action creates an mesh outMesh from an |
| 1928 |
image inImage, call `outMesh- |
| 1929 |
>setFrame(TransformationManager::getFrameOfReferenceOwnership(inImage- |
| 1930 |
>getDataFrame()));` as the mesh is computed from the image data, the |
| 1931 |
mesh is defined in the image component data frame |
| 1932 |
|
| 1933 |
- Registering a Component to another: for example, compute the |
| 1934 |
registration between two meshes, then use addTransformation() between |
| 1935 |
the frames of the two meshes. |
| 1936 |
|
| 1937 |
.. warning:: |
| 1938 |
: if there is already a Transformation path between the meshes and |
| 1939 |
the world frame is not in this path, addTransformation() will |
| 1940 |
return nullptr. This means that computed transformation (for |
| 1941 |
example after previous registration) already gives a |
| 1942 |
transformation between the two meshes. If you want to update |
| 1943 |
previous registration, you should use updateTransformation() |
| 1944 |
instead. If updateTransformation() also returns nullptr, this |
| 1945 |
means you are trying to create a cycle in the transformation |
| 1946 |
graph. - You can use multiple Frames and Transformation inside |
| 1947 |
your own Component, use the TransformationExplorer to check if it |
| 1948 |
is working as expected. |
| 1949 |
|
| 1950 |
In the case of an articulated robot, each part may have its own |
| 1951 |
FrameOfReference, and each articulation its own Transformation. You |
| 1952 |
can use methods addFrameOfReference, addTransformation, |
| 1953 |
updateTransformation to create and update frames and transformations |
| 1954 |
in your Action and Component extensions. |
| 1955 |
""" |
| 1956 |
@staticmethod |
| 1957 |
def addFrameOfReference(name: str, description: str = '') -> ...: |
| 1958 |
""" |
| 1959 |
Add a FrameOfReference with a name and description This is the |
| 1960 |
standard way to create a new FrameOfReference |
| 1961 |
|
| 1962 |
Returns: |
| 1963 |
the corresponding shared_ptr (save it to keep ownership, ignore if |
| 1964 |
ownership is not needed) |
| 1965 |
""" |
| 1966 |
@staticmethod |
| 1967 |
def addTransformation(arg0: ..., arg1: ...) -> ...: |
| 1968 |
""" |
| 1969 |
Create and register a new identity Transformation between two frames |
| 1970 |
if there is no existing transformation between those frames. |
| 1971 |
|
| 1972 |
Returns: |
| 1973 |
a pointer to the new Transformation or nullptr if a transformation |
| 1974 |
between those frames already exist (use getTransformation()) |
| 1975 |
""" |
| 1976 |
@staticmethod |
| 1977 |
def getFramesOfReference() -> list[FrameOfReference]: |
| 1978 |
""" |
| 1979 |
Get a list of all stored FrameOfReference |
| 1980 |
""" |
| 1981 |
@staticmethod |
| 1982 |
def getTransformation(arg0: ..., arg1: ...) -> ...: |
| 1983 |
""" |
| 1984 |
Get a transformation if it exists or compute it if a path exists |
| 1985 |
between the frames. |
| 1986 |
""" |
| 1987 |
@staticmethod |
| 1988 |
def getTransformations() -> list[FrameOfReference]: |
| 1989 |
""" |
| 1990 |
Returns the list of all transformations managed in the system, |
| 1991 |
independents or not. |
| 1992 |
""" |
| 1993 |
@staticmethod |
| 1994 |
def getWorldFrame() -> ...: |
| 1995 |
""" |
| 1996 |
Get the WorldFrame |
| 1997 |
|
| 1998 |
This is the Frame that links all Frames so that there is a common |
| 1999 |
space If a Component's frame is not linked by a Transformation to any |
| 2000 |
other Frame, a default identity Transformation should be created |
| 2001 |
between it and this worldFrame |
| 2002 |
|
| 2003 |
This is done by calling ensurePathToWorld |
| 2004 |
""" |
| 2005 |
@staticmethod |
| 2006 |
def preferredDefaultIdentityToWorldLink(arg0: ...) -> bool: |
| 2007 |
""" |
| 2008 |
Call this method when you prefer (for visualization purpose only) to |
| 2009 |
have a direct link to world from the given frame instead of any other |
| 2010 |
path. If another path to world exists from the frame and include a |
| 2011 |
default identity transformation to world, it will be delete in favor |
| 2012 |
of a new default identity transformation that directly links the given |
| 2013 |
frame to world. |
| 2014 |
|
| 2015 |
Returns: |
| 2016 |
false if there is a path to world that contains no default |
| 2017 |
identity transformation |
| 2018 |
""" |
| 2019 |
@staticmethod |
| 2020 |
@typing.overload |
| 2021 |
def removeTransformation(arg0: ...) -> bool: |
| 2022 |
""" |
| 2023 |
Remove an existing transformation between the two frames. |
| 2024 |
|
| 2025 |
This method checks that the given shared_ptr<Transformation> has no |
| 2026 |
other owner than the caller (i.e., only the caller of this method has |
| 2027 |
ownership of the given shared_ptr). If this is true, then the |
| 2028 |
shared_ptr will be set to nullptr, which will result in the deletion |
| 2029 |
of the Transformation. |
| 2030 |
|
| 2031 |
If there is another owner, the shared_ptr is not modified, and the |
| 2032 |
Transformation will not be removed. |
| 2033 |
|
| 2034 |
If the given shared_ptr is equal to nullptr (for instance when calling |
| 2035 |
removeTransformation(getTransformationOwnership(t)) with t being a |
| 2036 |
composite transformation), this method returns false. |
| 2037 |
|
| 2038 |
.. warning:: |
| 2039 |
if successful, the shared_ptr must not be used anymore (as it is |
| 2040 |
set to nullptr). |
| 2041 |
|
| 2042 |
Returns: |
| 2043 |
true if the Transformation was removed from the transformation |
| 2044 |
system, false otherwise. |
| 2045 |
""" |
| 2046 |
@staticmethod |
| 2047 |
@typing.overload |
| 2048 |
def removeTransformation(arg0: ..., arg1: ...) -> bool: |
| 2049 |
""" |
| 2050 |
Remove an existing transformation between the two frames. |
| 2051 |
|
| 2052 |
See also: |
| 2053 |
removeTransformation(std::shared_ptr<Transformation>&) |
| 2054 |
|
| 2055 |
.. warning:: |
| 2056 |
if successful, the shared_ptr must not be used anymore (as it is |
| 2057 |
set to nullptr) after that. |
| 2058 |
""" |
| 2059 |
@staticmethod |
| 2060 |
@typing.overload |
| 2061 |
def updateTransformation(arg0: ..., arg1: ..., arg2: numpy.ndarray) -> None: |
| 2062 |
""" |
| 2063 |
Modify the Transformation between the two frames by setting its |
| 2064 |
vtkTransform @warning only the vtkMatrix of the given vtkTransform is |
| 2065 |
duplicated (later modification of vtkTr will not update the |
| 2066 |
transformations) |
| 2067 |
""" |
| 2068 |
@staticmethod |
| 2069 |
@typing.overload |
| 2070 |
def updateTransformation(arg0: ..., arg1: ..., arg2: numpy.ndarray) -> None: |
| 2071 |
""" |
| 2072 |
Modify the Transformation between the two frames by setting its |
| 2073 |
vtkMatrix |
| 2074 |
Note that the vtkMatrix must is given as a 4x4 numpy array. |
| 2075 |
""" |
| 2076 |
@staticmethod |
| 2077 |
@typing.overload |
| 2078 |
def updateTransformation(arg0: ..., arg1: numpy.ndarray) -> None: |
| 2079 |
""" |
| 2080 |
Modify the Transformation by setting its vtkTransform @warning only |
| 2081 |
the vtkMatrix of the given vtkTransform is duplicated (later |
| 2082 |
modification of vtkTr will not update the transformations) |
| 2083 |
""" |
| 2084 |
@staticmethod |
| 2085 |
@typing.overload |
| 2086 |
def updateTransformation(arg0: ..., arg1: numpy.ndarray) -> None: |
| 2087 |
""" |
| 2088 |
Modify the Transformation by setting its matrix |
| 2089 |
Note that the vtkMatrix must is given as a 4x4 numpy array. |
| 2090 |
""" |
| 2091 |
class pythonConsoleRedirect: |
| 2092 |
@staticmethod |
| 2093 |
def flush() -> None: |
| 2094 |
... |
| 2095 |
@staticmethod |
| 2096 |
def write(arg0: typing.Any) -> None: |
| 2097 |
... |
| 2098 |
def error(arg0: str) -> None: |
| 2099 |
""" |
| 2100 |
Logs an error message. |
| 2101 |
""" |
| 2102 |
def getDebugInfo() -> str: |
| 2103 |
... |
| 2104 |
def getPythonVersion() -> str: |
| 2105 |
... |
| 2106 |
def info(arg0: str) -> None: |
| 2107 |
""" |
| 2108 |
Logs an info message. |
| 2109 |
""" |
| 2110 |
def newImageComponentFromNumpy(array: numpy.ndarray, name: str = 'image', spacing: typing.Any = None) -> ImageComponent: |
| 2111 |
""" |
| 2112 |
Create an Image Component by creating a new vtkImageData from the given array of voxel and spacing, if provided) |
| 2113 |
""" |
| 2114 |
def newMeshComponentFromNumpy(name: str = 'mesh', points_array: numpy.ndarray[numpy.float64], polys_array: numpy.ndarray[numpy.int64] = ...) -> MeshComponent: |
| 2115 |
""" |
| 2116 |
Creates a Mesh Component by creating a new vtkPointSet made of the given point array and poly array(only vtkPolyData and point clouds are supported for now) |
| 2117 |
""" |
| 2118 |
def redirectStandardStreams() -> None: |
| 2119 |
... |
| 2120 |
def refresh() -> None: |
| 2121 |
""" |
| 2122 |
Refreshes the application, including the transformation manager and all registered viewers. |
| 2123 |
""" |
| 2124 |
def show() -> None: |
| 2125 |
""" |
| 2126 |
Starts a default CamiTK Application with the default main window and event loop, and shows the main window. |
| 2127 |
This function is experimental and is still not entirely functional nor stable. |
| 2128 |
Use at your own risks and only if you know what your doing. |
| 2129 |
|
| 2130 |
You have been warned! |
| 2131 |
""" |
| 2132 |
def startApplication() -> None: |
| 2133 |
""" |
| 2134 |
Starts a default CamiTK Application with the default main window and event loop. |
| 2135 |
This function is experimental and is still not entirely functional nor stable. |
| 2136 |
Use at your own risks and only if you know what your doing. |
| 2137 |
|
| 2138 |
You have been warned! |
| 2139 |
""" |
| 2140 |
def trace(arg0: str) -> None: |
| 2141 |
""" |
| 2142 |
Logs a trace message. |
| 2143 |
""" |
| 2144 |
def warning(arg0: str) -> None: |
| 2145 |
""" |
| 2146 |
Logs a warning message. |
| 2147 |
""" |
| 2148 |
__version__: str = 'CamiTK 6.0.0' |