@@ -329,7 +329,7 @@ void BaseTearingEngine<DataTypes>::updateTriangleInformation()
329329
330330
331331template <class DataTypes >
332- inline void BaseTearingEngine<DataTypes>::computeFractureDirection(Coord principleStressDirection,Coord & fracture_direction)
332+ inline void BaseTearingEngine<DataTypes>::computeFractureDirection(const Coord principleStressDirection,Coord & fracture_direction)
333333{
334334 if (m_maxStressTriangleIndex == InvalidID) {
335335 fracture_direction = { 0.0 , 0.0 , 0.0 };
@@ -621,6 +621,22 @@ inline void BaseTearingEngine<DataTypes>::calculate_inverse_distance_weights(std
621621
622622
623623
624+ template <class DataTypes >
625+ void BaseTearingEngine<DataTypes>::clearFracturePath()
626+ {
627+ m_fracturePath.ptA = Vec3 ();
628+ m_fracturePath.ptB = Vec3 ();
629+ m_fracturePath.ptC = Vec3 ();
630+
631+ m_fracturePath.triIdA = InvalidID;
632+ m_fracturePath.triIdB = InvalidID;
633+ m_fracturePath.triIdC = InvalidID;
634+
635+ m_fracturePath.pointsToAdd .clear ();
636+ m_fracturePath.pathOk = false ;
637+ }
638+
639+
624640template <class DataTypes >
625641void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* event)
626642{
@@ -638,15 +654,17 @@ void BaseTearingEngine<DataTypes>::handleEvent(sofa::core::objectmodel::Event* e
638654 return ; // We only launch computation at end of a simulation step
639655 }
640656
641- if (m_tearingAlgo->getFractureNumber () > d_nbFractureMax.getValue ())
657+ if (m_tearingAlgo->getFractureNumber () > d_nbFractureMax.getValue ()) // reach the end of the engine behavior
642658 return ;
643659
644- computeFracturePath ();
645-
646660 // Hack: we access one output value to force the engine to call doUpdate()
647661 if (d_maxStress.getValue () == Real (0.0 ))
648662 return ;
649663
664+ // main method to compute the possible fracture if a triangle has reached threshold
665+ computeFracturePath ();
666+
667+
650668 // Perform fracture every d_stepModulo
651669 int step = d_stepModulo.getValue ();
652670 if (m_stepCounter > step)
@@ -721,25 +739,18 @@ void BaseTearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparam
721739 }
722740
723741
724-
725-
726-
727742 if (d_showFracturePath.getValue ())
728743 {
729- if (m_maxStressTriangleIndex != InvalidID && fractureSegmentEndpoints. size () == 2 )
744+ if (m_maxStressTriangleIndex != InvalidID && m_fracturePath. pathOk )
730745 {
731746 helper::ReadAccessor< Data<VecCoord> > x (d_input_positions);
747+
732748 Coord principalStressDirection = m_triangleInfoTearing[m_maxStressTriangleIndex].principalStressDirection ;
733749 Coord Pa = x[m_maxStressVertexIndex];
734- // Coord fractureDirection;
735- // computeFractureDirection(principalStressDirection, fractureDirection);
736- Coord Pb = fractureSegmentEndpoints[0 ];
737- Coord Pc = fractureSegmentEndpoints[1 ];
750+ Coord Pb = m_fracturePath.ptB ;
751+ Coord Pc = m_fracturePath.ptC ;
738752
739753 vector<Coord> points;
740- // Real norm_fractureDirection = fractureDirection.norm();
741- // Coord Pb = Pa + d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
742- // Coord Pc = Pa - d_fractureMaxLength.getValue() / norm_fractureDirection * fractureDirection;
743754 points.push_back (Pb);
744755 points.push_back (Pa);
745756 points.push_back (Pa);
@@ -757,11 +768,20 @@ void BaseTearingEngine<DataTypes>::draw(const core::visual::VisualParams* vparam
757768 vparams->drawTool ()->drawPoints (pointsDir, 10 , sofa::type::RGBAColor (0 , 1 , 0.2 , 1 ));
758769 vparams->drawTool ()->drawLines (pointsDir, 1 , sofa::type::RGBAColor (0 , 1 , 0.5 , 1 ));
759770
760- points.clear ();
771+ std::vector<Vec3> pointsPath;
772+ for (auto ptA : m_fracturePath.pointsToAdd )
773+ {
774+ sofa::type::Vec3 vecG = sofa::type::Vec3 (0.0 , 0.0 , 0.0 );
775+ sofa::Size nbr = ptA->m_ancestors .size ();
776+ for (int i = 0 ; i < nbr; ++i)
777+ {
778+
779+ vecG += x[ptA->m_ancestors [i]] * ptA->m_coefs [i];
780+ }
781+ pointsPath.push_back (vecG);
782+ }
783+ vparams->drawTool ()->drawSpheres (pointsPath, 0.01 , sofa::type::RGBAColor::red ());
761784
762- const vector<Coord>& path = m_tearingAlgo->getFracturePath ();
763- if (!path.empty ())
764- vparams->drawTool ()->drawPoints (path, 10 , sofa::type::RGBAColor (0 , 0.8 , 0.2 , 1 ));
765785 }
766786 }
767787}
0 commit comments