tomwalters@116: // Copyright 2006, Willem van Engen tomwalters@116: // tomwalters@116: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@116: // http://www.acousticscale.org/AIMC tomwalters@116: // tomwalters@116: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@116: // you may not use this file except in compliance with the License. tomwalters@116: // You may obtain a copy of the License at tomwalters@116: // tomwalters@116: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@116: // tomwalters@116: // Unless required by applicable law or agreed to in writing, software tomwalters@116: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@116: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@116: // See the License for the specific language governing permissions and tomwalters@116: // limitations under the License. tomwalters@116: tomwalters@116: /*! tomwalters@116: * \file tomwalters@116: * \brief Output device for output to a graphics file using plotutils tomwalters@116: * tomwalters@116: * \author Willem van Engen tomwalters@116: * \date created 2006/10/13 tomwalters@116: * \version \$Id: $ tomwalters@116: */ tomwalters@116: tomwalters@116: #ifndef __GRAPHICS_OUTPUT_DEVICE_PLOTUTILS_H__ tomwalters@116: #define __GRAPHICS_OUTPUT_DEVICE_PLOTUTILS_H__ tomwalters@116: tomwalters@116: #include tomwalters@116: #include tomwalters@116: tomwalters@116: #include tomwalters@116: tomwalters@116: #include "Support/util.h" tomwalters@116: #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h" tomwalters@116: tomwalters@116: /*! tomwalters@116: * \class GraphicsOutputDevicePlotutils "Output/GraphicsOutputDevicePlotutils.h" tomwalters@116: * \brief Output class for output to a graphics file using plotutils tomwalters@116: * tomwalters@116: * This class outputs a graphics operation to file. It only supports 2d though, tomwalters@116: * so the z-component is ignored. tomwalters@116: */ tomwalters@116: class GraphicsOutputDevicePlotutils : public GraphicsOutputDevice { tomwalters@116: public: tomwalters@116: GraphicsOutputDevicePlotutils(Parameters *pParam); tomwalters@116: virtual ~GraphicsOutputDevicePlotutils(); tomwalters@116: tomwalters@228: /*! \brief Initializes this output device, prepares plotting tools. tomwalters@228: * \param sDir Directory or filename where to put images, max length tomwalters@116: * is _MAX_PATH. Must end with slash!!! tomwalters@228: * \return true on success, false on failure. tomwalters@228: * tomwalters@228: * sDir can be either a filename, in which case the output will be tomwalters@228: * to that file, or a directory, in which case it will be filled tomwalters@228: * with 6-digit numbered files. A new file is then created at every tomwalters@228: * call to gGrab(). tomwalters@228: * tomwalters@228: * As usual, make sure to call this function before any other. If this tomwalters@228: * Initialize() failed, you shouldn't try the other functions either. tomwalters@228: */ tomwalters@228: bool Initialize(const char *sDir); tomwalters@228: bool Initialize(); tomwalters@116: tomwalters@116: void gGrab(); tomwalters@116: void gBeginLineStrip(); tomwalters@116: void gBeginQuadStrip(); tomwalters@228: using GraphicsOutputDevice::gVertex3f; // Because we overload it tomwalters@228: void gVertex3f(float x, float y, float z); tomwalters@228: void gColor3f(float r, float g, float b); tomwalters@116: void gEnd(); tomwalters@228: void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false); tomwalters@228: void gRelease(); tomwalters@228: char* GetBuffer(); tomwalters@116: protected: tomwalters@228: /*! \brief Open the file with given index for output tomwalters@228: * \param index File number to open tomwalters@228: * \return true on success, false on error tomwalters@228: * tomwalters@228: * This opens a file for output and sets up the plotting library. tomwalters@228: */ tomwalters@228: bool OpenFile(unsigned int index); tomwalters@116: tomwalters@228: //! \brief Closes a plot output file, if any is open. tomwalters@228: void CloseFile(); tomwalters@116: tomwalters@228: //! \brief Internal initialisation function called by overloaded variants of Initialize() tomwalters@228: void Init(); tomwalters@116: tomwalters@228: //! \brief The current output file's handle tomwalters@228: FILE *m_pOutputFile; tomwalters@228: //! \brief The plotutils plotter tomwalters@228: int m_iPlotHandle; tomwalters@228: //! \brief Output directory tomwalters@228: char m_sDir[PATH_MAX]; tomwalters@228: //! \brief Current file number tomwalters@228: unsigned int m_iFileNumber; tomwalters@228: //! \brief true if this is the first vertex after gBegin() tomwalters@228: bool m_bIsFirstVertex; tomwalters@116: tomwalters@228: enum VertexType { tomwalters@228: VertexTypeNone, tomwalters@116: VertexTypeLine, tomwalters@116: VertexTypeQuad tomwalters@228: }; tomwalters@228: //! \brief The current vertex type tomwalters@228: VertexType m_iVertexType; tomwalters@228: //! \brief Begin vertex of current quad tomwalters@228: float m_aPrevX[3], m_aPrevY[3]; tomwalters@228: //! \brief Current number of quad vertices stored tomwalters@228: unsigned int m_iPrevVertexCount; tomwalters@116: tomwalters@228: //! \brief Whether to invert the colors or not tomwalters@228: bool m_bInvertColors; tomwalters@116: tomwalters@228: //! \brief The size of the memory bitmap buffer as provided by open_memstream tomwalters@228: size_t m_sMemoryBufferSize; tomwalters@116: tomwalters@228: //! \brief Are we using a memory buffer for writing to (as opposed to a file)? tomwalters@228: bool m_bUseMemoryBuffer; tomwalters@116: tomwalters@228: //! \brief Pointer to the memory buffer in question tomwalters@228: char *m_pMemoryBuffer; tomwalters@116: tomwalters@228: //! \brief Width of the bitmap tomwalters@228: unsigned int m_uWidth; tomwalters@116: tomwalters@228: //! \brief Height of the bitmap tomwalters@228: unsigned int m_uHeight; tomwalters@116: }; tomwalters@116: tomwalters@116: #endif /* __GRAPHICS_OUTPUT_DEVICE_PLOTUTILS_H__ */