Skip to content

Commit f4f3c88

Browse files
authored
Merge branch 'master' into 202511_image_new_registration_mechanism
2 parents 8eee025 + 38b8425 commit f4f3c88

20 files changed

Lines changed: 197 additions & 110 deletions

File tree

Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ MeshTopology::MeshTopology()
491491
, d_seqQuads(initData(&d_seqQuads, "quads", "List of quad indices"))
492492
, d_seqTetrahedra(initData(&d_seqTetrahedra, "tetrahedra", "List of tetrahedron indices"))
493493
, d_seqHexahedra(initData(&d_seqHexahedra, "hexahedra", "List of hexahedron indices"))
494+
, d_seqPrisms(initData(&d_seqPrisms, "prisms", "List of prisms indices"))
495+
, d_seqPyramids(initData(&d_seqPyramids, "pyramids", "List of pyramids indices"))
494496
, d_seqUVs(initData(&d_seqUVs, "uv", "List of uv coordinates"))
495497
, d_computeAllBuffers(initData(&d_computeAllBuffers, false, "computeAllBuffers", "Option to compute all crossed topology buffers at init. False by default"))
496498
, nbPoints(0)
@@ -763,7 +765,6 @@ const MeshTopology::SeqTriangles& MeshTopology::getTriangles()
763765

764766
const MeshTopology::SeqQuads& MeshTopology::getQuads()
765767
{
766-
767768
return d_seqQuads.getValue();
768769
}
769770

@@ -787,6 +788,16 @@ const MeshTopology::SeqHexahedra& MeshTopology::getHexahedra()
787788
return d_seqHexahedra.getValue();
788789
}
789790

