HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_EdgeUtils.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: GU Library.
7  *
8  * COMMENTS: This file contains useful edge related tools.
9  *
10  */
11 
12 #pragma once
13 
14 #ifndef __GU_EdgeUtils_h__
15 #define __GU_EdgeUtils_h__
16 
17 #include "GU_API.h"
18 #include <GA/GA_Edge.h>
19 #include <GA/GA_ElementWrangler.h>
20 #include <UT/UT_Vector3.h>
21 #include <UT/UT_Vector4.h>
22 #include <stddef.h>
23 
24 class GEO_Face;
25 class GEO_PrimPoly;
26 class GEO_Detail;
27 class GA_EdgeGroup;
28 class GA_PrimitiveGroup;
29 class GU_Detail;
30 
32 {
33 public:
34  GU_EdgeDiv(const GEO_PrimPoly &poly, const GA_Edge &edge, int numcuts,
35  float fraction) :
36  myPoly(poly), myEdge(edge), myNumCuts(numcuts), myFraction(fraction)
37  {
38  UT_ASSERT(SYSisLessOrEqual(fraction * numcuts, 1.0f));
39  }
40 
43  int myNumCuts;
44  float myFraction;
45 };
46 
47 ////////////////////////////////////////////////////////////////////
48 // Useful edge-related functions
49 
50 // Computes the position resulting from insetting vertex at index "vtx" of
51 // "face" by an amount of "inset".
52 GU_API extern UT_Vector3 GUcomputeInsetPos(const GEO_Face &face, int vtx,
53  float inset);
54 
55 // Returns true if the three points are collinear and false otherwise.
56 GU_API extern bool GUisPointInline(const UT_Vector3 &start,
57  const UT_Vector3 &mid,
58  const UT_Vector3 &end, float tol);
59 
60 // Gets the points corresponding to edge edgenum in face. Returns true if
61 // successful, and false otherwise. A true return status does not imply that
62 // both p0 and p1 are valid.
63 GU_API extern bool GUgetEdgePoints(const GEO_Face &face, int edgenum,
64  GA_Offset &p0, GA_Offset &p1);
65 
66 /// Iterates through the primitives of the detail, calling edgeApply
67 /// on each primitive to count the number of times each (unordered) edge is
68 /// present, and adds any edges that appear only once.
69 /// If prims_on_edges is true, each edge in the edge group will
70 /// reference the primitive it's associated with.
71 /// WARNING: A lot of things can go bonkers if you use prims_on_edges!
72 /// For example, toggling the edge group will result in a
73 /// group that contains all of the original edges plus
74 /// every edge, so more edges than the total number.
76  const GEO_Detail &detail,
77  GA_EdgeGroup &edges,
78  const GA_PrimitiveGroup *primgroup = NULL,
79  bool prims_on_edges = false);
80 
81 /// Iterates through the primitives of the detail, calling edgeApply
82 /// on each primitive to count the number of times each (unordered) edge is
83 /// present, and adds any edges that appear only once, in the direction
84 /// they appear.
85 /// WARNING: GA_DirectedEdgeSet is an unordered set, so iteration order
86 /// can't be relied upon if you use that version.
87 /// @{
89  const GEO_Detail &detail,
90  GA_DirectedEdgeSet &edges,
91  const GA_PrimitiveGroup *primgroup = NULL);
93  const GEO_Detail &detail,
95  const GA_PrimitiveGroup *primgroup = NULL);
96 /// @}
97 
98 // convenience function to split an edge loop on the given detail with the
99 // loops(s) specified by pt0, pt1 and either u, or if splits is non-zero, splits
100 // number of edge loops evenly spaced along the edge, or if parallel is true
101 // then it is an equal edge length split
102 // This is also an example of how to calculate the edge loop and then apply it
103 // if you want to do it yourself elsewhere
104 // warningCoords is filled with coordinates of points that are clamped when
105 // a parallel loop hits the edge of the defining loop
107  fpreal u, exint splits = 0, bool parallel = false,
108  GA_EdgeGroup *edgeGroup = NULL,
109  UT_Fpreal32Array* warningCoords = NULL);
110 
111 // utility class to help identify individual splits when splitting a new edge
112 // loop - used by topobuild state and the polysplit sop
114 {
115 public:
116  // pt0 pt1 defines the edge which the edge loop will be generated from
117  GU_LoopFinder(const GU_Detail &gdp, GA_Offset pt0, GA_Offset pt1);
118 
119  const UT_Array<GA_Edge> &getSplits() const { return mySplits; }
120 
121  // cu is the edge percentage to create a single loop at. Ignored if
122  // splits > 0
123  // splits is the number of loops to create. Values > 0 force the positions
124  // pts0 is the starts of the edges
125  // pts1 is the ends of the new edges
126  // pos is the positions of the new points
127  // us is the list of edge percentages of the new points
128  // pts0, pts1, pos, and us are to be passed in as newly initialized
129  // structures which are filled in by this method. Each element of pts0 is
130  // paired with an element of pts1. If the pts1 element is GA_INVALID_INDEX,
131  // then the point has already been created by a previous split edge, and the
132  // pts0 element is just the index of that point. pos and us only contain an
133  // element for each non-GA_INVALID_INDEX value in pts1, and have been
134  // compacted, so a separate index needs to be maintained while iterating
135  // over these arrays.
136  void findAllLoops(fpreal cu, exint splits, GA_IndexArray &pts0,
137  GA_IndexArray &pts1, UT_Vector3Array &pos, UT_FprealArray &us) const;
138  // similare to the previous funcion, but follows one side of the defining
139  // geometry. dist is the distance along each edge to cross at, and
140  // warningCoords will be filled with a list of positions which are collided
141  // with when the distance is larger than the edge being crossed. This can
142  // be used to render these points as warnings in MSS files.
143  void findAllParallelLoops(fpreal dist, exint splits, GA_IndexArray &pts0,
145  UT_Fpreal32Array* warningCoords = NULL) const;
146 
147 private:
148  void split(const GEO_PrimPoly *poly, exint i);
149  void splitH15_5(const GEO_PrimPoly *poly, exint i);
150  bool getManifoldQuads(GA_Offset pt0, GA_Offset pt1,
151  GA_Offset &vtx0, GA_Offset &vtx1,
152  GA_OffsetArray &scratch) const;
153 
154  const GU_Detail &myGdp;
155  // list of edge pairs defining polygons being split
156  UT_Array<GA_Edge> mySplits;
157 };
158 
159 // utility class to actually change the geometry of the detail to add splits
160 // used by the topobuild and polysplit sops
162 {
163 public:
165 
166  GA_Offset splitEdge(GA_Offset pt0, GA_Offset pt1, fpreal u);
167  void splitPolygons(GA_Offset pt0, GA_Offset pt1);
168 
169 private:
170  GU_Detail &myGdp;
171  GA_PointWrangler myPointWrangler;
172  GA_PrimitiveWrangler myPrimWrangler;
173  GA_VertexWrangler myVtxWrangler;
174 };
175 
176 // utility function that will move connected points into circles
177 // only loops containing points participating in two edges will be moved
179  const GU_Detail &gdp,
180  const UT_Set<GA_Edge> &gaedges);
181 
182 // utility function that tries to make all connected edges the same length
183 // each connected island edges will move towards its own target length
185  const GU_Detail &gdp,
186  const UT_Set<GA_Edge> &gaedges);
187 
188 // utility function that will project connected points along a line
189 // only points participating in two edges will be moved
191  const GU_Detail &gdp,
192  const UT_Set<GA_Edge> &gaedges,
193  const UT_Vector3 *constrain_nml);
194 #endif
GA_Edge myEdge
Definition: GU_EdgeUtils.h:42
GA_API const UT_StringHolder dist
GU_API void GUfindUnsharedEdges(const GEO_Detail &detail, GA_EdgeGroup &edges, const GA_PrimitiveGroup *primgroup=NULL, bool prims_on_edges=false)
const GEO_PrimPoly & myPoly
Definition: GU_EdgeUtils.h:41
Unsorted map container.
Definition: UT_Map.h:83
GU_API void GUedgeLoopSplit(GU_Detail &gdp, GA_Offset pt0, GA_Offset pt1, fpreal u, exint splits=0, bool parallel=false, GA_EdgeGroup *edgeGroup=NULL, UT_Fpreal32Array *warningCoords=NULL)
GLuint start
Definition: glcorearb.h:474
GU_EdgeDiv(const GEO_PrimPoly &poly, const GA_Edge &edge, int numcuts, float fraction)
Definition: GU_EdgeUtils.h:34
GU_API void GUevenlySpaceEdges(UT_Map< GA_Offset, UT_Vector3 > &edits, const GU_Detail &gdp, const UT_Set< GA_Edge > &gaedges)
3D Vector class.
png_uint_32 i
Definition: png.h:2877
GA_Size GA_Offset
Definition: GA_Types.h:617
GLfloat f
Definition: glcorearb.h:1925
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
int64 exint
Definition: SYS_Types.h:109
GLuint GLuint end
Definition: glcorearb.h:474
#define GU_API
Definition: GU_API.h:11
GU_API bool GUgetEdgePoints(const GEO_Face &face, int edgenum, GA_Offset &p0, GA_Offset &p1)
GU_API UT_Vector3 GUcomputeInsetPos(const GEO_Face &face, int vtx, float inset)
double fpreal
Definition: SYS_Types.h:263
GU_API void GUcircleEdges(UT_Map< GA_Offset, UT_Vector3 > &edits, const GU_Detail &gdp, const UT_Set< GA_Edge > &gaedges)
const UT_Array< GA_Edge > & getSplits() const
Definition: GU_EdgeUtils.h:119
GU_API void GUstraightenEdges(UT_Map< GA_Offset, UT_Vector3 > &edits, const GU_Detail &gdp, const UT_Set< GA_Edge > &gaedges, const UT_Vector3 *constrain_nml)
float myFraction
Definition: GU_EdgeUtils.h:44
GU_API bool GUisPointInline(const UT_Vector3 &start, const UT_Vector3 &mid, const UT_Vector3 &end, float tol)