当前位置: 首页 > news >正文

网站开发技术及特点网络营销师月薪

网站开发技术及特点,网络营销师月薪,软件开发的公司,公司开通网站判断 一个点 ,判断是否在风格 stl 模型内部,或表面: 目录 1.方案一:使用vtkCellLocator FindClosestPoint 找到模型上距离给定点最近的一点,计算两点的距离 ,小于某一阈值 则认为此点在模型上; 2.方案二…

判断 一个点 ,判断是否在风格 stl 模型内部,或表面:

目录

1.方案一:使用vtkCellLocator  FindClosestPoint 找到模型上距离给定点最近的一点,计算两点的距离 ,小于某一阈值 则认为此点在模型上;

2.方案二 使用 vtkKdTreePointLocator

3.方案三 使用 vtkSelectEnclosedPoints


1.方案一:使用vtkCellLocator  FindClosestPoint 找到模型上距离给定点最近的一点,计算两点的距离 ,小于某一阈值 则认为此点在模型上;

vtkCellLocator本身是一个octree。典型的用法就是求最近的单元或者点

bool CheckPointInsidePolyData(vtkPolyData * poly, double* pt)
{bool inside=false; auto cellLocator = vtkSmartPointer<vtkCellLocator>::New();cellLocator->SetDataSet(poly);cellLocator->BuildLocator();auto assistCell = vtkSmartPointer<vtkGenericCell>::New();double closestPoint[3];//the coordinates of the closest point will be returned heredouble closestPointDist2; //the squared distance to the closest point will be returned herevtkIdType cellId; //the cell id of the cell containing the closest point will be returned hereint subId=-1;cellLocator->FindClosestPoint(point, closestPoint, assistCell, cellId, subId, closestPointDist2);if (-1!= subId&&closestPointDist2 < 0.001){return true;}return inside;
}

2.方案二 使用 vtkKdTreePointLocator

但这个只能找到最新的点,还需要自己判断一下距离

官方样例:

#include <vtkIdList.h>
#include <vtkKdTreePointLocator.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>int main(int, char*[])
{// Setup point coordinatesdouble x[3] = {1.0, 0.0, 0.0};double y[3] = {0.0, 1.0, 0.0};double z[3] = {0.0, 0.0, 1.0};vtkNew<vtkPoints> points;points->InsertNextPoint(x);points->InsertNextPoint(y);points->InsertNextPoint(z);vtkNew<vtkPolyData> polydata;polydata->SetPoints(points);// Create the treevtkNew<vtkKdTreePointLocator> kDTree;kDTree->SetDataSet(polydata);kDTree->BuildLocator();double testPoint[3] = {2.0, 0.0, 0.0};// Find the closest points to TestPointvtkIdType iD = kDTree->FindClosestPoint(testPoint);std::cout << "The closest point is point " << iD << std::endl;// Get the coordinates of the closest pointdouble closestPoint[3];kDTree->GetDataSet()->GetPoint(iD, closestPoint);std::cout << "Coordinates: " << closestPoint[0] << " " << closestPoint[1]<< " " << closestPoint[2] << std::endl;return EXIT_SUCCESS;
}

3.方案三 使用 vtkSelectEnclosedPoints

vtkSelectEnclosedPoints类可以判断标记点是否在封闭表面内。
vtkSelectEnclosedPoints是一个Filter,它计算所有输入点以确定它们是否位于封闭曲面中。过滤器生成一个(0,1)掩码(以vtkDataArray的形式),指示点是在提供的曲面的外部(掩码值=0)还是内部(掩码值=1)(输出vtkDataArray的名称是“SelectedPoints”。)
运行过滤器后,可以通过调用IsInside(ptId)方法来查询点是否在内部/外部。

样例:判断三个点是否在立方体内

注意:在立方体边上的点,不属于在立方体内部;

 CODE

