Commit in lcdd on MAIN | |||
include/CellReadout2D.hh | +34 | -92 | 1.2 -> 1.3 |
src/CellReadout.cc | +17 | added 1.1 | |
/CellReadout2D.cc | +106 | -97 | 1.2 -> 1.3 |
+157 | -189 |
diff -u -r1.2 -r1.3 --- CellReadout2D.hh 10 Jun 2013 19:42:47 -0000 1.2 +++ CellReadout2D.hh 18 Jun 2013 19:59:33 -0000 1.3 @@ -1,70 +1,65 @@
#ifndef lcdd_CellReadout2D_hh #define lcdd_CellReadout2D_hh 1
+// LCDD +#include "CellReadout.hh" + +// STL
#include <vector> #include <map> /**
- * This class defines and implements a 2D cell readout with positive coordinate - * system originating at the upper left of a box volume. Cells are numbered from - * x,y = (1,1). Unless otherwise noted, any reference to a "position" in the comments - * refers to coordinates in the readout's system. Coordinates should be transformed into - * the readout's system by the caller such as a segmentation class.
+ *
*/
-class CellReadout2D
+class CellReadout2D : public CellReadout
{ public:
- /** - * A pair of cell indices. - */ - typedef std::pair<int, int> Cell; -
/**
- * A 2D position in the readout. - */ - typedef std::pair<double, double> PositionXY; - - /** - * dtor
+ * Class destructor.
*/ virtual ~CellReadout2D(); /**
- * ctor
+ * Class constructor.
*/ CellReadout2D(double cellSizeX, double cellSizeY);
- /** - * Get the X cell size. - */ - double getCellSizeX();
+ /** + * ---------------------------------------------------------- + * Implementation of CellReadout + * ---------------------------------------------------------- + */
- /** - * Get the Y cell size. - */ - double getCellSizeY();
+ /** + * Get the position of the cell. + */ + Position2D position(CellId);
- /** - * Get the dimension of the readout in X. - */ - double getReadoutDimensionX();
+ /** + * Compute cell ID from local position. + */ + CellId cellId(Position2D);
- /** - * Get the dimension of the readout in Y. - */ - double getReadoutDimensionY();
+ /** + * Create a list of neighbor cells from a cell ID. + */ + Neighbors neighbors(CellId); + + /** + * ---------------------------------------------------------- + */
/**
- * Get the position of the cell.
+ * Get the X cell size.
*/
- PositionXY getCellPosition(Cell);
+ double getCellSizeX();
/**
- * Get the cell from a position.
+ * Get the Y cell size.
*/
- Cell getCell(PositionXY);
+ double getCellSizeY();
/** * Get the X index from a position.
@@ -87,35 +82,10 @@
double getCellPositionY(int iy); /**
- * Get the neighbors of a cell. - */ - //std::vector<Cell> getNeighbors(Cell); - - /**
* Get a pair of indices representing a cell. * This method should check that the indices are valid. */
- Cell createCell(int x, int y); - - /** - * Check if an X index is valid. - */ - bool isValidXIndex(int x); - - /** - * Check if a Y index is valid. - */ - bool isValidYIndex(int y); - - /** - * Check if an X position is inside this readout. - */ - bool isCoordinateInsideX(double x); - - /** - * Check if a Y position is inside this readout. - */ - bool isCoordinateInsideY(double y);
+ CellId createCell(int x, int y);
/** * Given an index and cell size, compute the corresponding coordinate.
@@ -127,38 +97,10 @@
*/ int getCellIndex(double x, double cellSize);
- /** - * Set the X dimension of the readout. - */ - void setReadoutDimensionX(double x); - - /** - * Set the Y dimension of the readout. - */ - void setReadoutDimensionY(double y); - - /** - * Get the maximum valid X index. - */ - int getMaximumXIndex(); - - /** - * Get the maximum valid Y index. - */ - int getMaximumYIndex(); - - /** - * Transform local XY coordinates into readout coordinates. - */ - PositionXY localToReadoutCoordinates(PositionXY xy); -
private: double m_cellSizeX; double m_cellSizeY;
- - double m_dimensionX; - double m_dimensionY;
}; #endif
diff -N CellReadout.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ CellReadout.cc 18 Jun 2013 19:59:34 -0000 1.1 @@ -0,0 +1,17 @@
+#include "CellReadout.hh" + +CellReadout::CellReadout() +{ +} + +CellReadout::~CellReadout() +{ +} + +/** + * Get the list of field names. + */ +const CellReadout::FieldNames& CellReadout::fieldNames() +{ + return m_fieldNames; +}
diff -u -r1.2 -r1.3 --- CellReadout2D.cc 10 Jun 2013 19:42:47 -0000 1.2 +++ CellReadout2D.cc 18 Jun 2013 19:59:34 -0000 1.3 @@ -5,36 +5,115 @@
#include <stdexcept> CellReadout2D::CellReadout2D(double cellSizeX, double cellSizeY)
-//: m_cellSizeX(cellSizeX), m_cellSizeY(m_cellSizeY)
{ m_cellSizeX = cellSizeX; m_cellSizeY = cellSizeY;
- //std::cout << "args x,y: " << cellSizeX << " " << cellSizeY << std::endl; - //std::cout << "CellReadout2D(x,y): " << m_cellSizeX << " " << m_cellSizeY << std::endl;
+ + m_fieldNames.push_back("ix"); + m_fieldNames.push_back("iy");
} CellReadout2D::~CellReadout2D() { }
-double CellReadout2D::getCellSizeX()
+CellReadout2D::Position2D CellReadout2D::position(CellReadout2D::CellId cellId)
{
- return m_cellSizeX;
+ Position2D pos; + pos.first = getCellPositionX(cellId[0]); + pos.second = getCellPositionY(cellId[1]); + return pos;
}
-double CellReadout2D::getCellSizeY()
+CellReadout::CellId CellReadout2D::cellId(Position2D pos)
{
- return m_cellSizeY;
+ return createCell(getXIndex(pos.first), getYIndex(pos.second));
}
-double CellReadout2D::getReadoutDimensionX()
+/** + * Create a list of neighbor cells from a cell ID. + */ +CellReadout::Neighbors CellReadout2D::neighbors(CellId cellId) +{ + Neighbors neighbors; + int ix, iy; + + // top left + ix = cellId[0] - 1; + if (ix == 0) + ix = -1; + iy = cellId[1] + 1; + if (iy == 0) + iy = 1; + neighbors.push_back(createCell(ix, iy)); + + // top middle + ix = cellId[0]; + iy = cellId[1] + 1; + if (iy == 0) + iy = 1; + neighbors.push_back(createCell(ix, iy)); + + // top right + ix = cellId[0]; + if (ix == 0) + ix = 1; + iy = cellId[1] + 1; + if (iy == 0) + iy = 1; + neighbors.push_back(createCell(ix, iy)); + + // middle left + ix = cellId[0] - 1; + if (ix == 0) + ix = -1; + iy = cellId[1]; + neighbors.push_back(createCell(ix, iy)); + + // middle right + ix = cellId[0] + 1; + if (ix == 0) + ix = 1; + iy = cellId[1]; + neighbors.push_back(createCell(ix, iy)); + + // bottom left + ix = cellId[0] - 1; + if (ix == 0) + ix = -1; + iy = cellId[1] - 1; + if (iy == 0) + iy = -1; + neighbors.push_back(createCell(ix-1, iy-1)); + + // bottom middle + ix = cellId[0]; + iy = cellId[1] - 1; + if (iy == 0) + iy = -1; + neighbors.push_back(createCell(ix, iy-1)); + + // bottom right + ix = cellId[0] + 1; + if (ix == 0) + ix = 1; + iy = cellId[1] - 1; + if (iy == 0) + iy = -1; + neighbors.push_back(createCell(ix, iy-1)); + + return neighbors; + +} + +double CellReadout2D::getCellSizeX()
{
- return m_dimensionX;
+ return m_cellSizeX;
}
-double CellReadout2D::getReadoutDimensionY()
+double CellReadout2D::getCellSizeY()
{
- return m_dimensionY;
+ return m_cellSizeY;
} int CellReadout2D::getXIndex(double x)
@@ -47,26 +126,22 @@
return getCellIndex(y, m_cellSizeY); }
-CellReadout2D::PositionXY CellReadout2D::getCellPosition(CellReadout2D::Cell cell) -{ - int ix = cell.first; - int iy = cell.second; - PositionXY pos; - pos.first = getCellPositionX(ix); - pos.second = getCellPositionY(iy); - return pos; -} -
double CellReadout2D::getCellCoordinate(int i, double cellSize) {
- return (i * cellSize) - cellSize / 2;
+ double v = i * cellSize; + if (v > 0) + v -= cellSize / 2; + else + v += cellSize / 2; + return v;
}
-int CellReadout2D::getCellIndex(double x, double cellSize) -{ - //std::cout << "getIndex(x,cellSize): " << x << " " << cellSize << std::endl; - //std::cout << "floor(x/cellSize): " << std::floor(x/cellSize) << std::endl; - return std::floor(x / cellSize) + 1;
+int CellReadout2D::getCellIndex(double c, double cellSize) +{ + int v = std::ceil(c / cellSize); + if (v == 0) + v -= 1; + return v;
} double CellReadout2D::getCellPositionX(int ix)
@@ -79,76 +154,10 @@
return getCellCoordinate(iy, m_cellSizeY); }
-CellReadout2D::Cell CellReadout2D::getCell(PositionXY xy)
+CellReadout2D::CellId CellReadout2D::createCell(int x, int y)
{
- Cell cell = createCell(getXIndex(xy.first), getYIndex(xy.second));
+ CellId cell; + cell.push_back(x); + cell.push_back(y);
return cell; }
- -//std::vector<CellReadout2D::Cell> CellReadout2D::getNeighbors(CellReadout2D::Cell cell) -//{ -//} - -CellReadout2D::Cell CellReadout2D::createCell(int x, int y) -{ - if (!isValidXIndex(x)) { - std::cerr << "X coordinate is outside readout: " << x << std::endl; - throw std::runtime_error("invalid X index"); - } - if (!isValidYIndex(y)) { - std::cerr << "Y coordinate is outside readout: " << y << std::endl; - throw std::runtime_error("invalid Y index"); - } - Cell cell; - cell.first = x; - cell.second = y; - return cell; -} - -bool CellReadout2D::isValidXIndex(int x) -{ - return x > 0 && x <= getMaximumXIndex(); -} - -bool CellReadout2D::isValidYIndex(int y) -{ - return y > 0 && y <= getMaximumYIndex(); -} - -bool CellReadout2D::isCoordinateInsideX(double x) -{ - return x >= 0 && x <= getReadoutDimensionX(); -} - -bool CellReadout2D::isCoordinateInsideY(double y) -{ - return y >= 1 && y <= getReadoutDimensionY(); -} - -void CellReadout2D::setReadoutDimensionX(double dimensionX) -{ - m_dimensionX = dimensionX; -} - -void CellReadout2D::setReadoutDimensionY(double dimensionY) -{ - m_dimensionY = dimensionY; -} - -int CellReadout2D::getMaximumXIndex() -{ - return getXIndex(getReadoutDimensionX()); -} - -int CellReadout2D::getMaximumYIndex() -{ - return getYIndex(getReadoutDimensionY()); -} - -CellReadout2D::PositionXY CellReadout2D::localToReadoutCoordinates(CellReadout2D::PositionXY localPos) -{ - CellReadout2D::PositionXY readoutPos; - readoutPos.first = localPos.first + this->getReadoutDimensionX() / 2.0; - readoutPos.second = localPos.second + this->getReadoutDimensionY() / 2.0; - return readoutPos; -}
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1