Any type of point can be transformed
This commit is contained in:
parent
4e2b0b891d
commit
3de574af36
|
@ -49,7 +49,7 @@ namespace geom {
|
|||
return rotation;
|
||||
}
|
||||
|
||||
inline void TransformPoint (Location &in_point) const {
|
||||
inline void TransformPoint (Vector3D &in_point) const {
|
||||
|
||||
// Rotate
|
||||
double cy = cos(Math::to_radians(rotation.yaw));
|
||||
|
@ -59,7 +59,7 @@ namespace geom {
|
|||
double cp = cos(Math::to_radians(rotation.pitch));
|
||||
double sp = sin(Math::to_radians(rotation.pitch));
|
||||
|
||||
Location out_point;
|
||||
Vector3D out_point;
|
||||
out_point.x = in_point.x * ( cp * cy )
|
||||
+ in_point.y * ( cy * sp * sr - sy * cr)
|
||||
+ in_point.z * (-cy * sp * cr - sy * sr);
|
||||
|
|
|
@ -55,6 +55,13 @@ namespace geom {
|
|||
} // namespace geom
|
||||
} // namespace carla
|
||||
|
||||
static void TransformList(const carla::geom::Transform &self, boost::python::list &list) {
|
||||
auto length = boost::python::len(list);
|
||||
for (auto i = 0u; i < length; ++i) {
|
||||
self.TransformPoint(boost::python::extract<carla::geom::Vector3D &>(list[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void export_geom() {
|
||||
using namespace boost::python;
|
||||
namespace cg = carla::geom;
|
||||
|
@ -73,7 +80,7 @@ void export_geom() {
|
|||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<cg::Location>("Location")
|
||||
class_<cg::Location, bases<cg::Vector3D>>("Location")
|
||||
.def(init<float, float, float>((arg("x")=0.0f, arg("y")=0.0f, arg("z")=0.0f)))
|
||||
.add_property("x", +[](const cg::Location &self) { return self.x; }, +[](cg::Location &self, float x) { self.x = x; })
|
||||
.add_property("y", +[](const cg::Location &self) { return self.y; }, +[](cg::Location &self, float y) { self.y = y; })
|
||||
|
@ -98,11 +105,6 @@ void export_geom() {
|
|||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<std::vector<cg::Location> >("vector_of_locations")
|
||||
.def(vector_indexing_suite<std::vector<cg::Location>>())
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<cg::Transform>("Transform")
|
||||
|
||||
.def(init<cg::Location, cg::Rotation>(
|
||||
|
@ -111,17 +113,11 @@ void export_geom() {
|
|||
.def_readwrite("rotation", &cg::Transform::rotation)
|
||||
.def("__eq__", &cg::Transform::operator==)
|
||||
.def("__ne__", &cg::Transform::operator!=)
|
||||
.def("transform_point", +[](const cg::Transform &self, cg::Location &location) {
|
||||
.def("transform", &TransformList)
|
||||
.def("transform", +[](const cg::Transform &self, cg::Vector3D &location) {
|
||||
self.TransformPoint(location);
|
||||
return location;
|
||||
}, arg("in_point"))
|
||||
|
||||
.def("transform_point_list", +[](const cg::Transform &self, std::vector<cg::Location> &location_list) {
|
||||
for (cg::Location &location : location_list) {
|
||||
self.TransformPoint(location);
|
||||
}
|
||||
return location_list;
|
||||
})
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -150,21 +150,19 @@ class testTransform(unittest.TestCase):
|
|||
self.assertTrue(abs(point.y - 0.0) <= error)
|
||||
self.assertTrue(abs(point.z - (-1.0)) <= error)
|
||||
|
||||
def test_list_rotation_and_translation(self):
|
||||
def test_list_rotation_and_translation_location(self):
|
||||
error = .001
|
||||
t = carla.Transform(
|
||||
carla.Location(x=0.0, y=0.0, z=-1.0),
|
||||
carla.Rotation(pitch=90.0, yaw=0.0, roll=0.0))
|
||||
|
||||
point_list = carla.vector_of_locations()
|
||||
point_list.append(carla.Location(x=0.0, y=0.0, z=2.0))
|
||||
point_list.append(carla.Location(x=0.0, y=10.0, z=1.0))
|
||||
point_list.append(carla.Location(x=0.0, y=18.0, z=2.0))
|
||||
|
||||
|
||||
point_list = [ carla.Location(x=0.0, y=0.0, z=2.0),
|
||||
carla.Location(x=0.0, y=10.0, z=1.0),
|
||||
carla.Location(x=0.0, y=18.0, z=2.0)
|
||||
]
|
||||
t.transform_point_list(point_list)
|
||||
|
||||
solution_list = carla.vector_of_locations()
|
||||
solution_list.append(carla.Location(x=-2.0, y=0.0, z=-1.0))
|
||||
solution_list.append(carla.Location(x=-2.0, y=0.0, z=-1.0))
|
||||
solution_list.append(carla.Location(x=-1.0, y=10.0, z=-1.0))
|
||||
solution_list.append(carla.Location(x=-2.0, y=18.0, z=-1.0))
|
||||
|
||||
|
@ -173,5 +171,24 @@ class testTransform(unittest.TestCase):
|
|||
self.assertTrue(abs(point_list[i].y - solution_list[i].y) <= error)
|
||||
self.assertTrue(abs(point_list[i].z - solution_list[i].z) <= error)
|
||||
|
||||
|
||||
|
||||
def test_list_rotation_and_translation_vector3d(self):
|
||||
error = .001
|
||||
t = carla.Transform(
|
||||
carla.Location(x=0.0, y=0.0, z=-1.0),
|
||||
carla.Rotation(pitch=90.0, yaw=0.0, roll=0.0))
|
||||
|
||||
point_list = [ carla.Vector3D(0.0, 0.0, 2.0),
|
||||
carla.Vector3D(0.0, 10.0, 1.0),
|
||||
carla.Vector3D(0.0, 18.0, 2.0)
|
||||
]
|
||||
t.transform_point_list(point_list)
|
||||
|
||||
solution_list.append(carla.Vector3D(-2.0, 0.0, -1.0))
|
||||
solution_list.append(carla.Vector3D(-1.0, 10.0, -1.0))
|
||||
solution_list.append(carla.Vector3D(-2.0, 18.0, -1.0))
|
||||
|
||||
for i in range(len(point_list)):
|
||||
self.assertTrue(abs(point_list[i].x - solution_list[i].x) <= error)
|
||||
self.assertTrue(abs(point_list[i].y - solution_list[i].y) <= error)
|
||||
self.assertTrue(abs(point_list[i].z - solution_list[i].z) <= error)
|
||||
|
||||
|
|
Loading…
Reference in New Issue