CEDRIC  Revision_backup-2009-02
PhastNode.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2008 Boris Iven, Max Hermann
4  *
5  * This file is part of the "CEDRIC Event Display" application.
6  *
7  *****************************************************************************/
8 
9 #ifndef PHASTNODE_H
10 #define PHASTNODE_H
11 
12 #include <Phast.h>
13 
14 #include <osg/ref_ptr>
15 #include <osg/Geode>
16 #include <osg/Drawable>
17 #include <osgText/Text>
18 #include <osg/Vec3>
19 
20 #include <iostream>
21 #include <string>
22 
23 #include "TypedTransform.h"
24 #include "Selectable.h"
25 
26 
32 class PhastNode : public TypedTransform, public Selectable
33 {
34 public:
38  enum Type { GROUP=1, DETECTOR=2, CALORIMETER=4, RICH=8, TRACK=16, MAGNET=32, TARGET=64,
39  CLUSTER=128 };
40 
43  struct Magnet
44  {
45  Magnet( const PaMagInfo& magInfo, const std::string& name_, const std::string& model_ )
46  : name(name_), model(model_)
47  {
48  x = magInfo.xcm *.1;
49  y = magInfo.ycm *.1;
50  z = magInfo.zcm *.1;
51  }
52 
53  std::string name;
54  std::string model;
55  double x,y,z;
56  };
57 
58  struct Target
59  {
60  Target( const PaSetup& setup, const int ncells_, const std::vector<float>& polarization_)
61  : ncells(ncells_), polarization(polarization_)
62  {
63  name = "Target";
64  x = 0;
65  y = 0;
66  z = setup.TargetCenterZ();
67  if( z == -35.0 ) cout << "WARNING: Possibly target z position is not stored in mDST and default of -35cm is used." << endl;
68  }
69  std::string name;
70  int ncells;
71  double x,y,z;
72  vector<float> polarization;
73  };
75 
77  PhastNode();
79  PhastNode( const PaDetect& det , osg::Vec4 color=osg::Vec4(1.f,1.f,1.f,1.f) );
81  PhastNode( const PaCalorimeter& cal , osg::Vec4 color=osg::Vec4(1.f,1.f,1.f,1.f) );
83  PhastNode( const PaRich& rich , osg::Vec4 color=osg::Vec4(1.f,1.f,1.f,1.f) );
84 
86  PhastNode( const PaTrack& track, osg::Vec4 color=osg::Vec4(1.f,1.f,1.f,1.f) );
88  PhastNode( const PaCaloClus& cluster );
89 
92  PhastNode( const Magnet& magnet, osg::Vec4 color=osg::Vec4(1.f,1.f,1.f,1.f) );
93  PhastNode( const Target& target, osg::Vec4 color=osg::Vec4(1.f,1.f,1.f,1.f) );
95 
98  bool isSetupEntity() { return m_type & DETECTOR || m_type & CALORIMETER || m_type & RICH || m_type & MAGNET || m_type & TARGET; }
99  bool isEventEntity() { return m_type & TRACK || m_type & CLUSTER; }
100 
101  bool isGroup() { return m_type & GROUP; }
102  bool isDetector() { return m_type & DETECTOR; }
103  bool isCalorimeter() { return m_type & CALORIMETER; }
104  bool isRich() { return m_type & RICH; }
105 
106  bool isTrack() { return m_type & TRACK; }
107  bool isCluster() { return m_type & CLUSTER; }
108 
109  bool isMagnet() { return m_type & MAGNET; }
110  bool isTarget() { return m_type & TARGET; }
112 
114  std::string getName() const { return m_name; }
115 
117  int getUID() const { return m_uid; }
118 
120  void setColor( osg::Vec3 color );
122  void setAlpha( float alpha );
124  void setVisible( bool visible );
125 
126  void highlight( bool highlighted );
127 
130  virtual bool onHighlight( bool highlight );
131  virtual bool onSelect( bool select );
132  virtual const std::string& toolTip( osg::Node* /*node*/ );
134 
138  virtual bool isPickable( osg::Node* node ) { return node != _shadow.get(); }
140 
141 protected:
142  osg::Geode* createHighlightBox( osg::BoundingBox bbox );
143 
144  osg::Node* createWireframe( osg::Node* node );
145 
147  osg::Node* createShadow( osg::Node* /*node*/ ) { return new osg::Node; }
149  void createSimplifiedGeometry( osg::Vec4 /*color*/ ) {}
150 
152  void init( int type, const std::string& name );
154  void assemble();
155 
156 private:
157  osg::ref_ptr<osg::Switch> _switch;
158 
159  osg::ref_ptr<osg::Node> _solid;
160  osg::ref_ptr<osg::Node> _outlines;
161  osg::ref_ptr<osg::Node> _shadow;
162 
163  osg::ref_ptr<osg::Node> _highlight;
164 
165  int m_uid;
166  static int s_nextUID;
167  static int createUID() { return s_nextUID++; }
168 
169  std::string m_name;
170 };
171 
172 #endif
virtual bool isPickable(osg::Node *node)
Definition: PhastNode.h:138
std::string getName() const
Return name (matches Phast object's name if node corresponds to a Phast object)
Definition: PhastNode.h:114
Magnet(const PaMagInfo &magInfo, const std::string &name_, const std::string &model_)
Definition: PhastNode.h:45
bool isCluster()
Definition: PhastNode.h:107
Type
Definition: PhastNode.h:38
Definition: Selectable.h:15
void assemble()
Assemble switch node with geometry nodes (last call in constructor)
Definition: PhastNode.cpp:57
osg::Node * createWireframe(osg::Node *node)
Definition: PhastNode.cpp:534
void setAlpha(float alpha)
Change alpha value of this node and all its children.
Definition: PhastNode.cpp:570
Definition: PhastNode.h:38
void init(int type, const std::string &name)
Setup uid, type and name (first call in constructor)
Definition: PhastNode.cpp:47
std::string name
Definition: PhastNode.h:53
int ncells
Definition: PhastNode.h:70
int getUID() const
Return unique PhastNode index (e.g. usefull for mapping a PhastNode to a QTreeWidget item) ...
Definition: PhastNode.h:117
bool isSetupEntity()
Definition: PhastNode.h:98
osg::Node * createShadow(osg::Node *)
Definition: PhastNode.h:147
bool isRich()
Definition: PhastNode.h:104
double x
Definition: PhastNode.h:71
Definition: PhastNode.h:38
vector< float > polarization
Definition: PhastNode.h:72
double z
Definition: PhastNode.h:55
void highlight(bool highlighted)
Definition: PhastNode.cpp:604
bool isTrack()
Definition: PhastNode.h:106
Definition: PhastNode.h:43
Definition: PhastNode.h:38
virtual const std::string & toolTip(osg::Node *)
Definition: PhastNode.cpp:636
Graphical representation of Phast objects (e.g. PaDetector, PaTrack, ...) as OpenSceneGraph node...
Definition: PhastNode.h:32
double y
Definition: PhastNode.h:71
virtual bool onHighlight(bool highlight)
Definition: PhastNode.cpp:626
Definition: TypedTransform.h:26
Definition: PhastNode.h:38
Definition: PhastNode.h:38
bool isEventEntity()
Definition: PhastNode.h:99
bool isCalorimeter()
Definition: PhastNode.h:103
void createSimplifiedGeometry(osg::Vec4)
Definition: PhastNode.h:149
virtual bool onSelect(bool select)
Definition: PhastNode.cpp:617
Definition: PhastNode.h:38
bool isGroup()
Definition: PhastNode.h:101
Target(const PaSetup &setup, const int ncells_, const std::vector< float > &polarization_)
Definition: PhastNode.h:60
Definition: PhastNode.h:39
PhastNode()
Constructor for a GROUP node.
Definition: PhastNode.cpp:70
void setColor(osg::Vec3 color)
Change color of this node and all its children.
Definition: PhastNode.cpp:549
bool isTarget()
Definition: PhastNode.h:110
Definition: PhastNode.h:58
bool isDetector()
Definition: PhastNode.h:102
void setVisible(bool visible)
Change visibility of this node and its subtree.
Definition: PhastNode.cpp:589
std::string name
Definition: PhastNode.h:69
osg::Geode * createHighlightBox(osg::BoundingBox bbox)
Definition: PhastNode.cpp:524
int m_type
Definition: TypedTransform.h:105
bool isMagnet()
Definition: PhastNode.h:109
Definition: PhastNode.h:38
std::string model
Definition: PhastNode.h:54
double y
Definition: PhastNode.h:55
double z
Definition: PhastNode.h:71
double x
Definition: PhastNode.h:55