791+
const BaseMeshTopology::SeqPrisms& MeshTopology::getPrisms()
792+
{
793+
return d_seqPrisms.getValue();
794+
}
795+
796+
const BaseMeshTopology::SeqPyramids& MeshTopology::getPyramids()
797+
{
798+
return d_seqPyramids.getValue();
799+
}
800+
790801
const MeshTopology::SeqUV& MeshTopology::getUVs()
791802
{
792803
return d_seqUVs.getValue();

Sofa/Component/Topology/Container/Constant/src/sofa/component/topology/container/constant/MeshTopology.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class SOFA_COMPONENT_TOPOLOGY_CONTAINER_CONSTANT_API MeshTopology : public core:
9898
const SeqQuads& getQuads() override;
9999
const SeqTetrahedra& getTetrahedra() override;
100100
const SeqHexahedra& getHexahedra() override;
101+
const SeqPrisms& getPrisms() override;
102+
const SeqPyramids& getPyramids() override;
101103

102104
// If using STEP loader, include also uv coordinates
103105
typedef Index UVID;
@@ -298,6 +300,8 @@ class SOFA_COMPONENT_TOPOLOGY_CONTAINER_CONSTANT_API MeshTopology : public core:
298300
Data<SeqQuads> d_seqQuads; ///< List of quad indices
299301
Data<SeqTetrahedra> d_seqTetrahedra; ///< List of tetrahedron indices
300302
Data<SeqHexahedra> d_seqHexahedra; ///< List of hexahedron indices
303+
Data<SeqPrisms> d_seqPrisms;
304+
Data<SeqPyramids> d_seqPyramids;
301305
Data<SeqUV> d_seqUVs; ///< List of uv coordinates
302306
Data<bool> d_computeAllBuffers; ///< Option to call method computeCrossElementBuffers. False by default
303307

Sofa/Component/Topology/Mapping/src/sofa/component/topology/mapping/Hexa2TetraTopologicalMapping.cpp

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ void Hexa2TetraTopologicalMapping::init()
6666
{
6767
using namespace container::dynamic;
6868

69+
Inherit1::init();
70+
6971
if (!this->checkTopologyInputTypes()) // method will display error message if false
7072
{
7173
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
7274
return;
7375
}
7476

75-
TetrahedronSetTopologyModifier* to_tstm;
77+
TetrahedronSetTopologyModifier* to_tstm { nullptr };
7678
toModel->getContext()->get(to_tstm);
7779
if (!to_tstm)
7880
{
@@ -83,8 +85,15 @@ void Hexa2TetraTopologicalMapping::init()
8385

8486
// INITIALISATION of TETRAHEDRAL mesh from HEXAHEDRAL mesh :
8587

86-
TetrahedronSetTopologyContainer *to_tstc;
88+
TetrahedronSetTopologyContainer *to_tstc { nullptr };
8789
toModel->getContext()->get(to_tstc);
90+
if (!to_tstc)
91+
{
92+
msg_error() << "No TetrahedronSetTopologyContainer found in the Tetrahedron topology Node.";
93+
this->d_componentState.setValue(sofa::core::objectmodel::ComponentState::Invalid);
94+
return;
95+
}
96+
8897
// Clear output topology
8998
to_tstc->clear();
9099

@@ -111,45 +120,49 @@ void Hexa2TetraTopologicalMapping::init()
111120
}
112121
}
113122

123+
static constexpr int numberTetraInHexa = 6;
124+
Loc2GlobVec.reserve(nbcubes*numberTetraInHexa);
125+
126+
const bool swapping = d_swapping.getValue();
127+
114128
// Tessellation of each cube into 6 tetrahedra
115-
for (size_t i=0; i<nbcubes; i++)
129+
for (size_t i = 0; i < nbcubes; ++i)
116130
{
117131
core::topology::BaseMeshTopology::Hexa c = fromModel->getHexahedron(i);
118-
#define swap(a,b) { int t = a; a = b; b = t; }
119-
// TODO : swap indexes where needed (currently crash in TriangleSetContainer)
132+
120133
bool swapped = false;
121134

122-
if(d_swapping.getValue())
135+
if(swapping)
123136
{
124137
if (!((i%nx)&1))
125138
{
126139
// swap all points on the X edges
127-
swap(c[0],c[1]);
128-
swap(c[3],c[2]);
129-
swap(c[4],c[5]);
130-
swap(c[7],c[6]);
140+
std::swap(c[0],c[1]);
141+
std::swap(c[3],c[2]);
142+
std::swap(c[4],c[5]);
143+
std::swap(c[7],c[6]);
131144
swapped = !swapped;
132145
}
133146
if (((i/nx)%ny)&1)
134147
{
135148
// swap all points on the Y edges
136-
swap(c[0],c[3]);
137-
swap(c[1],c[2]);
138-
swap(c[4],c[7]);
139-
swap(c[5],c[6]);
149+
std::swap(c[0],c[3]);
150+
std::swap(c[1],c[2]);
151+
std::swap(c[4],c[7]);
152+
std::swap(c[5],c[6]);
140153
swapped = !swapped;
141154
}
142155
if ((i/(nx*ny))&1)
143156
{
144157
// swap all points on the Z edges
145-
swap(c[0],c[4]);
146-
swap(c[1],c[5]);
147-
swap(c[2],c[6]);
148-
swap(c[3],c[7]);
158+
std::swap(c[0],c[4]);
159+
std::swap(c[1],c[5]);
160+
std::swap(c[2],c[6]);
161+
std::swap(c[3],c[7]);
149162
swapped = !swapped;
150163
}
151164
}
152-
#undef swap
165+
153166
if(!swapped)
154167
{
155168
to_tstc->addTetra(c[0],c[5],c[1],c[6]);
@@ -168,9 +181,11 @@ void Hexa2TetraTopologicalMapping::init()
168181
to_tstc->addTetra(c[6],c[7],c[5],c[0]);
169182
to_tstc->addTetra(c[7],c[5],c[0],c[4]);
170183
}
171-
for(int j=0; j<6; j++)
184+
for (int j = 0; j < numberTetraInHexa; j++)
185+
{
172186
Loc2GlobVec.push_back(i);
173-
Glob2LocMap[i] = (unsigned int)Loc2GlobVec.size()-1;
187+
}
188+
Glob2LocMap[i] = static_cast<unsigned int>(Loc2GlobVec.size()) -1;
174189
}
175190

176191
// Need to fully init the target topology
@@ -181,7 +196,6 @@ void Hexa2TetraTopologicalMapping::init()
181196

182197
Index Hexa2TetraTopologicalMapping::getFromIndex(Index /*ind*/)
183198
{
184-
185199
return sofa::InvalidID;
186200
}
187201

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,18 @@ 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)
540+
void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point, Quat orientationCam, type::Vec3 positionCam)
541541
{
542542
type::Vec3 tempAxis;
543543
SReal tempAngle;
544-
//Quat orientationCam = this->getOrientation();
545-
type::Vec3& positionCam = *d_position.beginEdit();
546544

547545
rotation.quatToAxis(tempAxis, tempAngle);
548-
const Quat tempQuat (orientationCam.rotate(-tempAxis), tempAngle);
546+
const Quat tempQuat(orientationCam.rotate(-tempAxis), tempAngle);
549547

550548
const sofa::type::Transform<SReal> world_H_cam(positionCam, orientationCam);
551549
const sofa::type::Transform<SReal> world_H_pivot(point, Quat());
552550
const sofa::type::Transform<SReal> pivotBefore_R_pivotAfter(type::Vec3(0.0,0.0,0.0), tempQuat);
553551
const sofa::type::Transform<SReal> camera_H_WorldAfter = world_H_cam.inversed() * world_H_pivot * pivotBefore_R_pivotAfter * world_H_pivot.inversed();
554-
//defaulttype::SolidTypes<double>::Transform camera_H_WorldAfter = worldBefore_H_cam.inversed()*worldBefore_R_worldAfter;
555552

556553
positionCam = camera_H_WorldAfter.inversed().getOrigin();
557554
orientationCam = camera_H_WorldAfter.inversed().getOrientation();
@@ -563,13 +560,17 @@ void BaseCamera::rotateWorldAroundPoint(Quat &rotation, const type::Vec3 &point,
563560
}
564561

565562
d_orientation.setValue(orientationCam);
566-
d_position.endEdit();
563+
d_position.setValue(positionCam);
567564

568565
updateOutputData();
569566
}
570567

571568

572-
569+
void BaseCamera::rotateWorldAroundPoint(Quat& rotation, const type::Vec3& point, Quat orientationCam)
570+
{
571+
auto positionCam = sofa::helper::getReadAccessor(d_position);
572+
rotateWorldAroundPoint(rotation, point, orientationCam, positionCam);
573+
}
573574

574575

575576
type::Vec3 BaseCamera::screenToViewportPoint(const type::Vec3& p) const

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
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);
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);
106107

107108
type::Vec3 screenToViewportPoint(const type::Vec3& p) const;
108109
type::Vec3 screenToWorldPoint(const type::Vec3& p);

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void InteractiveCamera::moveCamera(int x, int y)
7070
currentTrackball.ComputeQuaternion(x1, y1, x2, y2);
7171
//fetch rotation
7272
newQuat = currentTrackball.GetQuaternion();
73+
7374
type::Vec3 pivot;
7475
switch (d_pivot.getValue())
7576
{
@@ -87,7 +88,7 @@ void InteractiveCamera::moveCamera(int x, int y)
8788
pivot = sceneCenter;
8889
break;
8990
}
90-
rotateWorldAroundPoint(newQuat, pivot, this->getOrientation());
91+
rotateWorldAroundPoint(newQuat, pivot, m_startingCameraOrientation, m_startingCameraPosition);
9192
}
9293
else if (currentMode == ZOOM_MODE)
9394
{
@@ -117,8 +118,11 @@ void InteractiveCamera::moveCamera(int x, int y)
117118
}
118119
//must call update afterwards
119120

120-
lastMousePosX = x;
121-
lastMousePosY = y;
121+
if (currentMode != TRACKBALL_MODE)
122+
{
123+
lastMousePosX = x;
124+
lastMousePosY = y;
125+
}
122126
}
123127
else if (currentMode == WHEEL_ZOOM_MODE)
124128
{
@@ -186,6 +190,9 @@ void InteractiveCamera::processMouseEvent(core::objectmodel::MouseEvent* me)
186190
{
187191
isMoving = true;
188192
currentMode = TRACKBALL_MODE;
193+
194+
m_startingCameraOrientation = this->getOrientation();
195+
m_startingCameraPosition = this->getPosition();
189196
lastMousePosX = posX;
190197
lastMousePosY = posY;
191198
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class SOFA_COMPONENT_VISUAL_API InteractiveCamera : public BaseCamera
5656
bool isMoving;
5757
int lastMousePosX, lastMousePosY;
5858
helper::visual::Trackball currentTrackball;
59+
sofa::type::Quatd m_startingCameraOrientation;
60+
sofa::type::Vec3 m_startingCameraPosition;
5961

6062
void internalUpdate() override;
6163
protected:

Sofa/framework/Core/src/sofa/core/CategoryLibrary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace sofa::core
2727
{
2828

2929

30-
typedef sofa::core::ObjectFactory::Creator Creator;
30+
using Creator = sofa::core::ObjectFactory::BaseObjectCreator;
3131

3232
/**
3333
* \brief An Generic Category of the Sofa Library

0 commit comments

Comments
 (0)