HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_EdgeSlide.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: Interface for computing sliding of edges.
9  */
10 
11 #ifndef __GU_EdgeSlide_h__
12 #define __GU_EdgeSlide_h__
13 
14 #include "GU_API.h"
15 #include "GU_Detail.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_Map.h>
18 #include <UT/UT_Set.h>
19 #include <UT/UT_VectorTypes.h>
20 
21 class GU_RayIntersect;
22 
24 {
31 };
32 
34 {
35 public:
36  typedef std::pair<GA_Index, GA_Index> Edge;
37 
38  // caller can optionally pass a GU_RayIntersect that they want the slide
39  // points to be snapped onto
40  GU_EdgeSlide(GU_RayIntersect* templateGeoRayIntersect = nullptr)
41  : myTemplateGeoRayIntersect(templateGeoRayIntersect)
42  , myIsLoop(false)
43  , myIsValidEdge(false)
44  , myMovingLeft(false)
45  , myMode(GU_SLIDE_ANCHOREDBLEND)
46  , myGrabEdge(Edge(-1,-1))
47  , myLastEdge(Edge(-1,-1)) {}
48 
49  // Generates the list of slide points given a list of selected edges
50  // according to the current detail.
51  bool setSlidePoints(const GU_Detail &geo, const UT_Array<Edge> &selection);
52 
53  // Called every movement step (i.e mouse move), fills indices and positions
54  // in same order. Caller can optionnaly pass a map that gets filled with
55  // which slide points hit their borders and should be snapped.
56  void moveSlidePoints(UT_Array<GA_Index> &indices,
57  UT_Vector3Array &positions, const GU_Detail &geo,
58  const UT_Vector3 &dir, const UT_Vector3 &orig,
59  bool staticShift,
60  UT_Map<GA_Index, GA_Index> *snapped = nullptr);
61 
62  // called to "end" slide edit, sliding works based on intial position of the
63  // slide edge, this will set all the initial positions to the current
64  // positions
65  void setCurPosToInitPos();
66 
67  // clears slide pints array
68  void clearSlidePoints();
69 
70  // Fills points with ordered traversal of slide edge (from end to end).
71  // Points will contain all VALID point indices according to where on the
72  // selection myGrabEdge is. Called can optionally get the UNORDERED set of
73  // invalid points.
74  void getSlidePoints(UT_Array<GA_Index> &points,
75  UT_Set<GA_Index> *invalid=nullptr) const;
76 
77  void getSlidePointsSnaps(UT_Array<GA_Index> &snaps,
78  UT_Set<GA_Index> *invalid = nullptr) const;
79 
80  // Fills points with ordered traversal of 'left' or 'right' side of current
81  // slide edge.
82  void getNeighbouringPoints(UT_Array<GA_Index> &points, bool left) const;
83 
84  // Fills points with ordered traversal of slide edge (from end to end).
85  // Points will contain all point positions according to where on the
86  // selection myGrabEdge is.
87  void getSlidePointsPos(UT_Vector3Array &points) const;
88 
89  // Fills points with ordered traversal of 'left' or 'right' side of current
90  // slide edge.
91  void getNeighbouringPointsPos(UT_Vector3Array &points, bool left) const;
92 
93  inline bool isEmpty() const { return !mySlidePoints.entries(); }
94  inline bool isLoop() const { return myIsLoop; }
95  inline bool isValid() const { return myIsValidEdge; }
96  inline bool isMovingLeft() const { return myMovingLeft; }
97  inline GU_SlideMode getMode() const { return myMode; }
98  inline void setMode(GU_SlideMode mode) { myMode = mode; }
99  inline void setGrabEdge(GA_Index p0, GA_Index p1)
100  { myGrabEdge = std::make_pair(p0, p1); }
101  inline Edge getGrabEdge() { return myGrabEdge; }
102  inline GU_RayIntersect* getRayIntersect() const { return myTemplateGeoRayIntersect; }
103  inline void setRayIntersect(GU_RayIntersect *rayintersect) { myTemplateGeoRayIntersect = rayintersect; }
104 private:
105  /****** structs ******/
106 
107  struct SlidePoint
108  {
109  SlidePoint(GA_Index idx, const UT_Vector3 &pos)
110  : myLeft(GA_INVALID_INDEX)
111  , myRight(GA_INVALID_INDEX)
112  , myIndex(idx)
113  , mySnap(GA_INVALID_INDEX)
114  , myPos(pos)
115  , myInitialPos(pos)
116  , myCorner(false)
117  , myValid(false) {}
118 
119  // existing points to the respective 'left' and 'right' in terms of
120  // winding
121  GA_Index myLeft;
122  GA_Index myRight;
123  GA_Index myIndex;
124  GA_Index mySnap;
125 
126  UT_Vector3 myPos;
127  UT_Vector3 myInitialPos;
128  UT_Vector3 myLeftPos;
129  UT_Vector3 myRightPos;
130 
131  bool myCorner;
132  bool myValid;
133  };
134 
135  /****** functions ******/
136 
137  // Generates Slide Edge
138  void decideSlideEdge(const GU_Detail &geo, const UT_Array<Edge> &edges);
139 
140  // Helper function for decideSlideEdge that assigns 'left' and 'right'
141  // neighbours
142  void assignNeighbours(const GU_Detail &geo,
143  const UT_Array<GA_Index>& neighbours,
144  UT_Map<GA_Index, exint>& slidePointRef,
145  GA_Index point1, GA_Index point2, bool flipped,
146  int index);
147 
148  /****** members ******/
149  GU_RayIntersect *myTemplateGeoRayIntersect;
150  bool myIsLoop;
151  bool myIsValidEdge;
152  bool myMovingLeft;
153  GU_SlideMode myMode;
154  Edge myGrabEdge;
155  Edge myLastEdge;
156  // Indices for grabbed edge into mySlidePoints so that we don't need to
157  // look them up every time.
158  std::pair<exint, exint> myGrabEdgeIndices;
159  UT_Array<SlidePoint> mySlidePoints;
160 };
161 
162 #endif
GT_API const UT_StringHolder selection
Definition: UT_Set.h:58
GLsizei GLenum const void * indices
Definition: glcorearb.h:405
void setRayIntersect(GU_RayIntersect *rayintersect)
Definition: GU_EdgeSlide.h:103
Unsorted map container.
Definition: UT_Map.h:83
GLint left
Definition: glcorearb.h:2004
GU_SlideMode
Definition: GU_EdgeSlide.h:23
void setMode(GU_SlideMode mode)
Definition: GU_EdgeSlide.h:98
GU_SlideMode getMode() const
Definition: GU_EdgeSlide.h:97
3D Vector class.
bool isLoop() const
Definition: GU_EdgeSlide.h:94
Edge getGrabEdge()
Definition: GU_EdgeSlide.h:101
GU_RayIntersect * getRayIntersect() const
Definition: GU_EdgeSlide.h:102
void setGrabEdge(GA_Index p0, GA_Index p1)
Definition: GU_EdgeSlide.h:99
#define GU_API
Definition: GU_API.h:12
bool isMovingLeft() const
Definition: GU_EdgeSlide.h:96
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
GLenum mode
Definition: glcorearb.h:98
GLuint index
Definition: glcorearb.h:785
#define GA_INVALID_INDEX
Definition: GA_Types.h:653
bool isEmpty() const
Definition: GU_EdgeSlide.h:93
std::pair< GA_Index, GA_Index > Edge
Definition: GU_EdgeSlide.h:36
bool isValid() const
Definition: GU_EdgeSlide.h:95
GU_EdgeSlide(GU_RayIntersect *templateGeoRayIntersect=nullptr)
Definition: GU_EdgeSlide.h:40