root/OpenSceneGraph/trunk/src/osgPlugins/ive/Shape.cpp @ 13041

Revision 13041, 10.6 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            HeightField.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::HeightField in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerator
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 27.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Shape.h"
17#include "Object.h"
18
19#include <osg/Endian>
20
21using namespace ive;
22
23
24////////////////////////////////////////////////////////////////////////////////
25//
26//  Sphere
27//
28void Sphere::write(DataOutputStream* out)
29{
30    // Write CullFace's identification.
31    out->writeInt(IVESPHERE);
32    // If the osg class is inherited by any other class we should also write this to file.
33    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
34    if(obj)
35    {
36        ((ive::Object*)(obj))->write(out);
37    }
38    else
39        out_THROW_EXCEPTION("Sphere::write(): Could not cast this osg::Sphere to an osg::Object.");
40
41    // Write Sphere's properties.
42    out->writeVec3(getCenter());
43    out->writeFloat(getRadius());
44}
45
46void Sphere::read(DataInputStream* in)
47{
48    // Peek on Sphere's identification.
49    int id = in->peekInt();
50    if(id == IVESPHERE)
51    {
52        // Read Sphere's identification.
53        id = in->readInt();
54        // If the osg class is inherited by any other class we should also read this from file.
55        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
56        if(obj)
57        {
58            ((ive::Object*)(obj))->read(in);
59        }
60        else
61            in_THROW_EXCEPTION("Sphere::read(): Could not cast this osg::Sphere to an osg::Object.");
62
63        // Read Sphere's properties
64        setCenter(in->readVec3());
65        setRadius(in->readFloat());
66
67    }
68    else
69    {
70        in_THROW_EXCEPTION("Sphere::read(): Expected Sphere identification.");
71    }
72}
73
74
75////////////////////////////////////////////////////////////////////////////////
76//
77//  Box
78//
79void Box::write(DataOutputStream* out)
80{
81    // Write CullFace's identification.
82    out->writeInt(IVEBOX);
83    // If the osg class is inherited by any other class we should also write this to file.
84    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
85    if(obj)
86    {
87        ((ive::Object*)(obj))->write(out);
88    }
89    else
90        out_THROW_EXCEPTION("Box::write(): Could not cast this osg::Box to an osg::Object.");
91
92    // Write Box's properties.
93    out->writeVec3(getCenter());
94    out->writeVec3(getHalfLengths());
95    out->writeQuat(getRotation());
96}
97
98void Box::read(DataInputStream* in)
99{
100    // Peek on Box's identification.
101    int id = in->peekInt();
102    if(id == IVEBOX)
103    {
104        // Read Box's identification.
105        id = in->readInt();
106        // If the osg class is inherited by any other class we should also read this from file.
107        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
108        if(obj)
109        {
110            ((ive::Object*)(obj))->read(in);
111        }
112        else
113           in_THROW_EXCEPTION("Box::read(): Could not cast this osg::Box to an osg::Object.");
114
115        // Read Box's properties
116        setCenter(in->readVec3());
117        setHalfLengths(in->readVec3());
118        setRotation(in->readQuat());
119
120    }
121    else
122    {
123        in_THROW_EXCEPTION("Box::read(): Expected Box identification.");
124    }
125}
126
127
128////////////////////////////////////////////////////////////////////////////////
129//
130//  Cone
131//
132void Cone::write(DataOutputStream* out)
133{
134    // Write CullFace's identification.
135    out->writeInt(IVECONE);
136    // If the osg class is inherited by any other class we should also write this to file.
137    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
138    if(obj)
139    {
140        ((ive::Object*)(obj))->write(out);
141    }
142    else
143        out_THROW_EXCEPTION("Cone::write(): Could not cast this osg::Cone to an osg::Object.");
144
145    // Write Cone's properties.
146    out->writeVec3(getCenter());
147    out->writeFloat(getRadius());
148    out->writeFloat(getHeight());
149    out->writeQuat(getRotation());
150}
151
152void Cone::read(DataInputStream* in)
153{
154    // Peek on Cone's identification.
155    int id = in->peekInt();
156    if(id == IVECONE)
157    {
158        // Read Cone's identification.
159        id = in->readInt();
160        // If the osg class is inherited by any other class we should also read this from file.
161        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
162        if(obj)
163        {
164            ((ive::Object*)(obj))->read(in);
165        }
166        else
167            in_THROW_EXCEPTION("Cone::read(): Could not cast this osg::Cone to an osg::Object.");
168
169        // Read Cone's properties
170        setCenter(in->readVec3());
171        setRadius(in->readFloat());
172        setHeight(in->readFloat());
173        setRotation(in->readQuat());
174
175    }
176    else
177    {
178        in_THROW_EXCEPTION("Cone::read(): Expected Cone identification.");
179    }
180}
181
182
183////////////////////////////////////////////////////////////////////////////////
184//
185//  Cylinder
186//
187void Cylinder::write(DataOutputStream* out)
188{
189    // Write CullFace's identification.
190    out->writeInt(IVECYLINDER);
191    // If the osg class is inherited by any other class we should also write this to file.
192    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
193    if(obj)
194    {
195        ((ive::Object*)(obj))->write(out);
196    }
197    else
198        out_THROW_EXCEPTION("Cylinder::write(): Could not cast this osg::Cylinder to an osg::Object.");
199
200    // Write Cylinder's properties.
201    out->writeVec3(getCenter());
202    out->writeFloat(getRadius());
203    out->writeFloat(getHeight());
204    out->writeQuat(getRotation());
205}
206
207void Cylinder::read(DataInputStream* in)
208{
209    // Peek on Cylinder's identification.
210    int id = in->peekInt();
211    if(id == IVECYLINDER)
212    {
213        // Read Cylinder's identification.
214        id = in->readInt();
215        // If the osg class is inherited by any other class we should also read this from file.
216        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
217        if(obj)
218        {
219            ((ive::Object*)(obj))->read(in);
220        }
221        else
222            in_THROW_EXCEPTION("Cylinder::read(): Could not cast this osg::Cylinder to an osg::Object.");
223
224        // Read Cylinder's properties
225        setCenter(in->readVec3());
226        setRadius(in->readFloat());
227        setHeight(in->readFloat());
228        setRotation(in->readQuat());
229
230    }
231    else
232    {
233        in_THROW_EXCEPTION("Cylinder::read(): Expected Cylinder identification.");
234    }
235}
236
237
238////////////////////////////////////////////////////////////////////////////////
239//
240//  Capsule
241//
242void Capsule::write(DataOutputStream* out)
243{
244    // Write CullFace's identification.
245    out->writeInt(IVECAPSULE);
246    // If the osg class is inherited by any other class we should also write this to file.
247    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
248    if(obj)
249    {
250        ((ive::Object*)(obj))->write(out);
251    }
252    else
253        out_THROW_EXCEPTION("Capsule::write(): Could not cast this osg::Capsule to an osg::Object.");
254
255    // Write Capsule's properties.
256    out->writeVec3(getCenter());
257    out->writeFloat(getRadius());
258    out->writeFloat(getHeight());
259    out->writeQuat(getRotation());
260}
261
262void Capsule::read(DataInputStream* in)
263{
264    // Peek on Capsule's identification.
265    int id = in->peekInt();
266    if(id == IVECAPSULE)
267    {
268        // Read Capsule's identification.
269        id = in->readInt();
270        // If the osg class is inherited by any other class we should also read this from file.
271        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
272        if(obj)
273        {
274            ((ive::Object*)(obj))->read(in);
275        }
276        else
277            in_THROW_EXCEPTION("Capsule::read(): Could not cast this osg::Capsule to an osg::Object.");
278
279        // Read Capsule's properties
280        setCenter(in->readVec3());
281        setRadius(in->readFloat());
282        setHeight(in->readFloat());
283        setRotation(in->readQuat());
284
285    }
286    else
287    {
288        in_THROW_EXCEPTION("Capsule::read(): Expected Capsule identification.");
289    }
290}
291
292
293////////////////////////////////////////////////////////////////////////////////
294//
295//  HeightField
296//
297void HeightField::write(DataOutputStream* out)
298{
299    // Write CullFace's identification.
300    out->writeInt(IVEHEIGHTFIELD);
301    // If the osg class is inherited by any other class we should also write this to file.
302    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
303    if(obj)
304    {
305        ((ive::Object*)(obj))->write(out);
306    }
307    else
308        out_THROW_EXCEPTION("HeightField::write(): Could not cast this osg::HeightField to an osg::Object.");
309
310    // Write HeightField's properties.
311    out->writeUInt(getNumColumns());
312    out->writeUInt(getNumRows());
313    out->writeVec3(getOrigin());
314    out->writeFloat(getXInterval());
315    out->writeFloat(getYInterval());
316    out->writeQuat(getRotation());
317    out->writeFloat(getSkirtHeight());
318    out->writeUInt(getBorderWidth());
319
320    unsigned int size = getHeightList().size();
321    out->writeUInt(size);
322    for(unsigned int i = 0; i < size; i++)
323    {
324        out->writeFloat((getHeightList())[i]);
325    }
326
327
328
329
330}
331
332void HeightField::read(DataInputStream* in)
333{
334    // Peek on HeightField's identification.
335    int id = in->peekInt();
336    if(id == IVEHEIGHTFIELD)
337    {
338        // Read HeightField's identification.
339        id = in->readInt();
340        // If the osg class is inherited by any other class we should also read this from file.
341        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
342        if(obj)
343        {
344            ((ive::Object*)(obj))->read(in);
345        }
346        else
347            in_THROW_EXCEPTION("HeightField::read(): Could not cast this osg::HeightField to an osg::Object.");
348
349        // Read HeightField's properties
350        //setColor(in->readVec4());
351        unsigned int col = in->readUInt();
352        unsigned int row = in->readUInt();
353        allocate(col,row);
354
355        setOrigin(in->readVec3());
356        setXInterval(in->readFloat());
357        setYInterval(in->readFloat());
358        setRotation(in->readQuat());
359
360        setSkirtHeight(in->readFloat());
361        setBorderWidth(in->readUInt());
362
363        unsigned int size = in->readUInt();
364        in->_istream->read((char*)&(getHeightList()[0]), FLOATSIZE*size);
365        if (in->_istream->rdstate() & in->_istream->failbit)
366            in_THROW_EXCEPTION("HeightField::read(): Failed to read height array.");
367        if (in->_byteswap) {
368           float *ptr = (float*)&(getHeightList()[0]) ;
369           for (unsigned int i = 0 ; i < size ; i++ ) {
370              osg::swapBytes((char *)&(ptr[i]),FLOATSIZE) ;
371           }
372        }
373
374    }
375    else
376    {
377        in_THROW_EXCEPTION("HeightField::read(): Expected HeightField identification.");
378    }
379}
Note: See TracBrowser for help on using the browser.