Fork me on GitHub

source: svn/trunk/Utilities/FROG/Includes/FROG/FROG_Element_Primitive_Disc.h@ 95

Last change on this file since 95 was 95, checked in by severine ovyn, 16 years ago

first commit frog

File size: 3.6 KB
Line 
1#ifndef _FROG_ELEMENT_PRIMITIVE_DISC_H__
2#define _FROG_ELEMENT_PRIMITIVE_DISC_H__
3
4#include "FROG_Element_Base.h"
5
6class FROG_Element_Primitive_Disc : public FROG_Element_Base_With_DetId {
7public :
8 float Radius;
9 float PosX; float PosY; float PosZ;
10 float DirX; float DirY; float DirZ;
11 unsigned short NPhi;
12 FROG_Objects* frogObjects_;
13
14 virtual bool isCompactible(){ return true; }
15
16 static unsigned int sizeOf(){ return FROG_Element_Base_With_DetId::sizeOf() + 7*sizeof(float) + sizeof(unsigned short); }
17
18 FROG_Element_Primitive_Disc(
19 unsigned int detId, float radius,
20 float posX, float posY, float posZ,
21 float dirX, float dirY, float dirZ,
22 unsigned short nPhi = 10):
23 FROG_Element_Base_With_DetId(C_PRIMITIVE_DISC,detId),
24 Radius(radius),
25 PosX(posX), PosY(posY), PosZ(posZ),
26 DirX(dirX), DirY(dirY), DirZ(dirZ),
27 NPhi(nPhi)
28 {
29 size_ = sizeOf();
30 }
31
32 FROG_Element_Primitive_Disc(FILE* pFile) : FROG_Element_Base_With_DetId(C_PRIMITIVE_DISC)
33 {
34 size_ = sizeOf();
35 fread(&detId_ ,sizeof(detId_) ,1,pFile);
36 fread(&Radius ,sizeof(Radius) ,1,pFile);
37 fread(&PosX ,sizeof(PosX) ,1,pFile);
38 fread(&PosY ,sizeof(PosY) ,1,pFile);
39 fread(&PosZ ,sizeof(PosZ) ,1,pFile);
40 fread(&DirX ,sizeof(DirX) ,1,pFile);
41 fread(&DirY ,sizeof(DirY) ,1,pFile);
42 fread(&DirZ ,sizeof(DirZ) ,1,pFile);
43 fread(&NPhi ,sizeof(NPhi) ,1,pFile);
44 }
45
46 virtual void write () {
47 size_ = sizeOf();
48 data_ = new unsigned char[size_-6];
49 data_ = FillBuffer( data_, &detId_, sizeof(detId_));
50 data_ = FillBuffer( data_, &Radius, sizeof(Radius));
51 data_ = FillBuffer( data_, &PosX, sizeof(PosX));
52 data_ = FillBuffer( data_, &PosY, sizeof(PosY));
53 data_ = FillBuffer( data_, &PosZ, sizeof(PosZ));
54 data_ = FillBuffer( data_, &DirX, sizeof(DirX));
55 data_ = FillBuffer( data_, &DirY, sizeof(DirY));
56 data_ = FillBuffer( data_, &DirZ, sizeof(DirZ));
57 data_ = FillBuffer( data_, &NPhi, sizeof(NPhi));
58 data_ = (unsigned char*)((unsigned long)data_ - (size_-6) );
59 }
60
61 #ifdef FROG_OPENGL
62 virtual void display(bool UseDisplayList=true, float* color=NULL){
63 // first Init Colors & Style!
64 init(NULL);
65
66 glLineWidth(style_->thickness_);
67 if(color){glColor4fv(color);}else{glColor4fv(style_->color_);}
68 glLoadName( detId_ );
69
70 double dphi = 6.283185307179586476925286766559 /NPhi;
71 double D = sqrt(DirX*DirX+DirY*DirY+DirZ*DirZ);
72
73 glPushMatrix();
74 glTranslatef(PosX,PosY,PosZ);
75 glRotatef(57.29*acos(DirX/D),1,0,0);
76 glRotatef(57.29*acos(DirY/D),0,1,0);
77 glRotatef(57.29*acos(DirZ/D),0,0,1);
78 glBegin (GL_TRIANGLES);
79 for(double phi=0; phi<=6.2831;phi+=dphi){
80 glVertex3f (Radius*cos(phi) ,Radius*sin(phi) ,0); // FIRST FACE
81 glVertex3f (Radius*cos(phi+dphi) ,Radius*sin(phi+dphi) ,0);
82 glVertex3f (0 ,0 ,0);
83
84 glVertex3f (Radius*cos(phi+dphi) ,Radius*sin(phi+dphi) ,0); // SECOND FACE
85 glVertex3f (Radius*cos(phi) ,Radius*sin(phi) ,0);
86 glVertex3f (0 ,0 ,0);
87 }
88 glEnd();
89 glPopMatrix();
90 }
91 #endif
92
93 virtual void init(void* frogObjects){
94 if(frogObjects!=NULL){
95 frogObjects_ = (FROG_Objects*) frogObjects;
96 }else if(frogObjects==NULL && frogObjects_ != NULL){
97 if(mother_ != NULL && mother_->style_ !=NULL){ style_ = new FROG_Objects_Style(mother_->style_);
98 }else{ style_ = new FROG_Objects_Style(); }
99
100 frogObjects_->frogCard_->GetColor( style_->color_ ,"Id_%i_Color" ,detId_);
101 frogObjects_->frogCard_->GetFloat(&style_->thickness_ ,"Id_%i_Thickness" ,detId_);
102 }
103 }
104};
105#endif
Note: See TracBrowser for help on using the repository browser.