Debian Codegraph @

src/Base/ViewProj.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2005 Imetric 3D GmbH *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Library General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Library General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Library General Public *
19 * License along with this library; see the file COPYING.LIB. If not, *
20 * write to the Free Software Foundation, Inc., 59 Temple Place, *
21 * Suite 330, Boston, MA 02111-1307, USA *
22 * *
23 ***************************************************************************/
24
25
26 #ifndef BASE_VIEWPROJ_H
27 #define BASE_VIEWPROJ_H
28
29 #include "Matrix.h"
30
31
32 namespace Base
33 {
34 template<typename T>
35 class Vector3;
36 using Vector3d = Vector3<double>;
37
38
39 /**
40 * Abstract base class for all project methods.
41 */
42 class BaseExport ViewProjMethod
43 {
44 public:
45 ViewProjMethod(const ViewProjMethod&) = default;
46 ViewProjMethod(ViewProjMethod&&) = default;
47 ViewProjMethod& operator=(const ViewProjMethod&) = default;
48 ViewProjMethod& operator=(ViewProjMethod&&) = default;
49 virtual ~ViewProjMethod() = default;
50
51 virtual bool isValid() const;
52 /** Convert 3D point to 2D projection plane */
53 virtual Vector3f operator()(const Vector3f& rclPt) const = 0;
54 /** Convert 3D point to 2D projection plane */
55 virtual Vector3d operator()(const Vector3d& rclPt) const = 0;
56 /** Convert a 2D point on the projection plane in 3D space */
57 virtual Vector3f inverse(const Vector3f& rclPt) const = 0;
58 /** Convert a 2D point on the projection plane in 3D space */
59 virtual Vector3d inverse(const Vector3d& rclPt) const = 0;
60 /** Calculate the projection (+ mapping) matrix */
61 virtual Matrix4D getProjectionMatrix() const = 0;
62 /** Calculate the composed projection matrix */
63 Matrix4D getComposedProjectionMatrix() const;
64 /** Apply an additional transformation to the input points */
65 void setTransform(const Base::Matrix4D&);
66 const Base::Matrix4D& getTransform() const
67 {
68 return transform;
69 }
70
71 protected:
72 ViewProjMethod();
73 void transformInput(const Base::Vector3f&, Base::Vector3f&) const;
74 void transformInput(const Base::Vector3d&, Base::Vector3d&) const;
75
76 private:
77 bool hasTransform {false};
78 Base::Matrix4D transform;
79 };
80
81 /**
82 * The ViewProjMatrix class returns the result of the multiplication
83 * of the 3D vector and the view transformation matrix.
84 */
85 class BaseExport ViewProjMatrix: public ViewProjMethod
86 {
87 public:
88 explicit ViewProjMatrix(const Matrix4D& rclMtx);
89
90 Vector3f operator()(const Vector3f& inp) const override;
91 Vector3d operator()(const Vector3d& inp) const override;
92 Vector3f inverse(const Vector3f& src) const override;
93 Vector3d inverse(const Vector3d& src) const override;
94
95 Matrix4D getProjectionMatrix() const override;
96
97 private:
98 bool isOrthographic;
99 Matrix4D _clMtx, _clMtxInv;
100 };
101
102 /**
103 * The ViewOrthoProjMatrix class returns the result of the multiplication
104 * of the 3D vector and the transformation matrix.
105 * Unlike ViewProjMatrix this class is not supposed to project points onto
106 * a viewport but project points onto a plane in 3D.
107 */
108 class BaseExport ViewOrthoProjMatrix: public ViewProjMethod
109 {
110 public:
111 explicit ViewOrthoProjMatrix(const Matrix4D& rclMtx);
112
113 Vector3f operator()(const Vector3f& rclPt) const override;
114 Vector3d operator()(const Vector3d& rclPt) const override;
115 Vector3f inverse(const Vector3f& rclPt) const override;
116 Vector3d inverse(const Vector3d& rclPt) const override;
117
118 Matrix4D getProjectionMatrix() const override;
119
120 private:
121 Matrix4D _clMtx, _clMtxInv;
122 };
123
124 } // namespace Base
125
126 #endif // BASE_VIEWPROJ_H