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-2014 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 00116 class SoGetPrimitiveCountAction : public SoAction { 00117 00118 SO_ACTION_HEADER(SoGetPrimitiveCountAction); 00119 00120 public: 00124 SoGetPrimitiveCountAction(); 00125 00129 virtual ~SoGetPrimitiveCountAction(); 00130 00134 int32_t getTriangleCount() const { return numTriangles; } 00138 int32_t getLineCount() const { return numLines; } 00142 int32_t getPointCount() const { return numPoints; } 00146 int32_t getTextCount() const { return numText; } 00150 int32_t getImageCount() const { return numImage; } 00151 00155 SbBool containsNoPrimitives(); 00159 SbBool containsNonTriangleShapes(); 00160 00181 void setDecimationValue(SoDecimationTypeElement::Type type, 00182 float percentage = 1.0); 00186 SoDecimationTypeElement::Type getDecimationType() { return decType; }; 00190 float getDecimationPercentage() { return decPercent; }; 00191 00197 void setCount3DTextAsTriangles(SbBool treatAsTris) 00198 { treatText3AsTris = treatAsTris; }; 00203 SbBool is3DTextCountedAsTriangles() { return treatText3AsTris; }; 00204 00211 void setCanApproximate(SbBool onOff) 00212 { canApproximate = onOff; }; 00216 SbBool canApproximateCount() { return canApproximate; }; 00217 00218 private: 00219 // These functions are called by nodes to add a number of 00220 // a type of primitive to the number of primitives found. 00221 void addNumTriangles(int32_t num) { numTriangles += num; }; 00222 void addNumLines(int32_t num) { numLines += num; }; 00223 void addNumPoints(int32_t num) { numPoints += num; }; 00224 void addNumText(int32_t num) { numText += num; }; 00225 void addNumImage(int32_t num) { numImage += num; }; 00226 void incNumTriangles() { numTriangles++; }; 00227 void incNumLines() { numLines++; }; 00228 void incNumPoints() { numPoints++; }; 00229 void incNumText() { numText++; }; 00230 void incNumImage() { numImage++; }; 00231 00232 private: 00233 static void initClass(); 00234 static void exitClass(); 00235 00236 private: 00237 // Initiates action on graph 00238 virtual void beginTraversal(SoNode *node); 00239 00240 private: 00241 int32_t numTriangles; 00242 int32_t numLines; 00243 int32_t numPoints; 00244 int32_t numText; 00245 int32_t numImage; 00246 00247 SbBool treatText3AsTris; 00248 SbBool canApproximate; 00249 00250 SoDecimationTypeElement::Type decType; 00251 float decPercent; 00252 00253 }; 00254 00255 #endif /* _SO_GET_PRIMITIVE_COUNT_ACTION_ */ 00256 00257