显示顶点的法向量

在顶点法方向处显示圆锥

这里写图片描述

关键代码:

    //改变polydata的颜色
    vtkSmartPointer<vtkElevationFilter> colorIt =
      vtkSmartPointer<vtkElevationFilter>::New();
    colorIt->SetInputConnection(sphere->GetOutputPort());
    colorIt->SetLowPoint(0,0,-1);
    colorIt->SetHighPoint(0,0,1);

    //延顶点法向量生成圆锥
    vtkNew<vtkGlyph3D> glyph;
    glyph->SetInputConnection(colorIt->GetOutputPort());
    glyph->SetSourceConnection(cone->GetOutputPort());
    glyph->SetVectorModeToUseNormal();
    glyph->SetScaleModeToScaleByVector();
    glyph->SetColorModeToColorByScale ();
    glyph->SetScaleFactor(0.25);

    //显示线及平滑处理
    sphereActor->GetProperty()->SetEdgeVisibility(true);
    sphereActor->GetProperty()->SetInterpolationToPhong();

demo:
https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/Mace/
https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/FlatVersusGouraud/
https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/ColoredSphere/
https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/CameraBlur/

估计顶点的法向量,并显示顶点的法向量

原文地址:
https://kitware.github.io/vtk-examples/site/Cxx/Points/NormalEstimation/

    void MakeGlyphs(vtkPolyData* src, double size, vtkGlyph3D* glyph)
    {
      // Source for the glyph filter
      vtkNew<vtkArrowSource> arrow;
      arrow->SetTipResolution(16);
      arrow->SetTipLength(0.3);
      arrow->SetTipRadius(0.1);

      glyph->SetSourceConnection(arrow->GetOutputPort());
      glyph->SetInputData(src);
      glyph->SetVectorModeToUseNormal();
      glyph->SetScaleModeToScaleByVector();
      glyph->SetScaleFactor(size);
      glyph->OrientOn();
      glyph->Update();
    }
    void ShowPointsNormal(){
        vtkNew<vtkPoints> selectionPoints;
        QList<int> keys = m_points.keys();
        for(int i=0;i<m_points.size();i++){
            QVector3D tmpPos = m_points.value(keys.at(i));
            selectionPoints->InsertPoint(i, tmpPos.x(),tmpPos.y(),tmpPos.z());
        }
        vtkNew<vtkPolyData> myData;
        myData->SetPoints(selectionPoints);
        myData->Modified();

        vtkNew<vtkPCANormalEstimation> normals;
        normals->SetInputData(myData);
        normals->Update();

        vtkNew<vtkNamedColors> colors;
        vtkNew<vtkGlyph3D> glyph3D;
        MakeGlyphs(normals->GetOutput(), 2.0, glyph3D.GetPointer());

        vtkNew<vtkPolyDataMapper> glyph3DMapper;
        glyph3DMapper->SetInputConnection(glyph3D->GetOutputPort());

        vtkNew<vtkActor> glyph3DActor;
        glyph3DActor->SetMapper(glyph3DMapper);
        glyph3DActor->GetProperty()->SetDiffuseColor(
            colors->GetColor3d("Banana").GetData());

        this->GetDefaultRenderer()->AddActor(glyph3DActor);
        this->GetDefaultRenderer()->GetRenderWindow()->Render();
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力减肥的小胖子5

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值