/* 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 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. */ #ifndef DCM_CLUSTERMATH_H #define DCM_CLUSTERMATH_H #include #include #include #include #include #include "defines.hpp" #define MAXFAKTOR 1.2 //the maximal distance allowed by a point normed to the cluster size #define MINFAKTOR 0.8 //the minimal distance allowed by a point normed to the cluster size #define SKALEFAKTOR 1. //the faktor by which the biggest size is multiplied to get the scale value #define NQFAKTOR 0.5 //the faktor by which the norm quaternion is multiplied with to get the RealScalar //norm quaternion to generate the unit quaternion namespace dcm { namespace details { enum Scalemode { one, two, three, multiple_inrange, multiple_outrange }; template struct ClusterMath : public boost::noncopyable { public: typedef typename Sys::Kernel Kernel; typedef typename Sys::Cluster Cluster; typedef typename system_traits::template getModule::type module3d; typedef typename module3d::Geometry3D Geometry3D; typedef std::shared_ptr Geom; typedef typename module3d::math_prop math_prop; typedef typename module3d::fix_prop fix_prop; typedef typename Kernel::number_type Scalar; typename Kernel::Transform3D m_transform, m_ssrTransform, m_resetTransform; typename Kernel::DiffTransform3D m_diffTrans; typename Kernel::Vector3Map m_normQ; typename Kernel::Quaternion m_resetQuaternion; int m_offset, m_offset_rot; bool init, fix; std::vector m_geometry; typename Kernel::Vector3Map m_translation; //shift scale stuff typename Kernel::Vector3 midpoint, m_shift, scale_dir, maxm, minm, max, fixtrans; Scalemode mode; Scalar m_scale; typedef std::vector > Vec; Vec m_points, m_pseudo; #ifdef USE_LOGGING src::logger log; #endif public: ClusterMath(); void setParameterOffset(int offset, AccessType t); int getParameterOffset(AccessType t); typename Kernel::Vector3Map& getNormQuaternionMap(); typename Kernel::Vector3Map& getTranslationMap(); void initMaps(); 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); void finishCalculation(); void finishFixCalculation(); void resetClusterRotation(typename Kernel::Transform3D& trans); void calcDiffTransform(typename Kernel::DiffTransform3D& trans); void recalculate(); void addGeometry(Geom g); void clearGeometry(); std::vector& getGeometry(); struct map_downstream { details::ClusterMath& m_clusterMath; typename Kernel::Transform3D m_transform; bool m_isFixed; map_downstream(details::ClusterMath& cm, bool fix); void operator()(Geom g); void operator()(std::shared_ptr c); }; void mapClusterDownstreamGeometry(std::shared_ptr cluster); //Calculate the scale of the cluster. Therefore the midpoint is calculated and the scale is // defined as the max distance between the midpoint and the points. Scalar calculateClusterScale(); void applyClusterScale(Scalar scale, bool isFixed); private: Scalar calcOnePoint(const typename Kernel::Vector3& p); Scalar calcTwoPoints(const typename Kernel::Vector3& p1, const typename Kernel::Vector3& p2); Scalar calcThreePoints(const typename Kernel::Vector3& p1, const typename Kernel::Vector3& p2, const typename Kernel::Vector3& p3); public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; }//details }//dcm #ifndef DCM_EXTERNAL_3D #include "imp/clustermath_imp.hpp" #endif #endif //GCM_CLUSTERMATH_H