Skip to content

Instantly share code, notes, and snippets.

@bunelr
Last active September 9, 2015 14:57
Show Gist options
  • Save bunelr/3fde138f21e2b280bcee to your computer and use it in GitHub Desktop.
Save bunelr/3fde138f21e2b280bcee to your computer and use it in GitHub Desktop.
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}
\usepackage{keyval}
\usepackage{ifthen}
%====================================
%emphasize vertices --> switch and emph style (e.g. thick,black)
%====================================
\makeatletter
% Standard Values for Parameters
\newcommand{\tikzcuboid@shiftx}{0}
\newcommand{\tikzcuboid@shifty}{0}
\newcommand{\tikzcuboid@dimx}{3}
\newcommand{\tikzcuboid@dimy}{3}
\newcommand{\tikzcuboid@dimz}{3}
\newcommand{\tikzcuboid@scale}{1}
\newcommand{\tikzcuboid@densityx}{1}
\newcommand{\tikzcuboid@densityy}{1}
\newcommand{\tikzcuboid@densityz}{1}
\newcommand{\tikzcuboid@rotation}{0}
\newcommand{\tikzcuboid@anglex}{0}
\newcommand{\tikzcuboid@angley}{90}
\newcommand{\tikzcuboid@anglez}{225}
\newcommand{\tikzcuboid@scalex}{1}
\newcommand{\tikzcuboid@scaley}{1}
\newcommand{\tikzcuboid@scalez}{sqrt(0.5)}
\newcommand{\tikzcuboid@linefront}{black}
\newcommand{\tikzcuboid@linetop}{black}
\newcommand{\tikzcuboid@lineright}{black}
\newcommand{\tikzcuboid@fillfront}{white}
\newcommand{\tikzcuboid@filltop}{white}
\newcommand{\tikzcuboid@fillright}{white}
\newcommand{\tikzcuboid@shaded}{N}
\newcommand{\tikzcuboid@shadecolor}{black}
\newcommand{\tikzcuboid@shadeperc}{25}
\newcommand{\tikzcuboid@emphedge}{N}
\newcommand{\tikzcuboid@emphstyle}{thick}
% Definition of Keys
\define@key{tikzcuboid}{shiftx}[\tikzcuboid@shiftx]{\renewcommand{\tikzcuboid@shiftx}{#1}}
\define@key{tikzcuboid}{shifty}[\tikzcuboid@shifty]{\renewcommand{\tikzcuboid@shifty}{#1}}
\define@key{tikzcuboid}{dimx}[\tikzcuboid@dimx]{\renewcommand{\tikzcuboid@dimx}{#1}}
\define@key{tikzcuboid}{dimy}[\tikzcuboid@dimy]{\renewcommand{\tikzcuboid@dimy}{#1}}
\define@key{tikzcuboid}{dimz}[\tikzcuboid@dimz]{\renewcommand{\tikzcuboid@dimz}{#1}}
\define@key{tikzcuboid}{scale}[\tikzcuboid@scale]{\renewcommand{\tikzcuboid@scale}{#1}}
\define@key{tikzcuboid}{densityx}[\tikzcuboid@densityx]{\renewcommand{\tikzcuboid@densityx}{#1}}
\define@key{tikzcuboid}{densityy}[\tikzcuboid@densityy]{\renewcommand{\tikzcuboid@densityy}{#1}}
\define@key{tikzcuboid}{densityz}[\tikzcuboid@densityz]{\renewcommand{\tikzcuboid@densityz}{#1}}
\define@key{tikzcuboid}{rotation}[\tikzcuboid@rotation]{\renewcommand{\tikzcuboid@rotation}{#1}}
\define@key{tikzcuboid}{anglex}[\tikzcuboid@anglex]{\renewcommand{\tikzcuboid@anglex}{#1}}
\define@key{tikzcuboid}{angley}[\tikzcuboid@angley]{\renewcommand{\tikzcuboid@angley}{#1}}
\define@key{tikzcuboid}{anglez}[\tikzcuboid@anglez]{\renewcommand{\tikzcuboid@anglez}{#1}}
\define@key{tikzcuboid}{scalex}[\tikzcuboid@scalex]{\renewcommand{\tikzcuboid@scalex}{#1}}
\define@key{tikzcuboid}{scaley}[\tikzcuboid@scaley]{\renewcommand{\tikzcuboid@scaley}{#1}}
\define@key{tikzcuboid}{scalez}[\tikzcuboid@scalez]{\renewcommand{\tikzcuboid@scalez}{#1}}
\define@key{tikzcuboid}{linefront}[\tikzcuboid@linefront]{\renewcommand{\tikzcuboid@linefront}{#1}}
\define@key{tikzcuboid}{linetop}[\tikzcuboid@linetop]{\renewcommand{\tikzcuboid@linetop}{#1}}
\define@key{tikzcuboid}{lineright}[\tikzcuboid@lineright]{\renewcommand{\tikzcuboid@lineright}{#1}}
\define@key{tikzcuboid}{fillfront}[\tikzcuboid@fillfront]{\renewcommand{\tikzcuboid@fillfront}{#1}}
\define@key{tikzcuboid}{filltop}[\tikzcuboid@filltop]{\renewcommand{\tikzcuboid@filltop}{#1}}
\define@key{tikzcuboid}{fillright}[\tikzcuboid@fillright]{\renewcommand{\tikzcuboid@fillright}{#1}}
\define@key{tikzcuboid}{shaded}[\tikzcuboid@shaded]{\renewcommand{\tikzcuboid@shaded}{#1}}
\define@key{tikzcuboid}{shadecolor}[\tikzcuboid@shadecolor]{\renewcommand{\tikzcuboid@shadecolor}{#1}}
\define@key{tikzcuboid}{shadeperc}[\tikzcuboid@shadeperc]{\renewcommand{\tikzcuboid@shadeperc}{#1}}
\define@key{tikzcuboid}{emphedge}[\tikzcuboid@emphedge]{\renewcommand{\tikzcuboid@emphedge}{#1}}
\define@key{tikzcuboid}{emphstyle}[\tikzcuboid@emphstyle]{\renewcommand{\tikzcuboid@emphstyle}{#1}}
% Commands
\newcommand{\tikzcuboid}[1]{
\setkeys{tikzcuboid}{#1} % Process Keys passed to command
\pgfmathsetmacro{\vectorxx}{\tikzcuboid@scalex*cos(\tikzcuboid@anglex)}
\pgfmathsetmacro{\vectorxy}{\tikzcuboid@scalex*sin(\tikzcuboid@anglex)}
\pgfmathsetmacro{\vectoryx}{\tikzcuboid@scaley*cos(\tikzcuboid@angley)}
\pgfmathsetmacro{\vectoryy}{\tikzcuboid@scaley*sin(\tikzcuboid@angley)}
\pgfmathsetmacro{\vectorzx}{\tikzcuboid@scalez*cos(\tikzcuboid@anglez)}
\pgfmathsetmacro{\vectorzy}{\tikzcuboid@scalez*sin(\tikzcuboid@anglez)}
\begin{scope}[xshift=\tikzcuboid@shiftx, yshift=\tikzcuboid@shifty, scale=\tikzcuboid@scale, rotate=\tikzcuboid@rotation, x={(\vectorxx,\vectorxy)}, y={(\vectoryx,\vectoryy)}, z={(\vectorzx,\vectorzy)}]
\pgfmathsetmacro{\steppingx}{1/\tikzcuboid@densityx}
\pgfmathsetmacro{\steppingy}{1/\tikzcuboid@densityy}
\pgfmathsetmacro{\steppingz}{1/\tikzcuboid@densityz}
\newcommand{\dimx}{\tikzcuboid@dimx}
\newcommand{\dimy}{\tikzcuboid@dimy}
\newcommand{\dimz}{\tikzcuboid@dimz}
\pgfmathsetmacro{\secondx}{2*\steppingx}
\pgfmathsetmacro{\secondy}{2*\steppingy}
\pgfmathsetmacro{\secondz}{2*\steppingz}
% X-span
\pgfmathtruncatemacro{\squarenumberx}{\dimx / \steppingx}
\ifthenelse{\equal{\squarenumberx}{1}}
{
\newcommand\totraversex{\steppingx}
}{
\newcommand\totraversex{\steppingx,\secondx,...,\dimx}
}
% Y-span
\pgfmathtruncatemacro{\squarenumbery}{\dimy / \steppingy}
\ifthenelse{\equal{\squarenumbery}{1}}
{
\newcommand\totraversey{\steppingy}
}{
\newcommand\totraversey{\steppingy,\secondy,...,\dimy}
}
% Z-span
\pgfmathtruncatemacro{\squarenumberz}{\dimz / \steppingz}
\ifthenelse{\equal{\squarenumberz}{1}}
{
\newcommand\totraversez{\steppingz}
}{
\newcommand\totraversez{\steppingz,\secondz,...,\dimz}
}
% Front Face
\foreach \x in \totraversex
{
\foreach \y in \totraversey
{
\pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\filldraw[fill=\tikzcuboid@fillfront,draw=\tikzcuboid@linefront] (\lowx,\lowy,\dimz) -- (\lowx,\y,\dimz) -- (\x,\y,\dimz) -- (\x,\lowy,\dimz) -- cycle;
}
}
% Top Face
\foreach \x in \totraversex
{
\foreach \z in \totraversez
{
\pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[fill=\tikzcuboid@filltop,draw=\tikzcuboid@linetop] (\lowx,\dimy,\lowz) -- (\lowx,\dimy,\z) -- (\x,\dimy,\z) -- (\x,\dimy,\lowz) -- cycle;
}
}
% Side Face
\foreach \y in \totraversey
{ \foreach \z in \totraversez
{
\pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[fill=\tikzcuboid@fillright,draw=\tikzcuboid@lineright] (\dimx,\lowy,\lowz) -- (\dimx,\lowy,\z) -- (\dimx,\y,\z) -- (\dimx,\y,\lowz) -- cycle;
}
}
\iffalse
\ifthenelse{\equal{\tikzcuboid@emphedge}{Y}}%
{\draw[\tikzcuboid@emphstyle](0,\dimy,0) -- (\dimx,\dimy,0) -- (\dimx,\dimy,\dimz) -- (0,\dimy,\dimz) -- cycle;%
\draw[\tikzcuboid@emphstyle] (0,0,\dimz) -- (0,\dimy,\dimz) -- (\dimx,\dimy,\dimz) -- (\dimx,0,\dimz) -- cycle;%
\draw[\tikzcuboid@emphstyle](\dimx,0,0) -- (\dimx,\dimy,0) -- (\dimx,\dimy,\dimz) -- (\dimx,0,\dimz) -- cycle;%
}%
{}
\fi
\end{scope}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\tikzcuboid{shiftx=0cm,%
shifty=0cm,%
scale=1.00,%
rotation=0,%
densityx=3,%
densityy=5,%
densityz=5,%
dimx=1,%
dimy=3,%
dimy=5,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](img) at (-1,-2) {Image};
\tikzcuboid{shiftx=3cm,%
shifty=0.2cm,%
scale=0.95,%
rotation=0,%
densityx=6,%
densityy=5,%
densityz=5,%
dimx=2,%
dimy=3,%
dimy=5,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](conv2) at (3, -2) {conv2\_out};
\draw[->, thick] (img) -- (conv2) node [pos=0.5, below, yshift=-10] {conv1+conv2};
\tikzcuboid{shiftx=6cm,%
shifty=1cm,%
scale=0.5,%
rotation=0,%
densityx=3,%
densityy=3,%
densityz=3,%
dimx=4,%
dimy=3,%
dimy=5,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](mp1) at (6.5, -2) {maxpool1\_out};
\draw[->, thick] (conv2) -- (mp1) node [pos=0.5, below, yshift=-10] {maxpooling};
\tikzcuboid{shiftx=9cm,%
shifty=1.2cm,%
scale=0.4,%
rotation=0,%
densityx=3,%
densityy=3,%
densityz=3,%
dimx=6,%
dimy=3,%
dimy=5,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](conv4) at (10, -2) {conv4\_out};
\draw[->, thick] (mp1) -- (conv4) node [pos=0.5, below, yshift=-10] {conv3 + conv4};
\tikzcuboid{shiftx=12cm,%
shifty=1.4cm,%
scale=0.2,%
rotation=0,%
densityx=2,%
densityy=1,%
densityz=1,%
dimx=12,%
dimy=3,%
dimy=5,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](mp2) at (13, -2) {maxpool2\_out};
\draw[->, thick] (conv4) -- (mp2) node [pos=0.5, below, yshift=-10] {maxpooling};
\tikzcuboid{shiftx=15cm,%
shifty=1.7cm,%
scale=0.2,%
rotation=0,%
densityx=2,%
densityy=1,%
densityz=1,%
dimx=15,%
dimy=1,%
dimz=1,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](conv5) at (16.5, -2) {conv5\_out};
\draw[->, thick] (mp2) -- (conv5) node [pos=0.5, below, yshift=-10] {conv5};
\tikzcuboid{shiftx=19.5cm,%
shifty=1.7cm,%
scale=0.2,%
rotation=0,%
densityx=1,%
densityy=1,%
densityz=1,%
dimx=1,%
dimy=1,%
dimz=1,%
linefront=yellow!30!black,%
linetop=red!30!black,%
lineright=blue!30!black,%
fillfront=gray!30!white,%
filltop=gray!30!white,%
fillright=gray!30!white%
}
\node[draw](final) at (20, -2) {Prediction};
\draw[->, thick] (conv5) -- (final) node [pos=0.5, below, yshift=-10] {conv6+conv7};
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment