CompositeFunctionRep.cxx
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 
14 #include "CompositeFunctionRep.h"
15 
16 #include "FunctionParameter.h"
17 
18 #include "functions/FunctionBase.h"
20 
21 #include "reps/LineFunctionRep.h"
22 
23 #include <algorithm>
24 
25 #include <cassert>
26 
27 using std::find;
28 using std::string;
29 using std::vector;
30 
31 using namespace hippodraw;
32 
34 CompositeFunctionRep ( FunctionBase * function, DataRep * target )
35  : FunctionRep ( function, target )
36 {
37  m_rep = new LineFunctionRep ();
38  // The above deleted in ~DataRep()
39 
40  const Color blue ( Color::blue );
41  m_rep -> setColor ( blue );
42  m_rep -> setSize ( 2 );
43 }
44 
49 void
52 {
53  frep -> setInComposite ( true );
54  m_func_reps.push_back ( frep );
55 
56  FunctionBase * composite = getFunction ();
57  FunctionBase * function = frep -> getFunction ();
58 
59  composite -> addToComposite ( function );
60 
61  Fitter * fitter = getFitter ();
62  if ( fitter != 0 ) {
63  vector < int > flags = getFixedFlags (); // a copy
64  int size = function -> size ();
65  while ( size-- != 0 ) {
66  flags.push_back ( 0 );
67  }
68 
69  setFixedFlags ( flags );
70  }
71 }
72 
73 bool
76 {
77  FunctionRepList_t::iterator first
78  = find ( m_func_reps.begin(), m_func_reps.end(), rep );
79 
80  return first != m_func_reps.end();
81 }
82 
83 void
86 {
87  FunctionBase * function = frep -> getFunction ();
88  FunctionBase * composite = getFunction ();
89  composite -> removeFromComposite ( function );
90 
91  FunctionRepList_t::iterator first
92  = find ( m_func_reps.begin(), m_func_reps.end(), frep );
93  if ( first != m_func_reps.end () ) {
94  m_func_reps.erase ( first );
95  }
96 
97  frep -> setInComposite ( false );
98 }
99 
100 unsigned int
102 count () const
103 {
104  return m_func_reps.size ();
105 }
106 
110 {
111  return m_func_reps;
112 }
113 
114 void
117 {
118 
119  drawCuts ( transform, view );
120 
121  const Range & range = m_projector -> getRange ( Axes::X );
122  FunctionBase * function = getFunction ();
123  LineFunctionRep * rep = dynamic_cast < LineFunctionRep * > ( m_rep );
124  assert ( rep != 0 );
125 
126  rep -> drawProjectedValues ( range, function, transform, view );
127 
128  setDirty ( false );
129 }
130 
131 void
133 setFixedFlags ( const std::vector < int > & flags )
134 {
135  unsigned int size = m_func_reps.size ();
136  vector<int>::const_iterator first = flags.begin();
137 
138  for ( unsigned int i = 0; i < size; i++ ) {
139  FunctionRep * frep = m_func_reps[i];
140  vector < int > tmp = frep -> getFixedFlags ();// a copy
141  unsigned int number = tmp.size ();
142  vector<int>::const_iterator end = first + number;
143  copy ( first, end, tmp.begin() );
144  frep -> setFixedFlags ( tmp );
145  first = end;
146  }
147 
148  FunctionRep::setFixedFlags ( flags );
149 }
unsigned int i
virtual void setFixedFlags(const std::vector< int > &flags)
Set the parameters that are to be held fixed during a fit.
A LinePointRep class that draws a function by trying to make a smooth line after the transform to the...
FunctionBase * getFunction() const
Returns the actual function, a FunctionBase derived class.
virtual void setFixedFlags(const std::vector< int > &flags)
Sets the fixed flags of its contained function representations and itself.
virtual void addToComposite(FunctionRep *frep)
A transform that transforms coordinates from one coordinate system to another.
Definition: TransformBase.h:35
const std::vector< int > & getFixedFlags() const
Returns a set of flags indicating which function parameters are fixed during a fit.
CompositeFunctionRep class interface.
FunctionParameter class interface.
A derived class of DataRep which is a base class for displaying a function.
Definition: FunctionRep.h:34
return rep
Definition: Inspector.cxx:3843
RepBase * m_rep
The representation used for drawing each data point in the view.
Definition: DataRep.h:94
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
std::vector< FunctionRep * > FunctionRepList_t
The type of container for the list of FunctionRep objects.
The base class for fitters.
Definition: Fitter.h:33
The base class for data representations.
Definition: DataRep.h:68
LineFunctionRep class interface.
bool isMember(const FunctionRep *)
Returns true if the FunctionRep is a member of the Composite.
intp size(numeric::array arr)
Definition: num_util.cpp:296
virtual void removeFromComposite(FunctionRep *frep)
Removes the function representation from composite if receiving object is a CompositeFunctionRep, otherwise does nothing.
void drawCuts(TransformBase *transform, ViewBase *view)
Draws the cuts.
Definition: DataRep.cxx:290
hippodraw::ProjectorBase class interface.
virtual void drawProjectedValues(TransformBase *transform, ViewBase *view)
Draws the projected values.
void setInComposite(bool yes)
Informs receiving object that it is a member of a composite.
CompositeFunctionRep(FunctionBase *, DataRep *)
The constructor.
FunctionRepList_t m_func_reps
The list of FunctionRep objects making up the composite.
Fitter * getFitter() const
Returns the Fitter object currently in use.
The abstract base class for views.
Definition: ViewBase.h:62
A function that can be added to a DataRep and used in a fitter.
Definition: FunctionBase.h:90
ProjectorBase * m_projector
A projector used to transform data to projected values that will be plotted.
Definition: DataRep.h:90
unsigned int count() const
Returns the number of FunctionRep objects contained by the composite.
virtual void setDirty(bool yes=true)
Sets the dirty flag.
Definition: DataRep.cxx:133
Expresses a range of values.
Definition: Range.h:33
hippodraw::FunctionBase class interface
const FunctionRepList_t & getFunctionReps() const
Returns the list of contained FunctionRep objects.

Generated for HippoDraw Class Library by doxygen