#include <vtkVersion.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkCubeSource.h>
#include <vtkSmartPointer.h>
#include <vtkSelectEnclosedPoints.h>
#include <vtkIntArray.h>
#include <vtkDataArray.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>int main(int, char*[])
{vtkNew<vtkCubeSource> cubeSource;cubeSource->Update();vtkPolyData* cube = cubeSource->GetOutput();double testInside[3] = { 0.0, 0.0, 0.0 };double testOutside[3] = { 0.7, 0.0, 0.0 };double testBorderOutside[3] = { 0.5, 0.0, 0.0 };vtkNew<vtkPoints> points;points->InsertNextPoint(testInside);points->InsertNextPoint(testOutside);points->InsertNextPoint(testBorderOutside);vtkNew<vtkPolyData> pointsPolydata;pointsPolydata->SetPoints(points);//Points inside testvtkNew<vtkSelectEnclosedPoints> selectEnclosedPoints;selectEnclosedPoints->SetInputData(pointsPolydata);selectEnclosedPoints->SetSurfaceData(cube);selectEnclosedPoints->Update();for (unsigned int i = 0; i < 3; i++) {std::cout << "Point " << i << ": " << selectEnclosedPoints->IsInside(i) << std::endl;}vtkDataArray* insideArray = vtkDataArray::SafeDownCast(selectEnclosedPoints->GetOutput()->GetPointData()->GetArray("SelectedPoints"));for (vtkIdType i = 0; i < insideArray->GetNumberOfTuples(); i++) {std::cout << i << " : " << insideArray->GetComponent(i, 0) << std::endl;}//Cube mapper, actorvtkNew<vtkPolyDataMapper> cubeMapper;cubeMapper->SetInputConnection(cubeSource->GetOutputPort());vtkNew<vtkActor> cubeActor;cubeActor->SetMapper(cubeMapper);cubeActor->GetProperty()->SetOpacity(0.5);//First, apply vtkVertexGlyphFilter to make cells around points, vtk only render cells.vtkNew<vtkVertexGlyphFilter> vertexGlyphFilter;vertexGlyphFilter->AddInputData(pointsPolydata);vertexGlyphFilter->Update();vtkNew<vtkPolyDataMapper> pointsMapper;pointsMapper->SetInputConnection(vertexGlyphFilter->GetOutputPort());vtkNew<vtkActor> pointsActor;pointsActor->SetMapper(pointsMapper);pointsActor->GetProperty()->SetPointSize(5); pointsActor->GetProperty()->SetColor(1.0, 0.0, 0);//Create a renderer, render window, and interactorvtkNew<vtkRenderer> renderer;vtkNew<vtkRenderWindow> renderWindow;renderWindow->AddRenderer(renderer);vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;renderWindowInteractor->SetRenderWindow(renderWindow);// Add the actor to the scenerenderer->AddActor(cubeActor);renderer->AddActor(pointsActor);renderer->SetBackground(.0, 1, .0);renderWindow->Render();renderWindowInteractor->Start();return EXIT_SUCCESS;
}

输出:

Point 0: 1
Point 1: 0
Point 2: 0
0 : 1
1 : 0
2 : 0

http://www.hkea.cn/news/767842/

相关文章:

  • django做视频网站网络营销推广专家
  • 国外手做网站搜索引擎推广的关键词
  • 网站建设商标注册多少类目域名注册免费
  • 哪里有网站设计公司长沙网络公司最新消息
  • 试描述一下网站建设的基本流程百度怎么发布短视频
  • 我现在有域名怎么做网站搜索关键词热度
  • 海外如何 淘宝网站建设快速seo整站优化排行
  • 代还信用卡网站建设赣州seo顾问
  • 响应式网站建设推广开网店
  • 成都专业网站推广公司优化大师优化项目有
  • 怎么用wordpress搭建网站百度关键词排名点
  • 外挂网站模板域名搜索引擎入口
  • 手机网站开发 pdfseo搜索引擎优化工作内容
  • 上海中小网站建设洛阳seo博客
  • 南宁网站建设公司哪家专业搜索引擎优化包括
  • 新疆住房与建设厅网站新产品推广方式有哪些
  • 做网站站怎么赚钱网络营销模式有哪些?
  • 南通城市建设集团有限公司网站南京谷歌推广
  • 南通网站定制方案怎么查找关键词排名
  • 权大师的网站是哪个公司做的百度做个人简介多少钱
  • 烟台网站建设设计软文广告经典案例100字
  • 做微信用什么网站广州百度seo代理
  • 网站建设目标 优帮云跨境电商营销推广
  • 郑州华恩科技做网站怎么样竞价排名适合百度吗
  • flask做大型网站开发深圳seo博客
  • 合肥网站建设平台小程序怎么引流推广
  • 做网站被拘留免费找客源软件
  • 门户型网站建设百度seo快速提升排名
  • 印度做杂质的网站如何进行网络推广
  • 建设厅八大员兴安盟新百度县seo快速排名