Commit 23d1b87f authored by Adam Majzlík's avatar Adam Majzlík Committed by Radek Ošlejšek
Browse files

Symmetry, Icp, Glyphs - Dependency Injection

parent 21efab7f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -230,6 +230,12 @@
            <artifactId>kotlin-osgi-bundle</artifactId>
            <version>1.8.21</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>3.4.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+14 −5
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package cz.fidentis.analyst.engines.face;

import cz.fidentis.analyst.data.face.HumanFace;
import cz.fidentis.analyst.data.shapes.Plane;
import cz.fidentis.analyst.engines.AcaGeometryEngines;
import cz.fidentis.analyst.engines.face.impl.FaceRegistrationServicesImpl;
import cz.fidentis.analyst.engines.icp.IcpConfig;
import cz.fidentis.analyst.engines.landmarks.PrTransformation;
@@ -23,7 +24,7 @@ public interface FaceRegistrationServices {
     * @param icpConfig ICP configuration
     */
    static void alignMeshes(HumanFace transformedFace, IcpConfig icpConfig) {
        new FaceRegistrationServicesImpl().alignMeshes(transformedFace, icpConfig);
        impl().alignMeshes(transformedFace, icpConfig);
    }

    /**
@@ -35,7 +36,7 @@ public interface FaceRegistrationServices {
     * @param scale Scale factor (1 = no scale).
     */
    static void transformFace(HumanFace face, Vector3d rotation, Vector3d translation, double scale) {
        new FaceRegistrationServicesImpl().transformFace(face, rotation, translation, scale);
        impl().transformFace(face, rotation, translation, scale);
    }

    /**
@@ -48,7 +49,7 @@ public interface FaceRegistrationServices {
     * @throws NullPointerException if the symmetry planes are missing.
     */
    static void alignSymmetryPlanes(HumanFace staticFace, HumanFace transformedFace, boolean preserveUpDir) {
        new FaceRegistrationServicesImpl().alignSymmetryPlanes(staticFace, transformedFace, preserveUpDir);
        impl().alignSymmetryPlanes(staticFace, transformedFace, preserveUpDir);
    }

    /**
@@ -60,7 +61,7 @@ public interface FaceRegistrationServices {
     * @param scale Whether to scale faces as well
     */
    static PrTransformation alignFeaturePoints(HumanFace staticFace, HumanFace transformedFace, boolean scale) {
        return new FaceRegistrationServicesImpl().alignFeaturePoints(staticFace, transformedFace, scale);
        return impl().alignFeaturePoints(staticFace, transformedFace, scale);
    }

    /**
@@ -75,6 +76,14 @@ public interface FaceRegistrationServices {
     */
    @Deprecated
    static Plane transformPlane(Plane plane, Quaternion rot, Vector3d translation, double scale) {
        return new FaceRegistrationServicesImpl().transformPlane(plane,rot,translation,scale);
        return impl().transformPlane(plane,rot,translation,scale);
    }

    /**
     * Temporary method used while refactoring and introducing dependency injection step-by-step
     * @return FaceRegistrationServicesImpl bean
     */
    static FaceRegistrationServicesImpl impl() {
        return AcaGeometryEngines.getInstance().getBean(FaceRegistrationServicesImpl.class);
    }
}
+19 −10
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package cz.fidentis.analyst.engines.face;

import cz.fidentis.analyst.data.face.HumanFace;
import cz.fidentis.analyst.data.mesh.measurement.MeshDistances;
import cz.fidentis.analyst.engines.AcaGeometryEngines;
import cz.fidentis.analyst.engines.face.impl.FaceStateServicesImpl;
import cz.fidentis.analyst.engines.sampling.PointSamplingConfig;
import cz.fidentis.analyst.engines.symmetry.SymmetryConfig;
@@ -32,7 +33,7 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateKdTree(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateKdTree(face, mode);
        impl().updateKdTree(face, mode);
    }

    /**
@@ -42,7 +43,7 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateLeftBalancedKdTree(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateLeftBalancedKdTree(face, mode);
        impl().updateLeftBalancedKdTree(face, mode);
    }

    /**
@@ -52,7 +53,7 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateOctree(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateOctree(face, mode);
        impl().updateOctree(face, mode);
    }

    /**
@@ -62,7 +63,7 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateBoundingBox(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateBoundingBox(face, mode);
        impl().updateBoundingBox(face, mode);
    }

    /**
@@ -74,7 +75,7 @@ public interface FaceStateServices {
     * @param maxSamples Maximum number of glyphs. Used only if new glyphs are computed.
     */
    static void updateGlyphs(HumanFace face, Mode mode, PointSamplingConfig.Method method, int maxSamples) {
        new FaceStateServicesImpl().updateGlyphs(face, mode, method, maxSamples);
        impl().updateGlyphs(face, mode, method, maxSamples);
    }

    /**
@@ -84,7 +85,7 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateCurvature(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateCurvature(face, mode);
        impl().updateCurvature(face, mode);
    }

    /**
@@ -94,7 +95,7 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateLandmarksVicinity(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateLandmarksVicinity(face, mode);
        impl().updateLandmarksVicinity(face, mode);
    }

    /**
@@ -106,7 +107,7 @@ public interface FaceStateServices {
     *                           If {@code null}, then the symmetry plane is computed from landmarks.
     */
    static void updateSymmetryPlane(HumanFace face, Mode mode, SymmetryConfig meshSymmetryConfig) {
        new FaceStateServicesImpl().updateSymmetryPlane(face, mode, meshSymmetryConfig);
        impl().updateSymmetryPlane(face, mode, meshSymmetryConfig);
    }

    /**
@@ -123,7 +124,7 @@ public interface FaceStateServices {
     * optionally registered using ICP. Non-overlapping areas are excluded from the measurement.
     */
    static MeshDistances measureSymmetry(HumanFace face, int precision) {
        return new FaceStateServicesImpl().measureSymmetry(face, precision);
        return impl().measureSymmetry(face, precision);
    }

    /**
@@ -133,6 +134,14 @@ public interface FaceStateServices {
     * @param mode Operation to be performed
     */
    static void updateFaceFrontalDirection(HumanFace face, Mode mode) {
        new FaceStateServicesImpl().updateFaceFrontalDirection(face, mode);
        impl().updateFaceFrontalDirection(face, mode);
    }

    /**
     * Temporary method used while refactoring and introducing dependency injection step-by-step
     * @return FaceStateServicesImpl bean
     */
    static FaceStateServicesImpl impl() {
        return AcaGeometryEngines.getInstance().getBean(FaceStateServicesImpl.class);
    }
}
+13 −2
Original line number Diff line number Diff line
@@ -4,12 +4,15 @@ 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.face.FaceRegistrationServices;
import cz.fidentis.analyst.engines.face.FaceStateServices;
import cz.fidentis.analyst.engines.icp.IcpConfig;
import cz.fidentis.analyst.engines.icp.IcpServices;
import cz.fidentis.analyst.engines.landmarks.LandmarkServices;
import cz.fidentis.analyst.engines.landmarks.PrTransformation;
import cz.fidentis.analyst.math.Quaternion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.vecmath.*;
import java.util.Collection;
@@ -19,7 +22,15 @@ import java.util.Collection;
 *
 * @author Radek Oslejsek
 */
public class FaceRegistrationServicesImpl {
@Service
public class FaceRegistrationServicesImpl implements FaceRegistrationServices {

    private final IcpServices icpServices;

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

    /**
     * Superimpose given face to the face included in the ICP configuration object.
@@ -30,7 +41,7 @@ public class FaceRegistrationServicesImpl {
    public void alignMeshes(HumanFace transformedFace, IcpConfig icpConfig) {

        // transform mesh:
        var trHistory = IcpServices.transform(transformedFace.getMeshModel(), icpConfig);
        var trHistory = icpServices.transform(transformedFace.getMeshModel(), icpConfig);

        FaceStateServices.updateKdTree(transformedFace, FaceStateServices.Mode.DELETE);
        FaceStateServices.updateOctree(transformedFace, FaceStateServices.Mode.DELETE);
+21 −7
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import cz.fidentis.analyst.engines.point2surface.PointToSurfaceDistanceServices;
import cz.fidentis.analyst.engines.sampling.PointSamplingConfig;
import cz.fidentis.analyst.engines.symmetry.SymmetryConfig;
import cz.fidentis.analyst.engines.symmetry.SymmetryServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;

@@ -37,8 +39,20 @@ import java.util.Collection;
 *
 * @author Radek Oslejsek
 */
@Service
public class FaceStateServicesImpl implements FaceStateServices {

