Skip to content
Snippets Groups Projects
Commit 28088f75 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Fixed randrom reduction

parent fb401035
No related branches found
No related tags found
No related merge requests found
......@@ -244,7 +244,7 @@ public class IcpVisitor extends MeshVisitor {
);
MeshFacet reducedFacet = new ReducedMeshFacet(transformedFacet, reductionStrategy);
int currentIteration = 0;
IcpTransformation transformation = null;
......
package cz.fidentis.analyst.icp;
import cz.fidentis.analyst.mesh.core.MeshPoint;
import java.util.Collection;
import java.util.List;
/**
......
......@@ -2,11 +2,11 @@ package cz.fidentis.analyst.icp;
import cz.fidentis.analyst.mesh.core.MeshPoint;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Random reduction strategy when the mesh vertices are selected randomly.
......@@ -47,14 +47,27 @@ public class RandomReductionStrategy extends ReductionStrategy {
return meshPoints;
}
SortedMap<Integer, MeshPoint> map = new TreeMap<>();
for (int i = 0; i < meshPoints.size(); i++) {
map.put(i, meshPoints.get(i));
}
Random rand = new Random();
while (map.size() > maxVertices) {
map.remove(rand.nextInt(map.size()));
// generate randomly ordered indexes:
List<Integer> range = IntStream.range(0, meshPoints.size()).boxed().collect(Collectors.toCollection(ArrayList::new));
Collections.shuffle(range);
if (maxVertices < meshPoints.size()/2) { // copy indices
MeshPoint[] array = new MeshPoint[meshPoints.size()];
range.stream().limit(maxVertices).forEach(
i -> array[i] = meshPoints.get(i)
);
return Arrays.stream(array).filter(
p -> p != null
).collect(Collectors.<MeshPoint>toList());
} else { // remove indices
List<MeshPoint> copy = new ArrayList<>(meshPoints);
range.stream().limit(meshPoints.size()-maxVertices).forEach(
i -> copy.set(i, null)
);
return copy.parallelStream().filter(
p -> p != null
).collect(Collectors.<MeshPoint>toList());
}
return new ArrayList<>(map.values());
}
}
package cz.fidentis.analyst.icp;
import cz.fidentis.analyst.mesh.core.MeshPoint;
import java.util.Collection;
import java.util.List;
/**
......
......@@ -14,9 +14,7 @@ import static com.jogamp.opengl.GL2GL3.GL_LINE;
import com.jogamp.opengl.GLAutoDrawable;
import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW_MATRIX;
import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION_MATRIX;
import cz.fidentis.analyst.icp.Icp;
import cz.fidentis.analyst.icp.IcpVisitor;
import cz.fidentis.analyst.icp.NoReductionStrategy;
import cz.fidentis.analyst.icp.RandomReductionStrategy;
//import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.mesh.core.MeshFacet;
......@@ -88,7 +86,7 @@ public class RegistrationGLEventListener extends GeneralGLEventListener{
primaryModel = model;
}
else {
IcpVisitor icpVisitor = new IcpVisitor(primaryModel, 10, true, 0.05, new RandomReductionStrategy(0.5));
IcpVisitor icpVisitor = new IcpVisitor(primaryModel, 10, true, 0.05, new RandomReductionStrategy(0.25));
for (MeshFacet f: model.getFacets()) {
icpVisitor.visitMeshFacet(f);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment