[VTK]vtkAngleWidget角度测量设置线颜色color

上次

http://www.cnblogs.com/dawnWind/archive/2013/05/03/3D_10.html

通过继承类对vtkAngleWidget的点进行初始化,这次想修改测量时候显示的直线颜色。

Update PS:What a shame, this codes is easy....

刚刚发现,这个情况与初始化三个点是不同的。三个点是需要通过representation设置,当时对于这里的

边以及弧来说,程序里面本身就已经有,而且也提供了直接返回的函数,因此可以直接设置--!

比如:this->GetRay1()->GetProperty()->SetColor(widgetColor);

         this->GetRay1()->GetProperty()->SetColor(widgetColor);
         this->GetRay1()->GetProperty()->SetLineWidth(2);
         // has the same result
         this->Ray2->GetProperty()->SetColor(widgetColor);
         this->Ray2->GetProperty()->SetLineWidth(2);

 

效果:

因此下面的文字可以不用你看了...

----------------Not Recommend------------

通过对vtkAngleRepresentation3D的分析发现没有内置的函数可以进行颜色设置。

还是通过源码的分析,对于一个angleWidget用于测量的是3个点两条线。

而在代码里面是这样呈现的:使用lineSource+mapper+actor对线进行显示。

vtkLineSource *Line1Source;
vtkLineSource *Line2Source;
vtkPolyDataMapper *Line1Mapper;
vtkPolyDataMapper *Line2Mapper;
vtkActor *Ray1;
vtkActor *Ray2;

而在实现里面是设置为红色的(1.0, 0.0, 0.0)

  // Represent the line1
  this->Line1Source = vtkLineSource::New();
  this->Line1Source->SetResolution(5);
  this->Line1Mapper = vtkPolyDataMapper::New();
  this->Line1Mapper->SetInput(this->Line1Source->GetOutput());
  this->Ray1 = vtkActor::New();
  this->Ray1->SetMapper(this->Line1Mapper);
  this->Ray1->GetProperty()->SetColor( 1.0, 0.0, 0.0 );

由于可以通过actor设置其颜色,那么这里也可以这样用。

class vtkAngleRepresentation3DWithPointRepresentation: public vtkAngleRepresentation3D
{
    public:
     static vtkAngleRepresentation3DWithPointRepresentation *New()
     {
          return new vtkAngleRepresentation3DWithPointRepresentation;
     }
     void initialPointRepresentation()
     {
         this->Point1Representation = vtkPointHandleRepresentation3D::New();
         this->Point2Representation = vtkPointHandleRepresentation3D::New();
         this->CenterRepresentation = vtkPointHandleRepresentation3D::New();
     }
     void SetTheColorOfRays(double point[3])
     {
         this->Ray1->GetProperty()->SetColor(point);
         this->Ray2->GetProperty()->SetColor(point);
     }
     void SetThePoint1WordPosition(double point[3])
     {
         this->GetPoint1Representation()->SetWorldPosition(point);
     }
     void SetThePoint2WordPosition(double point[3])
     {
         this->GetPoint2Representation()->SetWorldPosition(point);
     }
     void SetTheCenterWordPosition(double point[3])
     {
         this->GetCenterRepresentation()->SetWorldPosition(point);
     }
};

因此如下的SetTheColorOfRays函数,然后在程序里面调用就可,比如设置(1.0, 1.0, 1.0)

同理可以对其中涉及的弧、文字进行颜色的设置:)

PS:看来对于开源库来说,其中不完备或不能完全达到需求是常有的,自己就可在这基础上进行一些修改。

 

转载于:https://www.cnblogs.com/dawnWind/archive/2013/05/23/3D_12.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个用VTK绘制带箭头的可设置角度长度的直线的示例代码: ```python import vtk # 创建箭头 arrowSource = vtk.vtkArrowSource() arrowSource.SetShaftRadius(0.02) arrowSource.SetTipLength(0.2) # 创建线 lineSource = vtk.vtkLineSource() lineSource.SetPoint1(0,0,0) lineSource.SetPoint2(1,1,0) # 创建箭头mapper和actor arrowMapper = vtk.vtkPolyDataMapper() arrowMapper.SetInputConnection(arrowSource.GetOutputPort()) arrowActor = vtk.vtkActor() arrowActor.SetMapper(arrowMapper) # 创建线mapper和actor lineMapper = vtk.vtkPolyDataMapper() lineMapper.SetInputConnection(lineSource.GetOutputPort()) lineActor = vtk.vtkActor() lineActor.SetMapper(lineMapper) # 计算箭头位置和方向 arrowPosition = lineSource.GetPoint2() arrowDirection = [lineSource.GetPoint2()[0] - lineSource.GetPoint1()[0], lineSource.GetPoint2()[1] - lineSource.GetPoint1()[1], lineSource.GetPoint2()[2] - lineSource.GetPoint1()[2]] arrowLength = vtk.vtkMath.Normalize(arrowDirection) arrowActor.SetPosition(arrowPosition) arrowActor.SetOrientation(vtk.vtkMath.RotationBetweenVectors([1,0,0], arrowDirection)) # 设置箭头长度 arrowActor.SetScale(arrowLength, arrowLength, arrowLength) # 创建渲染器和窗口 renderer = vtk.vtkRenderer() renderer.AddActor(lineActor) renderer.AddActor(arrowActor) renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) # 创建交互器 interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renderWindow) # 开始渲染和交互 renderWindow.Render() interactor.Start() ``` 这个示例代码可以绘制一条从原点到(1,1,0)的直线,并在直线末端添加一个长度和方向可调的箭头。箭头方向和直线方向相同,箭头长度为直线长度的倍数。可以通过调整`lineSource.SetPoint1()`和`lineSource.SetPoint2()`来改变直线的起点和终点,通过调整`arrowSource.SetTipLength()`来改变箭头长度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值