HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_IORib.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 Conversion Utility Library (C++)
7  *
8  * COMMENTS:
9  * Save a gdp to RIB. This is not able to load or convert any files.
10  *
11  */
12 
13 #ifndef __GEO_IORib_h__
14 #define __GEO_IORib_h__
15 
16 #include "GEO_API.h"
17 #include "GEO_IOTranslator.h"
18 #include "GEO_IORibExt.h"
19 
20 #include <UT/UT_BitArray.h>
21 #include <UT/UT_IntArray.h>
22 #include <UT/UT_Array.h>
23 #include <GA/GA_AttributeRef.h>
24 #include <UT/UT_VectorTypes.h>
25 #include <TS/TS_Expression.h>
26 #include <iosfwd>
27 
28 class GEO_Detail;
29 class GEO_Primitive;
30 class GEO_PrimPoly;
31 class GEO_Vertex;
32 class GEO_IORibXlate;
33 class GEO_IORibPrinter;
34 class GEO_PrimParticle;
35 class GA_PrimitiveGroup;
36 
37 #define GEO_RIB_MAX_SEGMENTS 5
38 
40 {
41 public:
42  GEO_IORib();
43  virtual ~GEO_IORib();
44 
45  /// This method is used to create a copy of the sub-class
46  virtual GEO_IOTranslator *duplicate() const;
47 
48  virtual const char *formatName() const;
49 
50  virtual int checkExtension(const char *name);
51  virtual int checkMagicNumber(unsigned magic);
52 
53  virtual GA_Detail::IOStatus fileSave(const GEO_Detail *gdp, std::ostream &);
55 
56  // This method does not duplicate the geometry, make sure it's stays
57  // around while fileSave is called!
58  void setMBGeo(const GEO_Detail *gdp) { myGdps[1] = gdp; }
59  // Add gdp's in sequence
60  void addMBGeo(const GEO_Detail *gdp);
61  void setMBParticle(int onoff) { myBlurParticle = onoff; }
63  {
64  myOutPrimGroup = grp;
65  }
66 
67  //
68  // Setting the version of the renderer turns on extensions to the RIB
69  // stream. These extensions are defined in GEO_IORibExt.h. The different
70  // renderers we expect to see are:
71  // "rdc" - RenderDotC (Support Version 3.1)
72  // "bmrt" - BMRT (No extensions supported)
73  // "prman" - Pixar's RenderMan (Support Version 3.6 to 10.0)
74  //
75  void setVersion(const char *renderer,
76  int major=3, int minor=6)
77  {
78  myExtensions.setRenderer(renderer, major, minor);
79  }
80  // GEO_IO is being used for IFDs. If it's not flagged as being used for
81  // IFD's, shading interpolation will be set on and the normal attribute
82  // will be declared.
83  void setForIFD(int onoff=1) { myIFDFlag = onoff; }
84 
85  void setCurveBasis(const char *basis);
86  void setPolySubdivide(int on);
87  void setPoints(int on, float size=1);
88 
89  // The shutter speed is used for particle blur.
90  void setShutterSpeed(float shutter=1)
91  {
92  myShutterTime = shutter;
93  }
94 
95  // The following are public, but shouldn't really be called unless
96  // you really know what you're doing...
97  static void outputQuadricAttributes(GEO_IORibPrinter &,
98  const GEO_Primitive *, GA_Size vtx,
99  int dup = 4, float pscale = 1);
100  // This returns 1 if the "width" parameter was found, 0 if not.
101  static int outputParticleAttributes(GEO_IORibPrinter &out,
102  const GEO_PrimParticle *part,
103  float pscale=1, int dup=1,
104  int allow_N=0);
105 
106 private:
107  int isBlurred() const { return myGdps[1] != 0; }
108  int hasExtension(int ext)
109  {
110  return myExtensions.hasExtension(ext);
111  }
112 
113  const GEO_Detail *myGdps[GEO_RIB_MAX_SEGMENTS];
114  int mySegments;
115  GA_ROHandleV3 ptVel; // Point velocity
116  int myBlurParticle; // Motion blur particles
117 
118  unsigned myGeoFlag; // For geometry interpretation
119  float myPointSize; // Size for RiPoints()
120  float myShutterTime;
121 
122  const GA_PrimitiveGroup *myOutPrimGroup; // Motion blur gdp
123 
124 #if 0
125  int myParticleIndex;
126  UT_Array<GEO_Detail*> *myParticleDetails;
127  UT_Array<GEO_Detail*> *myParticleMBDetails;
128 #endif
129 
130  void outputPolysAttrib(GEO_IORibPrinter &, const GEO_Detail *,
131  const UT_BitArray &, const GEO_IORibXlate *,
132  const UT_IntArray *group);
133  void outputBlobbyAttrib(GEO_IORibPrinter &, const GEO_Detail *,
134  const GEO_IORibXlate *,
136  void outputCurvesAttrib(GEO_IORibPrinter &, const GEO_Detail *,
137  const GEO_IORibXlate *,
138  const char *curve_interp,
139  int curve_step);
140 
141  void outputParticleLinePosition(GEO_IORibPrinter &out,
142  const GEO_PrimParticle *part,
143  const GA_ROHandleV3 &vel,
144  float vscale);
145  void outputMatrix (GEO_IORibPrinter &out, const UT_Matrix4 &xform);
146  void outputBlobbies(GEO_IORibPrinter &out, int nblobs,
147  const GEO_Detail *gdp);
148  int outputPolys(GEO_IORibPrinter &out, const GEO_Detail *gdp);
149  void outputSubDivs(GEO_IORibPrinter &out);
150  void outputSubDivGroup(GEO_IORibPrinter &out,
151  const GEO_Detail *gdp,
152  UT_IntArray &group, // may be modified !
153  bool first_time);
154  int outputPolyCurves(GEO_IORibPrinter &out, const GEO_Detail *gdp,
155  const char *curve_interp, int curve_step);
156  void outputNURBSCurves(GEO_IORibPrinter &out, const GEO_Detail *gdp);
157  void outputMesh (GEO_IORibPrinter &out, const GEO_Primitive *prim);
158  void outputNURBS (GEO_IORibPrinter &out, const GEO_Primitive *prim);
159  void outputBezier (GEO_IORibPrinter &out, const GEO_Primitive *prim);
160  void outputSphere (GEO_IORibPrinter &out, const GEO_Primitive *p[]);
161  void outputTube (GEO_IORibPrinter &out, const GEO_Primitive *p[]);
162  void outputCircle (GEO_IORibPrinter &out, const GEO_Primitive *p[]);
163  void outputPoints (GEO_IORibPrinter &out, const GEO_Detail *gdp);
164  void outputParticles(GEO_IORibPrinter &out,
165  const GEO_Primitive *prim);
166  void outputParticlePoints(GEO_IORibPrinter &out,
167  const GEO_PrimParticle *part,
168  const GA_ROHandleV3 &vel,
169  float vscale, float pscale);
170  void outputParticleLines(GEO_IORibPrinter &out,
171  const GEO_PrimParticle *part,
172  float pscale);
173 
174  int isOutputPrim( const GEO_Primitive *prim );
175 
176 
177  static void outputExpressionBlobbies(GEO_IORibPrinter &out,
178  const TS_MetaExpressionPtr &expr,
179  int &floatAddr, int &exprNum);
180 
181  GEO_IORibExt myExtensions;
182  UT_Array<GEO_IORibXlate *> myTranslators;
183 
184  int myIFDFlag;
185 };
186 
187 // A wrapper class that implements buffered C-style output.
189 {
190 public:
191  GEO_IORibPrinter(std::ostream &os);
192  ~GEO_IORibPrinter();
193 
194  void print(const char *fmt, ...);
195  void print(const UT_Matrix4 &mat);
196 
197  std::ostream &getStream();
198  void flush();
199 private:
200  static const int theBufferSize;
201  static const int theBlockSize;
202 
203  std::ostream &myStream;
204  unsigned mySize;
205  unsigned myLineLen;
206  char *myFreeStart;
207  char *myFileBuffer;
208 };
209 
210 
211 #endif
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual GEO_IOTranslator * duplicate() const =0
This method is used to create a copy of the sub-class.
GLsizeiptr size
Definition: glcorearb.h:663
virtual GA_Detail::IOStatus fileLoad(GEO_Detail *gdp, UT_IStream &is, bool ate_magic)=0
void setVersion(const char *renderer, int major=3, int minor=6)
Definition: GEO_IORib.h:75
#define GEO_API
Definition: GEO_API.h:10
#define GEO_RIB_MAX_SEGMENTS
Definition: GEO_IORib.h:37
GLuint const GLchar * name
Definition: glcorearb.h:785
void setShutterSpeed(float shutter=1)
Definition: GEO_IORib.h:90
virtual const char * formatName() const =0
void setForIFD(int onoff=1)
Definition: GEO_IORib.h:83
virtual int checkExtension(const char *name)=0
GA_API const UT_StringHolder pscale
void setMBParticle(int onoff)
Definition: GEO_IORib.h:61
virtual int checkMagicNumber(unsigned magic)=0
void setMBGeo(const GEO_Detail *gdp)
Definition: GEO_IORib.h:58
virtual GA_Detail::IOStatus fileSave(const GEO_Detail *gdp, std::ostream &os)=0
void setOutputPrimGroup(const GA_PrimitiveGroup *grp)
Definition: GEO_IORib.h:62