CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Public Attributes | Static Public Attributes
svgfig.Curve Class Reference
Inheritance diagram for svgfig.Curve:
svgfig.CurveAxis svgfig.Ellipse svgfig.Line svgfig.Rect svgfig.HLine svgfig.LineAxis svgfig.VLine svgfig.XAxis svgfig.YAxis

Classes

class  Sample
 nested class Sample More...
 
class  Samples
 end Sample More...
 

Public Member Functions

def __init__
 
def __repr__
 
def Path
 
def sample
 end nested class More...
 
def subsample
 
def SVG
 

Public Attributes

 attr
 
 f
 
 high
 
 last_samples
 
 loop
 
 low
 

Static Public Attributes

dictionary defaults = {}
 
int discontinuity_limit = 5
 
float linearity_limit = 0.05
 
 random_sampling = True
 
int recursion_limit = 15
 

Detailed Description

Draws a parametric function as a path.

Curve(f, low, high, loop, attribute=value)

f                      required         a Python callable or string in
                                        the form "f(t), g(t)"
low, high              required         left and right endpoints
loop                   default=False    if True, connect the endpoints
attribute=value pairs  keyword list     SVG attributes

Definition at line 1498 of file svgfig.py.

Constructor & Destructor Documentation

def svgfig.Curve.__init__ (   self,
  f,
  low,
  high,
  loop = False,
  attr 
)

Definition at line 1518 of file svgfig.py.

1519  def __init__(self, f, low, high, loop=False, **attr):
1520  self.f = f
1521  self.low = low
1522  self.high = high
1523  self.loop = loop
1525  self.attr = dict(self.defaults)
1526  self.attr.update(attr)
def __init__
Definition: svgfig.py:1518
dictionary defaults
Definition: svgfig.py:1509

Member Function Documentation

def svgfig.Curve.__repr__ (   self)

Definition at line 1515 of file svgfig.py.

References svgfig.SVG.attr, svgfig.Path.attr, svgfig.Curve.attr, svgfig.Curve.f, svgfig.Curve.high, and svgfig.Curve.low.

1516  def __repr__(self):
1517  return "<Curve %s [%s, %s] %s>" % (self.f, self.low, self.high, self.attr)
def __repr__
Definition: svgfig.py:1515
def svgfig.Curve.Path (   self,
  trans = None,
  local = False 
)
Apply the transformation "trans" and return a Path object in
global coordinates.  If local=True, return a Path in local coordinates
(which must be transformed again).

Definition at line 1653 of file svgfig.py.

References svgfig.SVG.attr, svgfig.Path.attr, svgfig.Curve.attr, svgfig.Curve.f, svgfig.funcRtoR2(), svgfig.Curve.last_samples, svgfig.Curve.loop, CastorLedAnalysis.sample, HcalLedAnalysis.sample, HcalPedestalAnalysis.sample, CastorPedestalAnalysis.sample, svgfig.Curve.sample(), and svgfig.totrans().

Referenced by svgfig.Curve.SVG(), svgfig.Poly.SVG(), svgfig.Line.SVG(), svgfig.Rect.SVG(), and svgfig.Ellipse.SVG().

1654  def Path(self, trans=None, local=False):
1655  """Apply the transformation "trans" and return a Path object in
1656  global coordinates. If local=True, return a Path in local coordinates
1657  (which must be transformed again)."""
1658 
1659  if isinstance(trans, basestring): trans = totrans(trans)
1660  if isinstance(self.f, basestring): self.f = funcRtoR2(self.f)
1661 
1662  self.sample(trans)
1663 
1664  output = []
1665  for s in self.last_samples:
1666  if s.X != None and s.Y != None:
1667  if s.left == None or s.left.Y == None:
1668  command = "M"
1669  else:
1670  command = "L"
1671 
1672  if local: output.append((command, s.x, s.y, False))
1673  else: output.append((command, s.X, s.Y, True))
1674 
1675  if self.loop: output.append(("Z",))
1676  return Path(output, **self.attr)
def funcRtoR2
Definition: svgfig.py:1468
def totrans
Definition: svgfig.py:597
def sample
end nested class
Definition: svgfig.py:1575
def svgfig.Curve.sample (   self,
  trans = None 
)

end nested class

Adaptive-sampling algorithm that chooses the best sample points
for a parametric curve between two endpoints and detects
discontinuities.  Called by SVG().

Definition at line 1575 of file svgfig.py.

References funct.abs(), svgfig.Curve.f, svgfig.Curve.high, svgfig.Curve.linearity_limit, svgfig.Curve.low, svgfig.Curve.recursion_limit, and svgfig.Curve.subsample().

