From 2f64c4bc816fb901efe5f8cf19de09c591365dc7 Mon Sep 17 00:00:00 2001 From: Mafo369 Date: Tue, 12 Jul 2022 14:05:56 +0200 Subject: [PATCH] [tests] Change transformation logic --- .../BezierUtils/CubicBezierApproximation.hpp | 8 +-- .../BezierUtils/LeastSquareSystem.hpp | 10 +--- examples/CurveEditor/CurveEditor.cpp | 60 +++++++++---------- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/examples/CurveEditor/BezierUtils/CubicBezierApproximation.hpp b/examples/CurveEditor/BezierUtils/CubicBezierApproximation.hpp index f214245147f..47c1e5c92aa 100644 --- a/examples/CurveEditor/BezierUtils/CubicBezierApproximation.hpp +++ b/examples/CurveEditor/BezierUtils/CubicBezierApproximation.hpp @@ -130,7 +130,7 @@ class CubicBezierApproximation bool m_hasComputed { false }; int m_dim { 0 }; int m_step { 0 }; - float m_distThreshold; + float m_distThreshold { 0.f }; VectorArray m_data; std::vector m_params; std::set m_bzjunctions; @@ -174,10 +174,10 @@ class CubicBezierApproximation int b { (int)( m_data.size() - 1 ) }; float h = ( b - a ) / (float)( nb_junctions - 1 ); std::vector xs( nb_junctions ); - typename std::vector::iterator x; + typename std::vector::iterator it; float val; - for ( x = xs.begin(), val = a; x != xs.end(); ++x, val += h ) - *x = (int)val; + for ( it = xs.begin(), val = a; it != xs.end(); ++it, val += h ) + *it = (int)val; for ( int x : xs ) { m_bzjunctions.insert( x ); diff --git a/examples/CurveEditor/BezierUtils/LeastSquareSystem.hpp b/examples/CurveEditor/BezierUtils/LeastSquareSystem.hpp index 8bef5ea4a98..c455c31e3ef 100644 --- a/examples/CurveEditor/BezierUtils/LeastSquareSystem.hpp +++ b/examples/CurveEditor/BezierUtils/LeastSquareSystem.hpp @@ -29,7 +29,8 @@ class LeastSquareSystem * @param dimension of the variables (optional) * @param expected number of constraints (optional) */ - LeastSquareSystem( int nvar, int dim = 1, int exp_ncstr = 0 ) : m_nvar( nvar ), m_dim( dim ) { + explicit LeastSquareSystem( int nvar, int dim = 1, int exp_ncstr = 0 ) : + m_nvar( nvar ), m_dim( dim ) { m_constrainedVar.resize( m_nvar, false ); if ( exp_ncstr > 0 ) { m_bval.reserve( exp_ncstr ); } } @@ -188,13 +189,6 @@ class LeastSquareSystem return true; } - bool simpleCholesky( const SparseMat& A, const VectorXf& b, VectorXf& x ) const { - Eigen::SimplicialCholesky chol( A.transpose() * A ); - if ( chol.info() != Eigen::Success ) { return false; } - x = chol.solve( A.transpose() * b ); - return true; - } - bool jacobiSVD( const SparseMat& A, const VectorXf& b, VectorXf& x ) const { MatrixXf denseA( A ); Eigen::JacobiSVD svd( denseA, Eigen::ComputeThinU | Eigen::ComputeThinV ); diff --git a/examples/CurveEditor/CurveEditor.cpp b/examples/CurveEditor/CurveEditor.cpp index 3f46278ca37..7aacae6779b 100644 --- a/examples/CurveEditor/CurveEditor.cpp +++ b/examples/CurveEditor/CurveEditor.cpp @@ -125,7 +125,6 @@ void CurveEditor::updateCurves( bool onRelease ) { auto oldPoint = pointComponent->m_point; unsigned int curveIdSize = pointComponent->m_curveId.size(); - CurveFactory factory; m_viewer->makeCurrent(); for ( unsigned int i = 0; i < curveIdSize; i++ ) { @@ -292,9 +291,9 @@ void CurveEditor::addPointInCurve( const Vector3& worldPos, int mouseX, int mous auto e = ro->getComponent(); int curveIndex = -1; - for ( int i = 0; i < m_curveEntities.size(); i++ ) { - if ( m_curveEntities[i] == e ) { - curveIndex = i; + for ( int z = 0; z < m_curveEntities.size(); z++ ) { + if ( m_curveEntities[z] == e ) { + curveIndex = z; break; } } @@ -359,35 +358,14 @@ void CurveEditor::processPicking( const Vector3& worldPos ) { auto transformTranslate = Transform::Identity(); transformTranslate.translate( worldPos - point ); - auto transform = Transform::Identity(); - transform = m_selectedRo->getLocalTransform() * transformTranslate; + auto transform = m_selectedRo->getLocalTransform() * transformTranslate; m_selectedRo->setLocalTransform( transform ); - if ( m_smooth && !( m_currentPoint == 0 || m_currentPoint == 1 || - m_currentPoint == m_pointEntities.size() - 2 || - m_currentPoint == m_pointEntities.size() - 1 ) ) { + if ( !( m_currentPoint == 0 || m_currentPoint == 1 || + m_currentPoint == m_pointEntities.size() - 2 || + m_currentPoint == m_pointEntities.size() - 1 ) ) { - if ( m_currentPoint % 3 == 2 ) { - auto pointMid = m_pointEntities[m_currentPoint + 1]; - pointComponent = m_pointEntities[m_currentPoint + 2]; - auto symTransform = - computePointTransform( pointComponent, pointMid->m_point, worldPos ); - auto ro = m_roMgr->getRenderObject( pointComponent->getRenderObjects()[0] ); - ro->setLocalTransform( symTransform ); - - if ( m_tangentPoints.empty() ) { m_tangentPoints.push_back( m_currentPoint + 2 ); } - } - else if ( m_currentPoint % 3 == 1 ) { - auto pointMid = m_pointEntities[m_currentPoint - 1]; - pointComponent = m_pointEntities[m_currentPoint - 2]; - auto symTransform = - computePointTransform( pointComponent, pointMid->m_point, worldPos ); - auto ro = m_roMgr->getRenderObject( pointComponent->getRenderObjects()[0] ); - ro->setLocalTransform( symTransform ); - - if ( m_tangentPoints.empty() ) { m_tangentPoints.push_back( m_currentPoint - 2 ); } - } - else if ( m_currentPoint % 3 == 0 ) { + if ( m_currentPoint % 3 == 0 ) { auto leftRo = m_roMgr->getRenderObject( m_pointEntities[m_currentPoint - 1]->getRenderObjects()[0] ); auto leftTransform = leftRo->getTransform() * transformTranslate; @@ -403,6 +381,28 @@ void CurveEditor::processPicking( const Vector3& worldPos ) { m_tangentPoints.push_back( m_currentPoint + 1 ); } } + else if ( m_smooth ) { + if ( m_currentPoint % 3 == 2 ) { + auto pointMid = m_pointEntities[m_currentPoint + 1]; + pointComponent = m_pointEntities[m_currentPoint + 2]; + auto symTransform = + computePointTransform( pointComponent, pointMid->m_point, worldPos ); + auto ro = m_roMgr->getRenderObject( pointComponent->getRenderObjects()[0] ); + ro->setLocalTransform( symTransform ); + + if ( m_tangentPoints.empty() ) { m_tangentPoints.push_back( m_currentPoint + 2 ); } + } + else if ( m_currentPoint % 3 == 1 ) { + auto pointMid = m_pointEntities[m_currentPoint - 1]; + pointComponent = m_pointEntities[m_currentPoint - 2]; + auto symTransform = + computePointTransform( pointComponent, pointMid->m_point, worldPos ); + auto ro = m_roMgr->getRenderObject( pointComponent->getRenderObjects()[0] ); + ro->setLocalTransform( symTransform ); + + if ( m_tangentPoints.empty() ) { m_tangentPoints.push_back( m_currentPoint - 2 ); } + } + } } updateCurves(); }