Skip to content

Commit 754ced7

Browse files
committed
Squashed merge of PR #5471
commit 9ffc78f Merge: 0059ef6 25a096d Author: Hugo <hugo.talbot@sofa-framework.org> Date: Wed Apr 8 18:53:35 2026 +0200 Merge branch 'master' into 2025_sprintsed_BaseCamera commit 0059ef6 Merge: bf53c56 fb6ac6c Author: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Tue Jan 6 11:21:01 2026 +0100 Merge branch 'master' into 2025_sprintsed_BaseCamera commit bf53c56 Author: lbinria <77280433+lbinria@users.noreply.github.com> Date: Wed May 14 10:44:48 2025 +0200 [Framework] Apply template method design pattern to BaseCamera
1 parent 2c61228 commit 754ced7

7 files changed

Lines changed: 117 additions & 23 deletions

File tree

Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ type::Vec2 BaseCamera::worldToScreenCoordinates(const type::Vec3& pos)
366366
return screenCoord + type::Vec2(viewport[0], viewport[1]);
367367
}
368368

369-
void BaseCamera::getModelViewMatrix(double mat[16])
369+
void BaseCamera::doGetModelViewMatrix(double mat[16])
370370
{
371371
const sofa::type::Transform<SReal> world_H_cam(d_position.getValue(), this->getOrientation());
372372
Mat3 rot = world_H_cam.inversed().getRotationMatrix();
@@ -395,7 +395,7 @@ void BaseCamera::getOpenGLModelViewMatrix(double mat[16])
395395
world_H_cam.inversed().writeOpenGlMatrix(mat);
396396
}
397397

398-
void BaseCamera::getProjectionMatrix(double mat[16])
398+
void BaseCamera::doGetProjectionMatrix(double mat[16])
399399
{
400400
const double width = double(d_widthViewport.getValue());
401401
const double height = double(d_heightViewport.getValue());
@@ -537,7 +537,8 @@ void BaseCamera::rotateCameraAroundPoint(Quat& rotation, const type::Vec3& point
537537
updateOutputData();
538538
}
539539

540-
void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point, Quat orientationCam, type::Vec3 positionCam)
540+
541+
void BaseCamera::doRotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point, Quat orientationCam, type::Vec3 positionCam)
541542
{
542543
type::Vec3 tempAxis;
543544
SReal tempAngle;
@@ -566,7 +567,7 @@ void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point,
566567
}
567568

568569

569-
void BaseCamera::rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam)
570+
void BaseCamera::doRotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam)
570571
{
571572
auto positionCam = sofa::helper::getReadAccessor(d_position);
572573
rotateWorldAroundPoint(rotation, point, orientationCam, positionCam);
@@ -941,7 +942,7 @@ void BaseCamera::draw(const sofa::core::visual::VisualParams* /*params*/)
941942
{
942943
}
943944

944-
void BaseCamera::drawCamera(const core::visual::VisualParams* vparams)
945+
void BaseCamera::doDrawCamera(const core::visual::VisualParams* vparams)
945946
{
946947
const auto dt = (vparams->drawTool());
947948
dt->setPolygonMode(0, true);

Sofa/Component/Visual/src/sofa/component/visual/BaseCamera.h

Lines changed: 106 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,34 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo
102102
void moveCamera(const type::Vec3 &p, const Quat &q);
103103

104104
void rotateCameraAroundPoint( Quat& rotation, const type::Vec3& point);
105-
virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam);
106-
virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam, type::Vec3 positionCam);
105+
106+
/**
107+
* !!! WARNING since v25.12 !!!
108+
*
109+
* The template method pattern has been applied to this part of the API.
110+
* This method calls the newly introduced method "doRotateWorldAroundPoint" internally,
111+
* which is the method to override from now on.
112+
*
113+
**/
114+
virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam) final {
115+
//TODO (SPRINT SED 2025): Component state mechanism
116+
this->doRotateWorldAroundPoint(rotation, point, orientationCam);
117+
}
118+
119+
120+
/**
121+
* !!! WARNING since v25.12 !!!
122+
*
123+
* The template method pattern has been applied to this part of the API.
124+
* This method calls the newly introduced method "doRotateWorldAroundPoint" internally,
125+
* which is the method to override from now on.
126+
*
127+
**/
128+
virtual void rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam, type::Vec3 positionCam) final {
129+
//TODO (SPRINT SED 2025): Component state mechanism
130+
this->doRotateWorldAroundPoint(rotation, point, orientationCam, positionCam);
131+
}
132+
107133

