Commit 2e52b77d authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Resolve "Accelerate octree creation"

parent cf48d852
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -307,7 +307,8 @@ public class HumanFaceFactory {
        int ret =  0;
        int counter = 0;
        while (counter++ < this.MAX_DUMP_FACES &&
                (double) presumableFreeMemory() / Runtime.getRuntime().maxMemory() <= MIN_FREE_MEMORY) {
                (double) presumableFreeMemory() / Runtime.getRuntime().maxMemory() <= MIN_FREE_MEMORY &&
                !inMemoryFaces.isEmpty()) {
            
            Long time = null;
            switch (strategy) {
+17 −5
Original line number Diff line number Diff line
@@ -2,9 +2,11 @@ package cz.fidentis.analyst.raycasting;

import cz.fidentis.analyst.raycasting.RayIntersectionOctree;
import cz.fidentis.analyst.octree.OctNode;
import cz.fidentis.analyst.octree.OctNodeLeaf;
import static cz.fidentis.analyst.raycasting.RayIntersectionOctree.getOctantIndex;
import static cz.fidentis.analyst.raycasting.RayIntersectionOctree.isPointInCube;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -37,7 +39,11 @@ public class RayIntersectionVisitorTest {
            }
        }

        var cube = new OctNode(new Point3d(-halfSize, -halfSize, -halfSize), new Point3d(halfSize, halfSize, halfSize));
        var cube = new OctNodeLeaf(
                new Point3d(-halfSize, -halfSize, -halfSize), 
                new Point3d(halfSize, halfSize, halfSize),
                Collections.emptyList()
        );

        for (Vector3d m : multipliers) {
            var point = new Point3d(m.x * halfSize, m.y * halfSize, m.z * halfSize);
@@ -83,8 +89,11 @@ public class RayIntersectionVisitorTest {
        int quaterSize = 1;
        int halfSize = quaterSize * 2;
        int size = halfSize * 2;
        var cube = new OctNode(new Point3d(-halfSize, -halfSize, -halfSize),
                new Point3d(halfSize, halfSize, halfSize));
        var cube = new OctNodeLeaf(
                new Point3d(-halfSize, -halfSize, -halfSize),
                new Point3d(halfSize, halfSize, halfSize),
                Collections.emptyList()
        );
        Point3d point;
        for (int i = 0; i < multipliers.size(); i++) {
            for (Vector3d m : multipliers.get(i)) {
@@ -142,8 +151,11 @@ public class RayIntersectionVisitorTest {
    public void rayCubeIntersectionTest() {
        int quaterSize = 1;
        int halfSize = quaterSize * 2;
        var cube = new OctNode(new Point3d(-halfSize, -halfSize, -halfSize),
                new Point3d(halfSize, halfSize, halfSize));
        var cube = new OctNodeLeaf(
                new Point3d(-halfSize, -halfSize, -halfSize),
                new Point3d(halfSize, halfSize, halfSize),
                Collections.emptyList()
        );
        int[] originSmallValues = {-7 * quaterSize, -2 * quaterSize, 3 * quaterSize};
        int[] mainCoorIndeces = {0, 1, 2};
        int[] mainCoorValues = {-2 * quaterSize, 2 * quaterSize};
+7 −49
Original line number Diff line number Diff line
@@ -3,9 +3,7 @@ package cz.fidentis.analyst.octree;
import cz.fidentis.analyst.mesh.core.MeshTriangle;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.vecmath.Point3d;

/**
@@ -14,12 +12,12 @@ import javax.vecmath.Point3d;
 *
 * @author Enkh-Undral EnkhBayar
 */
public class OctNode implements Serializable {
public abstract class OctNode implements Serializable {

    /**
     * Mesh facets sharing the stored vertex
     */
    private final Set<MeshTriangle> triangles;
    private final List<MeshTriangle> triangles;

    /**
     * Octree topology
@@ -36,22 +34,7 @@ public class OctNode implements Serializable {
     */
    private final Point3d largestBoundary;

    /**
     * Constructor of OctNode for leaf Nodes
     *
     * @param smallest boundary box - corner with smallest coordinates. Must not
     * be null
     * @param largest boundary box - corner with largest coordinates. Must not
     * be null
     * @param triangles Mesh triangles which this oct node holds, meaning a
     * bounding box of the triangle intersects with this oct node Must not be
     * null
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public OctNode(Point3d smallest, Point3d largest, Set<MeshTriangle> triangles) {
        if (triangles == null) {
            throw new IllegalArgumentException("triangles");
        }
    protected OctNode(Point3d smallest, Point3d largest, List<MeshTriangle> triangles, List<OctNode> octants) {
        if (smallest == null) {
            throw new IllegalArgumentException("Smallest boundary in OctNode cannot be null");
        }
@@ -60,33 +43,6 @@ public class OctNode implements Serializable {
        }

        this.triangles = triangles;
        this.smallestBoundary = smallest;
        this.largestBoundary = largest;
    }

    /**
     * Constructor of OctNode for internal nodes
     *
     * @param smallest boundary box - corner with smallest coordinates. Must not
     * be null
     * @param largest boundary box - corner with largest coordinates. Must not
     * be null
     * @param octants List of octNodes which are children for this node. Must
     * not be null and has to have size of 8.
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public OctNode(Point3d smallest, Point3d largest, List<OctNode> octants) {
        if (octants == null || octants.size() != 8) {
            throw new IllegalArgumentException("octants");
        }
        if (smallest == null) {
            throw new IllegalArgumentException("Smallest boundary in OctNode cannot be null");
        }
        if (largest == null) {
            throw new IllegalArgumentException("Largest boundary in OctNode cannot be null");
        }

        this.triangles = new HashSet<>();
        this.octants = octants;
        this.smallestBoundary = smallest;
        this.largestBoundary = largest;
@@ -101,6 +57,7 @@ public class OctNode implements Serializable {
     * be null
     * @throws IllegalArgumentException if some parameter is wrong
     */
    /*
    public OctNode(Point3d smallest, Point3d largest) {
        if (smallest == null) {
            throw new IllegalArgumentException("Smallest boundary in OctNode cannot be null");
@@ -113,6 +70,7 @@ public class OctNode implements Serializable {
        this.largestBoundary = largest;
        this.triangles = new HashSet<>();
    }
    */

    public boolean isLeafNode() {
        return octants == null || octants.isEmpty();
@@ -140,8 +98,8 @@ public class OctNode implements Serializable {
     *
     * @return triangles which this oct node holds
     */
    public Set<MeshTriangle> getTriangles() {
        return Collections.unmodifiableSet(triangles);
    public List<MeshTriangle> getTriangles() {
        return Collections.unmodifiableList(triangles);
    }

    /**
+31 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.octree;

import java.util.Collections;
import java.util.List;
import javax.vecmath.Point3d;

/**
 * An inner node of an Octree.
 *
 * @author Enkh-Undral EnkhBayar
 */
public class OctNodeInner extends OctNode {
    
    /**
     * Constructor of an <b>internal node</b>
     *
     * @param smallest boundary box - corner with smallest coordinates. Must not
     * be null
     * @param largest boundary box - corner with largest coordinates. Must not
     * be null
     * @param octants List of octNodes which are children for this node. Must
     * not be null and has to have size of 8.
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public OctNodeInner(Point3d smallest, Point3d largest, List<OctNode> octants) {
        super(smallest, largest, Collections.emptyList(), octants);
        if (octants == null || octants.size() != 8) {
            throw new IllegalArgumentException("octants");
        }
    }
}
+32 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.octree;

import cz.fidentis.analyst.mesh.core.MeshTriangle;
import java.util.List;
import javax.vecmath.Point3d;

/**
 * A leaf node of an Octree.
 *
 * @author Enkh-Undral EnkhBayar
 */
public class OctNodeLeaf extends OctNode {
    
    /**
     * Constructor of a <b>leaf node</b>
     *
     * @param smallest boundary box - corner with smallest coordinates. Must not
     * be null
     * @param largest boundary box - corner with largest coordinates. Must not
     * be null
     * @param triangles Mesh triangles which this oct node holds, meaning a
     * bounding box of the triangle intersects with this oct node Must not be
     * null
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public OctNodeLeaf(Point3d smallest, Point3d largest, List<MeshTriangle> triangles) {
        super(smallest, largest, triangles, null);
        if (triangles == null) {
            throw new IllegalArgumentException("triangles");
        }
    }
}
Loading