COPASI API  4.16.103
Public Member Functions | Protected Attributes | Friends | List of all members
CLCurve Class Reference

#include <CLCurve.h>

Inheritance diagram for CLCurve:
Inheritance graph
[legend]
Collaboration diagram for CLCurve:
Collaboration graph
[legend]

Public Member Functions

void addCurveSegment (const CLLineSegment &ls)
 
void addCurveSegment (const CLLineSegment *pLs)
 
CLBoundingBox calculateBoundingBox () const
 
 CLCurve ()
 
 CLCurve (const CLCurve &c)
 
 CLCurve (const Curve &sbmlcurve)
 
void clear ()
 
void exportToSBML (Curve *c, const std::map< const CCopasiObject *, SBase * > &copasimodelmap) const
 
const std::vector
< CLLineSegment > & 
getCurveSegments () const
 
std::vector< CLPointgetListOfPoints () const
 
size_t getNumCurveSegments () const
 
const CLLineSegmentgetSegmentAt (size_t i) const
 
CLLineSegmentgetSegmentAt (size_t i)
 
bool isContinuous () const
 
virtual void moveBy (const CLPoint &p)
 
bool operator== (const CLCurve &rhs) const
 
void scale (const double &scaleFactor)
 
 ~CLCurve ()
 
- Public Member Functions inherited from CLBase
 CLBase ()
 
 CLBase (const CLBase &b)
 
 CLBase (const SBase &)
 
const std::string & getTag () const
 
bool hasTag () const
 
void setTag (const std::string &tag)
 
virtual ~CLBase ()
 

Protected Attributes

std::vector< CLLineSegmentmvCurveSegments
 
- Protected Attributes inherited from CLBase
std::string mTag
 

Friends

std::ostream & operator<< (std::ostream &os, const CLCurve &c)
 

Detailed Description

Definition at line 131 of file CLCurve.h.

Constructor & Destructor Documentation

CLCurve::CLCurve ( )
inline

Definition at line 139 of file CLCurve.h.

140  : CLBase(), mvCurveSegments() {};
CLBase()
Definition: CLBase.h:36
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
CLCurve::CLCurve ( const CLCurve c)

copy constructor (should make deep copy)

Definition at line 74 of file CLCurve.cpp.

75  : CLBase(c),
77 {}
CLBase()
Definition: CLBase.h:36
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
CLCurve::CLCurve ( const Curve &  sbmlcurve)

constructor from libsbml object

Definition at line 79 of file CLCurve.cpp.

References C_INT32, and mvCurveSegments.

80  : CLBase(sbmlcurve),
82 {
83  //TODO
84  C_INT32 i, imax = sbmlcurve.getListOfCurveSegments()->size();
85 
86  for (i = 0; i < imax; ++i)
87  {
88  const LineSegment* tmp
89  = dynamic_cast<const LineSegment*>(sbmlcurve.getListOfCurveSegments()->get(i));
90 
91  if (tmp)
92  mvCurveSegments.push_back(CLLineSegment(*tmp));
93 
94  //addCurveSegment(CLLineSegment(*tmp));
95  }
96 }
CLBase()
Definition: CLBase.h:36
#define C_INT32
Definition: copasi.h:90
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
CLCurve::~CLCurve ( )

Definition at line 98 of file CLCurve.cpp.

99 {}

Member Function Documentation

void CLCurve::addCurveSegment ( const CLLineSegment ls)

add a copy of the line segment to the curve

Definition at line 101 of file CLCurve.cpp.

References mvCurveSegments.

Referenced by CCopasiXMLParser::CurveElement::end(), CCopasiSpringLayout::finalizeState(), and CLLayoutRenderer::revert_curve().

102 {
103  mvCurveSegments.push_back(ls);
104 }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
void CLCurve::addCurveSegment ( const CLLineSegment pLs)

add a copy of the line segment to the curve

Definition at line 106 of file CLCurve.cpp.

References mvCurveSegments.

107 {
108  if (pLs)
109  mvCurveSegments.push_back(*pLs);
110 }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
CLBoundingBox CLCurve::calculateBoundingBox ( ) const

Calculates the bounding box for the curve. Basepoints for cubic beziers are considered to belong inside the bounding box.

Definition at line 218 of file CLCurve.cpp.

References CLLineSegment::getBase1(), CLLineSegment::getBase2(), CLLineSegment::getEnd(), getNumCurveSegments(), getSegmentAt(), CLLineSegment::getStart(), CLPoint::getX(), CLPoint::getY(), CLLineSegment::isBezier(), and max.

Referenced by CLayout::calculateBoundingBox().

