VTK/ExamplesBoneyard/Cxx/PolyData/AddLineToPolydata

原文转自:

http://www.paraview.org/Wiki/VTK/ExamplesBoneyard/Cxx/PolyData/AddLineToPolydata


This example shows how to add a line to a polydata.

AddLineToPolydata.cxx

#include <vtkSmartPointer.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkLine.h>
#include <vtkPolyData.h>
#include <vtkXMLPolyDataWriter.h>
 
int main(int, char *[])
{
  // Create two points
  double p0[3];
  p0[0] = 1;
  p0[1] = 0;
  p0[2] = 0;
 
  double p1[3];
  p1[0] = 0;
  p1[1] = 1;
  p1[2] = 0;
 
  // Add the two poitns to a vtkPoints object
  vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
  pts->InsertNextPoint(p0);
  pts->InsertNextPoint(p1);
 
  // Create a line between the two points
  vtkSmartPointer<vtkLine> line = 
    vtkSmartPointer<vtkLine>::New();
  line->GetPointIds()->SetId(0,0); //the SetId(A,B) call is the following: 
  //A = the id of the point relative to the line - this can only be 0 or 1. 
  //B = the index into the vtkPoints object of the point that you would like to set the Ath point to.
  line->GetPointIds()->SetId(1,1);
 
  // Create a cell array to store the line in
  vtkSmartPointer<vtkCellArray> lines = 
    vtkSmartPointer<vtkCellArray>::New();
  lines->InsertNextCell(line);
 
  // Create a polydata to store everything in
  vtkSmartPointer<vtkPolyData> pdata = 
    vtkSmartPointer<vtkPolyData>::New();
 
  // Add the points to the dataset
  pdata->SetPoints(pts);
 
  // Add the lines to the dataset
  pdata->SetLines(lines);
 
  // Write the file
  vtkSmartPointer<vtkXMLPolyDataWriter> writer = 
    vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetInput(pdata);
  writer->SetFileName("Line.vtp");
  writer->Write();
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(AddLineToPolydata)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
add_executable(AddLineToPolydata MACOSX_BUNDLE AddLineToPolydata)
 
if(VTK_LIBRARIES)
  target_link_libraries(AddLineToPolydata ${VTK_LIBRARIES})
else()
  target_link_libraries(AddLineToPolydata vtkHybrid)
endif()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值