Skip to content

Commit

Permalink
[tests] Change transformation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Mafo369 authored and dlyr committed Jul 15, 2022
1 parent 10be81c commit 2f64c4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
8 changes: 4 additions & 4 deletions examples/CurveEditor/BezierUtils/CubicBezierApproximation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Curve2D::Vector> m_data;
std::vector<float> m_params;
std::set<int> m_bzjunctions;
Expand Down Expand Up @@ -174,10 +174,10 @@ class CubicBezierApproximation
int b { (int)( m_data.size() - 1 ) };
float h = ( b - a ) / (float)( nb_junctions - 1 );
std::vector<int> xs( nb_junctions );
typename std::vector<int>::iterator x;
typename std::vector<int>::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 );
Expand Down
10 changes: 2 additions & 8 deletions examples/CurveEditor/BezierUtils/LeastSquareSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ); }
}
Expand Down Expand Up @@ -188,13 +189,6 @@ class LeastSquareSystem
return true;
}

bool simpleCholesky( const SparseMat& A, const VectorXf& b, VectorXf& x ) const {
Eigen::SimplicialCholesky<SparseMat> 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<MatrixXf> svd( denseA, Eigen::ComputeThinU | Eigen::ComputeThinV );
Expand Down
60 changes: 30 additions & 30 deletions examples/CurveEditor/CurveEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++ ) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}

0 comments on commit 2f64c4b

Please sign in to comment.