Commit 2aba0aa2842ab4a7da7926f395e5913043848f60

Authored by Scott Klum
1 parent 05452b11

Updated FlipTransform

Showing 1 changed file with 39 additions and 1 deletions
openbr/plugins/register.cpp
... ... @@ -121,6 +121,24 @@ private:
121 121 BR_REGISTER(Transform, AffineTransform)
122 122  
123 123 /*!
  124 + * \ingroup initializers
  125 + * \brief Initialize Stasm
  126 + * \author Scott Klum \cite sklum
  127 + */
  128 +class FlipInitializer : public Initializer
  129 +{
  130 + Q_OBJECT
  131 +
  132 + void initialize() const
  133 + {
  134 + Globals->abbreviations.insert("FlipMUCT","Flip(from=[ 0, 1, 2, 3, 4, 5, 6, 7, 17,18,19,20,21,31,32,36,37,38,39,40,41,48,49,50,55,56,60,61,65], \
  135 + to=[16,15,14,13,12,11,10, 9, 26,25,24,23,22,35,34,45,44,43,42,47,46,54,53,52,59,58,64,63,67])");
  136 + }
  137 +};
  138 +
  139 +BR_REGISTER(Initializer, FlipInitializer)
  140 +
  141 +/*!
124 142 * \ingroup transforms
125 143 * \brief Flips the image about an axis.
126 144 * \author Josh Klontz \cite jklontz
... ... @@ -130,6 +148,8 @@ class FlipTransform : public UntrainableMetaTransform
130 148 Q_OBJECT
131 149 Q_ENUMS(Axis)
132 150 Q_PROPERTY(Axis axis READ get_axis WRITE set_axis RESET reset_axis STORED false)
  151 + Q_PROPERTY(QList<int> from READ get_from WRITE set_from RESET reset_from STORED false)
  152 + Q_PROPERTY(QList<int> to READ get_to WRITE set_to RESET reset_to STORED false)
133 153  
134 154 public:
135 155 /*!< */
... ... @@ -139,6 +159,8 @@ public:
139 159  
140 160 private:
141 161 BR_PROPERTY(Axis, axis, Y)
  162 + BR_PROPERTY(QList<int>, from, QList<int>())
  163 + BR_PROPERTY(QList<int>, to, QList<int>())
142 164  
143 165 void project(const TemplateList &src, TemplateList &dst) const
144 166 {
... ... @@ -148,7 +170,23 @@ private:
148 170 flip(src[i], buffer, axis);
149 171 dst.append(Template(src[i].file,buffer));
150 172  
151   - dst.last().file.setPoints(QtUtils::flipPoints(dst.last().file.points(),src[i].m().rows,src[i].m().cols));
  173 + if (from.size() == to.size()) {
  174 + QList<QPointF> flippedPoints;
  175 + foreach(const QPointF &point, dst.last().file.points()) {
  176 + if (axis == Y) {
  177 + flippedPoints.append(QPointF(src[i].m().cols-point.x(),point.y()));
  178 + } else if (axis == X) {
  179 + flippedPoints.append(QPointF(point.x(),src[i].m().rows-point.y()));
  180 + } else {
  181 + flippedPoints.append(QPointF(src[i].m().cols-point.x(),src[i].m().rows-point.y()));
  182 + }
  183 + }
  184 +
  185 + for (int j=0; j<from.size(); j++)
  186 + std::swap(flippedPoints[from[j]],flippedPoints[to[j]]);
  187 +
  188 + dst.last().file.setPoints(flippedPoints);
  189 + }
152 190 }
153 191 }
154 192  
... ...