19 #include <Inventor/SbBox.h>
20 #include <Inventor/actions/SoAction.h>
21 #include <Inventor/misc/SoChildList.h>
22 #include <Inventor/nodes/SoSeparator.h>
23 #include <Inventor/nodes/SoIndexedFaceSet.h>
24 #include <Inventor/nodes/SoNormal.h>
25 #include <Inventor/nodes/SoCoordinate3.h>
26 #include <Inventor/nodes/SoNormalBinding.h>
27 #include <Inventor/SoPrimitiveVertex.h>
28 #include <Inventor/elements/SoTextureCoordinateElement.h>
29 #include <Inventor/elements/SoGLCacheContextElement.h>
37 SO_NODE_CONSTRUCTOR(
SoLAr);
40 SO_NODE_ADD_FIELD(fRmin, (0.0));
41 SO_NODE_ADD_FIELD(fRmax, (0.0));
42 SO_NODE_ADD_FIELD(fDz, (0.0));
43 SO_NODE_ADD_FIELD(fSPhi, (0.0));
44 SO_NODE_ADD_FIELD(fDPhi, ((
float)(2*
M_PI)));
45 SO_NODE_ADD_FIELD(smoothDraw, (
TRUE));
46 SO_NODE_ADD_FIELD(pOverrideNPhi, (0));
47 SO_NODE_ADD_FIELD(alternateRep, (NULL));
48 m_children =
new SoChildList(
this);
50 float rMinDef[]={10.0, 15.0, 10.0};
51 float rMaxDef[]={11.0, 17.0, 12.0};
52 float zDef []={-10.0, 0.0, 10.0};
54 fRmin.setValues(0,2,rMinDef);
55 fRmax.setValues(0,2,rMaxDef);
56 fDz.setValues(0,2,zDef);
57 setNodeType(EXTENSION);
68 [[maybe_unused]]
static const bool didInit = [&]() {
69 SO_NODE_INIT_CLASS(
SoLAr,SoShape,
"Shape");
81 SoState *state =
action->getState();
87 SbBool useTexFunction=
89 SoTextureCoordinateElement::FUNCTION);
94 const SoTextureCoordinateElement *tce = NULL;
97 tce = SoTextureCoordinateElement::getInstance(state);
102 SbVec3f point, normal;
106 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
107 point.setValue((float)(x),(float)(y),(float)(z)); \
108 normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
109 if (useTexFunction) { \
110 texCoord=tce->get(point,normal); \
112 texCoord[0]=(float)(s); \
113 texCoord[1]=(float)(t); \
115 pv.setPoint(point); \
116 pv.setNormal(normal); \
117 pv.setTextureCoords(texCoord); \
126 int nSeg =
fRmin.getNum()-1;
131 for (
int p=0;
p<nSeg;
p++) {
139 double zMin =
fDz[
p];
140 double zMax=
fDz[
p+1];
149 double cosPhi1 =
cos(phi1);
150 double sinPhi1 =
sin(phi1);
163 double dR =rMax2-rMax1;
164 double dZ =zMax-zMin;
165 double cosTheta = -dR/sqrt(dR*dR+dZ*dZ);
166 double sinTheta = dZ/sqrt(dR*dR+dZ*dZ);
168 beginShape(
action,TRIANGLE_STRIP);
171 for (
i = 0;
i<=NPHI;
i++) {
172 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta);
173 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta);
174 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
183 beginShape(
action,TRIANGLE_STRIP);
187 double dR =rMin2-rMin1;
188 double dZ =zMax-zMin;
189 double cosTheta = -dR/sqrt(dR*dR+dZ*dZ);
190 double sinTheta = dZ/sqrt(dR*dR+dZ*dZ);
192 for (
i = 0;
i<=NPHI;
i++) {
193 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,-cosPhi*sinTheta,-sinPhi*sinTheta,-cosTheta);
194 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,1.0,1.0,-cosPhi*sinTheta,-sinPhi*sinTheta,-cosTheta);
195 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
206 beginShape(
action,TRIANGLE_STRIP);
209 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);
210 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);
211 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);
212 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);
217 beginShape(
action,TRIANGLE_STRIP);
220 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);
221 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);
222 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);
223 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);
231 beginShape(
action,TRIANGLE_STRIP);
234 for (
i = 0;
i<=NPHI;
i++) {
235 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,0,0,1);
236 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,1.0,1.0,0,0,1);
237 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
245 beginShape(
action,TRIANGLE_STRIP);
248 for (
i = 0;
i<=NPHI;
i++) {
249 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,0.0,0,0,-1);
250 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,0,0,-1);
251 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
257 if (state&&state->isElementEnabled(SoGLCacheContextElement::getClassStackIndex())) {
259 SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DO_AUTO_CACHE);
260 #if ((COIN_MAJOR_VERSION>=3)||((COIN_MAJOR_VERSION==2)&&(COIN_MINOR_VERSION>=5)))
261 SoGLCacheContextElement::incNumShapes(state);
274 if (
fRmax.getNum()< 2)
return;
275 if (
fRmin.getNum()< 2)
return;
276 if (
fDz.getNum() < 2)
return;
278 double MinMin =
fRmin[0];
279 double MaxMax =
fRmax[0];
281 double ZMin =
fDz[0];
282 double ZMax =
fDz[0];
285 for (
int i=1;
i<
fRmin.getNum();
i++) {
289 for (
int i=1;
i<
fRmax.getNum();
i++) {
293 for (
int i=1;
i<
fDz.getNum();
i++) {
318 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) (
sep->getChild(0));
319 SoNormal *theNormals = (SoNormal *) (
sep->getChild(1));
320 SoNormalBinding *theNormalBinding = (SoNormalBinding *) (
sep->getChild(2));
321 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) (
sep->getChild(3));
323 const int NPHI=96, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
324 float points[NPOINTS][3], normals[NFACES][3];
328 static int32_t
indices[NINDICES];
331 double phi, pp, DeltaPhi;
340 for (
i = 0;
i< NPHI;
i++) {
349 for (
i=0;
i<NPHI;
i++) {
350 indices[5*1*NPHI + 5*
i+0] = 2*NPHI+2 + 2*
i+0;
351 indices[5*1*NPHI + 5*
i+1] = 2*NPHI+2 + 2*
i+1;
352 indices[5*1*NPHI + 5*
i+2] = 2*NPHI+2 + 2*
i+3;
353 indices[5*1*NPHI + 5*
i+3] = 2*NPHI+2 + 2*
i+2;
354 indices[5*1*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
357 for (
i=0;
i<NPHI;
i++) {
360 indices[5*2*NPHI + 5*
i+2] = NPOINTS - (2*
i+4);
361 indices[5*2*NPHI + 5*
i+3] = NPOINTS - (2*
i+2);
362 indices[5*2*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
365 for (
i=0;
i<NPHI;
i++) {
367 indices[5*3*NPHI + 5*
i+1] = NPOINTS - (2*
i+1);
368 indices[5*3*NPHI + 5*
i+2] = NPOINTS - (2*
i+3);
370 indices[5*3*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
374 indices[5*4*NPHI +1] = 2*NPHI+1;
375 indices[5*4*NPHI +2] = 2*NPHI+3;
376 indices[5*4*NPHI +3] = 2*NPHI+2;
377 indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
380 indices[5*4*NPHI +5 +1] = NPOINTS-2;
381 indices[5*4*NPHI +5 +2] = NPOINTS-1;
383 indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
389 t =
FATAN((fRmax2.getValue()-fRmax1.getValue())/(2*
fDz.getValue()));
392 for (
i = 0;
i<=NPHI;
i++) {
399 pp =
phi+DeltaPhi/2.0;
409 t =
FATAN((fRmin2.getValue()-fRmin1.getValue())/(2*
fDz.getValue()));
412 for (
i = 0;
i<=NPHI;
i++) {
419 pp =
phi-DeltaPhi/2.0;
421 normals[NPHI+
i][0] = -
ct*
FCOS(pp);
422 normals[NPHI+
i][1] = -
ct*
FSIN(pp);
423 normals[NPHI+
i][2] = st;
428 for (
i=0;
i<NPHI;
i++) {
429 normals[2*NPHI+
i][0]=normals[2*NPHI+
i][1]=0;
430 normals[2*NPHI+
i][2]= 1.0;
433 for (
i=0;
i<NPHI;
i++) {
434 normals[3*NPHI+
i][0]=normals[3*NPHI+
i][1]=0;
435 normals[3*NPHI+
i][2]= -1.0;
439 normals[4*NPHI+0][0]=
FSIN(
phi);
440 normals[4*NPHI+0][1]= -
FCOS(
phi);
441 normals[4*NPHI+0][2]= 0;
445 normals[4*NPHI+1][0]= -
FSIN(
phi);
446 normals[4*NPHI+1][1]= +
FCOS(
phi);
447 normals[4*NPHI+1][2]=0;
450 theFaceSet->coordIndex.setValues(0,NINDICES,
indices);
454 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
455 theNormalBinding->value=SoNormalBinding::PER_FACE;
458 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
459 theNormalBinding->value=SoNormalBinding::PER_FACE;
476 SoSeparator *
sep =
new SoSeparator();
477 SoCoordinate3 *theCoordinates =
new SoCoordinate3();
478 SoNormal *theNormals =
new SoNormal();
479 SoNormalBinding *theNormalBinding =
new SoNormalBinding();
480 SoIndexedFaceSet *theFaceSet =
new SoIndexedFaceSet();
484 sep->addChild(theCoordinates);
485 sep->addChild(theNormals);
486 sep->addChild(theNormalBinding);
487 sep->addChild(theFaceSet);