37 #ifdef G4VIS_BUILD_OI_DRIVER
44 #include <Inventor/SbBox.h>
45 #include <Inventor/actions/SoAction.h>
46 #include <Inventor/fields/SoSFFloat.h>
47 #include <Inventor/misc/SoChildList.h>
48 #include <Inventor/nodes/SoSeparator.h>
49 #include <Inventor/nodes/SoIndexedFaceSet.h>
50 #include <Inventor/nodes/SoNormal.h>
51 #include <Inventor/nodes/SoCoordinate3.h>
52 #include <Inventor/nodes/SoNormalBinding.h>
53 #include <Inventor/SoPrimitiveVertex.h>
54 #include <Inventor/elements/SoTextureCoordinateElement.h>
64 SO_NODE_CONSTRUCTOR(SoCons);
67 SO_NODE_ADD_FIELD(fRmin1, (0.0));
68 SO_NODE_ADD_FIELD(fRmin2, (0.0));
69 SO_NODE_ADD_FIELD(fRmax1, (1.0));
70 SO_NODE_ADD_FIELD(fRmax2, (1.0));
71 SO_NODE_ADD_FIELD(fDz, (10.0));
72 SO_NODE_ADD_FIELD(fSPhi, (0.0));
73 SO_NODE_ADD_FIELD(fDPhi, ((
float)(2*
M_PI)));
74 SO_NODE_ADD_FIELD(smoothDraw, (
TRUE));
75 SO_NODE_ADD_FIELD(alternateRep, (NULL));
76 children =
new SoChildList(
this);
88 SO_NODE_INIT_CLASS(SoCons,SoShape,
"Shape");
98 SoState *state = action->getState();
102 SbBool useTexFunction=
103 (SoTextureCoordinateElement::getType(state) ==
104 SoTextureCoordinateElement::FUNCTION);
109 const SoTextureCoordinateElement *tce = NULL;
111 if (useTexFunction) {
112 tce = SoTextureCoordinateElement::getInstance(state);
121 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
122 point.setValue((float)(x),(float)(y),(float)(z)); \
123 normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
124 if (useTexFunction) { \
125 texCoord=tce->get(point,normal); \
127 texCoord[0]=(float)(s); \
128 texCoord[1]=(float)(t); \
130 pv.setPoint(point); \
131 pv.setNormal(normal); \
132 pv.setTextureCoords(texCoord); \
138 int NPHI = (
int)(2+22*std::fabs(
fDPhi.getValue()/(2.0*
M_PI)));
139 double deltaPhi =
fDPhi.getValue()/NPHI;
140 double phi0 =
fSPhi.getValue();
141 double phi1 = phi0 +
fDPhi.getValue();
142 double rMax1 =
fRmax1.getValue();
143 double rMin1 =
fRmin1.getValue();
144 double rMax2 =
fRmax2.getValue();
145 double rMin2 =
fRmin2.getValue();
146 double zMax =
fDz.getValue();
148 double cosPhi0 = std::cos(phi0);
149 double sinPhi0 = std::sin(phi0);
150 double cosPhi1 = std::cos(phi1);
151 double sinPhi1 = std::sin(phi1);
152 double cosDeltaPhi = std::cos(deltaPhi);
153 double sinDeltaPhi = std::sin(deltaPhi);
157 beginShape(action,TRIANGLE_STRIP);
159 double sinPhi=sinPhi0;
160 double cosPhi=cosPhi0;
161 for (i = 0; i<=NPHI; i++) {
162 GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,cosPhi,sinPhi,0);
163 GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,cosPhi,sinPhi,0);
164 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
170 beginShape(action,TRIANGLE_STRIP);
173 for (i = 0; i<=NPHI; i++) {
174 GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,-cosPhi,-sinPhi,0);
175 GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi,zMin,1.0,1.0,-cosPhi,-sinPhi,0);
176 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
179 if (std::fabs(deltaPhi)<2.0*
M_PI) {
183 beginShape(action,TRIANGLE_STRIP);
186 GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);
187 GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);
188 GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);
189 GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);
194 beginShape(action,TRIANGLE_STRIP);
197 GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);
198 GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);
199 GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);
200 GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);
207 beginShape(action,TRIANGLE_STRIP);
210 for (i = 0; i<=NPHI; i++) {
211 GEN_VERTEX(pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,0,0,1);
212 GEN_VERTEX(pv,rMax2*cosPhi,rMax2*sinPhi,zMax,1.0,1.0,0,0,1);
213 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
219 beginShape(action,TRIANGLE_STRIP);
222 for (i = 0; i<=NPHI; i++) {
223 GEN_VERTEX(pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,0.0,0,0,-1);
224 GEN_VERTEX(pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,0,0,-1);
225 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
239 float fRmax=
fRmax1.getValue();
240 if (
fRmax2.getValue() > fRmax) fRmax =
fRmax2.getValue();
242 SbVec3f vmin(-fRmax,-fRmax,-
fDz.getValue()),
243 vmax( fRmax, fRmax,
fDz.getValue());
244 center.setValue(0,0,0);
245 box.setBounds(vmin,vmax);
258 SoSeparator *sep = (SoSeparator *) ( *
children)[0];
259 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) ( sep->getChild(0));
260 SoNormal *theNormals = (SoNormal *) ( sep->getChild(1));
261 SoNormalBinding *theNormalBinding = (SoNormalBinding *) ( sep->getChild(2));
262 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) ( sep->getChild(3));
264 const int NPHI=24, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
265 float points[NPOINTS][3], normals[NFACES][3];
267 static long indices[NINDICES];
269 static int32_t indices[NINDICES];
272 double phi,
pp, DeltaPhi;
281 for (i = 0; i< NPHI; i++) {
283 indices[5*i+0] = 2*i+0;
284 indices[5*i+1] = 2*i+1;
285 indices[5*i+2] = 2*i+3;
286 indices[5*i+3] = 2*i+2;
287 indices[5*i+4] = SO_END_FACE_INDEX;
290 for (i=0;i<NPHI;i++) {
291 indices[5*1*NPHI + 5*i+0] = 2*NPHI+2 + 2*i+0;
292 indices[5*1*NPHI + 5*i+1] = 2*NPHI+2 + 2*i+1;
293 indices[5*1*NPHI + 5*i+2] = 2*NPHI+2 + 2*i+3;
294 indices[5*1*NPHI + 5*i+3] = 2*NPHI+2 + 2*i+2;
295 indices[5*1*NPHI + 5*i+4] = SO_END_FACE_INDEX;
298 for (i=0;i<NPHI;i++) {
299 indices[5*2*NPHI + 5*i+0] = 2*i+0;
300 indices[5*2*NPHI + 5*i+1] = 2*i+2;
301 indices[5*2*NPHI + 5*i+2] = NPOINTS - (2*i+4);
302 indices[5*2*NPHI + 5*i+3] = NPOINTS - (2*i+2);
303 indices[5*2*NPHI + 5*i+4] = SO_END_FACE_INDEX;
306 for (i=0;i<NPHI;i++) {
307 indices[5*3*NPHI + 5*i+0] = 2*i+1;
308 indices[5*3*NPHI + 5*i+1] = NPOINTS - (2*i+1);
309 indices[5*3*NPHI + 5*i+2] = NPOINTS - (2*i+3);
310 indices[5*3*NPHI + 5*i+3] = 2*i+3;
311 indices[5*3*NPHI + 5*i+4] = SO_END_FACE_INDEX;
314 indices[5*4*NPHI +0] = 2*NPHI;
315 indices[5*4*NPHI +1] = 2*NPHI+1;
316 indices[5*4*NPHI +2] = 2*NPHI+3;
317 indices[5*4*NPHI +3] = 2*NPHI+2;
318 indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
320 indices[5*4*NPHI +5 +0] = 0;
321 indices[5*4*NPHI +5 +1] = NPOINTS-2;
322 indices[5*4*NPHI +5 +2] = NPOINTS-1;
323 indices[5*4*NPHI +5 +3] = 1;
324 indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
328 DeltaPhi =
fDPhi.getValue()/NPHI, phi =
fSPhi.getValue();
333 for (i = 0; i<=NPHI; i++) {
334 points[2*i+0][0] =
fRmax2.getValue()*
FCOS(phi);
335 points[2*i+0][1] =
fRmax2.getValue()*
FSIN(phi);
336 points[2*i+0][2] = +
fDz.getValue();
337 points[2*i+1][0] =
fRmax1.getValue()*
FCOS(phi);
338 points[2*i+1][1] =
fRmax1.getValue()*
FSIN(phi);
339 points[2*i+1][2] = -
fDz.getValue();
340 pp = phi+DeltaPhi/2.0;
342 normals[i][0] = ct *
FCOS(pp);
343 normals[i][1] = ct *
FSIN(pp);
353 for (i = 0; i<=NPHI; i++) {
354 points[2*NPHI+2+2*i+0][0] =
fRmin2.getValue()*
FCOS(phi);
355 points[2*NPHI+2+2*i+0][1] =
fRmin2.getValue()*
FSIN(phi);
356 points[2*NPHI+2+2*i+0][2] = +
fDz.getValue();
357 points[2*NPHI+2+2*i+1][0] =
fRmin1.getValue()*
FCOS(phi);
358 points[2*NPHI+2+2*i+1][1] =
fRmin1.getValue()*
FSIN(phi);
359 points[2*NPHI+2+2*i+1][2] = -
fDz.getValue();
360 pp = phi-DeltaPhi/2.0;
362 normals[NPHI+i][0] = -ct*
FCOS(pp);
363 normals[NPHI+i][1] = -ct*
FSIN(pp);
364 normals[NPHI+i][2] = st;
369 for (i=0;i<NPHI;i++) {
370 normals[2*NPHI+i][0]=normals[2*NPHI+i][1]=0;
371 normals[2*NPHI+i][2]= 1.0;
374 for (i=0;i<NPHI;i++) {
375 normals[3*NPHI+i][0]=normals[3*NPHI+i][1]=0;
376 normals[3*NPHI+i][2]= -1.0;
379 phi =
fSPhi.getValue();
380 normals[4*NPHI+0][0]=
FSIN(phi);
381 normals[4*NPHI+0][1]= -
FCOS(phi);
382 normals[4*NPHI+0][2]= 0;
386 normals[4*NPHI+1][0]= -
FSIN(phi);
387 normals[4*NPHI+1][1]= +
FCOS(phi);
388 normals[4*NPHI+1][2]=0;
390 for (
int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
391 theFaceSet->coordIndex.setValues(0,NINDICES,indices);
395 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
396 theNormalBinding->value=SoNormalBinding::PER_FACE;
399 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
400 theNormalBinding->value=SoNormalBinding::PER_FACE;
413 SoSeparator *sep =
new SoSeparator();
414 SoCoordinate3 *theCoordinates =
new SoCoordinate3();
415 SoNormal *theNormals =
new SoNormal();
416 SoNormalBinding *theNormalBinding =
new SoNormalBinding();
417 SoIndexedFaceSet *theFaceSet =
new SoIndexedFaceSet();
421 sep->addChild(theCoordinates);
422 sep->addChild(theNormals);
423 sep->addChild(theNormalBinding);
424 sep->addChild(theFaceSet);