File: ObjectCurve.h

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (154 lines) | stat: -rw-r--r-- 3,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "Bezier.h"
#include "PyMOLObject.h"
#include "Result.h"

#include <glm/vec3.hpp>
#include <vector>

struct ObjectCurveState : public CObjectState {
  ObjectCurveState(PyMOLGlobals* G);

  /**
   * Deserializes pylists into ObjectCurveState
   * @param serializedList serialized ObjectCurveState
   */
  ObjectCurveState(PyMOLGlobals* G, PyObject* serializedList);

  /**
   * Adds spline to object
   */
  void addDefaultBezierSpline();

  /**
   * @param t parameter t across Bezier Spline
   * @return interpolated position along curve object
   */
  glm::vec3 getPosition(float t) const;

  /**
   * @param t parameter t across Bezier Spline
   * @return direction at t
   */
  glm::vec3 getNormalizedDirection(float t) const;

  /**
   * updates the render CGO
   */
  void updateRenderCGO();

  /**
   * updates the raw bezier CGO
   */
  void updateRawCGO();

  /**
   * Serializes ObjectCurveState into python lists
   */
  PyObject* asPyList() const;

  std::vector<pymol::BezierSpline> splines;
  pymol::cache_ptr<CGO> rawCGO;
  pymol::cache_ptr<CGO> renderCGO;
};

class ObjectCurve : public pymol::CObject
{
public:
  ObjectCurve(PyMOLGlobals* G);

  /**
   * Deserializes pylists into ObjectCurve
   * @param serializedList serialized ObjectCurve
   */
  ObjectCurve(PyMOLGlobals* G, PyObject* serializedList);

  /**
   * Creates copy of this curve object
   */
  pymol::CObject* clone() const override;

  /**
   * Renders this object
   * @info render information context
   */
  void render(RenderInfo* info) override;

  /**
   * Updates the object
   */
  void update() override;

  /**
   * Invalidates parts of the object
   * @param rep representation[unused]
   * @param level invalidation level [unused]
   * @param state state to invalidate
   */
  void invalidate(cRep_t rep, cRepInv_t level, int state) override;

  /**
   * For picking, we hijack:
   * Picking::src::index => bezier point index in spline
   * - 0: Control Point
   * - 1: Left Handle
   * - 2: Right Handle
   * Picking::src::bond => spline index
   */

  /**
   * @param pick Picking information (maps picking to object details)
   * @return position from picking information
   */
  pymol::Result<glm::vec3> getPositionByPick(const Picking& pick);

  /**
   * @param pick Picking information (maps picking to object details)
   * @param newPos new position of picked bezier point
   */
  pymol::Result<> setPositionByPick(
      const Picking& pick, const glm::vec3& newPos);

  /**
   * @param pick Picking information (maps picking to object details)
   * @return pointer to Bezier spline based on picking info
   */
  pymol::Result<pymol::BezierSpline*> getBezierSplineByPick(
      const Picking& pick);

  /**
   * Serializes ObjectCurve into python lists
   */
  PyObject* asPyList() const;

  /**
   * Serializes managed ObjectCurveStates into python lists
   */
  PyObject* statesAsPyList() const;

  /**
   * Deserializes ObjectCurveStates from python lists
   */
  pymol::Result<> statesFromPyList(PyObject* serializedList);

  /**
   * @param t parameter t across Bezier Spline
   * @return interpolated position along curve object
   */
  glm::vec3 getPosition(float t) const;

  /**
   * @param t parameter t across Bezier Spline
   * @return direction at t
   */
  glm::vec3 getNormalizedDirection(float t) const;

private:
  std::vector<ObjectCurveState> m_states;

  /**
   * @param pick Picking information (maps picking to object details)
   * @return BezierSplinePoint based on pick
   */
  pymol::Result<pymol::BezierSplinePoint> getBezierPointByPick(
      const Picking& pick);
};