HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_FacePointParser.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: Point parser for the curve SOP
9  *
10  */
11 
12 #ifndef __SOP_FacePointParser_h__
13 #define __SOP_FacePointParser_h__
14 
15 #include "SOP_API.h"
16 #include <GOP/GOP_Parser.h>
17 #include <SYS/SYS_Math.h>
18 #include "SOP_Curve.h"
19 
20 
21 // Special Characters recognized by the parser
22 #define CHAR_POINT 'p'
23 #define CHAR_POINTCOPY 'P'
24 #define CHAR_RELATIVE '@'
25 #define CHAR_BREAKPOINT 'b'
26 #define CHAR_BRACKETOPEN '['
27 #define CHAR_BRACKETCLOSE ']'
28 #define CHAR_XYZW_DELIM ','
29 #define CHAR_UV_DELIM ','
30 
32 {
33 public:
34  SOP_FacePointParser(const GU_Detail *gdp, UT_String &str);
35  SOP_FacePointParser(const GU_Detail *gdp, const UT_StringHolder &str);
36 
37  ~SOP_FacePointParser() override {}
38 
39  enum RefType
40  {
41  RefTypeNone = -1,
42  RefTypePoint = 0,
43  RefTypeBreakpoint = 1,
44  RefTypeRelative = 2
45  };
46 
47 protected:
48  // The following methods should be handled by the child classes, depending
49  // on how they store the point list.
50  void handleError() override;
51  virtual void resetPointList() = 0;
52  virtual void addPoint(const UT_Vector4R &v, bool relative,
53  bool use_w, const UT_Vector4R &last,
54  RefType reftype = RefTypeNone,
55  int pid = -1) = 0;
56  virtual void referencePoint(GA_Offset point) = 0;
57 
58  // this is where we know what error occurred, but the actual message error
59  // display happens somewhere else; therefore have an integer which keeps
60  // track of error messages (negative for generic, index of error message
61  // otherwise)
63 
64  const GU_Detail *myRefGdp; // gdp to use for references
65 
66 private:
67  void init() override;
68  void finish() override;
69  bool dispatch(char c) override;
70 
71  // State handlers
72  void handleStart() override;
73  void handleCollectX();
74  void handleCollectY();
75  void handleCollectZ();
76  void handleCollectW();
77  void handleCollectP();
78  void handleCollectBU();
79  void handleCollectBV();
80 
81  // Puts the position of the breakpoint from primitive at index primidx
82  // specified by u and v. (Set v to -1 for curves).
83  // Returns true if the u and v and primidx are valid, false otherwise
84  bool getPosFromBreakpoint(int u, int v,
85  GA_Index primidx,
86  UT_Vector4R &pos);
87 
88  void updateLastPos(UT_Vector4R curpos,
89  bool relative,
90  bool use_w,
91  UT_Vector4R lastpos);
92 
93  UT_Vector4R myLastPos;
94  UT_Vector4R myCurrPos;
95 
96  bool myRelative;
97  bool myCopyPoint;
98  bool myAllSpaces;
99  bool myFirstBracket;
100  bool myOpenBracket;
101  bool myZDone;
102  int myIndex;
103  int myU, myV;
104 };
105 
107 {
108 public:
110  : SOP_FacePointParser(gdp, str) {}
111 
113 
114  void pointList(UT_Vector3Array *ptarray)
115  { myPointList = ptarray; }
116 
117 
118 protected:
119  void handleError() override
120  {
121  startToken();
122  endToken();
123  resetPointList();
125  }
126 
127  void resetPointList() override
128  {
129  if (myPointList)
130  myPointList->setSize(0);
131  }
132 
133  void referencePoint(GA_Offset point) override
134  {
135  UT_ASSERT(false); //not supported
136  }
137 
138  void addPoint(const UT_Vector4R &pt,
139  bool relative,
140  bool use_w,
141  const UT_Vector4R &last,
142  SOP_FacePointParser::RefType reftype = RefTypeNone,
143  int pid = -1) override
144  {
145  #define DEBUG_addPoint 0
146  UT_Vector4 v(pt);
147 
148  if (relative)
149  v += UT_Vector4{ last };
150 
151  UT_ASSERT(!use_w); //we should not use w at all.
152  if (!use_w)
153  v.w() = 1;
154 
155  #if DEBUG_addPoint
156  UTformat("Appending {} {} {}\n", v[0], v[1], v[2]);
157  #endif
158 
159  if (myPointList)
160  myPointList->emplace_back(v[0], v[1], v[2]);
161  }
162 
163  UT_Vector3Array* myPointList; // positions only
164 };
165 
166 #endif
const GLdouble * v
Definition: glcorearb.h:837
void startToken()
virtual bool dispatch(char c)=0
virtual void finish()
void endToken()
GA_Size GA_Offset
Definition: GA_Types.h:641
virtual void handleError()=0
void handleError() override
void addPoint(const UT_Vector4R &pt, bool relative, bool use_w, const UT_Vector4R &last, SOP_FacePointParser::RefType reftype=RefTypeNone, int pid=-1) override
void referencePoint(GA_Offset point) override
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:635
UT_Vector3Array * myPointList
virtual void init()
void pointList(UT_Vector3Array *ptarray)
SOP_PointPositionParser(const GU_Detail *gdp, const UT_StringHolder &str)
virtual void resetPointList()=0
const GU_Detail * myRefGdp
constexpr SYS_FORCE_INLINE T & w() noexcept
Definition: UT_Vector4.h:497
#define SOP_API
Definition: SOP_API.h:10
size_t UTformat(FILE *file, const char *format, const Args &...args)
Definition: UT_Format.h:657
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
virtual void handleStart()=0