H'H
H'H

Reputation: 1678

rtree is indexable assertion

Here is the piece of my code. I am trying to create a rtree tree for the vertex class objects RTreeVertex.

class Entity {

public:
  int num;
public:
  Entity(int nr): num(nr){ }
  virtual ~Entity(){}
   bool operator==(const Entity& b)
   {
     return num == b.num;
   } 
};


class Vertex : public Entity {

public : 
  struct Coord{
  double X, Y, Z;  
  }Pos;

  Vertex(int num=0, double X=0., double Y=0., double Z=0.): Entity (num)
  {
    Pos.X = X;
    Pos.Y = Y;
    Pos.Z = Z;
  }
};

here is how I declare the rtree:

#include <boost/geometry/index/rtree.hpp>
namespace bgi = boost::geometry::index;
bgi::rtree< Vertex, bgi::linear<32> > RTreeVertex;

but I get an error saying that vertec is not Indexable.

and one more general question: Is it a good idea to use rtree for storing data related to a mesh?

Upvotes: 1

Views: 323

Answers (1)

lakeweb
lakeweb

Reputation: 1939

You have to register your point class with boost geometry. It creates a slew of traits for your class. I tested this, it works.

    class Vertex : public Entity {

    public : 
            double X, Y, Z;  

        Vertex(int num=0, double x=0., double y=0., double z=0.): Entity (num)
        {
            X = x;
            Y = y;
            Z = z;
        }
    };

BOOST_GEOMETRY_REGISTER_POINT_3D( Vertex, double, bg::cs::cartesian, X, X, X );
#include <boost/geometry/index/rtree.hpp>
namespace bgi = boost::geometry::index;
bgi::rtree< Vertex, bgi::linear<32> > RTreeVertex;

I could not get it to work with X,Y,Z in a structure with Pos::X..., there may be a way. You could join the geometry group on boost.org. They are the geometry experts.

Addendum: I was curious, so I looked at how REGISTER.. works. With:

BOOST_GEOMETRY_REGISTER_POINT_3D( Vertex, double, bg::cs::cartesian, Pos.X, Pos.Y, Pos.Z );

You can use your structure for your x,y,z.

And namespace bg = boost::geometry;

is the name space I used above

Upvotes: 2

Related Questions