1717 */
1818
1919#include " adjustment.h"
20+ #include " constants.h"
2021#include " constraints.h"
2122#include " geometry/minrot.h"
2223#include " global.h"
3031#include " qcontainerfwd.h"
3132#include " qlogging.h"
3233
33- #include < algorithm>
3434#include < cassert>
3535#include < cmath>
3636#include < memory>
37- #include < numeric>
3837#include < sstream>
3938#include < utility>
4039
4544using Graph::IncidenceMatrix;
4645using Constraint::ConstraintBase;
4746
47+ using Eigen::Array;
4848using Eigen::ArrayXi;
4949using Eigen::ColMajor;
50+ using Eigen::Dynamic;
5051using Eigen::Index;
5152using Eigen::VectorXd;
5253using Eigen::Vector3d;
@@ -102,7 +103,9 @@ void AdjustmentFramework::update( const VectorXd &x)
102103
103104bool AdjustmentFramework::enforceConstraints ( const QVector<std::shared_ptr<ConstraintBase> > & constr,
104105 const IncidenceMatrix & relsub,
105- const ArrayXi & mapc )
106+ const ArrayXi & mapc,
107+ Array<Attribute,Dynamic,1 > & status,
108+ Array<bool ,Dynamic,1 > & enforced)
106109{
107110 // assert( relsub.rows()==maps.size() );
108111 assert ( relsub.cols ()==mapc.size () );
@@ -115,8 +118,7 @@ bool AdjustmentFramework::enforceConstraints( const QVector<std::shared_ptr<Cons
115118 }
116119
117120 // number of required constraints, inclusive hypothesis to be tested
118- const Index numOfRequiredConstraints = std::count_if ( mapc.begin (), mapc.end (),
119- [&constr](Index i){ return constr.at (i)->required ();} );
121+ const Index numOfRequiredConstraints = (status (mapc)==Attribute::Required).count ();
120122
121123 if ( verbose ) {
122124 qDebug ().noquote () << QString ( numOfConstraints==1 ?
@@ -128,10 +130,10 @@ bool AdjustmentFramework::enforceConstraints( const QVector<std::shared_ptr<Cons
128130
129131 // number of required equations (not constraints!),
130132 // e.g., two equations for parallelism
131- const int numOfRequiredEquations = std::accumulate (
132- mapc. begin (), mapc. end (), 0 ,
133- [&constr]( int acc, int i){
134- return acc += constr. at (i)-> required () ? constr. at (i)-> dof () : 0 ;} );
133+ int numOfRequiredEquations = 0 ;
134+ for ( const auto c : mapc) {
135+ numOfRequiredEquations += status (c)==Attribute::Required ? constr. at (c)-> dof () : 0 ;
136+ }
135137
136138
137139 l0_ = l_; // set adjusted observations l0 := l
@@ -154,7 +156,7 @@ bool AdjustmentFramework::enforceConstraints( const QVector<std::shared_ptr<Cons
154156 qDebug ().noquote () << QStringLiteral (" iteration #%1..." ).arg (it+1 );
155157 }
156158
157- Jacobian ( constr, relsub, BBr, g0, mapc);
159+ Jacobian ( constr, relsub, BBr, g0, mapc, status );
158160 reduce ( lr, rCov_ll);
159161
160162 // check rank and condition .....................................
@@ -213,7 +215,9 @@ bool AdjustmentFramework::enforceConstraints( const QVector<std::shared_ptr<Cons
213215 }
214216
215217 // check constraints
216- checkConstraints ( constr, relsub, mapc);
218+ assert ( enforced.size ()==status.size () );
219+
220+ checkConstraints ( constr, relsub, mapc, status, enforced);
217221
218222 return true ;
219223}
@@ -256,7 +260,8 @@ void AdjustmentFramework::Jacobian(
256260 const IncidenceMatrix & relsub,
257261 SparseMatrix<double ,ColMajor> & BBr,
258262 VectorXd & g0,
259- const ArrayXi & mapc ) const
263+ const ArrayXi & mapc,
264+ const Array<Attribute,Dynamic,1 > & status ) const
260265{
261266 // assert( relsub.rows()==maps.size() );
262267 assert ( relsub.cols ()==mapc.size () );
@@ -270,7 +275,8 @@ void AdjustmentFramework::Jacobian(
270275
271276 // !! not required ==> obsolete or(!) unevaluated
272277 const auto & con = constr.at ( mapc (c) );
273- if ( con->status () != ConstraintBase::REQUIRED ) { // observe the "!="
278+
279+ if ( status (mapc (c)) != Attribute::Required ) { // observe the "!="
274280 continue ;
275281 }
276282
@@ -295,14 +301,15 @@ void AdjustmentFramework::Jacobian(
295301void AdjustmentFramework::checkConstraints (
296302 const QVector<std::shared_ptr<ConstraintBase> > & constr,
297303 const IncidenceMatrix & relsub,
298- const ArrayXi & mapc) const
304+ const ArrayXi & mapc,
305+ const Array<Attribute,Dynamic,1 > & status,
306+ Array<bool ,Eigen::Dynamic,1 > & enforced) const
299307{
300308 // assert( relsub.rows()==maps.size() );
301309 assert ( relsub.cols ()==mapc.size () );
302310
303311 const Index numOfConstraints = mapc.size ();
304312
305-
306313 // check intrinsic constraints ..............................
307314#ifdef QT_DEBUG
308315 const Index numOfSegments = relsub.rows ();
@@ -328,23 +335,24 @@ void AdjustmentFramework::checkConstraints(
328335 for ( Index c=0 ; c<numOfConstraints; c++ )
329336 {
330337 const auto & con = constr.at ( mapc (c) );
331- if ( con-> unevaluated () ) {
332- continue ;
338+ if ( status ( mapc (c))==Attribute::Unevaluated ) {
339+ continue ;
333340 }
334341
335342 const VectorXidx idx = spfind ( relsub.col (c).eval () );
336343
337344 const double d = con->contradict ( idx, l0_ ).norm ();
338- con->setEnforced ( std::fabs (d) < threshold_numericalCheck () );
345+ assert ( enforced.size ()==status.size () );
346+ enforced ( mapc (c)) = ( std::fabs (d) < threshold_numericalCheck () );
339347
340348#ifdef QT_DEBUG
341349 if ( verbose ) {
342350 const QString msg1 = QStringLiteral (" %1: " ).arg (QString::fromLatin1 (con->type_name ()), 12 );
343351 const QString msg2 = QStringLiteral (" check = %2, \t " ).arg (d);
344352 QDebug deb = qDebug ().noquote ();
345353 deb << QStringLiteral (" constraint #%1: " ).arg (c+1 ,3 );
346- deb << (con-> required () ? green : blue) << msg1 << black;
347- deb << (con-> enforced () ? black : red) << msg2 << black;
354+ deb << ( status (c)==Attribute::Required ? green : blue) << msg1 << black;
355+ deb << ( enforced (c ) ? black : red) << msg2 << black;
348356 }
349357#endif
350358 }
0 commit comments