vtk-mfc框架中显示坐标轴

本文介绍了使用VTK库绘制三维坐标轴的具体实现过程,包括窗口尺寸设置、交互器配置、相机视图调整以及坐标轴属性设置等。通过具体代码展示了如何创建并设置vtkTransformPolyDataFilter和vtkAxesActor来实现三维坐标轴的定制化显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

借鉴了vtk里WidgetsCxxTests的例子

vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
    vtkSmartPointer<vtkTransformPolyDataFilter>::New();
  vtkSmartPointer<vtkTransform> transform =
    vtkSmartPointer<vtkTransform>::New();
  transformFilter->SetTransform( transform );

 
  CRect rect;
  HWND hWnd = this->GetSafeHwnd();
  pvtkMFCWindow->GetClientRect(&rect);
  int cx,cy;
  cx=rect.Width();
  cy=rect.Height();


   pvtkMFCWindow->GetRenderWindow()->SetSize( cx, cy );

  vtkSmartPointer<vtkRenderWindowInteractor> iren =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  iren->SetRenderWindow( pvtkMFCWindow->GetRenderWindow() );


  // set up an interesting view
  //
  vtkCamera* camera = this->pvtkRenderer->GetActiveCamera();
  camera->SetViewUp( 0, 0, 1 );
  camera->SetFocalPoint( 0, 0, 0 );
  camera->SetPosition( 4.5, 4.5, 2.5 );
  this->pvtkRenderer->ResetCameraClippingRange();

 
  // this static function improves the appearance of the text edges
  // since they are overlaid on a surface rendering of the cube's faces
  //
  vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();

 

  vtkSmartPointer<vtkAxesActor> axes2 =
    vtkSmartPointer<vtkAxesActor>::New();

  // simulate a left-handed coordinate system
  //
  transform->Identity();
  //transform->RotateY(90);
  axes2->SetShaftTypeToCylinder();
  axes2->SetUserTransform( transform );
  axes2->SetXAxisLabelText( "x" );
  axes2->SetYAxisLabelText( "y" );
  axes2->SetZAxisLabelText( "z" );

  axes2->SetTotalLength( 0.5, 0.5, 0.5 );
  axes2->SetCylinderRadius( 0.500 * axes2->GetCylinderRadius() );
  axes2->SetConeRadius    ( 1.025 * axes2->GetConeRadius() );
  axes2->SetSphereRadius  ( 1.500 * axes2->GetSphereRadius() );

  vtkTextProperty* tprop = axes2->GetXAxisCaptionActor2D()->
    GetCaptionTextProperty();
  tprop->ItalicOn();
  tprop->ShadowOn();
  tprop->SetFontFamilyToTimes();

  axes2->GetYAxisCaptionActor2D()->GetCaptionTextProperty()->ShallowCopy( tprop );
  axes2->GetZAxisCaptionActor2D()->GetCaptionTextProperty()->ShallowCopy( tprop );

  // combine orientation markers into one with an assembly
  //
  vtkSmartPointer<vtkPropAssembly> assembly =
    vtkSmartPointer<vtkPropAssembly>::New();
  assembly->AddPart( axes2 );
 // assembly->AddPart( cube );

   this->pvtkRenderer->AddViewProp( axes2 );

 
 // iren->Initialize();
  pvtkMFCWindow->GetRenderWindow()->Render();
 

  //iren->Start();

  return EXIT_SUCCESS;

转载于:https://www.cnblogs.com/xiaohaha/archive/2010/02/20/1669836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值