Referenced by svgfig.Curve.Path().

1576  def sample(self, trans=None):
1577  """Adaptive-sampling algorithm that chooses the best sample points
1578  for a parametric curve between two endpoints and detects
1579  discontinuities. Called by SVG()."""
1580  oldrecursionlimit = sys.getrecursionlimit()
1581  sys.setrecursionlimit(self.recursion_limit + 100)
1582  try:
1583  # the best way to keep all the information while sampling is to make a linked list
1584  if not (self.low < self.high): raise ValueError, "low must be less than high"
1585  low, high = self.Sample(float(self.low)), self.Sample(float(self.high))
1586  low.link(None, high)
1587  high.link(low, None)
1588 
1589  low.evaluate(self.f, trans)
1590  high.evaluate(self.f, trans)
1591 
1592  # adaptive sampling between the low and high points
1593  self.subsample(low, high, 0, trans)
1594 
1595  # Prune excess points where the curve is nearly linear
1596  left = low
1597  while left.right != None:
1598  # increment mid and right
1599  mid = left.right
1600  right = mid.right
1601  if right != None and left.X != None and left.Y != None and mid.X != None and mid.Y != None and right.X != None and right.Y != None:
1602  numer = left.X*(right.Y - mid.Y) + mid.X*(left.Y - right.Y) + right.X*(mid.Y - left.Y)
1603  denom = math.sqrt((left.X - right.X)**2 + (left.Y - right.Y)**2)
1604  if denom != 0. and abs(numer/denom) < self.linearity_limit:
1605  # drop mid (the garbage collector will get it)
1606  left.right = right
1607  right.left = left
1608  else:
1609  # increment left
1610  left = left.right
1611  else:
1612  left = left.right
1614  self.last_samples = self.Samples(low, high)
1615 
1616  finally:
1617  sys.setrecursionlimit(oldrecursionlimit)
end Sample
Definition: svgfig.py:1551
def subsample
Definition: svgfig.py:1618
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int recursion_limit
Definition: svgfig.py:1511
float linearity_limit
Definition: svgfig.py:1512
def sample
end nested class
Definition: svgfig.py:1575
nested class Sample
Definition: svgfig.py:1528
def svgfig.Curve.subsample (   self,
  left,
  right,
  depth,
  trans = None 
)
Part of the adaptive-sampling algorithm that chooses the best
sample points.  Called by sample().

Definition at line 1618 of file svgfig.py.

References funct.abs(), svgfig.Curve.discontinuity_limit, svgfig.Curve.f, svgfig.Curve.linearity_limit, svgfig.Curve.random_sampling, svgfig.Curve.recursion_limit, and svgfig.Curve.subsample().

Referenced by svgfig.Curve.sample(), and svgfig.Curve.subsample().

1619  def subsample(self, left, right, depth, trans=None):
1620  """Part of the adaptive-sampling algorithm that chooses the best
1621  sample points. Called by sample()."""
1622 
1623  if self.random_sampling:
1624  mid = self.Sample(left.t + random.uniform(0.3, 0.7) * (right.t - left.t))
1625  else:
1626  mid = self.Sample(left.t + 0.5 * (right.t - left.t))
1627 
1628  left.right = mid
1629  right.left = mid
1630  mid.link(left, right)
1631  mid.evaluate(self.f, trans)
1632 
1633  # calculate the distance of closest approach of mid to the line between left and right
1634  numer = left.X*(right.Y - mid.Y) + mid.X*(left.Y - right.Y) + right.X*(mid.Y - left.Y)
1635  denom = math.sqrt((left.X - right.X)**2 + (left.Y - right.Y)**2)
1636 
1637  # if we haven't sampled enough or left fails to be close enough to right, or mid fails to be linear enough...
1638  if depth < 3 or (denom == 0 and left.t != right.t) or denom > self.discontinuity_limit or (denom != 0. and abs(numer/denom) > self.linearity_limit):
1639 
1640  # and we haven't sampled too many points
1641  if depth < self.recursion_limit:
1642  self.subsample(left, mid, depth+1, trans)
1643  self.subsample(mid, right, depth+1, trans)
1644 
1645  else:
1646  # We've sampled many points and yet it's still not a small linear gap.
1647  # Break the line: it's a discontinuity
1648  mid.y = mid.Y = None
def subsample
Definition: svgfig.py:1618
int discontinuity_limit
Definition: svgfig.py:1513
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int recursion_limit
Definition: svgfig.py:1511
float linearity_limit
Definition: svgfig.py:1512
nested class Sample
Definition: svgfig.py:1528
def svgfig.Curve.SVG (   self,
  trans = None 
)
Apply the transformation "trans" and return an SVG object.

