COPASI API  4.16.103
CLCurve.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef CLCURVE_H_
16 #define CLCURVE_H_
17 
18 #include <vector>
19 #include <map>
20 
21 #include "copasi/layout/CLBase.h"
23 
24 class CCopasiObject;
25 class LineSegment;
26 class Curve;
27 class CubicBezier;
28 class LineSegment;
29 
30 /**
31  * This class describes a line segment.
32  */
33 class CLLineSegment : public CLBase
34 {
35 protected:
36 
39 
42 
43  bool mIsBezier;
44 
45 public:
46 
48  : mStart(), mEnd(),
49  mBase1(), mBase2(),
50  mIsBezier(false) {};
51 
52  /**
53  * Constructor for a straight line segment
54  */
55  CLLineSegment(const CLPoint & s, const CLPoint & e)
56  : mStart(s), mEnd(e),
57  mBase1(), mBase2(),
58  mIsBezier(false) {};
59 
60  /**
61  * Constructor for a bezier segment
62  */
63  CLLineSegment(const CLPoint & s, const CLPoint & e,
64  const CLPoint & b1, const CLPoint & b2)
65  : mStart(s), mEnd(e),
66  mBase1(b1), mBase2(b2),
67  mIsBezier(true) {};
68 
69  /**
70  * constructor from libsbml object
71  */
72  CLLineSegment(const LineSegment & ls);
73 
74  const CLPoint & getStart() const {return mStart;};
75  const CLPoint & getEnd() const {return mEnd;};
76  CLPoint & getStart() {return mStart;};
77  CLPoint & getEnd() {return mEnd;};
78 
79  void setStart(const CLPoint & p) {mStart = p;};
80  void setEnd(const CLPoint & p) {mEnd = p;};
81 
82  const CLPoint & getBase1() const {return mBase1;};
83  const CLPoint & getBase2() const {return mBase2;};
84  CLPoint & getBase1() {return mBase1;};
85  CLPoint & getBase2() {return mBase2;};
86 
87  void setBase1(const CLPoint & p) {mBase1 = p;};
88  void setBase2(const CLPoint & p) {mBase2 = p;};
89 
90  bool isBezier() const {return mIsBezier;};
91  void setIsBezier(bool b) {mIsBezier = b;};
92 
93  // if two lines are congruent, they are supposed to be ==
94  bool operator==(const CLLineSegment & rhs) const
95  {
96  if (mIsBezier) return((mStart == rhs.mStart) && (mEnd == rhs.mEnd) && (mBase1 == rhs.mBase1) && (mBase2 == rhs.mBase2));
97  else return ((mStart == rhs.mStart) && (mEnd == rhs.mEnd));
98  };
99 
100  // compare two line segments according to their start point (needed for use of line segment as a key in a map)
101  bool operator<(const CLLineSegment & rhs) const
102  {return (mStart < rhs.mStart);};
103 
104  void scale(const double & scaleFactor)
105  {
106  mStart.scale(scaleFactor); mEnd.scale(scaleFactor);
107 
108  if (mIsBezier) {mBase1.scale(scaleFactor); mBase2.scale(scaleFactor);}
109  }
110 
111  /**
112  * This method writes the information of the copasi layout object into the
113  * corresponding sbml object. This is only guaranteed to work if
114  * isBezier() is true.
115  */
116  void exportToSBMLBezier(CubicBezier * c, const std::map<const CCopasiObject*, SBase*> & copasimodelmap) const;
117 
118  /**
119  * This method writes the information of the copasi layout object into the
120  * corresponding sbml object. This is only guaranteed to work if
121  * isBezier() is false.
122  */
123  void exportToSBMLLineSegment(LineSegment * l, const std::map<const CCopasiObject*, SBase*> & copasimodelmap) const;
124 
125  /**
126  * insert operator
127  */
128  friend std::ostream & operator<<(std::ostream &os, const CLLineSegment & ls);
129 };
130 
131 class CLCurve : public CLBase
132 {
133 protected:
134 
135  std::vector<CLLineSegment> mvCurveSegments;
136 
137 public:
138 
140  : CLBase(), mvCurveSegments() {};
141 
142  /**
143  * copy constructor (should make deep copy)
144  */
145  CLCurve(const CLCurve & c);
146 
147  /**
148  * constructor from libsbml object
149  */
150  CLCurve(const Curve & sbmlcurve);
151 
152  ~CLCurve();
153 
154  const std::vector<CLLineSegment> & getCurveSegments() const {return mvCurveSegments;};
155 
156  const CLLineSegment* getSegmentAt(size_t i) const
157  {
158  if (i < mvCurveSegments.size())return &(mvCurveSegments[i]);
159  else return NULL;
160  }
161 
163  {
164  if (i < mvCurveSegments.size())return &(mvCurveSegments[i]);
165  else return NULL;
166  }
167 
168  size_t getNumCurveSegments() const {return mvCurveSegments.size();};
169 
170  void clear();
171 
172  /**
173  * add a copy of the line segment to the curve
174  */
175  void addCurveSegment(const CLLineSegment & ls);
176 
177  /**
178  * add a copy of the line segment to the curve
179  */
180  void addCurveSegment(const CLLineSegment * pLs);
181 
182  /**
183  * this method tells whether the curve is a continuous
184  * set of line segments, i.e. if the end point of one
185  * line segment is identical to the starting point of the
186  * following one.
187  */
188  bool isContinuous() const;
189 
190  /**
191  * This method should only be called if isContinuous() is true.
192  * It returns the curve as a list of points rather than a list
193  * of line segments.
194  */
195  std::vector <CLPoint> getListOfPoints() const;
196 
197  /**
198  * Two curves are supposed to be equal iff all there line segments
199  * including their order are equal
200  */
201  bool operator==(const CLCurve & rhs) const
202  {
203  bool result = true;
204  unsigned int i;
205 
206  for (i = 0; i < mvCurveSegments.size(); i++)
207  {
208  result = result && (mvCurveSegments[i] == rhs.mvCurveSegments[i]);
209  }
210 
211  return result;
212  }
213 
214  void scale(const double & scaleFactor)
215  {
216  unsigned int i; // scale all segments
217 
218  for (i = 0; i < mvCurveSegments.size(); i++)
219  {
220  mvCurveSegments[i].scale(scaleFactor);
221  }
222  }
223 
224  /**
225  * This method writes the information of the copasi layout object into the
226  * corresponding sbml object
227  */
228  void exportToSBML(Curve * c, const std::map<const CCopasiObject*, SBase*> & copasimodelmap) const;
229 
230  /**
231  * Calculates the bounding box for the curve.
232  * Basepoints for cubic beziers are considered to belong inside the bounding
233  * box.
234  */
236 
237  virtual void moveBy(const CLPoint &p);
238 
239  /**
240  * insert operator
241  */
242  friend std::ostream & operator<<(std::ostream &os, const CLCurve & c);
243 };
244 
245 #endif
friend std::ostream & operator<<(std::ostream &os, const CLCurve &c)
Definition: CLCurve.cpp:173
CLBoundingBox calculateBoundingBox() const
Definition: CLCurve.cpp:218
void exportToSBML(Curve *c, const std::map< const CCopasiObject *, SBase * > &copasimodelmap) const
Definition: CLCurve.cpp:148
void setStart(const CLPoint &p)
Definition: CLCurve.h:79
CLPoint mEnd
Definition: CLCurve.h:38
bool mIsBezier
Definition: CLCurve.h:43
const std::vector< CLLineSegment > & getCurveSegments() const
Definition: CLCurve.h:154
void scale(const double &scaleFactor)
Definition: CLCurve.h:214
void exportToSBMLLineSegment(LineSegment *l, const std::map< const CCopasiObject *, SBase * > &copasimodelmap) const
Definition: CLCurve.cpp:53
~CLCurve()
Definition: CLCurve.cpp:98
void setIsBezier(bool b)
Definition: CLCurve.h:91
void exportToSBMLBezier(CubicBezier *c, const std::map< const CCopasiObject *, SBase * > &copasimodelmap) const
Definition: CLCurve.cpp:41
CLLineSegment * getSegmentAt(size_t i)
Definition: CLCurve.h:162
virtual void moveBy(const CLPoint &p)
Definition: CLCurve.cpp:187
const CLPoint & getBase1() const
Definition: CLCurve.h:82
CLPoint mBase1
Definition: CLCurve.h:40
CLCurve()
Definition: CLCurve.h:139
const CLPoint & getBase2() const
Definition: CLCurve.h:83
const CLPoint & getEnd() const
Definition: CLCurve.h:75
void scale(const double &scaleFactor)
Definition: CLCurve.h:104
CLLineSegment(const CLPoint &s, const CLPoint &e, const CLPoint &b1, const CLPoint &b2)
Definition: CLCurve.h:63
CLPoint & getBase1()
Definition: CLCurve.h:84
Definition: CLBase.h:54
bool operator==(const CLLineSegment &rhs) const
Definition: CLCurve.h:94
CLLineSegment(const CLPoint &s, const CLPoint &e)
Definition: CLCurve.h:55
CLPoint & getStart()
Definition: CLCurve.h:76
Definition: CLBase.h:33
void setBase1(const CLPoint &p)
Definition: CLCurve.h:87
void addCurveSegment(const CLLineSegment &ls)
Definition: CLCurve.cpp:101
void setBase2(const CLPoint &p)
Definition: CLCurve.h:88
std::vector< CLPoint > getListOfPoints() const
Definition: CLCurve.cpp:130
CLPoint mBase2
Definition: CLCurve.h:41
bool isBezier() const
Definition: CLCurve.h:90
const CLLineSegment * getSegmentAt(size_t i) const
Definition: CLCurve.h:156
void scale(const double &scaleFactor)
Definition: CLBase.h:95
void setEnd(const CLPoint &p)
Definition: CLCurve.h:80
bool operator==(const CLCurve &rhs) const
Definition: CLCurve.h:201
CLPoint & getBase2()
Definition: CLCurve.h:85
bool operator<(const CLLineSegment &rhs) const
Definition: CLCurve.h:101
CLPoint & getEnd()
Definition: CLCurve.h:77
size_t getNumCurveSegments() const
Definition: CLCurve.h:168
void clear()
Definition: CLCurve.cpp:112
friend std::ostream & operator<<(std::ostream &os, const CLLineSegment &ls)
Definition: CLCurve.cpp:62
bool isContinuous() const
Definition: CLCurve.cpp:117
const CLPoint & getStart() const
Definition: CLCurve.h:74
CLPoint mStart
Definition: CLCurve.h:37
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
CLLineSegment()
Definition: CLCurve.h:47