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