HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PasteSurf.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 surface class.
9  *
10  */
11 
12 #ifndef __GEO_PasteSurf_h__
13 #define __GEO_PasteSurf_h__
14 
15 #include "GEO_API.h"
16 #include <UT/UT_RefMatrix.h>
17 #include <UT/UT_Vector2.h>
18 #include <GP/GP_Domain.h>
19 #include <GA/GA_Handle.h>
20 #include "GEO_PasteVertex.h"
21 
22 class GA_AttributeRefMap;
23 class GA_LoadMap;
24 class GA_SaveMap;
25 class GP_NodeList;
26 class GEO_Vertex;
28 class GEO_TPSurf;
29 class GEO_PasteSurfDAG;
30 
31 
33 {
34  friend class GEO_PasteSurfDAG;
35 
36 public:
37  // Class c-tors and d-tor
38  GEO_PasteSurf();
39  GEO_PasteSurf(GEO_TPSurf &tpsurf, const GP_XformHandle &xform,
40  int pasteup = 1, float height = 0);
41  GEO_PasteSurf(const GEO_PasteSurf &d);
42  ~GEO_PasteSurf() override;
43 
44  // Produce a brand new copy of ourselves. Must free it yourself.
45  // Does not copy the spline surface, just its primitive index!
46  GP_Node *copy() const override;
47 
48  // Create a a brand new object of the same type as us just using the
49  // default c-tor.
50  GP_Node *newSpecies() const override;
51 
52  // I/O functions returning 0 if OK and -1 otherwise.
53  int save(std::ostream &os, int binary = 0) const override;
54  bool load(UT_IStream &is) override;
55 
57  const GA_SaveMap &map) const override;
58  void initJSONLoad() override;
59  bool loadJSONField(UT_JSONParser &p, const GA_LoadMap &map,
60  const char *field_token) override;
61 
62  // Return a decreasing-order list of would-be parents listed in decreasing
63  // order in a stack of nodes.
64  void findParents(GP_NodeList &stack,
65  GP_NodeList &parents) override;
66  void findParent(GP_Domain &parent) override;
67 
68  // Spawn a child and link it to us, assign its frames accordingly, update
69  // its vertices, set its parent and base, etc. Return that domain if
70  // everything is successful, else 0. The child in the domain area defined
71  // by brect, and the ub/vb stuff are belt reinforcements.
72  GP_Domain *spawn(const UT_BoundingRect &brect,
73  float ubwidth = 0, float vbwidth = 0,
74  int ubdivs = 2, int vbdivs = 2,
75  int newkey = 0) override;
76 
77  // Evaluate at a world domain point and return 0 if successful, else -1:
78  bool evaluate(fpreal worldu, fpreal worldv,
81  unsigned du = 0, unsigned dv = 0) const;
82  bool evaluate(fpreal worldu, fpreal worldv,
84  GA_AttributeRefMap &map,
85  unsigned du = 0, unsigned dv = 0) const;
86 
87  int evaluate(float worldu, float worldv, UT_Vector4 &pos,
88  unsigned du = 0, unsigned dv = 0) const;
89 
90  // Make this surface's CVs independent of any base surfaces and reset the
91  // base surface pointers to point at myself:
92  void independentVertices(int preserve_shape = 1);
93 
94  // Translate all the CVs by an equal amount in world space:
95  void translateVertices(const UT_Vector3 &delta);
96 
97  // Update the frame origins by translating them because the CVs of the
98  // spline surface have been translated by this amount too.
99  void updateTranslation(const UT_Vector3 &delta);
100 
101  // Build the local frames using the current base surfaces, then apply
102  // the displacements to compute the world image. This is likely to
103  // change the contents of the GEO_Points.
104  void updateVertices();
105 
106  // Some vertices (or all) have changed, so reverse engineer our
107  // displacements from the CVs of the spline surface. In other words,
108  // given the local frames and the GEO_Points, build our displacements.
109  void updateDisplacements(int keepframes = 1);
110 
111  // Indicate that a CV has changed.
112  // These methods don't touch mySurf in any way, so make sure you do it
113  // yourself before calling us. Also, we don't flag the surface cache, and
114  // we don't update the hierarchy pasted on us. Better change all you have
115  // to change, then updateDescendents() from the DAG class.
116  // Another WARNING: we don't check if r and c are within bounds!
117  void updateDisplacement(int r, int c);
118 
119  // Recompute the vertices and the domain of the root surface such that
120  // the domain fits the root tightly, and the CVs are displaced from
121  // the Grevilles as tightly as possible.
122  void optimizeDisplacements(int update = 1);
123 
124  // Set the bases from a single parent. Be careful with this method.
125  void setBases(GEO_PasteSurf *base = 0);
126 
127  // A much cheaper version than modifyBasis(). To be called when the
128  // original basis has been remapped _affinely_ to another range, e.g.
129  // using GEO_TPSurf::mapU/VBasis(). The result should leave everything
130  // unchanged, including displacements, world image, base surfaces, etc.
131  // Don't even think of using it when reparameterizing the surface or
132  // refining it.
133  void affineBasis();
134 
135  /// Compute the texture coordinates either uniformly of chord length.
136  /// If ptattrib is true we deal with points, else with vertices.
137  /// Return the texture offset or -1 if problems.
138  bool rowColTexture (const GA_RWHandleV3 &txth, bool ptattrib = true);
139  bool uniformTexture (const GA_RWHandleV3 &txth, bool ptattrib = true);
140  bool grevilleTexture(const GA_RWHandleV3 &txth, bool ptattrib = true);
141  bool chordLenTexture(const GA_RWHandleV3 &txth, bool ptattrib = true);
142 
143  // Trim the underlying base(s):
144  void trimUnder(float scale = 1.0f, int keepoutside = 1);
145 
146  // Query or set the height, which is just an offset of the CV displacement:
147  float height() const { return myHeight; }
148  void height(float h);
149 
150  // Reset the spline surface pointer. If mutual, then we reset the
151  // surface's pointer to us as well. Use with care.
152  // Pardon the choice of names :-)
153  void sterilize(int mutual = 1);
154  void pregnant (GEO_TPSurf &s, int mutual=1, int rebuild=1);
155 
156  // Query or set the paste direction flag, and then possibly update the
157  // world image. Normally you want the image to update:
158  int pastedUp () const { return myPasteUp; }
159  void pasteUp (int updt=1) { flipPaste(1, updt); }
160  void pasteDown(int updt=1) { flipPaste(0, updt); }
161 
162  // Cautious handles to our frame and surface:
163  const GP_Frame &frame () const { return frames()->root(); }
164  const GEO_TPSurf &surface() const { return *mySurf; }
165 
166  // Determine if we are associated with a surface:
167  int hasSurface() const { return (mySurf) ? 1 : 0; }
168 
169  GEO_PasteSurfDAG *hierarchy() const; // return dag();
170 
171  // Index of spline primitive we should use as mySurf. To be used ONLY
172  // for loading purposes. myNum is never updated afterwards.
173  int primNumber() const { return myNum; }
174 
175 
176 protected:
177  // Copy the in nodes from a pool of already built nodes:
178  // Return 0 if OK and -1 otherwise.
179  int copyInNodes(const GP_Node &src,
180  const GP_NodeTree &destpool) override;
181 
182 
183 private:
184  GEO_TPSurf *mySurf;
186  GP_PointMatrix myGrev;
187  float myHeight;
188  int myPasteUp;
189  int myNum; // used ONLY to resolve loading
190 
191  // Special c-tor using for spawning.
192  GEO_PasteSurf(GEO_TPSurf &tpsurf, GEO_PasteSurf &parent, int spawnkey);
193 
194  // Assign us the the surface and vice versa, and update the GP_Domain's
195  // internals. Used during load.
196  void surface(GEO_TPSurf &tpsurf, int buildvertices = 1);
197 
198  // Compute the Greville matrix from the original basis information:
199  void buildGrevilles();
200 
201  // Set up the diffuse CV matrix by mapping the Greville space into 3D
202  // and computing CV displacements. Build the Grevilles first.
203  void buildVertices(int originalgrev = 1);
204 
205  // Change the local frame to point to the world greville image with an
206  // identity matrix. This is almost equivalent to pasting onto a plane.
207  // This method does not update the GEO_Points, so call updateWorldImage()
208  // if you need to.
209  void resetVertices();
210 
211  // Anything goes in terms of spline surface changes, especially if it
212  // involves changes of both knots and CVs, as in refinement, unrefinement,
213  // degree elevation, or cutting. If "standalone" is 1, we temporarily go
214  // back to our unpasted shape before calling (*apply)(). Return 0 if OK,
215  // else -1. This method resets the base surfaces to self, and does not
216  // update the GEO_Points if standalone is 1, so call updateWorldImage()
217  // if you need to.
218  int modifyBasis(int (*apply)(void *tpsurf, void *d),
219  void *data = 0,
220  int standalone = 1) override;
221 
222  // Assign myself to all the base surfaces:
223  void initializeBases();
224 
225  // Flip the pasting direction:
226  void flipPaste(int up, int updateimage = 1);
227 
228  // Update the texture coordinates of the surface by mapping the existing
229  // ones to the transformed domain (using the frame xform). txtoff must be
230  // >= 0 for anything to happen.
231  void updateTextureCoordinates(const GA_RWHandleV3 &txth,
232  bool ptattrib = true);
233 
234  // Assuming that everything is clean, load the world values of the
235  // transformed CVs into the GEO_Points.
236  void updateWorldImage();
237 
238  // A truly internal method, originalImage() loads the CVs from the original
239  // grevilles and displacements and ignores the current frames and world
240  // xform. Nothing else gets changed, so this is meant to be temporary.
241  // We use this to apply spline algorithms on the original surface (eg.
242  // refine it), and then go back to the pasted image.
243  void buildOriginalImage();
244 };
245 
246 #endif
GLdouble s
Definition: glew.h:1390
virtual bool load(UT_IStream &is)
GP_FrameHierarchy * frames() const
Definition: GP_Domain.h:73
virtual void initJSONLoad()
GLenum src
Definition: glew.h:2410
void pasteUp(int updt=1)
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
bool rowColTexture(const GA_RWHandleV3 &txth, bool ptattrib)
bool chordLenTexture(const GA_RWHandleV3 &txth, bool ptattrib)
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:13880
bool grevilleTexture(const GA_RWHandleV3 &txth, bool ptattrib)
virtual bool loadJSONField(UT_JSONParser &p, const GA_LoadMap &map, const char *field_token)
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1252
const GP_CorrectionFrame & root() const
virtual void findParent(GP_Domain &parent)=0
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:76
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
virtual void findParents(GP_NodeList &stack, GP_NodeList &parns)=0
GP_Node * copy() const override
virtual GP_Node * newSpecies() const
GA_Size GA_Offset
Definition: GA_Types.h:639
GLclampf f
Definition: glew.h:3499
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
const GLuint GLenum const void * binary
Definition: glew.h:3502
virtual int save(std::ostream &os, int binary=0) const
int primNumber() const
virtual int copyInNodes(const GP_Node &src, const GP_NodeTree &destpool)
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
void optimizeDisplacements(int update=1)
const GLfloat * c
Definition: glew.h:16296
#define GEO_API
Definition: GEO_API.h:14
virtual bool saveJSONFields(UT_JSONWriter &w, const GA_SaveMap &map) const
A handle to simplify manipulation of multiple attributes.
Options during loading.
Definition: GA_LoadMap.h:42
void pasteDown(int updt=1)
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
int hasSurface() const
const GEO_TPSurf & surface() const
GLfloat GLfloat p
Definition: glew.h:16321
virtual int modifyBasis(int(*apply)(void *tpsurf, void *d), void *data=0, int standalone=1)=0
bool uniformTexture(const GA_RWHandleV3 &txth, bool ptattrib)
GA_API const UT_StringHolder up
virtual GP_Domain * spawn(const UT_BoundingRect &brect, float ubwidth=0, float vbwidth=0, int ubdivs=2, int vbdivs=2, int newkey=0)=0
fpreal64 fpreal
Definition: SYS_Types.h:277
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
GLuint64EXT * result
Definition: glew.h:14007
int updateDisplacements(GP_Domain &child, int keepframes=1) override
const GP_Frame & frame() const
bool evaluate(fpreal u, fpreal v, GEO_Vertex result, GEO_AttributeHandleList &hlist, unsigned du=0, unsigned dv=0) const
int pastedUp() const
float height() const