219 {
220  double xMin = std::numeric_limits<double>::max();
221  double yMin = xMin;
222  double xMax = -xMin;
223  double yMax = -xMin;
224  double x, y;
225  size_t i, iMax = this->getNumCurveSegments();
226  const CLLineSegment* pLS = NULL;
227  const CLPoint* pP = NULL;
228 
229  for (i = 0; i < iMax; ++i)
230  {
231  pLS = this->getSegmentAt(i);
232  pP = &pLS->getStart();
233  x = pP->getX();
234  y = pP->getY();
235  xMin = (xMin < x) ? xMin : x;
236  yMin = (yMin < y) ? yMin : y;
237  xMax = (xMax > x) ? xMax : x;
238  yMax = (yMax > y) ? yMax : y;
239  pP = &pLS->getEnd();
240  x = pP->getX();
241  y = pP->getY();
242  xMin = (xMin < x) ? xMin : x;
243  yMin = (yMin < y) ? yMin : y;
244  xMax = (xMax > x) ? xMax : x;
245  yMax = (yMax > y) ? yMax : y;
246 
247  if (pLS->isBezier())
248  {
249  pP = &pLS->getBase1();
250  x = pP->getX();
251  y = pP->getY();
252  xMin = (xMin < x) ? xMin : x;
253  yMin = (yMin < y) ? yMin : y;
254  xMax = (xMax > x) ? xMax : x;
255  yMax = (yMax > y) ? yMax : y;
256  pP = &pLS->getBase2();
257  x = pP->getX();
258  y = pP->getY();
259  xMin = (xMin < x) ? xMin : x;
260  yMin = (yMin < y) ? yMin : y;
261  xMax = (xMax > x) ? xMax : x;
262  yMax = (yMax > y) ? yMax : y;
263  }
264  }
265 
266  return CLBoundingBox(CLPoint(xMin, yMin), CLDimensions(xMax - xMin, yMax - yMin));
267 }
const CLPoint & getBase1() const
Definition: CLCurve.h:82
const CLPoint & getBase2() const
Definition: CLCurve.h:83
const CLPoint & getEnd() const
Definition: CLCurve.h:75
const C_FLOAT64 & getX() const
Definition: CLBase.h:83
Definition: CLBase.h:54
const C_FLOAT64 & getY() const
Definition: CLBase.h:84
bool isBezier() const
Definition: CLCurve.h:90
const CLLineSegment * getSegmentAt(size_t i) const
Definition: CLCurve.h:156
size_t getNumCurveSegments() const
Definition: CLCurve.h:168
const CLPoint & getStart() const
Definition: CLCurve.h:74
#define max(a, b)
Definition: f2c.h:176
void CLCurve::clear ( )

Definition at line 112 of file CLCurve.cpp.

References mvCurveSegments.

Referenced by CCopasiSpringLayout::finalizeState(), and CCopasiXMLParser::CurveElement::start().

113 {
114  mvCurveSegments.clear();
115 }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
void CLCurve::exportToSBML ( Curve *  c,
const std::map< const CCopasiObject *, SBase * > &  copasimodelmap 
) const

This method writes the information of the copasi layout object into the corresponding sbml object

Definition at line 148 of file CLCurve.cpp.

References mvCurveSegments.

Referenced by CLMetabReferenceGlyph::exportToSBML(), CLGeneralGlyph::exportToSBML(), and CLReactionGlyph::exportToSBML().

149 {
150  if (!c) return;
151 
152  //we will reconstruct the curve completely without checking the existing curve
153  size_t i, imax = c->getListOfCurveSegments()->size();
154 
155  for (i = 0; i < imax; ++i) delete c->getListOfCurveSegments()->remove(0);
156 
157  //curve segments
158  imax = mvCurveSegments.size();
159 
160  for (i = 0; i < imax; ++i)
161  {
162  if (mvCurveSegments[i].isBezier())
163  {
164  mvCurveSegments[i].exportToSBMLBezier(c->createCubicBezier(), copasimodelmap);
165  }
166  else
167  {
168  mvCurveSegments[i].exportToSBMLLineSegment(c->createLineSegment(), copasimodelmap);
169  }
170  }
171 }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
const std::vector<CLLineSegment>& CLCurve::getCurveSegments ( ) const
inline
std::vector< CLPoint > CLCurve::getListOfPoints ( ) const

This method should only be called if isContinuous() is true. It returns the curve as a list of points rather than a list of line segments.

Definition at line 130 of file CLCurve.cpp.

References isContinuous(), and mvCurveSegments.

Referenced by CQGLNetworkPainter::checkCurve(), and fillItemFromCurve().

