Skip to content
Snippets Groups Projects
Commit e20670fa authored by Matej Kovár's avatar Matej Kovár
Browse files

Merge branch 'master' into 113-introduce-new-features-on-list-of-faces-in-a-project

parents 0f7f9e0c c0329df4
No related branches found
No related tags found
No related merge requests found
Showing
with 720 additions and 93 deletions
......@@ -2,7 +2,7 @@ package cz.fidentis.analyst.face;
import com.google.common.eventbus.EventBus;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.services.FeaturePointImportExportService;
import cz.fidentis.analyst.feature.services.FeaturePointImportService;
import cz.fidentis.analyst.kdtree.KdTree;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshModel;
......@@ -192,7 +192,7 @@ public class HumanFace implements MeshListener, Serializable {
* @throws IOException on I/O failure
*/
public void loadFeaturePoints(String path, String fileName) throws IOException {
featurePoints = FeaturePointImportExportService.importFeaturePoints(path, fileName);
featurePoints = FeaturePointImportService.importFeaturePoints(path, fileName);
}
/**
......
......@@ -126,6 +126,13 @@
<artifactId>opencsv</artifactId>
<version>5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml/jaxb-api -->
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
package cz.fidentis.analyst.feature;
import java.io.Serializable;
import java.util.Objects;
import javax.vecmath.Point3d;
/**
*
* @author kubok
* @author Jakub Kolman
*/
public class FeaturePoint implements Serializable {
private final Point3d position;
private final FeaturePointType FEATURE_POINT_TYPE;
private final FeaturePointType featurePointType;
/**
* Constructor.
*
* @param x Location x
*
* @param x Location x
* @param y Location y
* @param z Location z
* @param featurePointType Original type
*/
public FeaturePoint(double x, double y, double z, FeaturePointType featurePointType) {
this.position = new Point3d(x, y, z);
this.FEATURE_POINT_TYPE = featurePointType;
this.featurePointType = featurePointType;
}
public Point3d getPosition() {
return position;
}
public double getX() {
return position.x;
}
......@@ -42,6 +43,44 @@ public class FeaturePoint implements Serializable {
}
public FeaturePointType getFeaturePointType() {
return FEATURE_POINT_TYPE;
return featurePointType;
}
@Override
public boolean equals(Object o) {
// self check
if (this == o) {
return true;
}
// null check
if (o == null) {
return false;
}
// type check and cast
if (getClass() != o.getClass()) {
return false;
}
FeaturePoint fp = (FeaturePoint) o;
// field comparison
return Objects.equals(position.x, fp.position.x)
&& Objects.equals(position.y, fp.position.y)
&& Objects.equals(position.z, fp.position.z)
&& Objects.equals(featurePointType.getCode(), fp.featurePointType.getCode())
&& Objects.equals(featurePointType.getInfo(), fp.featurePointType.getInfo())
&& Objects.equals(featurePointType.getName(), fp.featurePointType.getName())
&& Objects.equals(featurePointType.getType(), fp.featurePointType.getType());
}
/**
* generated hash code function
*
* @return
*/
@Override
public int hashCode() {
int hash = 5;
hash = 23 * hash + Objects.hashCode(this.position);
hash = 23 * hash + Objects.hashCode(this.featurePointType);
return hash;
}
}
......@@ -2,13 +2,25 @@ package cz.fidentis.analyst.feature;
import java.io.Serializable;
/**
* Class with basic structure of feature point
*
* @author Jakub Kolman
*/
public class FeaturePointType implements Serializable {
private final int type;
private final String name;
private final String info;
private final String code;
/**
* Constructor
*
* @param type
* @param name
* @param info
* @param code
*/
public FeaturePointType(int type, String name, String info, String code) {
this.type = type;
this.name = name;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cz.fidentis.analyst.feature.exception;
/**
*
* @author Jakub Kolman
*/
public class FeaturePointException extends RuntimeException {
/**
* Calls super method that throws exception with message parameter
* @param message
*/
public FeaturePointException(String message) {
super(message);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cz.fidentis.analyst.feature.provider;
import cz.fidentis.analyst.feature.FeaturePointType;
import cz.fidentis.analyst.feature.services.FeaturePointTypesService;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Feature point type provider class
*
* @author kubok
* @author Jakub Kolman
*/
public class FeaturePointTypeProvider {
public final class FeaturePointTypeProvider {
private final Map<Integer, FeaturePointType> featurePointTypesById;
private final Map<String, FeaturePointType> featurePointTypesByCode;
// provide thread safe singleton
private static class InstanceHolder {
public static FeaturePointTypeProvider instance = new FeaturePointTypeProvider();
/**
* provide thread safe singleton
*
* @author Jakub Kolman
*/
private static class InstanceHolder {
public static final FeaturePointTypeProvider INSTANCE = new FeaturePointTypeProvider();
}
/**
*
*/
private FeaturePointTypeProvider() {
FeaturePointTypesService service = new FeaturePointTypesService();
featurePointTypesById = service.readResources().orElse(new HashMap<>());
......@@ -33,26 +37,48 @@ public class FeaturePointTypeProvider {
/**
* Access feature point types
* @return
*
* @return
*/
public static FeaturePointTypeProvider getInstance() {
return InstanceHolder.instance;
return InstanceHolder.INSTANCE;
}
/**
* get feature points types by id
*
* @return
*/
public Map<Integer, FeaturePointType> getFeaturePointTypesById() {
return featurePointTypesById;
return Collections.unmodifiableMap(featurePointTypesById);
}
/**
* sorted feature point types by code
*
* @return
*/
public Map<String, FeaturePointType> getFeaturePointTypesByCode() {
return featurePointTypesByCode;
return Collections.unmodifiableMap(featurePointTypesByCode);
}
/**
* Get feature point by code
* get single feature point type by its code
*
* @param code
* @return
* @return
*/
public FeaturePointType getFeaturePointTypeByCode(String code) {
return getFeaturePointTypesByCode().get(code);
}
/**
* get single feature point type by its id
*
* @param id
* @return
*/
public FeaturePointType getFeaturePointTypeById(int id) {
return getFeaturePointTypesById().get(id);
}
}
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Class used to export feature points to file of csv format
*
* @author Jakub Kolman
*/
public class FeaturePointCsvExporter {
/**
* Exports a file to set location in csv format <br>
* File is located and named as {@param objectName}_landmarks.csv
*
* @param featurePointList
* @param objectName
* @throws IOException
*/
public static void exportFeaturePointsToCSV(List<FeaturePoint> featurePointList, String objectName) throws IOException {
File csvOutputFile = new File(String.format("%s_landmarks.csv", objectName));
writeToFile(featurePointList, csvOutputFile, objectName);
}
// /**
// * This method is only for testing purpose and saves the file only TEMPORARILY. <br>
// * <p>
// * Exports a file to set location for testing purpose. To permatently store feature points {@see exportFeaturePointsToCSV}
// *
// * @param featurePointList
// * @param objectName path + name of file
// * @throws IOException
// */
// public static void testExportFeaturePointsToCSV(List<FeaturePoint> featurePointList, String objectName) throws IOException {
//// File csvOutputFile = new File(String.format("%s_test_landmarks.csv", objectName));
// File csvOutputFile = File.createTempFile(String.format("%s_test_landmarks", objectName), "csv");
// writeToFile(featurePointList, csvOutputFile, objectName);
// }
/**
* Handles logic and format of exported csv file
*
* @param featurePointList
* @param csvOutputFile
* @param objectName
* @throws IOException
*/
public static void writeToFile(List<FeaturePoint> featurePointList, File csvOutputFile, String objectName) throws IOException {
// CSV is a normal text file, need a writer
try (BufferedWriter bw = new BufferedWriter(new FileWriter(csvOutputFile))) {
bw.write("Scan name");
featurePointList.forEach(featurePoint -> {
try {
bw.write(String.format(",%s x", featurePoint.getFeaturePointType().getCode()));
bw.write(String.format(",%s y", featurePoint.getFeaturePointType().getCode()));
bw.write(String.format(",%s z", featurePoint.getFeaturePointType().getCode()));
} catch (IOException ex) {
Logger.getLogger(FeaturePointCsvExporter.class.getName()).log(Level.SEVERE, null, ex);
}
});
bw.newLine();
bw.write(String.format("%s", objectName));
featurePointList.forEach(featurePoint -> {
try {
bw.write(",");
bw.write(Double.toString(featurePoint.getX()));
bw.write(",");
bw.write(Double.toString(featurePoint.getY()));
bw.write(",");
bw.write(Double.toString(featurePoint.getZ()));
} catch (IOException ex) {
Logger.getLogger(FeaturePointCsvExporter.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
}
}
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.provider.FeaturePointTypeProvider;
import cz.fidentis.analyst.feature.utils.FileResourcesUtils;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
/**
*
* @author kubok
* Class used to import feature points from file of csv format
*
* @author Jakub Kolman
*/
public class FeaturePointImportExportService {
public class FeaturePointCsvLoader {
private static final String COLUMN_DELIMETER = ",";
private static final String CODE_PREFIX_DELIMETER = " ";
public static List<FeaturePoint> importFeaturePoints(String path, String fileName) throws FileNotFoundException, IOException {
/**
* Loads feature points from file of csv format
* @param path
* @param fileName
* @return
* @throws FileNotFoundException
* @throws IOException
*/
public static List<FeaturePoint> loadFeaturePoints(String path, String fileName) throws FileNotFoundException, IOException {
FileResourcesUtils app = new FileResourcesUtils();
try (InputStreamReader streamReader
= new InputStreamReader(app.getFileAsStream(path, fileName), StandardCharsets.UTF_8);
......@@ -72,36 +71,4 @@ public class FeaturePointImportExportService {
private static String getCode(String str) {
return str.substring(0, str.indexOf(CODE_PREFIX_DELIMETER));
}
public static void exportFeaturePoints(List<FeaturePoint> featurePointList, String objectName) throws FileNotFoundException, IOException {
File csvOutputFile = new File(String.format("%s_landmarks.csv", objectName));
// CSV is a normal text file, need a writer
try (BufferedWriter bw = new BufferedWriter(new FileWriter(csvOutputFile))) {
bw.write("Scan name");
featurePointList.forEach(featurePoint -> {
try {
bw.write(String.format(",%s x", featurePoint.getFeaturePointType().getCode()));
bw.write(String.format(",%s y", featurePoint.getFeaturePointType().getCode()));
bw.write(String.format(",%s z", featurePoint.getFeaturePointType().getCode()));
} catch (IOException ex) {
Logger.getLogger(FeaturePointImportExportService.class.getName()).log(Level.SEVERE, null, ex);
}
});
bw.newLine();
bw.write(String.format("%s", objectName));
featurePointList.forEach(featurePoint -> {
try {
bw.write(",");
bw.write(Double.toString(featurePoint.getX()));
bw.write(",");
bw.write(Double.toString(featurePoint.getY()));
bw.write(",");
bw.write(Double.toString(featurePoint.getZ()));
} catch (IOException ex) {
Logger.getLogger(FeaturePointImportExportService.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
}
}
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.utils.FeaturePointFileFormatTypes;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
/**
* Class used for exporting feature points from file
*
* for more details @see
* cz.fidentis.analyst.feature.services.FeaturePointCsvExporter or @see
* cz.fidentis.analyst.feature.services.FeaturePointFpExporter
*
* @author Jakub Kolman
*/
public class FeaturePointExportService {
/**
* Method calls either @see FeaturePointCsvExporter or @see
* FeaturePointFpExporter based on the format given as parameter
*
* @param featurePointList
* @param objectName
* @param format
* @throws FileNotFoundException
* @throws IOException
*/
public void exportFeaturePoints(List<FeaturePoint> featurePointList, String objectName, String format) throws FileNotFoundException, IOException {
switch (format) {
case FeaturePointFileFormatTypes.FORMAT_TYPE_CSV:
FeaturePointCsvExporter.exportFeaturePointsToCSV(featurePointList, objectName);
break;
case FeaturePointFileFormatTypes.FORMAT_TYPE_FP:
FeaturePointFpExporter.exportFeaturePointsToFP(featurePointList, objectName);
break;
default:
break;
}
}
}
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Class used to export feature points to file of fp format
*
* @author Jakub Kolman
*/
public class FeaturePointFpExporter {
/**
* Exports feature points to file format fp at default location
*
* @param featurePointList
* @param objectName
* @throws FileNotFoundException
* @throws IOException
*/
public static void exportFeaturePointsToFP(List<FeaturePoint> featurePointList, String objectName) throws IOException {
File fpOutputFile = new File(String.format("%s_landmarks.fp", objectName));
writeToFile(featurePointList, fpOutputFile, objectName);
}
protected static void writeToFile(List<FeaturePoint> featurePointList, File fpOutputFile, String objectName) throws IOException {
// CSV is a normal text file, need a writer
try (BufferedWriter bw = new BufferedWriter(new FileWriter(fpOutputFile))) {
bw.write(String.format("<!--Saved by software Fidentis Analyst--><facialPoints model=\"%s\">", objectName));
featurePointList.forEach(featurePoint -> {
try {
bw.newLine();
bw.write(String.format("<facialPoint type=\"%s\">", featurePoint.getFeaturePointType().getType()));
bw.newLine();
bw.write(String.format("<x>%f</x>", featurePoint.getX()));
bw.newLine();
bw.write(String.format("<y>%f</y>", featurePoint.getY()));
bw.newLine();
bw.write(String.format("<z>%f</z>", featurePoint.getZ()));
} catch (IOException ex) {
Logger.getLogger(FeaturePointFpExporter.class.getName()).log(Level.SEVERE, null, ex);
}
});
bw.newLine();
bw.write("</facialPoints>");
}
}
}
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.exception.FeaturePointException;
import cz.fidentis.analyst.feature.provider.FeaturePointTypeProvider;
import cz.fidentis.analyst.feature.utils.FileResourcesUtils;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
* Class used to import feature points from file of fp format
*
* @author Jakub Kolman
*/
public class FeaturePointFpLoader {
private static final String GREATER_THAN_DELIMETER = ">";
private static final String LESS_THAN_DELIMETER = "<";
/**
* Loads feature points form given file
*
* @param path
* @param fileName
* @return List of FeaturePoint
* @throws FileNotFoundException
*/
public static List<FeaturePoint> loadFeaturePoints(String path, String fileName) throws FileNotFoundException {
FileResourcesUtils app = new FileResourcesUtils();
try (InputStreamReader streamReader
= new InputStreamReader(app.getFileAsStream(path, fileName), StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(streamReader)) {
Stream<String> lines = reader.lines();
List<String> linesList = new ArrayList<>();
lines.forEach(line -> {
linesList.add(line);
});
if (linesList.isEmpty()) {
throw new FeaturePointException(String.format("Feature point import file '%s' has wrong format", fileName));
}
List<FeaturePoint> points = new ArrayList<>();
for (int i = 1; i < linesList.size() - 6; i += 5) {
FeaturePoint point = new FeaturePoint(
Double.parseDouble(linesList.get(i + 1).substring(
linesList.get(i + 1).indexOf(GREATER_THAN_DELIMETER) + 1,
linesList.get(i + 1).indexOf(LESS_THAN_DELIMETER, linesList.get(i + 1).indexOf(GREATER_THAN_DELIMETER)))),
Double.parseDouble(linesList.get(i + 2).substring(
linesList.get(i + 2).indexOf(GREATER_THAN_DELIMETER) + 1,
linesList.get(i + 2).indexOf(LESS_THAN_DELIMETER, linesList.get(i + 2).indexOf(GREATER_THAN_DELIMETER)))),
Double.parseDouble(linesList.get(i + 3).substring(
linesList.get(i + 3).indexOf(GREATER_THAN_DELIMETER) + 1,
linesList.get(i + 3).indexOf(LESS_THAN_DELIMETER, linesList.get(i + 3).indexOf(GREATER_THAN_DELIMETER)))),
FeaturePointTypeProvider.getInstance().getFeaturePointTypeById(
Integer.parseInt(linesList.get(i).replaceAll("[^0-9]", "")))
);
points.add(point);
}
return points;
} catch (IOException e) {
throw new FeaturePointException(String.format("Feature point service cannot open file", fileName));
} catch (NumberFormatException e1) {
throw new FeaturePointException(e1.getMessage());
}
}
}
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.utils.FeaturePointFileFormatTypes;
import java.io.IOException;
import java.util.List;
/**
*
* @author Jakub Kolman
*/
public class FeaturePointImportService {
private static final String DELIMETER = ".";
/**
* Method calls either @see FeaturePointCsvLoader or @see
FeaturePointFpLoader based on the format taken out of filename
*
* @param path
* @param fileName
* @return
* @throws IOException
*/
public static List<FeaturePoint> importFeaturePoints(String path, String fileName) throws IOException {
String format = fileName.substring(fileName.lastIndexOf(DELIMETER) + 1);
switch (format.toUpperCase()) {
case (FeaturePointFileFormatTypes.FORMAT_TYPE_CSV):
return FeaturePointCsvLoader.loadFeaturePoints(path, fileName);
case (FeaturePointFileFormatTypes.FORMAT_TYPE_FP):
return FeaturePointFpLoader.loadFeaturePoints(path, fileName);
default:
return null;
}
}
}
......@@ -2,10 +2,11 @@ package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePointType;
import cz.fidentis.analyst.feature.utils.FileResourcesUtils;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
......@@ -13,6 +14,10 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
*
* @author Jakub Kolman
*/
public class FeaturePointTypesService {
private static final String FILE_NAME = "fp_text_default.csv";
......@@ -48,6 +53,7 @@ public class FeaturePointTypesService {
/**
* Creates map of feature point types
* @param featurePointTypes
* @return Optional map of feature point types mapped by code
*/
public Map<String, FeaturePointType> getFeaturepointTypesByCode(Map<Integer, FeaturePointType> featurePointTypes) {
......
package cz.fidentis.analyst.feature.utils;
/**
* Currently are available csv and fp formats. Rest can be added later.
*
* @author Jakub Kolman
*/
public class FeaturePointFileFormatTypes {
public static final String FORMAT_TYPE_OBJ = "OBJ";
public static final String FORMAT_TYPE_STL = "STL";
public static final String FORMAT_TYPE_PLY = "PLY";
public static final String FORMAT_TYPE_CSV = "CSV";
public static final String FORMAT_TYPE_FP = "FP";
public static final String FORMAT_TYPE_PP = "PP";
public static final String FORMAT_TYPE_PTS = "PTS";
public static final String FORMAT_TYPE_DTA = "DTA";
public static final String FORMAT_TYPE_PNG = "PNG";
public static final String FORMAT_TYPE_FID = "FID";
public static final String FORMAT_TYPE_NONE = "NONE";
/**
* enum containing all possible file formats of feature points
* @author Jakub Kolman
*/
enum FormatType {
OBJ,
STL,
PLY,
CSV,
FP,
PP,
PTS,
DTA,
PNG,
FID,
NONE
}
}
package cz.fidentis.analyst.feature.utils;
import java.io.*;
import java.net.URI;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
/**
* Deprecated class
*
* @author Jakub Kolman
*/
public class FileResourcesUtils {
/**
* main method
*
* @param args
* @throws IOException
* @throws URISyntaxException
*/
public static void main(String[] args) throws IOException, URISyntaxException {
FileResourcesUtils app = new FileResourcesUtils();
......@@ -27,8 +44,13 @@ public class FileResourcesUtils {
}
// get a file from the resources folder
// works everywhere, IDEA, unit test and JAR file.
/**
* get a file from the resources folder
* works everywhere, IDEA, unit test and JAR file.
*
* @param fileName
* @return
*/
public InputStream getFileFromResourceAsStream(String fileName) {
// The class loader that loaded the class
......@@ -44,12 +66,14 @@ public class FileResourcesUtils {
}
/*
The resource URL is not working in the JAR
If we try to access a file that is inside a JAR,
It throws NoSuchFileException (linux), InvalidPathException (Windows)
Resource URL Sample: file:java-io.jar!/json/file1.json
/**
* The resource URL is not working in the JAR If we try to access a file
* that is inside a JAR, It throws NoSuchFileException (linux),
* InvalidPathException (Windows)
*
* Resource URL Sample: file:java-io.jar!/json/file1.json
*
* @param fileName
*/
private File getFileFromResource(String fileName) throws URISyntaxException {
......@@ -66,17 +90,35 @@ public class FileResourcesUtils {
}
// get a file from the resources folder
// works everywhere, IDEA, unit test and JAR file.
/**
* get a file from the resources folder works everywhere, IDEA, unit test
* and JAR file.
*
* @param path
* @param fileName
* @return
* @throws FileNotFoundException
*/
public InputStream getFileAsStream(String path, String fileName) throws FileNotFoundException {
return new FileInputStream(getFile(path, fileName));
}
/**
* get File from path, file name
*
* @param path
* @param fileName
* @return
*/
private File getFile(String path, String fileName) {
return new File(path, fileName);
}
// print input stream
/**
* print input stream
*
* @param is
*/
private static void printInputStream(InputStream is) {
try (InputStreamReader streamReader
= new InputStreamReader(is, StandardCharsets.UTF_8);
......
......@@ -59,4 +59,4 @@ Type;Name;Info;Acronym
58;Supercilium Lateralis R;No information;SUL_R
59;Supercilium Lateralis L;No information;SUL_L
60;Supercilium Medialis R;No information;SUM_R
61;Supercilium Medialis L;No information;SUM_L
61;Supercilium Medialis L;No information;SUM_L
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.services.FeaturePointCsvLoader;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
/**
* @author Jakub Kolman
*/
public class FeaturePointExportServiceTest {
private static final Path MODEL_TEST_FILE_DIRECTORY = Paths.get("src", "test", "resources", "cz", "fidentis", "analyst", "feature", "services");
private static final String MODEL_FILE = "00007_01_landmarks.csv";
@DisplayName("Test writing a CSV file")
@Test
void exportFeaturePointsCSVTest() throws IOException {
// load model of feature points from file
FeaturePointCsvExporter service = new FeaturePointCsvExporter();
List<FeaturePoint> featurePoints = loadCsvFeaturePoints(MODEL_TEST_FILE_DIRECTORY.toString(), MODEL_FILE);
// create tmp file to write in
File csvOutputFile = File.createTempFile(String.format("%s_test_file_csv_landmarks", MODEL_TEST_FILE_DIRECTORY.toString()), "csv");
service.writeToFile(featurePoints, csvOutputFile, MODEL_TEST_FILE_DIRECTORY.toString() + "/" + "test_file_csv");
// check if model file and created file generate lists with the same elements
List<FeaturePoint> loadedFeaturePoints = loadCsvFeaturePoints(MODEL_TEST_FILE_DIRECTORY.toString(), "test_file_csv_landmarks.csv");
assertEquals(featurePoints.size(), loadedFeaturePoints.size());
assertEquals(featurePoints, loadedFeaturePoints);
assertNotSame(featurePoints, loadedFeaturePoints);
}
@DisplayName("Test writing a FP file")
@Test
void exportFeaturePointsFPTest() throws IOException {
// load model of feature points from file
FeaturePointFpExporter service = new FeaturePointFpExporter();
List<FeaturePoint> featurePoints = loadCsvFeaturePoints(MODEL_TEST_FILE_DIRECTORY.toString(), MODEL_FILE);
// create tmp file to write in
File fpOutputFile = File.createTempFile(String.format("%s_test_file_fp_landmarks", MODEL_TEST_FILE_DIRECTORY.toString()), "fp");
service.writeToFile(featurePoints, fpOutputFile, MODEL_TEST_FILE_DIRECTORY.toString() + "/" + "test_file_fp");
// check if model file and created file generate lists with the same elements
List<FeaturePoint> loadedFeaturePoints = loadFpFeaturePoints(MODEL_TEST_FILE_DIRECTORY.toString(), "test_file_fp_landmarks.fp");
assertEquals(featurePoints.size(), loadedFeaturePoints.size());
assertEquals(featurePoints, loadedFeaturePoints);
assertNotSame(featurePoints, loadedFeaturePoints);
}
private List<FeaturePoint> loadCsvFeaturePoints(String path, String fileName) throws IOException {
FeaturePointCsvLoader service = new FeaturePointCsvLoader();
List<FeaturePoint> featurePoints = service.loadFeaturePoints(MODEL_TEST_FILE_DIRECTORY.toString(), MODEL_FILE);
return featurePoints;
}
private List<FeaturePoint> loadFpFeaturePoints(String path, String fileName) throws IOException {
FeaturePointCsvLoader service = new FeaturePointCsvLoader();
List<FeaturePoint> featurePoints = service.loadFeaturePoints(MODEL_TEST_FILE_DIRECTORY.toString(), MODEL_FILE);
return featurePoints;
}
}
......@@ -2,6 +2,8 @@ package cz.fidentis.analyst.feature.services;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.provider.FeaturePointTypeProvider;
import cz.fidentis.analyst.feature.services.FeaturePointCsvLoader;
import cz.fidentis.analyst.feature.services.FeaturePointFpLoader;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
......@@ -15,22 +17,23 @@ import org.junit.jupiter.api.DisplayName;
*
* @author Jakub Kolman
*/
public class FeaturePointImportExportServiceTest {
public class FeaturePointImportServiceTest {
private static final Path testFileDirectory = Paths.get("src", "test", "resources", "cz", "fidentis", "analyst", "feature", "services");
private static final String TEST_CSV_FILE = "00007_01_landmarks.csv";
private static final String TEST_FP_FILE = "fp_head1_test.fp";
@DisplayName("Test if CSV file can be read")
@Test()
void fileExistsTest() throws IOException {
File testCsv = new File(testFileDirectory.toFile(), TEST_CSV_FILE);
assertTrue(testCsv.canRead());
}
@DisplayName("Test loading a CSV file")
@Test
void importFeaturePointsTest() throws IOException {
List<FeaturePoint> featurePoints = loadFeaturePoints();
void importFeaturePointsCSVTest() throws IOException {
List<FeaturePoint> featurePoints = FeaturePointCsvLoader.loadFeaturePoints(testFileDirectory.toString(), TEST_CSV_FILE);
assertTrue(featurePoints != null);
assertTrue(featurePoints.size() > 0);
assertTrue(featurePoints.get(0).getX() == -45.3298
......@@ -40,16 +43,46 @@ public class FeaturePointImportExportServiceTest {
FeaturePointTypeProvider.getInstance().getFeaturePointTypeByCode("EX_R"))
);
}
@DisplayName("Test writing a CSV file")
@DisplayName("Test loading a FP file")
@Test
void importFeaturePointsTest() throws IOException {
List<FeaturePoint> featurePoints = FeaturePointFpLoader.loadFeaturePoints(testFileDirectory.toString(), TEST_FP_FILE);
assertTrue(featurePoints != null);
assertTrue(featurePoints.size() > 0);
assertTrue(featurePoints.get(0).getX() == -40.429775
&& featurePoints.get(0).getY() == 45.756405
&& featurePoints.get(0).getZ() == 37.12462
&& featurePoints.get(0).getFeaturePointType().equals(
FeaturePointTypeProvider.getInstance().getFeaturePointTypeByCode("EX_R"))
);
}
@DisplayName("Test loading a FP file from generic service")
@Test
void exportFeaturePointsTest() throws IOException {
List<FeaturePoint> featurePoints = loadFeaturePoints();
FeaturePointImportExportService.exportFeaturePoints(featurePoints, "test_file");
void importFeaturePointsFpFromGenericServiceTest() throws IOException {
List<FeaturePoint> featurePoints = FeaturePointImportService.importFeaturePoints(testFileDirectory.toString(), TEST_FP_FILE);
assertTrue(featurePoints != null);
assertTrue(featurePoints.size() > 0);
assertTrue(featurePoints.get(0).getX() == -40.429775
&& featurePoints.get(0).getY() == 45.756405
&& featurePoints.get(0).getZ() == 37.12462
&& featurePoints.get(0).getFeaturePointType().equals(
FeaturePointTypeProvider.getInstance().getFeaturePointTypeByCode("EX_R"))
);
}
private List<FeaturePoint> loadFeaturePoints() throws IOException {
List<FeaturePoint> featurePoints = FeaturePointImportExportService.importFeaturePoints(testFileDirectory.toString(), TEST_CSV_FILE);
return featurePoints;
@DisplayName("Test loading a CSV file from generic service")
@Test
void importFeaturePointsCsvFromGenericServiceTest() throws IOException {
List<FeaturePoint> featurePoints = FeaturePointImportService.importFeaturePoints(testFileDirectory.toString(), TEST_CSV_FILE);
assertTrue(featurePoints != null);
assertTrue(featurePoints.size() > 0);
assertTrue(featurePoints.get(0).getX() == -45.3298
&& featurePoints.get(0).getY() == 37.1466
&& featurePoints.get(0).getZ() == -40.5415
&& featurePoints.get(0).getFeaturePointType().equals(
FeaturePointTypeProvider.getInstance().getFeaturePointTypeByCode("EX_R"))
);
}
}
......@@ -16,7 +16,6 @@ class FeaturePointTypeTypesServiceTest {
@DisplayName("Test loading a CSV file")
@Test
void readResourcesTest() {
FeaturePointTypesService service = new FeaturePointTypesService();
Optional<Map<Integer, FeaturePointType>> featurePointTypes = service.readResources();
assertTrue(featurePointTypes.isPresent());
......@@ -26,4 +25,8 @@ class FeaturePointTypeTypesServiceTest {
&& featurePointTypes.get().get(1).getCode().equals("EX_R"));
}
void aTest() {
FeaturePointTypesService service = new FeaturePointTypesService();
}
}
\ No newline at end of file
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