64 for(
unsigned int i=0;i<
m_polygon.size();i++)
70 if((b.
x-a.
x)*(p.
y-a.
y)<(p.
x-a.
x)*(b.
y-a.
y))
76 if((b.
x-a.
x)*(p.
y-a.
y)>(p.
x-a.
x)*(b.
y-a.
y))
90 for(
unsigned int i=0;i<count;i++)
153 for(
unsigned int i=0;i<
m_polygon.size();i++)
163 for (
unsigned int i = 0; i <
m_polygon.size(); i++)
174 for(
unsigned int i=0;i<
m_polygon.size();i++)
190 unsigned int count=oldPoly.size();
192 for(
unsigned int i=0;i<count;i++)
197 double distance=
norm(p2-p1);
198 if(distance>max_distance)
201 double currentDistance=max_distance;
202 while(currentDistance<distance)
206 currentDistance+=max_distance;
219 for(
unsigned int i=1;i<
m_polygon.size();i++)
243 return p.
x>=r.left();
245 return p.
x<=r.right();
249 return p.
y<=r.bottom();
268 a=(q.
y-p.
y)/(q.
x-p.
x);
307 for(
unsigned int i=0;i<polygon.size();i++)
316 newPolygon.push_back(p);
362 std::vector<hugin_utils::FDiff2D> intersections;
366 return intersections;
369 double dotproduct=p2.
x*slope.
x+p2.
y*slope.
y;
387 for(std::set<double>::const_iterator it=t.begin();it!=t.end();++it)
389 intersections.push_back(p+slope*(*it));
392 return intersections;
415 double maxDistance=5.0;
420 double angle=atan2(p.
y-center.
y,p.
x-center.
x);
421 double final_angle=atan2(s.
y-center.
y,s.
x-center.
x);
423 double step=std::min<double>(
PI/180,atan2(maxDistance,radius));
426 while(final_angle<angle)
431 while(angle<final_angle)
439 while(final_angle>angle)
444 while(angle>final_angle)
462 bool needsFinalArc=
false;
463 double angleCovered=0;
464 double angleCoveredOffset=0;
465 for(
unsigned int i=0;i<
m_polygon.size();i++)
474 newPolygon.push_back(p);
482 if(newPolygon.empty())
485 angleCoveredOffset=angleCovered;
489 generateArc(newPolygon,points[0],center,radius,angleCovered<0);
491 newPolygon.push_back(points[0]);
492 newPolygon.push_back(p);
505 if(newPolygon.empty())
508 angleCoveredOffset=angleCovered;
512 generateArc(newPolygon,points[0],center,radius,angleCovered<0);
514 newPolygon.push_back(points[0]);
515 newPolygon.push_back(points[1]);
529 newPolygon.push_back(points[0]);
535 if(needsFinalArc && newPolygon.size()>1)
537 generateArc(newPolygon,newPolygon[0],center,radius,(angleCovered+angleCoveredOffset)<0);
546 for(
unsigned int i=0;i<
m_polygon.size();i++)
571 for(
unsigned int i=0;i<
m_polygon.size();i++)
579 if((u>=0.1) && (u<=0.9))
584 if(
norm(p-footpoint)<tol)
585 return i==0 ? j+1 : i;
595 if (
this == &otherPoly)
612 if(polygonStr.length()==0)
614 std::stringstream is(polygonStr);
633 o<<
"k i"<<newImgNr<<
" ";
636 for(
unsigned int i=0; i<
m_polygon.size(); i++)
654 for (
size_t i = 0; i <
m_polygon.size(); ++i)
658 return center / (double)
m_polygon.size();
664 while (stream.good())
667 std::getline(stream,line);
674 imageSize.setWidth(w);
677 imageSize.setHeight(h);
694 newMasks.push_back(newPolygon);
709 stream <<
"# w" << imageSize.width() <<
" h" << imageSize.height() << std::endl;
void SaveMaskToStream(std::ostream &stream, vigra::Size2D imageSize, MaskPolygon &maskToWrite, size_t imgNr)
save the mask into stream
hugin_utils::FDiff2D getCenter() const
return the center point of the polygon
bool isInside(const hugin_utils::FDiff2D p) const
checks if given point is inside of the stored polygon
void removePoint(const unsigned int index)
removes point at the position index from the polygon
bool parsePolygonString(const std::string &polygonStr)
parses the x and y positions from the given string
int getWindingNumber(const hugin_utils::FDiff2D p) const
returns the winding number of the polygon around point p
void movePointBy(const unsigned int index, const hugin_utils::FDiff2D diff)
relativ moves the point at position index by diff
std::vector< hugin_utils::FDiff2D > clip_getIntersectionCircle(const hugin_utils::FDiff2D p, const hugin_utils::FDiff2D s, const hugin_utils::FDiff2D center, const double radius)
returns intersection of line and circle
void LoadMaskFromStream(std::istream &stream, vigra::Size2D &imageSize, MaskPolygonVector &newMasks, size_t imgNr)
load the mask from stream
bool clip_insideCircle(const hugin_utils::FDiff2D p, const hugin_utils::FDiff2D center, const double radius)
check if point is inside circle
VectorPolygon clip_onPlane(const VectorPolygon &polygon, const vigra::Rect2D r, const clipSide side)
bool getIntParam(T &value, const std::string &line, const std::string &name)
void printPolygonLine(std::ostream &o, const unsigned int newImgNr) const
writes the complete k line which describes the mask to the stream, using the given newImgNr for the i...
#define DEBUG_ASSERT(cond)
declaration of classes to work with mask
bool getPTParam(std::string &output, const std::string &line, const std::string ¶meter)
helper functions for parsing of a script line
#define PI
Header file for Khan's deghosting algorithm Copyright (C) 2009 Lukáš Jirkovský l...
void calcBoundingBox()
calculates the bounding box of the polygon to speed up tests
VectorPolygon getMaskPolygon() const
returns vector with coordinates of the polygon
void generateArc(VectorPolygon &poly, const hugin_utils::FDiff2D s, const hugin_utils::FDiff2D center, const double radius, const bool clockwise)
adds an arc with given radius at the end of the polygon, the point is not added to the arc ...
void setMaskPolygon(const VectorPolygon &newMask)
set complete vector with all corrdinates of the polygon
bool isInverted() const
returns if mask is inverted
void setInverted(const bool inverted)
set mask to normal or inverted
vigra::Rect2D m_boundingBox
int getTotalWindingNumber() const
returns the total winding number of the polygon
void transformPolygon(const PTools::Transform &trans)
transforms the polygon coordinates by the given transformation
double angle_between(const hugin_utils::FDiff2D a, const hugin_utils::FDiff2D b)
calculates angle between vector a and b in radians
const bool operator==(const MaskPolygon &otherPoly) const
comparision operator
bool clip_isSide(const hugin_utils::FDiff2D p, const vigra::Rect2D r, const clipSide side)
MaskType
enumeration with type of possible masks
unsigned int getImgNr() const
returns the associated image number, only used when loading a project, otherwise discarded ...
bool clipPolygon(const vigra::Rect2D rect)
clips the polygon to the given rectangle
MaskPolygon & operator=(const MaskPolygon &otherPoly)
assign operator
TDiff2D< double > FDiff2D
std::vector< MaskPolygon > MaskPolygonVector
T squareLength() const
Return the square of the length of the vector.
hugin_utils::FDiff2D clip_getIntersection(const hugin_utils::FDiff2D p, const hugin_utils::FDiff2D q, const vigra::Rect2D r, const clipSide side)
void setImgNr(const unsigned int newImgNr)
sets the associated image number, only used when loading a project, otherwise discarded ...
void movePointTo(const unsigned int index, const hugin_utils::FDiff2D p)
moves the point at position index to the new absolute position p
void insertPoint(const unsigned int index, const hugin_utils::FDiff2D p)
insert point at the position index into the polygon
std::vector< hugin_utils::FDiff2D > VectorPolygon
vector, which stores coordinates of one polygon
void setMaskType(const MaskType newType)
sets mask type
bool isPositive() const
returns true, if mask type is positive
void subSample(const double max_distance)
subsamples the polygon, so that the longest distance between 2 points is max_distance ...
unsigned int FindPointNearPos(const hugin_utils::FDiff2D p, const double tol) const
search a point which lies near the polygon line and return the index for inserting the new point ...
MaskType getMaskType() const
returns mask type
void rotate90(bool clockwise, unsigned int maskWidth, unsigned int maskHeight)
rotate the polygon by 90 degrees
void addPoint(const hugin_utils::FDiff2D p)
adds point at the end to the polygon
void scale(const double factorx, const double factory)
scales all polygon coordinates by factorx for x position and factory for y position ...
base class, which stores one mask polygon
T squareDistance(TDiff2D< T > other) const
Return square of the distance to another point.