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>
39 SO_NODE_CONSTRUCTOR(
SoCons);
42 SO_NODE_ADD_FIELD(fRmin1, (0.0));
43 SO_NODE_ADD_FIELD(fRmin2, (0.0));
44 SO_NODE_ADD_FIELD(fRmax1, (1.0));
45 SO_NODE_ADD_FIELD(fRmax2, (1.0));
46 SO_NODE_ADD_FIELD(fDz, (10.0));
47 SO_NODE_ADD_FIELD(fSPhi, (0.0));
48 SO_NODE_ADD_FIELD(fDPhi, ((
float)(2*
M_PI)));
49 SO_NODE_ADD_FIELD(smoothDraw, (
TRUE));
50 SO_NODE_ADD_FIELD(pOverrideNPhi, (0));
51 SO_NODE_ADD_FIELD(alternateRep, (NULL));
52 m_children =
new SoChildList(
this);
54 setNodeType(EXTENSION);
65 [[maybe_unused]]
static const bool didInit = [&]() {
66 SO_NODE_INIT_CLASS(
SoCons,SoShape,
"Shape");
78 SoState *state =
action->getState();
84 SbBool useTexFunction=
86 SoTextureCoordinateElement::FUNCTION);
91 const SoTextureCoordinateElement *tce = NULL;
94 tce = SoTextureCoordinateElement::getInstance(state);
99 SbVec3f point, normal;
103 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
104 point.setValue((float)(x),(float)(y),(float)(z)); \
105 normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
106 if (useTexFunction) { \
107 texCoord=tce->get(point,normal); \
109 texCoord[0]=(float)(s); \
110 texCoord[1]=(float)(t); \
112 pv.setPoint(point); \
113 pv.setNormal(normal); \
114 pv.setTextureCoords(texCoord); \
124 double rMax1 =
fRmax1.getValue();
125 double rMin1 =
fRmin1.getValue();
126 double rMax2 =
fRmax2.getValue();
127 double rMin2 =
fRmin2.getValue();
128 double zMax =
fDz.getValue();
132 double cosPhi1 =
cos(phi1);
133 double sinPhi1 =
sin(phi1);
140 double sinPhi=sinPhi0;
141 double cosPhi=cosPhi0;
144 double dR =rMax2-rMax1;
145 double dZ =zMax-zMin;
146 double cosTheta = -dR/sqrt(dR*dR+dZ*dZ);
147 double sinTheta = dZ/sqrt(dR*dR+dZ*dZ);
149 beginShape(
action,TRIANGLE_STRIP);
150 for (
i = 0;
i<=NPHI;
i++) {
151 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta);
152 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta);
153 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
165 double dR =rMin2-rMin1;
166 double dZ =zMax-zMin;
167 double cosTheta = -dR/sqrt(dR*dR+dZ*dZ);
168 double sinTheta = dZ/sqrt(dR*dR+dZ*dZ);
169 beginShape(
action,TRIANGLE_STRIP);
170 for (
i = 0;
i<=NPHI;
i++) {
171 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,-sinTheta*cosPhi,-sinTheta*sinPhi,-cosTheta);
172 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,1.0,1.0,-sinTheta*cosPhi,-sinTheta*sinPhi,-cosTheta);
173 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
181 beginShape(
action,TRIANGLE_STRIP);
184 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);
185 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);
186 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);
187 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);
192 beginShape(
action,TRIANGLE_STRIP);
195 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);
196 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);
197 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);
198 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);
205 beginShape(
action,TRIANGLE_STRIP);
208 for (
i = 0;
i<=NPHI;
i++) {
209 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,0,0,1);
210 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,1.0,1.0,0,0,1);
211 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
217 beginShape(
action,TRIANGLE_STRIP);
220 for (
i = 0;
i<=NPHI;
i++) {
221 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,0.0,0,0,-1);
222 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,0,0,-1);
223 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
227 if (state&&state->isElementEnabled(SoGLCacheContextElement::getClassStackIndex())) {
229 SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DO_AUTO_CACHE);
230 #if ((COIN_MAJOR_VERSION>=3)||((COIN_MAJOR_VERSION==2)&&(COIN_MINOR_VERSION>=5)))
231 SoGLCacheContextElement::incNumShapes(state);
247 -
fDz.getValue(),
fDz.getValue(),
262 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) (
sep->getChild(0));
263 SoNormal *theNormals = (SoNormal *) (
sep->getChild(1));
264 SoNormalBinding *theNormalBinding = (SoNormalBinding *) (
sep->getChild(2));
265 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) (
sep->getChild(3));
267 const int NPHI=96, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
268 float points[NPOINTS][3], normals[NFACES][3];
272 static int32_t
indices[NINDICES];
275 double phi, pp, DeltaPhi;
284 for (
i = 0;
i< NPHI;
i++) {
293 for (
i=0;
i<NPHI;
i++) {
294 indices[5*1*NPHI + 5*
i+0] = 2*NPHI+2 + 2*
i+0;
295 indices[5*1*NPHI + 5*
i+1] = 2*NPHI+2 + 2*
i+1;
296 indices[5*1*NPHI + 5*
i+2] = 2*NPHI+2 + 2*
i+3;
297 indices[5*1*NPHI + 5*
i+3] = 2*NPHI+2 + 2*
i+2;
298 indices[5*1*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
301 for (
i=0;
i<NPHI;
i++) {
304 indices[5*2*NPHI + 5*
i+2] = NPOINTS - (2*
i+4);
305 indices[5*2*NPHI + 5*
i+3] = NPOINTS - (2*
i+2);
306 indices[5*2*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
309 for (
i=0;
i<NPHI;
i++) {
311 indices[5*3*NPHI + 5*
i+1] = NPOINTS - (2*
i+1);
312 indices[5*3*NPHI + 5*
i+2] = NPOINTS - (2*
i+3);
314 indices[5*3*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
318 indices[5*4*NPHI +1] = 2*NPHI+1;
319 indices[5*4*NPHI +2] = 2*NPHI+3;
320 indices[5*4*NPHI +3] = 2*NPHI+2;
321 indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
324 indices[5*4*NPHI +5 +1] = NPOINTS-2;
325 indices[5*4*NPHI +5 +2] = NPOINTS-1;
327 indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
336 for (
i = 0;
i<=NPHI;
i++) {
339 points[2*
i+0][2] = +
fDz.getValue();
342 points[2*
i+1][2] = -
fDz.getValue();
343 pp =
phi+DeltaPhi/2.0;
356 for (
i = 0;
i<=NPHI;
i++) {
359 points[2*NPHI+2+2*
i+0][2] = +
fDz.getValue();
362 points[2*NPHI+2+2*
i+1][2] = -
fDz.getValue();
363 pp =
phi-DeltaPhi/2.0;
365 normals[NPHI+
i][0] = -
ct*
FCOS(pp);
366 normals[NPHI+
i][1] = -
ct*
FSIN(pp);
367 normals[NPHI+
i][2] = st;
372 for (
i=0;
i<NPHI;
i++) {
373 normals[2*NPHI+
i][0]=normals[2*NPHI+
i][1]=0;
374 normals[2*NPHI+
i][2]= 1.0;
377 for (
i=0;
i<NPHI;
i++) {
378 normals[3*NPHI+
i][0]=normals[3*NPHI+
i][1]=0;
379 normals[3*NPHI+
i][2]= -1.0;
383 normals[4*NPHI+0][0]=
FSIN(
phi);
384 normals[4*NPHI+0][1]= -
FCOS(
phi);
385 normals[4*NPHI+0][2]= 0;
389 normals[4*NPHI+1][0]= -
FSIN(
phi);
390 normals[4*NPHI+1][1]= +
FCOS(
phi);
391 normals[4*NPHI+1][2]=0;
393 for (
int np=0;
np<NPOINTS;
np++) theCoordinates->point.set1Value(
np,points[
np][0],points[
np][1],points[
np][2]);
394 theFaceSet->coordIndex.setValues(0,NINDICES,
indices);
398 for (
int nf=0;
nf<NFACES;
nf++) theNormals->vector.set1Value(
nf,normals[
nf][0],normals[
nf][1],normals[
nf][2]);
399 theNormalBinding->value=SoNormalBinding::PER_FACE;
402 for (
int nf=0;
nf<NFACES;
nf++) theNormals->vector.set1Value(
nf,normals[
nf][0],normals[
nf][1],normals[
nf][2]);
403 theNormalBinding->value=SoNormalBinding::PER_FACE;
416 SoSeparator *
sep =
new SoSeparator();
417 SoCoordinate3 *theCoordinates =
new SoCoordinate3();
418 SoNormal *theNormals =
new SoNormal();
419 SoNormalBinding *theNormalBinding =
new SoNormalBinding();
420 SoIndexedFaceSet *theFaceSet =
new SoIndexedFaceSet();
424 sep->addChild(theCoordinates);
425 sep->addChild(theNormals);
426 sep->addChild(theNormalBinding);
427 sep->addChild(theFaceSet);