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 = std::make_unique<SoChildList>(
this);
54 setNodeType(EXTENSION);
61 [[maybe_unused]]
static const bool didInit = [&]() {
62 SO_NODE_INIT_CLASS(
SoCons,SoShape,
"Shape");
74 SoState *state =
action->getState();
80 SbBool useTexFunction=
82 SoTextureCoordinateElement::FUNCTION);
87 const SoTextureCoordinateElement *tce = NULL;
90 tce = SoTextureCoordinateElement::getInstance(state);
95 SbVec3f point, normal;
99 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
100 point.setValue((float)(x),(float)(y),(float)(z)); \
101 normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
102 if (useTexFunction) { \
103 texCoord=tce->get(point,normal); \
105 texCoord[0]=(float)(s); \
106 texCoord[1]=(float)(t); \
108 pv.setPoint(point); \
109 pv.setNormal(normal); \
110 pv.setTextureCoords(texCoord); \
120 double rMax1 =
fRmax1.getValue();
121 double rMin1 =
fRmin1.getValue();
122 double rMax2 =
fRmax2.getValue();
123 double rMin2 =
fRmin2.getValue();
124 double zMax =
fDz.getValue();
128 double cosPhi1 =
cos(phi1);
129 double sinPhi1 =
sin(phi1);
136 double sinPhi=sinPhi0;
137 double cosPhi=cosPhi0;
140 double dR =rMax2-rMax1;
141 double dZ =zMax-zMin;
142 double cosTheta = -dR/sqrt(dR*dR+dZ*dZ);
143 double sinTheta = dZ/sqrt(dR*dR+dZ*dZ);
145 beginShape(
action,TRIANGLE_STRIP);
146 for (
i = 0;
i<=NPHI;
i++) {
147 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta);
148 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta);
149 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
161 double dR =rMin2-rMin1;
162 double dZ =zMax-zMin;
163 double cosTheta = -dR/sqrt(dR*dR+dZ*dZ);
164 double sinTheta = dZ/sqrt(dR*dR+dZ*dZ);
165 beginShape(
action,TRIANGLE_STRIP);
166 for (
i = 0;
i<=NPHI;
i++) {
167 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,-sinTheta*cosPhi,-sinTheta*sinPhi,-cosTheta);
168 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,1.0,1.0,-sinTheta*cosPhi,-sinTheta*sinPhi,-cosTheta);
169 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
177 beginShape(
action,TRIANGLE_STRIP);
180 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);
181 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);
182 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);
183 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);
188 beginShape(
action,TRIANGLE_STRIP);
191 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);
192 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);
193 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);
194 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);
201 beginShape(
action,TRIANGLE_STRIP);
204 for (
i = 0;
i<=NPHI;
i++) {
205 GEN_VERTEX(
pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,0,0,1);
206 GEN_VERTEX(
pv,rMax2*cosPhi,rMax2*sinPhi,zMax,1.0,1.0,0,0,1);
207 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
213 beginShape(
action,TRIANGLE_STRIP);
216 for (
i = 0;
i<=NPHI;
i++) {
217 GEN_VERTEX(
pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,0.0,0,0,-1);
218 GEN_VERTEX(
pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,0,0,-1);
219 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
223 if (state&&state->isElementEnabled(SoGLCacheContextElement::getClassStackIndex())) {
225 SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DO_AUTO_CACHE);
226 #if ((COIN_MAJOR_VERSION>=3)||((COIN_MAJOR_VERSION==2)&&(COIN_MINOR_VERSION>=5)))
227 SoGLCacheContextElement::incNumShapes(state);
243 -
fDz.getValue(),
fDz.getValue(),
258 SoCoordinate3 *theCoordinates = (SoCoordinate3 *) (
sep->getChild(0));
259 SoNormal *theNormals = (SoNormal *) (
sep->getChild(1));
260 SoNormalBinding *theNormalBinding = (SoNormalBinding *) (
sep->getChild(2));
261 SoIndexedFaceSet *theFaceSet = (SoIndexedFaceSet *) (
sep->getChild(3));
263 const int NPHI=96, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
264 float points[NPOINTS][3], normals[NFACES][3];
268 static int32_t
indices[NINDICES];
271 double phi, pp, DeltaPhi;
280 for (
i = 0;
i< NPHI;
i++) {
289 for (
i=0;
i<NPHI;
i++) {
290 indices[5*1*NPHI + 5*
i+0] = 2*NPHI+2 + 2*
i+0;
291 indices[5*1*NPHI + 5*
i+1] = 2*NPHI+2 + 2*
i+1;
292 indices[5*1*NPHI + 5*
i+2] = 2*NPHI+2 + 2*
i+3;
293 indices[5*1*NPHI + 5*
i+3] = 2*NPHI+2 + 2*
i+2;
294 indices[5*1*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
297 for (
i=0;
i<NPHI;
i++) {
300 indices[5*2*NPHI + 5*
i+2] = NPOINTS - (2*
i+4);
301 indices[5*2*NPHI + 5*
i+3] = NPOINTS - (2*
i+2);
302 indices[5*2*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
305 for (
i=0;
i<NPHI;
i++) {
307 indices[5*3*NPHI + 5*
i+1] = NPOINTS - (2*
i+1);
308 indices[5*3*NPHI + 5*
i+2] = NPOINTS - (2*
i+3);
310 indices[5*3*NPHI + 5*
i+4] = SO_END_FACE_INDEX;
314 indices[5*4*NPHI +1] = 2*NPHI+1;
315 indices[5*4*NPHI +2] = 2*NPHI+3;
316 indices[5*4*NPHI +3] = 2*NPHI+2;
317 indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
320 indices[5*4*NPHI +5 +1] = NPOINTS-2;
321 indices[5*4*NPHI +5 +2] = NPOINTS-1;
323 indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
332 for (
i = 0;
i<=NPHI;
i++) {
339 pp =
phi+DeltaPhi/2.0;
352 for (
i = 0;
i<=NPHI;
i++) {
359 pp =
phi-DeltaPhi/2.0;
361 normals[NPHI+
i][0] = -
ct*
FCOS(pp);
362 normals[NPHI+
i][1] = -
ct*
FSIN(pp);
363 normals[NPHI+
i][2] = st;
368 for (
i=0;
i<NPHI;
i++) {
369 normals[2*NPHI+
i][0]=normals[2*NPHI+
i][1]=0;
370 normals[2*NPHI+
i][2]= 1.0;
373 for (
i=0;
i<NPHI;
i++) {
374 normals[3*NPHI+
i][0]=normals[3*NPHI+
i][1]=0;
375 normals[3*NPHI+
i][2]= -1.0;
379 normals[4*NPHI+0][0]=
FSIN(
phi);
380 normals[4*NPHI+0][1]= -
FCOS(
phi);
381 normals[4*NPHI+0][2]= 0;
385 normals[4*NPHI+1][0]= -
FSIN(
phi);
386 normals[4*NPHI+1][1]= +
FCOS(
phi);
387 normals[4*NPHI+1][2]=0;
390 theFaceSet->coordIndex.setValues(0,NINDICES,
indices);
394 for (
int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
395 theNormalBinding->value=SoNormalBinding::PER_FACE;
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;
412 SoSeparator *
sep =
new SoSeparator();
413 SoCoordinate3 *theCoordinates =
new SoCoordinate3();
414 SoNormal *theNormals =
new SoNormal();
415 SoNormalBinding *theNormalBinding =
new SoNormalBinding();
416 SoIndexedFaceSet *theFaceSet =
new SoIndexedFaceSet();
420 sep->addChild(theCoordinates);
421 sep->addChild(theNormals);
422 sep->addChild(theNormalBinding);
423 sep->addChild(theFaceSet);