131 {
132  std::vector <CLPoint> ret;
133 
134  if (mvCurveSegments.size() == 0) return ret;
135 
136  if (!isContinuous()) return ret;
137 
138  size_t i, imax = mvCurveSegments.size();
139 
140  for (i = 0; i < imax; ++i)
141  ret.push_back(mvCurveSegments[i].getStart());
142 
143  ret.push_back(mvCurveSegments[i - 1].getEnd());
144 
145  return ret;
146 }
bool isContinuous() const
Definition: CLCurve.cpp:117
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
size_t CLCurve::getNumCurveSegments ( ) const
inline
const CLLineSegment* CLCurve::getSegmentAt ( size_t  i) const
inline
CLLineSegment* CLCurve::getSegmentAt ( size_t  i)
inline

Definition at line 162 of file CLCurve.h.

References mvCurveSegments.

163  {
164  if (i < mvCurveSegments.size())return &(mvCurveSegments[i]);
165  else return NULL;
166  }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
bool CLCurve::isContinuous ( ) const

this method tells whether the curve is a continuous set of line segments, i.e. if the end point of one line segment is identical to the starting point of the following one.

Definition at line 117 of file CLCurve.cpp.

References mvCurveSegments.

Referenced by fillItemFromCurve(), and getListOfPoints().

118 {
119  if (mvCurveSegments.size() <= 1) return true;
120 
121  size_t i, imax = mvCurveSegments.size() - 1;
122 
123  for (i = 0; i < imax; ++i)
124  if (!(mvCurveSegments[i].getEnd() == mvCurveSegments[i + 1].getStart()))
125  return false;
126 
127  return true;
128 }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
void CLCurve::moveBy ( const CLPoint p)
virtual

Reimplemented from CLBase.

Definition at line 187 of file CLCurve.cpp.

References CLLineSegment::getBase1(), CLLineSegment::getBase2(), CLLineSegment::getEnd(), getNumCurveSegments(), getSegmentAt(), CLLineSegment::getStart(), CLLineSegment::isBezier(), and CLPoint::moveBy().

Referenced by CLGlyphWithCurve::moveBy().

188 {
189  CLLineSegment* pLS = NULL;
190  CLPoint* pP = NULL;
191  size_t i, iMax = this->getNumCurveSegments();
192 
193  for (i = 0; i < iMax; ++i)
194  {
195  pLS = this->getSegmentAt(i);
196  pP = &pLS->getStart();
197  pP->moveBy(p);
198 
199  pP = &pLS->getEnd();
200  pP->moveBy(p);
201 
202  if (pLS->isBezier())
203  {
204  pP = &pLS->getBase1();
205  pP->moveBy(p);
206 
207  pP = &pLS->getBase2();
208  pP->moveBy(p);
209  }
210  }
211 }
const CLPoint & getBase1() const
Definition: CLCurve.h:82
const CLPoint & getBase2() const
Definition: CLCurve.h:83
const CLPoint & getEnd() const
Definition: CLCurve.h:75
Definition: CLBase.h:54
bool isBezier() const
Definition: CLCurve.h:90
const CLLineSegment * getSegmentAt(size_t i) const
Definition: CLCurve.h:156
size_t getNumCurveSegments() const
Definition: CLCurve.h:168
virtual void moveBy(const CLPoint &p)
Definition: CLBase.h:120
const CLPoint & getStart() const
Definition: CLCurve.h:74
bool CLCurve::operator== ( const CLCurve rhs) const
inline

Two curves are supposed to be equal iff all there line segments including their order are equal

Definition at line 201 of file CLCurve.h.

References mvCurveSegments.

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  }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135
void CLCurve::scale ( const double &  scaleFactor)
inline

Definition at line 214 of file CLCurve.h.

References mvCurveSegments.

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  }
std::vector< CLLineSegment > mvCurveSegments
Definition: CLCurve.h:135

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CLCurve c 
)
friend

insert operator

Definition at line 173 of file CLCurve.cpp.

174 {
175  if (c.getNumCurveSegments())
176  {
177  os << " Curve:\n";
178  size_t i, imax = c.getNumCurveSegments();
179 
180  for (i = 0; i < imax; ++i)
181  os << " " << c.getCurveSegments()[i] << "\n";
182  }
183 
184  return os;
185 }
const std::vector< CLLineSegment > & getCurveSegments() const
Definition: CLCurve.h:154
size_t getNumCurveSegments() const
Definition: CLCurve.h:168

Member Data Documentation

std::vector<CLLineSegment> CLCurve::mvCurveSegments
protected

The documentation for this class was generated from the following files: