MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / cn_PnPoly

Method cn_PnPoly

annotation/AnnotationToMask.cpp:123–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123int AnnotationToMask::cn_PnPoly(const Point& P, const std::vector<Point>& V) const {
124 int cn = 0; // the crossing number counter
125
126 // loop through all edges of the polygon
127 for (int i = 0; i < V.size() - 1; i++) { // edge from V[i] to V[i+1]
128 if (((V[i].getY() <= P.getY()) && (V[i + 1].getY() > P.getY())) // an upward crossing
129 || ((V[i].getY() > P.getY()) && (V[i + 1].getY() <= P.getY()))) { // a downward crossing
130 // compute the actual edge-ray intersect x-coordinate
131 float vt = (float)(P.getY() - V[i].getY()) / (V[i + 1].getY() - V[i].getY());
132 if (P.getX() < V[i].getX() + vt * (V[i + 1].getX() - V[i].getX())) // P.x < intersect
133 ++cn; // a valid crossing of y=P.y right of P.x
134 }
135 }
136 return (cn & 1);
137}
138
139int AnnotationToMask::wn_PnPoly(const Point& P, const std::vector<Point>& V) const {
140 int wn = 0; // the winding number counter

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected