Mercurial > hg > aimc
diff src/Modules/Output/Graphics/Devices/GraphicsOutputDevicePlotutils.cc @ 117:c5ac2f0c7fc5
- All \t to two spaces (style guide compliance)
author | tomwalters |
---|---|
date | Fri, 15 Oct 2010 05:46:53 +0000 |
parents | 47b009f2c936 |
children | 73c6d61440ad |
line wrap: on
line diff
--- a/src/Modules/Output/Graphics/Devices/GraphicsOutputDevicePlotutils.cc Fri Oct 15 05:40:53 2010 +0000 +++ b/src/Modules/Output/Graphics/Devices/GraphicsOutputDevicePlotutils.cc Fri Oct 15 05:46:53 2010 +0000 @@ -36,53 +36,53 @@ GraphicsOutputDevicePlotutils::GraphicsOutputDevicePlotutils(Parameters *pParam) : GraphicsOutputDevice(pParam) { - m_iPlotHandle = 0; - m_pOutputFile = NULL; - m_iFileNumber = 0; - m_iVertexType = VertexTypeNone; - m_bUseMemoryBuffer = false; - m_pMemoryBuffer = NULL; - m_uWidth=0; - m_uHeight=0; + m_iPlotHandle = 0; + m_pOutputFile = NULL; + m_iFileNumber = 0; + m_iVertexType = VertexTypeNone; + m_bUseMemoryBuffer = false; + m_pMemoryBuffer = NULL; + m_uWidth=0; + m_uHeight=0; } bool GraphicsOutputDevicePlotutils::Initialize(const char *sDir) { Init(); - //! \todo Output to file if sDir is a file, to directory with multiple + //! \todo Output to file if sDir is a file, to directory with multiple //! images if it's a directory. - strncpy(m_sDir, sDir, sizeof(m_sDir)/sizeof(m_sDir[0])); + strncpy(m_sDir, sDir, sizeof(m_sDir)/sizeof(m_sDir[0])); - /* Try to open an image to see if everything is allright. We want to avoid - * errors in the main Process()ing loop. */ - if (!OpenFile(0)) { - //! \todo Better error message that is more specific about the cause. - AIM_ERROR(_T("Could not open output directory '%s' using graphics format '%s'."), - m_sDir, m_pParam->GetString("output.img.format") ); - return false; - } - CloseFile(); - return true; + /* Try to open an image to see if everything is allright. We want to avoid + * errors in the main Process()ing loop. */ + if (!OpenFile(0)) { + //! \todo Better error message that is more specific about the cause. + AIM_ERROR(_T("Could not open output directory '%s' using graphics format '%s'."), + m_sDir, m_pParam->GetString("output.img.format") ); + return false; + } + CloseFile(); + return true; } void GraphicsOutputDevicePlotutils::Init() { AIM_ASSERT(m_pParam); - /* - * Set parameters - */ - pl_parampl("BG_COLOR", (void*)m_pParam->GetString("output.img.color.background")); - // Handle GIFs as other output formats, don't merge frames into single GIF. - pl_parampl("GIF_ANIMATION", (void*)"no"); - pl_parampl("INTERLACE", (void*)"no"); + /* + * Set parameters + */ + pl_parampl("BG_COLOR", (void*)m_pParam->GetString("output.img.color.background")); + // Handle GIFs as other output formats, don't merge frames into single GIF. + pl_parampl("GIF_ANIMATION", (void*)"no"); + pl_parampl("INTERLACE", (void*)"no"); - m_bInvertColors = m_pParam->GetBool("output.img.color.invert"); + m_bInvertColors = m_pParam->GetBool("output.img.color.invert"); - // Output size! - m_uWidth = m_pParam->GetUInt("output.img.width"); - m_uHeight = m_pParam->GetUInt("output.img.height"); - char strSize[100]; - snprintf(strSize, sizeof(strSize)/sizeof(strSize[0]), "%ux%u", m_uWidth, m_uHeight); - pl_parampl("BITMAPSIZE", (void*)strSize); + // Output size! + m_uWidth = m_pParam->GetUInt("output.img.width"); + m_uHeight = m_pParam->GetUInt("output.img.height"); + char strSize[100]; + snprintf(strSize, sizeof(strSize)/sizeof(strSize[0]), "%ux%u", m_uWidth, m_uHeight); + pl_parampl("BITMAPSIZE", (void*)strSize); } bool GraphicsOutputDevicePlotutils::Initialize() { @@ -136,30 +136,30 @@ strPlottype="pnm"; // Force pnm format or this doesn't work } - /* - * Create a plotter - * - * Plotutils knows the following types for file output: - * pnm gif ai ps gif pcl hpgl tek meta - */ - if ((m_iPlotHandle = pl_newpl(strPlottype, + /* + * Create a plotter + * + * Plotutils knows the following types for file output: + * pnm gif ai ps gif pcl hpgl tek meta + */ + if ((m_iPlotHandle = pl_newpl(strPlottype, NULL, m_pOutputFile, stderr)) < 0 ) { - return false; - } - pl_selectpl(m_iPlotHandle); + return false; + } + pl_selectpl(m_iPlotHandle); - if ( pl_openpl() < 0) { - return false; - } + if ( pl_openpl() < 0) { + return false; + } - // Now setup things for this plotter - pl_fontname(m_pParam->GetString("output.img.fontname")); - //! \todo Make fontsize work in Plotutils, currently disabled - //pl_ffontsize(m_pParam->GetUInt("output.fontsize")); + // Now setup things for this plotter + pl_fontname(m_pParam->GetString("output.img.fontname")); + //! \todo Make fontsize work in Plotutils, currently disabled + //pl_ffontsize(m_pParam->GetUInt("output.fontsize")); - return true; + return true; } char* GraphicsOutputDevicePlotutils::GetBuffer() { @@ -170,27 +170,27 @@ } void GraphicsOutputDevicePlotutils::CloseFile() { - // Plotting library - if (m_iPlotHandle>0) { - pl_closepl(); + // Plotting library + if (m_iPlotHandle>0) { + pl_closepl(); - pl_selectpl(0); - pl_deletepl(m_iPlotHandle); - m_iPlotHandle = 0; - } + pl_selectpl(0); + pl_deletepl(m_iPlotHandle); + m_iPlotHandle = 0; + } - // And the output file - if (m_pOutputFile) { - fclose(m_pOutputFile); - m_pOutputFile = NULL; - } + // And the output file + if (m_pOutputFile) { + fclose(m_pOutputFile); + m_pOutputFile = NULL; + } } GraphicsOutputDevicePlotutils::~GraphicsOutputDevicePlotutils() { - // Output file should be closed by gRelease() - AIM_ASSERT(!m_pOutputFile); - AIM_ASSERT(!m_iPlotHandle); - CloseFile(); + // Output file should be closed by gRelease() + AIM_ASSERT(!m_pOutputFile); + AIM_ASSERT(!m_iPlotHandle); + CloseFile(); } PixelFormat GraphicsOutputDevicePlotutils::GetPixelFormat() { @@ -198,91 +198,91 @@ } void GraphicsOutputDevicePlotutils::gGrab() { - // Open file - if (!OpenFile(m_iFileNumber)) { - return; + // Open file + if (!OpenFile(m_iFileNumber)) { + return; } - // Setup plotting area - pl_fspace(0.0, 0.0, 1.0, 1.0); - pl_flinewidth(0.0001); - pl_pencolorname("darkblue"); - pl_erase(); + // Setup plotting area + pl_fspace(0.0, 0.0, 1.0, 1.0); + pl_flinewidth(0.0001); + pl_pencolorname("darkblue"); + pl_erase(); } void GraphicsOutputDevicePlotutils::gBeginLineStrip() { - m_bIsFirstVertex = true; - m_iVertexType = VertexTypeLine; - pl_filltype(0); + m_bIsFirstVertex = true; + m_iVertexType = VertexTypeLine; + pl_filltype(0); } void GraphicsOutputDevicePlotutils::gBeginQuadStrip() { - m_bIsFirstVertex = true; - m_iVertexType = VertexTypeQuad; - m_iPrevVertexCount = 0; - pl_filltype(1); + m_bIsFirstVertex = true; + m_iVertexType = VertexTypeQuad; + m_iPrevVertexCount = 0; + pl_filltype(1); } void GraphicsOutputDevicePlotutils::gColor3f(float r, float g, float b) { - if (m_bInvertColors) { - r = 1-r; - g = 1-g; - b = 1-b; - } - int ir = (int)(r*0xffff); - int ig = (int)(g*0xffff); - int ib = (int)(b*0xffff); - ir = MIN(0xffff, MAX(0,ir)); - ig = MIN(0xffff, MAX(0,ig)); - ib = MIN(0xffff, MAX(0,ib)); - pl_color(ir, ig, ib); + if (m_bInvertColors) { + r = 1-r; + g = 1-g; + b = 1-b; + } + int ir = (int)(r*0xffff); + int ig = (int)(g*0xffff); + int ib = (int)(b*0xffff); + ir = MIN(0xffff, MAX(0,ir)); + ig = MIN(0xffff, MAX(0,ig)); + ib = MIN(0xffff, MAX(0,ib)); + pl_color(ir, ig, ib); } void GraphicsOutputDevicePlotutils::gVertex3f(float x, float y, float z) { - switch(m_iVertexType) { - case VertexTypeLine: - if (m_bIsFirstVertex) { - m_bIsFirstVertex = false; - pl_fmove(x, y); - } else { - pl_fcont(x, y); - } - break; - case VertexTypeQuad: - /* Store vertices until we got four in a row. - * The order of vertices when processing quads is: - * 1-----3-----5 - * | | | - * 0-----2-----4 - */ - if (m_iPrevVertexCount>=3) { - // Plot this quad - pl_fmove(m_aPrevX[0],m_aPrevY[0]); - pl_fcont(m_aPrevX[1],m_aPrevY[1]); - pl_fcont(x,y); - pl_fcont(m_aPrevX[2],m_aPrevY[2]); - pl_endpath(); - // Last vertices of this quad are the first of the next - m_aPrevX[0] = m_aPrevX[2]; - m_aPrevY[0] = m_aPrevY[2]; - m_aPrevX[1] = x; - m_aPrevY[1] = y; - m_iPrevVertexCount = 2; - } else { - // Not at the fourth, keep storing - m_aPrevX[m_iPrevVertexCount] = x; - m_aPrevY[m_iPrevVertexCount] = y; - m_iPrevVertexCount++; - } - break; - default: - // Should not happen - AIM_ASSERT(0); - } + switch(m_iVertexType) { + case VertexTypeLine: + if (m_bIsFirstVertex) { + m_bIsFirstVertex = false; + pl_fmove(x, y); + } else { + pl_fcont(x, y); + } + break; + case VertexTypeQuad: + /* Store vertices until we got four in a row. + * The order of vertices when processing quads is: + * 1-----3-----5 + * | | | + * 0-----2-----4 + */ + if (m_iPrevVertexCount>=3) { + // Plot this quad + pl_fmove(m_aPrevX[0],m_aPrevY[0]); + pl_fcont(m_aPrevX[1],m_aPrevY[1]); + pl_fcont(x,y); + pl_fcont(m_aPrevX[2],m_aPrevY[2]); + pl_endpath(); + // Last vertices of this quad are the first of the next + m_aPrevX[0] = m_aPrevX[2]; + m_aPrevY[0] = m_aPrevY[2]; + m_aPrevX[1] = x; + m_aPrevY[1] = y; + m_iPrevVertexCount = 2; + } else { + // Not at the fourth, keep storing + m_aPrevX[m_iPrevVertexCount] = x; + m_aPrevY[m_iPrevVertexCount] = y; + m_iPrevVertexCount++; + } + break; + default: + // Should not happen + AIM_ASSERT(0); + } } void GraphicsOutputDevicePlotutils::gEnd() { - pl_endpath(); - m_iVertexType = VertexTypeNone; + pl_endpath(); + m_iVertexType = VertexTypeNone; } void GraphicsOutputDevicePlotutils::gText3f(float x, @@ -290,20 +290,20 @@ float z, const char *sStr, bool bRotated) { - if (bRotated) { - pl_textangle(90); - pl_fmove(x, y); - pl_alabel('l', 't', sStr); - } else { - pl_textangle(0); - pl_fmove(x, y); - pl_alabel('l', 'b', sStr); - } + if (bRotated) { + pl_textangle(90); + pl_fmove(x, y); + pl_alabel('l', 't', sStr); + } else { + pl_textangle(0); + pl_fmove(x, y); + pl_alabel('l', 'b', sStr); + } } void GraphicsOutputDevicePlotutils::gRelease() { - AIM_ASSERT(m_pOutputFile); - AIM_ASSERT(m_iPlotHandle>0); - CloseFile(); - m_iFileNumber++; + AIM_ASSERT(m_pOutputFile); + AIM_ASSERT(m_iPlotHandle>0); + CloseFile(); + m_iFileNumber++; }