Commit 5b13f239 by schurade

[ADD] additional pencil shapes

parent 0d57b8da
......@@ -378,6 +378,16 @@ int WGridRegular3D::getVoxelNum( const wmath::WPosition& pos ) const
+ zVoxelCoord * ( m_nbPosX ) * ( m_nbPosY );
}
int WGridRegular3D::getVoxelNum( const size_t x, const size_t y, const size_t z ) const
{
// since we use size_t here only a check for the upper bounds is needed
if ( x > m_nbPosX || y > m_nbPosY || z > m_nbPosZ )
{
return -1;
}
return x + y * ( m_nbPosX ) + z * ( m_nbPosX ) * ( m_nbPosY );
}
int WGridRegular3D::getNVoxelCoord( const wmath::WPosition& pos, size_t axis ) const
{
double result = pos[ axis ] - m_origin[ axis ];
......@@ -673,6 +683,196 @@ std::vector< size_t > WGridRegular3D::getNeighbours27( size_t id ) const
return neighbours;
}
std::vector< size_t > WGridRegular3D::getNeighbours9XY( 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
int vNum;
size_t test = 0;
vNum = getVoxelNum( x - 1, y, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x - 1, y - 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y - 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x + 1, y - 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x + 1, y, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x + 1, y + 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y + 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x - 1, y + 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
return neighbours;
}
std::vector< size_t > WGridRegular3D::getNeighbours9YZ( 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
int vNum;
vNum = getVoxelNum( x, y, z - 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y - 1, z - 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y - 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y - 1, z + 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y, z + 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y + 1, z + 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y + 1, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y + 1, z - 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
return neighbours;
}
std::vector< size_t > WGridRegular3D::getNeighbours9XZ( 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
int vNum;
vNum = getVoxelNum( x, y, z - 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x - 1, y, z - 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x - 1, y, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x - 1, y, z + 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x, y, z + 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x + 1, y, z + 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x + 1, y, z );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
vNum = getVoxelNum( x + 1, y, z - 1 );
if ( vNum != -1 )
{
neighbours.push_back( vNum );
}
return neighbours;
}
bool WGridRegular3D::encloses( const wmath::WPosition& pos ) const
......
......@@ -289,6 +289,18 @@ public:
int getVoxelNum( const wmath::WPosition& pos ) const;
/**
* returns the voxel index for a given discrete position in the grid
*
* \param x Position for which we want to have the voxel number.
* \param y Position for which we want to have the voxel number.
* \param z Position for which we want to have the voxel number.
*
* \return Voxel number or -1 if the position refers to a point outside of
* the grid.
*/
int getVoxelNum( const size_t x, const size_t y, const size_t z ) const;
/**
* Computes the X coordinate of that voxel that contains the
* position pos.
*
......@@ -417,6 +429,38 @@ public:
*/
std::vector< size_t > getNeighbours27( 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 along the XY plane
*/
std::vector< size_t > getNeighbours9XY( 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 along the YZ plane
*/
std::vector< size_t > getNeighbours9YZ( 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 along the XZ plane
*/
std::vector< size_t > getNeighbours9XZ( size_t id ) const;
/**
* Decides whether a certain position is inside this grid or not.
......
......@@ -97,6 +97,8 @@ void WMPaintTexture::properties()
m_pencilSelectionsList->addItem( "1x1", "" );
m_pencilSelectionsList->addItem( "3x3", "" );
m_pencilSelectionsList->addItem( "5x5", "" );
m_pencilSelectionsList->addItem( "3x1 (only works on orthogonal slices)", "" );
m_pencilSelectionsList->addItem( "5x1 (only works on orthogonal slices)", "" );
m_pencilSelection = m_properties->addProperty( "Pencil", "Pencil type.", m_pencilSelectionsList->getSelectorFirst() );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_pencilSelection );
......@@ -254,7 +256,8 @@ void WMPaintTexture::doPaint()
while ( !m_paintQueue.empty() )
{
wmath::WPosition paintPosition = m_paintQueue.front();
WPickInfo pickInfo = m_paintQueue.front();
wmath::WPosition paintPosition = pickInfo.getPickPosition();
m_paintQueue.pop();
int voxelNum = m_grid->getVoxelNum( paintPosition );
......@@ -282,13 +285,89 @@ void WMPaintTexture::doPaint()
for ( size_t i = 0; i < ids.size(); ++i )
{
std::vector< size_t > allIds = m_grid->getNeighbours27( ids[i] );
for ( size_t k = 0; k < ids.size(); ++k )
for ( size_t k = 0; k < allIds.size(); ++k )
{
data[ allIds[k] ] = m_paintIndex->get();
}
}
break;
}
case 3:
{
if ( pickInfo.getName() == "Axial Slice" )
{
data[ voxelNum ] = m_paintIndex->get();
std::vector< size_t > ids = m_grid->getNeighbours9XY( voxelNum );
for ( size_t i = 0; i < ids.size(); ++i )
{
data[ ids[i] ] = m_paintIndex->get();
}
}
if ( pickInfo.getName() == "Coronal Slice" )
{
data[ voxelNum ] = m_paintIndex->get();
std::vector< size_t > ids = m_grid->getNeighbours9XZ( voxelNum );
for ( size_t i = 0; i < ids.size(); ++i )
{
data[ ids[i] ] = m_paintIndex->get();
}
}
if ( pickInfo.getName() == "Sagittal Slice" )
{
data[ voxelNum ] = m_paintIndex->get();
std::vector< size_t > ids = m_grid->getNeighbours9YZ( voxelNum );
for ( size_t i = 0; i < ids.size(); ++i )
{
data[ ids[i] ] = m_paintIndex->get();
}
}
break;
}
case 4:
{
if ( pickInfo.getName() == "Axial Slice" )
{
data[ voxelNum ] = m_paintIndex->get();
std::vector< size_t > ids = m_grid->getNeighbours9XY( voxelNum );
for ( size_t i = 0; i < ids.size(); ++i )
{
std::vector< size_t > allIds = m_grid->getNeighbours9XY( ids[i] );
for ( size_t k = 0; k < allIds.size(); ++k )
{
data[ allIds[k] ] = m_paintIndex->get();
}
}
}
if ( pickInfo.getName() == "Coronal Slice" )
{
data[ voxelNum ] = m_paintIndex->get();
std::vector< size_t > ids = m_grid->getNeighbours9XZ( voxelNum );
for ( size_t i = 0; i < ids.size(); ++i )
{
std::vector< size_t > allIds = m_grid->getNeighbours9XZ( ids[i] );
for ( size_t k = 0; k < allIds.size(); ++k )
{
data[ allIds[k] ] = m_paintIndex->get();
}
}
}
if ( pickInfo.getName() == "Sagittal Slice" )
{
data[ voxelNum ] = m_paintIndex->get();
std::vector< size_t > ids = m_grid->getNeighbours9YZ( voxelNum );
for ( size_t i = 0; i < ids.size(); ++i )
{
std::vector< size_t > allIds = m_grid->getNeighbours9YZ( ids[i] );
for ( size_t k = 0; k < allIds.size(); ++k )
{
data[ allIds[k] ] = m_paintIndex->get();
}
}
}
break;
}
default:
break;
}
......@@ -305,7 +384,7 @@ void WMPaintTexture::queuePaint( WPickInfo pickInfo )
{
return;
}
m_paintQueue.push( pickInfo.getPickPosition() );
m_paintQueue.push( pickInfo );
m_queueAdded->set( true );
}
......
......@@ -196,7 +196,7 @@ private:
/**
* new paint coordinates get added here
*/
std::queue< wmath::WPosition >m_paintQueue;
std::queue< WPickInfo >m_paintQueue;
/**
* An input connector that accepts order 1 datasets.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment