29 #include "../common/exceptions/WOutOfBounds.h"
30 #include "../common/exceptions/WPreconditionNotMet.h"
31 #include "../common/math/WLinearAlgebraFunctions.h"
32 #include "../common/WBoundingBox.h"
33 #include "../common/WProperties.h"
34 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
36 #include "WGridRegular3D.h"
40 :
WGrid( nbPosX * nbPosY * nbPosZ ),
44 m_transform( transform )
93 if( xVoxelCoord == -1 || yVoxelCoord == -1 || zVoxelCoord == -1 )
118 WPropDouble xOffset =
m_infoProperties->addProperty(
"X offset: ",
"The distance between samples in x direction",
getOffsetX() );
119 WPropDouble yOffset =
m_infoProperties->addProperty(
"Y offset: ",
"The distance between samples in y direction",
getOffsetY() );
120 WPropDouble zOffset =
m_infoProperties->addProperty(
"Z offset: ",
"The distance between samples in z direction",
getOffsetZ() );
121 WPropMatrix4X4 transformation =
m_infoProperties->addProperty(
"Transformation",
"The transformation of this grid.",
132 v[ 2 ] = modf( v[ 0 ] + 0.5, &d );
133 int i =
static_cast< int >( v[ 0 ] >= 0.0 && v[ 0 ] <
m_nbPosX - 1.0 );
134 return -1 + i *
static_cast< int >( 1.0 + d );
142 v[ 0 ] = modf( v[ 1 ] + 0.5, &d );
143 int i =
static_cast< int >( v[ 1 ] >= 0.0 && v[ 1 ] <
m_nbPosY - 1.0 );
144 return -1 + i *
static_cast< int >( 1.0 + d );
152 v[ 0 ] = modf( v[ 2 ] + 0.5, &d );
153 int i =
static_cast< int >( v[ 2 ] >= 0.0 && v[ 2 ] <
m_nbPosZ - 1.0 );
154 return -1 + i *
static_cast< int >( 1.0 + d );
173 WAssert(
isNotRotated(),
"Only feasible for grids that are only translated or scaled so far." );
177 double xCellId = floor( posRelativeToOrigin[0] /
getOffsetX() );
178 double yCellId = floor( posRelativeToOrigin[1] /
getOffsetY() );
179 double zCellId = floor( posRelativeToOrigin[2] /
getOffsetZ() );
181 *success = xCellId >= 0 && yCellId >=0 && zCellId >= 0 && xCellId <
m_nbPosX - 1 && yCellId <
m_nbPosY -1 && zCellId <
m_nbPosZ -1;
188 std::vector< size_t > vertices( 8 );
190 size_t remainderXY = cellId - minVertexIdZ * ( (
m_nbPosX - 1 ) * (
m_nbPosY - 1 ) );
191 size_t minVertexIdY = remainderXY / (
m_nbPosX - 1 );
192 size_t minVertexIdX = remainderXY % (
m_nbPosX - 1 );
196 vertices[0] = minVertexId;
197 vertices[1] = minVertexId + 1;
198 vertices[2] = minVertexId +
m_nbPosX;
199 vertices[3] = minVertexId + m_nbPosX +1;
200 vertices[4] = minVertexId + m_nbPosX *
m_nbPosY;
201 vertices[5] = minVertexId + m_nbPosX * m_nbPosY + 1;
202 vertices[6] = minVertexId + m_nbPosX * m_nbPosY +
m_nbPosX;
203 vertices[7] = minVertexId + m_nbPosX * m_nbPosY + m_nbPosX +1;
209 typedef boost::shared_ptr< std::vector< WPosition > > ReturnType;
210 ReturnType result = ReturnType(
new std::vector< WPosition > );
211 result->reserve( 8 );
212 double halfMarginX =
getOffsetX() / 2.0 - std::abs( margin );
213 double halfMarginY =
getOffsetY() / 2.0 - std::abs( margin );
214 double halfMarginZ =
getOffsetZ() / 2.0 - std::abs( margin );
215 result->push_back(
WPosition( point[0] - halfMarginX, point[1] - halfMarginY, point[2] - halfMarginZ ) );
216 result->push_back(
WPosition( point[0] + halfMarginX, point[1] - halfMarginY, point[2] - halfMarginZ ) );
217 result->push_back(
WPosition( point[0] + halfMarginX, point[1] - halfMarginY, point[2] + halfMarginZ ) );
218 result->push_back(
WPosition( point[0] - halfMarginX, point[1] - halfMarginY, point[2] + halfMarginZ ) );
219 result->push_back(
WPosition( point[0] - halfMarginX, point[1] + halfMarginY, point[2] - halfMarginZ ) );
220 result->push_back(
WPosition( point[0] + halfMarginX, point[1] + halfMarginY, point[2] - halfMarginZ ) );
221 result->push_back(
WPosition( point[0] + halfMarginX, point[1] + halfMarginY, point[2] + halfMarginZ ) );
222 result->push_back(
WPosition( point[0] - halfMarginX, point[1] + halfMarginY, point[2] + halfMarginZ ) );
228 std::vector< size_t > neighbours;
235 std::stringstream ss;
236 ss <<
"This point: " <<
id <<
" is not part of this grid: ";
245 neighbours.push_back(
id - 1 );
249 neighbours.push_back(
id + 1 );
253 neighbours.push_back(
id -
m_nbPosX );
257 neighbours.push_back(
id +
m_nbPosX );
272 std::vector< size_t > neighbours;
279 std::stringstream ss;
280 ss <<
"This point: " <<
id <<
" is not part of this grid: ";
287 std::vector< int >tempResult;
290 tempResult.push_back(
getVoxelNum( x , y - 1, z ) );
291 tempResult.push_back(
getVoxelNum( x , y + 1, z ) );
292 tempResult.push_back(
getVoxelNum( x - 1, y , z ) );
293 tempResult.push_back(
getVoxelNum( x - 1, y - 1, z ) );
294 tempResult.push_back(
getVoxelNum( x - 1, y + 1, z ) );
295 tempResult.push_back(
getVoxelNum( x + 1, y , z ) );
296 tempResult.push_back(
getVoxelNum( x + 1, y - 1, z ) );
297 tempResult.push_back(
getVoxelNum( x + 1, y + 1, z ) );
299 tempResult.push_back(
getVoxelNum( x , y , z - 1 ) );
300 tempResult.push_back(
getVoxelNum( x , y - 1, z - 1 ) );
301 tempResult.push_back(
getVoxelNum( x , y + 1, z - 1 ) );
302 tempResult.push_back(
getVoxelNum( x - 1, y , z - 1 ) );
303 tempResult.push_back(
getVoxelNum( x - 1, y - 1, z - 1 ) );
304 tempResult.push_back(
getVoxelNum( x - 1, y + 1, z - 1 ) );
305 tempResult.push_back(
getVoxelNum( x + 1, y , z - 1 ) );
306 tempResult.push_back(
getVoxelNum( x + 1, y - 1, z - 1 ) );
307 tempResult.push_back(
getVoxelNum( x + 1, y + 1, z - 1 ) );
309 tempResult.push_back(
getVoxelNum( x , y , z + 1 ) );
310 tempResult.push_back(
getVoxelNum( x , y - 1, z + 1 ) );
311 tempResult.push_back(
getVoxelNum( x , y + 1, z + 1 ) );
312 tempResult.push_back(
getVoxelNum( x - 1, y , z + 1 ) );
313 tempResult.push_back(
getVoxelNum( x - 1, y - 1, z + 1 ) );
314 tempResult.push_back(
getVoxelNum( x - 1, y + 1, z + 1 ) );
315 tempResult.push_back(
getVoxelNum( x + 1, y , z + 1 ) );
316 tempResult.push_back(
getVoxelNum( x + 1, y - 1, z + 1 ) );
317 tempResult.push_back(
getVoxelNum( x + 1, y + 1, z + 1 ) );
319 for(
size_t k = 0; k < tempResult.size(); ++k )
321 if( tempResult[k] != -1 )
323 neighbours.push_back( tempResult[k] );
331 std::vector< size_t > neighbours;
338 std::stringstream ss;
339 ss <<
"This point: " <<
id <<
" is not part of this grid: ";
351 neighbours.push_back( vNum );
356 neighbours.push_back( vNum );
361 neighbours.push_back( vNum );
366 neighbours.push_back( vNum );
371 neighbours.push_back( vNum );
376 neighbours.push_back( vNum );
381 neighbours.push_back( vNum );
386 neighbours.push_back( vNum );
393 std::vector< size_t > neighbours;
400 std::stringstream ss;
401 ss <<
"This point: " <<
id <<
" is not part of this grid: ";
413 neighbours.push_back( vNum );
418 neighbours.push_back( vNum );
423 neighbours.push_back( vNum );
428 neighbours.push_back( vNum );
433 neighbours.push_back( vNum );
438 neighbours.push_back( vNum );
443 neighbours.push_back( vNum );
448 neighbours.push_back( vNum );
456 std::vector< size_t > neighbours;
463 std::stringstream ss;
464 ss <<
"This point: " <<
id <<
" is not part of this grid: ";
476 neighbours.push_back( vNum );
481 neighbours.push_back( vNum );
486 neighbours.push_back( vNum );
491 neighbours.push_back( vNum );
496 neighbours.push_back( vNum );
501 neighbours.push_back( vNum );
506 neighbours.push_back( vNum );
511 neighbours.push_back( vNum );
521 if( v[ 0 ] < 0.0 || v[ 0 ] >=
m_nbPosX - 1 )
525 if( v[ 1 ] < 0.0 || v[ 1 ] >=
m_nbPosY - 1 )
529 if( v[ 2 ] < 0.0 || v[ 2 ] >=
m_nbPosZ - 1 )