锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

VTK 设置点的标量属性

时间:2023-11-06 18:37:01 rwi电阻br4x121rok

#include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include   #include  #include  #include  #include  #include  #include  #include  #include  #include   #include  #include  #include  #include  #include   #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include   #include  #include  #include  #include  using namespace std;  #include    VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); VTK_MODULE_INIT(vtkRenderingFreeType);  typedef vtkSmartPointer Vertices;  int main() {  //加载数据  std::string target_filename = "D:\\tooth_tata_lvsilin\\IOS_single_o\\IOS11_rb.obj";  vtkSmartPointer target_reader = vtkSmartPointer::New();  target_reader->SetFileName(target_filename.c_str());  target_reader->Update();  vtkSmartPointer grid0 = target_reader->GetOutput();   // 提取边界边  vtkSmartPointer boundaryEdges = vtkSmartPointer::New();  boundaryEdges->SetInputData(grid0);  boundaryEdges->BoundaryEdgesOn();  boundaryEdges->FeatureEdgesOff();  boundaryEdges->ManifoldEdgesOff();  boundaryEdges->NonManifoldEdgesOff();  boundaryEdges->Update();    去除边  //vtkSmartPointer stripper = vtkSmartPointer::New();  //stripper->SetInputConnection(boundaryEdges->GetOutputPort());  //stripper->JoinContiguousSegmentsOn();  //stripper->Update();    去除重合点  //vtkSmartPointer cleanPolyData = vtkSmartPointer::New();  //cleanPolyData->SetInputConnection(stripper->GetOutputPort());  //cleanPolyData->ConvertPolysToLinesOff();  //cleanPolyData->ConvertStripsToPolysOff();  //cleanPolyData->Update();   vtkSmartPointer grid = boundaryEdges->GetOutput();   获取边界点的坐标  //vtkSmartPointer pts = vtkSmartPointer::New();  //vtkPoints *pt = boundaryEdges->GetOutput()->GetPoints();  //for (int i = 0; i < pt->GetNumberOfPoints();   i) {  // double *p = pt->GetPoint(i);  // pts->InsertNextPoint(p);  // //std::cout << p[0] << " "<< p[1]<<" "<< p[2]< polyData = vtkSmartPointer::New();  polyData->SetPoints(pts);*/  //polyData->SetVerts(vertices);   //定义一个标量  vtkSmartPointer colors = vtkSmartPointer::New();  for (int i = 0; i < grid->GetNumberOfPoints(); i  )  {   colors->SetNumberOfValues(grid->GetNumberOfPoints());   colors->SetValue(i, 255);   grid->GetPointData()->SetScalars(colors);  }   //定义标量,添加点数据的标量值,标量值为1  vtkSmartPointer colors0 = vtkSmartPointer::New();  for (int i = 0; i < grid0->GetNumberOfPoints(); i  )  {   colors0->SetNumberOfValues(grid0->GetNumberOfPoints());   colors0->SetValue(i, 1);   //首先获取多边形数据的点数据指针,然后设置该点数据的标量属性值   grid0->GetPointData()->SetScalars(colors0);  }    for (int i = 0; i < grid->GetNumberOfPoints(); i  )  {   double weight = vtkDoubleArray::SafeDownCast(grid->GetPointData()->GetScalars())->GetValue(i);///输出索引号为i点的标量值   if (weight == 255) {    vtkIdType point_ind = i;    std::cout << "double weight: " << point_ind << std::endl;    }  }   //vtkSmartPointer mapper = vtkSmartPointer::New();  //mapper->SetInputData(grid);  //mapper->SetScalarRange(0, 5);  //mapper->SetLookupTable(lut);   //vtkSmartPointer actor = vtkSmartPointer::Ne();
	//actor->SetMapper(mapper);
	actor->GetProperty()->SetPointSize(3);

	//vtkSmartPointer render = vtkSmartPointer::New();
	//render->AddActor(actor);
	//render->SetBackground(0.0, 0.0, 0.0);

	//vtkSmartPointer rw = vtkSmartPointer::New();
	//rw->AddRenderer(render);
	//rw->SetSize(320, 320);

	//vtkSmartPointer rwi = vtkSmartPointer::New();
	//rwi->SetRenderWindow(rw);
	//rwi->Start();

	return 0;

}

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章