multiple debug updates

This commit is contained in:
Stefan Tröger 2014-01-17 19:27:49 +01:00
parent cdd83966b1
commit 9bd19328ca
27 changed files with 742 additions and 305 deletions

View File

@ -53,6 +53,16 @@ ItemAssembly::ItemAssembly() {
ADD_PROPERTY(ApplyAtFailure,(false)); ADD_PROPERTY(ApplyAtFailure,(false));
ADD_PROPERTY(Precision,(1e-6)); ADD_PROPERTY(Precision,(1e-6));
ADD_PROPERTY(SaveState,(false)); ADD_PROPERTY(SaveState,(false));
ADD_PROPERTY(Iterations,(5e3));
ADD_PROPERTY(LogLevel, (long(1)));
std::vector<std::string> 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 #endif
} }
@ -71,6 +81,7 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
m_downstream_placement = Base::Placement(Base::Vector3<double>(0,0,0), Base::Rotation()); m_downstream_placement = Base::Placement(Base::Vector3<double>(0,0,0), Base::Rotation());
Base::Placement dummy; Base::Placement dummy;
initSolver(boost::shared_ptr<Solver>(), dummy, false); initSolver(boost::shared_ptr<Solver>(), dummy, false);
initConstraints(boost::shared_ptr<Solver>());
#ifdef ASSEMBLY_DEBUG_FACILITIES #ifdef ASSEMBLY_DEBUG_FACILITIES
@ -80,6 +91,7 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
m_solver->setOption<dcm::solverfailure>(dcm::IgnoreResults); m_solver->setOption<dcm::solverfailure>(dcm::IgnoreResults);
m_solver->setOption<dcm::precision>(Precision.getValue()); m_solver->setOption<dcm::precision>(Precision.getValue());
m_solver->setOption<dcm::iterations>(Iterations.getValue());
if(SaveState.getValue()) { if(SaveState.getValue()) {
@ -88,8 +100,10 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
m_solver->saveState(myfile); m_solver->saveState(myfile);
myfile.close(); myfile.close();
}; };
m_solver->setLoggingFilter(dcm::severity >= (dcm::severity_level)LogLevel.getValue());
#endif #endif
initConstraints(boost::shared_ptr<Solver>());
//solve the system //solve the system
m_solver->solve(); m_solver->solve();
@ -109,6 +123,12 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
//throw Base::Exception(message.str().c_str()); //throw Base::Exception(message.str().c_str());
Base::Console().Error(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 catch
(...) { (...) {
message.clear(); message.clear();
@ -321,3 +341,6 @@ void ItemAssembly::finish(boost::shared_ptr<Solver> subsystem) {
}; };
} //assembly } //assembly

View File

@ -88,6 +88,8 @@ public:
App::PropertyBool ApplyAtFailure; App::PropertyBool ApplyAtFailure;
App::PropertyFloat Precision; App::PropertyFloat Precision;
App::PropertyBool SaveState; App::PropertyBool SaveState;
App::PropertyInteger Iterations;
App::PropertyEnumeration LogLevel;
#endif #endif
private: private:

View File

@ -30,14 +30,15 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#include "opendcm/core.hpp" #include "opendcm/core.hpp"
#include "opendcm/module3d.hpp"
#include "opendcm/modulepart.hpp"
#ifdef ASSEMBLY_DEBUG_FACILITIES #ifdef ASSEMBLY_DEBUG_FACILITIES
#include "opendcm/modulestate.hpp" #include "opendcm/modulestate.hpp"
#endif #endif
#include "opendcm/module3d.hpp"
#include "opendcm/modulepart.hpp"
#include <Base/Placement.h> #include <Base/Placement.h>
#include <Base/Console.h>
#include <gp_Pnt.hxx> #include <gp_Pnt.hxx>
#include <gp_Lin.hxx> #include <gp_Lin.hxx>
@ -51,10 +52,13 @@ struct gp_pnt_accessor {
switch(ID) { switch(ID) {
case 0: case 0:
return t.X(); return t.X();
case 1: case 1:
return t.Y(); return t.Y();
case 2: case 2:
return t.Z(); return t.Z();
default: default:
return 0; return 0;
}; };
@ -65,166 +69,221 @@ struct gp_pnt_accessor {
case 0: case 0:
t.SetX(value); t.SetX(value);
break; break;
case 1: case 1:
t.SetY(value); t.SetY(value);
break; break;
case 2: case 2:
t.SetZ(value); t.SetZ(value);
break; break;
}; };
}; };
template<typename T>
void finalize(T& t) {};
}; };
struct gp_lin_accessor { struct gp_lin_accessor {
gp_Pnt pnt;
double dx,dy,dz;
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
Scalar get(T& t) { Scalar get(T& t) {
switch(ID) { switch(ID) {
case 0: case 0:
return t.Location().X(); return t.Location().X();
case 1: case 1:
return t.Location().Y(); return t.Location().Y();
case 2: case 2:
return t.Location().Z(); return t.Location().Z();
case 3: case 3:
return t.Direction().X(); return t.Direction().X();
case 4: case 4:
return t.Direction().Y(); return t.Direction().Y();
case 5: case 5:
return t.Direction().Z(); return t.Direction().Z();
default: default:
return 0; return 0;
}; };
}; };
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
void set(Scalar value, T& t) { void set(Scalar value, T& t) {
gp_Pnt p = t.Location();
gp_Dir d = t.Direction();
switch(ID) { switch(ID) {
case 0: case 0:
p.SetX(value); pnt.SetX(value);
break; break;
case 1: case 1:
p.SetY(value); pnt.SetY(value);
break; break;
case 2: case 2:
p.SetZ(value); pnt.SetZ(value);
break; break;
case 3: case 3:
d.SetX(value); dx=(value);
break; break;
case 4: case 4:
d.SetY(value); dy=(value);
break; break;
case 5: case 5:
d.SetZ(value); dz=(value);
break; break;
}; };
t.SetLocation(p); };
t.SetDirection(d); template<typename T>
void finalize(T& t) {
t.SetLocation(pnt);
t.SetDirection(gp_Dir(dx,dy,dz));
}; };
}; };
struct gp_pln_accessor { struct gp_pln_accessor {
gp_Pnt pnt;
double dx,dy,dz;
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
Scalar get(T& t) { Scalar get(T& t) {
switch(ID) { switch(ID) {
case 0: case 0:
return t.Axis().Location().X(); return t.Axis().Location().X();
case 1: case 1:
return t.Axis().Location().Y(); return t.Axis().Location().Y();
case 2: case 2:
return t.Axis().Location().Z(); return t.Axis().Location().Z();
case 3: case 3:
return t.Axis().Direction().X(); return t.Axis().Direction().X();
case 4: case 4:
return t.Axis().Direction().Y(); return t.Axis().Direction().Y();
case 5: case 5:
return t.Axis().Direction().Z(); return t.Axis().Direction().Z();
default: default:
return 0; return 0;
}; };
}; };
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
void set(Scalar value, T& t) { void set(Scalar value, T& t) {
gp_Pnt p = t.Axis().Location();
gp_Dir d = t.Axis().Direction();
switch(ID) { switch(ID) {
case 0: case 0:
p.SetX(value); pnt.SetX(value);
break; break;
case 1: case 1:
p.SetY(value); pnt.SetY(value);
break; break;
case 2: case 2:
p.SetZ(value); pnt.SetZ(value);
break; break;
case 3: case 3:
d.SetX(value); dx=value;
break; break;
case 4: case 4:
d.SetY(value); dy=value;
break; break;
case 5: case 5:
d.SetZ(value); dz=value;
break; break;
}; };
t.SetAxis(gp_Ax1(p,d)); };
template<typename T>
void finalize(T& t) {
t.SetAxis(gp_Ax1(pnt,gp_Dir(dx,dy,dz)));
}; };
}; };
struct gp_cylinder_accessor { struct gp_cylinder_accessor {
gp_Pnt pnt;
double dx,dy,dz;
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
Scalar get(T& t) { Scalar get(T& t) {
switch(ID) { switch(ID) {
case 0: case 0:
return t.Axis().Location().X(); return t.Axis().Location().X();
case 1: case 1:
return t.Axis().Location().Y(); return t.Axis().Location().Y();
case 2: case 2:
return t.Axis().Location().Z(); return t.Axis().Location().Z();
case 3: case 3:
return t.Axis().Direction().X(); return t.Axis().Direction().X();
case 4: case 4:
return t.Axis().Direction().Y(); return t.Axis().Direction().Y();
case 5: case 5:
return t.Axis().Direction().Z(); return t.Axis().Direction().Z();
case 6: case 6:
return t.Radius(); return t.Radius();
default: default:
return 0; return 0;
}; };
}; };
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
void set(Scalar value, T& t) { void set(Scalar value, T& t) {
gp_Pnt p = t.Axis().Location();
gp_Dir d = t.Axis().Direction();
switch(ID) { switch(ID) {
case 0: case 0:
p.SetX(value); pnt.SetX(value);
break; break;
case 1: case 1:
p.SetY(value); pnt.SetY(value);
break; break;
case 2: case 2:
p.SetZ(value); pnt.SetZ(value);
break; break;
case 3: case 3:
d.SetX(value); dx=value;
break; break;
case 4: case 4:
d.SetY(value); dy=value;
break; break;
case 5: case 5:
d.SetZ(value); dz=value;
break; break;
case 6: case 6:
t.SetRadius(value); t.SetRadius(value);
break; break;
}; };
t.SetAxis(gp_Ax1(p,d));
};
template<typename T>
void finalize(T& t) {
t.SetAxis(gp_Ax1(pnt,gp_Dir(dx,dy,dz)));
}; };
}; };
@ -236,21 +295,29 @@ struct placement_accessor {
template<typename Scalar, int ID, typename T> template<typename Scalar, int ID, typename T>
Scalar get(T& t) { Scalar get(T& t) {
t.getRotation().getValue(q0,q1,q2,q3); t.getRotation().getValue(q0,q1,q2,q3);
switch(ID) { switch(ID) {
case 0: case 0:
return q3; return q3;
case 1: case 1:
return q0; return q0;
case 2: case 2:
return q1; return q1;
case 3: case 3:
return q2; return q2;
case 4: case 4:
return t.getPosition()[0]; return t.getPosition()[0];
case 5: case 5:
return t.getPosition()[1]; return t.getPosition()[1];
case 6: case 6:
return t.getPosition()[2]; return t.getPosition()[2];
default: default:
return 0; return 0;
}; };
@ -261,21 +328,27 @@ struct placement_accessor {
case 0: case 0:
q3 = value; q3 = value;
break; break;
case 1: case 1:
q0 = value; q0 = value;
break; break;
case 2: case 2:
q1 = value; q1 = value;
break; break;
case 3: case 3:
q2 = value; q2 = value;
break; break;
case 4: case 4:
vec[0] = value; vec[0] = value;
break; break;
case 5: case 5:
vec[1] = value; vec[1] = value;
break; break;
case 6: case 6:
vec[2] = value; vec[2] = value;
break; break;
@ -333,7 +406,7 @@ typedef dcm::ModulePart< mpl::vector1< Base::Placement >, std::string > ModulePa
#ifdef ASSEMBLY_DEBUG_FACILITIES #ifdef ASSEMBLY_DEBUG_FACILITIES
typedef dcm::System<Kernel, Module3D, ModulePart, dcm::ModuleState> Solver; typedef dcm::System<Kernel, Module3D, ModulePart, dcm::ModuleState> Solver;
#elif #else
typedef dcm::System<Kernel, Module3D, ModulePart> Solver; typedef dcm::System<Kernel, Module3D, ModulePart> Solver;
#endif #endif

View File

@ -623,7 +623,8 @@ public:
* Sometimes it is needed to add a vertex with given global identifier. As the global vertex can not * 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 * 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 * 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<LocalVertex, GlobalVertex> the local and global vertex descriptor * @return fusion::vector<LocalVertex, GlobalVertex> the local and global vertex descriptor
**/ **/

View File

@ -217,7 +217,7 @@ class Geometry {
#ifdef USE_LOGGING #ifdef USE_LOGGING
protected: protected:
src::logger log; dcm_logger log;
#endif #endif
public: public:
@ -327,13 +327,7 @@ public:
void recalculate(DiffTransform& trans); void recalculate(DiffTransform& trans);
typename Kernel::Vector3 getPoint() { typename Kernel::Vector3 getPoint() {
if(m_isInCluster)
return m_toplocal.template segment<Dim>(0); return m_toplocal.template segment<Dim>(0);
else if(m_init)
return m_rotated.template segment<Dim>(0);
else
return m_global.template segment<Dim>(0);
}; };
//use m_value or parametermap as new value, dependend on the solving mode //use m_value or parametermap as new value, dependend on the solving mode

View File

@ -1,4 +1,4 @@
/* /*
openDCM, dimensional constraint manager openDCM, dimensional constraint manager
Copyright (C) 2012 Stefan Troeger <stefantroeger@gmx.net> Copyright (C) 2012 Stefan Troeger <stefantroeger@gmx.net>
@ -504,6 +504,10 @@ template< typename edge_prop, typename vertex_prop, typename cluster_prop, typen
fusion::vector<LocalVertex, GlobalVertex> fusion::vector<LocalVertex, GlobalVertex>
ClusterGraph<edge_prop, vertex_prop, cluster_prop, objects>::addVertex(GlobalVertex gv) { ClusterGraph<edge_prop, vertex_prop, cluster_prop, objects>::addVertex(GlobalVertex gv) {
setChanged();
std::pair<LocalVertex, bool> res = getLocalVertex(gv);
if(!res.second) {
vertex_bundle vp; vertex_bundle vp;
fusion::at_c<0> (vp) = gv; fusion::at_c<0> (vp) = gv;
LocalVertex v = boost::add_vertex(vp, *this); LocalVertex v = boost::add_vertex(vp, *this);
@ -512,8 +516,10 @@ ClusterGraph<edge_prop, vertex_prop, cluster_prop, objects>::addVertex(GlobalVer
if(gv > m_id->count()) if(gv > m_id->count())
m_id->setCount(gv); m_id->setCount(gv);
setChanged();
return fusion::make_vector(v, 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> template< typename edge_prop, typename vertex_prop, typename cluster_prop, typename objects>

View File

@ -107,7 +107,7 @@ void Geometry<Kernel, Dim, TagList>::init() {
m_init = false; m_init = false;
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "Init: "<<m_global.transpose(); BOOST_LOG_SEV(log, information) << "Init: "<<m_global.transpose();
#endif #endif
}; };
@ -198,7 +198,7 @@ void Geometry<Kernel, Dim, TagList>::recalculate(DiffTransform& trans) {
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isnormal(m_rotated.norm()) || !boost::math::isnormal(m_diffparam.norm())) { if(!boost::math::isnormal(m_rotated.norm()) || !boost::math::isnormal(m_diffparam.norm())) {
BOOST_LOG(log) << "Unnormal recalculated value detected: "<<m_rotated.transpose()<<std::endl BOOST_LOG_SEV(log, error) << "Unnormal recalculated value detected: "<<m_rotated.transpose()<<std::endl
<< "or unnormal recalculated diff detected: "<<std::endl<<m_diffparam<<std::endl << "or unnormal recalculated diff detected: "<<std::endl<<m_diffparam<<std::endl
<<" with Transform: "<<std::endl<<trans; <<" with Transform: "<<std::endl<<trans;
} }
@ -213,7 +213,7 @@ void Geometry<Kernel, Dim, TagList>::finishCalculation() {
//recalculate(1.); //remove scaling to get right global value //recalculate(1.); //remove scaling to get right global value
m_global = m_rotated; m_global = m_rotated;
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "Finish cluster calculation"; BOOST_LOG_SEV(log, information) << "Finish cluster calculation";
#endif #endif
} }
//TODO:non cluster paramter scaling //TODO:non cluster paramter scaling
@ -221,7 +221,7 @@ void Geometry<Kernel, Dim, TagList>::finishCalculation() {
m_global = m_parameter; m_global = m_parameter;
normalize(); normalize();
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "Finish calculation"; BOOST_LOG_SEV(log, information) << "Finish calculation";
#endif #endif
}; };
@ -247,7 +247,7 @@ void Geometry<Kernel, Dim, TagList>::transform(const Transform& t, VectorType& v
} }
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "Transformed with cluster: "<<m_isInCluster BOOST_LOG_SEV(log, manipulation) << "Transformed with cluster: "<<m_isInCluster
<< ", init: "<<m_init<<" into: "<< vec.transpose(); << ", init: "<<m_init<<" into: "<< vec.transpose();
#endif #endif
} }

View File

@ -35,7 +35,7 @@ Dogleg<Kernel>::Dogleg(Kernel* k) : m_kernel(k), tolg(1e-40), tolx(1e-20) {
}; };
template<typename Kernel> template<typename Kernel>
Dogleg<Kernel>::Dogleg() : tolg(1e-40), tolx(1e-20) { Dogleg<Kernel>::Dogleg() : tolg(1e-6), tolx(1e-3) {
#ifdef USE_LOGGING #ifdef USE_LOGGING
log.add_attribute("Tag", attrs::constant< std::string >("Dogleg")); log.add_attribute("Tag", attrs::constant< std::string >("Dogleg"));
@ -62,16 +62,17 @@ void Dogleg<Kernel>::calculateStep(const Eigen::MatrixBase<Derived>& g, const Ei
const typename Kernel::Vector h_gn = jacobi.fullPivLu().solve(-residual); const typename Kernel::Vector h_gn = jacobi.fullPivLu().solve(-residual);
const double eigen_error = (jacobi*h_gn + residual).norm(); const double eigen_error = (jacobi*h_gn + residual).norm();
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(h_gn.norm())) { if(!boost::math::isfinite(h_gn.norm())) {
BOOST_LOG(log)<< "Unnormal gauss-newton detected: "<<h_gn.norm(); BOOST_LOG_SEV(log, error) << "Unnormal gauss-newton detected: "<<h_gn.norm();
} }
if(!boost::math::isfinite(h_sd.norm())) { if(!boost::math::isfinite(h_sd.norm())) {
BOOST_LOG(log)<< "Unnormal steepest descent detected: "<<h_sd.norm(); BOOST_LOG_SEV(log, error) << "Unnormal steepest descent detected: "<<h_sd.norm();
} }
if(!boost::math::isfinite(alpha)) { if(!boost::math::isfinite(alpha)) {
BOOST_LOG(log)<< "Unnormal alpha detected: "<<alpha; BOOST_LOG_SEV(log, error) << "Unnormal alpha detected: "<<alpha;
} }
#endif #endif
@ -86,7 +87,7 @@ void Dogleg<Kernel>::calculateStep(const Eigen::MatrixBase<Derived>& g, const Ei
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(h_dl.norm())) { if(!boost::math::isfinite(h_dl.norm())) {
BOOST_LOG(log)<< "Unnormal dogleg descent detected: "<<h_dl.norm(); BOOST_LOG_SEV(log, error) << "Unnormal dogleg descent detected: "<<h_dl.norm();
} }
#endif #endif
@ -113,15 +114,15 @@ void Dogleg<Kernel>::calculateStep(const Eigen::MatrixBase<Derived>& g, const Ei
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(c)) { if(!boost::math::isfinite(c)) {
BOOST_LOG(log)<< "Unnormal dogleg c detected: "<<c; BOOST_LOG_SEV(log, error) << "Unnormal dogleg c detected: "<<c;
} }
if(!boost::math::isfinite(bas)) { if(!boost::math::isfinite(bas)) {
BOOST_LOG(log)<< "Unnormal dogleg bas detected: "<<bas; BOOST_LOG_SEV(log, error) << "Unnormal dogleg bas detected: "<<bas;
} }
if(!boost::math::isfinite(beta)) { if(!boost::math::isfinite(beta)) {
BOOST_LOG(log)<< "Unnormal dogleg beta detected: "<<beta; BOOST_LOG_SEV(log, error) << "Unnormal dogleg beta detected: "<<beta;
} }
#endif #endif
@ -149,14 +150,14 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
sys.recalculate(); sys.recalculate();
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "initial jacobi: "<<std::endl<<sys.Jacobi<<std::endl BOOST_LOG_SEV(log, solving) << "initial jacobi: "<<std::endl<<sys.Jacobi<<std::endl
<< "residual: "<<sys.Residual.transpose()<<std::endl << "residual: "<<sys.Residual.transpose()<<std::endl
<< "maximal differential: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>(); << "maximal differential: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>();
#endif #endif
sys.removeLocalGradientZeros(); sys.removeLocalGradientZeros();
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "LGZ jacobi: "<<std::endl<<sys.Jacobi<<std::endl BOOST_LOG_SEV(log, solving) << "LGZ jacobi: "<<std::endl<<sys.Jacobi<<std::endl
<< "maximal differential: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>(); << "maximal differential: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>();
#endif #endif
@ -179,17 +180,18 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
unused=0; unused=0;
counter=0; counter=0;
int maxIterNumber = 10000;//MaxIterations * xsize; int maxIterNumber = m_kernel->template getProperty<iterations>();
number_type pr = m_kernel->template getProperty<precision>()*sys.Scaling;
number_type diverging_lim = 1e6*err + 1e12; number_type diverging_lim = 1e6*err + 1e12;
do { do {
// check if finished // check if finished
if(fx_inf <= m_kernel->template getProperty<precision>()*sys.Scaling) // Success if(fx_inf <= pr) // Success
stop = 1; 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"); 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"); throw solving_error() << boost::errinfo_errno(3) << error_message("step size below limit");
else if(iter >= maxIterNumber) else if(iter >= maxIterNumber)
throw solving_error() << boost::errinfo_errno(4) << error_message("maximal iterations reached"); throw solving_error() << boost::errinfo_errno(4) << error_message("maximal iterations reached");
@ -210,11 +212,12 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
//get the update step //get the update step
calculateStep(g, sys.Jacobi, sys.Residual, h_dl, delta); calculateStep(g, sys.Jacobi, sys.Residual, h_dl, delta);
// #ifdef USE_LOGGING #ifdef USE_LOGGING
// BOOST_LOG(log)<< "Step in iter "<<iter<<std::endl BOOST_LOG_SEV(log, iteration) << "Step in iter "<<iter<<std::endl
// << "Step: "<<h_dl.transpose()<<std::endl << "Step: "<<h_dl.transpose()<<std::endl
// << "Jacobi: "<<sys.Jacobi<<std::endl; << "Jacobi: "<<sys.Jacobi<<std::endl
// #endif << "Residual: "<<sys.Residual.transpose();
#endif
// calculate the linear model // calculate the linear model
dL = sys.Residual.norm() - (sys.Residual + sys.Jacobi*h_dl).norm(); dL = sys.Residual.norm() - (sys.Residual + sys.Jacobi*h_dl).norm();
@ -226,11 +229,11 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(sys.Residual.norm())) { if(!boost::math::isfinite(sys.Residual.norm())) {
BOOST_LOG(log)<< "Unnormal residual detected: "<<sys.Residual.norm(); BOOST_LOG_SEV(log, error) << "Unnormal residual detected: "<<sys.Residual.norm();
} }
if(!boost::math::isfinite(sys.Jacobi.sum())) { if(!boost::math::isfinite(sys.Jacobi.sum())) {
BOOST_LOG(log)<< "Unnormal jacobi detected: "<<sys.Jacobi.sum(); BOOST_LOG_SEV(log, error) << "Unnormal jacobi detected: "<<sys.Jacobi.sum();
} }
#endif #endif
@ -253,17 +256,17 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
nu = 2*nu; nu = 2*nu;
} }
// #ifdef USE_LOGGING #ifdef USE_LOGGING
// BOOST_LOG(log)<<"Result of step dF: "<<dF<<", dL: "<<dL<<std::endl BOOST_LOG_SEV(log, iteration)<<"Result of step dF: "<<dF<<", dL: "<<dL<<std::endl
// << "New Residual: "<< sys.Residual.transpose()<<std::endl; << "New Residual: "<< sys.Residual.transpose()<<std::endl;
// #endif #endif
if(dF > 0 && dL > 0) { if(dF > 0 && dL > 0) {
//see if we got too high differentials //see if we got too high differentials
if(sys.Jacobi.template lpNorm<Eigen::Infinity>() > 2) { if(sys.Jacobi.template lpNorm<Eigen::Infinity>() > 2) {
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "High differential detected: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>()<<" in iteration: "<<iter; BOOST_LOG_SEV(log, iteration)<< "High differential detected: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>()<<" in iteration: "<<iter;
#endif #endif
rescale(); rescale();
sys.recalculate(); sys.recalculate();
@ -287,7 +290,7 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
} }
else { else {
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "Reject step in iter "<<iter<<", dF: "<<dF<<", dL: "<<dL; BOOST_LOG_SEV(log, iteration)<< "Reject step in iter "<<iter<<", dF: "<<dF<<", dL: "<<dL;
#endif #endif
sys.Residual = F_old; sys.Residual = F_old;
sys.Jacobi = J_old; sys.Jacobi = J_old;
@ -305,8 +308,10 @@ int Dogleg<Kernel>::solve(typename Kernel::MappedEquationSystem& sys, Functor& r
time = (double(end-start) * 1000.) / double(CLOCKS_PER_SEC); time = (double(end-start) * 1000.) / double(CLOCKS_PER_SEC);
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) <<"Done solving: "<<err<<", iter: "<<iter<<", unused: "<<unused<<", reason:"<< stop; BOOST_LOG_SEV(log, solving)<<"Done solving: "<<err<<", iter: "<<iter<<", unused: "<<unused<<", reason:"<< stop;
BOOST_LOG(log)<< "final jacobi: "<<std::endl<<sys.Jacobi; BOOST_LOG_SEV(log, solving)<< "final jacobi: "<<std::endl<<sys.Jacobi
<< "residual: "<<sys.Residual.transpose()<<std::endl
<< "maximal differential: "<<sys.Jacobi.template lpNorm<Eigen::Infinity>();
#endif #endif
return stop; return stop;

View File

@ -62,6 +62,14 @@ template<typename Scalar, int Dim>
const typename Transform<Scalar, Dim>::Rotation& Transform<Scalar, Dim>::rotation() const { const typename Transform<Scalar, Dim>::Rotation& Transform<Scalar, Dim>::rotation() const {
return m_rotation; return m_rotation;
} }
template<typename Scalar, int Dim>
template<typename Derived>
Transform<Scalar, Dim>& Transform<Scalar, Dim>::setRotation(const Eigen::RotationBase<Derived,Dim>& rotation) {
m_rotation = rotation.derived().normalized();
return *this;
}
template<typename Scalar, int Dim> template<typename Scalar, int Dim>
template<typename Derived> template<typename Derived>
Transform<Scalar, Dim>& Transform<Scalar, Dim>::rotate(const Eigen::RotationBase<Derived,Dim>& rotation) { Transform<Scalar, Dim>& Transform<Scalar, Dim>::rotate(const Eigen::RotationBase<Derived,Dim>& rotation) {
@ -73,6 +81,13 @@ template<typename Scalar, int Dim>
const typename Transform<Scalar, Dim>::Translation& Transform<Scalar, Dim>::translation() const { const typename Transform<Scalar, Dim>::Translation& Transform<Scalar, Dim>::translation() const {
return m_translation; return m_translation;
} }
template<typename Scalar, int Dim>
Transform<Scalar, Dim>& Transform<Scalar, Dim>::setTranslation(const Translation& translation) {
m_translation = translation;
return *this;
}
template<typename Scalar, int Dim> template<typename Scalar, int Dim>
Transform<Scalar, Dim>& Transform<Scalar, Dim>::translate(const Translation& translation) { Transform<Scalar, Dim>& Transform<Scalar, Dim>::translate(const Translation& translation) {
m_translation = m_translation*translation; m_translation = m_translation*translation;
@ -89,6 +104,11 @@ Transform<Scalar, Dim>& Transform<Scalar, Dim>::scale(const Scalar& scaling) {
return *this; return *this;
} }
template<typename Scalar, int Dim> template<typename Scalar, int Dim>
Transform<Scalar, Dim>& Transform<Scalar, Dim>::setScale(const Scaling& scaling) {
m_scale.factor() = scaling.factor();
return *this;
}
template<typename Scalar, int Dim>
Transform<Scalar, Dim>& Transform<Scalar, Dim>::scale(const Scaling& scaling) { Transform<Scalar, Dim>& Transform<Scalar, Dim>::scale(const Scaling& scaling) {
m_scale.factor() *= scaling.factor(); m_scale.factor() *= scaling.factor();
return *this; return *this;

View File

@ -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 //and the solver itself
template<typename Kernel> template<typename Kernel>
struct Dogleg { struct Dogleg {
#ifdef USE_LOGGING #ifdef USE_LOGGING
src::logger log; dcm_logger log;
#endif #endif
typedef typename Kernel::number_type number_type; typedef typename Kernel::number_type number_type;
@ -96,7 +107,7 @@ struct Dogleg {
}; };
template<typename Scalar, template<class> class Nonlinear = Dogleg> template<typename Scalar, template<class> class Nonlinear = Dogleg>
struct Kernel : public PropertyOwner< mpl::vector1<precision> > { struct Kernel : public PropertyOwner< mpl::vector2<precision, iterations> > {
//basics //basics
typedef Scalar number_type; typedef Scalar number_type;

View File

@ -27,7 +27,7 @@
#include <boost/log/core.hpp> #include <boost/log/core.hpp>
#include <boost/log/sinks.hpp> #include <boost/log/sinks.hpp>
#include <boost/log/expressions/formatters.hpp> #include <boost/log/expressions/formatters.hpp>
#include <boost/log/sources/basic_logger.hpp> #include <boost/log/sources/severity_logger.hpp>
#include <boost/log/attributes.hpp> #include <boost/log/attributes.hpp>
#include <boost/log/sources/logger.hpp> #include <boost/log/sources/logger.hpp>
#include <boost/log/sources/record_ostream.hpp> #include <boost/log/sources/record_ostream.hpp>
@ -44,8 +44,20 @@ namespace keywords = boost::log::keywords;
namespace dcm { namespace dcm {
enum severity_level {
iteration,
solving,
manipulation,
information,
error
};
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level)
static int counter = 0; static int counter = 0;
typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t; 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() { inline boost::shared_ptr< sink_t > init_log() {

View File

@ -283,6 +283,13 @@ public:
Shedule m_sheduler; Shedule m_sheduler;
Kernel m_kernel; Kernel m_kernel;
std::vector<boost::shared_ptr<System> > m_subsystems; std::vector<boost::shared_ptr<System> > m_subsystems;
#ifdef USE_LOGGING
template<typename Expr>
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 //implementations which always need to be with the definition as they can't be externalised

View File

@ -58,12 +58,16 @@ public:
//*********************** //***********************
const Rotation& rotation() const; const Rotation& rotation() const;
template<typename Derived> template<typename Derived>
Transform& setRotation(const Eigen::RotationBase<Derived,Dim>& rotation);
template<typename Derived>
Transform& rotate(const Eigen::RotationBase<Derived,Dim>& rotation); Transform& rotate(const Eigen::RotationBase<Derived,Dim>& rotation);
const Translation& translation() const; const Translation& translation() const;
Transform& setTranslation(const Translation& translation);
Transform& translate(const Translation& translation); Transform& translate(const Translation& translation);
const Scaling& scaling() const; const Scaling& scaling() const;
Transform& setScale(const Scaling& scaling);
Transform& scale(const Scalar& scaling); Transform& scale(const Scalar& scaling);
Transform& scale(const Scaling& scaling); Transform& scale(const Scaling& scaling);

View File

@ -22,6 +22,7 @@
#include <vector> #include <vector>
#include <Eigen/StdVector> #include <Eigen/StdVector>
#include <boost/noncopyable.hpp>
#include <opendcm/core/logging.hpp> #include <opendcm/core/logging.hpp>
#include <opendcm/core/kernel.hpp> #include <opendcm/core/kernel.hpp>
#include "defines.hpp" #include "defines.hpp"
@ -44,7 +45,7 @@ enum Scalemode {
}; };
template<typename Sys> template<typename Sys>
struct ClusterMath { struct ClusterMath : public boost::noncopyable {
public: public:
typedef typename Sys::Kernel Kernel; typedef typename Sys::Kernel Kernel;
@ -91,6 +92,12 @@ public:
void initFixMaps(); void initFixMaps();
typename Kernel::Transform3D& getTransform(); 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 mapsToTransform(typename Kernel::Transform3D& trans);
void transformToMaps(typename Kernel::Transform3D& trans); void transformToMaps(typename Kernel::Transform3D& trans);

View File

@ -85,7 +85,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > {
Vector3 diff, n, dist; Vector3 diff, n, dist;
#ifdef USE_LOGGING #ifdef USE_LOGGING
src::logger log; dcm_logger log;
attrs::mutable_constant< std::string > tag; attrs::mutable_constant< std::string > tag;
type() : tag("Distance point3D line3D") { 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); Vector3 pp = line.head(3) + (line.head(3)-point.head(3)).norm()*line.template segment<3>(3);
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isnormal(pp.norm())) if(!boost::math::isnormal(pp.norm()))
BOOST_LOG(log) << "Unnormal pseudopoint detected"; BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected";
#endif #endif
v2.push_back(pp); v2.push_back(pp);
}; };
@ -114,7 +114,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > {
const Scalar res = dist.norm() - sc_value; const Scalar res = dist.norm() - sc_value;
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal residual detected: "<<res; BOOST_LOG_SEV(log, error) << "Unnormal residual detected: "<<res;
#endif #endif
return res; return res;
}; };
@ -131,7 +131,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > {
const Scalar res = dist.dot(d_dist)/dist.norm(); const Scalar res = dist.dot(d_dist)/dist.norm();
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal first cluster gradient detected: "<<res BOOST_LOG_SEV(log, error) << "Unnormal first cluster gradient detected: "<<res
<<" with point: "<<point.transpose()<<", line: "<<line.transpose() <<" with point: "<<point.transpose()<<", line: "<<line.transpose()
<<" and dpoint: "<<dpoint.transpose(); <<" and dpoint: "<<dpoint.transpose();
#endif #endif
@ -151,7 +151,7 @@ struct Distance::type< Kernel, tag::point3D, tag::line3D > {
const Scalar res = dist.dot(d_dist)/dist.norm(); const Scalar res = dist.dot(d_dist)/dist.norm();
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal second cluster gradient detected: "<<res BOOST_LOG_SEV(log, error) << "Unnormal second cluster gradient detected: "<<res
<<" with point: "<<point.transpose()<<", line: "<<line.transpose() <<" with point: "<<point.transpose()<<", line: "<<line.transpose()
<< "and dline: "<<dline.transpose(); << "and dline: "<<dline.transpose();
#endif #endif
@ -217,7 +217,7 @@ struct Distance::type< Kernel, tag::point3D, tag::plane3D > {
v2.push_back(pp); v2.push_back(pp);
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isnormal(pp.norm())) if(!boost::math::isnormal(pp.norm()))
BOOST_LOG(log) << "Unnormal pseudopoint detected"; BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected";
#endif #endif
}; };
void setScale(Scalar scale) { void setScale(Scalar scale) {
@ -239,7 +239,7 @@ struct Distance::type< Kernel, tag::point3D, tag::plane3D > {
return result + sc_value; return result + sc_value;
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(result)) if(!boost::math::isfinite(result))
BOOST_LOG(log) << "Unnormal residual detected: " << result; BOOST_LOG_SEV(log, error) << "Unnormal residual detected: " << result;
#endif #endif
return result; 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(); const Scalar res = (dparam1.head(3)).dot(param2.tail(3)) / param2.tail(3).norm();
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal first cluster gradient detected: "<<res; BOOST_LOG_SEV(log, error) << "Unnormal first cluster gradient detected: "<<res;
#endif #endif
//r = sqrt(x^2) = (x^2)^(1/2) //r = sqrt(x^2) = (x^2)^(1/2)
//r' = 1/2(x^2)^(-1/2) * (x^2)' //r' = 1/2(x^2)^(-1/2) * (x^2)'
@ -279,7 +279,7 @@ struct Distance::type< Kernel, tag::point3D, tag::plane3D > {
const Scalar res = (((-dp2).dot(n) + (p1-p2).dot(dn)) / n.norm() - (p1-p2).dot(n)* n.dot(dn)/std::pow(n.norm(),3)); 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 #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal second cluster gradient detected: "<<res; BOOST_LOG_SEV(log, error) << "Unnormal second cluster gradient detected: "<<res;
#endif #endif
if(sspace == bidirectional && result<0.) if(sspace == bidirectional && result<0.)
return -res; return -res;
@ -423,7 +423,7 @@ struct Distance::type< Kernel, tag::line3D, tag::line3D > {
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(pp1.norm()) || !boost::math::isfinite(pp2.norm())) 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 #endif
v1.push_back(pp1); v1.push_back(pp1);
@ -451,7 +451,7 @@ struct Distance::type< Kernel, tag::line3D, tag::line3D > {
const Scalar res = std::abs(cdn) / nxn.norm(); const Scalar res = std::abs(cdn) / nxn.norm();
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal residual detected: "<<res; BOOST_LOG_SEV(log, error) << "Unnormal residual detected: "<<res;
#endif #endif
return res; return res;
}; };
@ -475,7 +475,7 @@ struct Distance::type< Kernel, tag::line3D, tag::line3D > {
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(diff)) if(!boost::math::isfinite(diff))
BOOST_LOG(log) << "Unnormal first cluster gradient detected: "<<diff BOOST_LOG_SEV(log, error) << "Unnormal first cluster gradient detected: "<<diff
<<" with line1: "<<line1.transpose()<<", line2: "<<line2.transpose() <<" with line1: "<<line1.transpose()<<", line2: "<<line2.transpose()
<<" and dline1: "<<dline1.transpose(); <<" and dline1: "<<dline1.transpose();
#endif #endif
@ -501,7 +501,7 @@ struct Distance::type< Kernel, tag::line3D, tag::line3D > {
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(diff)) if(!boost::math::isfinite(diff))
BOOST_LOG(log) << "Unnormal first cluster gradient detected: "<<diff BOOST_LOG_SEV(log, error) << "Unnormal first cluster gradient detected: "<<diff
<<" with line1: "<<line1.transpose()<<", line2: "<<line2.transpose() <<" with line1: "<<line1.transpose()<<", line2: "<<line2.transpose()
<<" and dline2: "<<dline2.transpose(); <<" and dline2: "<<dline2.transpose();
#endif #endif

View File

@ -55,6 +55,7 @@ namespace modell {
a.template set<Scalar, 0>(v(0), t); a.template set<Scalar, 0>(v(0), t);
a.template set<Scalar, 1>(v(1), t); a.template set<Scalar, 1>(v(1), t);
a.template set<Scalar, 2>(v(2), t); a.template set<Scalar, 2>(v(2), t);
a.finalize(t);
}; };
}; };
@ -87,6 +88,7 @@ namespace modell {
a.template set<Scalar, 3>(v(3), t); a.template set<Scalar, 3>(v(3), t);
a.template set<Scalar, 4>(v(4), t); a.template set<Scalar, 4>(v(4), t);
a.template set<Scalar, 5>(v(5), t); a.template set<Scalar, 5>(v(5), t);
a.finalize(t);
}; };
}; };
@ -122,6 +124,7 @@ namespace modell {
a.template set<Scalar, 4>(v(4), t); a.template set<Scalar, 4>(v(4), t);
a.template set<Scalar, 5>(v(5), t); a.template set<Scalar, 5>(v(5), t);
a.template set<Scalar, 6>(v(6), t); a.template set<Scalar, 6>(v(6), t);
a.finalize(t);
}; };
}; };
@ -138,6 +141,8 @@ struct dummy_accessor {
void set(Scalar value, T& t) { void set(Scalar value, T& t) {
//TODO: throw //TODO: throw
}; };
template<typename T>
void finalize(T& t) {};
}; };
//dummy geometry traits for boost blank, wil bever be used //dummy geometry traits for boost blank, wil bever be used

View File

@ -105,6 +105,31 @@ typename ClusterMath<Sys>::Kernel::Transform3D& ClusterMath<Sys>::getTransform()
return m_transform; return m_transform;
}; };
template<typename Sys>
typename ClusterMath<Sys>::Kernel::Transform3D::Translation const& ClusterMath<Sys>::getTranslation() const {
return m_transform.translation();
};
template<typename Sys>
typename ClusterMath<Sys>::Kernel::Transform3D::Rotation const& ClusterMath<Sys>::getRotation() const {
return m_transform.rotation();
};
template<typename Sys>
void ClusterMath<Sys>::setTransform(typename ClusterMath<Sys>::Kernel::Transform3D const& t) {
m_transform = t;
};
template<typename Sys>
void ClusterMath<Sys>::setTranslation(typename ClusterMath<Sys>::Kernel::Transform3D::Translation const& t) {
m_transform.setTranslation(t);
};
template<typename Sys>
void ClusterMath<Sys>::setRotation(typename ClusterMath<Sys>::Kernel::Transform3D::Rotation const& r) {
m_transform.setRotation(r);
};
template<typename Sys> template<typename Sys>
void ClusterMath<Sys>::mapsToTransform(typename ClusterMath<Sys>::Kernel::Transform3D& trans) { void ClusterMath<Sys>::mapsToTransform(typename ClusterMath<Sys>::Kernel::Transform3D& trans) {
//add scale only after possible reset //add scale only after possible reset
@ -173,7 +198,7 @@ void ClusterMath<Sys>::resetClusterRotation(typename ClusterMath<Sys>::Kernel::T
trans = m_resetTransform.inverse()*trans; trans = m_resetTransform.inverse()*trans;
m_ssrTransform *= m_resetTransform; 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 //apply the needed transformation to all geometries local values
typedef typename std::vector<Geom>::iterator iter; typedef typename std::vector<Geom>::iterator iter;
@ -593,6 +618,12 @@ void ClusterMath<Sys>::applyClusterScale(Scalar scale, bool isFixed) {
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "sstrans scale: "<<ssTrans.scaling().factor(); BOOST_LOG(log) << "sstrans scale: "<<ssTrans.scaling().factor();
BOOST_LOG(log) << "finish transform scale: "<<m_transform.scaling().factor(); BOOST_LOG(log) << "finish transform scale: "<<m_transform.scaling().factor();
//we may want to access the scale points for debuging (I mean you, freecad assembly debug!), so
//it is important to transform them too to ensure the points are in the same coordinate system
typename Vec::iterator it;
for(it=m_points.begin(); it!=m_points.end(); it++) {
(*it) = ssTrans * (*it);
};
#endif #endif
}; };

View File

@ -80,7 +80,7 @@ template<typename Sys>
void MES<Sys>::removeLocalGradientZeros() { void MES<Sys>::removeLocalGradientZeros() {
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "remove local gradient zero"; BOOST_LOG_SEV(log, information) << "remove local gradient zero";
#endif #endif
//let the constraints treat the local zeros //let the constraints treat the local zeros
typedef typename Cluster::template object_iterator<Constraint3D> oiter; typedef typename Cluster::template object_iterator<Constraint3D> oiter;
@ -269,7 +269,7 @@ void SystemSolver<Sys>::solveCluster(boost::shared_ptr<Cluster> cluster, Sys& sy
if(params <= 0 || constraints <= 0) { if(params <= 0 || constraints <= 0) {
//TODO:throw //TODO:throw
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "Error in system counting: params = " << params << " and constraints = "<<constraints; BOOST_LOG_SEV(log, error)<< "Error in system counting: params = " << params << " and constraints = "<<constraints;
#endif #endif
return; return;
} }
@ -337,11 +337,11 @@ void SystemSolver<Sys>::solveCluster(boost::shared_ptr<Cluster> cluster, Sys& sy
} }
try { try {
//if we don't have rotations we need no expensive scaling code /* //if we don't have rotations we need no expensive scaling code
if(!mes.hasAccessType(rotation)) { if(!mes.hasAccessType(rotation)) {
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "No rotation parameters in system, solve without scaling"; BOOST_LOG_SEV(log, solving)<< "No rotation parameters in system, solve without scaling";
#endif #endif
DummyScaler re; DummyScaler re;
sys.kernel().solve(mes, re); sys.kernel().solve(mes, re);
@ -369,7 +369,7 @@ void SystemSolver<Sys>::solveCluster(boost::shared_ptr<Cluster> cluster, Sys& sy
//if(!has_cycle) { //if(!has_cycle) {
#ifdef USE_LOGGING #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 #endif
//cool, lets do uncylic. first all rotational constraints with rotational parameters //cool, lets do uncylic. first all rotational constraints with rotational parameters
mes.setAccess(rotation); mes.setAccess(rotation);
@ -404,7 +404,7 @@ void SystemSolver<Sys>::solveCluster(boost::shared_ptr<Cluster> cluster, Sys& sy
done = true; done = true;
else { else {
#ifdef USE_LOGGING #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 #endif
//let's try translation only //let's try translation only
@ -423,9 +423,9 @@ void SystemSolver<Sys>::solveCluster(boost::shared_ptr<Cluster> cluster, Sys& sy
//}; //};
//not done already? try it the hard way! //not done already? try it the hard way!
if(!done) { if(!done) {*/
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "Full scale solver used"; BOOST_LOG_SEV(log, solving)<< "Full scale solver used";
#endif #endif
mes.setAccess(complete); mes.setAccess(complete);
mes.recalculate(); mes.recalculate();
@ -434,10 +434,10 @@ void SystemSolver<Sys>::solveCluster(boost::shared_ptr<Cluster> cluster, Sys& sy
re(); re();
sys.kernel().solve(mes, re); sys.kernel().solve(mes, re);
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log)<< "Numbers of rescale: "<<re.rescales; BOOST_LOG_SEV(log, solving)<< "Numbers of rescale: "<<re.rescales;
#endif #endif
}; /* };
} }*/
//done solving, write the results back //done solving, write the results back
finish(cluster, sys, mes); finish(cluster, sys, mes);

View File

@ -28,6 +28,8 @@
#include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/phoenix.hpp>
#include <boost/phoenix/function/adapt_function.hpp> #include <boost/phoenix/function/adapt_function.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/fusion/include/adapt_adt.hpp>
#include <boost/phoenix/fusion/at.hpp> #include <boost/phoenix/fusion/at.hpp>
#include <boost/mpl/int.hpp> #include <boost/mpl/int.hpp>
#include <boost/mpl/greater.hpp> #include <boost/mpl/greater.hpp>
@ -234,6 +236,48 @@ bool VectorInput(Geom& v, Row& r, Value& val) {
return true; // output continues return true; // output continues
}; };
template <typename Translation, typename Row, typename Value>
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 <typename CM>
bool TranslationInput(CM& t, std::vector<double> const& val) {
t.setTranslation(typename CM::Kernel::Transform3D::Translation(val[0],val[1],val[2]));
return true; // output continues
};
template <typename CM, typename Row, typename Value>
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 <typename CM>
bool RotationInput(CM& t, std::vector<double> const& val) {
t.setRotation(typename CM::Kernel::Transform3D::Rotation(val[3], val[0], val[1], val[2]));
return true; // output continues
};
template<typename Geom> template<typename Geom>
struct inject_set { 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_out, dcm::details::VectorOutput, 3)
BOOST_PHOENIX_ADAPT_FUNCTION(bool, vector_in, dcm::details::VectorInput, 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_PHOENIX_ADAPT_FUNCTION(bool, create, dcm::details::Create, 4)
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(
@ -331,6 +377,14 @@ void parser_generator< typename details::getModule3D<System>::type::vertex_prop
r = karma::lit("<type>Vertex</type>") r = karma::lit("<type>Vertex</type>")
<< karma::eol << "<value>" << karma::int_ << "</value>"; << karma::eol << "<value>" << karma::int_ << "</value>";
}; };
/*
template<typename System, typename iterator>
void parser_generator< typename details::getModule3D<System>::type::math_prop , System, iterator >::init(generator& r) {
r = karma::lit("<type>Math3D</type>")
<< karma::eol << "<Translation>" << (details::scientific[ boost::spirit::_pass = translation_out(karma::_val, karma::_a, karma::_1) ] % ' ') << "</Translation>"
<< karma::eol << karma::eps[karma::_a = 0] << "<Rotation>" << (details::scientific[ boost::spirit::_pass = rotation_out(karma::_val, karma::_a, karma::_1) ] % ' ') << "</Rotation>";
};*/
template<typename System, typename iterator> template<typename System, typename iterator>
void parser_generator< typename details::getModule3D<System>::type::Constraint3D , System, iterator >::init(generator& r) { void parser_generator< typename details::getModule3D<System>::type::Constraint3D , System, iterator >::init(generator& r) {
@ -373,6 +427,13 @@ void parser_parser< typename details::getModule3D<System>::type::vertex_prop, Sy
r %= qi::lit("<type>Vertex</type>") >> "<value>" >> qi::int_ >> "</value>"; r %= qi::lit("<type>Vertex</type>") >> "<value>" >> qi::int_ >> "</value>";
}; };
/*
template<typename System, typename iterator>
void parser_parser< typename details::getModule3D<System>::type::math_prop, System, iterator >::init(parser& r) {
//r = qi::lit("<type>Math3D</type>") >> "<Translation>" >> (*qi::double_)[ phx::bind(&details::TranslationInput<details::ClusterMath<System> >, qi::_val, qi::_1) ] >> "</Translation>"
// >> "<Rotation>" >> (*qi::double_)[ phx::bind(&details::RotationInput<details::ClusterMath<System> >,qi::_val, qi::_1) ] >> "</Rotation>";
};*/
template<typename System, typename iterator> template<typename System, typename iterator>
void parser_parser< typename details::getModule3D<System>::type::Constraint3D, System, iterator >::init(parser& r) { void parser_parser< typename details::getModule3D<System>::type::Constraint3D, System, iterator >::init(parser& r) {

View File

@ -46,7 +46,7 @@ struct MES : public Sys::Kernel::MappedEquationSystem {
boost::shared_ptr<Cluster> m_cluster; boost::shared_ptr<Cluster> m_cluster;
#ifdef USE_LOGGING #ifdef USE_LOGGING
src::logger log; dcm_logger log;
#endif #endif
MES(boost::shared_ptr<Cluster> cl, int par, int eqn); MES(boost::shared_ptr<Cluster> cl, int par, int eqn);

View File

@ -63,6 +63,17 @@ struct parser_generator< typename details::getModule3D<System>::type::vertex_pro
typedef karma::rule<iterator, GlobalVertex()> generator; typedef karma::rule<iterator, GlobalVertex()> generator;
static void init(generator& r); static void init(generator& r);
}; };
/*
template<typename System>
struct parser_generate< typename details::getModule3D<System>::type::math_prop , System>
: public mpl::true_ {};
template<typename System, typename iterator>
struct parser_generator< typename details::getModule3D<System>::type::math_prop , System, iterator > {
typedef karma::rule<iterator, details::ClusterMath<System>&(), karma::locals<int> > generator;
static void init(generator& r);
};*/
template<typename System> template<typename System>
struct parser_generate< typename details::getModule3D<System>::type::Constraint3D , System> struct parser_generate< typename details::getModule3D<System>::type::Constraint3D , System>
@ -127,7 +138,17 @@ struct parser_parser< typename details::getModule3D<System>::type::vertex_prop,
typedef qi::rule<iterator, GlobalVertex(), qi::space_type> parser; typedef qi::rule<iterator, GlobalVertex(), qi::space_type> parser;
static void init(parser& r); static void init(parser& r);
}; };
/*
template<typename System>
struct parser_parse< typename details::getModule3D<System>::type::math_prop, System>
: public mpl::true_ {};
template<typename System, typename iterator>
struct parser_parser< typename details::getModule3D<System>::type::math_prop, System, iterator > {
typedef qi::rule<iterator, details::ClusterMath<System>(), qi::space_type > parser;
static void init(parser& r);
};*/
template<typename System> template<typename System>
struct parser_parse< typename details::getModule3D<System>::type::Constraint3D , System> struct parser_parse< typename details::getModule3D<System>::type::Constraint3D , System>

View File

@ -58,7 +58,7 @@ struct ModulePart {
protected: protected:
#ifdef USE_LOGGING #ifdef USE_LOGGING
src::logger log; dcm_logger log;
#endif #endif
//check if we have module3d in this system //check if we have module3d in this system
@ -299,7 +299,7 @@ ModulePart<Typelist, ID>::type<Sys>::Part_base::Part_base(const T& geometry, Sys
m_cluster->template getProperty<typename module3d::math_prop>().getTransform() = m_transform; m_cluster->template getProperty<typename module3d::math_prop>().getTransform() = m_transform;
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "Init: "<<m_transform; BOOST_LOG_SEV(log, information) << "Init: "<<m_transform;
#endif #endif
}; };
@ -419,7 +419,7 @@ void ModulePart<Typelist, ID>::type<Sys>::Part_base::finishCalculation() {
apply(vis); apply(vis);
#ifdef USE_LOGGING #ifdef USE_LOGGING
BOOST_LOG(log) << "New Value: "<<m_transform; BOOST_LOG_SEV(log, manipulation) << "New Value: "<<m_transform;
#endif #endif
//emit the signal for new values //emit the signal for new values

View File

@ -41,7 +41,7 @@ struct Distance::type< Kernel, tag::point3D, tag::segment3D > {
Vector3 v01, v02, v12, cross; Vector3 v01, v02, v12, cross;
#ifdef USE_LOGGING #ifdef USE_LOGGING
src::logger log; dcm_logger log;
attrs::mutable_constant< std::string > tag; attrs::mutable_constant< std::string > tag;
type() : tag("Distance point3D segment3D") { 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; Vector3 pp = segment.head(3) + (segment.head(3)-point.head(3)).norm()*dir;
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isnormal(pp.norm())) if(!boost::math::isnormal(pp.norm()))
BOOST_LOG(log) << "Unnormal pseudopoint detected"; BOOST_LOG_SEV(log, error) << "Unnormal pseudopoint detected";
#endif #endif
v2.push_back(pp); 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; const Scalar res = cross.norm()/v12_n - sc_value;
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal residual detected: "<<res; BOOST_LOG_SEV(log, error) << "Unnormal residual detected: "<<res;
#endif #endif
return res; return res;
}; };
@ -92,7 +92,7 @@ struct Distance::type< Kernel, tag::point3D, tag::segment3D > {
const Scalar res = cross.dot(d_cross)/(cross_n*v12_n); const Scalar res = cross.dot(d_cross)/(cross_n*v12_n);
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal first cluster gradient detected: "<<res BOOST_LOG_SEV(log, error) << "Unnormal first cluster gradient detected: "<<res
<<" with point: "<<point.transpose()<<", segment: "<<segment.transpose() <<" with point: "<<point.transpose()<<", segment: "<<segment.transpose()
<<" and dpoint: "<<dpoint.transpose(); <<" and dpoint: "<<dpoint.transpose();
#endif #endif
@ -109,7 +109,7 @@ struct Distance::type< Kernel, tag::point3D, tag::segment3D > {
const Scalar res = cross.dot(d_cross)/(cross_n*v12_n) - v12.dot(d_v12)*cross_v12_n; const Scalar res = cross.dot(d_cross)/(cross_n*v12_n) - v12.dot(d_v12)*cross_v12_n;
#ifdef USE_LOGGING #ifdef USE_LOGGING
if(!boost::math::isfinite(res)) if(!boost::math::isfinite(res))
BOOST_LOG(log) << "Unnormal second cluster gradient detected: "<<res BOOST_LOG_SEV(log, error) << "Unnormal second cluster gradient detected: "<<res
<<" with point: "<<point.transpose()<<", segment: "<<segment.transpose() <<" with point: "<<point.transpose()<<", segment: "<<segment.transpose()
<< "and dsegment: "<<dsegment.transpose(); << "and dsegment: "<<dsegment.transpose();
#endif #endif

View File

@ -66,7 +66,7 @@ prop_parser<PropList, Prop, Par>::prop_parser() : prop_parser<PropList, Prop, Pa
typedef typename mpl::find<PropList, Prop>::type::pos pos; typedef typename mpl::find<PropList, Prop>::type::pos pos;
Par::init(subrule); Par::init(subrule);
start = qi::lit("<Property>") >> subrule[phx::at_c<pos::value>(*qi::_r1) = qi::_1] >> qi::lit("</Property>"); //start = qi::lit("<Property>") >> subrule[phx::at_c<pos::value>(*qi::_r1) = qi::_1] >> qi::lit("</Property>");
}; };
template<typename Sys, typename PropertyList> template<typename Sys, typename PropertyList>

View File

@ -116,7 +116,7 @@
<string>Angle</string> <string>Angle</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintAngle.svg</normaloff>:/icons/constraints/Assembly_ConstraintAngle.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintAngle.svg</normaloff>:/icons/constraints/Assembly_ConstraintAngle.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -157,7 +157,7 @@
<string>Coincident</string> <string>Coincident</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintCoincidence.svg</normaloff>:/icons/constraints/Assembly_ConstraintCoincidence.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintCoincidence.svg</normaloff>:/icons/constraints/Assembly_ConstraintCoincidence.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -198,7 +198,7 @@
<string>Fix</string> <string>Fix</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintLock.svg</normaloff>:/icons/constraints/Assembly_ConstraintLock.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintLock.svg</normaloff>:/icons/constraints/Assembly_ConstraintLock.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -239,7 +239,7 @@
<string>Distance</string> <string>Distance</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintDistance.svg</normaloff>:/icons/constraints/Assembly_ConstraintDistance.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintDistance.svg</normaloff>:/icons/constraints/Assembly_ConstraintDistance.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -280,7 +280,7 @@
<string>Orientation</string> <string>Orientation</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintOrientation.svg</normaloff>:/icons/constraints/Assembly_ConstraintOrientation.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintOrientation.svg</normaloff>:/icons/constraints/Assembly_ConstraintOrientation.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -321,7 +321,7 @@
<string>Align</string> <string>Align</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintAlignment.svg</normaloff>:/icons/constraints/Assembly_ConstraintAlignment.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintAlignment.svg</normaloff>:/icons/constraints/Assembly_ConstraintAlignment.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -422,6 +422,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="maximum"> <property name="maximum">
<double>999999.000000000000000</double> <double>999999.000000000000000</double>
</property> </property>
@ -436,7 +439,7 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintBidirectional.svg</normaloff>:/icons/constraints/Assembly_ConstraintBidirectional.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintBidirectional.svg</normaloff>:/icons/constraints/Assembly_ConstraintBidirectional.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -474,8 +477,8 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional2.svg</normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional2.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional1.svg</normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional1.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -509,8 +512,8 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional1.svg</normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional1.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional2.svg</normaloff>:/icons/constraints/Assembly_ConstraintUnidirectional2.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -566,7 +569,7 @@
<string>Parallel</string> <string>Parallel</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintParallel.svg</normaloff>:/icons/constraints/Assembly_ConstraintParallel.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintParallel.svg</normaloff>:/icons/constraints/Assembly_ConstraintParallel.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -604,7 +607,7 @@
<string>Equal</string> <string>Equal</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintEqual.svg</normaloff>:/icons/constraints/Assembly_ConstraintEqual.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintEqual.svg</normaloff>:/icons/constraints/Assembly_ConstraintEqual.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -645,7 +648,7 @@
<string>Opposite</string> <string>Opposite</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintOpposite.svg</normaloff>:/icons/constraints/Assembly_ConstraintOpposite.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintOpposite.svg</normaloff>:/icons/constraints/Assembly_ConstraintOpposite.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -686,7 +689,7 @@
<string>Perpend.</string> <string>Perpend.</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset> <iconset resource="Resources/Assembly.qrc">
<normaloff>:/icons/constraints/Assembly_ConstraintPerpendicular.svg</normaloff>:/icons/constraints/Assembly_ConstraintPerpendicular.svg</iconset> <normaloff>:/icons/constraints/Assembly_ConstraintPerpendicular.svg</normaloff>:/icons/constraints/Assembly_ConstraintPerpendicular.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -729,6 +732,7 @@
</widget> </widget>
<resources> <resources>
<include location="../../../Gui/Icons/resource.qrc"/> <include location="../../../Gui/Icons/resource.qrc"/>
<include location="Resources/Assembly.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>

View File

@ -25,20 +25,35 @@
#ifndef _PreComp_ #ifndef _PreComp_
# include <Inventor/nodes/SoGroup.h> # include <Inventor/nodes/SoGroup.h>
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/nodes/SoSwitch.h>
#include <Inventor/nodes/SoDrawStyle.h>
#endif #endif
#include "ViewProviderPart.h" #include "ViewProviderPart.h"
//#include <Gui/Command.h> //#include <Gui/Command.h>
//#include <Gui/Document.h> //#include <Gui/Document.h>
#include <Mod/Assembly/App/ItemPart.h> #include <Mod/Assembly/App/ItemPart.h>
#include <Base/Console.h>
using namespace AssemblyGui; 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) PROPERTY_SOURCE(AssemblyGui::ViewProviderItemPart,AssemblyGui::ViewProviderItem)
ViewProviderItemPart::ViewProviderItemPart() 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() ViewProviderItemPart::~ViewProviderItemPart()
@ -50,22 +65,46 @@ bool ViewProviderItemPart::doubleClicked(void)
return true; return true;
} }
void ViewProviderItemPart::attach(App::DocumentObject *pcFeat) void ViewProviderItemPart::attach(App::DocumentObject* pcFeat)
{ {
// call parent attach method // call parent attach method
ViewProviderGeometryObject::attach(pcFeat); ViewProviderGeometryObject::attach(pcFeat);
// putting all together with the switch // putting all together with the switch
addDisplayMaskMode(getChildRoot(), "Main"); 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) void ViewProviderItemPart::setDisplayMode(const char* ModeName)
{ {
if ( strcmp("Main",ModeName)==0 ) if(strcmp("Main",ModeName)==0)
setDisplayMaskMode("Main"); setDisplayMaskMode("Main");
ViewProviderGeometryObject::setDisplayMode( ModeName ); ViewProviderGeometryObject::setDisplayMode(ModeName);
} }
std::vector<std::string> ViewProviderItemPart::getDisplayModes(void) const std::vector<std::string> ViewProviderItemPart::getDisplayModes(void) const
@ -83,9 +122,10 @@ std::vector<App::DocumentObject*> ViewProviderItemPart::claimChildren(void)const
{ {
std::vector<App::DocumentObject*> res; std::vector<App::DocumentObject*> res;
res.insert( res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end()); res.insert(res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue()) if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue())
res.push_back( static_cast<Assembly::ItemPart*>(getObject())->Model.getValue()); res.push_back(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue());
return res; return res;
@ -95,10 +135,104 @@ std::vector<App::DocumentObject*> ViewProviderItemPart::claimChildren3D(void)con
{ {
std::vector<App::DocumentObject*> res; std::vector<App::DocumentObject*> res;
res.insert( res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end()); res.insert(res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue()) if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue())
res.push_back( static_cast<Assembly::ItemPart*>(getObject())->Model.getValue()); res.push_back(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue());
return res; 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<Part3D> part = static_cast<Assembly::ItemPart*>(getObject())->m_part;
if(!part) {
ViewProviderItem::onChanged(prop);
return;
}
dcm::detail::Transform<double,3> transform = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_transform;
dcm::detail::Transform<double,3> ssrTransform = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_ssrTransform;
dcm::detail::Transform<double,3> trans = ssrTransform.inverse();
int PseudoSize = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_pseudo.size();
typedef dcm::details::ClusterMath<Solver>::Vec Vector;
Vector& pv = part->m_cluster->getProperty<Module3D::type<Solver>::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<Geometry3D> g = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_geometry[0];
std::stringstream str;
str<<"Global: "<<g->m_global.transpose()<<std::endl;
str<<"Global TLPoint: "<<(trans * g->getPoint()).transpose()<<std::endl;
Kernel::Vector3 v = g->m_global.head(3);
str<<"Local Point : "<<(transform.inverse()*v).transpose()<<std::endl;
str<<"Local TLPoint: "<<(ssrTransform.inverse()*g->getPoint()).transpose()<<std::endl;
str<<"PVPoint : "<<(pv[0]).transpose()<<std::endl;
str<<"Local PVPoint: "<<(ssrTransform.inverse()*pv[0]).transpose()<<std::endl;
Base::Console().Message(str.str().c_str());
}
else {
m_switch->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

View File

@ -25,6 +25,11 @@
#define ASSEMBLYGUI_ViewProviderPart_H #define ASSEMBLYGUI_ViewProviderPart_H
#include "ViewProvider.h" #include "ViewProvider.h"
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/nodes/SoMarkerSet.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoSwitch.h>
namespace AssemblyGui { namespace AssemblyGui {
@ -50,6 +55,17 @@ public:
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const; virtual std::vector<App::DocumentObject*> 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
}; };