HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_PolyKnitParser.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SOP Library (C++)
7  *
8  * COMMENTS:
9  * Parser for the PolyKnit SOP.
10  *
11  * Grammar for the format:
12  * Legend:
13  * /\ - empty
14  * <?> - non-terminal
15  * # - number
16  *
17  * <S> -> <T0> | <Q0> | /\
18  * <T0> -> t###<T1> | ###<T1> | t###<Q1> | ###<Q1>
19  * <T1> -> #<T1> | t#<T1> | #<Q1> | t#<Q1> | /\
20  * <Q0> -> q####<T1> | ####<T1> | q####<Q1> | ####<Q1> | ##q##<Q1>
21  * | #q###<T1> | #q###<Q1>
22  * <Q1> -> ##<Q1> | q##<Q1> | ##<T1> | q##<T1> | /\
23  *
24  */
25 
26 #ifndef __SOP_PolyKnitParser_h__
27 #define __SOP_PolyKnitParser_h__
28 
29 #include "SOP_API.h"
30 #include <UT/UT_IntArray.h>
31 
32 #include <GOP/GOP_Parser.h>
33 #include <GU/GU_Detail.h>
34 
35 // Parser tokens
36 #define CHAR_TRIANGLE 't'
37 #define CHAR_QUAD 'q'
38 #define CHAR_META_TRIANGLE 'T'
39 #define CHAR_META_QUAD 'Q'
40 
41 class SOP_Node;
42 
44 {
45 public:
47  UT_IntArray &ptArray, UT_IntArray &typeArray);
48  ~SOP_PolyKnitParser() override {}
49 
50  bool haveMetas() const { return myHaveMetas; }
51 
52  // Returns the token which caused the error
53  const char *errorToken() const
54  { return (const char *)myErrorToken; }
55 
56 protected:
57  void handleError() override;
58 
59 private:
60  void init() override;
61  void finish() override;
62  bool dispatch(char c) override;
63 
64  // State handlers
65  void handleStart() override;
66 
67  void handleTrianglePoint();
68  void handleQuadPoint();
69  void handleMetaTrianglePoint();
70  void handleMetaQuadPoint();
71  void handlePoint(int polytype, int numpoints);
72 
73  // Updates the myCanSwitch flag based on new point count
74  void updateCanSwitch();
75 
76  // Small method to make code a little cleaner
77  void switchOutput(int out);
78 
79  GU_Detail &myGdp;
80  UT_IntArray &myPtArray;
81  UT_IntArray &myTypeArray;
82 
83  // Points seen so far in the current primitive being constructed.
84  int myCurrentPrimPoints;
85 
86  // Contains the current polygon type
87  int myCurrentPolyType;
88 
89  // Are we at a point where we can switch the poly
90  bool myCanSwitch;
91 
92  // Flag for whether or not we have meta polys
93  bool myHaveMetas;
94 
95  UT_String myErrorToken;
96  int myErrorPoint;
97 };
98 
99 #endif
100 
const char * errorToken() const
virtual bool dispatch(char c)=0
~SOP_PolyKnitParser() override
virtual void finish()
bool haveMetas() const
virtual void handleError()=0
virtual void init()
#define SOP_API
Definition: SOP_API.h:10
virtual void handleStart()=0