[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/panodata/Mask.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00014 /*  This program is free software; you can redistribute it and/or
00015  *  modify it under the terms of the GNU General Public
00016  *  License as published by the Free Software Foundation; either
00017  *  version 2 of the License, or (at your option) any later version.
00018  *
00019  *  This software is distributed in the hope that it will be useful,
00020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received a copy of the GNU General Public
00025  *  License along with this software; if not, write to the Free Software
00026  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  */
00029 
00030 #ifndef _PANODATA_MASK_H
00031 #define _PANODATA_MASK_H
00032 
00033 #include <hugin_shared.h>
00034 #include "hugin_utils/utils.h"
00035 #include "hugin_math/hugin_math.h"
00036 
00037 namespace HuginBase 
00038 {
00039 namespace PTools { class Transform; }
00040 
00041 using namespace hugin_utils;
00042 
00044 typedef std::vector<FDiff2D> VectorPolygon;
00045 
00049 const int maskOffset=100;
00050 
00052 class IMPEX MaskPolygon
00053 {
00054 public:
00056     enum MaskType 
00057     {
00058         Mask_negative=0,
00059         Mask_positive=1
00060     };
00062     MaskPolygon() : m_maskType(Mask_negative), m_invert(false), m_imgNr(0) {};
00064     bool isInside(const FDiff2D p) const;
00066     int getWindingNumber(const FDiff2D p) const;
00068     int getTotalWindingNumber() const;
00069 
00070     // access functions
00072     MaskType getMaskType() const { return m_maskType; };
00074     void setMaskType(const MaskType newType) { m_maskType=newType; };
00076     VectorPolygon getMaskPolygon() const { return m_polygon; };
00078     void setMaskPolygon(const VectorPolygon newMask) { m_polygon = newMask; };
00080     unsigned int getImgNr() const { return m_imgNr; };
00082     void setImgNr(const unsigned int newImgNr) { m_imgNr=newImgNr; };
00084     void setInverted(const bool inverted) { m_invert = inverted; };
00086     bool isInverted() const { return m_invert; };
00087 
00088     // polygon modifier
00090     void addPoint(const FDiff2D p);
00092     void insertPoint(const unsigned int index, const FDiff2D p);
00094     void removePoint(const unsigned int index);
00096     void movePointTo(const unsigned int index, const FDiff2D p);
00098     void movePointBy(const unsigned int index, const FDiff2D diff);
00100     void scale(const double factorx, const double factory);
00102     void scale(const double factor) { scale(factor,factor);} ;
00104     void transformPolygon(const PTools::Transform &trans);
00106     bool clipPolygon(const vigra::Rect2D rect);
00108     void rotate90(bool clockwise,unsigned int maskWidth,unsigned int maskHeight);
00110     void subSample(const double max_distance);
00111 
00113     unsigned int FindPointNearPos(const FDiff2D p, const double tol);
00114 
00115     //operators
00117     MaskPolygon &operator=(const MaskPolygon otherPoly);
00119     const bool operator==(const MaskPolygon &otherPoly) const;
00120 
00121     //input/output functions
00123     bool parsePolygonString(const std::string polygonStr);
00127     void printPolygonLine(std::ostream & o, const unsigned int newImgNr) const;
00128 
00129 private:
00130     // helper functions for clipping using Sutherland-Hodgeman Clipping Algorithm
00131     enum clipSide
00132     {
00133         clipLeft=0,
00134         clipRight,
00135         clipTop,
00136         clipBottom
00137     };
00138     bool clip_isSide(const FDiff2D p, const vigra::Rect2D r, const clipSide side);
00139     FDiff2D clip_getIntersection(const FDiff2D p, const FDiff2D q, const vigra::Rect2D r, const clipSide side);
00140     void clip_onPlane(const vigra::Rect2D r, clipSide side);
00141 
00142     //variables for internal storage of Mask type, polygon and assigned image number
00143     MaskType m_maskType;
00144     VectorPolygon m_polygon;
00145     unsigned int m_imgNr;
00146     bool m_invert;
00147 };
00148 
00149 typedef std::vector<MaskPolygon> MaskPolygonVector;
00150 
00151 }; //namespace
00152 
00153 namespace vigra_ext 
00154 {
00155 
00156 template <class SrcImageIterator, class SrcAccessor>
00157 void applyMask(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> img, HuginBase::MaskPolygonVector masks)
00158 {
00159     vigra::Diff2D imgSize = img.second - img.first;
00160 
00161     if(masks.size()<1)
00162         return;
00163     // create dest y iterator
00164     SrcImageIterator yd(img.first);
00165     // loop over the image and transform
00166     for(int y=0; y < imgSize.y; ++y, ++yd.y)
00167     {
00168         // create x iterators
00169         SrcImageIterator xd(yd);
00170         for(int x=0; x < imgSize.x; ++x, ++xd.x)
00171         {
00172             HuginBase::FDiff2D newPoint(x,y);
00173             bool insideMasks=false;
00174             unsigned int i=0;
00175             while(!insideMasks && (i<masks.size()))
00176             {
00177                 insideMasks=masks[i].isInside(newPoint);
00178                 i++;
00179             };
00180             if(insideMasks)
00181                 *xd=0;
00182         }
00183     }
00184 }
00185 
00186 } //namespace
00187 #endif // PANOIMAGE_H

Generated on Mon Sep 20 01:01:27 2010 for Hugintrunk by doxygen 1.3.9.1