Sorting Network Verify and Draw
Check Whether Comparator Networks Sort and Draw Them
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CRenderableComparatorNet Class Reference

Renderable comparator network. More...

#include <RenderableComparatorNet.h>

Inheritance diagram for CRenderableComparatorNet:
CComparatorNetwork CSortingNetwork CBitonicSort CBubbleSort CBubbleSortMax CBubbleSortMin COddEvenSort CPairwiseSort

Public Member Functions

 ~CRenderableComparatorNet ()
 Destructor. More...
 
void Draw (const eDrawStyle)
 Draw to a Gdiplus::Bitmap. More...
 
HRESULT ExportToPNG (LPWSTR)
 Export in PNG format. More...
 
HRESULT ExportToTex (LPWSTR)
 Export in TeX format. More...
 
HRESULT ExportToSVG (LPWSTR)
 Export in SVG format. More...
 
Gdiplus::Bitmap * GetBitmap ()
 Get bitmap pointer. More...
 
- Public Member Functions inherited from CComparatorNetwork
 ~CComparatorNetwork ()
 Destructor. More...
 
virtual bool Read (LPWSTR)
 Read from file. More...
 
void Prune (const UINT)
 Prune down number of inputs. More...
 
const UINT GetNumInputs () const
 Get number of inputs. More...
 
const UINT GetDepth () const
 Get depth. More...
 
const UINT GetSize () const
 Get size. More...
 
const bool FirstNormalForm () const
 Test for first normal form. More...
 

Protected Member Functions

Gdiplus::REAL ComputeBitmapHeight ()
 Compute bitmap height. More...
 
void DrawChannels (const float fLen)
 Draw channels. More...
 
void DrawComparator (const UINT, const UINT, const float, bool=false)
 Draw a comparator. More...
 
void DrawComparators ()
 Draw all comparators. More...
 
- Protected Member Functions inherited from CComparatorNetwork
void InsertComparator (UINT, UINT, UINT)
 Insert comparator. More...
 
void CreateMatchArray (UINT, UINT)
 Create match array. More...
 
void ComputeSize ()
 Compute size. More...
 

Protected Attributes

const Gdiplus::REAL m_fPenWidth = 2.0f
 Pen width in pixels. More...
 
const Gdiplus::REAL m_fXDelta = 24.0f
 Gap between channels in pixels. More...
 
const Gdiplus::REAL m_fYDelta = 16.0f
 Vertical comparator gap in pixels. More...
 
const Gdiplus::REAL m_fYDelta2 = 8.0f
 Extra vertical gap between layers in pixels. More...
 
const Gdiplus::REAL m_fDiameter = 8.0f
 Diameter of circles in pixels. More...
 
Gdiplus::Bitmap * m_pBitmap = nullptr
 Pointer to a bitmap image. More...
 
eDrawStyle m_eDrawStyle = eDrawStyle::Horizontal
 Drawing style. More...
 
Gdiplus::Graphics * m_pGraphics = nullptr
 Pointer to graphics object. More...
 
Gdiplus::Pen * m_pPen = nullptr
 Pointer to graphics pen. More...
 
Gdiplus::Pen * m_pRedPen = nullptr
 Pointer to graphics pen. More...
 
Gdiplus::SolidBrush * m_pBrush = nullptr
 Pointer to graphics brush. More...
 
Gdiplus::SolidBrush * m_pRedBrush = nullptr
 Pointer to graphics brush. More...
 
FILE * m_pOutput = nullptr
 File pointer. More...
 
eExport m_eExportType = eExport::Png
 Export type. More...
 
- Protected Attributes inherited from CComparatorNetwork
UINT ** m_nMatch = nullptr
 Matchings at each level. More...
 
bool ** m_bUsed = nullptr
 Whether comparators are used when sorting. More...
 
UINT m_nInputs = 0
 Number of inputs. More...
 
UINT m_nDepth = 0
 Depth. More...
 
UINT m_nSize = 0
 Size. More...
 
bool m_bSorts = false
 True if it sorts, false if it doesn't or unknown. More...
 

Detailed Description

A comparator network that can be rendered to a Gdiplus::Bitmap or exported in one of several graphics file formats. Uses GDI+, obviously.

Definition at line 37 of file RenderableComparatorNet.h.

Constructor & Destructor Documentation

◆ ~CRenderableComparatorNet()

CRenderableComparatorNet::~CRenderableComparatorNet ( )

< Delete the bitmap.

Definition at line 33 of file RenderableComparatorNet.cpp.

Member Function Documentation

◆ ComputeBitmapHeight()

Gdiplus::REAL CRenderableComparatorNet::ComputeBitmapHeight ( )
protected

Compute the bitmap height when drawn in vertical draw mode. Note that this does not actually draw the comparator network to a bitmap, but it goes through the motions and tallies up the height that would be used.

Returns
Bitmap height in pixels.

Definition at line 42 of file RenderableComparatorNet.cpp.

◆ Draw()

void CRenderableComparatorNet::Draw ( const eDrawStyle  d)

Draw the comparator network in black with a transparent background to a new Gdiplus::Bitmap of the right size. The comparator network is drawn either vertically or horzontally depending on the draw mode m_eDrawStyle. The calling function is responsible for deleting the bitmap when it is no longer needed. Note that m_eExportType is set to eExport::Png so that the calls to DrawComparators() and DrawChannels()draw to the bitmap pointed to bym_pBitmap`.

Parameters
dDraw style.

Definition at line 297 of file RenderableComparatorNet.cpp.

◆ DrawChannels()

void CRenderableComparatorNet::DrawChannels ( const float  fLen)
protected

Draw channels. The behaviour of this function depends on the value of m_eExportType. If it is m_eExportType::Png, then we draw the channels to the bitmap pointed to by m_pBitmap via the graphics object pointed to by m_pGraphics. Otherwise we output the vector graphics commands to draw the channels (a line for each channel) to the file pointed to by m_pOutput.

Parameters
fLenLength of channels in pixels.

Definition at line 234 of file RenderableComparatorNet.cpp.

◆ DrawComparator()

void CRenderableComparatorNet::DrawComparator ( const UINT  src,
const UINT  dest,
const float  fDist,
bool  bRed = false 
)
protected

Draw a comparator. The behaviour of this function depends on the value of m_eExportType. If it is m_eExportType::Png, then we draw the comparator to the bitmap pointed to by m_pBitmap via the graphics object pointed to by m_pGraphics. Otherwise we output the vector graphics commands to draw the comparator (a line and two filled circles) to the file pointed to by m_pOutput.

Parameters
srcSource (min) channel.
destDestination (max) channel.
fDistDistance along channel to comparator in pixels.
bRedTrue if comparator is to be drawn red (PNG only).

Definition at line 85 of file RenderableComparatorNet.cpp.

◆ DrawComparators()

void CRenderableComparatorNet::DrawComparators ( )
protected

Draw all comparators. Calls DrawComparator() once for each comparator. The behaviour of this function depends on the value of m_eExportType. If it is m_eExportType::Png, then we draw the comparators to the bitmap pointed to by m_pBitmap via the graphics object pointed to by m_pGraphics. Otherwise we output the vector graphics commands to draw the comparators (lines and filled circles) to the file pointed to by m_pOutput.

Definition at line 176 of file RenderableComparatorNet.cpp.

◆ ExportToPNG()

HRESULT CRenderableComparatorNet::ExportToPNG ( LPWSTR  lpwstr)

Export to an PNG file. This simply involves using GDI+ to save the bitmap pointed to by m_pBitmap to a file.

Parameters
lpwstrNull terminated wide file name.
Returns
S_OK if export succeeded, otherwise E_FAIL.

Definition at line 334 of file RenderableComparatorNet.cpp.

◆ ExportToSVG()

HRESULT CRenderableComparatorNet::ExportToSVG ( LPWSTR  lpwstr)

Export to an SVG file. Note that m_eExportType is set to eExport::Svg so that the calls to DrawComparators() and DrawChannels()` output the necessary vector graphics commands in SVG format to the file pointed to by m_pOutput.

