Skip to content

Commit

Permalink
CGAL Lab: Transformation of point normals (#7935)
Browse files Browse the repository at this point in the history
## Summary of Changes

Affine transformation transforms points, but didn't transform their
normals. This PR takes care of normal transformation of point sets.

## Release Management

* Affected package(s): Polyhedron Demo
  • Loading branch information
sloriot authored Dec 26, 2023
2 parents 6eff89b + 4fe88f8 commit 1a93452
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,20 @@ endPointSet(const QMatrix4x4& transform_matrix)
Point_set* new_ps = new_item->point_set();
CGAL::qglviewer::Vec c = aff_transformed_item->center();

QMatrix3x3 normal_matrix = transform_matrix.normalMatrix();

for(Point_set::Index idx : *new_ps)
{
QVector3D vec = transform_matrix.map(QVector3D(new_ps->point(idx).x() - c.x,
new_ps->point(idx).y() - c.y,
new_ps->point(idx).z() - c.z));
new_ps->point(idx) = Kernel::Point_3(vec.x(), vec.y(), vec.z());
if (new_ps->has_normal_map()) {
QVector3D n(new_ps->normal(idx).x(), new_ps->normal(idx).y(), new_ps->normal(idx).z());
new_ps->normal(idx) = Kernel::Vector_3(normal_matrix(0, 0) * n[0] + normal_matrix(0, 1) * n[1] + normal_matrix(0, 2) * n[2],
normal_matrix(1, 0) * n[0] + normal_matrix(1, 1) * n[1] + normal_matrix(1, 2) * n[2],
normal_matrix(2, 0) * n[0] + normal_matrix(2, 1) * n[1] + normal_matrix(2, 2) * n[2]);
}
}

new_item->setName(aff_transformed_item->name());
Expand Down

0 comments on commit 1a93452

Please sign in to comment.