fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / RAW / OSGRAWSceneFileType.cpp
blob5f5ea0c77a41051b90a99e3dcf6cc8906447895c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //-------------------------------
40 // Includes
41 //-------------------------------
43 #include <stdlib.h>
44 #include <stdio.h>
46 #include "OSGConfig.h"
48 #include <iostream>
49 #include <fstream>
51 #include "OSGLog.h"
53 #include "OSGNode.h"
54 #include "OSGGeometry.h"
55 #include "OSGSimpleMaterial.h"
56 #include "OSGTypedGeoIntegralProperty.h"
57 #include "OSGTypedGeoVectorProperty.h"
59 #include "OSGRAWSceneFileType.h"
61 OSG_USING_NAMESPACE
63 #if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
64 #pragma warning (disable : 383)
65 #endif
68 /*! \class OSG::RAWSceneFileType
69 \ingroup GrpSystemFileIO
73 /*****************************
74 * Types
75 *****************************/
76 // Static Class Varible implementations:
78 const Char8 *RAWSceneFileType::_suffixA[] = {"raw"};
81 RAWSceneFileType RAWSceneFileType::_the(_suffixA,
82 sizeof(_suffixA),
83 false,
84 10,
85 SceneFileType::OSG_READ_SUPPORTED);
87 /*****************************
88 * Classvariables
89 *****************************/
92 /********************************
93 * Class methodes
94 *******************************/
97 /*******************************
98 *public
99 *******************************/
101 //----------------------------
102 // Function name: read
103 //----------------------------
105 //Parameters:
106 //p: Scene &image, const char *fileName
107 //GlobalVars:
108 //g:
109 //Returns:
110 //r:bool
111 // Caution
112 //c:
113 //Assumations:
114 //a:
115 //Describtions:
116 //d: read the image from the given file
117 //SeeAlso:
118 //s:
120 //------------------------------
122 #ifdef __sgi
123 #pragma set woff 1209
124 #endif
126 NodeTransitPtr RAWSceneFileType::read( std::istream &is,
127 const Char8 *,
128 Resolver ) const
130 NodeTransitPtr root;
131 GeometryUnrecPtr geo;
132 GeoPnt3fPropertyUnrecPtr points;
133 GeoVec3fPropertyUnrecPtr normals;
134 GeoIntegralPropertyUnrecPtr index;
135 GeoIntegralPropertyUnrecPtr lens;
136 GeoIntegralPropertyUnrecPtr type;
138 Vec3f vec[3];
140 UInt32 i = 0, n, triCount = 0;
142 Real32 x,y,z;
144 if(is)
146 root = Node ::create();
147 geo = Geometry::create();
149 root->setCore( geo );
151 points = GeoPnt3fProperty::create();
153 geo->setPositions(points);
155 normals = GeoVec3fProperty::create();
157 geo->setNormals(normals);
159 triCount = i = 0;
162 while(1)
164 is >> x >> y >> z;
166 if(is.eof())
168 break;
170 else
172 points->editFieldPtr()->push_back(Pnt3f(x, y, z));
174 vec[i].setValues(x,y,z);
176 std::cerr << x << " " << y << " " << z << std::endl;
178 if(i == 2)
180 vec[0] -= vec[1];
181 vec[1] -= vec[2];
182 vec[0].crossThis(vec[1]);
183 vec[0].normalize();
185 normals->editFieldPtr()->push_back(vec[0]);
186 normals->editFieldPtr()->push_back(vec[0]);
187 normals->editFieldPtr()->push_back(vec[0]);
189 i = 0;
190 triCount++;
192 else
194 i++;
199 if(triCount != 0)
201 index = GeoUInt32Property::create();
203 geo->setIndex(index, Geometry::PositionsIndex);
204 geo->setIndex(index, Geometry::NormalsIndex );
206 n = triCount * 3;
208 for(i = 0; i < n; i++)
209 index->push_back(i);
213 lens = GeoUInt32Property::create();
215 geo->setLengths(lens);
217 lens->push_back(n);
219 type = GeoUInt8Property::create();
221 geo->setTypes(type);
223 type->push_back(GL_TRIANGLES);
226 SimpleMaterialUnrecPtr mat = SimpleMaterial::create();
228 mat->setDiffuse (Color3f( .8f, .8f, .8f));
229 mat->setSpecular (Color3f( 1.f, 1.f, 1.f ));
230 mat->setShininess(20.f );
232 geo->setMaterial(mat);
235 if(triCount)
237 SNOTICE << triCount << " triangle read " << std::endl;
240 commitChanges();
242 return root;
245 #ifdef __sgi
246 #pragma reset woff 1209
247 #endif
249 /******************************
250 *protected
251 ******************************/
254 /******************************
255 *private
256 ******************************/
259 /***************************
260 *instance methodes
261 ***************************/
264 /***************************
265 *public
266 ***************************/
269 /**constructors & destructors**/
272 RAWSceneFileType::RAWSceneFileType(const Char8 *suffixArray[],
273 UInt16 suffixByteCount,
274 bool override,
275 UInt32 overridePriority,
276 UInt32 flags) :
277 SceneFileType(suffixArray,
278 suffixByteCount,
279 override,
280 overridePriority,
281 flags)
285 RAWSceneFileType &RAWSceneFileType::the(void)
287 return _the;
290 const Char8 *RAWSceneFileType::getName(void) const
292 return "RAW Geometry";
296 RAWSceneFileType::~RAWSceneFileType (void )
298 return;