OpenWalnut  1.5.0dev
WDataSetHistogram1D.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "WDataSetHistogram1D.h"
30 
31 // prototype instance as singleton
32 std::shared_ptr< WPrototyped > WDataSetHistogram1D::m_prototype = std::shared_ptr< WPrototyped >();
33 
34 WDataSetHistogram1D::WDataSetHistogram1D( std::shared_ptr< WHistogramBasic const > const& histo )
35  : WDataSet(),
36  m_histogram( new WHistogramBasic( *histo ) ),
37  m_colors()
38 {
39 }
40 
41 WDataSetHistogram1D::WDataSetHistogram1D( std::shared_ptr< WHistogramBasic const > const& histo,
42  std::shared_ptr< std::vector< WColor > const > const& colors )
43  : WDataSet(),
44  m_histogram( new WHistogramBasic( *histo ) ),
45  m_colors( colors )
46 {
47 }
48 
50  : WDataSet(),
51  m_histogram()
52 {
53 }
54 
56 {
57 }
58 
59 std::string const WDataSetHistogram1D::getName() const
60 {
61  return "WDataSetHistogram1D";
62 }
63 
64 std::string const WDataSetHistogram1D::getDescription() const
65 {
66  return "A dataset that contains some 1D histogram.";
67 }
68 
69 std::shared_ptr< WPrototyped > WDataSetHistogram1D::getPrototype()
70 {
71  if( !m_prototype )
72  {
73  m_prototype = std::shared_ptr< WPrototyped >( new WDataSetHistogram1D() );
74  }
75 
76  return m_prototype;
77 }
78 
79 std::shared_ptr< WHistogramBasic const > const& WDataSetHistogram1D::getHistogram() const
80 {
81  return m_histogram;
82 }
83 
85 {
86  return m_histogram && m_colors && m_colors->size() == m_histogram->size();
87 }
88 
89 WColor WDataSetHistogram1D::getColor( std::size_t bin ) const
90 {
91  return m_colors->at( bin );
92 }
93 
virtual const std::string getDescription() const
Gets the description for this prototype.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
bool hasColors() const
Whether this dataset has colors associated with the bins.
std::shared_ptr< std::vector< WColor > const > const m_colors
The colors for the bins.
WColor getColor(std::size_t bin) const
Get the color of a bin.
virtual const std::string getName() const
Gets the name of this prototype.
virtual ~WDataSetHistogram1D()
Destroys this DataSet instance.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
WDataSetHistogram1D()
Construct an empty and unusable instance.
std::shared_ptr< WHistogramBasic const > const & getHistogram() const
Returns the histogram.
std::shared_ptr< WHistogramBasic const > const m_histogram
The histogram.
Base class for all data set types.
Definition: WDataSet.h:50
Container which associate values with (uniform width) bins (aka intervals or buckets).