Boost logo

Boost Users :

From: Olivier Tournaire (olitour_at_[hidden])
Date: 2007-05-09 18:05:42


OK. Here is the incriminated part of the main :

void Main_MPP( void )
{
    boost::shared_ptr<OGRRectangle> rect( new OGRRectangle(5.,TPoint2D
<double>(50.,20.),0.1325) );
    boost::shared_ptr< rectangle_with_profile<OGRRectangle> > r( new
rectangle_with_profile<OGRRectangle> ( rect , 5 , 12 , 1.5 , EXTREME) );
    //OGRRectangle destructor is call here ...
    r->DisplayConsole();
}

Here is the OGRRectangle class :

class OGRRectangle : public OGRPolygon
{
public:
    OGRRectangle() {};
    OGRRectangle( const double &width , const TPoint2D <double> &center ,
const double &angle=0. );
    OGRRectangle( const TPoint2D <double> &center , const double &width ,
const double &height , const double &angle=0. );
    OGRRectangle( const TPoint2D <double> &TopLeft , const TPoint2D <double>
&BottomRight , const double &angle=0. );
    ~OGRRectangle() {SORTIEMESSAGE("Destruction OGRRectangle
..."<<std::endl);};

    void Init( const TPoint2D <double> &center , const double &width , const
double &height , const double &angle=0. );

    inline void GetWidth( double &width ) {width=m_width;}
    inline double GetWidth() {return m_width;}
    inline void GetHeight( double &height ) {height=m_height;}
    inline double GetHeight() {return m_height;}

    void Translate( const TPoint2D <double> &trans );
    void Translate( const double &x , const double &y );
    void Rotate( const double &angle );

protected:
    double m_width;
    double m_height;
    double m_angle;
};

// Implementation

void OGRRectangle::Init( const TPoint2D <double> &center , const double
&width , const double &height , const double &angle )
{
    m_width = width;
    m_height = height;
    m_angle = angle;

    boost::shared_ptr<OGRPoint> pt( new OGRPoint );
    boost::shared_ptr< OGRLinearRing > lr( new OGRLinearRing );

    pt->setCoordinateDimension(2);
    pt->setX( center.x-0.5*width );
    pt->setY( center.y-0.5*height );
    pt->setZ( 0. );
    lr->addPoint( pt.get() );
    pt->setX( center.x+0.5*width );
    pt->setY( center.y-0.5*height );
    lr->addPoint( pt.get() );
    pt->setX( center.x+0.5*width );
    pt->setY( center.y+0.5*height );
    lr->addPoint( pt.get() );
    pt->setX( center.x-0.5*width );
    pt->setY( center.y+0.5*height );
    lr->addPoint( pt.get() );
    this->addRing( lr.get() );
    lr->setCoordinateDimension(2);
    this->setCoordinateDimension(2);

    this->closeRings();

    if ( m_angle != 0. )
        Rotate(m_angle);
}

OGRRectangle::OGRRectangle( const double &width , const TPoint2D <double>
&center , const double &angle )
{
    Init(center,width,width,angle);
    setCoordinateDimension(2);
}

OGRRectangle::OGRRectangle( const TPoint2D <double> &center , const double
&width , const double &height , const double &angle)
{
    Init(center,width,height,angle);
    setCoordinateDimension(2);
}

OGRRectangle::OGRRectangle( const TPoint2D <double> &TopLeft , const
TPoint2D <double> &BottomRight , const double &angle)

{
    double width = abs(BottomRight.x - TopLeft.x);
    double height = abs(BottomRight.y - TopLeft.y);
    Init(0.5*(TopLeft+BottomRight),width,height,angle);
    setCoordinateDimension(2);
}

// rectangle_with_profile

template <class Rect_class> class rectangle_with_profile
{
    friend class profile;
public:
    rectangle_with_profile() {};
    rectangle_with_profile( boost::shared_ptr<Rect_class> rect , const
unsigned int &nb_profiles , const unsigned int &nb_points , const double
&distance , const eProfilePosition &position=CENTER );
    ~rectangle_with_profile() {};

    inline void SetRectangle( boost::shared_ptr<Rect_class> rect )
{m_rectangle = rect;}
    inline boost::shared_ptr<Rect_class> GetRectangle() {return
m_rectangle;}
    void SetProfiles( const std::vector< boost::shared_ptr<
profile<Rect_class> > > &profiles ) {m_profiles=profiles;}
    void AddProfile( const TPoint2D <double> &first , const unsigned int
&nb_points , const double &distance );
    void AddProfile( const TPoint2D <double> &first , const TPoint2D
<double> &last , const unsigned int &nb_points );
    inline void GetProfiles( std::vector< boost::shared_ptr<
profile<Rect_class> > > &profiles ) {profiles=m_profiles;}
    inline std::vector< boost::shared_ptr< profile<Rect_class> > >
GetProfiles() {return m_profiles;}
    void GetProfile( boost::shared_ptr< profile<Rect_class> > &profiles ,
const unsigned int &i );
    boost::shared_ptr< profile<Rect_class> > GetProfile(const unsigned int
&i);

    void DrawShape( IdCalqueVecteur &layer , const bool &summits=true ,
const bool &edges=true , const bool &center=false , const bool
&profiles=true );
    void DrawAttributes( IdCalqueVecteur &layer , const bool &angle=true ,
const bool &width=true , const bool &height=true );
    void DisplayConsole();

    void Translate( const TPoint2D <double> &trans );
    void Translate( const double &x , const double &y );
    void Rotate( const double &angle );

private:
    std::vector< boost::shared_ptr< profile<Rect_class> > > m_profiles;
    boost::shared_ptr<Rect_class> m_rectangle;
};

// its constructor

template <class Rect_class>
rectangle_with_profile<Rect_class>::rectangle_with_profile(
boost::shared_ptr<Rect_class> rect , const unsigned int &nb_profiles , const
unsigned int &nb_points , const double &distance , const eProfilePosition
&position=CENTER ) : m_rectangle(rect)
{
    m_rectangle = rect;
    TPoint2D <double> h_direction, w_direction, profile_center;
    if ( typeid(m_rectangle.get()) == typeid(rectangle*) )
    {
        boost::shared_ptr<rectangle> rect( (rectangle*)(m_rectangle.get())
);
        h_direction = rect->GetRectangle()[1] - rect->GetRectangle()[0];
        w_direction = rect->GetRectangle()[1] - rect->GetRectangle()[2];
        profile_center.setx( 0.5 * ( rect->GetRectangle()[0].x +
rect->GetRectangle()[3].x ) );
        profile_center.sety( 0.5 * ( rect->GetRectangle()[0].y +
rect->GetRectangle()[3].y ) );
        TPoint2D <double> normalized_h_direction = h_direction;
        TPoint2D <double> normalized_w_direction = w_direction;
        normalized_h_direction.normaliser();
        normalized_w_direction.normaliser();

        unsigned int i;
        switch( position )
        {
        case CENTER:
            {
                double length_inter = h_direction.norme() /
(double)(nb_profiles+1);
                for (i=1;i<=nb_profiles;i++)
                {
                    // Point central du profil
                    profile_center = profile_center + ( (double)i *
length_inter * normalized_h_direction );
                    TPoint2D <double> first;
                    first.x = profile_center.x + (int)(0.5*nb_points) *
distance * normalized_w_direction.x;
                    first.y = profile_center.y + (int)(0.5*nb_points) *
distance * normalized_w_direction.y;
                    AddProfile(first,nb_points,distance);
                }
            }
            break;
        case EXTREME:
            {
                double length_inter = h_direction.norme() /
(double)(nb_profiles-1);
                for (i=0;i<nb_profiles;i++)
                {
                    // Point central du profil
                    boost::shared_ptr<rectangle> rect(
reinterpret_cast<rectangle*>(m_rectangle.get()) );
                    TPoint2D <double> profile_center( 0.5 * (
rect->GetRectangle()[0] + rect->GetRectangle()[3] ) );
                    profile_center = profile_center + ( (double)i *
length_inter * normalized_h_direction );
                    TPoint2D <double> first;
                    first.x = profile_center.x + (int)(0.5*nb_points) *
distance * normalized_w_direction.x;
                    first.y = profile_center.y + (int)(0.5*nb_points) *
distance * normalized_w_direction.y;
                    AddProfile(first,nb_points,distance);
                }
            }
            break;
        default:
            break;
        }
    }
    else if ( typeid(m_rectangle.get()) == typeid(OGRRectangle*) )
    {
        boost::shared_ptr<OGRRectangle> ogr_rect(
(OGRRectangle*)(m_rectangle.get()) );
        OGRLinearRing *cur_ring = ogr_rect->getExteriorRing();
        int nb = cur_ring->getNumPoints();
        boost::shared_ptr< OGRRawPoint > struc( new OGRRawPoint[ nb ] );
        cur_ring->getPoints( struc.get() );
        h_direction.x = (struc.get())[1].x - (struc.get())[0].x;
        h_direction.y = (struc.get())[1].y - (struc.get())[0].y;
        w_direction.x = (struc.get())[1].x - (struc.get())[2].x;
        w_direction.y = (struc.get())[1].y - (struc.get())[2].y;
        profile_center.setx( 0.5 * ( (struc.get())[0].x + (struc.get())[3].x
) );
        profile_center.sety( 0.5 * ( (struc.get())[0].y + (struc.get())[3].y
) );
        TPoint2D <double> normalized_h_direction = h_direction;
        TPoint2D <double> normalized_w_direction = w_direction;
        normalized_h_direction.normaliser();
        normalized_w_direction.normaliser();

        unsigned int i;
        switch( position )
        {
        case CENTER:
            {
                double length_inter = h_direction.norme() /
(double)(nb_profiles+1);
                for (i=1;i<=nb_profiles;i++)
                {
                    // Point central du profil
                    profile_center = profile_center + ( (double)i *
length_inter * normalized_h_direction );
                    TPoint2D <double> first;
                    first.x = profile_center.x + (int)(0.5*nb_points) *
distance * normalized_w_direction.x;
                    first.y = profile_center.y + (int)(0.5*nb_points) *
distance * normalized_w_direction.y;
                    AddProfile(first,nb_points,distance);
                }
            }
            break;
        case EXTREME:
            {
                double length_inter = h_direction.norme() /
(double)(nb_profiles-1);
                for (i=0;i<nb_profiles;i++)
                {
                    TPoint2D <double> profile_center;
                    profile_center.setx( 0.5 * ( (struc.get())[0].x + (
struc.get())[3].x ) );
                    profile_center.sety( 0.5 * ( (struc.get())[0].y + (
struc.get())[3].y ) );
                    profile_center = profile_center + ( (double)i *
length_inter * normalized_h_direction );
                    TPoint2D <double> first;
                    first.x = profile_center.x + (int)(0.5*nb_points) *
distance * normalized_w_direction.x;
                    first.y = profile_center.y + (int)(0.5*nb_points) *
distance * normalized_w_direction.y;
                    AddProfile(first,nb_points,distance);
                }
            }
            break;
        default:
            break;
        }
    }
}

Hope you could help me.
Regards.

2007/5/9, Peter Dimov <pdimov_at_[hidden]>:
>
> Olivier Tournaire wrote:
>
> > No one can help me ?
>
> Can you post a complete program that shows the error? I see nothing wrong
> with your code snippets.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Le temps des cerises reviendra. Dans l'immédiat, c'est le temps des noyaux.
Courage.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net