Package mbdyn :: Package interface :: Module mapper
[hide private]

Source Code for Module mbdyn.interface.mapper

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  # This file is part of MBDyn sim suite. 
 5  # Copyright (C) 2007 André ESPAZE, as part of a Master thesis supervised by 
 6  # Martin O.L.Hansen (DTU) and Nicolas Chauvat (Logilab) 
 7   
 8  # MBDyn sim suite is free software; you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation; either version 2 of the License, or 
11  # (at your option) any later version. 
12  # 
13  # This program is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU General Public License 
19  # along with this program; if not, write to the Free Software 
20  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
21  # 
22  """The VTK mapper description for nodes and elements. 
23  Until now only the nodes are described as sphere. 
24  Then the L{MAPPER_CLASS} dictionary gathers  
25  the available mappers for every class. A module still 
26  in heavy development.""" 
27  import vtk 
28   
29 -class Common:
30 """The common class for a mapper""" 31
32 - def __init__(self):
33 self.mapper = vtk.vtkPolyDataMapper()
34 35 NODE_CLASS = {} 36 NODE_CLASS["STRUCTURAL"] = {} 37 38
39 -class Node(Common):
40 """The node class mapper, a VTK sphere.""" 41
42 - def __init__(self):
43 Common.__init__(self) 44 self.sphere = vtk.vtkSphereSource() 45 self.mapper.SetInput(self.sphere.GetOutput()) 46 self.radius = 3. 47 self.set_radius(self.radius)
48
49 - def set_radius(self, value):
50 """Set the mapper radius""" 51 self.sphere.SetRadius(value)
52
53 - def set_scale_factor(self, scale_factor):
54 """Set the scale factor for the representation, 55 recalculate the radius""" 56 self.set_radius(scale_factor * self.radius)
57 58 NODE_CLASS["STRUCTURAL"]["general"] = Node 59
60 -class StructuralNode(Node):
61 """The structural node mapper""" 62 pass
63 64 NODE_CLASS["STRUCTURAL"]["structural"] = StructuralNode 65 66 MAPPER_CLASS = {} 67 MAPPER_CLASS["NODE"] = NODE_CLASS 68