34 std::vector<point_t> points;
51 if( points.size() < 4 )
52 throw std::runtime_error(
"Too few points in points");
55 for(
const auto &p : points ) {
65 pointOutside.x = c00.x - 0.5*(c11.x-c00.x);
66 pointOutside.x = c00.y - (c11.y-c00.y);
83 auto prev = points.begin();
85 while( next != points.end() ) {
86 ret += hasIntersection( p1, pointOutside, *prev, *next );
102 std::ifstream f( filename );
104 throw std::runtime_error(
"Gate2D::readFromAsciiFile(): Couldnot open the file." );
106 unsigned int row = 0;
110 std::string s_line, s_tmp;
113 std::getline( f, s_line );
115 tmp = sscanf( s_line.c_str(),
" %lf %lf", &x, &y );
117 gate.points.push_back( {x,y} );
119 if( tmp != 2 && tmp != 0 && tmp != EOF ) {
120 std::cerr <<
"Gate2D::readFromAsciiFile(): \n"
121 <<
" Error on file \'" << filename <<
"\' on line " << row <<
"!\n"
122 <<
" Line \'" << s_line <<
"\'\n"
123 <<
" tmp = " << tmp <<
"\n";
124 throw std::runtime_error(
"Syntax error when reading Gate2D from an ascii file" );
127 if( gate.points.size() < 3 )
128 throw std::runtime_error(
"Gate2D: Too few points in polygon." );
129 gate.points.push_back( gate.points.front() );
136 static int hasIntersection( point_t p0, point_t p1, point_t p2, point_t p3 ) noexcept {
137 const point_t s1{ p1.x - p0.x, p1.y - p0.y };
138 const point_t s2{ p3.x - p2.x, p3.y - p2.y };
141 (-s1.y * (p0.x - p2.x) + s1.x * (p0.y - p2.y)) / (-s2.x * s1.y + s1.x * s2.y),
142 ( s2.x * (p0.y - p2.y) - s2.y * (p0.x - p2.x)) / (-s2.x * s1.y + s1.x * s2.y) };
144 return st.x >= 0 && st.x <= 1 && st.y >=0 && st.y <= 1;
Definition: mainpage.dox:6
Point type.
Definition: Gate2D.hpp:27
Defines 2D polygon for 2D gating.
Definition: Gate2D.hpp:23
static Gate2D createFromAsciiFile(const std::string &filename)
Reads the polygon from a file.
Definition: Gate2D.hpp:100
bool operator()(double x, double y) const noexcept
Tests if a given point is inside the gate.
Definition: Gate2D.hpp:77
void update()
updates the other important fields after modifying points.
Definition: Gate2D.hpp:50