00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : VSG (MMM YYYY) 00022 **=======================================================================*/ 00023 00024 00025 #ifndef _SO_GET_PRIMITIVE_COUNT_ACTION_ 00026 #define _SO_GET_PRIMITIVE_COUNT_ACTION_ 00027 00028 #include <Inventor/actions/SoSubAction.h> 00029 #include <Inventor/elements/SoDecimationTypeElement.h> 00030 00032 // 00033 // Class: SoGetPrimitiveCountAction 00034 // 00035 // For computing the amount of primitives (triangles, lines, points, 00036 // text, images) in a scene. This could be used as an estimate 00037 // for a scene's complexity, or rendering time. The triangles, 00038 // lines, and points are counted; however, the text and images 00039 // count only the number of text or image nodes. 00040 // SoText3 can be counted as either triangles or text, depending 00041 // on the setting in this action. 00042 // The counts can be approximated depending on the setting in this 00043 // action. This allows IndexedShapes to take a guess based on 00044 // the number of vertices, instead of searching through 00045 // the actual values of their fields. 00046 // 00048 00117 class SoGetPrimitiveCountAction : public SoAction { 00118 00119 SO_ACTION_HEADER(SoGetPrimitiveCountAction); 00120 00121 public: 00125 SoGetPrimitiveCountAction(); 00126 00130 virtual ~SoGetPrimitiveCountAction(); 00131 00135 int32_t getTriangleCount() const { return numTriangles; } 00139 int32_t getLineCount() const { return numLines; } 00143 int32_t getPointCount() const { return numPoints; } 00147 int32_t getTextCount() const { return numText; } 00151 int32_t getImageCount() const { return numImage; } 00152 00156 SbBool containsNoPrimitives(); 00160 SbBool containsNonTriangleShapes(); 00161 00182 void setDecimationValue(SoDecimationTypeElement::Type type, 00183 float percentage = 1.0); 00187 SoDecimationTypeElement::Type getDecimationType() { return decType; }; 00191 float getDecimationPercentage() { return decPercent; }; 00192 00198 void setCount3DTextAsTriangles(SbBool treatAsTris) 00199 { treatText3AsTris = treatAsTris; }; 00204 SbBool is3DTextCountedAsTriangles() { return treatText3AsTris; }; 00205 00212 void setCanApproximate(SbBool onOff) 00213 { canApproximate = onOff; }; 00217 SbBool canApproximateCount() { return canApproximate; }; 00218 00219 private: 00220 // These functions are called by nodes to add a number of 00221 // a type of primitive to the number of primitives found. 00222 void addNumTriangles(int32_t num) { numTriangles += num; }; 00223 void addNumLines(int32_t num) { numLines += num; }; 00224 void addNumPoints(int32_t num) { numPoints += num; }; 00225 void addNumText(int32_t num) { numText += num; }; 00226 void addNumImage(int32_t num) { numImage += num; }; 00227 void incNumTriangles() { numTriangles++; }; 00228 void incNumLines() { numLines++; }; 00229 void incNumPoints() { numPoints++; }; 00230 void incNumText() { numText++; }; 00231 void incNumImage() { numImage++; }; 00232 00233 private: 00234 static void initClass(); 00235 static void exitClass(); 00236 00237 private: 00238 // Initiates action on graph 00239 virtual void beginTraversal(SoNode *node); 00240 00241 private: 00242 int32_t numTriangles; 00243 int32_t numLines; 00244 int32_t numPoints; 00245 int32_t numText; 00246 int32_t numImage; 00247 00248 SbBool treatText3AsTris; 00249 SbBool canApproximate; 00250 00251 SoDecimationTypeElement::Type decType; 00252 float decPercent; 00253 00254 }; 00255 00256 #endif /* _SO_GET_PRIMITIVE_COUNT_ACTION_ */ 00257 00258