From 9bd19328ca0fa00bc75ddc5c8bdc26e922526232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Fri, 17 Jan 2014 19:27:49 +0100 Subject: [PATCH] multiple debug updates --- src/Mod/Assembly/App/ItemAssembly.cpp | 25 +- src/Mod/Assembly/App/ItemAssembly.h | 2 + src/Mod/Assembly/App/Solver/Solver.h | 411 +++++++++++------- .../App/opendcm/core/clustergraph.hpp | 3 +- .../Assembly/App/opendcm/core/geometry.hpp | 8 +- .../App/opendcm/core/imp/clustergraph_imp.hpp | 54 ++- .../App/opendcm/core/imp/geometry_imp.hpp | 10 +- .../App/opendcm/core/imp/kernel_imp.hpp | 71 +-- .../opendcm/core/imp/transformation_imp.hpp | 20 + src/Mod/Assembly/App/opendcm/core/kernel.hpp | 15 +- src/Mod/Assembly/App/opendcm/core/logging.hpp | 14 +- src/Mod/Assembly/App/opendcm/core/system.hpp | 7 + .../App/opendcm/core/transformation.hpp | 4 + .../App/opendcm/module3d/clustermath.hpp | 9 +- .../App/opendcm/module3d/distance.hpp | 26 +- .../App/opendcm/module3d/geometry.hpp | 5 + .../opendcm/module3d/imp/clustermath_imp.hpp | 33 +- .../App/opendcm/module3d/imp/solver_imp.hpp | 22 +- .../App/opendcm/module3d/imp/state_imp.hpp | 61 +++ .../Assembly/App/opendcm/module3d/solver.hpp | 2 +- .../Assembly/App/opendcm/module3d/state.hpp | 21 + .../App/opendcm/modulePart/module.hpp | 6 +- .../App/opendcm/moduleShape3d/distance.hpp | 10 +- .../moduleState/imp/property_parser_imp.hpp | 2 +- .../Assembly/Gui/TaskAssemblyConstraints.ui | 34 +- src/Mod/Assembly/Gui/ViewProviderPart.cpp | 154 ++++++- src/Mod/Assembly/Gui/ViewProviderPart.h | 18 +- 27 files changed, 742 insertions(+), 305 deletions(-) diff --git a/src/Mod/Assembly/App/ItemAssembly.cpp b/src/Mod/Assembly/App/ItemAssembly.cpp index 5cefa44a9..121f64a58 100644 --- a/src/Mod/Assembly/App/ItemAssembly.cpp +++ b/src/Mod/Assembly/App/ItemAssembly.cpp @@ -53,6 +53,16 @@ ItemAssembly::ItemAssembly() { ADD_PROPERTY(ApplyAtFailure,(false)); ADD_PROPERTY(Precision,(1e-6)); ADD_PROPERTY(SaveState,(false)); + ADD_PROPERTY(Iterations,(5e3)); + ADD_PROPERTY(LogLevel, (long(1))); + + std::vector vec; + vec.push_back("iteration"); + vec.push_back("solving"); + vec.push_back("manipulation"); + vec.push_back("information"); + vec.push_back("error"); + LogLevel.setEnumVector(vec); #endif } @@ -71,6 +81,7 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) { m_downstream_placement = Base::Placement(Base::Vector3(0,0,0), Base::Rotation()); Base::Placement dummy; initSolver(boost::shared_ptr(), dummy, false); + initConstraints(boost::shared_ptr()); #ifdef ASSEMBLY_DEBUG_FACILITIES @@ -80,6 +91,7 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) { m_solver->setOption(dcm::IgnoreResults); m_solver->setOption(Precision.getValue()); + m_solver->setOption(Iterations.getValue()); if(SaveState.getValue()) { @@ -88,8 +100,10 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) { m_solver->saveState(myfile); myfile.close(); }; + + m_solver->setLoggingFilter(dcm::severity >= (dcm::severity_level)LogLevel.getValue()); + #endif - initConstraints(boost::shared_ptr()); //solve the system m_solver->solve(); @@ -109,6 +123,12 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) { //throw Base::Exception(message.str().c_str()); Base::Console().Error(message.str().c_str()); } + catch(Standard_ConstructionError& e) { + message.clear(); + message << "Construction Error raised in assembly solver during execution: "; + message << e.GetMessageString()<< std::endl; + Base::Console().Error(message.str().c_str()); + } catch (...) { message.clear(); @@ -321,3 +341,6 @@ void ItemAssembly::finish(boost::shared_ptr subsystem) { }; } //assembly + + + diff --git a/src/Mod/Assembly/App/ItemAssembly.h b/src/Mod/Assembly/App/ItemAssembly.h index fcea7a64e..7d380ea50 100644 --- a/src/Mod/Assembly/App/ItemAssembly.h +++ b/src/Mod/Assembly/App/ItemAssembly.h @@ -88,6 +88,8 @@ public: App::PropertyBool ApplyAtFailure; App::PropertyFloat Precision; App::PropertyBool SaveState; + App::PropertyInteger Iterations; + App::PropertyEnumeration LogLevel; #endif private: diff --git a/src/Mod/Assembly/App/Solver/Solver.h b/src/Mod/Assembly/App/Solver/Solver.h index 304d663c8..c40249eda 100644 --- a/src/Mod/Assembly/App/Solver/Solver.h +++ b/src/Mod/Assembly/App/Solver/Solver.h @@ -30,14 +30,15 @@ #include "PreCompiled.h" #include "opendcm/core.hpp" -#include "opendcm/module3d.hpp" -#include "opendcm/modulepart.hpp" #ifdef ASSEMBLY_DEBUG_FACILITIES #include "opendcm/modulestate.hpp" #endif +#include "opendcm/module3d.hpp" +#include "opendcm/modulepart.hpp" #include +#include #include #include @@ -49,182 +50,240 @@ struct gp_pnt_accessor { template Scalar get(T& t) { switch(ID) { - case 0: - return t.X(); - case 1: - return t.Y(); - case 2: - return t.Z(); - default: - return 0; + case 0: + return t.X(); + + case 1: + return t.Y(); + + case 2: + return t.Z(); + + default: + return 0; }; }; template void set(Scalar value, T& t) { switch(ID) { - case 0: - t.SetX(value); - break; - case 1: - t.SetY(value); - break; - case 2: - t.SetZ(value); - break; + case 0: + t.SetX(value); + break; + + case 1: + t.SetY(value); + break; + + case 2: + t.SetZ(value); + break; }; }; + template + void finalize(T& t) {}; }; struct gp_lin_accessor { + gp_Pnt pnt; + double dx,dy,dz; + template Scalar get(T& t) { switch(ID) { - case 0: - return t.Location().X(); - case 1: - return t.Location().Y(); - case 2: - return t.Location().Z(); - case 3: - return t.Direction().X(); - case 4: - return t.Direction().Y(); - case 5: - return t.Direction().Z(); - default: - return 0; + case 0: + return t.Location().X(); + + case 1: + return t.Location().Y(); + + case 2: + return t.Location().Z(); + + case 3: + return t.Direction().X(); + + case 4: + return t.Direction().Y(); + + case 5: + return t.Direction().Z(); + + default: + return 0; }; }; template void set(Scalar value, T& t) { - gp_Pnt p = t.Location(); - gp_Dir d = t.Direction(); + switch(ID) { - case 0: - p.SetX(value); - break; - case 1: - p.SetY(value); - break; - case 2: - p.SetZ(value); - break; - case 3: - d.SetX(value); - break; - case 4: - d.SetY(value); - break; - case 5: - d.SetZ(value); - break; + case 0: + pnt.SetX(value); + break; + + case 1: + pnt.SetY(value); + break; + + case 2: + pnt.SetZ(value); + break; + + case 3: + dx=(value); + break; + + case 4: + dy=(value); + break; + + case 5: + dz=(value); + break; }; - t.SetLocation(p); - t.SetDirection(d); + }; + template + void finalize(T& t) { + t.SetLocation(pnt); + t.SetDirection(gp_Dir(dx,dy,dz)); }; }; struct gp_pln_accessor { + gp_Pnt pnt; + double dx,dy,dz; + template Scalar get(T& t) { switch(ID) { - case 0: - return t.Axis().Location().X(); - case 1: - return t.Axis().Location().Y(); - case 2: - return t.Axis().Location().Z(); - case 3: - return t.Axis().Direction().X(); - case 4: - return t.Axis().Direction().Y(); - case 5: - return t.Axis().Direction().Z(); - default: - return 0; + case 0: + return t.Axis().Location().X(); + + case 1: + return t.Axis().Location().Y(); + + case 2: + return t.Axis().Location().Z(); + + case 3: + return t.Axis().Direction().X(); + + case 4: + return t.Axis().Direction().Y(); + + case 5: + return t.Axis().Direction().Z(); + + default: + return 0; }; }; template void set(Scalar value, T& t) { - gp_Pnt p = t.Axis().Location(); - gp_Dir d = t.Axis().Direction(); switch(ID) { - case 0: - p.SetX(value); - break; - case 1: - p.SetY(value); - break; - case 2: - p.SetZ(value); - break; - case 3: - d.SetX(value); - break; - case 4: - d.SetY(value); - break; - case 5: - d.SetZ(value); - break; + case 0: + pnt.SetX(value); + break; + + case 1: + pnt.SetY(value); + break; + + case 2: + pnt.SetZ(value); + break; + + case 3: + dx=value; + break; + + case 4: + dy=value; + break; + + case 5: + dz=value; + break; }; - t.SetAxis(gp_Ax1(p,d)); + }; + template + void finalize(T& t) { + t.SetAxis(gp_Ax1(pnt,gp_Dir(dx,dy,dz))); }; }; struct gp_cylinder_accessor { + gp_Pnt pnt; + double dx,dy,dz; + template Scalar get(T& t) { switch(ID) { - case 0: - return t.Axis().Location().X(); - case 1: - return t.Axis().Location().Y(); - case 2: - return t.Axis().Location().Z(); - case 3: - return t.Axis().Direction().X(); - case 4: - return t.Axis().Direction().Y(); - case 5: - return t.Axis().Direction().Z(); - case 6: - return t.Radius(); - default: - return 0; + case 0: + return t.Axis().Location().X(); + + case 1: + return t.Axis().Location().Y(); + + case 2: + return t.Axis().Location().Z(); + + case 3: + return t.Axis().Direction().X(); + + case 4: + return t.Axis().Direction().Y(); + + case 5: + return t.Axis().Direction().Z(); + + case 6: + return t.Radius(); + + default: + return 0; }; }; template void set(Scalar value, T& t) { - gp_Pnt p = t.Axis().Location(); - gp_Dir d = t.Axis().Direction(); + switch(ID) { - case 0: - p.SetX(value); - break; - case 1: - p.SetY(value); - break; - case 2: - p.SetZ(value); - break; - case 3: - d.SetX(value); - break; - case 4: - d.SetY(value); - break; - case 5: - d.SetZ(value); - break; - case 6: - t.SetRadius(value); - break; + case 0: + pnt.SetX(value); + break; + + case 1: + pnt.SetY(value); + break; + + case 2: + pnt.SetZ(value); + break; + + case 3: + dx=value; + break; + + case 4: + dy=value; + break; + + case 5: + dz=value; + break; + + case 6: + t.SetRadius(value); + break; }; - t.SetAxis(gp_Ax1(p,d)); + + }; + + template + void finalize(T& t) { + t.SetAxis(gp_Ax1(pnt,gp_Dir(dx,dy,dz))); }; }; @@ -236,49 +295,63 @@ struct placement_accessor { template Scalar get(T& t) { t.getRotation().getValue(q0,q1,q2,q3); + switch(ID) { - case 0: - return q3; - case 1: - return q0; - case 2: - return q1; - case 3: - return q2; - case 4: - return t.getPosition()[0]; - case 5: - return t.getPosition()[1]; - case 6: - return t.getPosition()[2]; - default: - return 0; + case 0: + return q3; + + case 1: + return q0; + + case 2: + return q1; + + case 3: + return q2; + + case 4: + return t.getPosition()[0]; + + case 5: + return t.getPosition()[1]; + + case 6: + return t.getPosition()[2]; + + default: + return 0; }; }; template void set(Scalar value, T& t) { switch(ID) { - case 0: - q3 = value; - break; - case 1: - q0 = value; - break; - case 2: - q1 = value; - break; - case 3: - q2 = value; - break; - case 4: - vec[0] = value; - break; - case 5: - vec[1] = value; - break; - case 6: - vec[2] = value; - break; + case 0: + q3 = value; + break; + + case 1: + q0 = value; + break; + + case 2: + q1 = value; + break; + + case 3: + q2 = value; + break; + + case 4: + vec[0] = value; + break; + + case 5: + vec[1] = value; + break; + + case 6: + vec[2] = value; + break; }; }; @@ -333,7 +406,7 @@ typedef dcm::ModulePart< mpl::vector1< Base::Placement >, std::string > ModulePa #ifdef ASSEMBLY_DEBUG_FACILITIES typedef dcm::System Solver; -#elif +#else typedef dcm::System Solver; #endif @@ -342,4 +415,4 @@ typedef Module3D::type::Geometry3D Geometry3D; typedef Module3D::type::Constraint3D Constraint3D; -#endif //SOLVER_H \ No newline at end of file +#endif //SOLVER_H diff --git a/src/Mod/Assembly/App/opendcm/core/clustergraph.hpp b/src/Mod/Assembly/App/opendcm/core/clustergraph.hpp index 4d4c00012..3e4a599f2 100644 --- a/src/Mod/Assembly/App/opendcm/core/clustergraph.hpp +++ b/src/Mod/Assembly/App/opendcm/core/clustergraph.hpp @@ -623,7 +623,8 @@ public: * Sometimes it is needed to add a vertex with given global identifier. As the global vertex can not * be changed after creation, this method can be used to specify the global vertex by which this * graph vertex can be identified. The given global vertex is not checked, you need to ensure that - * it is a unique id. The ID generator is changed so that it creates only identifier bigger than v. + * it is a unique id or the already existing vertex is returned. + * The ID generator is changed so that it creates only identifier bigger than v. * * @return fusion::vector the local and global vertex descriptor **/ diff --git a/src/Mod/Assembly/App/opendcm/core/geometry.hpp b/src/Mod/Assembly/App/opendcm/core/geometry.hpp index a56df5691..6042541dd 100644 --- a/src/Mod/Assembly/App/opendcm/core/geometry.hpp +++ b/src/Mod/Assembly/App/opendcm/core/geometry.hpp @@ -217,7 +217,7 @@ class Geometry { #ifdef USE_LOGGING protected: - src::logger log; + dcm_logger log; #endif public: @@ -327,13 +327,7 @@ public: void recalculate(DiffTransform& trans); typename Kernel::Vector3 getPoint() { - if(m_isInCluster) return m_toplocal.template segment(0); - else if(m_init) - return m_rotated.template segment(0); - else - return m_global.template segment(0); - }; //use m_value or parametermap as new value, dependend on the solving mode diff --git a/src/Mod/Assembly/App/opendcm/core/imp/clustergraph_imp.hpp b/src/Mod/Assembly/App/opendcm/core/imp/clustergraph_imp.hpp index 199a2e209..a49c31fc4 100644 --- a/src/Mod/Assembly/App/opendcm/core/imp/clustergraph_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/core/imp/clustergraph_imp.hpp @@ -1,20 +1,20 @@ - /* - openDCM, dimensional constraint manager - Copyright (C) 2012 Stefan Troeger +/* + openDCM, dimensional constraint manager + Copyright (C) 2012 Stefan Troeger - This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef DCM_CLUSTERGRAPH_IMP_HPP @@ -134,7 +134,7 @@ struct obj_helper { //used with vertex bundle type template - typename boost::enable_if < boost::is_same::type>, result_type >::type + typename boost::enable_if < boost::is_same::type>, result_type >::type operator()(bundle& p) { if(Type::value) @@ -504,16 +504,22 @@ template< typename edge_prop, typename vertex_prop, typename cluster_prop, typen fusion::vector ClusterGraph::addVertex(GlobalVertex gv) { - vertex_bundle vp; - fusion::at_c<0> (vp) = gv; - LocalVertex v = boost::add_vertex(vp, *this); - - //ensure that we never create this id, as it is used now - if(gv > m_id->count()) - m_id->setCount(gv); - setChanged(); - return fusion::make_vector(v, gv); + std::pair res = getLocalVertex(gv); + + if(!res.second) { + vertex_bundle vp; + fusion::at_c<0> (vp) = gv; + LocalVertex v = boost::add_vertex(vp, *this); + + //ensure that we never create this id, as it is used now + if(gv > m_id->count()) + m_id->setCount(gv); + + return fusion::make_vector(v, gv); + }; + + return fusion::make_vector(res.first, gv); }; template< typename edge_prop, typename vertex_prop, typename cluster_prop, typename objects> diff --git a/src/Mod/Assembly/App/opendcm/core/imp/geometry_imp.hpp b/src/Mod/Assembly/App/opendcm/core/imp/geometry_imp.hpp index 91b76fce5..4316e27be 100644 --- a/src/Mod/Assembly/App/opendcm/core/imp/geometry_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/core/imp/geometry_imp.hpp @@ -107,7 +107,7 @@ void Geometry::init() { m_init = false; #ifdef USE_LOGGING - BOOST_LOG(log) << "Init: "<::recalculate(DiffTransform& trans) { #ifdef USE_LOGGING if(!boost::math::isnormal(m_rotated.norm()) || !boost::math::isnormal(m_diffparam.norm())) { - BOOST_LOG(log) << "Unnormal recalculated value detected: "<::finishCalculation() { //recalculate(1.); //remove scaling to get right global value m_global = m_rotated; #ifdef USE_LOGGING - BOOST_LOG(log) << "Finish cluster calculation"; + BOOST_LOG_SEV(log, information) << "Finish cluster calculation"; #endif } //TODO:non cluster paramter scaling @@ -221,7 +221,7 @@ void Geometry::finishCalculation() { m_global = m_parameter; normalize(); #ifdef USE_LOGGING - BOOST_LOG(log) << "Finish calculation"; + BOOST_LOG_SEV(log, information) << "Finish calculation"; #endif }; @@ -247,7 +247,7 @@ void Geometry::transform(const Transform& t, VectorType& v } #ifdef USE_LOGGING - BOOST_LOG(log) << "Transformed with cluster: "<::Dogleg(Kernel* k) : m_kernel(k), tolg(1e-40), tolx(1e-20) { }; template -Dogleg::Dogleg() : tolg(1e-40), tolx(1e-20) { +Dogleg::Dogleg() : tolg(1e-6), tolx(1e-3) { #ifdef USE_LOGGING log.add_attribute("Tag", attrs::constant< std::string >("Dogleg")); @@ -62,16 +62,17 @@ void Dogleg::calculateStep(const Eigen::MatrixBase& g, const Ei const typename Kernel::Vector h_gn = jacobi.fullPivLu().solve(-residual); const double eigen_error = (jacobi*h_gn + residual).norm(); #ifdef USE_LOGGING - if(!boost::math::isfinite(h_gn.norm())) { - BOOST_LOG(log)<< "Unnormal gauss-newton detected: "<::calculateStep(const Eigen::MatrixBase& g, const Ei #ifdef USE_LOGGING if(!boost::math::isfinite(h_dl.norm())) { - BOOST_LOG(log)<< "Unnormal dogleg descent detected: "<::calculateStep(const Eigen::MatrixBase& g, const Ei #ifdef USE_LOGGING if(!boost::math::isfinite(c)) { - BOOST_LOG(log)<< "Unnormal dogleg c detected: "<::solve(typename Kernel::MappedEquationSystem& sys, Functor& r sys.recalculate(); #ifdef USE_LOGGING - BOOST_LOG(log)<< "initial jacobi: "<(); + BOOST_LOG_SEV(log, solving) << "initial jacobi: "<(); #endif sys.removeLocalGradientZeros(); #ifdef USE_LOGGING - BOOST_LOG(log)<< "LGZ jacobi: "<(); + BOOST_LOG_SEV(log, solving) << "LGZ jacobi: "<(); #endif err = sys.Residual.norm(); @@ -179,17 +180,18 @@ int Dogleg::solve(typename Kernel::MappedEquationSystem& sys, Functor& r unused=0; counter=0; - int maxIterNumber = 10000;//MaxIterations * xsize; + int maxIterNumber = m_kernel->template getProperty(); + number_type pr = m_kernel->template getProperty()*sys.Scaling; number_type diverging_lim = 1e6*err + 1e12; do { // check if finished - if(fx_inf <= m_kernel->template getProperty()*sys.Scaling) // Success + if(fx_inf <= pr) // Success stop = 1; - else if(g_inf <= tolg) + else if(g_inf <= tolg*pr) throw solving_error() << boost::errinfo_errno(2) << error_message("g infinity norm smaller below limit"); - else if(delta <= tolx) + else if(delta <= tolx*pr) throw solving_error() << boost::errinfo_errno(3) << error_message("step size below limit"); else if(iter >= maxIterNumber) throw solving_error() << boost::errinfo_errno(4) << error_message("maximal iterations reached"); @@ -210,11 +212,12 @@ int Dogleg::solve(typename Kernel::MappedEquationSystem& sys, Functor& r //get the update step calculateStep(g, sys.Jacobi, sys.Residual, h_dl, delta); -// #ifdef USE_LOGGING -// BOOST_LOG(log)<< "Step in iter "<::solve(typename Kernel::MappedEquationSystem& sys, Functor& r #ifdef USE_LOGGING if(!boost::math::isfinite(sys.Residual.norm())) { - BOOST_LOG(log)<< "Unnormal residual detected: "<::solve(typename Kernel::MappedEquationSystem& sys, Functor& r nu = 2*nu; } -// #ifdef USE_LOGGING -// BOOST_LOG(log)<<"Result of step dF: "< 0 && dL > 0) { //see if we got too high differentials if(sys.Jacobi.template lpNorm() > 2) { #ifdef USE_LOGGING - BOOST_LOG(log)<< "High differential detected: "<()<<" in iteration: "<()<<" in iteration: "<::solve(typename Kernel::MappedEquationSystem& sys, Functor& r } else { #ifdef USE_LOGGING - BOOST_LOG(log)<< "Reject step in iter "<::solve(typename Kernel::MappedEquationSystem& sys, Functor& r time = (double(end-start) * 1000.) / double(CLOCKS_PER_SEC); #ifdef USE_LOGGING - BOOST_LOG(log) <<"Done solving: "<(); #endif return stop; diff --git a/src/Mod/Assembly/App/opendcm/core/imp/transformation_imp.hpp b/src/Mod/Assembly/App/opendcm/core/imp/transformation_imp.hpp index 95a1ba058..012040adc 100644 --- a/src/Mod/Assembly/App/opendcm/core/imp/transformation_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/core/imp/transformation_imp.hpp @@ -62,6 +62,14 @@ template const typename Transform::Rotation& Transform::rotation() const { return m_rotation; } + +template +template +Transform& Transform::setRotation(const Eigen::RotationBase& rotation) { + m_rotation = rotation.derived().normalized(); + return *this; +} + template template Transform& Transform::rotate(const Eigen::RotationBase& rotation) { @@ -73,6 +81,13 @@ template const typename Transform::Translation& Transform::translation() const { return m_translation; } + +template +Transform& Transform::setTranslation(const Translation& translation) { + m_translation = translation; + return *this; +} + template Transform& Transform::translate(const Translation& translation) { m_translation = m_translation*translation; @@ -89,6 +104,11 @@ Transform& Transform::scale(const Scalar& scaling) { return *this; } template +Transform& Transform::setScale(const Scaling& scaling) { + m_scale.factor() = scaling.factor(); + return *this; +} +template Transform& Transform::scale(const Scaling& scaling) { m_scale.factor() *= scaling.factor(); return *this; diff --git a/src/Mod/Assembly/App/opendcm/core/kernel.hpp b/src/Mod/Assembly/App/opendcm/core/kernel.hpp index 97d6b93ef..7b6bfc14e 100644 --- a/src/Mod/Assembly/App/opendcm/core/kernel.hpp +++ b/src/Mod/Assembly/App/opendcm/core/kernel.hpp @@ -64,12 +64,23 @@ struct precision { }; }; +struct iterations { + + typedef int type; + typedef setting_property kind; + struct default_value { + int operator()() { + return 5e3; + }; + }; +}; + //and the solver itself template struct Dogleg { #ifdef USE_LOGGING - src::logger log; + dcm_logger log; #endif typedef typename Kernel::number_type number_type; @@ -96,7 +107,7 @@ struct Dogleg { }; template class Nonlinear = Dogleg> -struct Kernel : public PropertyOwner< mpl::vector1 > { +struct Kernel : public PropertyOwner< mpl::vector2 > { //basics typedef Scalar number_type; diff --git a/src/Mod/Assembly/App/opendcm/core/logging.hpp b/src/Mod/Assembly/App/opendcm/core/logging.hpp index bef24ef9b..ed4d7fef5 100644 --- a/src/Mod/Assembly/App/opendcm/core/logging.hpp +++ b/src/Mod/Assembly/App/opendcm/core/logging.hpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -44,8 +44,20 @@ namespace keywords = boost::log::keywords; namespace dcm { +enum severity_level { + + iteration, + solving, + manipulation, + information, + error +}; + +BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level) + static int counter = 0; typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t; +typedef src::severity_logger< severity_level > dcm_logger; inline boost::shared_ptr< sink_t > init_log() { diff --git a/src/Mod/Assembly/App/opendcm/core/system.hpp b/src/Mod/Assembly/App/opendcm/core/system.hpp index df8a6620d..a483c9620 100644 --- a/src/Mod/Assembly/App/opendcm/core/system.hpp +++ b/src/Mod/Assembly/App/opendcm/core/system.hpp @@ -283,6 +283,13 @@ public: Shedule m_sheduler; Kernel m_kernel; std::vector > m_subsystems; + +#ifdef USE_LOGGING + template + void setLoggingFilter(const Expr& ex) { + sink->set_filter(ex); + } +#endif }; //implementations which always need to be with the definition as they can't be externalised diff --git a/src/Mod/Assembly/App/opendcm/core/transformation.hpp b/src/Mod/Assembly/App/opendcm/core/transformation.hpp index e35fb4856..9f512d497 100644 --- a/src/Mod/Assembly/App/opendcm/core/transformation.hpp +++ b/src/Mod/Assembly/App/opendcm/core/transformation.hpp @@ -58,12 +58,16 @@ public: //*********************** const Rotation& rotation() const; template + Transform& setRotation(const Eigen::RotationBase& rotation); + template Transform& rotate(const Eigen::RotationBase& rotation); const Translation& translation() const; + Transform& setTranslation(const Translation& translation); Transform& translate(const Translation& translation); const Scaling& scaling() const; + Transform& setScale(const Scaling& scaling); Transform& scale(const Scalar& scaling); Transform& scale(const Scaling& scaling); diff --git a/src/Mod/Assembly/App/opendcm/module3d/clustermath.hpp b/src/Mod/Assembly/App/opendcm/module3d/clustermath.hpp index de96bdd20..aad0cd6c0 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/clustermath.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/clustermath.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include "defines.hpp" @@ -44,7 +45,7 @@ enum Scalemode { }; template -struct ClusterMath { +struct ClusterMath : public boost::noncopyable { public: typedef typename Sys::Kernel Kernel; @@ -91,6 +92,12 @@ public: void initFixMaps(); typename Kernel::Transform3D& getTransform(); + typename Kernel::Transform3D::Translation const& getTranslation() const; + typename Kernel::Transform3D::Rotation const& getRotation() const; + void setTransform(typename Kernel::Transform3D const& t); + void setTranslation(typename Kernel::Transform3D::Translation const& ); + void setRotation(typename Kernel::Transform3D::Rotation const&); + void mapsToTransform(typename Kernel::Transform3D& trans); void transformToMaps(typename Kernel::Transform3D& trans); diff --git a/src/Mod/Assembly/App/opendcm/module3d/distance.hpp b/src/Mod/Assembly/App/opendcm/module3d/distance.hpp index d26215f7d..af79e5d24 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/distance.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/distance.hpp @@ -85,7 +85,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > { Vector3 diff, n, dist; #ifdef USE_LOGGING - src::logger log; + dcm_logger log; attrs::mutable_constant< std::string > tag; type() : tag("Distance point3D line3D") { @@ -98,7 +98,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > { Vector3 pp = line.head(3) + (line.head(3)-point.head(3)).norm()*line.template segment<3>(3); #ifdef USE_LOGGING if(!boost::math::isnormal(pp.norm())) - BOOST_LOG(log) << "Unnormal pseudopoint detected"; + BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected"; #endif v2.push_back(pp); }; @@ -114,7 +114,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > { const Scalar res = dist.norm() - sc_value; #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal residual detected: "< { const Scalar res = dist.dot(d_dist)/dist.norm(); #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal first cluster gradient detected: "< { const Scalar res = dist.dot(d_dist)/dist.norm(); #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal second cluster gradient detected: "< { v2.push_back(pp); #ifdef USE_LOGGING if(!boost::math::isnormal(pp.norm())) - BOOST_LOG(log) << "Unnormal pseudopoint detected"; + BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected"; #endif }; void setScale(Scalar scale) { @@ -239,7 +239,7 @@ struct Distance::type< Kernel, tag::point3D, tag::plane3D > { return result + sc_value; #ifdef USE_LOGGING if(!boost::math::isfinite(result)) - BOOST_LOG(log) << "Unnormal residual detected: " << result; + BOOST_LOG_SEV(log, error) << "Unnormal residual detected: " << result; #endif return result; }; @@ -253,7 +253,7 @@ struct Distance::type< Kernel, tag::point3D, tag::plane3D > { const Scalar res = (dparam1.head(3)).dot(param2.tail(3)) / param2.tail(3).norm(); #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal first cluster gradient detected: "< { const Scalar res = (((-dp2).dot(n) + (p1-p2).dot(dn)) / n.norm() - (p1-p2).dot(n)* n.dot(dn)/std::pow(n.norm(),3)); #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal second cluster gradient detected: "< { #ifdef USE_LOGGING if(!boost::math::isfinite(pp1.norm()) || !boost::math::isfinite(pp2.norm())) - BOOST_LOG(log) << "Unnormal pseudopoint detected"; + BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected"; #endif v1.push_back(pp1); @@ -451,7 +451,7 @@ struct Distance::type< Kernel, tag::line3D, tag::line3D > { const Scalar res = std::abs(cdn) / nxn.norm(); #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal residual detected: "< { #ifdef USE_LOGGING if(!boost::math::isfinite(diff)) - BOOST_LOG(log) << "Unnormal first cluster gradient detected: "< { #ifdef USE_LOGGING if(!boost::math::isfinite(diff)) - BOOST_LOG(log) << "Unnormal first cluster gradient detected: "<(v(0), t); a.template set(v(1), t); a.template set(v(2), t); + a.finalize(t); }; }; @@ -87,6 +88,7 @@ namespace modell { a.template set(v(3), t); a.template set(v(4), t); a.template set(v(5), t); + a.finalize(t); }; }; @@ -122,6 +124,7 @@ namespace modell { a.template set(v(4), t); a.template set(v(5), t); a.template set(v(6), t); + a.finalize(t); }; }; @@ -138,6 +141,8 @@ struct dummy_accessor { void set(Scalar value, T& t) { //TODO: throw }; + template + void finalize(T& t) {}; }; //dummy geometry traits for boost blank, wil bever be used diff --git a/src/Mod/Assembly/App/opendcm/module3d/imp/clustermath_imp.hpp b/src/Mod/Assembly/App/opendcm/module3d/imp/clustermath_imp.hpp index 46f37b56d..e4043b20a 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/imp/clustermath_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/imp/clustermath_imp.hpp @@ -105,6 +105,31 @@ typename ClusterMath::Kernel::Transform3D& ClusterMath::getTransform() return m_transform; }; +template +typename ClusterMath::Kernel::Transform3D::Translation const& ClusterMath::getTranslation() const { + return m_transform.translation(); +}; + +template +typename ClusterMath::Kernel::Transform3D::Rotation const& ClusterMath::getRotation() const { + return m_transform.rotation(); +}; + +template +void ClusterMath::setTransform(typename ClusterMath::Kernel::Transform3D const& t) { + m_transform = t; +}; + +template +void ClusterMath::setTranslation(typename ClusterMath::Kernel::Transform3D::Translation const& t) { + m_transform.setTranslation(t); +}; + +template +void ClusterMath::setRotation(typename ClusterMath::Kernel::Transform3D::Rotation const& r) { + m_transform.setRotation(r); +}; + template void ClusterMath::mapsToTransform(typename ClusterMath::Kernel::Transform3D& trans) { //add scale only after possible reset @@ -173,7 +198,7 @@ void ClusterMath::resetClusterRotation(typename ClusterMath::Kernel::T trans = m_resetTransform.inverse()*trans; m_ssrTransform *= m_resetTransform; - m_transform = m_resetTransform.inverse()*m_transform; + //m_transform = m_resetTransform.inverse()*m_transform; //apply the needed transformation to all geometries local values typedef typename std::vector::iterator iter; @@ -593,6 +618,12 @@ void ClusterMath::applyClusterScale(Scalar scale, bool isFixed) { #ifdef USE_LOGGING BOOST_LOG(log) << "sstrans scale: "< void MES::removeLocalGradientZeros() { #ifdef USE_LOGGING - BOOST_LOG(log) << "remove local gradient zero"; + BOOST_LOG_SEV(log, information) << "remove local gradient zero"; #endif //let the constraints treat the local zeros typedef typename Cluster::template object_iterator oiter; @@ -269,7 +269,7 @@ void SystemSolver::solveCluster(boost::shared_ptr cluster, Sys& sy if(params <= 0 || constraints <= 0) { //TODO:throw #ifdef USE_LOGGING - BOOST_LOG(log)<< "Error in system counting: params = " << params << " and constraints = "<::solveCluster(boost::shared_ptr cluster, Sys& sy //if(!has_cycle) { #ifdef USE_LOGGING - BOOST_LOG(log)<< "non-cyclic system dedected: solve rotation only"; + BOOST_LOG_SEV(log, solving)<< "non-cyclic system dedected: solve rotation only"; #endif //cool, lets do uncylic. first all rotational constraints with rotational parameters mes.setAccess(rotation); @@ -404,7 +404,7 @@ void SystemSolver::solveCluster(boost::shared_ptr cluster, Sys& sy done = true; else { #ifdef USE_LOGGING - BOOST_LOG(log)<< "Solve Translation after Rotations are not enough"; + BOOST_LOG_SEV(log, solving)<< "Solve Translation after Rotations are not enough"; #endif //let's try translation only @@ -423,9 +423,9 @@ void SystemSolver::solveCluster(boost::shared_ptr cluster, Sys& sy //}; //not done already? try it the hard way! - if(!done) { + if(!done) {*/ #ifdef USE_LOGGING - BOOST_LOG(log)<< "Full scale solver used"; + BOOST_LOG_SEV(log, solving)<< "Full scale solver used"; #endif mes.setAccess(complete); mes.recalculate(); @@ -434,10 +434,10 @@ void SystemSolver::solveCluster(boost::shared_ptr cluster, Sys& sy re(); sys.kernel().solve(mes, re); #ifdef USE_LOGGING - BOOST_LOG(log)<< "Numbers of rescale: "< #include +#include +#include #include #include #include @@ -234,6 +236,48 @@ bool VectorInput(Geom& v, Row& r, Value& val) { return true; // output continues }; +template +bool TranslationOutput(Translation& v, Row& r, Value& val) { + + if(r < 3) { + + val = v.getTranslation().vector()(r++); + return true; // output continues + } + + return false; // fail the output +}; + +template +bool TranslationInput(CM& t, std::vector const& val) { + + t.setTranslation(typename CM::Kernel::Transform3D::Translation(val[0],val[1],val[2])); + return true; // output continues +}; + +template +bool RotationOutput(CM& v, Row& r, Value& val) { + + if(r < 3) { + + val = v.getRotation().vec()(r++); + return true; // output continues + } + else if( r < 4 ) { + val = v.getRotation().w(); + return true; + } + + return false; // fail the output +}; + +template +bool RotationInput(CM& t, std::vector const& val) { + + t.setRotation(typename CM::Kernel::Transform3D::Rotation(val[3], val[0], val[1], val[2])); + return true; // output continues +}; + template struct inject_set { @@ -302,6 +346,8 @@ static science_type const scientific = science_type(); BOOST_PHOENIX_ADAPT_FUNCTION(bool, vector_out, dcm::details::VectorOutput, 3) BOOST_PHOENIX_ADAPT_FUNCTION(bool, vector_in, dcm::details::VectorInput, 3) +BOOST_PHOENIX_ADAPT_FUNCTION(bool, translation_out, dcm::details::TranslationOutput, 3) +BOOST_PHOENIX_ADAPT_FUNCTION(bool, rotation_out, dcm::details::RotationOutput, 3) BOOST_PHOENIX_ADAPT_FUNCTION(bool, create, dcm::details::Create, 4) BOOST_FUSION_ADAPT_STRUCT( @@ -331,6 +377,14 @@ void parser_generator< typename details::getModule3D::type::vertex_prop r = karma::lit("Vertex") << karma::eol << "" << karma::int_ << ""; }; +/* +template +void parser_generator< typename details::getModule3D::type::math_prop , System, iterator >::init(generator& r) { + + r = karma::lit("Math3D") + << karma::eol << "" << (details::scientific[ boost::spirit::_pass = translation_out(karma::_val, karma::_a, karma::_1) ] % ' ') << "" + << karma::eol << karma::eps[karma::_a = 0] << "" << (details::scientific[ boost::spirit::_pass = rotation_out(karma::_val, karma::_a, karma::_1) ] % ' ') << ""; +};*/ template void parser_generator< typename details::getModule3D::type::Constraint3D , System, iterator >::init(generator& r) { @@ -373,6 +427,13 @@ void parser_parser< typename details::getModule3D::type::vertex_prop, Sy r %= qi::lit("Vertex") >> "" >> qi::int_ >> ""; }; +/* +template +void parser_parser< typename details::getModule3D::type::math_prop, System, iterator >::init(parser& r) { + + //r = qi::lit("Math3D") >> "" >> (*qi::double_)[ phx::bind(&details::TranslationInput >, qi::_val, qi::_1) ] >> "" + // >> "" >> (*qi::double_)[ phx::bind(&details::RotationInput >,qi::_val, qi::_1) ] >> ""; +};*/ template void parser_parser< typename details::getModule3D::type::Constraint3D, System, iterator >::init(parser& r) { diff --git a/src/Mod/Assembly/App/opendcm/module3d/solver.hpp b/src/Mod/Assembly/App/opendcm/module3d/solver.hpp index 45e750ac9..0522dce4f 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/solver.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/solver.hpp @@ -46,7 +46,7 @@ struct MES : public Sys::Kernel::MappedEquationSystem { boost::shared_ptr m_cluster; #ifdef USE_LOGGING - src::logger log; + dcm_logger log; #endif MES(boost::shared_ptr cl, int par, int eqn); diff --git a/src/Mod/Assembly/App/opendcm/module3d/state.hpp b/src/Mod/Assembly/App/opendcm/module3d/state.hpp index f115a0d75..26ad11ec5 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/state.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/state.hpp @@ -63,6 +63,17 @@ struct parser_generator< typename details::getModule3D::type::vertex_pro typedef karma::rule generator; static void init(generator& r); }; +/* +template +struct parser_generate< typename details::getModule3D::type::math_prop , System> + : public mpl::true_ {}; + +template +struct parser_generator< typename details::getModule3D::type::math_prop , System, iterator > { + + typedef karma::rule&(), karma::locals > generator; + static void init(generator& r); +};*/ template struct parser_generate< typename details::getModule3D::type::Constraint3D , System> @@ -127,7 +138,17 @@ struct parser_parser< typename details::getModule3D::type::vertex_prop, typedef qi::rule parser; static void init(parser& r); }; +/* +template +struct parser_parse< typename details::getModule3D::type::math_prop, System> + : public mpl::true_ {}; +template +struct parser_parser< typename details::getModule3D::type::math_prop, System, iterator > { + + typedef qi::rule(), qi::space_type > parser; + static void init(parser& r); +};*/ template struct parser_parse< typename details::getModule3D::type::Constraint3D , System> diff --git a/src/Mod/Assembly/App/opendcm/modulePart/module.hpp b/src/Mod/Assembly/App/opendcm/modulePart/module.hpp index 315a17112..b9fe7d019 100644 --- a/src/Mod/Assembly/App/opendcm/modulePart/module.hpp +++ b/src/Mod/Assembly/App/opendcm/modulePart/module.hpp @@ -58,7 +58,7 @@ struct ModulePart { protected: #ifdef USE_LOGGING - src::logger log; + dcm_logger log; #endif //check if we have module3d in this system @@ -299,7 +299,7 @@ ModulePart::type::Part_base::Part_base(const T& geometry, Sys m_cluster->template getProperty().getTransform() = m_transform; #ifdef USE_LOGGING - BOOST_LOG(log) << "Init: "<::type::Part_base::finishCalculation() { apply(vis); #ifdef USE_LOGGING - BOOST_LOG(log) << "New Value: "< { Vector3 v01, v02, v12, cross; #ifdef USE_LOGGING - src::logger log; + dcm_logger log; attrs::mutable_constant< std::string > tag; type() : tag("Distance point3D segment3D") { @@ -55,7 +55,7 @@ struct Distance::type< Kernel, tag::point3D, tag::segment3D > { Vector3 pp = segment.head(3) + (segment.head(3)-point.head(3)).norm()*dir; #ifdef USE_LOGGING if(!boost::math::isnormal(pp.norm())) - BOOST_LOG(log) << "Unnormal pseudopoint detected"; + BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected"; #endif v2.push_back(pp); }; @@ -77,7 +77,7 @@ struct Distance::type< Kernel, tag::point3D, tag::segment3D > { const Scalar res = cross.norm()/v12_n - sc_value; #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal residual detected: "< { const Scalar res = cross.dot(d_cross)/(cross_n*v12_n); #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal first cluster gradient detected: "< { const Scalar res = cross.dot(d_cross)/(cross_n*v12_n) - v12.dot(d_v12)*cross_v12_n; #ifdef USE_LOGGING if(!boost::math::isfinite(res)) - BOOST_LOG(log) << "Unnormal second cluster gradient detected: "<::prop_parser() : prop_parser::type::pos pos; Par::init(subrule); - start = qi::lit("") >> subrule[phx::at_c(*qi::_r1) = qi::_1] >> qi::lit(""); + //start = qi::lit("") >> subrule[phx::at_c(*qi::_r1) = qi::_1] >> qi::lit(""); }; template diff --git a/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui index d4f03872a..9c940cfc9 100644 --- a/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui +++ b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui @@ -116,7 +116,7 @@ Angle - + :/icons/constraints/Assembly_ConstraintAngle.svg:/icons/constraints/Assembly_ConstraintAngle.svg @@ -157,7 +157,7 @@ Coincident - + :/icons/constraints/Assembly_ConstraintCoincidence.svg:/icons/constraints/Assembly_ConstraintCoincidence.svg @@ -198,7 +198,7 @@ Fix - + :/icons/constraints/Assembly_ConstraintLock.svg:/icons/constraints/Assembly_ConstraintLock.svg @@ -239,7 +239,7 @@ Distance - + :/icons/constraints/Assembly_ConstraintDistance.svg:/icons/constraints/Assembly_ConstraintDistance.svg @@ -280,7 +280,7 @@ Orientation - + :/icons/constraints/Assembly_ConstraintOrientation.svg:/icons/constraints/Assembly_ConstraintOrientation.svg @@ -321,7 +321,7 @@ Align - + :/icons/constraints/Assembly_ConstraintAlignment.svg:/icons/constraints/Assembly_ConstraintAlignment.svg @@ -422,6 +422,9 @@ 0 + + false + 999999.000000000000000 @@ -436,7 +439,7 @@ ... - + :/icons/constraints/Assembly_ConstraintBidirectional.svg:/icons/constraints/Assembly_ConstraintBidirectional.svg @@ -474,8 +477,8 @@ ... - - :/icons/constraints/Assembly_ConstraintUnidirectional2.svg:/icons/constraints/Assembly_ConstraintUnidirectional2.svg + + :/icons/constraints/Assembly_ConstraintUnidirectional1.svg:/icons/constraints/Assembly_ConstraintUnidirectional1.svg @@ -509,8 +512,8 @@ ... - - :/icons/constraints/Assembly_ConstraintUnidirectional1.svg:/icons/constraints/Assembly_ConstraintUnidirectional1.svg + + :/icons/constraints/Assembly_ConstraintUnidirectional2.svg:/icons/constraints/Assembly_ConstraintUnidirectional2.svg @@ -566,7 +569,7 @@ Parallel - + :/icons/constraints/Assembly_ConstraintParallel.svg:/icons/constraints/Assembly_ConstraintParallel.svg @@ -604,7 +607,7 @@ Equal - + :/icons/constraints/Assembly_ConstraintEqual.svg:/icons/constraints/Assembly_ConstraintEqual.svg @@ -645,7 +648,7 @@ Opposite - + :/icons/constraints/Assembly_ConstraintOpposite.svg:/icons/constraints/Assembly_ConstraintOpposite.svg @@ -686,7 +689,7 @@ Perpend. - + :/icons/constraints/Assembly_ConstraintPerpendicular.svg:/icons/constraints/Assembly_ConstraintPerpendicular.svg @@ -729,6 +732,7 @@ + diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.cpp b/src/Mod/Assembly/Gui/ViewProviderPart.cpp index c1be685e2..b1e2ecbca 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderPart.cpp @@ -25,20 +25,35 @@ #ifndef _PreComp_ # include +#include +#include +#include #endif #include "ViewProviderPart.h" //#include //#include #include +#include using namespace AssemblyGui; +#ifdef ASSEMBLY_DEBUG_FACILITIES +SbColor PointColor(1.0f,0.0f,0.0f); +SbColor PseudoColor(0.0f,0.0f,1.0f); +SbColor MidpointColor(0.0f,1.0f,1.0f); +SbColor ZeroColor(1.0f,1.0f,0.0f); +#endif + PROPERTY_SOURCE(AssemblyGui::ViewProviderItemPart,AssemblyGui::ViewProviderItem) ViewProviderItemPart::ViewProviderItemPart() { - sPixmap = "Assembly_Assembly_Part_Tree.svg"; + sPixmap = "Assembly_Assembly_Part_Tree.svg"; + +#ifdef ASSEMBLY_DEBUG_FACILITIES + ADD_PROPERTY(ShowScalePoints,(false)); +#endif } ViewProviderItemPart::~ViewProviderItemPart() @@ -50,22 +65,46 @@ bool ViewProviderItemPart::doubleClicked(void) return true; } -void ViewProviderItemPart::attach(App::DocumentObject *pcFeat) +void ViewProviderItemPart::attach(App::DocumentObject* pcFeat) { // call parent attach method ViewProviderGeometryObject::attach(pcFeat); - - // putting all together with the switch addDisplayMaskMode(getChildRoot(), "Main"); + +#ifdef ASSEMBLY_DEBUG_FACILITIES + + m_anno = new SoAnnotation; + m_switch = new SoSwitch; + m_switch->addChild(m_anno); + + m_material = new SoMaterial; + m_anno->addChild(m_material); + + SoMaterialBinding* MtlBind = new SoMaterialBinding; + MtlBind->value = SoMaterialBinding::PER_VERTEX; + m_anno->addChild(MtlBind); + + m_pointsCoordinate = new SoCoordinate3; + m_anno->addChild(m_pointsCoordinate); + + SoDrawStyle* DrawStyle = new SoDrawStyle; + DrawStyle->pointSize = 8; + m_anno->addChild(DrawStyle); + m_points = new SoMarkerSet; + m_points->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7; + m_anno->addChild(m_points); + + pcRoot->addChild(m_switch); +#endif } void ViewProviderItemPart::setDisplayMode(const char* ModeName) { - if ( strcmp("Main",ModeName)==0 ) + if(strcmp("Main",ModeName)==0) setDisplayMaskMode("Main"); - ViewProviderGeometryObject::setDisplayMode( ModeName ); + ViewProviderGeometryObject::setDisplayMode(ModeName); } std::vector ViewProviderItemPart::getDisplayModes(void) const @@ -83,9 +122,10 @@ std::vector ViewProviderItemPart::claimChildren(void)const { std::vector res; - res.insert( res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); + res.insert(res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); + if(static_cast(getObject())->Model.getValue()) - res.push_back( static_cast(getObject())->Model.getValue()); + res.push_back(static_cast(getObject())->Model.getValue()); return res; @@ -95,10 +135,104 @@ std::vector ViewProviderItemPart::claimChildren3D(void)con { std::vector res; - res.insert( res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); + res.insert(res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); + if(static_cast(getObject())->Model.getValue()) - res.push_back( static_cast(getObject())->Model.getValue()); + res.push_back(static_cast(getObject())->Model.getValue()); return res; } + +#ifdef ASSEMBLY_DEBUG_FACILITIES + +void ViewProviderItemPart::onChanged(const App::Property* prop) { + + if(prop == &ShowScalePoints) { + if(ShowScalePoints.getValue()) { + m_switch->whichChild = 0; + + int counter = 0; + boost::shared_ptr part = static_cast(getObject())->m_part; + + if(!part) { + ViewProviderItem::onChanged(prop); + return; + } + + dcm::detail::Transform transform = part->m_cluster->getProperty::math_prop>().m_transform; + dcm::detail::Transform ssrTransform = part->m_cluster->getProperty::math_prop>().m_ssrTransform; + + dcm::detail::Transform trans = ssrTransform.inverse(); + + int PseudoSize = part->m_cluster->getProperty::math_prop>().m_pseudo.size(); + typedef dcm::details::ClusterMath::Vec Vector; + Vector& pv = part->m_cluster->getProperty::math_prop>().m_points; + + for(Vector::iterator it = pv.begin(); it != pv.end(); it++) { + + Kernel::Vector3 vec = trans * (*it); + m_pointsCoordinate->point.set1Value(counter, SbVec3f(vec(0),vec(1),vec(2))); + + if(counter < PseudoSize) + m_material->diffuseColor.set1Value(counter, PseudoColor); + else + m_material->diffuseColor.set1Value(counter, PointColor); + + counter++; + }; + + //midpoint + Kernel::Vector3 midpoint = trans * Kernel::Vector3(0,0,0); + + m_pointsCoordinate->point.set1Value(counter, SbVec3f(midpoint(0),midpoint(1),midpoint(2))); + + m_material->diffuseColor.set1Value(counter, MidpointColor); + + counter++; + + //origin + Kernel::Vector3 origin = Kernel::Vector3(0,0,0); + + m_pointsCoordinate->point.set1Value(counter, SbVec3f(origin(0),origin(1),origin(2))); + + m_material->diffuseColor.set1Value(counter, ZeroColor); + + counter++; + + m_points->numPoints = counter; + + //test + boost::shared_ptr g = part->m_cluster->getProperty::math_prop>().m_geometry[0]; + + std::stringstream str; + + str<<"Global: "<m_global.transpose()<getPoint()).transpose()<m_global.head(3); + + str<<"Local Point : "<<(transform.inverse()*v).transpose()<getPoint()).transpose()<whichChild = -1; + m_pointsCoordinate->point.setValues(0, 0, (SbVec3f*)NULL); + m_material->diffuseColor.setValues(0, 0, (SbColor*)NULL); + m_points->numPoints = 0; + } + }; + + ViewProviderItem::onChanged(prop); +} + +#endif diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.h b/src/Mod/Assembly/Gui/ViewProviderPart.h index 720b81ff5..ec8cbe30e 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.h +++ b/src/Mod/Assembly/Gui/ViewProviderPart.h @@ -25,6 +25,11 @@ #define ASSEMBLYGUI_ViewProviderPart_H #include "ViewProvider.h" +#include +#include +#include +#include +#include namespace AssemblyGui { @@ -49,7 +54,18 @@ public: virtual std::vector claimChildren(void)const; virtual std::vector claimChildren3D(void)const; - + +#ifdef ASSEMBLY_DEBUG_FACILITIES + //draw the dcm points + SoAnnotation* m_anno; + SoSwitch* m_switch; + SoMaterial* m_material; + SoCoordinate3* m_pointsCoordinate; + SoMarkerSet* m_points; + virtual void onChanged(const App::Property* prop); + + App::PropertyBool ShowScalePoints; +#endif };