Definition at line 1649 of file svgfig.py.

References SiPixelHistoPlotter::PlotParameter.Path, SiStripHistoPlotter::PlotParameter.Path, Json::PathArgument.Path, and svgfig.Curve.Path().

1650  def SVG(self, trans=None):
1651  """Apply the transformation "trans" and return an SVG object."""
1652  return self.Path(trans).SVG()

Member Data Documentation

svgfig.Curve.attr

Definition at line 1524 of file svgfig.py.

Referenced by svgfig.Curve.__repr__(), svgfig.Poly.__repr__(), svgfig.Text.__repr__(), svgfig.TextGlobal.__repr__(), svgfig.Dots.__repr__(), svgfig.Line.__repr__(), svgfig.LineGlobal.__repr__(), svgfig.VLine.__repr__(), svgfig.HLine.__repr__(), svgfig.Rect.__repr__(), svgfig.Ellipse.__repr__(), svgfig.Ticks.__repr__(), svgfig.CurveAxis.__repr__(), svgfig.LineAxis.__repr__(), svgfig.XAxis.__repr__(), svgfig.YAxis.__repr__(), svgfig.Axes.__repr__(), svgfig.HGrid.__repr__(), svgfig.VGrid.__repr__(), svgfig.Grid.__repr__(), svgfig.Curve.Path(), svgfig.Poly.Path(), svgfig.Rect.Path(), svgfig.Text.SVG(), svgfig.TextGlobal.SVG(), svgfig.LineGlobal.SVG(), svgfig.Axes.SVG(), svgfig.XErrorBars.SVG(), and svgfig.YErrorBars.SVG().

dictionary svgfig.Curve.defaults = {}
static

Definition at line 1509 of file svgfig.py.

int svgfig.Curve.discontinuity_limit = 5
static

Definition at line 1513 of file svgfig.py.

Referenced by svgfig.Curve.subsample().

svgfig.Curve.f

Definition at line 1519 of file svgfig.py.

Referenced by svgfig.Curve.__repr__(), svgfig.Ticks.__repr__(), svgfig.CurveAxis.__repr__(), Vispa.Views.RootCanvasView.RootCanvasView.createGraph(), Vispa.Views.RootCanvasView.RootCanvasView.createLegoPlot(), svgfig.Ticks.orient_tickmark(), svgfig.Curve.Path(), svgfig.Curve.sample(), svgfig.Curve.subsample(), and svgfig.LineAxis.SVG().

svgfig.Curve.high

Definition at line 1521 of file svgfig.py.

Referenced by svgfig.Curve.__repr__(), svgfig.Ticks.__repr__(), svgfig.CurveAxis.__repr__(), svgfig.HGrid.__repr__(), svgfig.VGrid.__repr__(), svgfig.Ticks.compute_logminiticks(), svgfig.Ticks.compute_logticks(), svgfig.Ticks.compute_miniticks(), svgfig.Ticks.compute_ticks(), svgfig.Ticks.interpret(), svgfig.Ticks.orient_tickmark(), svgfig.Ticks.regular_miniticks(), and svgfig.Curve.sample().

svgfig.Curve.last_samples

Definition at line 1613 of file svgfig.py.

Referenced by svgfig.Curve.Path().

float svgfig.Curve.linearity_limit = 0.05
static

Definition at line 1512 of file svgfig.py.

Referenced by svgfig.Curve.sample(), and svgfig.Curve.subsample().

svgfig.Curve.loop

Definition at line 1522 of file svgfig.py.

Referenced by svgfig.Poly.__repr__(), svgfig.Curve.Path(), and svgfig.Poly.Path().

svgfig.Curve.low

Definition at line 1520 of file svgfig.py.

Referenced by svgfig.Curve.__repr__(), svgfig.Ticks.__repr__(), svgfig.CurveAxis.__repr__(), svgfig.HGrid.__repr__(), svgfig.VGrid.__repr__(), svgfig.Ticks.compute_logminiticks(), svgfig.Ticks.compute_logticks(), svgfig.Ticks.compute_miniticks(), svgfig.Ticks.compute_ticks(), svgfig.Ticks.interpret(), svgfig.Ticks.orient_tickmark(), svgfig.Ticks.regular_miniticks(), and svgfig.Curve.sample().

svgfig.Curve.random_sampling = True
static

Definition at line 1510 of file svgfig.py.

Referenced by svgfig.Curve.subsample().

int svgfig.Curve.recursion_limit = 15
static

Definition at line 1511 of file svgfig.py.

Referenced by svgfig.Curve.sample(), and svgfig.Curve.subsample().