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
93e44850
There was an error fetching the commit references. Please try again later.
Commit
93e44850
authored
3 years ago
by
Daniel Schramm
Browse files
Options
Downloads
Patches
Plain Diff
Fixed error in adding collection of facets
parent
de03315f
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/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java
+173
-173
173 additions, 173 deletions
...rc/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java
with
173 additions
and
173 deletions
MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/MeshModel.java
+
173
−
173
View file @
93e44850
package
cz.fidentis.analyst.mesh.core
;
package
cz.fidentis.analyst.mesh.core
;
import
com.google.common.eventbus.EventBus
;
import
com.google.common.eventbus.EventBus
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
cz.fidentis.analyst.mesh.MeshVisitor
;
import
cz.fidentis.analyst.mesh.MeshVisitor
;
import
cz.fidentis.analyst.mesh.events.FacetAddedEvent
;
import
cz.fidentis.analyst.mesh.events.FacetAddedEvent
;
import
java.util.Collections
;
import
java.util.Collections
;
import
cz.fidentis.analyst.mesh.events.MeshListener
;
import
cz.fidentis.analyst.mesh.events.MeshListener
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
/**
/**
* The main object for triangular meshes. Each mesh model consists
* The main object for triangular meshes. Each mesh model consists
* of one or more mesh facets.
* of one or more mesh facets.
* <p>
* <p>
* This class implements the publish-subscribe notifications to changes.
* This class implements the publish-subscribe notifications to changes.
* However, the {@code HumanFace} class provides similar
* However, the {@code HumanFace} class provides similar
* functionality at the higher level of abstraction. Therefore, we recommend
* functionality at the higher level of abstraction. Therefore, we recommend
* to monitor this class when you want to be informed about changes in concrete human face.
* to monitor this class when you want to be informed about changes in concrete human face.
* <p>
* <p>
* Events fired by the class:
* Events fired by the class:
* <ul>
* <ul>
* <li>{@link cz.fidentis.analyst.mesh.events.FacetAddedEvent} when new facet is added.</li>
* <li>{@link cz.fidentis.analyst.mesh.events.FacetAddedEvent} when new facet is added.</li>
* </ul>
* </ul>
* </p>
* </p>
*
*
* @author Matej Lukes
* @author Matej Lukes
* @author Radek Oslejsek
* @author Radek Oslejsek
*/
*/
public
class
MeshModel
implements
Serializable
{
public
class
MeshModel
implements
Serializable
{
private
final
List
<
MeshFacet
>
facets
=
new
ArrayList
<>();
private
final
List
<
MeshFacet
>
facets
=
new
ArrayList
<>();
private
final
transient
EventBus
eventBus
=
new
EventBus
();
private
final
transient
EventBus
eventBus
=
new
EventBus
();
/**
/**
* Constructor of MeshModel
* Constructor of MeshModel
*/
*/
public
MeshModel
()
{
public
MeshModel
()
{
}
}
/**
/**
* Copy constructor of MeshModel
* Copy constructor of MeshModel
*
*
* @param meshModel copied MeshModel
* @param meshModel copied MeshModel
*/
*/
public
MeshModel
(
MeshModel
meshModel
)
{
public
MeshModel
(
MeshModel
meshModel
)
{
for
(
MeshFacet
facet:
meshModel
.
facets
)
{
for
(
MeshFacet
facet:
meshModel
.
facets
)
{
facets
.
add
(
new
MeshFacetImpl
(
facet
));
facets
.
add
(
new
MeshFacetImpl
(
facet
));
}
}
}
}
/**
/**
* returns list of MeshFacets
* returns list of MeshFacets
*
*
* @return list of MeshFacets
* @return list of MeshFacets
*/
*/
public
List
<
MeshFacet
>
getFacets
()
{
public
List
<
MeshFacet
>
getFacets
()
{
return
Collections
.
unmodifiableList
(
facets
);
return
Collections
.
unmodifiableList
(
facets
);
}
}
/**
/**
* Adds a new mesh facet to the model.
* Adds a new mesh facet to the model.
* Fires {@link cz.fidentis.analyst.mesh.events.FacetAddedEvent} to
* Fires {@link cz.fidentis.analyst.mesh.events.FacetAddedEvent} to
* registered listeners.
* registered listeners.
*
*
* @param facet new MeshFacet
* @param facet new MeshFacet
*/
*/
public
void
addFacet
(
MeshFacet
facet
)
{
public
void
addFacet
(
MeshFacet
facet
)
{
facets
.
add
(
facet
);
facets
.
add
(
facet
);
eventBus
.
post
(
new
FacetAddedEvent
(
facet
));
eventBus
.
post
(
new
FacetAddedEvent
(
facet
));
}
}
/**
/**
* Adds a new mesh facets to the model.
* Adds a new mesh facets to the model.
* Fires {@link cz.fidentis.analyst.mesh.events.FacetAddedEvent} to
* Fires {@link cz.fidentis.analyst.mesh.events.FacetAddedEvent} to
* registered listeners.
* registered listeners.
*
*
* @param
facet new MeshF
acet
* @param
newFacets collection of new new f
acet
s
*/
*/
public
void
addFacets
(
Collection
<
MeshFacet
>
f
acets
)
{
public
void
addFacets
(
Collection
<
MeshFacet
>
newF
acets
)
{
facets
.
addAll
(
f
acets
);
facets
.
addAll
(
newF
acets
);
for
(
MeshFacet
f:
f
acets
)
{
for
(
MeshFacet
f:
newF
acets
)
{
eventBus
.
post
(
new
FacetAddedEvent
(
f
));
eventBus
.
post
(
new
FacetAddedEvent
(
f
));
}
}
}
}
/**
/**
* Applies the visitor to all mesh facets. If the visitor is thread-safe
* Applies the visitor to all mesh facets. If the visitor is thread-safe
* and the {@code concurrently} is {@code true}, then the visitor is
* and the {@code concurrently} is {@code true}, then the visitor is
* applied to all mesh facet concurrently using all CPU cores.
* applied to all mesh facet concurrently using all CPU cores.
*
*
* @param visitor Visitor to be applied for the computation
* @param visitor Visitor to be applied for the computation
* @param concurrently Parallel computation
* @param concurrently Parallel computation
* @throws NullPointerException if the visitor is {@code null}
* @throws NullPointerException if the visitor is {@code null}
*/
*/
public
void
compute
(
MeshVisitor
visitor
,
boolean
concurrently
)
{
public
void
compute
(
MeshVisitor
visitor
,
boolean
concurrently
)
{
if
(
concurrently
&&
visitor
.
isThreadSafe
())
{
if
(
concurrently
&&
visitor
.
isThreadSafe
())
{
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
Runtime
.
getRuntime
().
availableProcessors
());
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
Runtime
.
getRuntime
().
availableProcessors
());
for
(
MeshFacet
f:
this
.
facets
)
{
for
(
MeshFacet
f:
this
.
facets
)
{
Runnable
worker
=
new
Runnable
()
{
Runnable
worker
=
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
f
.
accept
(
visitor
);
f
.
accept
(
visitor
);
}
}
};
};
executor
.
execute
(
worker
);
executor
.
execute
(
worker
);
}
}
// Wait until all symmetry planes are computed:
// Wait until all symmetry planes are computed:
executor
.
shutdown
();
executor
.
shutdown
();
while
(!
executor
.
isTerminated
()){}
while
(!
executor
.
isTerminated
()){}
}
else
{
}
else
{
for
(
MeshFacet
f:
this
.
facets
)
{
for
(
MeshFacet
f:
this
.
facets
)
{
f
.
accept
(
visitor
);
f
.
accept
(
visitor
);
}
}
}
}
}
}
/**
/**
* Applies the visitor to all mesh facets sequentially.
* Applies the visitor to all mesh facets sequentially.
*
*
* @param visitor Visitor to be applied for the computation
* @param visitor Visitor to be applied for the computation
* @throws NullPointerException if the visitor is {@code null}
* @throws NullPointerException if the visitor is {@code null}
*/
*/
public
void
compute
(
MeshVisitor
visitor
)
{
public
void
compute
(
MeshVisitor
visitor
)
{
compute
(
visitor
,
false
);
compute
(
visitor
,
false
);
}
}
/**
/**
* Registers listeners (objects concerned in the mesh model changes) to receive events.
* Registers listeners (objects concerned in the mesh model changes) to receive events.
* If listener is {@code null}, no exception is thrown and no action is taken.
* If listener is {@code null}, no exception is thrown and no action is taken.
*
*
* @param listener Listener concerned in the mesh model changes.
* @param listener Listener concerned in the mesh model changes.
*/
*/
public
void
registerListener
(
MeshListener
listener
)
{
public
void
registerListener
(
MeshListener
listener
)
{
eventBus
.
register
(
listener
);
eventBus
.
register
(
listener
);
}
}
/**
/**
* Unregisters listeners from receiving events.
* Unregisters listeners from receiving events.
*
*
* @param listener Registered listener
* @param listener Registered listener
*/
*/
public
void
unregisterListener
(
MeshListener
listener
)
{
public
void
unregisterListener
(
MeshListener
listener
)
{
eventBus
.
unregister
(
listener
);
eventBus
.
unregister
(
listener
);
}
}
/**
/**
* Removes duplicate vertices that differ only in normal vectors or texture coordinates.
* Removes duplicate vertices that differ only in normal vectors or texture coordinates.
* Multiple normals are replaced with the average normal. If the texture coordinate
* Multiple normals are replaced with the average normal. If the texture coordinate
* differ then randomly selected one is used.
* differ then randomly selected one is used.
*/
*/
public
void
simplifyModel
()
{
public
void
simplifyModel
()
{
for
(
MeshFacet
f
:
this
.
facets
)
{
for
(
MeshFacet
f
:
this
.
facets
)
{
f
.
simplify
();
f
.
simplify
();
}
}
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
int
verts
=
0
;
int
verts
=
0
;
for
(
MeshFacet
f:
facets
)
{
for
(
MeshFacet
f:
facets
)
{
verts
+=
f
.
getNumberOfVertices
();
verts
+=
f
.
getNumberOfVertices
();
}
}
return
facets
.
size
()
+
" facets with "
+
verts
+
" vertices"
;
return
facets
.
size
()
+
" facets with "
+
verts
+
" vertices"
;
}
}
}
}
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