Hugin trunk 0.1
Loading...
Searching...
No Matches
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"
33
34namespace HuginBase
35{
36namespace PTools { class Transform; }
37
39typedef std::vector<hugin_utils::FDiff2D> VectorPolygon;
40
44const int maskOffset=100;
45
53{
54public:
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 scale(const double factor, const hugin_utils::FDiff2D& p);
111 void transformPolygon(const PTools::Transform &trans);
113 bool clipPolygon(const vigra::Rect2D rect);
115 bool clipPolygon(const hugin_utils::FDiff2D center, const double radius);
117 void rotate90(bool clockwise,unsigned int maskWidth,unsigned int maskHeight);
119 void subSample(const double max_distance);
120
122 unsigned int FindPointNearPos(const hugin_utils::FDiff2D p, const double tol) const;
123
124 //operators
126 MaskPolygon &operator=(const MaskPolygon& otherPoly);
128 const bool operator==(const MaskPolygon& otherPoly) const;
129
130 //input/output functions
132 bool parsePolygonString(const std::string& polygonStr);
136 void printPolygonLine(std::ostream & o, const unsigned int newImgNr) const;
138 hugin_utils::FDiff2D getCenter() const;
139private:
141 void calcBoundingBox();
142 //variables for internal storage of Mask type, polygon and assigned image number
145 unsigned int m_imgNr;
147 vigra::Rect2D m_boundingBox;
148};
149
150typedef std::vector<MaskPolygon> MaskPolygonVector;
151
153IMPEX void LoadMaskFromStream(std::istream& stream, vigra::Size2D& imageSize, MaskPolygonVector &newMasks, size_t imgNr);
155IMPEX void SaveMaskToStream(std::ostream& stream, vigra::Size2D imageSize, MaskPolygon &maskToWrite, size_t imgNr);
156
157}; //namespace
158
159namespace vigra_ext
160{
161
162template <class SrcImageIterator, class SrcAccessor>
163void applyMask(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> img, HuginBase::MaskPolygonVector masks)
164{
165 const vigra::Diff2D imgSize = img.second - img.first;
166
167 if(masks.empty())
168 return;
169 // loop over the image and transform
170#pragma omp parallel for schedule(dynamic)
171 for(int y=0; y < imgSize.y; ++y)
172 {
173 // create x iterators
174 SrcImageIterator xd(img.first);
175 xd.y += y;
176 for(int x=0; x < imgSize.x; ++x, ++xd.x)
177 {
178 hugin_utils::FDiff2D newPoint(x,y);
179 bool insideMasks=false;
180 unsigned int i=0;
181 while(!insideMasks && (i<masks.size()))
182 {
183 insideMasks=masks[i].isInside(newPoint);
184 i++;
185 };
186 if(insideMasks)
187 *xd=0;
188 }
189 }
190}
191
192} //namespace
193#endif // _PANODATA_MASK_H
base class, which stores one mask polygon
Definition Mask.h:53
void scale(const double factor)
scales x and y axis equally by factor
Definition Mask.h:107
VectorPolygon getMaskPolygon() const
returns vector with coordinates of the polygon
Definition Mask.h:81
void setImgNr(const unsigned int newImgNr)
sets the associated image number, only used when loading a project, otherwise discarded
Definition Mask.h:87
MaskType getMaskType() const
returns mask type
Definition Mask.h:75
vigra::Rect2D m_boundingBox
Definition Mask.h:147
unsigned int m_imgNr
Definition Mask.h:145
unsigned int getImgNr() const
returns the associated image number, only used when loading a project, otherwise discarded
Definition Mask.h:85
bool isInverted() const
returns if mask is inverted
Definition Mask.h:91
VectorPolygon m_polygon
Definition Mask.h:144
void setMaskType(const MaskType newType)
sets mask type
Definition Mask.h:77
MaskPolygon()
constructor
Definition Mask.h:65
void setInverted(const bool inverted)
set mask to normal or inverted
Definition Mask.h:89
MaskType m_maskType
Definition Mask.h:143
MaskType
enumeration with type of possible masks
Definition Mask.h:57
Holds transformations for Image -> Pano and the other way.
misc math function & classes used by other parts of the program
#define IMPEX
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::vector< MaskPolygon > MaskPolygonVector
Definition Mask.h:150
const int maskOffset
polygon can exceed the image maximal maskOffset pixels in each direction bigger polygons will be clip...
Definition Mask.h:44
void LoadMaskFromStream(std::istream &stream, vigra::Size2D &imageSize, MaskPolygonVector &newMasks, size_t imgNr)
load the mask from stream
Definition Mask.cpp:662
void SaveMaskToStream(std::ostream &stream, vigra::Size2D imageSize, MaskPolygon &maskToWrite, size_t imgNr)
save the mask into stream
Definition Mask.cpp:707
std::vector< hugin_utils::FDiff2D > VectorPolygon
vector, which stores coordinates of one polygon
Definition Mask.h:39
void applyMask(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > img, HuginBase::MaskPolygonVector masks)
Definition Mask.h:163
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41