Page MenuHomeHEPForge

FROG_Element_Primitive_Sphere.h
No OneTemporary

FROG_Element_Primitive_Sphere.h

#ifndef _FROG_ELEMENT_PRIMITIVE_SPHERE_H__
#define _FROG_ELEMENT_PRIMITIVE_SPHERE_H__
#include "FROG_Element_Base.h"
class FROG_Element_Primitive_Sphere : public FROG_Element_Base_With_DetId {
public :
float Radius;
float PosX; float PosY; float PosZ;
unsigned short NPhi; unsigned short NTheta;
FROG_Objects* frogObjects_;
virtual bool isCompactible(){ return true; }
static unsigned int sizeOf(){ return FROG_Element_Base_With_DetId::sizeOf() + 4*sizeof(float) + 2*sizeof(unsigned short);}
FROG_Element_Primitive_Sphere() : FROG_Element_Base_With_DetId(C_PRIMITIVE_SPHERE){}
FROG_Element_Primitive_Sphere(
unsigned int detId, float radius,
float posX, float posY, float posZ,
unsigned short nPhi=10, unsigned short nTheta=5) :
FROG_Element_Base_With_DetId(C_PRIMITIVE_SPHERE,detId),
Radius(radius),
PosX(posX), PosY(posY), PosZ(posZ),
NPhi(nPhi), NTheta(nTheta)
{
size_ = sizeOf();
}
unsigned int read(FILE* pFile, unsigned int toRead=0)
{
unsigned int read = 0;
read += fread(&detId_ ,1,sizeof(detId_) ,pFile);
read += fread(&Radius ,1,sizeof(Radius) ,pFile);
read += fread(&PosX ,1,sizeof(PosX) ,pFile);
read += fread(&PosY ,1,sizeof(PosY) ,pFile);
read += fread(&PosZ ,1,sizeof(PosZ) ,pFile);
read += fread(&NPhi ,1,sizeof(NPhi) ,pFile);
read += fread(&NTheta ,1,sizeof(NTheta) ,pFile);
return read;
}
virtual void write () {
size_ = sizeOf();
data_ = new unsigned char[size_-6];
data_ = FillBuffer( data_, &detId_, sizeof(detId_));
data_ = FillBuffer( data_, &Radius, sizeof(Radius));
data_ = FillBuffer( data_, &PosX, sizeof(PosX));
data_ = FillBuffer( data_, &PosY, sizeof(PosY));
data_ = FillBuffer( data_, &PosZ, sizeof(PosZ));
data_ = FillBuffer( data_, &NPhi, sizeof(NPhi));
data_ = FillBuffer( data_, &NTheta, sizeof(NTheta));
data_ = (unsigned char*)((unsigned long)data_ - (size_-6) );
}
#ifdef FROG_OPENGL
virtual void display(bool UseDisplayList=true, float* color=NULL){
// first Init Colors & Style!
init(NULL);
glLineWidth(style_->thickness_);
if(color){glColor4fv(color);}else{glColor4fv(style_->color_);}
glLoadName( detId_ );
float dphi = 6.283185307f/NPhi;
float dthe = 3.141592653f/NTheta;
glPushMatrix();
glTranslatef(PosX,PosY,PosZ);
glBegin (GL_QUADS);
for(float the=0; the<=2*3.1416-dthe;the+=dthe){
for(float phi=0; phi<=6.2831;phi+=dphi){
glNormal3f ( cos(the)*cos(phi) , cos(the)*sin(phi) , sin(the));
glVertex3f (Radius*cos(the)*cos(phi) ,Radius*cos(the)*sin(phi) ,Radius*sin(the));
glVertex3f (Radius*cos(the+dthe)*cos(phi) ,Radius*cos(the+dthe)*sin(phi) ,Radius*sin(the+dthe));
glVertex3f (Radius*cos(the+dthe)*cos(phi+dphi) ,Radius*cos(the+dthe)*sin(phi+dphi) ,Radius*sin(the+dthe));
glVertex3f (Radius*cos(the)*cos(phi+dphi) ,Radius*cos(the)*sin(phi+dphi) ,Radius*sin(the)); }}
glEnd();
glPopMatrix();
}
#endif
virtual void init(void* frogObjects){
if(frogObjects!=NULL){
frogObjects_ = (FROG_Objects*) frogObjects;
}else if(frogObjects==NULL && frogObjects_ != NULL){
if(mother_ != NULL && mother_->style_ !=NULL){ style_ = new FROG_Objects_Style(mother_->style_);
}else{ style_ = new FROG_Objects_Style(); }
frogObjects_->frogCard_->GetColor( style_->color_ ,"Id_%i_Color" ,detId_);
frogObjects_->frogCard_->GetFloat(&style_->thickness_ ,"Id_%i_Thickness" ,detId_);
}
}
};
#endif

File Metadata

Mime Type
text/x-c++
Expires
Sun, Feb 23, 3:09 PM (58 m, 31 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4486858
Default Alt Text
FROG_Element_Primitive_Sphere.h (3 KB)

Event Timeline