108134
type::Vec3 screenToViewportPoint(const type::Vec3& p) const;
109135
type::Vec3 screenToWorldPoint(const type::Vec3& p);
@@ -191,17 +217,64 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo
191217
//be according to the gravity.
192218
void setDefaultView(const type::Vec3& gravity = type::Vec3(0, -9.81, 0));
193219

194-
virtual void getModelViewMatrix(double mat[16]);
195-
virtual void getProjectionMatrix(double mat[16]);
220+
/**
221+
* !!! WARNING since v25.12 !!!
222+
*
223+
* The template method pattern has been applied to this part of the API.
224+
* This method calls the newly introduced method "doGetModelViewMatrix" internally,
225+
* which is the method to override from now on.
226+
*
227+
**/
228+
virtual void getModelViewMatrix(double mat[16]) final {
229+
//TODO (SPRINT SED 2025): Component state mechanism
230+
this->doGetModelViewMatrix(mat);
231+
}
232+
233+
/**
234+
* !!! WARNING since v25.12 !!!
235+
*
236+
* The template method pattern has been applied to this part of the API.
237+
* This method calls the newly introduced method "doGetProjectionMatrix" internally,
238+
* which is the method to override from now on.
239+
*
240+
**/
241+
virtual void getProjectionMatrix(double mat[16]) final {
242+
//TODO (SPRINT SED 2025): Component state mechanism
243+
this->doGetProjectionMatrix(mat);
244+
}
245+
196246
void getOpenGLModelViewMatrix(double mat[16]);
197247
void getOpenGLProjectionMatrix(double mat[16]);
198248

199249
Quat getOrientationFromLookAt(const type::Vec3 &pos, const type::Vec3& lookat);
200250
type::Vec3 getLookAtFromOrientation(const type::Vec3 &pos, const double &distance,const Quat & orientation);
201251
type::Vec3 getPositionFromOrientation(const type::Vec3 &lookAt, const double &distance, const Quat& orientation);
202252

203-
virtual void manageEvent(core::objectmodel::Event* event) = 0 ;
204-
virtual void internalUpdate() {}
253+
/**
254+
* !!! WARNING since v25.12 !!!
255+
*
256+
* The template method pattern has been applied to this part of the API.
257+
* This method calls the newly introduced method "doManageEvent" internally,
258+
* which is the method to override from now on.
259+
*
260+
**/
261+
virtual void manageEvent(core::objectmodel::Event* event) final {
262+
//TODO (SPRINT SED 2025): Component state mechanism
263+
this->doManageEvent(event);
264+
}
265+
266+
/**
267+
* !!! WARNING since v25.12 !!!
268+
*
269+
* The template method pattern has been applied to this part of the API.
270+
* This method calls the newly introduced method "doInternalUpdate" internally,
271+
* which is the method to override from now on.
272+
*
273+
**/
274+
virtual void internalUpdate() final {
275+
//TODO (SPRINT SED 2025): Component state mechanism
276+
this->doInternalUpdate();
277+
}
205278

206279
void handleEvent(sofa::core::objectmodel::Event* event) override;
207280
void computeZ();
@@ -254,13 +327,38 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseCompo
254327

