Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
8b15296
basic classes for builder
Ekatereana Jun 2, 2019
ce13b51
parsing classes
Ekatereana Jun 2, 2019
6e9a32e
fix problems with import
Ekatereana Jun 2, 2019
ca6d511
test for parsing
Ekatereana Jun 2, 2019
b534f22
fix problem with fileReader
Ekatereana Jun 2, 2019
bdf1406
Delete LibertStatue.mtl
Ekatereana Jun 2, 2019
dd94b1b
Delete Liberty-PortaBronzo-1.bmp
Ekatereana Jun 2, 2019
fef4e13
Delete LibertStatue.obj
Ekatereana Jun 2, 2019
de2b0a6
Delete Liberty-Pavimentazione-1.bmp
Ekatereana Jun 2, 2019
218e69b
Delete Liberty-DecorazioniMarmo-2.bmp
Ekatereana Jun 2, 2019
f1f2747
Delete Liberty-MattoniBasamento-1.bmp
Ekatereana Jun 2, 2019
1bd4568
Delete Liberty-GreenBronze-1.bmp
Ekatereana Jun 2, 2019
d8ec335
fix problem with fileReader
Ekatereana Jun 2, 2019
4d61c0e
Merge branch 'loadingOBJ' of https://github.com/Brookoko/ProgrammingA…
Ekatereana Jun 2, 2019
939b627
fix problem with comments
Ekatereana Jun 2, 2019
c3d68f2
fix problem with tests
Ekatereana Jun 2, 2019
a1fc82c
fix problem with public variables
Ekatereana Jun 4, 2019
8077705
Delete misc.xml
Ekatereana Jun 8, 2019
c36d3b3
Delete modules.xml
Ekatereana Jun 8, 2019
e4d8ecd
Delete vcs.xml
Ekatereana Jun 8, 2019
70e15b6
Delete workspace.xml
Ekatereana Jun 8, 2019
8f12919
add comments to (ParserObj)
Ekatereana Jun 8, 2019
b8a83b2
Merge branch 'loadingOBJ' of https://github.com/Brookoko/ProgrammingA…
Ekatereana Jun 8, 2019
2925c07
add test for vertex part (test.com.*.builder.vertexTest)
Ekatereana Jun 8, 2019
6643c14
Merge branch 'dev' into loadingOBJ
Ekatereana Jun 8, 2019
25af686
add test for vertex part (test.com.*.builder.vertexTest)
Ekatereana Jun 8, 2019
51d8654
fix test for vertex part (test.com.*.builder.vertexTest)
Ekatereana Jun 8, 2019
fc72c0e
fix test for vertex part (test.com.*.builder.vertexTest)
Ekatereana Jun 8, 2019
64033c4
add test for vertex part (test.com.*.builder.vertexTest)
Ekatereana Jun 9, 2019
0e828a2
Delete ProgrammingAssignment5.iml
Ekatereana Jun 9, 2019
fda2ca9
Delete workspace.xml
Ekatereana Jun 9, 2019
3178b35
fix problem (BuilderInterface)
Ekatereana Jun 9, 2019
66861e8
add class Vector2 (geometry)
Ekatereana Jun 9, 2019
61859ca
Delete VertexNormal.java
Ekatereana Jun 9, 2019
4ffe1d3
Delete VertexGeometry.java
Ekatereana Jun 9, 2019
f0b1352
Delete VertexTexture.java
Ekatereana Jun 9, 2019
1bc691a
Merge branch 'loadingOBJ' of https://github.com/Brookoko/ProgrammingA…
Ekatereana Jun 9, 2019
e3c2274
fix problems with (Vector2)
Ekatereana Jun 9, 2019
a006efa
rewrite methods in (StringUtils)
Ekatereana Jun 10, 2019
5e51f6f
rewrite methods in (StringUtils)
Ekatereana Jun 10, 2019
992b205
fix problems with test
Ekatereana Jun 10, 2019
89ad6eb
Merge branch 'dev' into loadingOBJ
Ekatereana Jun 10, 2019
3740f6f
fix problems with test
Ekatereana Jun 10, 2019
3df79dd
Merge branch 'loadingOBJ' of https://github.com/Brookoko/ProgrammingA…
Ekatereana Jun 10, 2019
54b064e
rewrite basic classes.
Ekatereana Jun 10, 2019
ab29af5
Delete FacePlate.java
Ekatereana Jun 10, 2019
7291b07
Delete Material.java
Ekatereana Jun 10, 2019
b23c40c
Delete ReflectivityTransmission.java
Ekatereana Jun 10, 2019
d902577
Delete VertexFace.java
Ekatereana Jun 10, 2019
12a7b47
Delete BuilderInterface.java
Ekatereana Jun 10, 2019
7996e6d
Delete LoadDataFromParserObject.java
Ekatereana Jun 10, 2019
07e0edf
Delete BuilderTest.java
Ekatereana Jun 10, 2019
39140c2
Delete FacePlateTests.java
Ekatereana Jun 10, 2019
e6ecab3
Merge branch 'loadingOBJ' of https://github.com/Brookoko/ProgrammingA…
Ekatereana Jun 10, 2019
62752d8
add polygonNormal for three vertex (PolygonObject)
Ekatereana Jun 11, 2019
cca92ff
Delete Vector2.java
Ekatereana Jun 11, 2019
900db34
add polygonObject (PolygonObject)
Ekatereana Jun 11, 2019
9aff9a2
add crossProduct to polygon
Ekatereana Jun 11, 2019
65d2d43
add subtract to polygon
Ekatereana Jun 11, 2019
41ee8cd
rewrite input parameter in parseObj in (ParseObjFile).
Ekatereana Jun 11, 2019
8ff6050
add tests for StringUtils
Ekatereana Jun 11, 2019
ca39cbe
fix testes
Ekatereana Jun 11, 2019
a027cd7
fix problem with resources file
Ekatereana Jun 11, 2019
eb6a4a6
add more assertion to ParseObjFileTest
Ekatereana Jun 11, 2019
c2fbbb6
rewrite main
Ekatereana Jun 11, 2019
9771dae
rewrite main
Ekatereana Jun 11, 2019
99bbd54
rewrite main
Ekatereana Jun 11, 2019
7fce926
rewrite main
Ekatereana Jun 11, 2019
02d1146
Merge branch 'dev' into loadingOBJ
Ekatereana Jun 11, 2019
01ef578
rewrite empty line
Ekatereana Jun 11, 2019
740d222
Merge branch 'loadingOBJ' of https://github.com/Brookoko/ProgrammingA…
Ekatereana Jun 11, 2019
a00fe4b
rewrite empty line
Ekatereana Jun 11, 2019
a272d22
Merge branch 'dev' into loadingOBJ
Ekatereana Jun 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package labs.introtoprogramming.lab5.object.Parser;

import labs.introtoprogramming.lab5.geometry.Vector3;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;

public class ParseObjFile {
private Logger log = Logger.getLogger(ParseObjFile.class.getName());
/**
* String indicators of parameter in .obj file.
*/
private final static String OBJ_VERTEX_NORMAL = "vn";
private final static String OBJ_VERTEX = "v";
private final static String OBJ_FACE = "f";
private List<Vector3> verticesNormals = new ArrayList<>();
private List<Vector3> verticesGeometry = new ArrayList<>();
private PolygonObject polygonObject = null;

public ParseObjFile(InputStream is) throws FileNotFoundException, IOException {
polygonObject = new PolygonObject();
parseObjFile(is);
}
/**
* This is part to parse object file
* @param is
* @throws FileNotFoundException
* @throws IOException
*/
private void parseObjFile(InputStream is) throws IOException {
int lineCount = 0;
InputStreamReader fileReader;
BufferedReader bufferedReader;
fileReader = new InputStreamReader(is, "UTF-8");
bufferedReader = new BufferedReader(fileReader);
String line;

// read .obj file
while ((line = bufferedReader.readLine()) != null) {
line = line.trim();

if (line.length() == 0) {
continue;
}

// cases to process
if (line.startsWith("#")) {
continue;
} else if (line.startsWith(OBJ_VERTEX_NORMAL)) {
processVertexNormal(line);
// add vertex with some coordinates
} else if (line.startsWith(OBJ_VERTEX)) {
processVertex(line);
} else if (line.startsWith(OBJ_FACE)) {
processFace(line);
} else {
log.log(WARNING, "line " + lineCount + " unknown line |" + line + "|");
}
lineCount++;
}
bufferedReader.close();

log.log(INFO, "Loaded " + lineCount + " lines");
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this empty line

public PolygonObject getPolygonObject() {
return polygonObject;
}
/**
* Create vertex( just coordinates of each one) from data of file.
* @param line
*/
private void processVertex(String line) {
String[] values = line.split(" ");
float[] result = new float[3];
for (int i = 2; i < values.length; i++) {
result[i - 2] = Float.parseFloat(values[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking into account Vector3 uses Double, maybe change to Double here?

}
verticesGeometry.add(new Vector3(result[0], result[1], result[2]));
}
/**
* Create normal-data of vertex
* @param line
*/
private void processVertexNormal(String line) {
String[] values = line.split(" ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block repeats. Maybe create parseLineToVector3(String line, int offset)?

float[] result = new float[3];
for (int i = 2; i < values.length; i++) {
result[i - 2] = Float.parseFloat(values[i]);
}
verticesNormals.add(new Vector3(result[0], result[1], result[2]));
}


private void processFace(String line) {
line = line.substring(OBJ_FACE.length()).trim();
Integer[] vertexIndexAry = StringUtils.parseCodeLine(line);
addPolygon(vertexIndexAry);
}

public void addPolygon(Integer[] vertexIndices) {
Polygon polygon = new Polygon();

int indexOfStructure = 0;
Vertex fv;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable can be moved inside while loop


while (indexOfStructure + 2 < vertexIndices.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short explanation would be nice here


fv = new Vertex();
fv.setVertexG(verticesGeometry.get(vertexIndices[indexOfStructure] - 1));
if (vertexIndices[indexOfStructure + 2] != null) {
indexOfStructure++;
}
fv.setVertexN(verticesNormals.get(vertexIndices[++indexOfStructure] - 1));
polygonObject.addVertex(fv);
polygon.addVertex(fv);
indexOfStructure += 2;
}
polygon.calculatePolygonNormalTriangle();
polygonObject.addPolygon(polygon);
}

public List<Vector3> getVerticesNormals() {
return verticesNormals;
}

public List<Vector3> getVerticesGeometry() {
return verticesGeometry;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package labs.introtoprogramming.lab5.object.Parser;

import labs.introtoprogramming.lab5.geometry.Vector3;

import java.util.ArrayList;
import java.util.List;

public class Polygon {
private List<Vertex> vertices = new ArrayList<>();
private Vector3 polygonNormal;
public List<Vertex> getVertices() {
return vertices;
}

public void setVertecies(ArrayList<Vertex> vertices) {
this.vertices = vertices;
}

public void addVertex(Vertex vertex) {vertices.add(vertex);}

public void setVertices(ArrayList<Vertex> vertices) {
this.vertices = vertices;
}

public Vector3 getPolygonNormal() {
return polygonNormal;
}

public void calculatePolygonNormalTriangle() {
if (vertices.size() == 3) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line

Vector3 fromOneToTwo = vertices.get(0).getVertexG().subtract(vertices.get(1).getVertexG());
Vector3 fromOneToThree = vertices.get(0).getVertexG().subtract(vertices.get(2).getVertexG());
polygonNormal = fromOneToTwo.crossProduct(fromOneToThree);
}
}

public void setPolygonNormal(Vector3 polygonNormal) {
this.polygonNormal = polygonNormal;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package labs.introtoprogramming.lab5.object.Parser;

import labs.introtoprogramming.lab5.scene.SceneObject;

import java.util.ArrayList;
import java.util.List;

public class PolygonObject extends SceneObject {
private List<Vertex> vertices = new ArrayList<>();
private List<Polygon> polygons = new ArrayList<>();
public List<Vertex> getVertices() {
return vertices;
}
public List<Polygon> getPolygons() {
return polygons;
}

public void addVertex(Vertex vertex) {
vertices.add(vertex);
}

public void addPolygon(Polygon polygon) {
polygons.add(polygon);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package labs.introtoprogramming.lab5.object.Parser;

import java.util.logging.Logger;

public class StringUtils {
private static Logger log = Logger.getLogger(StringUtils.class.getName());

public static Integer[] parseCodeLine(String list) {
if (list == null) {
return null;
}
if (list.equals("")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmpty()

return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use Optional? Returning null does not seem like a good idea to me.

}
String[] temp;
String[] vertexStrings = list.split(" ");
temp = vertexStrings[0].split("/");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String[] temp = ...

boolean mark = true;
if (!temp[1].equals("")) {
mark = false;
}
Integer[] parsed = new Integer[vertexStrings.length * 3];

int j = 0;
for (int i = 0; i < vertexStrings.length; i++) {
if (mark) {
temp = vertexStrings[i].split("//");
parsed[j] = Integer.parseInt(temp[0]);
parsed[++j] = Integer.parseInt(temp[1]);
} else {
temp = vertexStrings[i].split("/");
parsed[j] = Integer.parseInt(temp[0]);
parsed[++j] = Integer.parseInt(temp[2]);
}
parsed[++j] = null;
j++;
}
return parsed;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package labs.introtoprogramming.lab5.object.Parser;

import labs.introtoprogramming.lab5.geometry.Vector3;

public class Vertex {
/**
* Vertex parameters: geometry coordinates and coordinates of normals
*/
private Vector3 vertexG = null;
private Vector3 vertexN = null;

public void setVertexG(Vector3 vertexG) {
this.vertexG = vertexG;
}

public void setVertexN(Vector3 vertexN) {
this.vertexN = vertexN;
}

public Vector3 getVertexG() {
return vertexG;
}

public Vector3 getVertexN() {
return vertexN;
}

public String toString() {
return vertexG + "|" + vertexN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package labs.introtoprogramming.lab5.object.Parser;

import labs.introtoprogramming.lab5.geometry.Vector3;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;

public class ParseObjFileTest {
private static final double DELTA = 1e-10;

@Test
public void ParseTest() throws IOException {
//4//4 5//5 18//18 17//17
ParseObjFile obj = new ParseObjFile(
ParseObjFileTest.class.getResourceAsStream("/LibertStatue.obj"));
Vector3 geometry = obj.getVerticesGeometry().get(4);
Polygon polygon = obj.getPolygonObject().getPolygons().get(4);
Vector3 findGeometry = polygon.getVertices().get(0).getVertexG();
assertEquals(geometry.x, findGeometry.x, DELTA);
obj.getPolygonObject().toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package labs.introtoprogramming.lab5.object.Parser;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class StringUtilsTest {
private static final double DELTA = 1e-10;

@Test
public void testStringUtil() {
String firstLine = "1//2 1//3 1//5";
String secondLine = "1/4/2 1/7/3 1/2/5";
Integer[] firstArr = StringUtils.parseCodeLine(firstLine);
Integer[] secondArr = StringUtils.parseCodeLine(secondLine);
assertEquals(1, secondArr[0], DELTA);
assertEquals(1, secondArr[0], DELTA);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package labs.introtoprogramming.lab5.object.Parser;

import labs.introtoprogramming.lab5.geometry.Vector3;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class VertexTest {
private static final double DELTA = 1e-10;

@Test
public void testVertex() {
Vertex vertex = new Vertex();
vertex.setVertexN(new Vector3(0, 0, 0));
vertex.setVertexG(new Vector3(1, 1, 1));
assertEquals(1, vertex.getVertexG().x, DELTA);
assertEquals(0, vertex.getVertexN().x, DELTA);
vertex.toString();
}
}
Loading