Skip to content

Commit 783084b

Browse files
committed
Merge branch 'master' of https://github.com/sofa-framework/sofa
2 parents 82a14c2 + c24cb2c commit 783084b

File tree

6 files changed

+147
-45
lines changed

6 files changed

+147
-45
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,23 @@ void BaseCamera::moveCamera(const type::Vec3 &p, const Quat &q)
217217
updateOutputData();
218218
}
219219

220-
type::Vec3 BaseCamera::cameraToWorldCoordinates(const type::Vec3& p)
220+
type::Vec3 BaseCamera::cameraToWorldCoordinates(const type::Vec3& p) const
221221
{
222222
return d_orientation.getValue().rotate(p) + d_position.getValue();
223223
}
224224

225-
type::Vec3 BaseCamera::worldToCameraCoordinates(const type::Vec3& p)
225+
type::Vec3 BaseCamera::worldToCameraCoordinates(const type::Vec3& p) const
226226
{
227227
return d_orientation.getValue().inverseRotate(p - d_position.getValue());
228228
}
229229

230-
type::Vec3 BaseCamera::cameraToWorldTransform(const type::Vec3& v)
230+
type::Vec3 BaseCamera::cameraToWorldTransform(const type::Vec3& v) const
231231
{
232232
const Quat q = d_orientation.getValue();
233233
return q.rotate(v) ;
234234
}
235235

236-
type::Vec3 BaseCamera::worldToCameraTransform(const type::Vec3& v)
236+
type::Vec3 BaseCamera::worldToCameraTransform(const type::Vec3& v) const
237237
{
238238
return d_orientation.getValue().inverseRotate(v);
239239
}
@@ -305,7 +305,7 @@ void BaseCamera::setCameraType(unsigned int type)
305305
}
306306

307307

