libSBNW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Modules Pages
curve.h
1 /*== SAGITTARIUS =====================================================================
2  * Copyright (c) 2012, Jesse K Medley
3  * All rights reserved.
4 
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of The University of Washington nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 //== FILEDOC =========================================================================
29 
34 //== BEGINNING OF CODE ===============================================================
35 
36 #ifndef __SBNW_LAYOUT_CURVE_H_
37 #define __SBNW_LAYOUT_CURVE_H_
38 
39 //== INCLUDES ========================================================================
40 
42 #include "graphfab/layout/point.h"
45 
46 //-- C++ code --
47 #ifdef __cplusplus
48 
49 #include <string>
50 
51 #include <iostream>
52 
53 namespace Graphfab {
54 
56  typedef enum {
57  RXN_CURVE_SUBSTRATE,
58  RXN_CURVE_PRODUCT,
59  RXN_CURVE_ACTIVATOR,
60  RXN_CURVE_INHIBITOR,
61  RXN_CURVE_MODIFIER
62  } RxnCurveType;
63 
64  class Node;
65 
72  class RxnBezier {
73  public:
74  RxnBezier() {
75  ns = ne = NULL;
76  }
77 
78  virtual ~RxnBezier() {
79  if(as && owns)
80  delete as;
81  if(ae && owne)
82  delete ae;
83  }
84 
86  virtual RxnCurveType getRole() const = 0;
87 
88  void applyTransform(const Affine2d& t) {
89  s = xformPoint(s, t);
90  c1 = xformPoint(c1,t);
91  c2 = xformPoint(c2,t);
92  e = xformPoint(e, t);
93  }
94 
96  Point* as;
98  int owns;
99 
101  Point* ae;
103  int owne;
104 
105  Node* ns;
106  Node* ne;
107 
108  //Calculated points:
110  Point s, e, c1, c2;
111 
112  Point getTransformedS() const { return tf_*s; }
113  Point getTransformedE() const { return tf_*e; }
114  Point getTransformedC1() const { return tf_*c1; }
115  Point getTransformedC2() const { return tf_*c2; }
116 
117  virtual Point getCentroidCP() const = 0;
118 
119  virtual bool isStartNodeSide() const = 0;
120 
121  Point getNodeSideCP() const {
122  if (isStartNodeSide())
123  return c1;
124  else
125  return c2;
126  }
127 
128  void setNodeSideCP(const Point& p) {
129  if (isStartNodeSide())
130  c1 = p;
131  else
132  c2 = p;
133  }
134 
135  Point getNodeSide() const {
136  if (isStartNodeSide())
137  return s;
138  else
139  return e;
140  }
141 
142  void setNodeSide(const Point& p) {
143  if (isStartNodeSide())
144  s = p;
145  else
146  e = p;
147  }
148 
149  Node* getNodeUsed() const {
150  if (isStartNodeSide())
151  return ns;
152  else
153  return ne;
154  }
155 
156  bool includes(const Node* n) {
157  if (ns == n)
158  return true;
159  else if (ne == n)
160  return true;
161  else
162  return false;
163  }
164 
165  virtual bool hasArrowhead() const { return false; }
166 
167  void transformArrowhead(Arrowhead& a) {
168  Point v;
169  if ((e - c2).mag2() < 1e-2)
170  v = (e - s).normed() * 5.;
171  else
172  v = (e - c2).normed() * 5.;
173  Point u = v.dextro();
174 
175  a.setTransform(tf_*Affine2d::fromBasis(u, v, e));
176  a.setInverseTransform(a.getTransform().inv());
177  }
178 
179  // For non-curved segments
180 // void transformArrowheadFlat(Arrowhead& a) {
181 // Point v = (e - s).normed() * 5.;
182 // Point u = v.dextro();
183 //
184 // a.setTransform(tf_*Affine2d::fromBasis(u, v, e));
185 // a.setInverseTransform(a.getTransform().inv());
186 // }
187 
189  virtual Arrowhead* getArrowhead() {
190  Arrowhead* result = new PlainArrowhead();
191  transformArrowhead(*result);
192  return result;
193  }
194 
195  Affine2d getTransform() const { return tf_; }
196 
197  void setTransform(const Affine2d& tf, bool recurse = true) { tf_ = tf; }
198 
199  Affine2d getInverseTransform() const { return itf_; }
200 
201  void setInverseTransform(const Affine2d& itf, bool recurse = true) { itf_ = itf; }
202 
203  virtual ArrowheadStyle getArrowheadStyle() const = 0;
204 
205 
207  Affine2d tf_;
209  Affine2d itf_;
210  protected:
211  };
212 
213  inline std::ostream& operator<< (std::ostream& os, const RxnBezier& b) {
214  os << b.s << "-" << b.c1 << "-" << b.c2 << "-" << b.e;
215  return os;
216  }
217 
218 }
219 
220 #endif
221 
222 #endif
Definition: SagittariusCommon.cpp:38
Arrowhead primitive.
First file included.
Roots of cubic equations.