Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F10882106
FROG_Element_Primitive_PartialSphere.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Subscribers
None
FROG_Element_Primitive_PartialSphere.h
View Options
#ifndef _FROG_ELEMENT_PRIMITIVE_PARTIALSPHERE_H__
#define _FROG_ELEMENT_PRIMITIVE_PARTIALSPHERE_H__
#include
"FROG_Element_Base.h"
class
FROG_Element_Primitive_PartialSphere
:
public
FROG_Element_Base_With_DetId
{
public
:
float
Radius
;
float
PosX
;
float
PosY
;
float
PosZ
;
float
Phi1
;
float
Phi2
;
float
Theta1
;
float
Theta2
;
unsigned
short
NPhi
;
unsigned
short
NTheta
;
float
ROT
;
virtual
bool
isCompactible
(){
return
true
;
}
static
unsigned
int
sizeOf
(){
return
FROG_Element_Base_With_DetId
::
sizeOf
()
+
9
*
sizeof
(
float
)
+
2
*
sizeof
(
unsigned
short
);}
FROG_Element_Primitive_PartialSphere
()
:
FROG_Element_Base_With_DetId
(
C_PRIMITIVE_PARTIALSPHERE
){}
FROG_Element_Primitive_PartialSphere
(
unsigned
int
detId
,
float
radius
,
float
posX
,
float
posY
,
float
posZ
,
float
phi1
,
float
phi2
,
float
theta1
,
float
theta2
,
unsigned
short
nPhi
=
10
,
unsigned
short
nTheta
=
5
,
float
rot
=
0
)
:
FROG_Element_Base_With_DetId
(
C_PRIMITIVE_PARTIALSPHERE
,
detId
),
Radius
(
radius
),
PosX
(
posX
),
PosY
(
posY
),
PosZ
(
posZ
),
Phi1
(
phi1
),
Phi2
(
phi2
),
Theta1
(
theta1
),
Theta2
(
theta2
),
NPhi
(
nPhi
),
NTheta
(
nTheta
),
ROT
(
rot
)
{
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
(
&
Phi1
,
1
,
sizeof
(
Phi1
)
,
pFile
);
read
+=
fread
(
&
Phi2
,
1
,
sizeof
(
Phi2
)
,
pFile
);
read
+=
fread
(
&
Theta1
,
1
,
sizeof
(
Theta1
)
,
pFile
);
read
+=
fread
(
&
Theta2
,
1
,
sizeof
(
Theta2
)
,
pFile
);
read
+=
fread
(
&
NPhi
,
1
,
sizeof
(
NPhi
)
,
pFile
);
read
+=
fread
(
&
NTheta
,
1
,
sizeof
(
NTheta
)
,
pFile
);
read
+=
fread
(
&
ROT
,
1
,
sizeof
(
ROT
)
,
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_
,
&
Phi1
,
sizeof
(
Phi1
));
data_
=
FillBuffer
(
data_
,
&
Phi2
,
sizeof
(
Phi2
));
data_
=
FillBuffer
(
data_
,
&
Theta1
,
sizeof
(
Theta1
));
data_
=
FillBuffer
(
data_
,
&
Theta2
,
sizeof
(
Theta2
));
data_
=
FillBuffer
(
data_
,
&
NPhi
,
sizeof
(
NPhi
));
data_
=
FillBuffer
(
data_
,
&
NTheta
,
sizeof
(
NTheta
));
data_
=
FillBuffer
(
data_
,
&
ROT
,
sizeof
(
ROT
));
data_
=
(
unsigned
char
*
)((
unsigned
long
)
data_
-
(
size_
-
6
)
);
}
#ifdef FROG_OPENGL
void
Object_SmartDisplay
(){
GLfloat
*
positionData
=
NULL
;
GLfloat
*
normalData
=
NULL
;
if
(
DisplayList_
){
glCallList
(
DisplayList_
);
return
;
}
if
(
!
VBO_Vertices_
){
VBO_VerticesN_
=
(
4
+
4
)
*
NPhi
*
NTheta
;
positionData
=
new
GLfloat
[
3
*
VBO_VerticesN_
];
normalData
=
new
GLfloat
[
3
*
VBO_VerticesN_
];
unsigned
int
Index
=
0
;
float
dphi
=
6.283185307f
/
NPhi
;
float
dthe
=
3.141592653f
/
NTheta
;
for
(
float
the
=
Theta1
;
the
<=
Theta2
-
dthe
;
the
+=
dthe
){
for
(
float
phi
=
Phi1
;
phi
<=
Phi2
-
dphi
;
phi
+=
dphi
){
positionData
[
Index
+
0
]
=
Radius
*
cos
(
the
)
*
cos
(
phi
);
positionData
[
Index
+
1
]
=
Radius
*
cos
(
the
)
*
sin
(
phi
);
positionData
[
Index
+
2
]
=
Radius
*
sin
(
the
);
positionData
[
Index
+
3
]
=
Radius
*
cos
(
the
)
*
cos
(
phi
+
dphi
);
positionData
[
Index
+
4
]
=
Radius
*
cos
(
the
)
*
sin
(
phi
+
dphi
);
positionData
[
Index
+
5
]
=
Radius
*
sin
(
the
);
positionData
[
Index
+
6
]
=
Radius
*
cos
(
the
+
dthe
)
*
cos
(
phi
+
dphi
);
positionData
[
Index
+
7
]
=
Radius
*
cos
(
the
+
dthe
)
*
sin
(
phi
+
dphi
);
positionData
[
Index
+
8
]
=
Radius
*
sin
(
the
+
dthe
);
positionData
[
Index
+
9
]
=
Radius
*
cos
(
the
+
dthe
)
*
cos
(
phi
);
positionData
[
Index
+
10
]
=
Radius
*
cos
(
the
+
dthe
)
*
sin
(
phi
);
positionData
[
Index
+
11
]
=
Radius
*
sin
(
the
+
dthe
);
positionData
[
Index
+
12
]
=
Radius
*
cos
(
the
)
*
cos
(
phi
);
positionData
[
Index
+
13
]
=
Radius
*
cos
(
the
)
*
sin
(
phi
);
positionData
[
Index
+
14
]
=
Radius
*
sin
(
the
);
positionData
[
Index
+
15
]
=
Radius
*
cos
(
the
+
dthe
)
*
cos
(
phi
);
positionData
[
Index
+
16
]
=
Radius
*
cos
(
the
+
dthe
)
*
sin
(
phi
);
positionData
[
Index
+
17
]
=
Radius
*
sin
(
the
+
dthe
);
positionData
[
Index
+
18
]
=
Radius
*
cos
(
the
+
dthe
)
*
cos
(
phi
+
dphi
);
positionData
[
Index
+
19
]
=
Radius
*
cos
(
the
+
dthe
)
*
sin
(
phi
+
dphi
);
positionData
[
Index
+
20
]
=
Radius
*
sin
(
the
+
dthe
);
positionData
[
Index
+
21
]
=
Radius
*
cos
(
the
)
*
cos
(
phi
+
dphi
);
positionData
[
Index
+
22
]
=
Radius
*
cos
(
the
)
*
sin
(
phi
+
dphi
);
positionData
[
Index
+
23
]
=
Radius
*
sin
(
the
);
Index
+=
24
;
}}
glPushMatrix
();
glLoadIdentity
();
glTranslatef
(
PosX
,
PosY
,
PosZ
);
glRotatef
(
ROT
,
0
,
1
,
0
);
TransformVerticesArray
(
positionData
,
VBO_VerticesN_
);
glPopMatrix
();
//Compute Cloud Vertice BaryCenter
GetVerticesArrayBarycenter
(
positionData
,
VBO_VerticesN_
,
obj_pos_x
,
obj_pos_y
,
obj_pos_z
);
//COmpute Normals
SetNormalArray
(
positionData
,
normalData
,
0
,
(
4
+
4
)
*
NPhi
*
NTheta
,
4
);
if
(
FROG
::
Support_VBO_
){
//Use VBO
glGenBuffersARB
(
1
,
&
VBO_Vertices_
);
// Get A Valid Name
glBindBufferARB
(
GL_ARRAY_BUFFER_ARB
,
VBO_Vertices_
);
// Bind The Buffer
glBufferDataARB
(
GL_ARRAY_BUFFER_ARB
,
3
*
VBO_VerticesN_
*
sizeof
(
float
),
positionData
,
GL_STATIC_DRAW_ARB
);
glGenBuffersARB
(
1
,
&
VBO_Normals_
);
// Get A Valid Name
glBindBufferARB
(
GL_ARRAY_BUFFER_ARB
,
VBO_Normals_
);
// Bind The Buffer
glBufferDataARB
(
GL_ARRAY_BUFFER_ARB
,
3
*
VBO_VerticesN_
*
sizeof
(
float
),
normalData
,
GL_STATIC_DRAW_ARB
);
delete
[]
normalData
;
delete
[]
positionData
;
}
}
if
(
!
FROG
::
Support_VBO_
){
//VBO not Available --> Use DisplayList
DisplayList_
=
glGenListsOptimized
(
1
);
glNewList
(
DisplayList_
,
GL_COMPILE_AND_EXECUTE
);
}
glEnableClientState
(
GL_VERTEX_ARRAY
);
glEnableClientState
(
GL_NORMAL_ARRAY
);
if
(
FROG
::
Support_VBO_
){
//Use VBO
glBindBufferARB
(
GL_ARRAY_BUFFER_ARB
,
VBO_Normals_
);
glNormalPointer
(
GL_FLOAT
,
0
,
(
char
*
)
NULL
);
glBindBufferARB
(
GL_ARRAY_BUFFER_ARB
,
VBO_Vertices_
);
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
(
char
*
)
NULL
);
}
else
{
//VBO not Available --> Use DisplayList
glNormalPointer
(
GL_FLOAT
,
0
,
normalData
);
glVertexPointer
(
3
,
GL_FLOAT
,
0
,
positionData
);
}
glDrawArrays
(
GL_QUADS
,
0
,
(
4
+
4
)
*
NPhi
*
NTheta
);
glDisableClientState
(
GL_NORMAL_ARRAY
);
glDisableClientState
(
GL_VERTEX_ARRAY
);
if
(
!
FROG
::
Support_VBO_
){
glEndList
();
delete
[]
normalData
;
delete
[]
positionData
;
}
}
virtual
void
display
(
bool
UseDisplayList
=
true
,
float
*
color
=
NULL
){
if
(
!
style_
)
init
();
glLoadName
(
detId_
);
if
(
color
){
glColor4fv
(
color
);}
else
{
glColor4fv
(
style_
->
color_
);}
glPushAttrib
(
GL_LINE_BIT
);
glLineWidth
(
style_
->
thickness_
);
Object_SmartDisplay
();
glPopAttrib
();
}
#endif
virtual
void
init
(){
if
(
style_
)
return
;
init_standard
();
//Decide if this objects has to be render now or later
if
(
NeedPostRendering
())
return
;
((
FROG_ReadCards
*
)
FROG
::
Card_
)
->
GetColor
(
style_
->
color_
,
"Id_%i_Color"
,
detId_
);
((
FROG_ReadCards
*
)
FROG
::
Card_
)
->
GetFloat
(
&
style_
->
thickness_
,
"Id_%i_Thickness"
,
detId_
);
}
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, May 3, 7:05 AM (6 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4983280
Default Alt Text
FROG_Element_Primitive_PartialSphere.h (7 KB)
Attached To
rFROGSVN frogsvn
Event Timeline
Log In to Comment