summaryrefslogtreecommitdiff
path: root/hw6/include/reflectanceParameter.h
blob: c9246537deed38f134bc1b4479e6ad1ef9bfb316 (plain) (blame)
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
/******************************************************************/
/* This file is part of the homework assignments for CSCI-427/527 */
/* at The College of William & Mary and authored by Pieter Peers. */
/* No part of this file, whether altered or in original form, can */
/* be distributed or used outside the context of CSCI-427/527     */
/* without consent of either the College of William & Mary or     */
/* Pieter Peers.                                                  */
/******************************************************************/
#ifndef _REFLECTANCEPARAMETER_H_
#define _REFLECTANCEPARAMETER_H_

#include <memory>
#include <ostream>

#include "vec2d.h"
#include "vec3d.h"
#include "color.h"
#include "texture_base.h"

class scalarReflectanceParameter {
 public:
  /////////////////
  // Constructor //
  /////////////////
  scalarReflectanceParameter(float value=0.0f);
  scalarReflectanceParameter(const std::shared_ptr<const texture_base>& texture, unsigned int channel=0);
  scalarReflectanceParameter(const scalarReflectanceParameter& src);

  //////////////
  // Operator //
  //////////////
  scalarReflectanceParameter& operator=(const scalarReflectanceParameter& src);

  float operator()(const vec2d& textureCoord) const;

  /////////////
  // Friends //
  /////////////
  friend void swap(scalarReflectanceParameter& a, scalarReflectanceParameter& b) { a._swap(b); }

  friend std::ostream& operator<<(std::ostream& s, const scalarReflectanceParameter& param)
  {
    if(param._texture) s << param._texture << "(channel=" << param._channel << ")";
    else s << param._value;
    return s;
  }

 private:
  /////////////////////
  // Private Methods //
  /////////////////////
  void _assign(const scalarReflectanceParameter& src);
  void _swap(scalarReflectanceParameter& swp);

  //////////////////
  // Data Members //
  //////////////////
  float _value;
  unsigned int _channel;
  std::shared_ptr<const texture_base> _texture;
};


class colorReflectanceParameter {
 public:
  /////////////////
  // Constructor //
  /////////////////
  colorReflectanceParameter(color value=color(0.0f));
  colorReflectanceParameter(const std::shared_ptr<const texture_base>& texture);
  colorReflectanceParameter(const colorReflectanceParameter& src);

  //////////////
  // Operator //
  //////////////
  colorReflectanceParameter& operator=(const colorReflectanceParameter& src);

  color operator()(const vec2d& textureCoord) const;

  /////////////
  // Friends //
  /////////////
  friend void swap(colorReflectanceParameter& a, colorReflectanceParameter& b) { a._swap(b); }

  friend std::ostream& operator<<(std::ostream& s, const colorReflectanceParameter& param)
  {
    if(param._texture) s << param._texture;
    else s << param._value;
    return s;
  }

 private:
  /////////////////////
  // Private Methods //
  /////////////////////
  void _assign(const colorReflectanceParameter& src);
  void _swap(colorReflectanceParameter& swp);

  //////////////////
  // Data Members //
  //////////////////
  color _value;
  std::shared_ptr<const texture_base> _texture;
};

#endif /* _REFLECTANCEPARAMETER_BASE_H_ */