1 /*
2  *    Copyright 2012, 2013 Thomas Schöps
3  *    Copyright 2012, 2014, 2016 Kai Pastor
4  *
5  *    This file is part of OpenOrienteering.
6  *
7  *    OpenOrienteering is free software: you can redistribute it and/or modify
8  *    it under the terms of the GNU General Public License as published by
9  *    the Free Software Foundation, either version 3 of the License, or
10  *    (at your option) any later version.
11  *
12  *    OpenOrienteering is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with OpenOrienteering.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef OPENORIENTEERING_TRANSFORMATION_H
23 #define OPENORIENTEERING_TRANSFORMATION_H
24 
25 #include <vector>
26 
27 #include "core/map_coord.h"
28 
29 class QTransform;
30 class QXmlStreamReader;
31 class QXmlStreamWriter;
32 
33 namespace OpenOrienteering {
34 
35 struct TemplateTransform;
36 
37 
38 /** Pair of source and destination coordinates used to calculate transformations. */
39 struct PassPoint
40 {
41 	void save(QXmlStreamWriter& xml) const;
42 	static PassPoint load(QXmlStreamReader& xml);
43 
44 	/** Start position specified by the user */
45 	MapCoordF src_coords;
46 
47 	/** End position specified by the user */
48 	MapCoordF dest_coords;
49 
50 	/** Position where the point really ended up */
51 	MapCoordF calculated_coords;
52 
53 	/** Distance between dest_coords_map and calculated_coords;
54 	 *  negative if not calculated yet */
55 	double error;
56 };
57 
58 /** List of pass points with methods for transformation calculation. */
59 class PassPointList : public std::vector< PassPoint >
60 {
61 public:
62 	/**
63 	 * Indicates arguments which must not be nullptr.
64 	 * \todo Use the Guideline Support Library
65 	 */
66 	template <typename T>
67 	using not_null = T;
68 
69 
70 	/** Estimates a similarity transformation based on the contained pass points
71 	 *  and applies it to the transformation passed in. */
72 	bool estimateSimilarityTransformation(not_null<TemplateTransform*> transform);
73 
74 	bool estimateSimilarityTransformation(not_null<QTransform*> out);
75 
76 	/** Estimates an affine transformation. */
77 	bool estimateNonIsometricSimilarityTransform(not_null<QTransform*> out);
78 };
79 
80 
81 }  // namespace OpenOrienteering
82 
83 #endif
84