⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmcimg.tex

📁 蒙特卡罗模拟光子成像C语言版,代码简洁专业
💻 TEX
📖 第 1 页 / 共 2 页
字号:
\hline
mua        & required & Tissue $\mu_a$ \\
\hline
g          & required & Tissue anisotropy parameter \\
\hline
n          & required & Tissue index of refraction\\
\hline
\hline
detector   & N/A & Introduce detector definition \\
\hline
source     & N/A & Introduce source definition \\
\hline
pos        & required & Source/Detector position \\
\hline
dir        & varies & Source/Detector direction \\
\hline
rad        & varies & Source/Detector radius \\
\hline
na         & 0 & Source/Detector numerical aperature \\
\hline
\hline
dx         & 1 & mm per voxel in X direction \\
\hline
dy         & 1 & currently only square voxels supported \\
\hline
dz         & 1 & \\
\hline
nxvox      & required & Total number of voxels in X \\
\hline
nyvox      & required & Total number of voxels in Y \\
\hline
nzvox      & required & Total number of voxels in Z \\
\hline
image\_x    & $0$--$\mbox{nxvox}-1$ & Region of interest \\
\hline
image\_y    & $0$--$\mbox{nyvox}-1$ & \\
\hline
image\_z    & $0$--$\mbox{nzvox}-1$ & \\
\hline
\end{tabular}
\end{center}
\caption{Configuration file keywords}
\label{tbl:keywords}
\end{table}

\subsection{Segmentation File}
\label{sub:segmentation_file}

The segmentation file is a contiguous block of data, one unsigned
8-bit number for every voxel being modeled.  A value of '0' is used
for ``air''; any photon making its way into the air is assumed to have
left the system.  A photon is recorded by a given detector if it exits
into ``air'' and its final position is within the specified radius of
the detector location.  Values greater than one correspond to tissues
whose optical properties were specified in the configuration file; the
first tissue defined is '1', the second tissue defined is '2', and so
on.  An error occurs if the value in any voxel of the segmentation
file exceedes the total number of defined tissue types.

{\bf Important note:} by default, \tMCimg\ assumes that the segmentation
data was generated by Matlab, which uses column-major storage instead
the usual C/C++ row-major storage.  If you are generating the
segmentation map from a C program, you must either transpose the X and
Y coordinates when you write out the data or use the ``-m'' flag when
running \tMCimg.  See Figures~\ref{fig:matlab_ex} and \ref{fig:C_ex}
for sample Matlab and C/C++ code respectively.

