刚开始赶工G4的作业,好不容易建好一个小人,塞到B1里面去发现怎么也找不到一个合适的视角,小人以各种崎岖的姿势站在坐标系里。很头疼,后来终于找到几条有用的命令。随便记一下。
tldr版本
几个指令:
这些命令可以写在vis.mac脚本里,也可以编译之后通过Idle输入
/vis/viewer/set/upVector [x] [y] [z]
:
在坐标系中,设置一个up-vector,调整viewer使得该vector总是朝上。
三个参数分别是up-vector的三个分量,数据类型是double(我猜)
/vis/viewer/centreOn [name]
:
选中一个volume作为target,就是让相机对准一个volume
这个name就是在放置logicalVolume为一个physicalVolume的时候写入的那个字符串
例如:
new G4PVPlacement(0,
G4ThreeVector(-leg_delta_x,0,leg_delta_z),
logicLeg,
"HumanLeg", // <----------------这个
logicWorld,
false,
0,
checkOverlaps);
/vis/viewer/zoomTo [n]
:
就好像把镜头拉近拉远一样,将视野放大和缩小
参数n越大,视野中的像越大
还有一个相对性的缩放指令:
/vis/viewer/zoom [n]
,如果多次使用/vis/viewer/zoom 2
那么视野中的像就会一直两倍两倍的放大。
/vis/viewer/set/viewpointVector [x] [y] [z]
:
这是设置从target位置到镜头位置到方向矢量
/vis/viewer/set/lightsVector [x] [y] [z]
:
顾名思义,就是调光照方向
唠叨版本
怎么蒙到的?
先去翻看了B1到vis.mac,因为事先大概知道这个是管可视化的,然后在最后几行中发现(大约是102行开始):
# To get nice view
# Make the "World" box invisible
/vis/geometry/set/visibility World 0 false
# "Envelope" is transparent blue to represent water
/vis/geometry/set/colour Envelope 0 0 0 1 .3
/vis/viewer/set/style surface
/vis/viewer/set/hiddenMarker true
/vis/viewer/set/viewpointThetaPhi 45 180 # <<------这里看着就很像视角
发现大约可以从/vis/viewer/set/viewpoint
入手
但怎么想这个视角应该有三个参数才对,但上面那个只给出两个。
在官网给出的《BookForApplicationDevelopers》中查找viewpoint
,发现在P310: 8.4.11 Basic camera workings: /vis/viewer/ commands中有如下内容:
The target point can be changed with a /vis/viewer/set command or with the /vis/viewer/pan commands. The up-vector and the viewpoint direction can also be changed with /vis/viewer/set commands. Care must be taken to avoid having the two vectors parallel, for in that case the view is undefined.
于是就知道了G4调整视角的逻辑中包含target和camera两个概念。
后来翻看UIterminal的讲解内容发现:(P42,2.9.2 A Short Description of Available Interfaces)
顺手在运行的魔改版B1里试一下:
Idle> ls /vis/viewer/set/
Command directory path : /vis/viewer/set/
Guidance :
Set view parameters of current viewer.
Sub-directories :
/vis/viewer/set/timeWindow/ Set time window parameters of current viewer.
Commands :
all * Copies view parameters.
autoRefresh * Sets auto-refresh.
auxiliaryEdge * Sets visibility of auxiliary edges
background * Set background colour and transparency (default black and opaque).
culling * Set culling options.
cutawayMode * Sets cutaway mode - add (union) or multiply (intersection).
defaultColour * Set defaultColour colour and transparency (default white and opaque).
defaultTextColour * Set defaultTextColour colour and transparency (default blue and opaque).
edge * Edges become visible/invisible in surface mode.
explodeFactor * Moves top-level drawn volumes by this factor from this centre.
globalLineWidthScale * Multiplies line widths by this factor.
globalMarkerScale * Multiplies marker sizes by this factor.
hiddenEdge * Edges become hidden/seen in wireframe or surface mode.
hiddenMarker * If true, closer objects hide markers. Otherwise, markers always show.
lightsMove * Lights move with camera or with object
lightsThetaPhi * Set direction from target to lights.
lightsVector * Set direction from target to lights.
lineSegmentsPerCircle * Set number of sides per circle for polygon/polyhedron drawing.
numberOfCloudPoints * Set number of points to be used for cloud representation of volumes.
picking * Sets picking, if available.
projection * Set projection style - o[rthogonal] or p[erspective].
If p[erspective], also set field half angle.
rotationStyle * Set style of rotation - constrainUpDirection or freeRotation.
sectionPlane * Set plane for drawing section (DCUT).
style * Set style of drawing - w[ireframe] or s[urface] or c[loud].
targetPoint * Set target point.
upThetaPhi * Set up vector.
upVector * Set up vector.
viewpointThetaPhi * Set direction from target to camera.
viewpointVector * Set direction from target to camera.
Idle>
这样可以浏览所有的commads。
Idle> help /vis/viewer/set/upVector
Command /vis/viewer/set/upVector
Guidance :
Set up vector.
Viewer will attempt always to show this direction upwards.
Parameter : x
Parameter type : d
Omittable : True
Default value : 0
Parameter : y
Parameter type : d
Omittable : True
Default value : 1
Parameter : z
Parameter type : d
Omittable : True
Default value : 0
Idle>
这样可以查看commands的用法!
顺手发现了不用ThetaPhi而用笛卡尔坐标系参数的命令。
美滋滋
放一个小录屏皮一下
主要就是这些指令:
/vis/viewer/zoom 0.5
/vis/viewer/zoom 1
/vis/viewer/set/viewpointVector 1 0 0
/vis/viewer/set/viewpointVector 1 1 1
/vis/viewer/set/upVector 1 0 0
/vis/viewer/set/upVector 0 0 1
/vis/viewer/set/upVector 0 1 0
/vis/viewer/zoom 4
/vis/viewer/centreOn HumanHeadNeck
/vis/viewer/centreOn Body
/vis/viewer/centreOn Leg
没法皮了,CSDN不支持放视频,我也懒得做Gif……哈哈哈哈哈哈哈哈
要不就放张图意思一下吧:
/vis/viewer/zoom 4:
/vis/viewer/set/viewpointVector 1 1 1
照相机迷失了233
/vis/viewer/centreOn HumanHeadNeck
/vis/viewer/centreOn HumanBody
/vis/viewer/set/upVector 0 0 1