大家好。我正在尝试用python学习VTK。现在我遇到了一个问题。我无法将下面的案例转换为python代码,而且我不知道这些参数代表什么。我得到的是多边形对象,下面的代码用于确定给定点是否在我绘制的多边形范围内。源链接enter link description here,我无法转换的原因是它位于polygon->ComputeNormal(polygon->GetPoints()->GetNumberOfPoints(),
static_cast<double*>(polygon->GetPoints()->GetData()->GetVoidPointer(0)), n);
中,我使用python获取多边形->;GetPoints()->;GetData()->;GetVoidPointer(0))以获取无
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolygon.h>
int main(int, char *[])
{
// Create the polygon
vtkSmartPointer<vtkPolygon> polygon =
vtkSmartPointer<vtkPolygon>::New();
polygon->GetPoints()->InsertNextPoint(0.0, 0.0, 0.0);
polygon->GetPoints()->InsertNextPoint(1.0, 0.0, 0.0);
polygon->GetPoints()->InsertNextPoint(1.0, 1.0, 0.0);
polygon->GetPoints()->InsertNextPoint(0.0, 1.0, 0.0);
double testIn[3] = {0.5, 0.5, 0.0};
double testOut[3] = {2.0, 0.5, 0.0};
double n[3];
polygon->ComputeNormal(polygon->GetPoints()->GetNumberOfPoints(),
static_cast<double*>(polygon->GetPoints()->GetData()->GetVoidPointer(0)), n);
double bounds[6];
polygon->GetPoints()->GetBounds(bounds);
std::cout << "testIn in polygon? " << polygon->PointInPolygon(testIn,
polygon->GetPoints()->GetNumberOfPoints(), static_cast<double*>(
polygon->GetPoints()->GetData()->GetVoidPointer(0)), bounds, n) << std::endl;
std::cout << "testOut in polygon? " << polygon->PointInPolygon(testOut,
polygon->GetPoints()->GetNumberOfPoints(), static_cast<double*>(
polygon->GetPoints()->GetData()->GetVoidPointer(0)), bounds, n) << std::endl;
/*
std::cout << "New functions:" << std::endl;
std::cout << "testIn in polygon? " << polygon->PointInPolygon(testIn) << std::endl;
std::cout << "testOut in polygon? " << polygon->PointInPolygon(testOut) << std::endl;
*/
return EXIT_SUCCESS;
}
/**
* Determine whether point is inside polygon. Function uses ray-casting
* to determine if point is inside polygon. Works for arbitrary polygon shape
* (e.g., non-convex). Returns 0 if point is not in polygon; 1 if it is.
* Can also return -1 to indicate degenerate polygon.
*/
static int PointInPolygon(double x[3], int numPts, double *pts,
double bounds[6], double n[3]);
目前没有回答
相关问题 更多 >
编程相关推荐