\begin{figure}
\begin{verbatim}
>> boundData = uint8(zeros(40,50,10));
>> boundData(:,:,2:9) = 1;
>> % Any other initializations would go here
>> fid = fopen('sample.bin', 'wb');
>> fwrite(fid, boundData, 'uint8);
>> fclose(fid);
\end{verbatim}
\caption{Sample Matlab code for writing a simple ``slab'' boundary
geometry.  Normally, source would be located in the $z=1$ plane
and detectors in either the $z=1$ or $z=10$ plane for this type
of boundary arrangement.  Because there is no layer of 0's around
the edges in $X$ or $Y$, photons leaving through the sides of the box
will be lost.}
\label{fig:matlab_ex}
\end{figure}

\begin{figure}
\begin{verbatim}
unsigned char boundData[40][50][10];
int i, j, k;
FILE *fp;

/* Initialize boundData.  The for-loops could probably
 *  be replaced with a memset(), but doing it this way
 *  is easier to follow */

memset(boundData, 0, sizeof(boundData));

for (k = 1; k < 9; k++)
  for (j = 0; j < 50; j++)
    for (i = 0; i < 40; i++)
      boundData[i][j][k] = 1;

/* Any other initializations would go here */

fp = fopen("sample.bin", "wb");

for (k = 0; k < 10; k++)
  for (i = 0; i < 40; i++)
    for (j = 0; j < 50; j++)
      fputc(boundData[i][j][k], fp);

fclose(fd);
\end{verbatim}
\caption{Sample C/C++ code for writing the same segmentation file as
in Figure~\ref{fig:matlab_ex}.}
\label{fig:C_ex}
\end{figure}

\section{Output File Format}
\label{sec:output_file}

The output of the program consists of two datafiles: the history
file and the two-point file.

\subsection{History Files}
\label{sub:history_file}

The history file contains a record of every photon that successfully
traversed the volume.  There are two different file formats for the
history file, based on the settings in the {\tt .cfg} file.  If no
detectors were specified, then the $(x,y,z)$ location of every photon
exiting the medium is recorded together with the time and the distance
the photon traveled inside each tissue type.  If at least one detector
was specified, the number of the detector that saw the photon is
recorded, along with the time and lengths as before.

\begin{table}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
$x_1$ & $y_1$ & $z_1$ & $t_1$ &
	$l^{(0)}_1$ & $l^{(1)}_1$ & \quad $\cdots$ \quad & $l^{(n)}_1$ \\
\hline
$x_2$ & $y_2$ & $z_2$ & $t_2$ &
	$l^{(0)}_2$ & $l^{(1)}_2$ & \quad $\cdots$ \quad & $l^{(n)}_2$ \\
\hline
\multicolumn{8}{c}{$\vdots$} \\
\hline
$x_N$ & $y_N$ & $z_N$ &  $t_N$ &
	$l^{(0)}_N$ & $l^{(1)}_N$ & \quad $\cdots$ \quad & $l^{(n)}_N$ \\
\hline
\end{tabular}
\end{center}
\caption{Format of history file when no detectors are specified.
	The file contains the $(x,y,z,t)$ position and the path length
	inside each of the $n$ tissue for all $N$ of the exiting
	photons.  All values are stored as 32-bit floating point
	numbers.}
\label{1.his}
\end{table}

\begin{table}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$d_1$ & $t_1$ & $l^{(0)}_1$ & $l^{(1)}_1$ & 
			\quad $\cdots$ \quad & $l^{(n)}_1$ \\
\hline
$d_2$ & $t_1$ & $l^{(0)}_2$ & $l^{(1)}_2$ & 
			\quad $\cdots$ \quad & $l^{(n)}_2$ \\
\hline
\multicolumn{6}{c}{$\vdots$} \\
\hline
$d_N$ & $t_1$ & $l^{(0)}_N$ & $l^{(1)}_N$ & 
			\quad $\cdots$ \quad & $l^{(n)}_N$ \\
\hline
\end{tabular}
\end{center}
\caption{Format of history file when a non-zero number of detectors
        are specified.  The file contains the number of the detector
	that recorded the photon and the path length inside each of
	the $n$ tissue for all $N$ of the exiting photons.  Note that
	it is possible for a single photon to be recorded by multiple
	detectors if the spacing between detectors is less than twice
	their radius.  All values are stored as 32-bit floating point
	numbers.}
\label{2.his}
\end{table}

To compute the fluence at the detector, sum and scale by $x$.

\subsection{Two-point Files}
\label{sub:two_point_file}

The two-point file ({\tt *.2pt}) contains the photon density at every
voxel and time gate, as computed by the Monte Carlo simulation.  The
data is stored as ``double'''s (64-bit IEEE floating point
representation) and the voxels are orded the same way as the
segmentation file (see Section~\ref{sub:segmentation_file}).  The real
part of all the time gates are written out sequentially, followed by
the imaginary parts (see Table~\ref{tbl:2pt}).

\begin{table}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Time Gate 1      & Time Gate 2     & $\cdots$   & Time Gate N    \\
Real Part        & Real Part       &            & Real Part      \\
\hline
\multicolumn{4}{c}{$\vdots$} \\
\hline
Time Gate 1      & Time Gate 2      & $\cdots$  & Time Gate N    \\
Imaginary Part   & Imaginary Part   &           & Imaginary Part \\
\hline 
\end{tabular}
\end{center}
\caption{Ordering of the two-point file.  Each block consists of
an $N_y\times N_x\times N_z$ block of doubles.}
\label{tbl:2pt}
\end{table}

Thus, if the simulation is run with two time gates on a $(N_x,N_y,N_z)$
volume, the first $N_y\times N_x\times N_z$ doubles will be the real part
of the first time gate, the second $N_y\times N_x\times N_z$ doubles will
be the real part of the second time gate, the third $N_y\times N_x\times
N_z$ doubles will be the the imaginary part of the first time gate, and
the final $N_y\times N_x\times N_z$ doubles will be the the imaginary
part of the second time gate.

Unscaled fluence for every voxel in the image.  
Missing scale factor is $\approx 1/N$.

\appendix
\section{Utility Programs}

\subsection{cfg2inp}

Convert {\tt .cfg} files into old-style {\tt .inp} for legacy support
(mostly Matlab code, which handles the fixed-format {\tt .inp} files much
better than the newer free-format {\tt .cfg} files).

\subsection{tmcv}

OpenGL viewer for {\tt .2pt} files, part of the {\tt tfwd} package.

% \section{References}
%
% \bibliographystyle{unsrt}
% \bibliography{mcrefs}

\end{document}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -