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++)
156 for(
unsigned int i=0;i<
m_polygon.size();i++)
168 for(
unsigned int i=0;i<
m_polygon.size();i++)
184 unsigned int count=oldPoly.size();
186 for(
unsigned int i=0;i<count;i++)
191 double distance=
norm(p2-p1);
192 if(distance>max_distance)
195 double currentDistance=max_distance;
196 while(currentDistance<distance)
200 currentDistance+=max_distance;
214 for(
unsigned int i=1;i<
m_polygon.size();i++)
238 return p.
x>=r.left();
240 return p.
x<=r.right();
244 return p.
y<=r.bottom();
263 a=(q.
y-p.
y)/(q.
x-p.
x);
302 for(
unsigned int i=0;i<polygon.size();i++)
311 newPolygon.push_back(p);
357 std::vector<hugin_utils::FDiff2D> intersections;
361 return intersections;
364 double dotproduct=p2.
x*slope.
x+p2.
y*slope.
y;
382 for(std::set<double>::const_iterator it=t.begin();it!=t.end();++it)
384 intersections.push_back(p+slope*(*it));
387 return intersections;
410 double maxDistance=5.0;
415 double angle=atan2(p.
y-center.
y,p.
x-center.
x);
416 double final_angle=atan2(s.
y-center.
y,s.
x-center.
x);
418 double step=std::min<double>(
PI/180,atan2(maxDistance,radius));
421 while(final_angle<angle)
426 while(angle<final_angle)
434 while(final_angle>angle)
439 while(angle>final_angle)
457 bool needsFinalArc=
false;
458 double angleCovered=0;
459 double angleCoveredOffset=0;
460 for(
unsigned int i=0;i<
m_polygon.size();i++)
469 newPolygon.push_back(p);
477 if(newPolygon.empty())
480 angleCoveredOffset=angleCovered;
484 generateArc(newPolygon,points[0],center,radius,angleCovered<0);
486 newPolygon.push_back(points[0]);
487 newPolygon.push_back(p);
500 if(newPolygon.empty())
503 angleCoveredOffset=angleCovered;
507 generateArc(newPolygon,points[0],center,radius,angleCovered<0);
509 newPolygon.push_back(points[0]);
510 newPolygon.push_back(points[1]);
524 newPolygon.push_back(points[0]);
530 if(needsFinalArc && newPolygon.size()>1)
532 generateArc(newPolygon,newPolygon[0],center,radius,(angleCovered+angleCoveredOffset)<0);
541 for(
unsigned int i=0;i<
m_polygon.size();i++)
566 for(
unsigned int i=0;i<
m_polygon.size();i++)
574 if((u>=0.1) && (u<=0.9))
579 if(
norm(p-footpoint)<tol)
580 return i==0 ? j+1 : i;
590 if (
this == &otherPoly)
607 if(polygonStr.length()==0)
609 std::stringstream is(polygonStr);
628 o<<
"k i"<<newImgNr<<
" ";
631 for(
unsigned int i=0; i<
m_polygon.size(); i++)
642 while (stream.good())
645 std::getline(stream,line);
652 imageSize.setWidth(w);
655 imageSize.setHeight(h);
672 newMasks.push_back(newPolygon);
687 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
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.