** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: scanner.cpp,v 1.30 2001/02/08 06:25:07 kevin Exp $
+** $Id$
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
const int Scanner::GEOMETRY_PARALLEL = 0;
const int Scanner::GEOMETRY_EQUIANGULAR = 1;
const int Scanner::GEOMETRY_EQUILINEAR = 2;
+const int Scanner::GEOMETRY_LINOGRAM = 3;
-const char* Scanner::s_aszGeometryName[] =
+const char* const Scanner::s_aszGeometryName[] =
{
- {"parallel"},
- {"equiangular"},
- {"equilinear"},
+ "parallel",
+ "equiangular",
+ "equilinear",
+ "linogram",
};
-const char* Scanner::s_aszGeometryTitle[] =
+const char* const Scanner::s_aszGeometryTitle[] =
{
- {"Parallel"},
- {"Equiangular"},
- {"Equilinear"},
+ "Parallel",
+ "Equiangular",
+ "Equilinear",
+ "Linogram",
};
const int Scanner::s_iGeometryCount = sizeof(s_aszGeometryName) / sizeof(const char*);
*/
Scanner::Scanner (const Phantom& phm, const char* const geometryName,
- int nDet, int nView, int nSample, const double rot_anglen,
- const double dFocalLengthRatio, const double dViewRatio,
- double dScanRatio)
+ int nDet, int nView, int offsetView,
+ int nSample, const double rot_anglen,
+ const double dFocalLengthRatio,
+ const double dCenterDetectorRatio,
+ const double dViewRatio, const double dScanRatio)
{
m_fail = false;
m_idGeometry = convertGeometryNameToID (geometryName);
m_nDet = nDet;
m_nView = nView;
+ m_iOffsetView = offsetView;
m_nSample = nSample;
m_dFocalLengthRatio = dFocalLengthRatio;
+ m_dCenterDetectorRatio = dCenterDetectorRatio;
m_dViewRatio = dViewRatio;
m_dScanRatio = dScanRatio;
+
m_dViewDiameter = phm.getDiameterBoundaryCircle() * m_dViewRatio;
- m_dFocalLength = (m_dViewDiameter / 2) * dFocalLengthRatio;
+ m_dFocalLength = (m_dViewDiameter / 2) * m_dFocalLengthRatio;
+ m_dCenterDetectorLength = (m_dViewDiameter / 2) * m_dCenterDetectorRatio;
+ m_dSourceDetectorLength = m_dFocalLength + m_dCenterDetectorLength;
m_dScanDiameter = m_dViewDiameter * m_dScanRatio;
m_dXCenter = phm.xmin() + (phm.xmax() - phm.xmin()) / 2;
m_rotLen = rot_anglen;
m_rotInc = m_rotLen / m_nView;
if (m_idGeometry == GEOMETRY_PARALLEL) {
+ m_dFanBeamAngle = 0;
m_detLen = m_dScanDiameter;
+ m_detStart = -m_detLen / 2;
m_detInc = m_detLen / m_nDet;
- if (m_nDet % 2 == 0) // Adjust for Even number of detectors
- m_detInc = m_detLen / (m_nDet - 1); // center detector = (nDet/2)-1
-
- m_dFanBeamAngle = 0;
+ double dDetectorArrayEndOffset = 0;
+ // For even number of detectors, make detInc slightly larger so that center lies
+ // at nDet/2. Also, extend detector array by one detInc so that all of the phantom is scanned
+ if (isEven (m_nDet)) { // Adjust for Even number of detectors
+ m_detInc = m_detLen / (m_nDet - 1); // center detector = (nDet/2)
+ dDetectorArrayEndOffset = m_detInc;
+ }
+
double dHalfDetLen = m_detLen / 2;
m_initPos.xs1 = m_dXCenter - dHalfDetLen;
m_initPos.ys1 = m_dYCenter + m_dFocalLength;
- m_initPos.xs2 = m_dXCenter + dHalfDetLen;
+ m_initPos.xs2 = m_dXCenter + dHalfDetLen + dDetectorArrayEndOffset;
m_initPos.ys2 = m_dYCenter + m_dFocalLength;
m_initPos.xd1 = m_dXCenter - dHalfDetLen;
- m_initPos.yd1 = m_dYCenter - m_dFocalLength;
- m_initPos.xd2 = m_dXCenter + dHalfDetLen;
- m_initPos.yd2 = m_dYCenter - m_dFocalLength;
- m_initPos.angle = 0.0;
+ m_initPos.yd1 = m_dYCenter - m_dCenterDetectorLength;
+ m_initPos.xd2 = m_dXCenter + dHalfDetLen + dDetectorArrayEndOffset;
+ m_initPos.yd2 = m_dYCenter - m_dCenterDetectorLength;
+ m_initPos.angle = m_iOffsetView * m_rotInc;
+ m_detLen += dDetectorArrayEndOffset;
} else if (m_idGeometry == GEOMETRY_EQUILINEAR) {
if (m_dScanDiameter / 2 >= m_dFocalLength) {
m_fail = true;
m_failMessage = "Invalid geometry: Focal length must be larger than scan length";
return;
}
+
const double dAngle = asin ((m_dScanDiameter / 2) / m_dFocalLength);
- const double dHalfDetLen = 2 * m_dFocalLength * tan (dAngle);
+ const double dHalfDetLen = m_dSourceDetectorLength * tan (dAngle);
m_detLen = dHalfDetLen * 2;
+ m_detStart = -dHalfDetLen;
m_detInc = m_detLen / m_nDet;
- if (m_nDet % 2 == 0) // Adjust for Even number of detectors
- m_detInc = m_detLen / (m_nDet - 1); // center detector = (nDet/2)-1
+ double dDetectorArrayEndOffset = 0;
+ if (isEven (m_nDet)) { // Adjust for Even number of detectors
+ m_detInc = m_detLen / (m_nDet - 1); // center detector = (nDet/2)
+ dDetectorArrayEndOffset = m_detInc;
+ m_detLen += dDetectorArrayEndOffset;
+ }
m_dFanBeamAngle = dAngle * 2;
- m_initPos.angle = 0.0;
m_initPos.xs1 = m_dXCenter;
m_initPos.ys1 = m_dYCenter + m_dFocalLength;
m_initPos.xs2 = m_dXCenter;
m_initPos.ys2 = m_dYCenter + m_dFocalLength;
m_initPos.xd1 = m_dXCenter - dHalfDetLen;
- m_initPos.yd1 = m_dYCenter - m_dFocalLength;
- m_initPos.xd2 = m_dXCenter + dHalfDetLen;
- m_initPos.yd2 = m_dYCenter - m_dFocalLength;
- m_initPos.angle = 0.0;
+ m_initPos.yd1 = m_dYCenter - m_dCenterDetectorLength;
+ m_initPos.xd2 = m_dXCenter + dHalfDetLen + dDetectorArrayEndOffset;
+ m_initPos.yd2 = m_dYCenter - m_dCenterDetectorLength;
+ m_initPos.angle = m_iOffsetView * m_rotInc;
} else if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
if (m_dScanDiameter / 2 > m_dFocalLength) {
m_fail = true;
const double dAngle = asin ((m_dScanDiameter / 2) / m_dFocalLength);
m_detLen = 2 * dAngle;
+ m_detStart = -dAngle;
m_detInc = m_detLen / m_nDet;
- if (m_nDet % 2 == 0) // Adjust for Even number of detectors
- m_detInc = m_detLen / (m_nDet - 1); // center detector = (nDet/2)-1
- m_dAngularDetIncrement = m_detInc * 2; // Angular Position 2x gamma angle
- m_dAngularDetLen = m_detLen * 2;
+ double dDetectorArrayEndOffset = 0;
+ if (isEven (m_nDet)) { // Adjust for Even number of detectors
+ m_detInc = m_detLen / (m_nDet - 1); // center detector = (nDet/2)
+ dDetectorArrayEndOffset = m_detInc;
+ }
+ // adjust for center-detector length
+ double dA1 = acos ((m_dScanDiameter / 2) / m_dCenterDetectorLength);
+ double dAngularScale = 2 * (HALFPI + dAngle - dA1) / m_detLen;
+
+ m_dAngularDetLen = dAngularScale * (m_detLen + dDetectorArrayEndOffset);
+ m_dAngularDetIncrement = dAngularScale * m_detInc;
m_initPos.dAngularDet = -m_dAngularDetLen / 2;
m_dFanBeamAngle = dAngle * 2;
- m_initPos.angle = 0;
+ m_initPos.angle = m_iOffsetView * m_rotInc;
m_initPos.xs1 = m_dXCenter;
m_initPos.ys1 = m_dYCenter + m_dFocalLength;;
m_initPos.xs2 = m_dXCenter;
m_initPos.ys2 = m_dYCenter + m_dFocalLength;
+ m_detLen += dDetectorArrayEndOffset;
}
// Calculate incrementatal rotation matrix
void
Scanner::collectProjections (Projections& proj, const Phantom& phm, const int trace, SGP* pSGP)
{
- collectProjections (proj, phm, 0, proj.nView(), true, trace, pSGP);
+ collectProjections (proj, phm, m_startView, proj.nView(), m_iOffsetView, true, trace, pSGP);
+}
+
+void
+Scanner::collectProjections (Projections& proj, const Phantom& phm, const int iStartView,
+ const int iNumViews, const int iOffsetView, bool bStoreAtViewPosition,
+ const int trace, SGP* pSGP)
+{
+ int iStorageOffset = (bStoreAtViewPosition ? iStartView : 0);
+ collectProjections (proj, phm, iStartView, iNumViews, iOffsetView, iStorageOffset, trace, pSGP);
}
void
-Scanner::collectProjections (Projections& proj, const Phantom& phm, const int iStartView, const int iNumViews, bool bStoreAtViewPosition, const int trace, SGP* pSGP)
+Scanner::collectProjections (Projections& proj, const Phantom& phm, const int iStartView,
+ const int iNumViews, const int iOffsetView, int iStorageOffset,
+ const int trace, SGP* pSGP)
{
m_trace = trace;
- double start_angle = iStartView * proj.rotInc();
+ double start_angle = (iStartView + iOffsetView) * proj.rotInc();
// Calculate initial rotation matrix
GRFMTX_2D rotmtx_initial, temp;
int iView;
double viewAngle;
for (iView = 0, viewAngle = start_angle; iView < iNumViews; iView++, viewAngle += proj.rotInc()) {
- int iStoragePosition = iView;
- if (bStoreAtViewPosition)
- iStoragePosition += iStartView;
-
+ int iStoragePosition = iView + iStorageOffset;
+
DetectorArray& detArray = proj.getDetectorArray( iStoragePosition );
#ifdef HAVE_SGP
if (pSGP && m_trace >= Trace::TRACE_PHANTOM) {
m_pSGP = pSGP;
- double dWindowSize = dmax (m_detLen, m_dFocalLength * 2) * SQRT2;
+ double dWindowSize = dmax (m_detLen, m_dSourceDetectorLength) * 2;
double dHalfWindowSize = dWindowSize / 2;
m_dXMinWin = m_dXCenter - dHalfWindowSize;
m_dXMaxWin = m_dXCenter + dHalfWindowSize;
m_pSGP->setColor (C_GREEN);
m_pSGP->drawCircle (m_dFocalLength);
m_pSGP->setColor (C_BLUE);
+#if MSVC
m_pSGP->setTextPointSize (9);
+#else
+ m_pSGP->setTextPointSize (14);
+#endif
phm.draw (*m_pSGP);
m_dTextHeight = m_pSGP->getCharHeight ();
traceShowParam ("Phantom:", "%s", PROJECTION_TRACE_ROW_PHANT_ID, C_BLACK, phm.name().c_str());
traceShowParam ("Geometry:", "%s", PROJECTION_TRACE_ROW_GEOMETRY, C_BLUE, convertGeometryIDToName(m_idGeometry));
traceShowParam ("Focal Length Ratio:", "%.2f", PROJECTION_TRACE_ROW_FOCAL_LENGTH, C_BLUE, m_dFocalLengthRatio);
-// traceShowParam ("Field Of View Ratio:", "%.2f", PROJECTION_TRACE_ROW_FIELD_OF_VIEW, C_BLUE, m_dFieldOfViewRatio);
+ // traceShowParam ("Field Of View Ratio:", "%.2f", PROJECTION_TRACE_ROW_FIELD_OF_VIEW, C_BLUE, m_dFieldOfViewRatio);
traceShowParam ("Num Detectors:", "%d", PROJECTION_TRACE_ROW_NDET, C_BLUE, proj.nDet());
traceShowParam ("Num Views:", "%d", PROJECTION_TRACE_ROW_NVIEW, C_BLUE, proj.nView());
traceShowParam ("Samples / Ray:", "%d", PROJECTION_TRACE_ROW_SAMPLES, C_BLUE, m_nSample);
- m_pSGP->setMarker (SGP::MARK_BDIAMOND, C_LTGREEN);
+ m_pSGP->setMarker (SGP::MARKER_BDIAMOND);
}
#endif
m_pSGP->lineAbs (xs2, ys2);
m_pSGP->setPenWidth (2);
m_pSGP->moveAbs (0., 0.);
- m_pSGP->drawArc (m_dFocalLength, viewAngle + 3 * HALFPI - (m_dAngularDetLen/2), viewAngle + 3 * HALFPI + (m_dAngularDetLen/2));
+ m_pSGP->drawArc (m_dCenterDetectorLength, viewAngle + 3 * HALFPI - (m_dAngularDetLen/2), viewAngle + 3 * HALFPI + (m_dAngularDetLen/2));
}
m_pSGP->setPenWidth (1);
}
if (phm.getComposition() == P_UNIT_PULSE) { // put unit pulse in center of view
for (int d = 0; d < detArray.nDet(); d++)
- if (detArray.nDet() / 2 == d && (d % 2) == 1)
- detval[d] = 1;
- else
detval[d] = 0;
+ detval[ detArray.nDet() / 2 ] = 1;
} else {
for (int d = 0; d < detArray.nDet(); d++) {
double xs = xs_maj;
double sum = 0.0;
for (unsigned int i = 0; i < m_nSample; i++) {
if (m_idGeometry == GEOMETRY_EQUIANGULAR) {
- xd = m_dFocalLength * cos (dAngle);
- yd = m_dFocalLength * sin (dAngle);
+ xd = m_dCenterDetectorLength * cos (dAngle);
+ yd = m_dCenterDetectorLength * sin (dAngle);
}
#ifdef HAVE_SGP