Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Yuhao Liu
ogs
Commits
7ff2ab75
Commit
7ff2ab75
authored
9 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[MeL] Replace common code with filter algorithm.
parent
abb3a39a
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
MeshLib/MeshSearch/ElementSearch.cpp
+30
-32
30 additions, 32 deletions
MeshLib/MeshSearch/ElementSearch.cpp
with
30 additions
and
32 deletions
MeshLib/MeshSearch/ElementSearch.cpp
+
30
−
32
View file @
7ff2ab75
...
...
@@ -42,30 +42,33 @@ std::size_t ElementSearch::searchByMaterialID(int const matID)
return
matchedIDs
.
size
();
}
std
::
size_t
ElementSearch
::
searchByElementType
(
MeshElemType
eleType
)
template
<
typename
Container
,
typename
Predicate
>
std
::
vector
<
std
::
size_t
>
filter
(
Container
const
&
container
,
Predicate
const
&
p
)
{
const
std
::
vector
<
MeshLib
::
Element
*>
&
ele_vec
(
this
->
_mesh
.
getElements
());
std
::
vector
<
std
::
size_t
>
matchedIDs
;
std
::
size_t
i
=
0
;
for
(
MeshLib
::
Element
*
ele
:
ele_vec
)
{
if
(
ele
->
getGeomType
()
==
eleTyp
e
)
for
(
auto
value
:
container
)
{
if
(
p
(
valu
e
)
)
matchedIDs
.
push_back
(
i
);
i
++
;
}
return
matchedIDs
;
}
std
::
size_t
ElementSearch
::
searchByElementType
(
MeshElemType
eleType
)
{
auto
matchedIDs
=
filter
(
_mesh
.
getElements
(),
[
&
](
MeshLib
::
Element
*
e
)
{
return
e
->
getGeomType
()
==
eleType
;
});
this
->
updateUnion
(
matchedIDs
);
return
matchedIDs
.
size
();
}
std
::
size_t
ElementSearch
::
searchByContent
(
double
eps
)
{
const
std
::
vector
<
MeshLib
::
Element
*>
&
ele_vec
(
this
->
_mesh
.
getElements
());
std
::
vector
<
std
::
size_t
>
matchedIDs
;
std
::
size_t
i
=
0
;
for
(
MeshLib
::
Element
*
ele
:
ele_vec
)
{
if
(
ele
->
getContent
()
<
eps
)
matchedIDs
.
push_back
(
i
);
i
++
;
}
auto
matchedIDs
=
filter
(
_mesh
.
getElements
(),
[
&
eps
](
MeshLib
::
Element
*
e
)
{
return
e
->
getContent
()
<
eps
;
});
this
->
updateUnion
(
matchedIDs
);
return
matchedIDs
.
size
();
}
...
...
@@ -73,20 +76,15 @@ std::size_t ElementSearch::searchByContent(double eps)
std
::
size_t
ElementSearch
::
searchByBoundingBox
(
GeoLib
::
AABB
<
MathLib
::
Point3d
>
const
&
aabb
)
{
const
std
::
vector
<
MeshLib
::
Element
*>
&
ele_vec
(
this
->
_mesh
.
getElements
());
auto
matchedIDs
=
filter
(
_mesh
.
getElements
(),
[
&
aabb
](
MeshLib
::
Element
*
e
)
{
std
::
size_t
const
nElemNodes
(
e
->
getNBaseNodes
());
for
(
std
::
size_t
n
=
0
;
n
<
nElemNodes
;
++
n
)
if
(
aabb
.
containsPoint
(
*
e
->
getNode
(
n
)))
return
true
;
// any node of element is in aabb.
return
false
;
// no nodes of element are in aabb.
});
std
::
vector
<
std
::
size_t
>
matchedIDs
;
const
std
::
size_t
n_elems
(
ele_vec
.
size
());
for
(
std
::
size_t
i
=
0
;
i
<
n_elems
;
i
++
)
{
std
::
size_t
nElemNodes
(
ele_vec
[
i
]
->
getNBaseNodes
());
for
(
std
::
size_t
j
=
0
;
j
<
nElemNodes
;
++
j
)
if
(
!
aabb
.
containsPoint
(
*
ele_vec
[
i
]
->
getNode
(
j
)))
{
matchedIDs
.
push_back
(
i
);
break
;
}
}
this
->
updateUnion
(
matchedIDs
);
return
matchedIDs
.
size
();
}
...
...
@@ -94,16 +92,16 @@ std::size_t ElementSearch::searchByBoundingBox(
std
::
size_t
ElementSearch
::
searchByNodeIDs
(
const
std
::
vector
<
std
::
size_t
>
&
nodes
)
{
std
::
vector
<
std
::
size_t
>
connected_elements
;
std
::
for_each
(
nodes
.
begin
(),
nodes
.
end
(),
[
&
](
std
::
size_t
node_id
)
{
for
(
auto
*
e
:
_mesh
.
getNode
(
node_id
)
->
getElements
())
{
connected_elements
.
push_back
(
e
->
getID
());
}
});
for
(
std
::
size_t
node_id
:
nodes
)
{
for
(
auto
*
e
:
_mesh
.
getNode
(
node_id
)
->
getElements
())
{
connected_elements
.
push_back
(
e
->
getID
());
}
}
std
::
sort
(
connected_elements
.
begin
(),
connected_elements
.
end
());
auto
it
=
std
::
unique
(
connected_elements
.
begin
(),
connected_elements
.
end
());
connected_elements
.
resize
(
std
::
distance
(
connected_elements
.
begin
(),
it
));
this
->
updateUnion
(
connected_elements
);
return
connected_elements
.
size
();
}
...
...
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