HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GP_Domain.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: Domain pasting Library (C++)
7  *
8  * COMMENTS: Paste domain class.
9  *
10  */
11 
12 #ifndef __GP_Domain_h__
13 #define __GP_Domain_h__
14 
15 #include "GP_API.h"
16 #include <iosfwd>
17 #include <UT/UT_BoundingRect.h>
18 #include "GP_FrameHierarchy.h"
19 #include "GP_Node.h"
20 
21 class UT_IStream;
22 class GA_SaveMap;
23 class GA_LoadMap;
24 class GP_FrameHierarchy;
25 class GP_DomainDAG;
26 class GP_NodeList;
27 
28 
29 class GP_API GP_Domain : public GP_Node
30 {
31 public:
32  // Class c-tors and d-tor
33  GP_Domain(void);
34  GP_Domain(const UT_BoundingRect &original,
35  const GP_XformHandle &xform,
36  int key = 0);
37  GP_Domain(const GP_Domain &d);
38  virtual ~GP_Domain(void);
39 
40  // Produce a brand new copy of ourselves. Must free it yourself.
41  // Does not copy the frames recursively!
42  virtual GP_Node *copy(void) const;
43 
44  // I/O functions returning 0 if OK and -1 otherwise.
45  virtual int save(std::ostream &os, int binary = 0) const;
46  virtual bool load(UT_IStream &is);
47 
48  virtual bool saveJSONFields(UT_JSONWriter &w,
49  const GA_SaveMap &map) const;
50  virtual void initJSONLoad();
51  virtual bool loadJSONField(UT_JSONParser &p,
52  const GA_LoadMap &map,
53  const char *field_token);
54 
55  // Return a decreasing-order list of would-be parents listed in decreasing
56  // order in a stack of nodes.
57  virtual void findParents(GP_NodeList &stack, GP_NodeList &parns)=0;
58  virtual void findParent (GP_Domain &parent)=0;
59 
60  // Spawn a child and link it to us, assign its frames accordingly, etc.
61  virtual GP_Domain *spawn(const UT_BoundingRect &brect,
62  float ubwidth = 0, float vbwidth = 0,
63  int ubdivs = 2, int vbdivs = 2,
64  int newkey = 0) = 0;
65 
66  // Anything goes in terms of spline changes, especially if it
67  // involves changes of both knots and CVs, as in refinement, unrefinement,
68  // degree elevation, or cutting. Return 0 if OK, else -1.
69  virtual int modifyBasis(int (*apply)(void *tpsurf, void *d),
70  void *data = 0, int standalone = 1) = 0;
71 
72  // Query or set the frame hierarchy. Use with care.
74  {
75  return myFrames;
76  }
78  {
79  if (myFrames && myOwnFrames) delete myFrames;
80  myFrames = f;
81  myOwnFrames = 0;
82  }
83 
84  // The DAG we live in:
85  GP_DomainDAG *dag(void) const;
86 
87  // Update node if a transformation has occurred:
88  void update(void);
89 
90  // Return the 4 values stored in the polygon. It first updates itself:
91  void polygon(GP_Point &p1, GP_Point &p2, GP_Point &p3,
92  GP_Point &p4)
93  {
94  update();
95  p1 = myWorldPoly[0];
96  p2 = myWorldPoly[1];
97  p3 = myWorldPoly[2];
98  p4 = myWorldPoly[3];
99  }
100 
101  // If we're pasted, grab the parent domain:
102  GP_Domain *parentDomain(void) const
103  {
104  return (myFrames && myFrames->parent())
105  ? myFrames->parent()->domain() : 0;
106  }
107 
108  // Convert p from world to our space and return 0 if OK, -1 if bad.
109  // This a a safer method than the GP_Frame counterpart because it
110  // checks the result against the original brect (myOriginal) -- needed
111  // when the xform is linear because linears never fail.
112  int fromWorld(GP_Point &p) const;
113 
114  // Check if the world polygon contains the given point. If quick is true
115  // we do only a bbox test. We assume the polygon is up-to-date.
116  int contains(const GP_Point &worldp, int quick=0) const;
117 
118  // Check if we fully contain the other domain. If quick is true we do only
119  // a bbox test. We assume the polygons are up-to-date.
120  int contains(const GP_Domain &d, int quick = 0) const;
121 
122  // Check if we intersect the other domain. If quick is true we do only
123  // a bbox test. We assume the polygons are up-to-date.
124  int intersects(const GP_Domain &d, int quick = 0) const;
125 
126  // Intersect our transformed domain with a world line and return the
127  // parametric value 't' of the line at the intersection point. If
128  // t is not in [0,1], we don't actually intersect.
129  float intersect(const GP_Point &a, const GP_Point &b) const;
130 
131  // Find out if we're in a paste graph, ie. if we have a parent or not:
132  int isFeature() const { return myFrames->parent() != 0; }
133 
134  // Query or set the "relative" pointer:
135  GP_Domain *relative(void) const { return myRelative; }
136  void relative(GP_Domain *d) { myRelative = d; }
137 
138  // Get a const handle to the original rectangle, which corresponds to
139  // the size of the valid interval, or set the brect and update the
140  // world poly.
141  const UT_BoundingRect &originalBRect() const { return myOriginal; }
142  void originalBRect(const UT_BoundingRect &brect)
143  {
144  myOriginal = brect;
145  updatePolygon();
146  }
147  // Replace the original brect but make sure it does not affect the world
148  // image (which means we must xform the personalXform and the children)
149  void safeOriginalBRect(const UT_BoundingRect &);
150 
151  // Return the world bounding rectangle. The non-const method will
152  // first update the polygon.
153  const UT_BoundingRect &worldBRect() const { return myWorldRect; }
154  const UT_BoundingRect &worldBRect() { update(); return myWorldRect; }
155 
156 
157 protected:
158  // Update the polygon if a transformation has occurred. This assumes the
159  // frame is up to date (ie. the frame hierarchy has been updated.
160  // Also see update(). The polygon is assumed convex.
161  void updatePolygon(void);
162 
163 
164 private:
165  GP_FrameHierarchy *myFrames; // frame we live in
166  UT_BoundingRect myOriginal; // non-transformed domain
167  UT_BoundingRect myWorldRect; // bounding rect for poly
168  GP_Point myWorldPoly[4];// domain boundaries (xformed to world)
169  int myOwnFrames; // do we own these frames?
170 
171  GP_Domain *myRelative; // used in DAG traversals
172 };
173 
174 #endif
#define GP_API
Definition: GP_API.h:10
const UT_BoundingRect & worldBRect() const
Definition: GP_Domain.h:153
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GP_Domain * relative(void) const
Definition: GP_Domain.h:135
const UT_BoundingRect & worldBRect()
Definition: GP_Domain.h:154
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
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
GLfloat f
Definition: glcorearb.h:1925
int isFeature() const
Definition: GP_Domain.h:132
void originalBRect(const UT_BoundingRect &brect)
Definition: GP_Domain.h:142
bool intersect(const Line3< T > &line, const Vec3< T > &v0, const Vec3< T > &v1, const Vec3< T > &v2, Vec3< T > &pt, Vec3< T > &barycentric, bool &front)
void polygon(GP_Point &p1, GP_Point &p2, GP_Point &p3, GP_Point &p4)
Definition: GP_Domain.h:91
GP_FrameHierarchy * frames(void) const
Definition: GP_Domain.h:73
Options during loading.
Definition: GA_LoadMap.h:42
GLboolean * data
Definition: glcorearb.h:130
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GP_Domain * parentDomain(void) const
Definition: GP_Domain.h:102
bool intersects(const Box< Vec3< T > > &b, const Line3< T > &r, Vec3< T > &ip)
Definition: ImathBoxAlgo.h:728
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const UT_BoundingRect & originalBRect() const
Definition: GP_Domain.h:141
void relative(GP_Domain *d)
Definition: GP_Domain.h:136
virtual GP_Node * copy(void) const
void frames(GP_FrameHierarchy *f)
Definition: GP_Domain.h:77