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

Method ClipPlotData

Rendering/Annotation/vtkXYPlotActor.cxx:2473–2589  ·  view source on GitHub ↗

------------------------------------------------------------------------------ This assumes that there are multiple polylines

Source from the content-addressed store, hash-verified

2471//------------------------------------------------------------------------------
2472// This assumes that there are multiple polylines
2473void vtkXYPlotActor::ClipPlotData(int* pos, int* pos2, vtkPolyData* pd)
2474{
2475 vtkPoints* points = pd->GetPoints();
2476 vtkPoints* newPoints;
2477 vtkCellArray* lines = pd->GetLines();
2478 vtkCellArray *newLines, *newVerts;
2479 vtkIdType numPts = pd->GetNumberOfPoints();
2480 vtkIdType npts = 0;
2481 vtkIdType newPts[2];
2482 const vtkIdType* pts = nullptr;
2483 vtkIdType i, id;
2484 int j;
2485 double x1[3], x2[3], px[3], n[3], xint[3], t;
2486 double p1[2], p2[2];
2487
2488 p1[0] = (double)pos[0];
2489 p1[1] = (double)pos[1];
2490 p2[0] = (double)pos2[0];
2491 p2[1] = (double)pos2[1];
2492
2493 newPoints = vtkPoints::New();
2494 newPoints->Allocate(numPts);
2495 newVerts = vtkCellArray::New();
2496 newVerts->AllocateCopy(lines);
2497 newLines = vtkCellArray::New();
2498 newLines->AllocateCopy(lines);
2499 int* pointMap = new int[numPts];
2500 for (i = 0; i < numPts; i++)
2501 {
2502 pointMap[i] = -1;
2503 }
2504
2505 // Loop over polyverts eliminating those that are outside
2506 for (lines->InitTraversal(); lines->GetNextCell(npts, pts);)
2507 {
2508 // loop over verts keeping only those that are not clipped
2509 for (i = 0; i < npts; i++)
2510 {
2511 points->GetPoint(pts[i], x1);
2512
2513 if (x1[0] >= p1[0] && x1[0] <= p2[0] && x1[1] >= p1[1] && x1[1] <= p2[1])
2514 {
2515 id = newPoints->InsertNextPoint(x1);
2516 pointMap[i] = id;
2517 newPts[0] = id;
2518 newVerts->InsertNextCell(1, newPts);
2519 }
2520 }
2521 }
2522
2523 // Loop over polylines clipping each line segment
2524 for (lines->InitTraversal(); lines->GetNextCell(npts, pts);)
2525 {
2526 // loop over line segment making up the polyline
2527 for (i = 0; i < (npts - 1); i++)
2528 {
2529 points->GetPoint(pts[i], x1);
2530 points->GetPoint(pts[i + 1], x2);

Callers 1

CreatePlotDataMethod · 0.95

Calls 15

AllocateCopyMethod · 0.80
SetVertsMethod · 0.80
SetLinesMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
GetPointsMethod · 0.45
GetLinesMethod · 0.45
GetNumberOfPointsMethod · 0.45
AllocateMethod · 0.45
InitTraversalMethod · 0.45
GetNextCellMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected