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

Method SamplePolygon

Filters/Modeling/vtkPolyDataPointSampler.cxx:322–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320 }
321
322 void SamplePolygon(vtkIdType npts, const vtkIdType* pts) override
323 {
324 // Specialize for quads
325 if (npts == 4)
326 {
327 double x0[3], x1[3], x2[3], x3[4];
328 this->InPts->GetPoint(pts[0], x0);
329 this->InPts->GetPoint(pts[1], x1);
330 this->InPts->GetPoint(pts[2], x2);
331 this->InPts->GetPoint(pts[3], x3);
332
333 double l1 = vtkMath::Distance2BetweenPoints(x0, x1);
334 double l2 = vtkMath::Distance2BetweenPoints(x0, x3);
335 if (l1 > this->Distance2 || l2 > this->Distance2)
336 {
337 vtkIdType pId;
338 double s, t, x[3];
339 if (this->InPD)
340 {
341 this->QuadIds->SetId(0, pts[0]);
342 this->QuadIds->SetId(1, pts[1]);
343 this->QuadIds->SetId(2, pts[2]);
344 this->QuadIds->SetId(3, pts[3]);
345 }
346
347 l1 = sqrt(l1);
348 l2 = sqrt(l2);
349 int n1 = static_cast<int>(l1 / this->Distance) + 2;
350 int n2 = static_cast<int>(l2 / this->Distance) + 2;
351 n1 = (n1 < 3 ? 3 : n1); // make sure there is at least one point
352 n2 = (n2 < 3 ? 3 : n2);
353 for (vtkIdType j = 1; j < (n2 - 1); j++)
354 {
355 t = static_cast<double>(j) / (n2 - 1);
356 for (vtkIdType i = 1; i < (n1 - 1); i++)
357 {
358 s = static_cast<double>(i) / (n1 - 1);
359 x[0] = x0[0] + s * (x1[0] - x0[0]) + t * (x3[0] - x0[0]);
360 x[1] = x0[1] + s * (x1[1] - x0[1]) + t * (x3[1] - x0[1]);
361 x[2] = x0[2] + s * (x1[2] - x0[2]) + t * (x3[2] - x0[2]);
362 pId = this->OutPts->InsertNextPoint(x);
363 if (this->InPD)
364 {
365 this->QuadWeights[0] = (1.0 - s) * (1.0 - t);
366 this->QuadWeights[1] = s * (1.0 - t);
367 this->QuadWeights[2] = s * t;
368 this->QuadWeights[3] = (1.0 - s) * t;
369 this->OutPD->InterpolatePoint(this->InPD, pId, this->QuadIds, this->QuadWeights);
370 }
371 }
372 }
373 }
374 } // if quad
375
376 // Otherwise perform simple fan triangulation, and process each triangle
377 // for polygons with more than 4 sides. Also have to sample fan edges if
378 // GenerateEdgePoints is enabled.
379 else

Callers

nothing calls this directly

Calls 9

SampleEdgeMethod · 0.95
SampleTriangleMethod · 0.95
sqrtFunction · 0.50
GetPointMethod · 0.45
SetIdMethod · 0.45
InsertNextPointMethod · 0.45
InterpolatePointMethod · 0.45
IsEdgeMethod · 0.45
InsertEdgeMethod · 0.45

Tested by

no test coverage detected