Commit 4aee5d9f authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch '316-integrate-gpu-rc-registration' into 'master'

Superimposition transformations are now computed on GPU in batch registration

Closes #316

See merge request grp-fidentis/analyst2!340
parents f0326c6a 9e5badcd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ public class BatchOctreeTestsMultipleFaces {

                    AVG_FACE_COMPUTATION_TIME.start();
                    if (avgFaceConstructorOctree == null) {
                        avgFaceConstructorOctree = (new AvgMeshConfig(initFace.getMeshModel())).getRayCastingVisitor();
                        avgFaceConstructorOctree = (new AvgMeshConfig(initFace.getMeshModel(), null)).getRayCastingVisitor();
                    }
                    face.getOctree().accept(avgFaceConstructorOctree);
                    AVG_FACE_COMPUTATION_TIME.stop();
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class BatchOctreeTestsTwoFaces {
        OCTREE_CONSTRUCTION_TIME.stop();

        AVG_FACE_COMPUTATION_TIME.start();
        AvgMeshVisitor avgFaceConstructorOctree = (new AvgMeshConfig(mainFace.getMeshModel())).getRayCastingVisitor();
        AvgMeshVisitor avgFaceConstructorOctree = (new AvgMeshConfig(mainFace.getMeshModel(), null)).getRayCastingVisitor();
        avgFaceConstructorOctree.visitOctree(secondFace.getOctree());
        AVG_FACE_COMPUTATION_TIME.stop();

+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ public class BatchRegistrationPanel extends ControlPanel {

    public static final String AVG_FACE_NEAREST_NEIGHBOURS = "Nearest neighbours";
    public static final String AVG_FACE_RAY_CASTING = "Ray casting [experimental]";
    public static final String AVG_FACE_RAY_CASTING_GPU = "Ray casting GPU [experimental]";
    public static final String AVG_FACE_NONE = "Skip (use selected face for registration)";
    
    public static final String REGISTRATION_NONE = "Skip registration";
@@ -74,6 +75,7 @@ public class BatchRegistrationPanel extends ControlPanel {
        
        jComboBox4.addItem(AVG_FACE_NEAREST_NEIGHBOURS);
        jComboBox4.addItem(AVG_FACE_RAY_CASTING);
        jComboBox4.addItem(AVG_FACE_RAY_CASTING_GPU);
        jComboBox4.addItem(AVG_FACE_NONE);
        
        jComboBox3.addItem(REGISTRATION_ICP);
+22 −6
Original line number Diff line number Diff line
@@ -70,7 +70,8 @@ public class BatchRegistrationTask extends SwingWorker<MeshModel, HumanFace> {
        boolean doRegistration = regStrategy.equals(BatchRegistrationPanel.REGISTRATION_GPA) ||
                regStrategy.equals(BatchRegistrationPanel.REGISTRATION_ICP);
        boolean computeAvgFace = avgFaceStrategy.equals(BatchRegistrationPanel.AVG_FACE_NEAREST_NEIGHBOURS) ||
                avgFaceStrategy.equals(BatchRegistrationPanel.AVG_FACE_RAY_CASTING);
                avgFaceStrategy.equals(BatchRegistrationPanel.AVG_FACE_RAY_CASTING) ||
                avgFaceStrategy.equals(BatchRegistrationPanel.AVG_FACE_RAY_CASTING_GPU);

        if (!(doRegistration || computeAvgFace)) { // nothing to do
            return null;
@@ -105,9 +106,12 @@ public class BatchRegistrationTask extends SwingWorker<MeshModel, HumanFace> {
            }

            if (computeAvgFace) { // update the average face
                avgFaceConstructor = (avgFaceStrategy.equals(BatchRegistrationPanel.AVG_FACE_NEAREST_NEIGHBOURS))
                        ? computeAvgFaceNN(initFace, superimposedFace, avgFaceConstructor, doRegistration)
                        : computeAvgFaceRT(initFace, superimposedFace, avgFaceConstructor, doRegistration);
                avgFaceConstructor = switch(avgFaceStrategy) {
                    case BatchRegistrationPanel.AVG_FACE_NEAREST_NEIGHBOURS -> computeAvgFaceNN(initFace, superimposedFace, avgFaceConstructor, doRegistration);
                    case BatchRegistrationPanel.AVG_FACE_RAY_CASTING -> computeAvgFaceRT(initFace, superimposedFace, avgFaceConstructor, doRegistration);
                    case BatchRegistrationPanel.AVG_FACE_RAY_CASTING_GPU -> computeAvgFaceRTGPU(initFace, superimposedFace, avgFaceConstructor);
                    default -> null;
                };
            }

            publish(superimposedFace);       // update progress bar and possibly render the transformed face
@@ -189,6 +193,18 @@ public class BatchRegistrationTask extends SwingWorker<MeshModel, HumanFace> {
        registrationTime.stop();
    }

    protected AvgMeshVisitor computeAvgFaceRTGPU(HumanFace initFace, HumanFace superimposedFace, AvgMeshVisitor avgFaceConstructor) {
        avgFaceComputationTime.start();
        AvgMeshVisitor ret = (avgFaceConstructor == null)
                ? (new AvgMeshConfig(initFace.getMeshModel(), canvas.getGLCanvas().getContext())).getRayCastingGpuVisitor()
                : avgFaceConstructor;

        superimposedFace.getMeshModel().compute(ret);
        //ret.visitMeshFacet(superimposedFace.getMeshModel());
        avgFaceComputationTime.stop();
        return ret;
    }

    protected AvgMeshVisitor computeAvgFaceRT(HumanFace initFace, HumanFace superimposedFace, AvgMeshVisitor avgFaceConstructor, boolean doRegistration) {
        // If the face was moved by registration, then the spatial ordering structure was removed => create it
        // If no transformation was made, then you can use old structure, if exists
@@ -201,7 +217,7 @@ public class BatchRegistrationTask extends SwingWorker<MeshModel, HumanFace> {

        avgFaceComputationTime.start();
        AvgMeshVisitor ret = (avgFaceConstructor == null)
                ? (new AvgMeshConfig(initFace.getMeshModel())).getRayCastingVisitor()
                ? (new AvgMeshConfig(initFace.getMeshModel(), null)).getRayCastingVisitor()
                : avgFaceConstructor;
        superimposedFace.getOctree().accept(ret);
        avgFaceComputationTime.stop();
@@ -221,7 +237,7 @@ public class BatchRegistrationTask extends SwingWorker<MeshModel, HumanFace> {

        avgFaceComputationTime.start();
        AvgMeshVisitor ret = (avgFaceConstructor == null)
                ? (new AvgMeshConfig(initFace.getMeshModel())).getNearestNeighborsVisitor()
                ? (new AvgMeshConfig(initFace.getMeshModel(), null)).getNearestNeighborsVisitor()
                : avgFaceConstructor;
        superimposedFace.getKdTree().accept(ret);
        avgFaceComputationTime.stop();
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package cz.fidentis.analyst.data.mesh;
 *
 * @author Radek Oslejsek
 */
@FunctionalInterface
public interface MeshVisitor {

    /**
Loading