File: spectrum.cpp

package info (click to toggle)
k3d 0.8.0.2-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,692 kB
  • ctags: 39,695
  • sloc: cpp: 171,303; ansic: 24,129; xml: 6,995; python: 5,796; makefile: 726; sh: 22
file content (104 lines) | stat: -rw-r--r-- 3,232 bytes parent folder | download | duplicates (5)
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
// K-3D
// Copyright (c) 1995-2009, Timothy M. Shead
//
// Contact: tshead@k-3d.com
//
// This program 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 2 of the License, or (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

/** \file
  \author Tim Shead <tshead@k-3d.com>
*/

#include "spectrum.h"

#include <k3dsdk/iomanip.h>

namespace module
{

namespace indigo
{

std::ostream& operator<<(std::ostream& Stream, const spectrum::type& Value)
{
  switch(Value)
  {
    case spectrum::BLACKBODY:
      Stream << "blackbody";
      break;
    case spectrum::RGB:
      Stream << "rgb";
      break;
  }
  return Stream;
}

std::istream& operator>>(std::istream& Stream, spectrum::type& Value)
{
  std::string text;
  Stream >> text;

  if(text == "blackbody")
    Value = spectrum::BLACKBODY;
  else if(text == "rgb")
    Value = spectrum::RGB;
  else
    k3d::log() << k3d_file_reference << ": unknown enumeration [" << text << "]" << std::endl;

  return Stream;
}

/////////////////////////////////////////////////////////////////////////////
// spectrum

void spectrum::setup(const k3d::string_t& ElementName, std::ostream& Stream)
{
  Stream << k3d::standard_indent << "<" << ElementName << ">\n" << k3d::push_indent;

  switch(m_type.pipeline_value())
  {
  case BLACKBODY:
    Stream << k3d::standard_indent << "<blackbody>\n" << k3d::push_indent;
    Stream << k3d::standard_indent << "<temperature>" << m_blackbody_temperature.pipeline_value() << "</temperature>\n";
    Stream << k3d::standard_indent << "<gain>" << m_blackbody_gain.pipeline_value() << "</gain>\n";
    Stream << k3d::pop_indent << k3d::standard_indent << "</blackbody>\n";
    break;
  case RGB:
    Stream << k3d::standard_indent << "<rgb>\n" << k3d::push_indent;
    Stream << k3d::standard_indent << "<rgb>" << m_red.pipeline_value() << " " << m_green.pipeline_value() << " " << m_blue.pipeline_value() << "</rgb>\n";
    Stream << k3d::standard_indent << "<gamma>" << m_gamma.pipeline_value() << "</gamma>\n";
    Stream << k3d::pop_indent << k3d::standard_indent << "</rgb>\n";
    break;
  }
  
  Stream << k3d::pop_indent << k3d::standard_indent << "</" << ElementName << ">\n";
}

const k3d::ienumeration_property::enumeration_values_t& spectrum::type_values()
{
  static k3d::ienumeration_property::enumeration_values_t values;
  if(values.empty())
  {
    values.push_back(k3d::ienumeration_property::enumeration_value_t("Blackbody", "blackbody", "Generate a blackbody spectrum."));
    values.push_back(k3d::ienumeration_property::enumeration_value_t("RGB", "rgb", "Generate an RGB spectrum."));
  }

  return values;
}

} // namespace indigo

} // namespace module