void SpatialSliceOP::prepareSlice(uint32_t slice,uint32_t N_cells) {
      this->N_cells = N_cells;
      
      if (slice >= getNumberOfSlices()) {
	 x_blocks = numeric_limits<uint32_t>::max();
	 y_blocks = numeric_limits<uint32_t>::max();
	 z_blocks = numeric_limits<uint32_t>::max();
	 return;
      }
      
      uint32_t bbox[3];
      bbox[0] = sim->x_blocks;  // Number of mesh blocks in x-direction in mesh bounding box.
      bbox[1] = sim->y_blocks;  // Number of mesh blocks in y-direction in mesh bounding box.
      bbox[2] = sim->z_blocks;  // Number of mesh blocks in z-direction in mesh bounding box.
      if (isCylindrical(slice) == true) {
	 bbox[getSlicedCoordinate(slice)+0] = bbox[2];
	 bbox[2] = N_cells;
      } else {
	 bbox[getSlicedCoordinate(slice)+0] = N_cells;
      }

      x_blocks = bbox[0];
      y_blocks = bbox[1];
      z_blocks = bbox[2];
   }
void VolumeDisplayUnit::setSlabThickness(int thickness)
{
    // Make sure thickness is within valid bounds. Must be between 1 and the maximum number of slices on the curren view.
    int admittedThickness = qBound(1, thickness, getNumberOfSlices());
    
    m_sliceHandler->setSlabThickness(admittedThickness);
    m_imagePipeline->setSlice(m_volume->getImageIndex(getSlice(), getPhase()));
    m_imagePipeline->setSlabThickness(admittedThickness);
}
   void SpatialSliceOP::getAcceptedBlocks(uint32_t slice,std::vector<pargrid::CellID>& blockGIDs,std::vector<pargrid::CellID>& blockLIDs) {
      blockLIDs.clear();
      blockGIDs.clear();
      if (slice >= getNumberOfSlices()) return;
      
      const vector<pargrid::CellID>& globalIDs = simClasses->pargrid.getGlobalIDs();
      const double* const blockCoordinateArray = getBlockCoordinateArray(*sim,*simClasses);
      
      Real blockCoords[3];
      uint32_t blockIndices[3];
      Real blockSizes[3];
      for (pargrid::CellID blockLID=0; blockLID<simClasses->pargrid.getNumberOfLocalCells(); ++blockLID) {
	 // Calculate spatial block indices:
	 block::calculateBlockIndices(*sim,globalIDs[blockLID],blockIndices[0],blockIndices[1],blockIndices[2]);
	 
	 // Get block coordinates:
	 blockCoords[0] = blockCoordinateArray[blockLID*3+0];
	 blockCoords[1] = blockCoordinateArray[blockLID*3+1];
	 blockCoords[2] = blockCoordinateArray[blockLID*3+2];
	 
	 // Get block size:
	 blockSizes[0] = sim->dx_block[blockIndices[0]];
	 blockSizes[1] = sim->dy_block[blockIndices[1]];
	 blockSizes[2] = sim->dz_block[blockIndices[2]];
	 
	 // Check if slice intersects block:
	 const Real sliceOrigin = sliceOrigins[slice];
	 const Real CRD = blockCoords[sliceCoordinates[slice]];
	 const Real DX  = blockSizes[sliceCoordinates[slice]];

	 if (CRD > sliceOrigin || CRD+DX < sliceOrigin) continue;
	 sliceIndices[slice] = blockIndices[sliceCoordinates[slice]];

	 if (isCylindrical(slice) == true) {
	    blockIndices[sliceCoordinates[slice]] = blockIndices[2];
	 }

	 // Calculate new global ID for cells in the accepted block:
	 for (uint32_t cell=0; cell<N_cells; ++cell) {
	    if (isCylindrical(slice) == true) {
	       blockIndices[2] = cell;
	    } else {
	       blockIndices[sliceCoordinates[slice]] = cell;
	    }
	    blockGIDs.push_back( calculateNewGlobalID(blockIndices) );
	 }
	 blockLIDs.push_back( blockLID );
      }
   }