Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoShape.h
1
2/*=======================================================================
3 * Copyright 1991-1996, Silicon Graphics, Inc.
4 * ALL RIGHTS RESERVED
5 *
6 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
7 * States. Use of a copyright notice is precautionary only and does not
8 * imply publication or disclosure.
9 *
10 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
11 * Use, duplication or disclosure by the Government is subject to restrictions
12 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
13 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
14 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
15 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
16 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
17 *
18 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
19 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
20 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
21 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
22 * GRAPHICS, INC.
23**=======================================================================*/
24/*=======================================================================
25** Author : Paul S. Strauss (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_SHAPE_
52#define _SO_SHAPE_
53
54#include <Inventor/SbBox.h>
55#include <Inventor/SbMatrix.h>
56#include <Inventor/actions/SoRayPickAction.h>
57#include <Inventor/nodes/SoNode.h>
58#include <Inventor/fields/SoSFBool.h>
59#include <Inventor/SbPImpl.h>
60
61class SoDetail;
62class SbVec2s;
63class SoFaceDetail;
64class SoPickedPoint;
66class SoState;
67class SoMFInt32;
68class PickedPointListImpl;
69
71typedef SoDetail *jySoDetailPtr;
72
73SO_PIMPL_PUBLIC_DECLARATION(SoShape)
74
75
76//
77// Class: SoShape
78//
79// Abstract base shape node class, which provides some convenience
80// functions for its subclasses.
81//
83
115class SoShape : public SoNode
116{
117 SO_NODE_ABSTRACT_HEADER(SoShape);
118 SO_PIMPL_PUBLIC_HEADER(SoShape)
119
120 public:
125
129 virtual SbBool affectsState() const;
130
146
151
161
162 private:
163
169 enum TriangleShape {
170 TRIANGLE_STRIP,
171 TRIANGLE_FAN,
172 TRIANGLES,
173 POLYGON,
174 SEGMENT_STRIP,
175 POINT_SET
176 };
177
200 void beginShape( SoAction *action, TriangleShape shapeType,
201 SoFaceDetail *faceDetail = NULL);
202
207 void shapeVertex(const SoPrimitiveVertex *v);
208
209
210
214 void endShape();
215
220 virtual void getBoundingBox(SoGetBoundingBoxAction *action);
221
226 virtual void GLRender(SoGLRenderAction *action);
227
233 virtual void rayPick(SoRayPickAction *action);
234
239 virtual void callback(SoCallbackAction *action);
240
247 static void getScreenSize(SoState *state, const SbBox3f &boundingBox, SbVec2s &rectSize);
248
257 static float getDecimatedComplexity(SoState *state, float complexity);
258
266 virtual void computeBBox(SoAction *action, SbBox3f &box, SbVec3f &center) = 0;
267
284 virtual void computeBBox(SoAction *action, SbXfBox3d &box, SbVec3d &center)
285 {
286 // SubClass did not redefine this function so by default use AABB version
287 SbBox3f boxf;
288 SbVec3f centerf;
289 computeBBox(action, boxf, centerf);
290
292 box.makeEmpty();
293 box.setBounds(SbVec3d(boxf.getMin().getValue()),SbVec3d(boxf.getMax().getValue()));
294 center.setValue(centerf);
295 }
296
302 inline virtual SbBool isBoundingBoxIgnoring() const
303 { return boundingBoxIgnoring.getValue(); }
304
310 virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action);
311
312 // Gets multi-texturing info:
313 // - Indicates if the multi-texturing is active
314 // - The list of texture units where texture coordinate should be sent (that is
315 // where texture coordinates different from a function.)
316 static SbBool getMultiTextureInfo(SoState *state, SbIntList &imageTextUnitList) ;
317
321 void setShapeType(SoShape::ShapeType st);
322
323 // These methods invoke whatever callbacks are registered with the
324 // primitive generation procedures. If primitives are being
325 // generated for picking or rendering purposes, the appropriate
326 // SoShape methods are called. If primitives are being generated
327 // for the SoCallbackAction, the callbacks registered with the
328 // action are called.
329 void invokeTriangleCallbacks(SoAction *action,
330 const SoPrimitiveVertex *v1,
331 const SoPrimitiveVertex *v2,
332 const SoPrimitiveVertex *v3);
333
334 void invokeLineSegmentCallbacks(SoAction *action,
335 const SoPrimitiveVertex *v1,
336 const SoPrimitiveVertex *v2);
337
338 void invokePointCallbacks(SoAction *action,
339 const SoPrimitiveVertex *v);
340
341
342 private:
343 static void initClass();
344 static void exitClass();
345
346 // redefined for Shapes
347 virtual void GLRenderP(SoGLRenderAction *action);
348
349 SB_THREAD_TLS_HEADER();
350
351 // It is possible to disable projection for a given shape even if the element is set
352 SbBool m_forceDisableProjection;
353
354 void setForceDisableProjection( SbBool disable ){m_forceDisableProjection = disable;}
355
356 static bool isVertexArrayAvailable(SoState* state=NULL);
357 static bool isMultiDrawArrayAvailable(SoState* state=NULL);
358 static bool isVertexBufferAvailable(SoState* state=NULL);
359
360 // Returns 0 if not available, 1 if NV version, 2 if core
361 static int getPrimitiveRestartMode(SoState* state = NULL);
362
363 static int getMaxPrimitiveLoop();
364
365 static int getMinVertexNumForVA();
366
367 static int getMinVertexNumForVBO();
368
369 static int getMinVertexNumForVAVBONoCache();
370
371 static bool isDesindexingAllowed();
372
373 static bool isTrisStripAllowedForQuadMesh();
374
375 static SbBool isDetailDebugEnabled();
376
377 static bool isCreaseAngleFixSet();
378
379 // This endShape is used by SoIndexedFaceSet and SoFaceSet to create hole
380 // in a face.
381 void endShape( int wt, SoMFInt32* indexes );
382
383 // Returns TRUE if the shape should be rendered. Subclasses can
384 // call this in their rendering methods to determine whether to
385 // continue.
386 SbBool shouldPrimitiveCount(SoGetPrimitiveCountAction *action);
387
388 virtual int getNumVert(SoState *state = NULL ){ return getNumPrim( state ); }
389
390 virtual int getNumPrim( SoState *state = NULL );
391
392 inline SbBool isRenderable(SoGLRenderAction* action)
393 {
394 return shouldGLRender(action, FALSE);
395 }
396
397 private:
398
399 SoShape();
400
401 virtual SbBool checkShapeHints(SoGLRenderAction *action);
402
403 inline virtual void countPrim( SoState *state = NULL );
404
405 virtual SbBool checkTransparency(SoGLRenderAction *action, SbBool isPointsOrLines);
406
407 virtual SbBool isRenderingPointsOrLines(SoGLRenderAction *action);
408
409 virtual SbBool shouldRenderNow(SoGLRenderAction *action,SbBool &isPointsOrLines);
410
411 //-------------------------------------------------------------------------------
412
413 // This method MUST be defined by each subclass to generate
414 // primitives (triangles, line segments, points) that represent
415 // the shape.
416 virtual void generatePrimitives(SoAction *action) = 0;
417
418 // Returns TRUE if the shape should be rendered. Subclasses can
419 // call this in their rendering methods to determine whether to
420 // continue.
421 virtual SbBool shouldGLRender(SoGLRenderAction *action,
422 SbBool isPointsOrLines = FALSE);
423
424 // Implementation of shouldGLRender to split the general case
425 // to tessellationShader support case. shouldGLRender always
426 // return false if tessellation shaders are on the state. This
427 // method is called for every shape with no tessellation shaders on the
428 // state and bufferedShape.
429 SbBool shouldGLRenderCore(SoGLRenderAction *action,
430 SbBool isPointsOrLines = FALSE,
431 SbBool hasTessellationShader = FALSE);
432
433 // Returns FALSE if the shape is invisible. If the complexity
434 // is BOUNDING_BOX, it renders the cuboid and returns FALSE.
435 // Otherwise returns TRUE.
436 SbBool handleInvisibleOrBBox(SoGLRenderAction *action,
437 SbBool isPointsOrLines = FALSE);
438
439 // Returns TRUE if the shape may be picked. Subclasses can call
440 // this in their picking methods to determine whether to continue.
441 SbBool shouldRayPick(SoRayPickAction *action);
442
443
444
446 // rendering. They take care of setting up shape hints in the
447 // state. Calls to these two methods should bracket the rendering
448 // code.
449 void beginSolidShape(SoGLRenderAction *action);
450 void endSolidShape(SoGLRenderAction *action);
451
452 // Computes a picking ray in the object space of the shape
453 // instance. The picking ray is stored in the SoRayPickAction for
454 // later access by the subclass. The second form takes a matrix to
455 // concatenate with the current transformation matrix. It can be
456 // used, for example, if a shape has sizing or positioning info
457 // built into it.
458 void computeObjectSpaceRay(SoRayPickAction *action);
459 void computeObjectSpaceRay(SoRayPickAction *action,
460 const SbMatrix &matrix);
461
462 // These methods are called during picking to create details
463 // representing extra info about a pick intersection. The default
464 // methods implemented in SoShape return NULL. Subclasses can
465 // override these methods to set up specific detail instances that
466 // contain the extra info. Subclasses can get whatever information
467 // they need from the SoPickedPoint, and can set information in it
468 // as well.
469 virtual SoDetail *createTriangleDetail(SoRayPickAction *action,
470 const SoPrimitiveVertex *v1,
471 const SoPrimitiveVertex *v2,
472 const SoPrimitiveVertex *v3,
473 SoPickedPoint *pp);
474 virtual SoDetail *createLineSegmentDetail(SoRayPickAction *action,
475 const SoPrimitiveVertex *v1,
476 const SoPrimitiveVertex *v2,
477 SoPickedPoint *pp);
478 virtual SoDetail *createPointDetail(SoRayPickAction *action,
479 const SoPrimitiveVertex *v,
480 SoPickedPoint *pp);
481
482
483
484 virtual ~SoShape();
485
486 // Applies GLRender action to the bounding box surrounding the shape.
487 // This is used to render shapes when BOUNDING_BOX complexity is on.
488 virtual void GLRenderBoundingBox(SoGLRenderAction *action);
489
490 // Changes the GL_MULTISAMPLE_ARB OpenGL bit value. This method is used to filter the
491 // antialiasing when traversing the shape. (See SoFullSceneAntialiasing for more).
492 virtual void applyFullSceneAntialiasingFilter(SoState* state);
493
494 // isProjectCoordNeeded = true if projection need to be done by SoShape
495 // isProjectCoordNeeded = false if projection is already handled somewhere (ex: vertexShape)
496 void setNeedToProjectCoord(bool isProjectCoordNeeded);
497
498 private:
499
500 static int s_keepReset;
501 static int s_forceSend;
502 static SbBool s_noClip;
503
504private:
505
506 // Applies rayPick action to the bounding box surrounding the shape.
507 // This is used to pick shapes when BOUNDING_BOX complexity is on.
508 void rayPickBoundingBox(SoRayPickAction *action);
509
510 void commonConstructor();
511};
512
513inline SbBool
514SoShape::checkShapeHints(SoGLRenderAction *)
515{
516 return FALSE;
517}
518
519void
520SoShape::countPrim( SoState* /*state*/ )
521{}
522
523#endif /* _SO_SHAPE_ */
3D box class.
Definition SbBox.h:649
const SbVec3f & getMin() const
Returns the minimum point of the box.
Definition SbBox.h:684
const SbVec3f & getMax() const
Returns the maximum point of the box.
Definition SbBox.h:699
4x4 matrix class.
Definition SbMatrix.h:309
static SbMatrixd identity()
Returns an identity matrix.
2D vector class.
Definition SbVec.h:700
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D vector class ...
Definition SbVec.h:1214
SbVec3d & setValue(const double v[3])
Sets the vector components.
Definition SbVec.h:1292
3D vector class.
Definition SbVec.h:932
const float * getValue() const
Returns vector components.
Definition SbVec.h:977
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D box with an a...
Definition SbBox.h:1513
void makeEmpty()
Sets the box to contain nothing.
Definition SbBox.h:1673
void setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Sets the bounds of the box.
Definition SbBox.h:1629
void setTransform(const SbMatrixd &m)
Sets the transformation on the box.
Abstract base class for all actions.
Definition SoAction.h:132
Performs a generic traversal of a scene graph or path.
Base class for describing detail information about a shape node.
Definition SoDetail.h:99
Stores detail information about vertex-based shapes made of faces.
Renders a scene graph using Open Inventor's Render Engine.
Computes bounding box of a scene.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Counts number of...
Multiple-value field containing any number of int32_t integers.
Definition SoMFInt32.h:88
Abstract base class for all database nodes.
Definition SoNode.h:145
Represents point on surface of picked object.
Represents a vertex of a generated primitive.
Intersects objects with a ray cast into scene.
Field containing a single Boolean value.
Definition SoSFBool.h:79
SbBool getValue() const
Returns this field's value.
Definition SoSFBool.h:82
Abstract base class for all shape nodes.
Definition SoShape.h:116
virtual SbBool affectsState() const
Overrides default method on SoNode.
static SbBool isPrimitiveRestartAvailable(SoState *state=NULL)
Returns TRUE if the primitive restart feature is available.
ShapeType
Basic type for antialiased rendering for this shape (Do not consider the SoDrawStyle property current...
Definition SoShape.h:136
@ LINES
The shape is render based on lines (Ex: SoLineSet).
Definition SoShape.h:140
@ POINTS
The shape is render based on points (Ex: SoPointSet).
Definition SoShape.h:138
@ POLYGONS
The shape is render based on polygons (Ex: SoFaceSet).
Definition SoShape.h:142
SoSFBool boundingBoxIgnoring
Whether to ignore this node during bounding box traversal.
Definition SoShape.h:124
ShapeType getShapeType()
Gets the current shape Full Scene Antialiasing type.
Traversal state.
Definition SoState.h:74
int SbBool
Boolean type.
Definition SbBase.h:87