MCPcopy Create free account
hub / github.com/Kitware/VTK / PolygonIntersectsBBox

Method PolygonIntersectsBBox

Common/DataModel/vtkPlanesIntersection.cxx:282–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280//
281
282int vtkPlanesIntersection::PolygonIntersectsBBox(double bounds[6], vtkPoints* pts)
283{
284 // a bogus vtkPlanesIntersection object containing only one plane
285
286 vtkPlanesIntersection* pi = vtkPlanesIntersection::New();
287
288 pi->SetRegionVertices(pts);
289
290 vtkPoints* Box = vtkPoints::New();
291 Box->SetNumberOfPoints(8);
292 Box->SetPoint(0, bounds[0], bounds[2], bounds[4]);
293 Box->SetPoint(1, bounds[1], bounds[2], bounds[4]);
294 Box->SetPoint(2, bounds[1], bounds[3], bounds[4]);
295 Box->SetPoint(3, bounds[0], bounds[3], bounds[4]);
296 Box->SetPoint(4, bounds[0], bounds[2], bounds[5]);
297 Box->SetPoint(5, bounds[1], bounds[2], bounds[5]);
298 Box->SetPoint(6, bounds[1], bounds[3], bounds[5]);
299 Box->SetPoint(7, bounds[0], bounds[3], bounds[5]);
300
301 int intersects = -1;
302
303 // 1. Does Box intersect the polygon's bounding box?
304
305 if (pi->IntersectsBoundingBox(Box) == 0)
306 {
307 intersects = 0;
308 }
309
310 // 2. If so, does Box entirely contain the polygon's bounding box?
311
312 else if (pi->EnclosesBoundingBox(Box) == 1)
313 {
314 intersects = 1;
315 }
316
317 if (intersects == -1)
318 {
319
320 // 3. If not, determine whether the Box intersects the plane of the polygon
321
322 vtkPoints* origin = vtkPoints::New();
323 origin->SetNumberOfPoints(1);
324 origin->SetPoint(0, pts->GetPoint(0));
325
326 vtkFloatArray* normal = vtkFloatArray::New();
327 normal->SetNumberOfComponents(3);
328 normal->SetNumberOfTuples(1);
329
330 // find 3 points that are not co-linear and compute a normal
331
332 double nvec[3], p0[3], p1[3], pp[3];
333
334 int npts = pts->GetNumberOfPoints();
335
336 pts->GetPoint(0, p0);
337 pts->GetPoint(1, p1);
338
339 for (int p = 2; p < npts; p++)

Callers

nothing calls this directly

Calls 15

SetRegionVerticesMethod · 0.80
IntersectsBoundingBoxMethod · 0.80
EnclosesBoundingBoxMethod · 0.80
SetPlaneEquationsMethod · 0.80
EvaluateFacePlaneMethod · 0.80
IntersectsProjectionMethod · 0.80
ComputeNormalFunction · 0.70
DeleteMethod · 0.65
NewFunction · 0.50
SetNumberOfPointsMethod · 0.45
SetPointMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected