@@ -41,85 +41,26 @@ using sofa::type::Vec3;
4141// --------------------------------------------------------------------------------------
4242// --- Computation methods
4343// --------------------------------------------------------------------------------------
44- template <class DataTypes >
45- inline bool TearingEngine<DataTypes>::computeIntersectionNeighborTriangle(Coord normalizedFractureDirection, Coord Pa, Coord& Pb, Real& t)
46- {
47- SOFA_UNUSED (Pa);
48-
49- if (m_maxStressVertexIndex == InvalidID)
50- return false ;
51-
52- // Get Geometry Algorithm
53- TriangleSetGeometryAlgorithms<DataTypes>* _triangleGeo = nullptr ;
54- this ->m_topology ->getContext ()->get (_triangleGeo);
55- if (!_triangleGeo)
56- {
57- msg_error () << " Missing component: Unable to get TriangleSetGeometryAlgorithms from the current context." ;
58- sofa::core::objectmodel::BaseObject::d_componentState.setValue (sofa::core::objectmodel::ComponentState::Invalid);
59- return false ;
60- }
61-
62-
63- Index triangle_id = _triangleGeo->getTriangleInDirection (m_maxStressVertexIndex, normalizedFractureDirection);
64- if (triangle_id > this ->m_topology ->getNbTriangles () - 1 )
65- return false ;
66-
67-
68- const Triangle& VertexIndicies = this ->m_topology ->getTriangle (triangle_id);
69-
70- constexpr size_t numVertices = 3 ;
71- Index B_id = -1 , C_id = -1 ;
72-
73- for (unsigned int vertex_id = 0 ; vertex_id < numVertices; vertex_id++)
74- {
75- if (VertexIndicies[vertex_id] == m_maxStressVertexIndex)
76- {
77- B_id = VertexIndicies[(vertex_id + 1 ) % 3 ];
78- C_id = VertexIndicies[(vertex_id + 2 ) % 3 ];
79- break ;
80- }
81-
82- }
83-
84- helper::ReadAccessor< Data<VecCoord> > x (d_input_positions);
85- Coord A = x[m_maxStressVertexIndex];
86- Coord B = x[B_id];
87- Coord C = x[C_id];
88-
89- if (rayTriangleIntersection (A, B, C, normalizedFractureDirection, t, Pb))
90- return true ;
91- else
92- return false ;
93-
94- }
9544
9645template <class DataTypes >
97- inline bool TearingEngine<DataTypes>::computeEndPointsNeighboringTriangles(Coord Pa, Coord direction , Coord& Pb, Coord& Pc)
46+ inline bool TearingEngine<DataTypes>::computeEndPointsNeighboringTriangles(const Coord& Pa, const Coord& fractureDirection , Coord& Pb, Coord& Pc)
9847{
9948 bool t_b_ok = false ;
10049 bool t_c_ok = false ;
101- // compute fracture direction perpendicular to the principal stress direction
102- Coord fractureDirection;
103- this ->computeFractureDirection (direction, fractureDirection);
10450
105- Real norm_fractureDirection = fractureDirection.norm ();
106- Coord dir_b = 1.0 / norm_fractureDirection * fractureDirection;
107-
108- Real t_b;
109- if (computeIntersectionNeighborTriangle (dir_b,Pa, Pb, t_b))
110- t_b_ok = true ;
51+ Coord dir_b = fractureDirection / fractureDirection.norm ();
52+ TriangleID t_b = this ->m_tearingAlgo ->computeIntersectionNeighborTriangle (m_maxStressVertexIndex, Pa, dir_b, Pb);
11153
112-
11354 Coord dir_c = -dir_b;
114- Real t_c;
115- if (computeIntersectionNeighborTriangle (dir_c,Pa,Pc, t_c))
116- t_c_ok = true ;
55+ TriangleID t_c = this ->m_tearingAlgo ->computeIntersectionNeighborTriangle (m_maxStressVertexIndex, Pa, dir_c, Pc);
56+
11757
118- if (!(t_b_ok && t_c_ok) )
58+ if (t_b == sofa::InvalidID || t_c == sofa::InvalidID )
11959 {
12060 msg_warning () << " Not able to build the fracture path through neighboring triangles." ;
12161 return false ;
12262 }
63+
12364 return true ;
12465}
12566
@@ -163,33 +104,36 @@ void TearingEngine<DataTypes>::computeFracturePath()
163104 // frist clear ereything
164105 this ->clearFracturePath ();
165106
166- if (m_maxStressTriangleIndex != InvalidID) // we have triangle to start and also a vertex id
107+ if (m_maxStressTriangleIndex == InvalidID) // no candidate to start fracture
108+ return ;
109+
110+ // Recording the endpoints of the fracture segment
111+ helper::ReadAccessor< Data<VecCoord> > x (d_input_positions);
112+
113+ const Coord fractureDirection = this ->computeFractureDirection (m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection );
114+
115+ const Coord Pa = x[m_maxStressVertexIndex];
116+ Coord Pb, Pc;
117+
118+ if (this ->d_fractureMaxLength .getValue () == 0.0 )
119+ {
120+ bool checkEndsPoints = this ->computeEndPointsNeighboringTriangles (Pa, fractureDirection, Pb, Pc);
121+ if (!checkEndsPoints)
122+ return ;
123+ }
124+ else
167125 {
168- // Recording the endpoints of the fracture segment
169- helper::ReadAccessor< Data<VecCoord> > x (d_input_positions);
170-
171- Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection ;
172- Coord Pa = x[m_maxStressVertexIndex];
173- Coord Pb, Pc;
174-
175- if (this ->d_fractureMaxLength .getValue () == 0.0 ) {
176- computeEndPointsNeighboringTriangles (Pa, principalStressDirection, Pb, Pc);
177- }
178- else
179- {
180- this ->computeEndPoints (Pa, principalStressDirection, Pb, Pc);
181- }
182-
183- this ->m_fracturePath .ptA = type::Vec3 (Pa[0 ], Pa[1 ], Pa[2 ]);
184- this ->m_fracturePath .ptB = type::Vec3 (Pb[0 ], Pb[1 ], Pb[2 ]);
185- this ->m_fracturePath .ptC = type::Vec3 (Pc[0 ], Pc[1 ], Pc[2 ]);
186- this ->m_fracturePath .triIdA = m_maxStressTriangleIndex;
187-
188- this ->m_tearingAlgo ->computeFracturePath (this ->m_fracturePath );
189- this ->m_stepCounter ++;
190-
191- // this->m_tearingAlgo->computeFracturePath(Pa, m_maxStressTriangleIndex, Pb, Pc);
126+ this ->computeEndPoints (Pa, fractureDirection, Pb, Pc); // compute orthogonal fracture using d_fractureMaxLength
192127 }
128+
129+
130+ this ->m_fracturePath .ptA = type::Vec3 (DataTypes::getCPos (Pa));
131+ this ->m_fracturePath .ptB = type::Vec3 (DataTypes::getCPos (Pb));
132+ this ->m_fracturePath .ptC = type::Vec3 (DataTypes::getCPos (Pc));
133+ this ->m_fracturePath .triIdA = m_maxStressTriangleIndex;
134+
135+ this ->m_tearingAlgo ->computeFracturePath (this ->m_fracturePath );
136+ this ->m_stepCounter ++;
193137}
194138
195139
0 commit comments