gpt4 book ai didi

r - 初始化图形设备时如何设置设备复制参数?

转载 作者:行者123 更新时间:2023-12-03 17:11:26 25 4
gpt4 key购买 nike

我正在 R 包中的图形设备上工作,需要设置一些
设备上的文本/标签在初始化或重置时的图形参数。
这个特性在 R Internals 中有描述:

The three copies of the GPar structure are used to store the current parameters (accessed via gpptr),the ‘device copy’ (accessed via dpptr) and space for a saved copy of the ‘device copy’ parameters.The current parameters are, clearly, those currently in use and are copied from the ‘device copy’whenever plot.new() is called (whether or not that advances to the next ‘page’). The saved copykeeps the state when the device was last completely cleared (e.g. when plot.new() was calledwith par(new=TRUE)), and is used to replay the display list.


我如何从包中实际访问和初始化“设备副本”?
我能找到的只是一个评论,其中包含一个较旧的,
复制粘贴评论于 GraphicsDevice.h :
  * 2. I found this comment in the doc for dev_Open -- looks nasty
* Any known instances of such a thing happening? Should be
* replaced by a function to query the device for preferred gpars
* settings? (to be called when the device is initialised)
*
* NOTE that it is perfectly acceptable for this
* function to set generic graphics parameters too
* (i.e., override the generic parameter settings
* which GInit sets up) all at the author's own risk
* of course :)

最佳答案

我不知道我是否完全理解你想要做什么,但我想你可能会发现 this guide有用。一些关键摘录:

To create a running graphics device with our own functions, we callthe graphicsDevice() function. While there are several methods forthis, essentially we give it a list of named functions that specifythe implementation of some or all of the 21 graphical primitiveoperations. We might give this as a list or as an instance ofRDevDescMethods or of a sub-class that we define for a particular typeof device. So we focus on writing these functions.


然后:

Each of the methods is passed an object of class DevDescPtr. This isalso the type of the value returned by the top-level functiongraphicsDevice() . This is a reference the C-level data structure thatrepresents the graphics device. We can use this to query the settingsof the graphics device.

Some of these fields in the device are usedwhen initializing the device rather than within the functions (e.g.those whose names are prefixed with "start"). Other fields arestructural information about the rendering of different aspects of thedevice. For example, we can find the dimensions of the drawing area,The DevDescPtr class is essentially an opaque data type in R(containing an external pointer to the C-level data structure) and isintended to be used as if it were an R-level list. We can use the $operator to access individual fields and we can find the names ofthese fields with names().


最后:

Under some rare circumstances, it is convenient to convert thereference to an R object. We can do this by coercing it to thecorresponding R class named DevDesc (i.e. with the "Ptr" remove), i.e.as(dev, "DevDesc"). This copies each of the fields in the C-levelstructure to the corresponding slot in the R class.


例如, circle设备的方法具有以下签名:
circle ( numeric, numeric, numeric, R_GE_gcontextPtr, DevDescPtr )
R_GE_gcontextPtr 是:

...another reference to an instance of a C-level data type. This is theinformation about the "current" settings of the device. This gives usinformation about the current pen/foreground color, the backgroundcolor, the setting for the gamma level, the line width, style, join,the character point size and expansion/magnification, and the fontinformation. The available fields are

names(new("R_GE_gcontextPtr"))
[1] "col" "fill" "gamma" "lwd" "lty"
[6] "lend" "ljoin" "lmitre" "cex" "ps"
[11] "lineheight" "fontface" "fontfamily"

关于r - 初始化图形设备时如何设置设备复制参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62598424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com