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