308-
double BaseCamera::getHorizontalFieldOfView()
308+
double BaseCamera::getHorizontalFieldOfView() const
309309
{
310310
const sofa::core::visual::VisualParams* vp = sofa::core::visual::VisualParams::defaultInstance();
311311
const core::visual::VisualParams::Viewport viewport = vp->viewport();
@@ -661,6 +661,9 @@ void BaseCamera::computeZ()
661661
{
662662
if (d_computeZClip.getValue())
663663
{
664+
const auto sceneCenter = getSceneCenter();
665+
const auto sceneRadius = getSceneRadius();
666+
664667
//modelview transform
665668
sofa::type::Transform<SReal> world_H_cam(d_position.getValue(), this->getOrientation());
666669

@@ -737,9 +740,7 @@ void BaseCamera::setView(const type::Vec3& position, const Quat &orientation)
737740

738741
void BaseCamera::setDefaultView(const type::Vec3 & gravity)
739742
{
740-
const type::Vec3 & minBBox = d_minBBox.getValue();
741-
const type::Vec3 & maxBBox = d_maxBBox.getValue();
742-
sceneCenter = (minBBox + maxBBox)*0.5;
743+
const auto sceneCenter = getSceneCenter();
743744

744745
if (b_setDefaultParameters)
745746
{
@@ -770,7 +771,7 @@ void BaseCamera::setDefaultView(const type::Vec3 & gravity)
770771

771772
//Distance
772773
const double coeff = 3.0;
773-
const double dist = (minBBox - sceneCenter).norm() * coeff;
774+
const double dist = (d_minBBox.getValue() - getSceneCenter()).norm() * coeff;
774775
d_distance.setValue(dist);
775776
currentDistance = dist;
776777

@@ -782,7 +783,7 @@ void BaseCamera::setDefaultView(const type::Vec3 & gravity)
782783
computeZ();
783784
}
784785

785-
void BaseCameraXMLExportSingleParameter(tinyxml2::XMLElement* root, core::objectmodel::BaseData& data, const std::string& comment)
786+
void BaseCameraXMLExportSingleParameter(tinyxml2::XMLElement* root, const core::objectmodel::BaseData& data, const std::string& comment)
786787
{
787788
tinyxml2::XMLElement* node = root->GetDocument()->NewElement( data.getName().c_str() );
788789
node->SetAttribute("value", data.getValueString().c_str() );
@@ -794,7 +795,7 @@ void BaseCameraXMLExportSingleParameter(tinyxml2::XMLElement* root, core::object
794795
root->LinkEndChild(node);
795796
}
796797

797-
bool BaseCamera::exportParametersInFile(const std::string& viewFilename)
798+
bool BaseCamera::exportParametersInFile(const std::string& viewFilename) const
798799
{
799800
tinyxml2::XMLDocument doc;
800801
tinyxml2::XMLDeclaration* decl = doc.NewDeclaration();
@@ -920,6 +921,16 @@ void BaseCamera::updateOutputData()
920921
d_zFar.setValue(currentZFar);
921922
}
922923

924+
type::Vec3 BaseCamera::getSceneCenter() const
925+
{
926+
return (d_minBBox.getValue() + d_maxBBox.getValue()) * 0.5_sreal;
927+
}
928+
929+
SReal BaseCamera::getSceneRadius() const
930+
{
931+
return 0.5_sreal * (d_maxBBox.getValue() - d_minBBox.getValue()).norm();
932+
}
933+
923934
void BaseCamera::handleEvent(sofa::core::objectmodel::Event* event)
924935
{
925936
if (sofa::simulation::AnimateBeginEvent::checkEventType(event))

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
9393
void desactivate();
9494
bool isActivated();
9595

96-
bool exportParametersInFile(const std::string& viewFilename);
96+
bool exportParametersInFile(const std::string& viewFilename) const;
9797
bool importParametersFromFile(const std::string& viewFilename);
9898

9999
void translate(const type::Vec3& t);
@@ -120,24 +120,25 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
120120
type::Ray toRay() const;
121121

122122

123-
type::Vec3 cameraToWorldCoordinates(const type::Vec3& p);
124-
type::Vec3 worldToCameraCoordinates(const type::Vec3& p);
125-
type::Vec3 cameraToWorldTransform(const type::Vec3& v);
126-
type::Vec3 worldToCameraTransform(const type::Vec3& v);
123+
type::Vec3 cameraToWorldCoordinates(const type::Vec3& p) const;
124+
type::Vec3 worldToCameraCoordinates(const type::Vec3& p) const;
125+
type::Vec3 cameraToWorldTransform(const type::Vec3& v) const;
126+
type::Vec3 worldToCameraTransform(const type::Vec3& v) const;
127127
type::Vec3 screenToWorldCoordinates(int x, int y);
128128
type::Vec2 worldToScreenCoordinates(const type::Vec3& p);
129129

130130
void fitSphere(const type::Vec3& center, SReal radius);
131131
void fitBoundingBox(const type::Vec3& min,const type::Vec3& max);
132132

133133

134-
type::Vec3 getPosition()
134+
const type::Vec3& getPosition() const
135135
{
136136
return d_position.getValue();
137137
}
138138

139-
Quat getOrientation() ;
140-
type::Vec3 getLookAt()
139+
Quat getOrientation();
140+
141+
const type::Vec3& getLookAt() const
141142
{
142143
return d_lookAt.getValue();
143144
}
@@ -148,12 +149,12 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
148149
return d_distance.getValue();
149150
}
150151

151-
double getFieldOfView()
152+
double getFieldOfView() const
152153
{
153154
return d_fieldOfView.getValue();
154155
}
155156

156-
double getHorizontalFieldOfView() ;
157+
double getHorizontalFieldOfView() const;
157158

158159
unsigned int getCameraType() const ;
159160

@@ -164,9 +165,6 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
164165
d_minBBox.setValue(min);
165166
d_maxBBox.setValue(max);
166167

167-
sceneCenter = (min + max)*0.5;
168-
sceneRadius = 0.5*(max - min).norm();
169-
170168
computeZ();
171169
}
172170

@@ -176,12 +174,12 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
176174
d_heightViewport.setValue(h);
177175
}
178176

179-
double getZNear()
177+
double getZNear() const
180178
{
181179
return currentZNear;
182180
}
183181

184-
double getZFar()
182+
double getZFar() const
185183
{
186184
return currentZFar;
187185
}
@@ -260,8 +258,8 @@ class SOFA_COMPONENT_VISUAL_API BaseCamera : public core::objectmodel::BaseObjec
260258
protected:
261259
void updateOutputData();
262260

263-
type::Vec3 sceneCenter;
264-
SReal sceneRadius;
261+
type::Vec3 getSceneCenter() const;
262+
SReal getSceneRadius() const;
265263

266264
bool b_setDefaultParameters;
267265

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ void InteractiveCamera::moveCamera(int x, int y)
8585
break;
8686
case SCENE_CENTER_PIVOT:
8787
default:
88-
pivot = sceneCenter;
88+
pivot = getSceneCenter();
8989
break;
9090
}
9191
rotateWorldAroundPoint(newQuat, pivot, m_startingCameraOrientation, m_startingCameraPosition);
9292
}
9393
else if (currentMode == ZOOM_MODE)
9494
{
95-
const double zoomStep = d_zoomSpeed.getValue() * (0.01 * sceneRadius ) / heightViewport;
95+
const double zoomStep = d_zoomSpeed.getValue() * (0.01 * getSceneRadius() ) / heightViewport;
9696
double zoomDistance = zoomStep * -(y - lastMousePosY);
9797

9898
type::Vec3 trans(0.0, 0.0, zoomDistance);
@@ -109,7 +109,7 @@ void InteractiveCamera::moveCamera(int x, int y)
109109
else if (currentMode == PAN_MODE)
110110
{
111111
type::Vec3 trans(lastMousePosX - x, y-lastMousePosY, 0.0);
112-
trans = cameraToWorldTransform(trans) * d_panSpeed.getValue() * (0.01 * sceneRadius ) ;
112+
trans = cameraToWorldTransform(trans) * d_panSpeed.getValue() * (0.01 * getSceneRadius() ) ;
113113
translate(trans);
114114
if ( !d_fixedLookAtPoint.getValue() )
115115
{
@@ -126,7 +126,7 @@ void InteractiveCamera::moveCamera(int x, int y)
126126
}
127127
else if (currentMode == WHEEL_ZOOM_MODE)
128128
{
129-
const double zoomStep = d_zoomSpeed.getValue() * (0.01 * sceneRadius ) / heightViewport;
129+
const double zoomStep = d_zoomSpeed.getValue() * (0.01 * getSceneRadius() ) / heightViewport;
130130
double zoomDistance = zoomStep * -(y*0.5);
131131

132132
type::Vec3 trans(0.0, 0.0, zoomDistance);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void RecordedCamera::moveCamera_mouse(int x, int y)
503503
break;
504504
case SCENE_CENTER_PIVOT :
505505
default:
506-
pivot = sceneCenter;
506+
pivot = getSceneCenter();
507507
break;
508508
}
509509

Sofa/framework/Type/src/sofa/type/RGBAColor.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ static int hexval(const char c)
6262
static void extractValidatedHexaString(std::istream& in, std::string& s)
6363
{
6464
s.reserve(9);
65-
char c = in.get();
65+
char c {};
66+
in.get(c);
67+
68+
if (in.fail())
69+
{
70+
return;
71+
}
6672

6773
if(c!='#')
6874
{
@@ -71,14 +77,15 @@ static void extractValidatedHexaString(std::istream& in, std::string& s)
7177
}
7278

7379
s.push_back(c);
74-
while(in.get(c)){
75-
if( !ishexsymbol(c) )
76-
return;
80+
while (in.get(c))
81+
{
82+
if (!ishexsymbol(c)) return;
7783

78-
s.push_back(c) ;
79-
if(s.size()>9){
80-
in.setstate(std::ios_base::failbit) ;
81-
return ;
84+
s.push_back(c);
85+
if (s.size() > 9)
86+
{
87+
in.setstate(std::ios_base::failbit);
88+
return;
8289
}
8390
}
8491
/// we need to reset the failbit because it is set by the get function
@@ -168,11 +175,11 @@ RGBAColor RGBAColor::fromHSVA(const float h, const float s, const float v, const
168175
/// This function remove the leading space in the stream.
169176
static std::istream& trimInitialSpaces(std::istream& in)
170177
{
171-
char first=in.peek();
172-
while(!in.eof() && !in.fail() && std::isspace(first, std::locale()))
178+
char first = static_cast<char>(in.peek());
179+
while (!in.eof() && !in.fail() && std::isspace(first, std::locale()))
173180
{
174181
in.get();
175-
first=in.peek();
182+
first = static_cast<char>(in.peek());
176183
}
177184
return in;
178185
}
@@ -213,7 +220,7 @@ SOFA_TYPE_API std::istream& operator>>(std::istream& i, RGBAColor& t)
213220
if( i.eof() || i.fail() )
214221
return i;
215222

216-
const char first = i.peek() ;
223+
const char first = static_cast<char>(i.peek()) ;
217224
if (std::isdigit(first, std::locale()))
218225
{
219226
i >> r >> g >> b ;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0"?>
2+
<Node name="root" dt="0.01" gravity="0 -9.81 0">
3+
<!--
4+
If all tetrahedra in a mesh are oriented in the same way (for example, all diagonals in a structured grid are split
5+
consistently in one direction), the mesh itself introduces a preferred direction.
6+
7+
Even if the material model is isotropic, the numerical solution behaves as if the material were anisotropic.
8+
9+
If the diagonals were alternated or randomized, the effect would largely disappear. The alternation can be
10+
controlled by the Data 'swapping' in the component 'Hexa2TetrahedronTopologicalMapping'.
11+
12+
This scene shows the effect of the mesh-induced anisotropy at equilibrium, compared to a mesh where the diagonals
13+
are alternated.
14+
-->
15+
<Node name="plugins">
16+
<RequiredPlugin name="Sofa.Component.Constraint.Projective"/> <!-- Needed to use components [FixedProjectiveConstraint] -->
17+
<RequiredPlugin name="Sofa.Component.Engine.Select"/> <!-- Needed to use components [BoxROI] -->
18+
<RequiredPlugin name="Sofa.Component.LinearSolver.Direct"/> <!-- Needed to use components [SparseLDLSolver] -->
19+
<RequiredPlugin name="Sofa.Component.Mass"/> <!-- Needed to use components [DiagonalMass] -->
20+
<RequiredPlugin name="Sofa.Component.ODESolver.Backward"/> <!-- Needed to use components [NewtonRaphsonSolver,StaticSolver] -->
21+
<RequiredPlugin name="Sofa.Component.SolidMechanics.FEM.Elastic"/> <!-- Needed to use components [TetrahedronFEMForceField] -->
22+
<RequiredPlugin name="Sofa.Component.StateContainer"/> <!-- Needed to use components [MechanicalObject] -->
23+
<RequiredPlugin name="Sofa.Component.Topology.Container.Dynamic"/> <!-- Needed to use components [TetrahedronSetGeometryAlgorithms,TetrahedronSetTopologyContainer,TetrahedronSetTopologyModifier] -->
24+
<RequiredPlugin name="Sofa.Component.Topology.Container.Grid"/> <!-- Needed to use components [RegularGridTopology] -->
25+
<RequiredPlugin name="Sofa.Component.Topology.Mapping"/> <!-- Needed to use components [Hexa2TetraTopologicalMapping] -->
26+
<RequiredPlugin name="Sofa.Component.Visual"/> <!-- Needed to use components [VisualMesh,VisualStyle] -->
27+
</Node>
28+
29+
<DefaultAnimationLoop/>
30+
<VisualStyle displayFlags="showBehaviorModels" />
31+
32+
<!-- Dimensions are in meters -->
33+
<RegularGridTopology name="grid" min="-0.01 -0.01 0" max="0.01 0.01 0.2" n="5 5 30"/>
34+
35+
<Node name="beam_with_anisotropy">
36+
<NewtonRaphsonSolver name="non_linear_solver" maxNbIterationsNewton="100"
37+
maxNbIterationsLineSearch="1" warnWhenLineSearchFails="false"/>
38+
<StaticSolver name="static_solver" newtonSolver="@non_linear_solver"/>
39+
<SparseLDLSolver name="linear_solver" template="CompressedRowSparseMatrixMat3x3d"/>
40+
41+
<MechanicalObject template="Vec3" name="state" position="@/grid.position"/>
42+
43+
<Node name="tetrahedra">
44+
<TetrahedronSetTopologyContainer name="Tetra_topo" position="@/grid.position"/>
45+
<TetrahedronSetTopologyModifier name="Modifier" />
46+
<TetrahedronSetGeometryAlgorithms template="Vec3" name="GeomAlgo" />
47+
<Hexa2TetraTopologicalMapping input="@grid" output="@Tetra_topo" swapping="false"/>
48+
49+
<!-- Density is in kg/m^3 -->
50+
<DiagonalMass massDensity="1100" />
51+
<!-- Young's modulus is in Pa -->
52+
<TetrahedronFEMForceField name="FEM" youngModulus="1e6" poissonRatio="0.48"/>
53+
54+
<VisualMesh position="@state.position" topology="@Tetra_topo"/>
55+
</Node>
56+
57+
<BoxROI template="Vec3" name="box_roi" box="-0.011 -0.011 -0.0001 0.011 0.011 0.0001" drawBoxes="1" />
58+
<FixedProjectiveConstraint template="Vec3" indices="@box_roi.indices" />
59+
</Node>
60+
61+
<Node name="beam_without_anisotropy">
62+
<NewtonRaphsonSolver name="non_linear_solver" maxNbIterationsNewton="100"
63+
maxNbIterationsLineSearch="1" warnWhenLineSearchFails="false"/>
64+
<StaticSolver name="static_solver" newtonSolver="@non_linear_solver"/>
65+
<SparseLDLSolver name="linear_solver" template="CompressedRowSparseMatrixMat3x3d"/>
66+
67+
<MechanicalObject template="Vec3" name="state" position="@/grid.position"/>
68+
69+
<Node name="tetrahedra">
70+
<TetrahedronSetTopologyContainer name="Tetra_topo" position="@/grid.position"/>
71+
<TetrahedronSetTopologyModifier name="Modifier" />
72+
<TetrahedronSetGeometryAlgorithms template="Vec3" name="GeomAlgo" />
73+
<Hexa2TetraTopologicalMapping input="@grid" output="@Tetra_topo" swapping="true"/>
74+
75+
<!-- Density is in kg/m^3 -->
76+
<DiagonalMass massDensity="1100" />
77+
<!-- Young's modulus is in Pa -->
78+
<TetrahedronFEMForceField name="FEM" youngModulus="1e6" poissonRatio="0.48"/>
79+
80+
<VisualMesh position="@state.position" topology="@Tetra_topo"/>
81+
</Node>
82+
83+
<BoxROI template="Vec3" name="box_roi" box="-0.011 -0.011 -0.0001 0.011 0.011 0.0001" drawBoxes="1" />
84+
<FixedProjectiveConstraint template="Vec3" indices="@box_roi.indices" />
85+
</Node>
86+
</Node>

0 commit comments

Comments
 (0)