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