很高兴在雪易的CSDN遇见你?
VTK技术爱好者 QQ:870202403
本文以vtkTextActor为起点,分享VTK中Text相关的内容,希望对各位小伙伴有所帮助!
感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!
你的点赞就是我的动力(^U^)ノ~YO
目录
? ? ? ? 用于展示文字的Actor,可以缩放,也可以不缩放。
?????????vtkTextActor可用于将文本注释放入窗口中。当TextScaleMode为NONE时,文本是固定字体,操作与vtkPolyDataMapper2D/vtkActor2D对相同。当TextScaleMode为VIEWPORT时,字体会调整大小,使其相对于呈现它的VIEWPORT保持一致的大小。当TextScaleMode为PROP时,字体会调整大小,使文本适合位置1和2坐标所定义的框。该类取代了已弃用的vtkScaledTextActor,并作为vtkTextMapper/vtkActor2D对的方便包装器。通过与此actor关联的vtkTextProperty设置文本属性/属性。其重要参数如下:
//@{
/**
* Set the text string to be displayed. "\n" is recognized
* as a carriage return/linefeed (line separator).
* The characters must be in the UTF-8 encoding.
* Convenience method to the underlying mapper
*/
void SetInput(const char* inputString);
char* GetInput();
//@}
//@{
/** 设置该Actor所占用的最小像素
* Set/Get the minimum size in pixels for this actor.
* Defaults to 10,10.
* Only valid when TextScaleMode is PROP.
*/
vtkSetVector2Macro(MinimumSize, int);
vtkGetVector2Macro(MinimumSize, int);
//@}
//@{
/**设置/获取文本行的最大高度,作为分配给它的垂直区域的百分比
* 缩放文本actor。默认为1.0。
* Set/Get the maximum height of a line of text as a
* percentage of the vertical area allocated to this
* scaled text actor. Defaults to 1.0.
* Only valid when TextScaleMode is PROP.
*/
vtkSetMacro(MaximumLineHeight, float);
vtkGetMacro(MaximumLineHeight, float);
//@}
//@{
/**
* 设置文本的缩放方式。
* 如果设置为vtkTextActor::TEXT_SCALE_MODE_NONE,字体大小将由TextProperty中给定的大小固定。
* 如果设置为vtkTextActor::TEXT_SCALE_MODE_PROP,文本将被缩放到完全适合由位置1和2坐标指定的道具。
* 如果设置为vtkTextActor::TEXT_SCALE_MODE_VIEWPORT,文本将根据显示的viewport的大小进行缩放。
* Set how text should be scaled. If set to
* vtkTextActor::TEXT_SCALE_MODE_NONE, the font size will be fixed by the
* size given in TextProperty. If set to vtkTextActor::TEXT_SCALE_MODE_PROP,
* the text will be scaled to fit exactly in the prop as specified by the
* position 1 & 2 coordinates. If set to
* vtkTextActor::TEXT_SCALE_MODE_VIEWPORT, the text will be scaled based on
* the size of the viewport it is displayed in.
*/
vtkSetClampMacro(TextScaleMode, int, TEXT_SCALE_MODE_NONE, TEXT_SCALE_MODE_VIEWPORT);
vtkGetMacro(TextScaleMode, int);
void SetTextScaleModeToNone() { this->SetTextScaleMode(TEXT_SCALE_MODE_NONE); }
void SetTextScaleModeToProp() { this->SetTextScaleMode(TEXT_SCALE_MODE_PROP); }
void SetTextScaleModeToViewport() { this->SetTextScaleMode(TEXT_SCALE_MODE_VIEWPORT); }
//@}
enum
{
TEXT_SCALE_MODE_NONE = 0,
TEXT_SCALE_MODE_PROP,
TEXT_SCALE_MODE_VIEWPORT
};
//@{
/**
* Turn on or off the UseBorderAlign option.
* When UseBorderAlign is on, the bounding rectangle is used to align the text,
* which is the proper behavior when using vtkTextRepresentation
*/
vtkSetMacro(UseBorderAlign, vtkTypeBool);
vtkGetMacro(UseBorderAlign, vtkTypeBool);
vtkBooleanMacro(UseBorderAlign, vtkTypeBool);
//@}
//@{
/**
* This method is being deprecated. Use SetJustification and
* SetVerticalJustification in text property instead.
* Set/Get the Alignment point
* if zero (default), the text aligns itself to the bottom left corner
* (which is defined by the PositionCoordinate)
* otherwise the text aligns itself to corner/midpoint or centre
* @verbatim
* 6 7 8
* 3 4 5
* 0 1 2
* @endverbatim
* This is the same as setting the TextProperty's justification.
* Currently TextActor is not oriented around its AlignmentPoint.
*/
void SetAlignmentPoint(int point);
int GetAlignmentPoint();
//@}
//@{
/**
* 围绕对齐点逆时针旋转。单位以度为单位,默认为0。
* text属性中的方向旋转纹理图中的文本。它可能不会给你想要的效果。
* Counterclockwise rotation around the Alignment point.
* Units are in degrees and defaults to 0.
* The orientation in the text property rotates the text in the
* texture map. It will proba ly not give you the effect you
* desire.
*/
void SetOrientation(float orientation);
vtkGetMacro(Orientation, float);
//@}
//@{
/**
* Set/Get the text property.
*/
virtual void SetTextProperty(vtkTextProperty* p);
vtkGetObjectMacro(TextProperty, vtkTextProperty);
//@}
/**
* Return the bounding box coordinates of the text in pixels.
* The bbox array is populated with [ xmin, xmax, ymin, ymax ]
* values in that order.
*/
virtual void GetBoundingBox(vtkViewport* vport, double bbox[4]);
/**
* Syntactic sugar to get the size of text instead of the entire bounding box.
*/
virtual void GetSize(vtkViewport* vport, double size[2]);
//@{
/**
* 根据设置的目标矩形,计算并设置合适的字体大小。
* 该方法的静态版本也可用于方便其他类(例如,小部件)。
* Set and return the font size required to make this mapper fit in a given
* target rectangle (width x height, in pixels). A static version of the
* method is also available for convenience to other classes (e.g., widgets).
*/
virtual int SetConstrainedFontSize(vtkViewport*, int targetWidth, int targetHeight);
static int SetConstrainedFontSize(vtkTextActor*, vtkViewport*, int targetWidth, int targetHeight);
//@}
/**
* 设置并返回使映射器数组的每个元素适合给定矩形(宽度x高度,以像素为单位)所需的字体大小。
* 此字体大小是适合此约束中最大映射器所需的最小大小。
* Set and return the font size required to make each element of an array
* of mappers fit in a given rectangle (width x height, in pixels). This
* font size is the smallest size that was required to fit the largest
* mapper in this constraint.
*/
static int SetMultipleConstrainedFontSize(vtkViewport*, int targetWidth, int targetHeight,
vtkTextActor** actors, int nbOfActors, int* maxResultingSize);
/**
* 启用非线性缩放字体大小。这在与缩放文本结合使用时非常有用。
* 对于小窗口,您希望使用整个缩放文本区域。
* 对于较大的窗口,您需要将字体大小减小一些,以便不使用整个区域。
* 这些值修改计算的字体大小如下:newFontSize = pow(FontSize,指数)*pow(目标,1.0 -指数)
* 通常指 数应该在0.7左右,目标应该在10左右
* Enable non-linear scaling of font sizes. This is useful in combination
* with scaled text. With small windows you want to use the entire scaled
* text area. With larger windows you want to reduce the font size some so
* that the entire area is not used. These values modify the computed font
* size as follows:
* newFontSize = pow(FontSize,exponent)*pow(target,1.0 - exponent)
* typically exponent should be around 0.7 and target should be around 10
*/
virtual void SetNonLinearFontScale(double exponent, int target);
/**这只是在渲染过程中使用的一种简单的坐标转换方法。
* This is just a simple coordinate conversion method used in the render
* process.
*/
void SpecifiedToDisplay(double* pos, vtkViewport* vport, int specified);
/**
* This is just a simple coordinate conversion method used in the render
* process.
*/
void DisplayToSpecified(double* pos, vtkViewport* vport, int specified);
/**
* Compute the scale the font should be given the viewport. The result
* is placed in the ScaledTextProperty ivar.
*/
virtual void ComputeScaledFont(vtkViewport* viewport);
//@{
/**
* Get the scaled font. Use ComputeScaledFont to set the scale for a given
* viewport.
*/
vtkGetObjectMacro(ScaledTextProperty, vtkTextProperty);
//@}
/**
* Provide a font scaling based on a viewport. This is the scaling factor
* used when the TextScaleMode is set to VIEWPORT and has been made public for
* other components to use. This scaling assumes that the long dimension of
* the viewport is meant to be 6 inches (a typical width of text in a paper)
* and then resizes based on if that long dimension was 72 DPI.
*/
static float GetFontScale(vtkViewport* viewport);
感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!
你的赞赏是我的最最最最大的动力(^U^)ノ~YO