在顶点法方向处显示圆锥
关键代码:
//改变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();
}