File: mutatable_image.h

package info (click to toggle)
evolvotron 0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,420 kB
  • ctags: 1,367
  • sloc: cpp: 10,462; python: 162; sh: 147; makefile: 9
file content (147 lines) | stat: -rw-r--r-- 5,331 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**************************************************************************/
/*  Copyright 2012 Tim Day                                                */
/*                                                                        */
/*  This file is part of Evolvotron                                       */
/*                                                                        */
/*  Evolvotron is free software: you can redistribute it and/or modify    */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation, either version 3 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/*  Evolvotron is distributed in the hope that it will be useful,         */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
/*  GNU General Public License for more details.                          */
/*                                                                        */
/*  You should have received a copy of the GNU General Public License     */
/*  along with Evolvotron.  If not, see <http://www.gnu.org/licenses/>.   */
/**************************************************************************/

/*! \file 
  \brief Interfaces for class MutatableImage.
*/

#ifndef _mutatable_image_h_
#define _mutatable_image_h_

class FunctionNull;
class FunctionTop;

//! Class to hold the base FunctionNode of an image.
/*! Once it owns a root FunctionNode* the whole structure should be fixed (mutate isn't available, only mutated).
  \todo Do reference counting on this object ?  Maybe not: have to worry about stateful nodes,
  \todo Generally tighten up const-ness of interfaces.
 */
class MutatableImage
#ifndef NDEBUG
: public InstanceCounted
#endif
{
 protected:

  //! The top level FunctionNode of the image.
  /*! This is partly here because FunctionNode::mutate can't change the type of
    the node it is invoked on (only child nodes can be zapped), partly so we
    can keep colour and space transforms under control.
   */
  std::auto_ptr<FunctionTop> _top;

  //! Whether to sweep z sinusoidally (vs linearly)
  bool _sinusoidal_z;

  //! Whether xyz should be interpreted as long/lat/radius
  bool _spheremap;

  //! Whether this image is locked \todo Should be a property of display, not image.
  bool _locked;

  //! Serial number for identity tracking (used by display to discover whether a recompute is needed)
  unsigned long long _serial;

  //! Object count to generate serial numbers
  static unsigned long long _count;

 public:
  
  //! Take ownership of the image tree with the specified root node.
  MutatableImage(std::auto_ptr<FunctionTop>&,bool sinz,bool sm,bool lock);
  
  //! Create a new random image tree.
  MutatableImage(const MutationParameters& parameters,bool exciting,bool sinz,bool sm);
  
  //! Destructor.  NB Deletes owned image function tree.
  virtual ~MutatableImage();

  //! Returns the sampling co-ordinate given a (sub)pixel position in the given frame of an animation.
  /*! This depends on things like sinusoidal_z and spheremap
   */
  const XYZ sampling_coordinate(real x,real y,uint z,uint sx,uint sy,uint sz) const;

  //! Accessor.
  const FunctionTop& top() const;

  //! Accessor.
  bool sinusoidal_z() const
    {
      return _sinusoidal_z;
    }

  //! Accessor.
  bool spheremap() const
    {
      return _spheremap;
    }

  //! Accessor.
  bool locked() const
    {
      return _locked;
    }

  //! Accessor.
  void locked(bool l)
    {
      _locked=l;
    }

  //! Accessor.
  unsigned long long serial() const
    {
      return _serial;
    }

  //! Clone this image.  The cloned image will not have locked state.
  boost::shared_ptr<const MutatableImage> deepclone() const;

  //! Clone this image, setting locked state to that specified.
  boost::shared_ptr<const MutatableImage> deepclone(bool lock) const;

  //! Return a mutated version of this image
  boost::shared_ptr<const MutatableImage> mutated(const MutationParameters& p) const;

  //! Return a simplified version of this image
  boost::shared_ptr<const MutatableImage> simplified() const;

  //! Return the a 0-255-scaled RGB value at the specified location.
  const XYZ get_rgb(const XYZ& p) const;

  //! Return the a 0-255-scaled RGB value at the specified pixel of an image/animation taking jitter (if random number generator provided) and multisampling into account
  const XYZ get_rgb(uint x,uint y,uint f,uint width,uint height,uint frames,Random01* r01,uint multisample) const;

  //! Return whether image value is independent of position.
  bool is_constant() const;

  //! Save the function-tree to the stream
  std::ostream& save_function(std::ostream& out) const;

  //! Read a new function tree from the given stream.
  static boost::shared_ptr<const MutatableImage> load_function(const FunctionRegistry& function_registry,std::istream& in,std::string& report);

  //! Obtain some statistics about the image function
  void get_stats(uint& total_nodes,uint& total_parameters,uint& depth,uint& width,real& proportion_constant) const;

  //! Check the function tree is ok.
  bool ok() const;
};

#endif