Commit 65cc4261 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch 'refactor-bounding-box' into 'master'

Refactor Bounding Box

See merge request grp-fidentis/analyst2!465
parents 894fa72c ba427893
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
package cz.fidentis.analyst.engines.face;

import com.jogamp.opencl.CLCommandQueue;
import cz.fidentis.analyst.data.face.Aca;
import cz.fidentis.analyst.data.face.HumanFace;
import cz.fidentis.analyst.data.landmarks.Landmark;
import cz.fidentis.analyst.data.shapes.Plane;
import cz.fidentis.analyst.engines.bbox.BoundingBoxConfig;
import cz.fidentis.analyst.engines.bbox.BoundingBoxManager;
import cz.fidentis.analyst.engines.icp.IcpConfig;
import cz.fidentis.analyst.engines.icp.IcpServicesOpenCL;
import cz.fidentis.analyst.math.Quaternion;
@@ -22,6 +25,8 @@ public class FaceRegistrationServicesOpenCL implements CLResources {

    private final IcpServicesOpenCL icpServicesOpenCL;

    private final BoundingBoxManager boundingBoxManager = Aca.getInstance().getBean(BoundingBoxManager.class);

    public FaceRegistrationServicesOpenCL(CLCommandQueue queue) {
        this.icpServicesOpenCL = new IcpServicesOpenCL(queue);
    }
@@ -41,7 +46,7 @@ public class FaceRegistrationServicesOpenCL implements CLResources {
        FaceStateServices.updateKdTree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateLeftBalancedKdTree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateOctree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateBoundingBox(transformedFace, FaceStateServices.Mode.RECOMPUTE_IF_PRESENT);
        boundingBoxManager.compute(transformedFace, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.RECOMPUTE_IF_PRESENT);

        // transform feature points:
        if (transformedFace.getLandmarks().hasLandmarks()) {
+0 −10
Original line number Diff line number Diff line
@@ -54,16 +54,6 @@ public interface FaceStateServices {
        impl().updateOctree(face, mode);
    }

    /**
     * Manages bounding box of the given human face.
     *
     * @param face Human face
     * @param mode Operation to be performed
     */
    static void updateBoundingBox(HumanFace face, Mode mode) {
        impl().updateBoundingBox(face, mode);
    }

    /**
     * Manages curvature values of the given human face.
     *
+7 −3
Original line number Diff line number Diff line
package cz.fidentis.analyst.engines.face.impl;

import cz.fidentis.analyst.data.face.Aca;
import cz.fidentis.analyst.data.face.HumanFace;
import cz.fidentis.analyst.data.shapes.Plane;
import cz.fidentis.analyst.engines.face.FaceStateServices;
import cz.fidentis.analyst.engines.bbox.BoundingBoxConfig;
import cz.fidentis.analyst.engines.bbox.BoundingBoxManager;

import javax.vecmath.Vector3d;

@@ -14,6 +16,8 @@ import javax.vecmath.Vector3d;
 */
public class FaceCuttingServicesImpl {

    private final BoundingBoxManager boundingBoxManager = Aca.getInstance().getBean(BoundingBoxManager.class);

    /**
     * Creates a cutting plane from the symmetry plane of the face
     *
@@ -37,7 +41,7 @@ public class FaceCuttingServicesImpl {
        if (direction.x == 1) {
            rotatedSymmetryPlane = new Plane(copyOfSymmetryPlane);
        } else {
            FaceStateServices.updateBoundingBox(face, FaceStateServices.Mode.COMPUTE_IF_ABSENT);
            boundingBoxManager.compute(face, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.COMPUTE_IF_ABSENT);
            if (direction.y == 1) {
                copyOfSymmetryPlane.rotateOverZ();
                rotatedSymmetryPlane = new Plane(copyOfSymmetryPlane.getNormal(), face.getBoundingBox().midPoint().y);
@@ -58,7 +62,7 @@ public class FaceCuttingServicesImpl {
     * @return a cutting plane
     */
    public Plane fromBoundingBox(HumanFace face, Vector3d direction) {
        FaceStateServices.updateBoundingBox(face, FaceStateServices.Mode.COMPUTE_IF_ABSENT);
        boundingBoxManager.compute(face, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.COMPUTE_IF_ABSENT);
        // compute plane distance based on direction
        double distance;
        if (direction.x == 1) {
+9 −5
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ import cz.fidentis.analyst.data.face.HumanFace;
import cz.fidentis.analyst.data.landmarks.Landmark;
import cz.fidentis.analyst.data.mesh.MeshFacet;
import cz.fidentis.analyst.data.shapes.Plane;
import cz.fidentis.analyst.engines.bbox.BoundingBoxConfig;
import cz.fidentis.analyst.engines.bbox.BoundingBoxManager;
import cz.fidentis.analyst.engines.face.FaceRegistrationServices;
import cz.fidentis.analyst.engines.face.FaceStateServices;
import cz.fidentis.analyst.engines.icp.IcpConfig;
@@ -26,10 +28,12 @@ import java.util.Collection;
public class FaceRegistrationServicesImpl implements FaceRegistrationServices {

    private final IcpServices icpServices;
    private final BoundingBoxManager boundingBoxManager;

    @Autowired
    public FaceRegistrationServicesImpl(IcpServices icpServices) {
    public FaceRegistrationServicesImpl(IcpServices icpServices, BoundingBoxManager boundingBoxManager) {
        this.icpServices = icpServices;
        this.boundingBoxManager = boundingBoxManager;
    }

    /**
@@ -45,7 +49,7 @@ public class FaceRegistrationServicesImpl implements FaceRegistrationServices {

        FaceStateServices.updateKdTree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateOctree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateBoundingBox(transformedFace, FaceStateServices.Mode.RECOMPUTE_IF_PRESENT);
        boundingBoxManager.compute(transformedFace, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.RECOMPUTE_IF_PRESENT);

        // transform feature points:
        if (transformedFace.getLandmarks().hasLandmarks()) {
@@ -96,7 +100,7 @@ public class FaceRegistrationServicesImpl implements FaceRegistrationServices {

        FaceStateServices.updateKdTree(face, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateOctree(face, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateBoundingBox(face, FaceStateServices.Mode.RECOMPUTE_IF_PRESENT);
        boundingBoxManager.compute(face, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.RECOMPUTE_IF_PRESENT);

        // transform feature points:
        if (face.getLandmarks().hasLandmarks()) {
@@ -143,7 +147,7 @@ public class FaceRegistrationServicesImpl implements FaceRegistrationServices {

        FaceStateServices.updateKdTree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateOctree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateBoundingBox(transformedFace, FaceStateServices.Mode.RECOMPUTE_IF_PRESENT);
        boundingBoxManager.compute(transformedFace, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.RECOMPUTE_IF_PRESENT);

        // Transform feature points:
        if (transformedFace.getLandmarks().hasLandmarks()) {
@@ -180,7 +184,7 @@ public class FaceRegistrationServicesImpl implements FaceRegistrationServices {

        FaceStateServices.updateKdTree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateOctree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateBoundingBox(transformedFace, FaceStateServices.Mode.RECOMPUTE_IF_PRESENT);
        boundingBoxManager.compute(transformedFace, new BoundingBoxConfig(), BoundingBoxManager.FaceStateUpdateMode.RECOMPUTE_IF_PRESENT);

        // transform symmetry plane:
        if (transformedFace.hasSymmetryPlane()) {
+0 −27
Original line number Diff line number Diff line
@@ -11,8 +11,6 @@ import cz.fidentis.analyst.data.mesh.MeshPoint;
import cz.fidentis.analyst.data.mesh.measurement.MeshDistances;
import cz.fidentis.analyst.data.octree.Octree;
import cz.fidentis.analyst.data.shapes.Plane;
import cz.fidentis.analyst.engines.bbox.BoundingBoxConfig;
import cz.fidentis.analyst.engines.bbox.BoundingBoxServices;
import cz.fidentis.analyst.engines.curvature.CurvatureConfig;
import cz.fidentis.analyst.engines.curvature.CurvatureServices;
import cz.fidentis.analyst.engines.distance.MeshDistanceConfig;
@@ -116,31 +114,6 @@ public class FaceStateServicesImpl implements FaceStateServices {
        }
    }

    /**
     * Manages bounding box of the given human face.
     *
     * @param face Human face
     * @param mode Operation to be performed
     */
    public void updateBoundingBox(HumanFace face, Mode mode) {
        switch (mode) {
            case RECOMPUTE_IF_PRESENT -> {
                if (face.hasBoundingBox()) {
                    face.setBoundingBox(BoundingBoxServices.compute(face.getMeshModel(), new BoundingBoxConfig()));
                }
            }
            case COMPUTE_IF_ABSENT -> {
                if (!face.hasBoundingBox()) {
                    face.setBoundingBox(BoundingBoxServices.compute(face.getMeshModel(), new BoundingBoxConfig()));
                }
            }
            case COMPUTE_ALWAYS ->
                    face.setBoundingBox(BoundingBoxServices.compute(face.getMeshModel(), new BoundingBoxConfig()));
            case DELETE -> face.setBoundingBox(null);
            default -> throw new IllegalStateException("Unexpected value: " + mode);
        }
    }

    /**
     * Manages curvature values of the given human face.
     *
Loading