Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
cdc5490f
Commit
cdc5490f
authored
Aug 11, 2010
by
schurade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] function that returns a 27 neighbourhood for a voxel
parent
8bc05e46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
0 deletions
+140
-0
src/dataHandler/WGridRegular3D.cpp
src/dataHandler/WGridRegular3D.cpp
+128
-0
src/dataHandler/WGridRegular3D.h
src/dataHandler/WGridRegular3D.h
+12
-0
No files found.
src/dataHandler/WGridRegular3D.cpp
View file @
cdc5490f
...
...
@@ -547,6 +547,134 @@ std::vector< size_t > WGridRegular3D::getNeighbours( size_t id ) const
return
neighbours
;
}
std
::
vector
<
size_t
>
WGridRegular3D
::
getNeighbours27
(
size_t
id
)
const
{
std
::
vector
<
size_t
>
neighbours
;
size_t
x
=
id
%
m_nbPosX
;
size_t
y
=
(
id
/
m_nbPosX
)
%
m_nbPosY
;
size_t
z
=
id
/
(
m_nbPosX
*
m_nbPosY
);
if
(
x
>=
m_nbPosX
||
y
>=
m_nbPosY
||
z
>=
m_nbPosZ
)
{
std
::
stringstream
ss
;
ss
<<
"This point: "
<<
id
<<
" is not part of this grid: "
;
ss
<<
" nbPosX: "
<<
m_nbPosX
;
ss
<<
" nbPosY: "
<<
m_nbPosY
;
ss
<<
" nbPosZ: "
<<
m_nbPosZ
;
throw
WOutOfBounds
(
ss
.
str
()
);
}
// for every neighbour we must check if its not on the boundary, it will be skipped otherwise
if
(
x
>
0
)
{
neighbours
.
push_back
(
id
-
1
);
if
(
y
>
0
)
{
neighbours
.
push_back
(
id
-
m_nbPosX
-
1
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
id
+
m_nbPosX
-
1
);
}
}
if
(
x
<
m_nbPosX
-
1
)
{
neighbours
.
push_back
(
id
+
1
);
if
(
y
>
0
)
{
neighbours
.
push_back
(
id
-
m_nbPosX
+
1
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
id
+
m_nbPosX
+
1
);
}
}
if
(
y
>
0
)
{
neighbours
.
push_back
(
id
-
m_nbPosX
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
id
+
m_nbPosX
);
}
if
(
z
>
0
)
{
int
tempId
=
id
-
(
m_nbPosX
*
m_nbPosY
);
neighbours
.
push_back
(
tempId
);
if
(
x
>
0
)
{
neighbours
.
push_back
(
tempId
-
1
);
if
(
y
>
0
)
{
neighbours
.
push_back
(
tempId
-
m_nbPosX
-
1
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
tempId
+
m_nbPosX
-
1
);
}
}
if
(
x
<
m_nbPosX
-
1
)
{
neighbours
.
push_back
(
tempId
+
1
);
if
(
y
>
0
)
{
neighbours
.
push_back
(
tempId
-
m_nbPosX
+
1
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
tempId
+
m_nbPosX
+
1
);
}
}
if
(
y
>
0
)
{
neighbours
.
push_back
(
tempId
-
m_nbPosX
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
tempId
+
m_nbPosX
);
}
}
if
(
z
<
m_nbPosZ
-
1
)
{
int
tempId
=
id
+
(
m_nbPosX
*
m_nbPosY
);
neighbours
.
push_back
(
tempId
);
if
(
x
>
0
)
{
neighbours
.
push_back
(
tempId
-
1
);
if
(
y
>
0
)
{
neighbours
.
push_back
(
tempId
-
m_nbPosX
-
1
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
tempId
+
m_nbPosX
-
1
);
}
}
if
(
x
<
m_nbPosX
-
1
)
{
neighbours
.
push_back
(
tempId
+
1
);
if
(
y
>
0
)
{
neighbours
.
push_back
(
tempId
-
m_nbPosX
+
1
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
tempId
+
m_nbPosX
+
1
);
}
}
if
(
y
>
0
)
{
neighbours
.
push_back
(
tempId
-
m_nbPosX
);
}
if
(
y
<
m_nbPosY
-
1
)
{
neighbours
.
push_back
(
tempId
+
m_nbPosX
);
}
}
return
neighbours
;
}
bool
WGridRegular3D
::
encloses
(
const
wmath
::
WPosition
&
pos
)
const
{
return
getVoxelNum
(
pos
)
!=
-
1
;
// note this is an integer comparision, hence it should be numerical stable!
...
...
src/dataHandler/WGridRegular3D.h
View file @
cdc5490f
...
...
@@ -406,6 +406,18 @@ public:
*/
std
::
vector
<
size_t
>
getNeighbours
(
size_t
id
)
const
;
/**
* Return the list of all neighbour voxels.
*
* \throw WOutOfBounds If the voxel id is outside of the grid.
*
* \param id Number of the voxel for which the neighbours should be computed
*
* \return Vector of voxel ids which are all neighboured
*/
std
::
vector
<
size_t
>
getNeighbours27
(
size_t
id
)
const
;
/**
* Decides whether a certain position is inside this grid or not.
*
...
...
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