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

Corner table extended with vertex-to-row hash map

parent 8667d56c
No related branches found
No related tags found
No related merge requests found
......@@ -37,16 +37,18 @@ public class EfficiencyTests {
System.out.println(measureKdTreeCreation(boy) + " msec: Kd-tree creation of the boy");
System.out.println(measureKdTreeCreation(boy) + " msec: Kd-tree creation of the girl");
System.out.println(measureDist(new Vector3d(), boy, false, false, true) + " msec: Distance (sequential, point-to-point)");
System.out.println(measureDist(new Vector3d(), boy, true, false, true) + " msec: Distance (concurrent, point-to-point)");
System.out.println(measureDist(new Vector3d(), boy, false, false, false) + " msec: Distance (sequential, point-to-tri)");
System.out.println(measureDist(new Vector3d(), boy, true, false, false) + " msec: Distance (concurrent, point-to-tri)");
boolean print = true;
System.out.println(measureDist(new Vector3d(), boy, false, print, true) + " msec: Distance (sequential, point-to-point)");
System.out.println(measureDist(new Vector3d(), boy, true, print, true) + " msec: Distance (concurrent, point-to-point)");
System.out.println(measureDist(new Vector3d(), boy, false, print, false) + " msec: Distance (sequential, point-to-tri)");
System.out.println(measureDist(new Vector3d(), boy, true, print, false) + " msec: Distance (concurrent, point-to-tri)");
System.out.println(measureHD(boy, girl, false, false, false, true) + " msec: Hausdorff distance (relative, sequential, point-to-point)");
System.out.println(measureHD(boy, girl, false, true, false, true) + " msec: Hausdorff distance (relative, concurrent, point-to-point)");
System.out.println(measureHD(boy, girl, false, false, false, false) + " msec: Hausdorff distance (relative, sequential, point-to-tri)");
System.out.println(measureHD(boy, girl, false, true, false, false) + " msec: Hausdorff distance (relative, concurrent, point-to-tri)");
System.out.println(measureHD(boy, girl, false, false, print, true) + " msec: Hausdorff distance (relative, sequential, point-to-point)");
System.out.println(measureHD(boy, girl, false, true, print, true) + " msec: Hausdorff distance (relative, concurrent, point-to-point)");
System.out.println(measureHD(boy, girl, false, false, print, false) + " msec: Hausdorff distance (relative, sequential, point-to-tri)");
System.out.println(measureHD(boy, girl, false, true, print, false) + " msec: Hausdorff distance (relative, concurrent, point-to-tri)");
}
private static long measureKdTreeCreation(HumanFace face) {
......
package cz.fidentis.analyst.mesh.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -12,8 +15,10 @@ import java.util.stream.Collectors;
*/
public class CornerTable {
private List<CornerTableRow> rows = new ArrayList<>();
private final List<CornerTableRow> rows = new ArrayList<>();
private final Map<Integer, List<CornerTableRow>> vertexToRow = new HashMap<>();
/**
* Constructor of CornerTable
*/
......@@ -27,10 +32,12 @@ public class CornerTable {
* @param cornerTable copied CornerTable
*/
public CornerTable(CornerTable cornerTable) {
for (CornerTableRow row :
cornerTable.rows) {
for (CornerTableRow row : cornerTable.rows) {
rows.add(new CornerTableRow(row));
}
for (Integer i: cornerTable.vertexToRow.keySet()) {
vertexToRow.put(i, new ArrayList<>(cornerTable.vertexToRow.get(i)));
}
}
/**
......@@ -147,6 +154,11 @@ public class CornerTable {
*/
public void addRow(CornerTableRow row) {
rows.add(row);
int vIndex = row.getVertexIndex();
if (!vertexToRow.containsKey(vIndex)) {
vertexToRow.put(vIndex, new ArrayList<>());
}
vertexToRow.get(vIndex).add(row);
}
/**
......@@ -156,7 +168,18 @@ public class CornerTable {
* @param row new row
*/
public void replaceRow(int index, CornerTableRow row) {
CornerTableRow oldRow = rows.get(index);
int oldIndex = oldRow.getVertexIndex();
List<CornerTableRow> oldReferences = vertexToRow.get(oldIndex);
oldReferences.remove(oldRow);
rows.set(index, row);
int vIndex = row.getVertexIndex();
if (!vertexToRow.containsKey(vIndex)) {
vertexToRow.put(vIndex, new ArrayList<>());
}
vertexToRow.get(vIndex).add(row);
}
/**
......@@ -185,9 +208,10 @@ public class CornerTable {
* @return list of rows of corner table
*/
public List<CornerTableRow> getCornersByVertexIndex(int vertexIndex) {
return rows.stream()
.filter(corner -> corner.getVertexIndex() == vertexIndex)
.collect(Collectors.toList());
return Collections.unmodifiableList(vertexToRow.get(vertexIndex));
//return rows.stream()
// .filter(corner -> corner.getVertexIndex() == vertexIndex)
// .collect(Collectors.toList());
}
/**
......@@ -197,10 +221,14 @@ public class CornerTable {
* @return list of indexes of faces
*/
public List<Integer> getTriangleIndexesByVertexIndex(int vertexIndex) {
return rows.stream()
.filter(corner -> corner.getVertexIndex() == vertexIndex)
.map(corner -> getIndexOfFace(rows.indexOf(corner)))
List<CornerTableRow> vertexRows = vertexToRow.get(vertexIndex);
return vertexRows.stream()
.map(corner -> getIndexOfFace(vertexRows.indexOf(corner)))
.collect(Collectors.toList());
//return rows.stream()
// .filter(corner -> corner.getVertexIndex() == vertexIndex)
// .map(corner -> getIndexOfFace(rows.indexOf(corner)))
// .collect(Collectors.toList());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment