Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Analyst WebApp
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fidentis
Analyst WebApp
Commits
954410ee
There was an error fetching the commit references. Please try again later.
Commit
954410ee
authored
4 years ago
by
MakroCZ
Browse files
Options
Downloads
Patches
Plain Diff
Create MeshObjLoaderTest.java
parent
f8759b9c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MeshModel/src/test/java/cz/fidentis/analyst/mesh/io/MeshObjLoaderTest.java
+200
-0
200 additions, 0 deletions
...t/java/cz/fidentis/analyst/mesh/io/MeshObjLoaderTest.java
with
200 additions
and
0 deletions
MeshModel/src/test/java/cz/fidentis/analyst/mesh/io/MeshObjLoaderTest.java
0 → 100644
+
200
−
0
View file @
954410ee
package
cz.fidentis.analyst.mesh.io
;
import
com.mokiat.data.front.parser.IOBJParser
;
import
com.mokiat.data.front.parser.OBJDataReference
;
import
com.mokiat.data.front.parser.OBJFace
;
import
com.mokiat.data.front.parser.OBJMesh
;
import
com.mokiat.data.front.parser.OBJModel
;
import
com.mokiat.data.front.parser.OBJNormal
;
import
com.mokiat.data.front.parser.OBJObject
;
import
com.mokiat.data.front.parser.OBJParser
;
import
com.mokiat.data.front.parser.OBJTexCoord
;
import
com.mokiat.data.front.parser.OBJVertex
;
import
cz.fidentis.analyst.mesh.core.MeshFacet
;
import
cz.fidentis.analyst.mesh.core.MeshModel
;
import
cz.fidentis.analyst.mesh.core.MeshPoint
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.vecmath.Vector3d
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
/**
* Tests for {@link cz.fidentis.analyst.mesh.io.MeshObjLoader}
* @author Marek Barinka; 456295
*/
public
class
MeshObjLoaderTest
{
Path
testFileDirectory
=
Paths
.
get
(
"src"
,
"test"
,
"resources"
,
"cz"
,
"fidentis"
,
"analyst"
,
"mesh"
,
"io"
);
@Test
void
nullFileTest
()
throws
IOException
{
Exception
ex
=
assertThrows
(
NullPointerException
.
class
,
()
->
MeshObjLoader
.
read
((
File
)
null
));
}
@Test
void
nullStreamTest
()
throws
IOException
{
Exception
ex
=
assertThrows
(
NullPointerException
.
class
,
()
->
MeshObjLoader
.
read
((
InputStream
)
null
));
}
@Test
()
void
emptyFileTest
()
throws
IOException
{
File
empty
=
new
File
(
testFileDirectory
.
toFile
(),
"Empty.obj"
);
Exception
ex
=
assertThrows
(
IOException
.
class
,
()
->
MeshObjLoader
.
read
(
empty
));
assertTrue
(
ex
.
getMessage
().
contains
(
"File doesn't contain any model"
));
}
@Test
void
moreObjectFileTest
()
{
//TODO: Not testing in loader
File
moreObjects
=
new
File
(
testFileDirectory
.
toFile
(),
"MoreObjects.obj"
);
Exception
ex
=
assertThrows
(
IOException
.
class
,
()
->
MeshObjLoader
.
read
(
moreObjects
));
}
@Test
void
nonTriangularFaceAloneTest
()
{
File
plane
=
new
File
(
testFileDirectory
.
toFile
(),
"Plane.obj"
);
Exception
ex
=
assertThrows
(
IOException
.
class
,
()
->
MeshObjLoader
.
read
(
plane
));
assertTrue
(
ex
.
getMessage
().
contains
(
"Mesh contains non-triangular face"
));
}
@Test
void
nonTriangularFaceInTriangularModelTest
()
{
File
icoSphereQuad
=
new
File
(
testFileDirectory
.
toFile
(),
"IcoSphere-withQuad.obj"
);
Exception
ex
=
assertThrows
(
IOException
.
class
,
()
->
MeshObjLoader
.
read
(
icoSphereQuad
));
assertTrue
(
ex
.
getMessage
().
contains
(
"Mesh contains non-triangular face"
));
}
@Test
void
validFileIcoSphereTest
()
throws
IOException
{
File
icoSphere
=
new
File
(
testFileDirectory
.
toFile
(),
"IcoSphere-Triangles.obj"
);
MeshModel
m
=
MeshObjLoader
.
read
(
icoSphere
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getCornerTable
().
getSize
(),
240
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getNumberOfVertexes
(),
240
);
assertEquals
(
m
.
getFacets
().
size
(),
1
);
OBJModel
model
;
final
IOBJParser
parser
=
new
OBJParser
();
try
(
InputStream
is
=
new
FileInputStream
(
icoSphere
))
{
model
=
parser
.
parse
(
is
);
}
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
Set
<
MeshPoint
>
points
=
getPointsInObject
(
model
,
object
);
MeshFacet
facet
=
m
.
getFacets
().
get
(
0
);
for
(
int
i
=
0
;
i
<
facet
.
getNumberOfVertexes
();
i
++)
{
MeshPoint
p
=
facet
.
getVertex
(
i
);
assertTrue
(
points
.
contains
(
p
));
}
}
@Test
void
validStreamTest
()
throws
FileNotFoundException
,
IOException
{
File
icoSphere
=
new
File
(
testFileDirectory
.
toFile
(),
"IcoSphere-Triangles.obj"
);
MeshModel
m
;
try
(
InputStream
is
=
new
FileInputStream
(
icoSphere
))
{
m
=
MeshObjLoader
.
read
(
is
);
}
assertEquals
(
m
.
getFacets
().
get
(
0
).
getCornerTable
().
getSize
(),
240
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getNumberOfVertexes
(),
240
);
assertEquals
(
m
.
getFacets
().
size
(),
1
);
OBJModel
model
;
final
IOBJParser
parser
=
new
OBJParser
();
try
(
InputStream
is
=
new
FileInputStream
(
icoSphere
))
{
model
=
parser
.
parse
(
is
);
}
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
Set
<
MeshPoint
>
points
=
getPointsInObject
(
model
,
object
);
MeshFacet
facet
=
m
.
getFacets
().
get
(
0
);
for
(
int
i
=
0
;
i
<
facet
.
getNumberOfVertexes
();
i
++)
{
MeshPoint
p
=
facet
.
getVertex
(
i
);
assertTrue
(
points
.
contains
(
p
));
}
}
@Test
void
validFileTetrahedronTest
()
throws
IOException
{
File
tetrahedron
=
new
File
(
testFileDirectory
.
toFile
(),
"tetrahedron.obj"
);
MeshModel
m
=
MeshObjLoader
.
read
(
tetrahedron
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getCornerTable
().
getSize
(),
12
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getNumberOfVertexes
(),
12
);
assertEquals
(
m
.
getFacets
().
size
(),
1
);
OBJModel
model
;
final
IOBJParser
parser
=
new
OBJParser
();
try
(
InputStream
is
=
new
FileInputStream
(
tetrahedron
))
{
model
=
parser
.
parse
(
is
);
}
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
Set
<
MeshPoint
>
points
=
getPointsInObject
(
model
,
object
);
MeshFacet
facet
=
m
.
getFacets
().
get
(
0
);
for
(
int
i
=
0
;
i
<
facet
.
getNumberOfVertexes
();
i
++)
{
MeshPoint
p
=
facet
.
getVertex
(
i
);
assertTrue
(
points
.
contains
(
p
));
}
}
@Test
void
validFileIco20Test
()
throws
IOException
{
File
ico20
=
new
File
(
testFileDirectory
.
toFile
(),
"IcoSphere-20.obj"
);
MeshModel
m
=
MeshObjLoader
.
read
(
ico20
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getCornerTable
().
getSize
(),
60
);
assertEquals
(
m
.
getFacets
().
get
(
0
).
getNumberOfVertexes
(),
60
);
assertEquals
(
m
.
getFacets
().
size
(),
1
);
OBJModel
model
;
final
IOBJParser
parser
=
new
OBJParser
();
try
(
InputStream
is
=
new
FileInputStream
(
ico20
))
{
model
=
parser
.
parse
(
is
);
}
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
Set
<
MeshPoint
>
points
=
getPointsInObject
(
model
,
object
);
MeshFacet
facet
=
m
.
getFacets
().
get
(
0
);
for
(
int
i
=
0
;
i
<
facet
.
getNumberOfVertexes
();
i
++)
{
MeshPoint
p
=
facet
.
getVertex
(
i
);
assertTrue
(
points
.
contains
(
p
));
}
}
private
Set
<
MeshPoint
>
getPointsInObject
(
OBJModel
model
,
OBJObject
object
)
{
Set
<
MeshPoint
>
points
=
new
HashSet
();
for
(
OBJMesh
mesh
:
object
.
getMeshes
())
{
for
(
OBJFace
face
:
mesh
.
getFaces
())
{
for
(
OBJDataReference
reference
:
face
.
getReferences
())
{
final
OBJVertex
vertex
=
model
.
getVertex
(
reference
);
Vector3d
coords
=
new
Vector3d
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
Vector3d
norm
=
null
;
Vector3d
texCoords
=
null
;
if
(
reference
.
hasNormalIndex
())
{
final
OBJNormal
normal
=
model
.
getNormal
(
reference
);
norm
=
new
Vector3d
(
normal
.
x
,
normal
.
y
,
normal
.
z
);
}
if
(
reference
.
hasTexCoordIndex
())
{
final
OBJTexCoord
texCoord
=
model
.
getTexCoord
(
reference
);
texCoords
=
new
Vector3d
(
texCoord
.
u
,
texCoord
.
v
,
texCoord
.
w
);
}
points
.
add
(
new
MeshPoint
(
coords
,
norm
,
texCoords
));
}
}
}
return
points
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment