点信息标注

编程入门 行业动态 更新时间:2024-10-20 07:39:32

点<a href=https://www.elefans.com/category/jswz/34/1770440.html style=信息标注"/>

点信息标注


开发环境:

  1. Windows 11 家庭中文版
  2. Microsoft Visual Studio Community 2019
  3. VTK-9.3.0.rc0
  4. vtk-example
  5. 参考代码

demo解决问题:点附近创建左边或其他信息,且信息面板显示状态不受相机缩放、旋转影响


prj name: BillboardTextActor3D

#include <vtkActor.h>
#include <vtkBillboardTextActor3D.h>
#include <vtkMinimalStandardRandomSequence.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkTextProperty.h>#include <iostream>
#include <sstream>
#include <string>namespace {
void ActorCallback(vtkObject* caller, long unsigned int vtkNotUsed(eventId),void* clientData, void* vtkNotUsed(callData))
{auto textActor = static_cast<vtkBillboardTextActor3D*>(clientData);auto actor = static_cast<vtkActor*>(caller);std::ostringstream label;label << std::setprecision(3) << actor->GetPosition()[0] << ", "<< actor->GetPosition()[1] << ", " << actor->GetPosition()[2]<< std::endl;textActor->SetPosition(actor->GetPosition());textActor->SetInput(label.str().c_str());
}void RandomPosition(double p[3], double const& min_r, double const& max_r,vtkMinimalStandardRandomSequence* rng);} // namespaceint main(int, char*[])
{vtkNew<vtkNamedColors> colors;// For testingvtkNew<vtkMinimalStandardRandomSequence> rng;// rng->SetSeed(8775070);rng->SetSeed(5127);// Create a renderervtkNew<vtkRenderer> renderer;renderer->SetBackground(colors->GetColor3d("DarkSlateGray").GetData());// Create a render windowvtkNew<vtkRenderWindow> renderWindow;renderWindow->AddRenderer(renderer);renderWindow->SetWindowName("BillboardTextActor3D");// Create an interactorvtkNew<vtkRenderWindowInteractor> renderWindowInteractor;renderWindowInteractor->SetRenderWindow(renderWindow);// Create a spherevtkNew<vtkSphereSource> sphereSource;//公用一个data sourcesphereSource->SetCenter(0.0, 0.0, 0.0);sphereSource->SetRadius(1.0);auto min_r = -10.0;auto max_r = 10.0;for (auto i = 0; i < 10; ++i){if (i == 0){// Create an actor representing the originvtkNew<vtkPolyDataMapper> mapper;mapper->SetInputConnection(sphereSource->GetOutputPort());vtkNew<vtkActor> actor;actor->SetMapper(mapper);actor->SetPosition(0, 0, 0);actor->GetProperty()->SetColor(colors->GetColor3d("Peacock").GetData());renderer->AddActor(actor);}// Create a mappervtkNew<vtkPolyDataMapper> mapper;mapper->SetInputConnection(sphereSource->GetOutputPort());// Create an actorvtkNew<vtkActor> actor;actor->SetMapper(mapper);actor->SetPosition(0, 0, 0);actor->GetProperty()->SetColor(colors->GetColor3d("MistyRose").GetData());// Setup the text and add it to the renderervtkNew<vtkBillboardTextActor3D> textActor;textActor->SetInput("");textActor->SetPosition(actor->GetPosition());textActor->GetTextProperty()->SetFontSize(12);textActor->GetTextProperty()->SetColor(colors->GetColor3d("Gold").GetData());textActor->GetTextProperty()->SetJustificationToCentered();renderer->AddActor(actor);renderer->AddActor(textActor);// If you want to use a callback, do this:// vtkNew<vtkCallbackCommand> actorCallback;// actorCallback->SetCallback(ActorCallback);// actorCallback->SetClientData(textActor);// actor->AddObserver(vtkCommand::ModifiedEvent, actorCallback);// Otherwise do this:double position[3];RandomPosition(position, min_r, max_r, rng);//随机生成坐标actor->SetPosition(position);std::ostringstream label;label << std::setprecision(3) << actor->GetPosition()[0] << ", "<< actor->GetPosition()[1] << ", " << actor->GetPosition()[2]<< std::endl;textActor->SetPosition(actor->GetPosition());textActor->SetInput(label.str().c_str());}renderWindow->Render();renderWindow->SetWindowName("BillboardTextActor3D");renderWindowInteractor->Start();return EXIT_SUCCESS;
}namespace {void RandomPosition(double p[3], double const& min_r, double const& max_r,vtkMinimalStandardRandomSequence* rng)
{for (auto i = 0; i < 3; ++i){p[i] = rng->GetRangeValue(min_r, max_r);rng->Next();}
}} // namespace

更多推荐

点信息标注

本文发布于:2023-11-15 17:09:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!