From 70d5018fa96995eda93176ac6332ab27feba71d6 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 7 Jun 2016 18:29:50 +0300 Subject: [PATCH] PlaneGCSSolver: workaround for wrong redundant constraints available on arc-line tangency which are smoothly connected --- .../PlaneGCSSolver/PlaneGCSSolver_Solver.cpp | 13 +++++++++++++ .../PlaneGCSSolver/PlaneGCSSolver_Solver.h | 9 +++++++++ .../PlaneGCSSolver/PlaneGCSSolver_Storage.cpp | 12 ++++++++++++ .../PlaneGCSSolver/PlaneGCSSolver_Storage.h | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 9aa18c592..37e58bf82 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -40,6 +40,17 @@ void PlaneGCSSolver_Solver::removeConstraint(GCSConstraintPtr theConstraint) myConstraints.erase(aConstraint); } +static void removeTangent(GCS::VEC_I& theRedundant, const GCS::SET_I& theTangent) +{ + int i = 0; + while (i < theRedundant.size()) { + if (theTangent.find(theRedundant[i]) == theTangent.end()) + ++i; + else + theRedundant.erase(theRedundant.begin() + i); + } +} + SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() { // clear list of conflicting constraints @@ -76,6 +87,8 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() // additionally check redundant constraints GCS::VEC_I aRedundantID; myEquationSystem.getRedundant(aRedundantID); + // remove redundant constraints relative to tangency + removeTangent(aRedundantID, myTangent); if (!aRedundantID.empty()) aResult = GCS::Failed; } diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 35920bca0..a3c266346 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -34,6 +34,13 @@ public: void setParameters(const GCS::VEC_pD& theParams) { myParameters = theParams; } + /// \brief Set list of IDs of tangent constraints + /// + /// Workaround to avoid incorrect report about redundant constraints + /// if an arc is already smoothly connected to a line. + void setTangent(const GCS::SET_I& theTangentIDs) + { myTangent = theTangentIDs; } + /** \brief Solve the set of equations * \return identifier whether solution succeeded */ @@ -62,6 +69,8 @@ private: GCS::VEC_I myConflictingIDs; ///< list of IDs of conflicting constraints bool myConfCollected; ///< specifies the conflicting constraints are already collected + + GCS::SET_I myTangent; ///< list of tangent IDs to check incorrect redundant constraints }; #endif diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index aa011cc4f..35973564d 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -556,6 +557,7 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver) // initialize constraints std::map >::const_iterator aCIt = myConstraintMap.begin(); + GCS::SET_I aTangentIDs; for (; aCIt != myConstraintMap.end(); ++aCIt) { std::list::const_iterator aCWIt = aCIt->second.begin(); for (; aCWIt != aCIt->second.end(); ++ aCWIt) { @@ -566,6 +568,14 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver) if (!isRedundant(*anIt, aGCS)) aSolver->addConstraint(*anIt); } + // store IDs of tangent constraints to avoid incorrect report of redundant constraints + if (aCIt->first && aCIt->first->getKind() == SketchPlugin_ConstraintTangent::ID()) + for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++ aCWIt) { + std::shared_ptr aGCS = + std::dynamic_pointer_cast(*aCWIt); + if (aGCS->constraints().front()->getTypeId() == GCS::P2LDistance) + aTangentIDs.insert((int)(*aCWIt)->id()); + } } // additional constraints for arcs std::map >::const_iterator @@ -580,6 +590,8 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver) for (; aRemIt != myRemovedConstraints.end(); ++aRemIt) aSolver->removeConstraint(*aRemIt); myRemovedConstraints.clear(); + // set list of tangent constraints + aSolver->setTangent(aTangentIDs); // initialize unknowns aSolver->setParameters(myParameters); } diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index de3fbe301..dd71f9eed 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -116,7 +116,7 @@ private: ConstraintID myConstraintLastID; ///< identifier of last added constraint std::map > - myArcConstraintMap; ///< additional constraints for correct processing of the arcs + myArcConstraintMap; ///< additional constraints for correct processing of the arcs std::list myRemovedConstraints; ///< list of removed constraints to notify solver }; -- 2.39.2