Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mask.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /* This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This software is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this software. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef _PANODATA_MASK_H
28 #define _PANODATA_MASK_H
29 
30 #include <hugin_shared.h>
31 #include "hugin_utils/utils.h"
32 #include "hugin_math/hugin_math.h"
33 
34 namespace HuginBase
35 {
36 namespace PTools { class Transform; }
37 
39 typedef std::vector<hugin_utils::FDiff2D> VectorPolygon;
40 
44 const int maskOffset=100;
45 
53 {
54 public:
56  enum MaskType
57  {
58  Mask_negative=0,
59  Mask_positive=1,
60  Mask_Stack_negative=2,
61  Mask_Stack_positive=3,
62  Mask_negative_lens=4
63  };
65  MaskPolygon() : m_maskType(Mask_negative), m_imgNr(0), m_invert(false) {};
67  bool isInside(const hugin_utils::FDiff2D p) const;
69  int getWindingNumber(const hugin_utils::FDiff2D p) const;
71  int getTotalWindingNumber() const;
72 
73  // access functions
75  MaskType getMaskType() const { return m_maskType; };
77  void setMaskType(const MaskType newType) { m_maskType=newType; };
79  bool isPositive() const;
81  VectorPolygon getMaskPolygon() const { return m_polygon; };
83  void setMaskPolygon(const VectorPolygon& newMask);
85  unsigned int getImgNr() const { return m_imgNr; };
87  void setImgNr(const unsigned int newImgNr) { m_imgNr=newImgNr; };
89  void setInverted(const bool inverted) { m_invert = inverted; };
91  bool isInverted() const { return m_invert; };
92 
93  // polygon modifier
95  void addPoint(const hugin_utils::FDiff2D p);
97  void insertPoint(const unsigned int index, const hugin_utils::FDiff2D p);
99  void removePoint(const unsigned int index);
101  void movePointTo(const unsigned int index, const hugin_utils::FDiff2D p);
103  void movePointBy(const unsigned int index, const hugin_utils::FDiff2D diff);
105  void scale(const double factorx, const double factory);
107  void scale(const double factor) { scale(factor,factor);} ;
109  void transformPolygon(const PTools::Transform &trans);
111  bool clipPolygon(const vigra::Rect2D rect);
113  bool clipPolygon(const hugin_utils::FDiff2D center, const double radius);
115  void rotate90(bool clockwise,unsigned int maskWidth,unsigned int maskHeight);
117  void subSample(const double max_distance);
118 
120  unsigned int FindPointNearPos(const hugin_utils::FDiff2D p, const double tol) const;
121 
122  //operators
124  MaskPolygon &operator=(const MaskPolygon& otherPoly);
126  const bool operator==(const MaskPolygon& otherPoly) const;
127 
128  //input/output functions
130  bool parsePolygonString(const std::string& polygonStr);
134  void printPolygonLine(std::ostream & o, const unsigned int newImgNr) const;
135 
136 private:
138  void calcBoundingBox();
139  //variables for internal storage of Mask type, polygon and assigned image number
142  unsigned int m_imgNr;
143  bool m_invert;
144  vigra::Rect2D m_boundingBox;
145 };
146 
147 typedef std::vector<MaskPolygon> MaskPolygonVector;
148 
150 IMPEX void LoadMaskFromStream(std::istream& stream, vigra::Size2D& imageSize, MaskPolygonVector &newMasks, size_t imgNr);
152 IMPEX void SaveMaskToStream(std::ostream& stream, vigra::Size2D imageSize, MaskPolygon &maskToWrite, size_t imgNr);
153 
154 }; //namespace
155 
156 namespace vigra_ext
157 {
158 
159 template <class SrcImageIterator, class SrcAccessor>
160 void applyMask(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> img, HuginBase::MaskPolygonVector masks)
161 {
162  const vigra::Diff2D imgSize = img.second - img.first;
163 
164  if(masks.empty())
165  return;
166  // loop over the image and transform
167 #pragma omp parallel for schedule(dynamic)
168  for(int y=0; y < imgSize.y; ++y)
169  {
170  // create x iterators
171  SrcImageIterator xd(img.first);
172  xd.y += y;
173  for(int x=0; x < imgSize.x; ++x, ++xd.x)
174  {
175  hugin_utils::FDiff2D newPoint(x,y);
176  bool insideMasks=false;
177  unsigned int i=0;
178  while(!insideMasks && (i<masks.size()))
179  {
180  insideMasks=masks[i].isInside(newPoint);
181  i++;
182  };
183  if(insideMasks)
184  *xd=0;
185  }
186  }
187 }
188 
189 } //namespace
190 #endif // _PANODATA_MASK_H
void SaveMaskToStream(std::ostream &stream, vigra::Size2D imageSize, MaskPolygon &maskToWrite, size_t imgNr)
save the mask into stream
Definition: Mask.cpp:685
void applyMask(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > img, HuginBase::MaskPolygonVector masks)
Definition: Mask.h:160
const int maskOffset
polygon can exceed the image maximal maskOffset pixels in each direction bigger polygons will be clip...
Definition: Mask.h:44
misc math function &amp; classes used by other parts of the program
void LoadMaskFromStream(std::istream &stream, vigra::Size2D &imageSize, MaskPolygonVector &newMasks, size_t imgNr)
load the mask from stream
Definition: Mask.cpp:640
VectorPolygon getMaskPolygon() const
returns vector with coordinates of the polygon
Definition: Mask.h:81
MaskPolygon()
constructor
Definition: Mask.h:65
bool isInverted() const
returns if mask is inverted
Definition: Mask.h:91
void setInverted(const bool inverted)
set mask to normal or inverted
Definition: Mask.h:89
vigra::Rect2D m_boundingBox
Definition: Mask.h:144
MaskType m_maskType
Definition: Mask.h:140
VectorPolygon m_polygon
Definition: Mask.h:141
MaskType
enumeration with type of possible masks
Definition: Mask.h:56
unsigned int getImgNr() const
returns the associated image number, only used when loading a project, otherwise discarded ...
Definition: Mask.h:85
void scale(const double factor)
scales x and y axis equally by factor
Definition: Mask.h:107
std::vector< MaskPolygon > MaskPolygonVector
Definition: Mask.h:147
#define IMPEX
Definition: hugin_shared.h:39
void setImgNr(const unsigned int newImgNr)
sets the associated image number, only used when loading a project, otherwise discarded ...
Definition: Mask.h:87
std::vector< hugin_utils::FDiff2D > VectorPolygon
vector, which stores coordinates of one polygon
Definition: Mask.h:39
void setMaskType(const MaskType newType)
sets mask type
Definition: Mask.h:77
Holds transformations for Image -&gt; Pano and the other way.
MaskType getMaskType() const
returns mask type
Definition: Mask.h:75
base class, which stores one mask polygon
Definition: Mask.h:52
unsigned int m_imgNr
Definition: Mask.h:142