    private SymmetryServices symmetryServices;
    private IcpServices icpServices;
    private GlyphServices glyphServices;

    @Autowired
    public FaceStateServicesImpl(SymmetryServices symmetryServices, IcpServices icpServices, GlyphServices glyphServices) {
        this.symmetryServices = symmetryServices;
        this.icpServices = icpServices;
        this.glyphServices = glyphServices;
    }

    /**
     * Manages a k-d tree storing the mesh of given human face.
     *
@@ -150,15 +164,15 @@ public class FaceStateServicesImpl implements FaceStateServices {
        switch (mode) {
            case RECOMPUTE_IF_PRESENT -> {
                if (face.hasGlyphs()) {
                    face.setGlyphs(GlyphServices.calculateGlyphs(face.getMeshModel(), config));
                    face.setGlyphs(glyphServices.calculateGlyphs(face.getMeshModel(), config));
                }
            }
            case COMPUTE_IF_ABSENT -> {
                if (!face.hasGlyphs()) {
                    face.setGlyphs(GlyphServices.calculateGlyphs(face.getMeshModel(), config));
                    face.setGlyphs(glyphServices.calculateGlyphs(face.getMeshModel(), config));
                }
            }
            case COMPUTE_ALWAYS -> face.setGlyphs(GlyphServices.calculateGlyphs(face.getMeshModel(), config));
            case COMPUTE_ALWAYS -> face.setGlyphs(glyphServices.calculateGlyphs(face.getMeshModel(), config));
            case DELETE -> face.setGlyphs(null);
            default -> throw new IllegalStateException("Unexpected value: " + mode);
        }
@@ -225,7 +239,7 @@ public class FaceStateServicesImpl implements FaceStateServices {
            case RECOMPUTE_IF_PRESENT -> {
                if (face.hasSymmetryPlane()) {
                    if (meshSymmetryConfig != null) {
                        face.setSymmetryPlane(SymmetryServices.estimate(face.getMeshModel(), meshSymmetryConfig));
                        face.setSymmetryPlane(symmetryServices.estimate(face.getMeshModel(), meshSymmetryConfig));
                    } else {
                        face.setSymmetryPlane(LandmarkServices.computeSymmetryPlane(face.getLandmarks().getAllLandmarks()));
                    }
@@ -234,7 +248,7 @@ public class FaceStateServicesImpl implements FaceStateServices {
            case COMPUTE_IF_ABSENT -> {
                if (!face.hasSymmetryPlane()) {
                    if (meshSymmetryConfig != null) {
                        face.setSymmetryPlane(SymmetryServices.estimate(face.getMeshModel(), meshSymmetryConfig));
                        face.setSymmetryPlane(symmetryServices.estimate(face.getMeshModel(), meshSymmetryConfig));
                    } else {
                        face.setSymmetryPlane(LandmarkServices.computeSymmetryPlane(face.getLandmarks().getAllLandmarks()));
                    }
@@ -242,7 +256,7 @@ public class FaceStateServicesImpl implements FaceStateServices {
            }
            case COMPUTE_ALWAYS -> {
                if (meshSymmetryConfig != null) {
                    face.setSymmetryPlane(SymmetryServices.estimate(face.getMeshModel(), meshSymmetryConfig));
                    face.setSymmetryPlane(symmetryServices.estimate(face.getMeshModel(), meshSymmetryConfig));
                } else {
                    face.setSymmetryPlane(LandmarkServices.computeSymmetryPlane(face.getLandmarks().getAllLandmarks()));
                }
@@ -278,7 +292,7 @@ public class FaceStateServicesImpl implements FaceStateServices {
        HumanFace mirrorFace = HumanFaceFactory.create("tmp", clone, false);

        if (precision > 0) { // perform registration
            IcpServices.transform(
            icpServices.transform(
                    mirrorFace.getMeshModel(),
                    new IcpConfig(
                            face.getMeshModel(),
Loading