1 /* 2 * Portable Agile C++ Classes (PACC) 3 * Copyright (C) 2001-2003 by Marc Parizeau 4 * http://manitou.gel.ulaval.ca/~parizeau/PACC 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * 20 * Contact: 21 * Laboratoire de Vision et Systemes Numeriques 22 * Departement de genie electrique et de genie informatique 23 * Universite Laval, Quebec, Canada, G1K 7P4 24 * http://vision.gel.ulaval.ca 25 * 26 */ 27 28 /*! 29 * \file PACC/SVG/Transforms.hpp 30 * \brief Class definition for the SVG transform. 31 * \author Marc Parizeau and Michel Fortin, Laboratoire de vision et systèmes numériques, Université Laval 32 * $Revision: 1.5.2.1 $ 33 * $Date: 2007/09/10 18:24:09 $ 34 */ 35 36 #ifndef PACC_SVG_Transforms_hpp_ 37 #define PACC_SVG_Transforms_hpp_ 38 39 #include "SVG/Types.hpp" 40 #include "Util/StringFunc.hpp" 41 42 namespace PACC { 43 44 namespace SVG { 45 46 using namespace std; 47 48 /*!\brief Coordinate tranform for graphic elements. 49 * \ingroup SVG 50 */ 51 class Transform : public string { 52 public: 53 //! Return the transform which results from the concatenation of this transform with \c inTranform. operator +(const Transform & inTransform)54 Transform operator+(const Transform& inTransform) { 55 return Transform(*this) += inTransform; 56 } 57 58 //! Append transform \c inTranform to this transform. operator +=(const Transform & inTransform)59 Transform& operator+=(const Transform& inTransform) { 60 string::operator+=(string(" ")+inTransform); 61 return *this; 62 } 63 64 protected: 65 //! Make transform with name \c inName and value \c inValue. Transform(const string & inName,const string & inValue)66 Transform(const string &inName, const string &inValue) : string(inName+"("+inValue+")") {} 67 }; 68 69 //! \brief Rotation tranform. 70 //! \ingroup SVG 71 class Rotate : public Transform { 72 public: 73 //! Make a rotation transform of angle \c inAngle. Rotate(float inAngle)74 Rotate(float inAngle) : Transform("rotate", String::convert(inAngle)) {} 75 76 //! make a rotation transform of angle \c inAngle from point \c inPoint. Rotate(float inAngle,const Point & inPoint)77 Rotate(float inAngle, const Point &inPoint) : Transform("rotate", String::convert(inAngle) + " " + String::convert(inPoint.x) + " " + String::convert(inPoint.y)) {} 78 79 //! make a rotation transform of angle \c inAngle from coordinates \c inX and \c inY. Rotate(float inAngle,float inX,float inY)80 Rotate(float inAngle, float inX, float inY) : Transform("rotate", String::convert(inAngle) + " " + String::convert(inX) + " " + String::convert(inY)) {} 81 }; 82 83 /*!\brief Translation tranform. 84 * \ingroup SVG 85 * 86 * If you want to set a new origin, you can use the translation. As an 87 * example, to put the origin at (1,1), translate by (-1,-1). 88 */ 89 class Translate : public Transform { 90 public: 91 //! Make a translation transform to point \c inPoint. Translate(const Point & inPoint)92 Translate(const Point &inPoint) : Transform("translate", String::convert(inPoint.x) + " " + String::convert(inPoint.y)) {} 93 94 //! make a translation transform to relative coordinates \c inX and \c inY. Translate(float inX,float inY)95 Translate(float inX, float inY) : Transform("translate", String::convert(inX) + " " + String::convert(inY)) {} 96 }; 97 98 //! \brief Scaling tranform. 99 //! \ingroup SVG 100 class Scale : public Transform { 101 public: 102 //! Make a scaling transform of scale \c inScale. Scale(float inScale)103 Scale(float inScale) : Transform("scale", String::convert(inScale)) {} 104 105 //! make a scaling transformm of scale \c inX and \c inY. Scale(float inX,float inY)106 Scale(float inX, float inY) : Transform("scale", String::convert(inX) + " " + String::convert(inY)) {} 107 }; 108 109 //! \brief Horizontal skewing tranform. 110 //! \ingroup SVG 111 class SkewX : public Transform { 112 public: 113 //! Make a horizontal skewing transform of angle \c inAngle. SkewX(float inAngle)114 SkewX(float inAngle) : Transform("skewX", String::convert(inAngle)) {} 115 }; 116 117 //! \brief Vertical skewing tranform. 118 //! \ingroup SVG 119 class SkewY : public Transform { 120 public: 121 //! Make a vertical skewing transform of angle \c inAngle. SkewY(float inAngle)122 SkewY(float inAngle) : Transform("skewY", String::convert(inAngle)) {} 123 }; 124 125 //! \brief General matrix transformation. 126 //! \ingroup SVG 127 class MatrixTransform : public Transform { 128 public: 129 /*!\brief Construct a matrix transform from the six upper values of 130 * the matrix. 131 * \param inA . 132 * \param inB . 133 * \param inC . 134 * \param inD . 135 * \param inE . 136 * \param inF . 137 * 138 * Transformation matrix is of the form: 139 * 140 * <code>[a b c]<br> 141 * [d e f]<br> 142 * [0 0 1]</code> 143 */ MatrixTransform(float inA,float inB,float inC,float inD,float inE,float inF)144 MatrixTransform(float inA, float inB, float inC, float inD, float inE, float inF) 145 : Transform("matrix", String::convert(inA) + " " + String::convert(inB) + " " + String::convert(inC) + " " + String::convert(inD) + " " + String::convert(inE) + " " + String::convert(inF)) {} 146 }; 147 148 } // end of SVG namespace 149 150 } // end of PACC namespace 151 152 #endif 153