annotate src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.h @ 611:0fbaf443ec82

Carfac C++ revision 3, indluding more style improvements. The output structs are now classes again, and have separate storage methods for each output structure along with flags in the Run and RunSegment methods to allow for only storing NAPs if desired.
author alexbrandmeyer
date Fri, 17 May 2013 19:52:45 +0000
parents e35740ed81f3
children
rev   line source
tomwalters@116 1 // Copyright 2007, Thomas Walters
tomwalters@116 2 //
tomwalters@116 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@116 4 // http://www.acousticscale.org/AIMC
tomwalters@116 5 //
tomwalters@116 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@116 7 // you may not use this file except in compliance with the License.
tomwalters@116 8 // You may obtain a copy of the License at
tomwalters@116 9 //
tomwalters@116 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@116 11 //
tomwalters@116 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@116 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@116 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@116 15 // See the License for the specific language governing permissions and
tomwalters@116 16 // limitations under the License.
tomwalters@116 17
tomwalters@116 18 /*!
tomwalters@116 19 * \file
tomwalters@116 20 * \brief Output device for output to a graphics file using cairo
tomwalters@116 21 *
tomwalters@116 22 * \author Tom Walters <tom@acousticscale.org> and Willem van Engen <cnbh@willem.engen.nl>
tomwalters@116 23 * \date created 2007/09/17
tomwalters@116 24 * \version \$Header: $
tomwalters@116 25 */
tomwalters@116 26
tomwalters@116 27 #ifndef __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__
tomwalters@116 28 #define __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__
tomwalters@116 29
tom@230 30 #include <string>
tom@230 31
tomwalters@116 32 #include <stdlib.h>
tomwalters@116 33 #include <stdio.h>
tomwalters@116 34
tomwalters@116 35 #include "cairo.h"
tomwalters@116 36
tomwalters@116 37 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h"
tomwalters@116 38
tom@229 39 namespace aimc {
tom@230 40 using std::string;
tomwalters@116 41 /*!
tomwalters@116 42 * \class GraphicsOutputDeviceCairo "Output/GraphicsOutputDeviceCairo.h"
tomwalters@116 43 * \brief Output class for output to a graphics file using Cairo
tomwalters@116 44 *
tomwalters@116 45 * This class outputs a graphics operation to file. It only supports 2d though,
tomwalters@116 46 * so the z-component is ignored.
tomwalters@116 47 */
tom@229 48 class GraphicsOutputDeviceCairo : public GraphicsOutputDevice {
tomwalters@116 49 public:
tomwalters@237 50 GraphicsOutputDeviceCairo(Parameters *parameters);
tomwalters@116 51 virtual ~GraphicsOutputDeviceCairo();
tomwalters@116 52
tomwalters@228 53 /*! \brief Initializes this output device, prepares plotting tools.
tomwalters@228 54 * \param sDir Directory or filename where to put images, max length is
tomwalters@237 55 * _MAX_PATH. Must end with slash.
tomwalters@228 56 * \return true on success, false on failure.
tomwalters@228 57 *
tomwalters@228 58 * sDir can be either a filename, in which case the output will be
tomwalters@228 59 * to that file, or a directory, in which case it will be filled
tomwalters@228 60 * with 6-digit numbered files. A new file is then created at every
tomwalters@228 61 * call to gGrab().
tomwalters@228 62 *
tomwalters@228 63 * As usual, make sure to call this function before any other. If this
tomwalters@228 64 * Initialize() failed, you shouldn't try the other functions either.
tomwalters@228 65 */
tomwalters@237 66 bool Initialize(string directory);
tomwalters@256 67 virtual bool Initialize(Parameters *global_parameters);
tomwalters@256 68
tomwalters@116 69 void gGrab();
tomwalters@116 70 void gBeginLineStrip();
tomwalters@116 71 void gBeginQuadStrip();
tomwalters@228 72 using GraphicsOutputDevice::gVertex3f; // Because we overload it
tomwalters@228 73 void gVertex3f(float x, float y, float z);
tomwalters@228 74 void gColor3f(float r, float g, float b);
tomwalters@116 75 void gEnd();
tomwalters@228 76 void gText3f(float x, float y, float z, const char *sStr, bool bRotated = false);
tomwalters@228 77 void gRelease();
tomwalters@228 78 unsigned char* GetBuffer();
tomwalters@228 79 int GetPixelFormat();
tomwalters@256 80 virtual void Reset(Parameters* global_parameters);
tomwalters@116 81 protected:
tomwalters@116 82 /*! \brief Internal initialisation
tomwalters@116 83 *
tomwalters@116 84 */
tomwalters@256 85 void InitialzeInternal();
tomwalters@116 86
tomwalters@228 87 /*! \brief Open the file with given index for output
tomwalters@228 88 * \param index File number to open
tomwalters@228 89 * \return true on success, false on error
tomwalters@228 90 *
tomwalters@228 91 * This opens a file for output and sets up the plotting library.
tomwalters@228 92 */
tomwalters@228 93 bool OpenFile(unsigned int index);
tomwalters@116 94
tomwalters@228 95 //! \brief Closes a plot output file, if any is open.
tomwalters@228 96 void CloseFile();
tomwalters@116 97
tomwalters@228 98 //! \brief Set to true if the input file can be written to
tomwalters@228 99 bool m_bOutputFile;
tomwalters@228 100 //! \brief Output directory
tomwalters@237 101 string directory_;
tomwalters@228 102 //! \brief Current file number
tomwalters@228 103 unsigned int m_iFileNumber;
tomwalters@228 104 //! \brief true if this is the first vertex after gBegin()
tomwalters@228 105 bool m_bIsFirstVertex;
tomwalters@116 106
tomwalters@228 107 enum VertexType {
tomwalters@228 108 VertexTypeNone,
tomwalters@116 109 VertexTypeLine,
tomwalters@116 110 VertexTypeQuad
tomwalters@228 111 };
tomwalters@228 112 //! \brief The current vertex type
tomwalters@228 113 VertexType m_iVertexType;
tomwalters@228 114 //! \brief Begin vertex of current quad
tomwalters@228 115 float m_aPrevX[3], m_aPrevY[3];
tomwalters@228 116 //! \brief Current number of quad vertices stored
tomwalters@228 117 unsigned int m_iPrevVertexCount;
tomwalters@116 118
tomwalters@228 119 //! \brief Whether to invert the colors or not
tomwalters@228 120 bool m_bInvertColors;
tomwalters@116 121
tomwalters@116 122 //! \brief Cairo Drawing Surface
tomwalters@116 123 cairo_surface_t *m_cSurface;
tomwalters@116 124
tomwalters@116 125 //! \brief Cairo Context
tomwalters@228 126 cairo_t *m_cCr;
tomwalters@116 127
tomwalters@116 128 //! \brief Internal store for the input filename
tomwalters@237 129 string image_filename_;
tomwalters@116 130
tomwalters@228 131 unsigned int m_iWidth;
tomwalters@228 132 unsigned int m_iHeight;
tomwalters@228 133 bool m_bUseMemoryBuffer;
tomwalters@116 134 };
tom@229 135 } // namespace aimc
tomwalters@116 136 #endif /* __GRAPHICS_OUTPUT_DEVICE_CAIRO_H__ */