Skip to content

Commit

Permalink
Update CartesianGridXY.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sebouh137 authored Aug 31, 2023
1 parent 9b7833c commit 2ef97dd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions DDCore/src/segmentations/CartesianGridXY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ CartesianGridXY::CartesianGridXY(const std::string& cellEncoding) :
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)", _staggerX, 0);
registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)", _staggerY, 0);
registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
}
Expand Down Expand Up @@ -51,16 +53,17 @@ CartesianGridXY::~CartesianGridXY() {
/// determine the position based on the cell ID
Vector3D CartesianGridXY::position(const CellID& cID) const {
Vector3D cellPosition;
cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX);
cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY);
int layer= _decoder->get(cID,"layer");
cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX+_staggerX*_gridSizeX*(layer%2)/2.);
cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY+_staggerY*_gridSizeY*(layer%2)/2.);
return cellPosition;
}

/// determine the cell ID based on the position
CellID CartesianGridXY::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
CellID cID = vID ;
_decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX) );
_decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY) );
_decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX+_staggerX*_gridSizeX*(layer%2)/2) );
_decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY+_staggerY*_gridSizeY*(layer%2)/2) );
return cID ;
}

Expand Down

0 comments on commit 2ef97dd

Please sign in to comment.