Fix too much memory usage for Cycles attribute map.
[blender.git] / intern / iksolver / intern / IK_QTask.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Original author: Laurence
24  * Contributor(s): Brecht
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file iksolver/intern/IK_QTask.h
30  *  \ingroup iksolver
31  */
32
33 #pragma once
34
35 #include "IK_Math.h"
36 #include "IK_QJacobian.h"
37 #include "IK_QSegment.h"
38
39 class IK_QTask
40 {
41 public:
42         IK_QTask(
43                 int size,
44                 bool primary,
45                 bool active,
46                 const IK_QSegment *segment
47         );
48         virtual ~IK_QTask() {}
49
50         int Id() const
51         { return m_size; }
52
53         void SetId(int id)
54         { m_id = id; }
55
56         int Size() const
57         { return m_size; }
58
59         bool Primary() const
60         { return m_primary; }
61
62         bool Active() const
63         { return m_active; }
64
65         double Weight() const
66         { return m_weight*m_weight; }
67
68         void SetWeight(double weight)
69         { m_weight = sqrt(weight); }
70
71         virtual void ComputeJacobian(IK_QJacobian& jacobian)=0;
72
73         virtual double Distance() const=0;
74
75         virtual bool PositionTask() const { return false; }
76
77         virtual void Scale(double) {}
78
79 protected:
80         int m_id;
81         int m_size;
82         bool m_primary;
83         bool m_active;
84         const IK_QSegment *m_segment;
85         double m_weight;
86 };
87
88 class IK_QPositionTask : public IK_QTask
89 {
90 public:
91         IK_QPositionTask(
92                 bool primary,
93                 const IK_QSegment *segment,
94                 const Vector3d& goal
95         );
96
97         void ComputeJacobian(IK_QJacobian& jacobian);
98
99         double Distance() const;
100
101         bool PositionTask() const { return true; }
102         void Scale(double scale) { m_goal *= scale; m_clamp_length *= scale; }
103
104 private:
105         Vector3d m_goal;
106         double m_clamp_length;
107 };
108
109 class IK_QOrientationTask : public IK_QTask
110 {
111 public:
112         IK_QOrientationTask(
113                 bool primary,
114                 const IK_QSegment *segment,
115                 const Matrix3d& goal
116         );
117
118         double Distance() const { return m_distance; }
119         void ComputeJacobian(IK_QJacobian& jacobian);
120
121 private:
122         Matrix3d m_goal;
123         double m_distance;
124 };
125
126
127 class IK_QCenterOfMassTask : public IK_QTask
128 {
129 public:
130         IK_QCenterOfMassTask(
131                 bool primary,
132                 const IK_QSegment *segment,
133                 const Vector3d& center
134         );
135
136         void ComputeJacobian(IK_QJacobian& jacobian);
137
138         double Distance() const;
139
140         void Scale(double scale) { m_goal_center *= scale; m_distance *= scale; }
141
142 private:
143         double ComputeTotalMass(const IK_QSegment *segment);
144         Vector3d ComputeCenter(const IK_QSegment *segment);
145         void JacobianSegment(IK_QJacobian& jacobian, Vector3d& center, const IK_QSegment *segment);
146
147         Vector3d m_goal_center;
148         double m_total_mass_inv;
149         double m_distance;
150 };
151