28 Şubat 2018 Çarşamba

geometry BOOST_GEOMETRY_REGISTER_POINT_3D

Giriş
Şu satırı dahil ederiz.
#include <boost/geometry/geometries/register/point.hpp>
3 boyutlu nokta içeren RTree veya polygon için kullanılır.

Örnek
Şöyle yaparız.
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

#include <glm/vec3.hpp>
BOOST_GEOMETRY_REGISTER_POINT_3D(glm::vec3, float, bg::cs::cartesian, x, y, z)

using IndexedPoint = std::pair<glm::vec3, uint32_t>;
using RTree = boost::geometry::index::rtree<IndexedPoint,
  boost::geometry::index::rstar<8>>;

RTree rtree;
rtree.insert({glm::vec3(1,1,1), 1});
rtree.insert({glm::vec3(2,2,2), 2});
rtree.insert({glm::vec3(3,3,3), 3});
rtree.insert({glm::vec3(4,4,4), 4});

auto it = rtree.qbegin(bgi::nearest(glm::vec3(2.9, 2.9, 2.9), 99));

auto p = it->first;
std::cout << "Nearest: # " << it->second
          << " (" << p.x << ", " << p.y << " " << p.z << ")\n";
Örnek
Şöyle yaparız.
#include <boost/geometry/geometry.hpp> 
#include <boost/geometry/geometries/register/point.hpp> 


struct MyPoint
{
    double x, y, z;
};

BOOST_GEOMETRY_REGISTER_POINT_3D(MyPoint, double, boost::geometry::cs::cartesian, x, y, z)

typedef boost::geometry::model::polygon<MyPoint> Polygon;

using boost::geometry::append;

Polygon poly1;


append(poly1, MyPoint{ 2, 0, 1 });
append(poly1, MyPoint{ 2, 2, 1 });
append(poly1, MyPoint{ 0, 2, 1 });
append(poly1, MyPoint{ 0, 0, 1 });
append(poly1, MyPoint{ 2, 0, 1 });




Hiç yorum yok:

Yorum Gönder