Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Protos
Nomad 3D
nomad-3d-commons
Commits
1cb4418a
Commit
1cb4418a
authored
Jun 16, 2017
by
Ivan Dages
Browse files
levels of detail
parent
4dcc66fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/n3d/io/Nomad3DExporter.java
View file @
1cb4418a
...
...
@@ -53,8 +53,24 @@ public class Nomad3DExporter {
// Create document
Element
eNomad3D
=
doc
.
createElement
(
"Nomad3DXML"
);
eNomad3D
.
setAttribute
(
"state"
,
model
.
getState
().
next
().
toString
());
Element
eRoot
=
writeComponent
(
model
.
getRoot
(),
doc
);
eNomad3D
.
appendChild
(
eRoot
);
Element
eGeometriesDirs
=
doc
.
createElement
(
"GeometriesDirectories"
);
String
[]
dirs
=
{
// from the most detailed to the coarsest
"exported"
,
"decimated"
,
"convex_hull"
};
for
(
int
i
=
0
;
i
<
dirs
.
length
;
i
++)
{
Element
eDir
=
doc
.
createElement
(
"Directory"
);
eDir
.
setAttribute
(
"lod"
,
Integer
.
toString
(
i
));
eDir
.
setTextContent
(
dirs
[
i
]);
eGeometriesDirs
.
appendChild
(
eDir
);
}
eNomad3D
.
appendChild
(
eGeometriesDirs
);
doc
.
appendChild
(
eNomad3D
);
doc
.
setXmlVersion
(
"1.0"
);
...
...
src/main/java/fr/ill/ics/n3d/io/Nomad3DImporter.java
View file @
1cb4418a
...
...
@@ -30,6 +30,7 @@ import fr.ill.ics.n3d.model.Model;
import
fr.ill.ics.n3d.model.ParallelMate
;
import
fr.ill.ics.n3d.model.PerpendicularMate
;
import
fr.ill.ics.n3d.model.TangentMate
;
import
fr.ill.ics.n3d.model.Model.State
;
import
javafx.geometry.Insets
;
import
javafx.geometry.Point3D
;
import
javafx.geometry.Pos
;
...
...
@@ -123,7 +124,7 @@ public class Nomad3DImporter {
Logger
.
getLogger
(
"nomad-3d"
).
severe
(
e
.
getMessage
()
+
"\n"
);
}
}
/**
* Reads a Nomad 3D model. A dialog box is used to select the xml file.
*/
...
...
@@ -159,10 +160,13 @@ public class Nomad3DImporter {
private
void
readModel
(
Document
doc
,
String
dirPath
)
throws
XMLParseException
{
Element
eNomad3D
=
(
Element
)
doc
.
getElementsByTagName
(
"Nomad3DXML"
).
item
(
0
);
Model
.
State
state
=
Model
.
State
.
fromString
(
eNomad3D
.
getAttribute
(
"state"
));
this
.
model
.
setState
(
state
);
Element
eRoot
=
(
Element
)
eNomad3D
.
getElementsByTagName
(
"RootComponent"
).
item
(
0
);
Component
root
=
readComponent
(
eRoot
,
dirPath
);
this
.
model
.
setRoot
(
root
);
this
.
model
.
setState
(
state
);
if
(
state
!=
State
.
EXPORTED
)
{
readGeometriesDirectories
(
eNomad3D
);
}
}
/**
...
...
@@ -205,10 +209,14 @@ public class Nomad3DImporter {
}
}
if
(
component
.
isLeaf
())
{
File
stlFile
=
new
File
(
dirPath
,
fileName
+
".STL"
);
if
(!
stlFile
.
exists
())
{
return
null
;
/* TODO do this if model.state == EXPORTED
*/
if
(
model
.
getState
()
==
State
.
EXPORTED
)
{
if
(
component
.
isLeaf
())
{
File
stlFile
=
new
File
(
dirPath
,
fileName
+
".STL"
);
if
(!
stlFile
.
exists
())
{
return
null
;
}
}
}
...
...
@@ -612,6 +620,24 @@ public class Nomad3DImporter {
config
.
addMate
(
mate
);
}
/**
* Reads the geometries directories and store them in the model.
* @param eNomad3D XML element of the model
*/
private
void
readGeometriesDirectories
(
Element
eNomad3D
)
{
Element
eGeomDirs
=
(
Element
)
eNomad3D
.
getElementsByTagName
(
"GeometriesDirectories"
).
item
(
0
);
NodeList
dirList
=
eGeomDirs
.
getChildNodes
();
for
(
int
i
=
0
;
i
<
dirList
.
getLength
()
;
i
++)
{
Node
nDir
=
dirList
.
item
(
i
);
if
(
nDir
.
getNodeType
()
==
Node
.
ELEMENT_NODE
&&
nDir
.
getNodeName
().
equals
(
"Directory"
))
{
Element
eDir
=
(
Element
)
nDir
;
Integer
lod
=
Integer
.
parseInt
(
eDir
.
getAttribute
(
"lod"
));
String
dirName
=
eDir
.
getTextContent
();
this
.
model
.
addGeometryDirectory
(
lod
,
dirName
);
}
}
}
/**
* Prints the memory usage of the application. For debug purpose.
*/
...
...
src/main/java/fr/ill/ics/n3d/model/Component.java
View file @
1cb4418a
...
...
@@ -533,9 +533,9 @@ public class Component {
* @param recursive true to toggle the focus selection of the descendants
*/
public
void
focusSelection
(
CopyOnWriteArraySet
<
Component
>
selection
,
boolean
focusSelection
,
String
configName
,
boolean
recursive
)
{
this
.
sceneNode
.
setVisible
(
(
!
this
.
isLeaf
()
||
(
focusSelection
&&
selection
.
contains
(
this
))
||
!
focusSelection
)
&&
getConfigurationByName
(
configName
).
isVisible
()
);
this
.
setVisible
(!
this
.
isLeaf
()
||
(
focusSelection
&&
selection
.
contains
(
this
))
||
!
focusSelection
,
configName
,
false
);
if
(
recursive
)
{
for
(
Component
child
:
this
.
children
)
{
child
.
focusSelection
(
selection
,
focusSelection
,
configName
,
recursive
);
...
...
@@ -680,8 +680,9 @@ public class Component {
* Compute the scene tree of this component's hierarchy, for the specified configuration.
* @param model Model owning the component
* @param configName Name of the configuration
* @param lod Level of detail of the displayed mesh
*/
void
computeSceneHierarchy
(
Model
model
,
String
configName
)
{
void
computeSceneHierarchy
(
Model
model
,
String
configName
,
int
lod
)
{
ConfigParams
config
=
getConfigurationByName
(
configName
);
if
(
config
==
null
)
{
Logger
.
getLogger
(
"nomad-3d"
).
severe
(
"Cannot find configuration "
+
configName
+
" in component "
+
this
.
name
);
...
...
@@ -704,7 +705,7 @@ public class Component {
if
(
this
.
children
.
isEmpty
())
{
String
stlPath
=
this
.
fileName
+
".STL"
;
File
stlFile
=
new
File
(
model
.
getDirectoryPath
(),
stlPath
);
File
stlFile
=
new
File
(
model
.
getDirectoryPath
()
+
File
.
separator
+
model
.
getGeometryDirectory
(
lod
)
,
stlPath
);
MeshView
meshView
=
importMesh
(
model
,
stlFile
);
this
.
setSceneNode
(
meshView
);
}
else
{
...
...
@@ -726,7 +727,7 @@ public class Component {
}
for
(
Component
child
:
this
.
children
)
{
child
.
computeSceneHierarchy
(
model
,
configName
);
child
.
computeSceneHierarchy
(
model
,
configName
,
lod
);
}
}
...
...
@@ -843,9 +844,10 @@ public class Component {
/**
* Compute the scene tree of this component's hierarchy, for the first configuration in its configuration list.
* @param model Model owning the component
* @param lod Level of detail
*/
void
computeSceneHierarchy
(
Model
model
)
{
computeSceneHierarchy
(
model
,
this
.
configurations
.
get
(
0
).
getConfiguration
());
void
computeSceneHierarchy
(
Model
model
,
int
lod
)
{
computeSceneHierarchy
(
model
,
this
.
configurations
.
get
(
0
).
getConfiguration
()
,
lod
);
}
/**
...
...
src/main/java/fr/ill/ics/n3d/model/Model.java
View file @
1cb4418a
package
fr.ill.ics.n3d.model
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.concurrent.CopyOnWriteArraySet
;
import
java.util.logging.Logger
;
...
...
@@ -100,6 +102,12 @@ public class Model {
/** Path of the directory containing the XML and STL files for this model. */
private
String
directoryPath
;
/**
* Map associating the different Levels Of Detail (LOD) and the directories containing the geometries of the
* components.
*/
private
HashMap
<
Integer
,
String
>
geometriesDirectories
;
/** Root component of the model. */
private
Component
root
;
...
...
@@ -117,6 +125,7 @@ public class Model {
public
Model
()
{
this
.
name
=
""
;
this
.
directoryPath
=
""
;
this
.
geometriesDirectories
=
new
HashMap
<>();
this
.
root
=
null
;
this
.
selection
=
new
CopyOnWriteArraySet
<>();
this
.
visualizeAxes
=
true
;
...
...
@@ -187,6 +196,23 @@ public class Model {
this
.
directoryPath
=
directoryPath
;
}
/**
* Gets the map of the geometry directories and their LOD.
* @return The geometry directories
*/
public
HashMap
<
Integer
,
String
>
getGeometriesDirectories
()
{
return
geometriesDirectories
;
}
/**
* Gets a geometry directory from its LOD.
* @param lod Level of detail
* @return The directory if the LOD is defined, null otherwise
*/
public
String
getGeometryDirectory
(
int
lod
)
{
return
this
.
geometriesDirectories
.
get
(
lod
);
}
/**
* Sets the root component of the model
* @param root New root component
...
...
@@ -213,6 +239,16 @@ public class Model {
updateVisualAxes
();
}
/**
* Adds a geometry directory to the model
* @param lod Level of detail of the geometries
* @param dir Directory path
* @return The previous value associated with the LOD, or null if there was directory for the LOD
*/
public
String
addGeometryDirectory
(
Integer
lod
,
String
dir
)
{
return
this
.
geometriesDirectories
.
put
(
lod
,
dir
);
}
/**
* Adds a component to the selection.
* @param c Component to add
...
...
@@ -287,14 +323,22 @@ public class Model {
}
/**
* Computes the scene hierarchies for all the configurations.
* Computes the scene hierarchies for all the configurations
and the finest LOD
.
*/
public
void
computeSceneHierarchies
()
{
computeSceneHierarchies
(
0
);
}
/**
* Computes the scene hierarchies for all the configurations.
* @param lod Level of detail of the components geometries
*/
public
void
computeSceneHierarchies
(
int
lod
)
{
Logger
.
getLogger
(
"nomad-3d"
).
info
(
"Computing tree view of the model \""
+
this
.
name
+
"\"...\n"
);
this
.
root
.
toTreeItem
(
this
);
// must be done before computing scene hierarchy
Logger
.
getLogger
(
"nomad-3d"
).
info
(
"Tree view computed.\n"
);
Logger
.
getLogger
(
"nomad-3d"
).
info
(
"Computing 3D scene graph of the model \""
+
this
.
name
+
"\"...\n"
);
this
.
root
.
computeSceneHierarchy
(
this
);
this
.
root
.
computeSceneHierarchy
(
this
,
lod
);
Logger
.
getLogger
(
"nomad-3d"
).
info
(
"Scene graph computed.\n"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment