<commit_before>#ifndef __GF2_PLANEPRIMITIVE_H__
#define __GF2_PLANEPRIMITIVE_H__

#include <Eigen/Dense>
#include "globfit2/primitives/primitive.h"
//#include "pcltools/util.hpp"
#include "globfit2/processing/util.hpp" // pca

#ifdef GF2_USE_PCL
#   include "pcl/ModelCoefficients.h"
#   include "pcl/sample_consensus/sac_model_plane.h"
#   include "pcl/common/common.h"
#   include "pcl/visualization/pcl_visualizer.h"
#endif

namespace GF2
{
    //! \brief   Class to wrap a plane with. Implements #pos() and #dir() functions, and a constructor taking a position and a direction.
    //!
    //!          Stores 3D normal at the first three coeffs, and distance from origin at the fourth coordinate.
    class PlanePrimitive : public ::GF2::Primitive<4>, public ::GF2::Taggable
    {
            typedef ::GF2::Primitive<4> ParentT;
        public:
            //! \brief Defines the tags (ids) that this primitive can manage using setTag and getTag functions.
            enum TAGS {
                GID        = 0  //!< group id             - which group this primitive is supposed to explain
                , DIR_GID  = 1  //!< direction group id   - which group this primitive got it's direction from
                , CHOSEN   = 2  //!< an additional flag to store, if this is part of a solution.
                , USER_ID1 = 10 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID2 = 11 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID3 = 12 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID4 = 13 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID5 = 14 //!< additional flag to store processing attributes (values only in the generation scope)
            };//...TAGS

            typedef ParentT::Scalar Scalar;

            //! \brief Inherited constructor from Primitive.
            // using ::GF2::Primitive<4>::Primitive;

            // ____________________CONSTRUCT____________________

            PlanePrimitive() : ParentT() {}

            //! \brief Constructor that takes raw data in Eigen format as input.
            PlanePrimitive( Eigen::Matrix<Scalar,Dim,1> coeffs ) : ParentT( coeffs ) {}

            //! \brief Constructor that takes raw data in std::vector format as input.
            PlanePrimitive( std::vector<Scalar> const& coeffs ) : ParentT( coeffs ) {}

            //! \brief           Creates PlanePrimitive from point on plane and direction.
            //! \param[in] p0    Point on plane.
            //! \param[in] dir   Plane normal.
            PlanePrimitive( Eigen::Matrix<Scalar,3,1> pnt, Eigen::Matrix<Scalar,3,1> normal );

            // ____________________VIRTUALS____________________
            //! \brief  Compulsory virtual overload of position getter. The position of the plane is calculated on the fly from the formula N . x0 + d = 0.
            //! \return The position of the plane as a 3D Eigen::Vector.
            virtual Eigen::Matrix<Scalar,3,1> pos() const { return _coeffs.head<3>() * (-1.f*_coeffs(3)); }
            //! \brief  Compulsory virtual overload of orientation getter. The orientation of the plane is the normal stored at the first three coordinates of #_coeffs.
            //! \return The normal of the plane as a 3D Eigen::Vector.
            virtual Eigen::Matrix<Scalar,3,1> dir() const { return _coeffs.head<3>()                    ; }

            //! \brief  Returns the normal, that is stored at the first three coordinates of the internal storage.
            //! \return The plane normal as a 3D Eigen::Vector Map.
            inline Eigen::Map<const Eigen::Matrix<Scalar,3,1> > normal() const { return Eigen::Map<const Eigen::Matrix<Scalar,3,1>>(_coeffs.data()); }

            //! \brief              Returns point to plane distance.
            //! \param[in] point    Point to calculate distance from.
            //! \return             Distance from point to plane.
            inline Scalar
            getDistance( Eigen::Matrix<Scalar,3,1> const& point ) const
            {
                // verified, this works well:
                // n . x + d = 0
                return this->dir().dot(point) + this->_coeffs(3);
            }

            inline Eigen::Matrix<Scalar,3,1>
            projectPoint( Eigen::Matrix<Scalar,3,1> const& point ) const
            {
                // verified, this works well:
                return point - (this->getDistance(point) * this->dir() );
            } // projectPoint

            /*! \brief                          Calculates the length of the plane based on the points in \p cloud, masked by \p indices and the distance from point to plane \p threshold.
             *
             *                                  The method calculates the inliers and selects the most far away point from #pos() in both directions.
             *  \tparam     _PointT             Point wrapper stored in _PointContainerT.<commit_msg>Fix wrong return type in normal()<commit_after>#ifndef __GF2_PLANEPRIMITIVE_H__
#define __GF2_PLANEPRIMITIVE_H__

#include <Eigen/Dense>
#include "globfit2/primitives/primitive.h"
//#include "pcltools/util.hpp"
#include "globfit2/processing/util.hpp" // pca

#ifdef GF2_USE_PCL
#   include "pcl/ModelCoefficients.h"
#   include "pcl/sample_consensus/sac_model_plane.h"
#   include "pcl/common/common.h"
#   include "pcl/visualization/pcl_visualizer.h"
#endif

namespace GF2
{
    //! \brief   Class to wrap a plane with. Implements #pos() and #dir() functions, and a constructor taking a position and a direction.
    //!
    //!          Stores 3D normal at the first three coeffs, and distance from origin at the fourth coordinate.
    class PlanePrimitive : public ::GF2::Primitive<4>, public ::GF2::Taggable
    {
            typedef ::GF2::Primitive<4> ParentT;
        public:
            //! \brief Defines the tags (ids) that this primitive can manage using setTag and getTag functions.
            enum TAGS {
                GID        = 0  //!< group id             - which group this primitive is supposed to explain
                , DIR_GID  = 1  //!< direction group id   - which group this primitive got it's direction from
                , CHOSEN   = 2  //!< an additional flag to store, if this is part of a solution.
                , USER_ID1 = 10 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID2 = 11 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID3 = 12 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID4 = 13 //!< additional flag to store processing attributes (values only in the generation scope)
                , USER_ID5 = 14 //!< additional flag to store processing attributes (values only in the generation scope)
            };//...TAGS

            typedef ParentT::Scalar Scalar;

            //! \brief Inherited constructor from Primitive.
            // using ::GF2::Primitive<4>::Primitive;

            // ____________________CONSTRUCT____________________

            PlanePrimitive() : ParentT() {}

            //! \brief Constructor that takes raw data in Eigen format as input.
            PlanePrimitive( Eigen::Matrix<Scalar,Dim,1> coeffs ) : ParentT( coeffs ) {}

            //! \brief Constructor that takes raw data in std::vector format as input.
            PlanePrimitive( std::vector<Scalar> const& coeffs ) : ParentT( coeffs ) {}

            //! \brief           Creates PlanePrimitive from point on plane and direction.
            //! \param[in] p0    Point on plane.
            //! \param[in] dir   Plane normal.
            PlanePrimitive( Eigen::Matrix<Scalar,3,1> pnt, Eigen::Matrix<Scalar,3,1> normal );

            // ____________________VIRTUALS____________________
            //! \brief  Compulsory virtual overload of position getter. The position of the plane is calculated on the fly from the formula N . x0 + d = 0.
            //! \return The position of the plane as a 3D Eigen::Vector.
            virtual Eigen::Matrix<Scalar,3,1> pos() const { return _coeffs.head<3>() * (-1.f*_coeffs(3)); }
            //! \brief  Compulsory virtual overload of orientation getter. The orientation of the plane is the normal stored at the first three coordinates of #_coeffs.
            //! \return The normal of the plane as a 3D Eigen::Vector.
            virtual Eigen::Matrix<Scalar,3,1> dir() const { return _coeffs.head<3>()                    ; }

            //! \brief  Returns the normal, that is stored at the first three coordinates of the internal storage.
            //! \return The plane normal as a 3D Eigen::Vector Map.
            inline Eigen::Matrix<Scalar,4,1>::ConstFixedSegmentReturnType<3>::Type normal() const { return _coeffs.head<3>(); }

            //! \brief              Returns point to plane distance.
            //! \param[in] point    Point to calculate distance from.
            //! \return             Distance from point to plane.
            inline Scalar
            getDistance( Eigen::Matrix<Scalar,3,1> const& point ) const
            {
                // verified, this works well:
                // n . x + d = 0
                return this->dir().dot(point) + this->_coeffs(3);
            }

            inline Eigen::Matrix<Scalar,3,1>
            projectPoint( Eigen::Matrix<Scalar,3,1> const& point ) const
            {
                // verified, this works well:
                return point - (this->getDistance(point) * this->dir() );
            } // projectPoint

            /*! \brief                          Calculates the length of the plane based on the points in \p cloud, masked by \p indices and the distance from point to plane \p threshold.
             *
             *                                  The method calculates the inliers and selects the most far away point from #pos() in both directions.
             *  \tparam     _PointT             Point wrapper stored in _PointContainerT.
{'fraction_non_alphanumeric': 0.09559038255621533, 'fraction_numerical': 0.012265161101917648, 'mean_word_length': 2.0369494531480936, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2008394', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2639, 'n_words': 976}