255328
void draw(const core::visual::VisualParams*) override ;
256329
void computeClippingPlane(const core::visual::VisualParams* vp, double& zNear, double& zFar);
257-
virtual void drawCamera(const core::visual::VisualParams*);
330+
331+
/**
332+
* !!! WARNING since v25.12 !!!
333+
*
334+
* The template method pattern has been applied to this part of the API.
335+
* This method calls the newly introduced method "doDrawCamera" internally,
336+
* which is the method to override from now on.
337+
*
338+
**/
339+
virtual void drawCamera(const core::visual::VisualParams* vparams) final {
340+
//TODO (SPRINT SED 2025): Component state mechanism
341+
this->doDrawCamera(vparams);
342+
}
343+
258344
protected:
259345
void updateOutputData();
260346

347+
virtual void doRotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam);
348+
virtual void doRotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam, type::Vec3 positionCam);
349+
350+
virtual void doManageEvent(core::objectmodel::Event* event) = 0;
351+
352+
virtual void doGetModelViewMatrix(double mat[16]);
353+
virtual void doGetProjectionMatrix(double mat[16]);
354+
355+
virtual void doInternalUpdate() {}
356+
357+
virtual void doDrawCamera(const core::visual::VisualParams*);
358+
261359
type::Vec3 getSceneCenter() const;
262360
SReal getSceneRadius() const;
263-
361+
264362
bool b_setDefaultParameters;
265363

266364
//need to keep "internal" lookAt and distance for updating Data

Sofa/Component/Visual/src/sofa/component/visual/Camera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SOFA_COMPONENT_VISUAL_API Camera : public BaseCamera
3737
~Camera() override;
3838

3939
public:
40-
void manageEvent(core::objectmodel::Event* e) override { SOFA_UNUSED(e); }
40+
void doManageEvent(core::objectmodel::Event* e) override { SOFA_UNUSED(e); }
4141

4242
private:
4343

Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ InteractiveCamera::~InteractiveCamera()
4848
{
4949
}
5050

51-
void InteractiveCamera::internalUpdate()
52-
{
53-
}
54-
5551
void InteractiveCamera::moveCamera(int x, int y)
5652
{
5753
Quat newQuat;
@@ -147,7 +143,7 @@ void InteractiveCamera::moveCamera(int x, int y)
147143
}
148144

149145

150-
void InteractiveCamera::manageEvent(core::objectmodel::Event* e)
146+
void InteractiveCamera::doManageEvent(core::objectmodel::Event* e)
151147
{
152148

153149

Sofa/Component/Visual/src/sofa/component/visual/InteractiveCamera.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ class SOFA_COMPONENT_VISUAL_API InteractiveCamera : public BaseCamera
5959
sofa::type::Quatd m_startingCameraOrientation;
6060
sofa::type::Vec3 m_startingCameraPosition;
6161

62-
void internalUpdate() override;
6362
protected:
6463
void moveCamera(int x, int y);
65-
void manageEvent(core::objectmodel::Event* e) override;
64+
void doManageEvent(core::objectmodel::Event* e) override;
6665
void processMouseEvent(core::objectmodel::MouseEvent* me);
6766
void processKeyPressedEvent(core::objectmodel::KeypressedEvent* kpe);
6867
void processKeyReleasedEvent(core::objectmodel::KeyreleasedEvent* kre);

Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void RecordedCamera::initializeViewUp()
391391
}
392392
}
393393

394-
void RecordedCamera::manageEvent(core::objectmodel::Event* e)
394+
void RecordedCamera::doManageEvent(core::objectmodel::Event* e)
395395
{
396396
if(d_activated.getValue())
397397
{

Sofa/Component/Visual/src/sofa/component/visual/RecordedCamera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SOFA_COMPONENT_VISUAL_API RecordedCamera : public BaseCamera
6565

6666
// Kepp functions for mouse interaction (TODO: removed them and allow interactive and recorded camera in same scene)
6767
void moveCamera_mouse(int x, int y);
68-
void manageEvent(core::objectmodel::Event* e) override;
68+
void doManageEvent(core::objectmodel::Event* e) override;
6969
void processMouseEvent(core::objectmodel::MouseEvent* me);
7070

7171
void configureRotation();

0 commit comments

Comments
 (0)