Parameters
lpwstrNull terminated wide file name.
Returns
S_OK if export succeeded, otherwise E_FAIL.

Definition at line 403 of file RenderableComparatorNet.cpp.

◆ ExportToTex()

HRESULT CRenderableComparatorNet::ExportToTex ( LPWSTR  lpwstr)

Export to a TeX file. Note that m_eExportType is set to eExport::TeX so that the calls to DrawComparators() and DrawChannels()` output the necessary vector graphics commands in TeX format to the file pointed to by m_pOutput.

Parameters
lpwstrNull terminated wide file name.
Returns
S_OK if export succeeded, otherwise E_FAIL.

Definition at line 354 of file RenderableComparatorNet.cpp.

◆ GetBitmap()

Gdiplus::Bitmap * CRenderableComparatorNet::GetBitmap ( )

Reader function for bitmap pointer.

Returns
Pointer to bitmap.

Definition at line 460 of file RenderableComparatorNet.cpp.

Member Data Documentation

◆ m_eDrawStyle

eDrawStyle CRenderableComparatorNet::m_eDrawStyle = eDrawStyle::Horizontal
protected

Definition at line 47 of file RenderableComparatorNet.h.

◆ m_eExportType

eExport CRenderableComparatorNet::m_eExportType = eExport::Png
protected

Definition at line 56 of file RenderableComparatorNet.h.

◆ m_fDiameter

const Gdiplus::REAL CRenderableComparatorNet::m_fDiameter = 8.0f
protected

Definition at line 43 of file RenderableComparatorNet.h.

◆ m_fPenWidth

const Gdiplus::REAL CRenderableComparatorNet::m_fPenWidth = 2.0f
protected

Definition at line 39 of file RenderableComparatorNet.h.

◆ m_fXDelta

const Gdiplus::REAL CRenderableComparatorNet::m_fXDelta = 24.0f
protected

Definition at line 40 of file RenderableComparatorNet.h.

◆ m_fYDelta

const Gdiplus::REAL CRenderableComparatorNet::m_fYDelta = 16.0f
protected

Definition at line 41 of file RenderableComparatorNet.h.

◆ m_fYDelta2

const Gdiplus::REAL CRenderableComparatorNet::m_fYDelta2 = 8.0f
protected

Definition at line 42 of file RenderableComparatorNet.h.

◆ m_pBitmap

Gdiplus::Bitmap* CRenderableComparatorNet::m_pBitmap = nullptr
protected

Definition at line 45 of file RenderableComparatorNet.h.

◆ m_pBrush

Gdiplus::SolidBrush* CRenderableComparatorNet::m_pBrush = nullptr
protected

Definition at line 52 of file RenderableComparatorNet.h.

◆ m_pGraphics

Gdiplus::Graphics* CRenderableComparatorNet::m_pGraphics = nullptr
protected

Definition at line 49 of file RenderableComparatorNet.h.

◆ m_pOutput

FILE* CRenderableComparatorNet::m_pOutput = nullptr
protected

Definition at line 55 of file RenderableComparatorNet.h.

◆ m_pPen

Gdiplus::Pen* CRenderableComparatorNet::m_pPen = nullptr
protected

Definition at line 50 of file RenderableComparatorNet.h.

◆ m_pRedBrush

Gdiplus::SolidBrush* CRenderableComparatorNet::m_pRedBrush = nullptr
protected

Definition at line 53 of file RenderableComparatorNet.h.

◆ m_pRedPen

Gdiplus::Pen* CRenderableComparatorNet::m_pRedPen = nullptr
protected

Definition at line 51 of file RenderableComparatorNet.h.