Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VTK Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VTK
VTK Examples
Commits
f9e4bb39
Commit
f9e4bb39
authored
2 months ago
by
Andrew Maclean
Browse files
Options
Downloads
Patches
Plain Diff
Adding Light.py
parent
eb1e94df
No related branches found
Branches containing commit
No related tags found
1 merge request
!397
C++ to python api 12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/PythonicAPI.md
+1
-0
1 addition, 0 deletions
src/PythonicAPI.md
src/PythonicAPI/Lighting/Light.py
+101
-0
101 additions, 0 deletions
src/PythonicAPI/Lighting/Light.py
src/Testing/Baseline/PythonicAPI/Lighting/TestLight.png
+3
-0
3 additions, 0 deletions
src/Testing/Baseline/PythonicAPI/Lighting/TestLight.png
with
105 additions
and
0 deletions
src/PythonicAPI.md
+
1
−
0
View file @
f9e4bb39
...
...
@@ -498,6 +498,7 @@ This section includes ?vtkUnstructuredGrid?.
| Example Name | Description | Image |
| -------------- | ------------- | ------- |
[
Light
](
/PythonicAPI/Lighting/Light
)
| Add a directional light to a scene.
[
ShadowsLightsDemo
](
/PythonicAPI/Visualization/ShadowsLightsDemo
)
| Show lights casting shadows.
## Texture Mapping
...
...
This diff is collapsed.
Click to expand it.
src/PythonicAPI/Lighting/Light.py
0 → 100644
+
101
−
0
View file @
f9e4bb39
#!/usr/bin/env python3
from
dataclasses
import
dataclass
# noinspection PyUnresolvedReferences
import
vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import
vtkmodules.vtkRenderingOpenGL2
# noinspection PyUnresolvedReferences
import
vtkmodules.vtkRenderingUI
from
vtkmodules.vtkCommonColor
import
vtkNamedColors
from
vtkmodules.vtkFiltersSources
import
vtkSphereSource
,
vtkPlaneSource
from
vtkmodules.vtkRenderingCore
import
(
vtkActor
,
vtkPolyDataMapper
,
vtkRenderWindow
,
vtkRenderWindowInteractor
,
vtkRenderer
,
vtkLight
,
vtkLightActor
)
def
main
():
colors
=
vtkNamedColors
()
renderer
=
vtkRenderer
(
background
=
colors
.
GetColor3d
(
'
Black
'
),
background2
=
colors
.
GetColor3d
(
'
Silver
'
),
gradient_background
=
True
,
automatic_light_creation
=
True
)
# Create a light.
light_position
=
(
0
,
0
,
1
)
light_focal_point
=
(
0
,
0
,
0
)
light
=
vtkLight
(
light_type
=
Light
.
LightType
.
VTK_LIGHT_TYPE_SCENE_LIGHT
,
position
=
light_position
,
positional
=
True
,
focal_point
=
light_focal_point
,
cone_angle
=
10
,
diffuse_color
=
colors
.
GetColor3d
(
'
Red
'
),
ambient_color
=
colors
.
GetColor3d
(
'
Green
'
),
specular_color
=
colors
.
GetColor3d
(
'
Blue
'
)
)
original_lights
=
renderer
.
lights
print
(
f
'
Originally there
{
lights_txt
(
original_lights
)
}
'
)
# Display where the light is.
light_actor
=
vtkLightActor
(
light
=
light
)
renderer
.
AddViewProp
(
light_actor
)
# Display where the light is focused.
light_focal_point_sphere
=
vtkSphereSource
(
center
=
light_focal_point
,
radius
=
0.1
)
light_focal_point_mapper
=
vtkPolyDataMapper
()
light_focal_point_sphere
>>
light_focal_point_mapper
light_focal_point_actor
=
vtkActor
(
mapper
=
light_focal_point_mapper
)
light_focal_point_actor
.
property
.
color
=
colors
.
GetColor3d
(
'
Yellow
'
)
renderer
.
AddViewProp
(
light_focal_point_actor
)
# Create a plane for the light to shine on.
plane_source
=
vtkPlaneSource
(
resolution
=
(
100
,
100
))
plane_mapper
=
vtkPolyDataMapper
(
input_data
=
plane_source
.
update
().
output
)
plane_actor
=
vtkActor
(
mapper
=
plane_mapper
)
renderer
.
AddActor
(
plane_actor
)
ren_win
=
vtkRenderWindow
(
window_name
=
'
Light
'
)
ren_win
.
AddRenderer
(
renderer
)
iren
=
vtkRenderWindowInteractor
()
iren
.
render_window
=
ren_win
ren_win
.
Render
()
print
(
f
'
Now there
{
lights_txt
(
original_lights
)
}
'
)
renderer
.
AddLight
(
light
)
# We must do this after ren_win.Render()
print
(
f
'
Now there
{
lights_txt
(
original_lights
)
}
'
)
camera
=
renderer
.
active_camera
camera
.
position
=
(
-
2.17199
,
-
2.50774
,
2.18
)
camera
.
focal_point
=
(
-
0.144661
,
-
0.146372
,
0.180482
)
camera
.
view_up
=
(
0.0157883
,
0.638203
,
0.769706
)
camera
.
SetDistance
(
3.69921
)
camera
.
SetClippingRange
(
1.76133
,
6.14753
)
iren
.
Start
()
def
lights_txt
(
light_collection
):
number_of_lights
=
light_collection
.
number_of_items
match
number_of_lights
:
case
0
:
return
f
'
are no lights.
'
case
1
:
return
f
'
is one light.
'
case
_
:
return
f
'
are
{
number_of_lights
}
lights.
'
@dataclass
(
frozen
=
True
)
class
Light
:
@dataclass
(
frozen
=
True
)
class
LightType
:
VTK_LIGHT_TYPE_HEADLIGHT
:
int
=
1
VTK_LIGHT_TYPE_CAMERA_LIGHT
:
int
=
2
VTK_LIGHT_TYPE_SCENE_LIGHT
:
int
=
3
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
src/Testing/Baseline/PythonicAPI/Lighting/TestLight.png
0 → 100644
LFS
+
3
−
0
View file @
f9e4bb39
130 B
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment