HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PasteSurfDAG.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: Geometry Library (C++)
7  *
8  * COMMENTS: Paste DAG class.
9  *
10  */
11 
12 #ifndef __GEO_PasteSurfDAG_h__
13 #define __GEO_PasteSurfDAG_h__
14 
15 #include "GEO_API.h"
16 #include <GP/GP_DomainDAG.h>
17 #include <GA/GA_Handle.h>
18 #include "GEO_PasteSurf.h"
19 
20 class GA_AttributeRefMap;
21 class GA_PointGroup;
22 class GA_SaveMap;
23 class GA_LoadMap;
24 class GA_Defragment;
25 class GEO_Vertex;
27 class UT_IStream;
28 
30 {
31 public:
32  // C-tor with 0 nodes. Can't paste on it.
33  GEO_PasteSurfDAG(void);
34 
35  // The root this c-tor assigns to its root cannot be already pasted
36  // somewhere else.
38 
39  // Shallow copy c-tor: same nodes, but different lists.
40  GEO_PasteSurfDAG(const GEO_PasteSurfDAG &srcdag);
41  GEO_PasteSurfDAG(const GP_DomainDAG &srcdag);
42 
43  // D-tor that destroys all the nodes (thanks to its base class).
44  virtual ~GEO_PasteSurfDAG(void);
45 
46  // Clear the graph and destroy the nodes as well. If "total" is
47  // 1, even the GEO_TPSurfs will be deleted; otherwise the GEO_TPSurfs
48  // will be disconnected by removing their pasted pointer, and will
49  // survive.
50  virtual void clearAndDestroy(int total = 1);
51 
52  // Evaluate one point (when du=dv=0), or the du-th dv-th derivative.
53  // Return 0 if successful, and -1 otherwise. origu and origv must lie
54  // in the original domain of the root surface. The root is assumed present.
55  bool evaluate(fpreal u, fpreal v, GEO_Vertex result,
57  unsigned du=0, unsigned dv=0) const;
58  bool evaluate(fpreal u, fpreal v, GA_Offset result,
59  GA_AttributeRefMap &map, unsigned du=0,
60  unsigned dv=0) const;
61  int evaluate(float origu, float origv, UT_Vector4 &pos,
62  unsigned du = 0, unsigned dv = 0) const;
63 
64  // Evaluate the unit normal at (origu,origv). origu and origv must lie
65  // in the original domain of the root surface. The root is assumed present.
66  // Return 0 if successful, else -1.
67  int evaluateNormal(float origu,float origv,
68  UT_Vector3 &nml) const;
69 
70  // Evaluate the surface between breakpoints. 'lod' is
71  // the number of points between two breakpoints in u or v. The methods
72  // compute the number of spans in v if vspans is -1. The number of isoparms
73  // computed in v is returned if OK; else -1. Pass in the bkpoint index of
74  // the startidx knot if you know it.
75  int fillBreakMesh(int ustartidx, int ustopidx,
76  int vstartidx, int vstopidx,
77  int ulod, int vlod,
78  UT_Vector4 *pos, int &vspans /* = -1 */,
79  int vbreakidx = -1,
80  unsigned du = 0, unsigned dv = 0,
81  UT_FloatArray *uval = 0,
82  UT_FloatArray *vval = 0) const;
83  int fillBreakMesh(int ustartidx, int ustopidx,
84  int vstartidx, int vstopidx,
85  int ulod, int vlod,
86  GEO_Vertex **result,
88  int &vspans, int vbreakidx = -1,
89  unsigned du = 0, unsigned dv = 0) const;
90 
91  // Increase the order. Return 0 if successful, -1 otherwise (eg.
92  // order cannot be increased because it's >= MAXORDER).
93  // Return -1 if child isn't ours, else if all OK, 0.
94  int raiseOrderU(GEO_PasteSurf &child, int neworder,
95  GA_AttributeRefMap &map);
96  int raiseOrderU (GEO_PasteSurf &child, int neworder);
97  int raiseOrderV(GEO_PasteSurf &child, int neworder,
98  GA_AttributeRefMap &map);
99  int raiseOrderV (GEO_PasteSurf &child, int neworder);
100 
101  // U and V knot insertion methods. Return inserted index or -1.
102  int refineU(GEO_PasteSurf &c, float k,
103  GA_AttributeRefMap &hlist, int r=1);
104  int refineU (GEO_PasteSurf &c, float k, int r=1);
105 
106  int refineV(GEO_PasteSurf &c, float k,
107  GA_AttributeRefMap &hlist, int r=1);
108  int refineV (GEO_PasteSurf &c, float k, int r=1);
109 
110  // Refine an area around the boundary of the surface, called the "belt".
111  // Return 0 if OK, else -1.
112  int refineBelt(GEO_PasteSurf &child,
113  float ubwidth = 0.4F, float vbwidth = 0.4F,
114  int ubdivs = 2, int vbdivs = 2);
115 
116  // Remove rows and or columns based on a curvature tolerance. Return 1 of
117  // something was removed, 0 if nothing removed, and -1 if c is not a
118  // child.
119  int unrefineU(GEO_PasteSurf &c, int kidx,
120  GA_AttributeRefMap &hlist,
121  int mult=0, float tol=1e-4F,
122  GA_PointGroup *delgroup = 0);
123  int unrefineU (GEO_PasteSurf &c, int kidx,
124  int mult=0, float tol=1e-4F,
125  GA_PointGroup *delgroup = 0);
126 
127  int unrefineV(GEO_PasteSurf &c, int kidx,
128  GA_AttributeRefMap &hlist,
129  int mult=0, float tol=1e-4F,
130  GA_PointGroup *delgroup = 0);
131  int unrefineV (GEO_PasteSurf &c, int kidx,
132  int mult=0, float tol=1e-4F,
133  GA_PointGroup *delgroup = 0);
134 
135  // Reverse rows (V) or columns (U). Reversing in either direction will
136  // flip the normal. Return -1 if child isn't ours, else 0.
137  int reverseU(GEO_PasteSurf &child);
138  int reverseV(GEO_PasteSurf &child);
139 
140  // Reparameterize the surface by changing its basis. This type of
141  // reparameterization is generally NOT shape preserving.
142  // Return -1 if child isn't ours, else 0.
143  int reparameterizeU(GEO_PasteSurf &child,
145  int reparameterizeV(GEO_PasteSurf &child,
147 
148  // Unpaste a surface alone or with all its contained children. If you know
149  // what the contained set is, pass it in for speed. Don't try to unpaste
150  // the root surface unless it has no kids. If preserveshape is 1,
151  // preservexform is ignored. If preserveshape is 0, we have the option to
152  // keep the domain xform as it is or reset it to identity.
153  GEO_PasteSurf *unpasteAt (GEO_PasteSurf &child, int preserveshape=0,
154  int preservexform=0);
156  int preserveshape=0,
157  int preservexform=0);
158 
159  // Change the height of the unpasted vertices by the given amount either
160  // for a single surface or for it and all of its descendents. Return 0
161  // if surf is pasted on us, else -1.
162  int offsetAt (GEO_PasteSurf &surf, float height);
163  int offsetFrom(GEO_PasteSurf &surf, float height);
164  int height(float newheight)
165  {
166  return (rootSurface())
167  ? offsetAt(*rootSurface(),newheight) : -1;
168  }
169 
170  // Reverse the pasting direction of the given surface and make sure
171  // everybody pasted on it partially or fully is refreshed.
172  // Return 0 if child is pasted on us, else -1.
173  int flipAt (GEO_PasteSurf &child);
174  int flipFrom(GEO_PasteSurf &child);
175  int flip (void)
176  {
177  return (rootSurface())?flipFrom(*rootSurface()):-1;
178  }
179 
180  // Make sure the xforms, the displacements and the world image are up
181  // to date:
182  void updateHierarchy(void);
183 
184  // Recompute the vertices and the domain of the root surface such that
185  // the domain fits the root tightly, and the CVs are displaced from
186  // the Grevilles as tightly as possible.
187  void optimizeDisplacements(int update = 1);
188 
189  // Copy from the source. Shallow in the nodes. All out nodes are
190  // destroyed first. Be careful.
193 
194  // Assuming "child" is the root of a newly pasted DAG, link it to its
195  // parent domain(s) (top containers) in our DAG. The methods make sure
196  // everything is (re)pasted and updated accordingly. The bases are
197  // already set at this point by findParents().
198  virtual void link(GP_Domain &child, GP_NodeList &parents,
199  int keepshape = 0);
200  virtual void link(GP_Domain &child, GP_Domain &parent,
201  int withcorrection = 1);
202 
203  // Assuming child is pasted on us, update the pasted image of all of
204  // surf's descendents in pasted order. surf is not updated.
205  // Return 0 upon success, else -1.
206  virtual int updateDescendents(GP_Domain &child,
207  int including_child = 0);
208 
209  // Some vertices (or all) have changed, so reverse engineer the
210  // displacements from the CVs of the spline surface. In other words,
211  // given the local frames and the GEO_Points, build the displacements for
212  // the child node, then update its descendents. Return -1 if not our child.
213  virtual int updateDisplacements(GP_Domain &child,
214  int keepframes = 1);
215 
216  // Use this method after loading to make sure all the proper links are
217  // set. ONLY after loading. Return 0 is OK and -1 otherwise.
218  int pasteInPlace(GEO_PasteSurf &ps, GEO_TPSurf &tpsurf);
219 
220  /// Compute the texture coordinates either uniformly of chord length. If
221  /// the attribute is invalid, the methods find it and create the attribute
222  /// if necessary. If ptattrib is true we deal with points, else with vertices.
223  /// Returns false iff problems.
224  bool rowColTexture (const GA_RWHandleV3 &txth, bool ptattrib);
225  bool uniformTexture (const GA_RWHandleV3 &txth, bool ptattrib);
226  bool grevilleTexture(const GA_RWHandleV3 &txth, bool ptattrib);
227  bool chordLenTexture(const GA_RWHandleV3 &txth, bool ptattrib);
228 
229  // Traverse the paated surfaces in the order in which they were pasted.
230  // Stop the traversal if the applied function returns zero.
231  int traverse (int (*f)(const GEO_PasteSurf*,void*),
232  void *d) const;
233  int traverseBackward(int (*f)(const GEO_PasteSurf*,void*),
234  void *d) const;
235 
236  // The public can only look at the root but not change it because things
237  // are tricky in the hierarchy:
238  const GEO_PasteSurf *rootSurface() const
239  {
240  return (const GEO_PasteSurf*) root();
241  }
242 
243  // I/O functions returning 0 if OK and -1 otherwise.
244  // In inFromH9() all the nodes and the frames are loaded in, but they are
245  // not connected to each other in any way. The pointers to TPSurfs are
246  // not set either, but we have loaded the primitive numbers. The reason we
247  // cannot resolve them now is that we're not sure the primitives have been
248  // loaded. Once the primitives are loaded, call resolveLinks() in the
249  // derived class.
250  bool outToH9 (std::ostream &os, int binary = 0) const;
251  bool inFromH9(UT_IStream &is);
252 
253  bool saveHierarchy(UT_JSONWriter &w,
254  const GA_SaveMap &map) const;
255  bool loadHierarchy(UT_JSONParser &p,
256  const GA_LoadMap &map);
257 
258 protected:
259  // Let us know when something has changed in the root domain.
260  virtual void changedRoot(void);
261 
262  // Derived classes get a full look at the root with a non-const handle:
264 
265  // Virtual (shallow) c-tor that can be used by classes derived
266  // from us to instantiate themselves at this level:
267  virtual GEO_PasteSurfDAG *newDAGSpecies(void) const;
268  int fillVCurve(float u,int uidx, int vstartidx,int vstopidx,
269  int density, UT_Vector4 *pos, int pvoffset,
270  int rbound, unsigned du, unsigned dv) const;
271  int fillVCurve(float u, int uidx, int vstartidx,
272  int vstopidx, int density,
273  GEO_Vertex **result,
275  int pvoffset, int rbound,
276  unsigned du, unsigned dv) const;
277 
278 };
279 
280 #endif
virtual void changedRoot(void)
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
const GEO_PasteSurf * rootSurface() const
const GLdouble * v
Definition: glcorearb.h:836
int height(float newheight)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GP_Domain * unpasteAt(GP_Domain &child)
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
int pasteInPlace(GP_Domain &child)
GA_ParameterizationType
Definition: GA_Types.h:173
GA_Size GA_Offset
Definition: GA_Types.h:617
GP_DomainDAG & operator=(const GP_DomainDAG &src)
GLfloat f
Definition: glcorearb.h:1925
GP_DomainDAG * unpasteFrom(GP_Domain &child, GP_NodeTree *ctree=0)
#define GEO_API
Definition: GEO_API.h:10
virtual void link(GP_Domain &child, GP_NodeList &parents, int keepshape=0)
A handle to simplify manipulation of multiple attributes.
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
virtual int updateDescendents(GP_Domain &child, int including_child=0)
GLint GLsizei GLsizei height
Definition: glcorearb.h:102
double fpreal
Definition: SYS_Types.h:270
const GP_Domain * root(void) const
Definition: GP_DomainDAG.h:206
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GLboolean r
Definition: glcorearb.h:1221
virtual int updateDisplacements(GP_Domain &child, int keepframes=1)
GEO_PasteSurf * rootSurface()
virtual void clearAndDestroy(int total=1)
GLenum src
Definition: glcorearb.h:1792