Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,9 @@ \section{The auto Keyword}
\section{Initialization and Assignment}
\label{sec:IniitalizationAndAssignment}

\subsection{Initialization of member variables}
\label{subsec:InitializationOfMemberVariables}

All member variables must be initialized when they are declared. For such
purpose, brace initializers, e.g.

Expand Down Expand Up @@ -1654,6 +1657,54 @@ \section{Initialization and Assignment}
example \code{FixedArray::m\_InternalArray} and \code{Index::m\_InternalArray}
do not have a default member initializer.

\subsection{Initializing variables of fixed size array types}
\label{subsec:InitializingVariablesOfFixedSizeArrayTypes}

ITK has various fixed size array types, including template instantiations of
\code{Index}, \code{Size}, \code{FixedArray}, \code{Point}, and \code{Vector}.

A variable of such a fixed size array type can be zero-initialized by an empty
initializer list, `{}`. This is usually the preferred way to initialize the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`{}` will not highlight the content in LaTeX as you would expect in Markdown: LaTex uses double backticks at the beginning/upright ticks at the end for ticks, simple backticks will render as opening simple ticks both at the beginning/end. To me, the right thing to use here is \code{}.

variable, when it should initially be filled with zeroes. For example:

\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
// Declare an index at position (0, 0).
Index<2> index{};

// Declare a point whose coordinates are all 0.0 (the origin).
PointType origin{};
\end{minted}
\normalsize

\code{Index} and \code{Size} both have a static `Filled(fillValue)` member
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above about bacticks.

function, to allow creating a variable that is filled with an arbitrary value.
For these types, this is usually the preferred way to initialize the variable,
when it should initially be filled with a value that may be non-zero. For
example:

\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
// Declare the index {1, 1, 1}.
auto index = Index<3>::Filled(1);

// Declare the size of an 256 x 256 image.
auto imageSize = Size<2>::Filled(256);
\end{minted}
\normalsize

For other fixed size array types, the function `itk::MakeFilled<T>(fillValue)`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above about backticks.

is preferable, when the array should initially be filled with a value that may
be non-zero. For example:

\small
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cpp}
// Declare a spacing filled with the value 0.5 (for each direction).
// SpacingType is typically defined as Vector<double, Dimension>.
auto spacing = MakeFilled<SpacingType>(0.5);
\end{minted}
\normalsize

\section{Accessing Members}
\label{sec:Accessing Members}

Expand Down