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;
220 for(
unsigned int i=1;i<
m_polygon.size();i++)
244 return p.
x>=r.left();
246 return p.
x<=r.right();
250 return p.
y<=r.bottom();
269 a=(q.
y-p.
y)/(q.
x-p.
x);
308 for(
unsigned int i=0;i<polygon.size();i++)
317 newPolygon.push_back(p);
363 std::vector<hugin_utils::FDiff2D> intersections;
367 return intersections;
370 double dotproduct=p2.
x*slope.
x+p2.
y*slope.
y;
388 for(std::set<double>::const_iterator it=t.begin();it!=t.end();++it)
390 intersections.push_back(p+slope*(*it));
393 return intersections;
416 double maxDistance=5.0;
421 double angle=atan2(p.
y-center.
y,p.
x-center.
x);
422 double final_angle=atan2(s.
y-center.
y,s.
x-center.
x);
424 double step=std::min<double>(
PI/180,atan2(maxDistance,radius));
427 while(final_angle<angle)
432 while(angle<final_angle)
440 while(final_angle>angle)
445 while(angle>final_angle)
463 bool needsFinalArc=
false;
464 double angleCovered=0;
465 double angleCoveredOffset=0;
466 for(
unsigned int i=0;i<
m_polygon.size();i++)
475 newPolygon.push_back(p);
483 if(newPolygon.empty())
486 angleCoveredOffset=angleCovered;
490 generateArc(newPolygon,points[0],center,radius,angleCovered<0);
492 newPolygon.push_back(points[0]);
493 newPolygon.push_back(p);
506 if(newPolygon.empty())
509 angleCoveredOffset=angleCovered;
513 generateArc(newPolygon,points[0],center,radius,angleCovered<0);
515 newPolygon.push_back(points[0]);
516 newPolygon.push_back(points[1]);
530 newPolygon.push_back(points[0]);
536 if(needsFinalArc && newPolygon.size()>1)
538 generateArc(newPolygon,newPolygon[0],center,radius,(angleCovered+angleCoveredOffset)<0);
547 for(
unsigned int i=0;i<
m_polygon.size();i++)
572 for(
unsigned int i=0;i<
m_polygon.size();i++)
580 if((u>=0.1) && (u<=0.9))
585 if(
norm(p-footpoint)<tol)
586 return i==0 ? j+1 : i;
596 if (
this == &otherPoly)
613 if(polygonStr.length()==0)
615 std::stringstream is(polygonStr);
634 o<<
"k i"<<newImgNr<<
" ";
637 for(
unsigned int i=0; i<
m_polygon.size(); i++)
655 for (
size_t i = 0; i <
m_polygon.size(); ++i)
659 return center / (double)
m_polygon.size();
665 while (stream.good())
668 std::getline(stream,line);
675 imageSize.setWidth(w);
678 imageSize.setHeight(h);
695 newMasks.push_back(newPolygon);
710 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.