Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGRAWSceneFileType.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //-------------------------------
00040 //  Includes
00041 //-------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include "OSGConfig.h"
00047 
00048 #include <iostream>
00049 #include <fstream>
00050 
00051 #include <OSGLog.h>
00052 
00053 #include <OSGNode.h>
00054 #include <OSGGeometry.h>
00055 #include <OSGGeoProperty.h>
00056 #include <OSGSimpleMaterial.h>
00057 
00058 #include "OSGRAWSceneFileType.h"
00059 
00060 OSG_USING_NAMESPACE
00061 
00062 #if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
00063 #pragma warning (disable : 383)
00064 #endif
00065 
00066 
00072 /*****************************
00073  *   Types
00074  *****************************/
00075 // Static Class Varible implementations:
00076 
00077 const Char8            *RAWSceneFileType::_suffixA[] = {"raw"};
00078 
00079       RAWSceneFileType  RAWSceneFileType::_the         (_suffixA,
00080                                                         sizeof(_suffixA),
00081                                                         false,
00082                                                         10,
00083                                                         SceneFileType::OSG_READ_SUPPORTED);
00084 
00085 /*****************************
00086  *    Classvariables
00087  *****************************/
00088 
00089 
00090 /********************************
00091  *    Class methodes
00092  *******************************/
00093 
00094 
00095 /*******************************
00096 *public
00097 *******************************/
00098 
00099 //----------------------------
00100 // Function name: read
00101 //----------------------------
00102 //
00103 //Parameters:
00104 //p: Scene &image, const char *fileName
00105 //GlobalVars:
00106 //g:
00107 //Returns:
00108 //r:bool
00109 // Caution
00110 //c:
00111 //Assumations:
00112 //a:
00113 //Describtions:
00114 //d: read the image from the given file
00115 //SeeAlso:
00116 //s:
00117 //
00118 //------------------------------
00119 
00120 #ifdef __sgi
00121 #pragma set woff 1209
00122 #endif
00123 
00124 NodePtr RAWSceneFileType::read(std::istream &is, const Char8 *) const
00125 {
00126     NodePtr root;
00127     GeometryPtr geo;
00128     GeoPositions3f::PtrType points;
00129     GeoNormals3f::PtrType   normals;
00130     GeoIndicesUI32Ptr index;
00131     GeoPLengthsUI32Ptr lens;
00132     GeoPTypesUI8Ptr type;
00133     Vec3f vec[3];
00134     UInt32 i = 0, n, triCount = 0;
00135     Real32 x,y,z;
00136 
00137     fprintf(stderr, "Loading using Loader 0\n");
00138 
00139     if(is)
00140     {
00141         root = Node::create();
00142         geo = Geometry::create();
00143 
00144         beginEditCP(geo, FieldBits::AllFields);
00145         beginEditCP(root, Node::CoreFieldMask);
00146         root->setCore( geo );
00147         endEditCP(root, Node::CoreFieldMask);
00148 
00149         points = GeoPositions3f::create();
00150         geo->setPositions( points );
00151         normals = GeoNormals3f::create();
00152         geo->setNormals ( normals );
00153 
00154         triCount = i = 0;
00155 
00156         beginEditCP(points,  FieldBits::AllFields);
00157         beginEditCP(normals, FieldBits::AllFields);
00158 
00159         while (1) {
00160             is >> x >> y >> z;
00161             if (is.eof())
00162                 break;
00163             else {
00164                 points->getFieldPtr()->push_back( Pnt3f ( x, y, z) );
00165                 vec[i].setValues(x,y,z);
00166                 if (i == 2) {
00167                     vec[0] -= vec[1];
00168                     vec[1] -= vec[2];
00169                     vec[0].crossThis(vec[1]);
00170                     vec[0].normalize();
00171 
00172                     normals->getFieldPtr()->push_back ( vec[0] );
00173                     normals->getFieldPtr()->push_back ( vec[0] );
00174                     normals->getFieldPtr()->push_back ( vec[0] );
00175 
00176                     i = 0;
00177                     triCount++;
00178                 }
00179                 else
00180                     i++;
00181             }
00182         }
00183 
00184         endEditCP(points,  FieldBits::AllFields);
00185         endEditCP(normals, FieldBits::AllFields);
00186 
00187         if (triCount)
00188         {
00189 
00190             index = GeoIndicesUI32::create();
00191             geo->setIndices( index );
00192             beginEditCP(index, FieldBits::AllFields);
00193             n = triCount * 3;
00194             for (i = 0; i < n; i++)
00195                 index->getFieldPtr()->push_back( i );
00196             endEditCP(index, FieldBits::AllFields);
00197 
00198 
00199             lens = GeoPLengthsUI32::create();
00200             geo->setLengths( lens );
00201             beginEditCP(lens, FieldBits::AllFields);
00202             lens->push_back( n );
00203             endEditCP(lens, FieldBits::AllFields);
00204 
00205             type = GeoPTypesUI8::create();
00206             geo->setTypes( type );
00207             beginEditCP(type, FieldBits::AllFields);
00208             type->push_back( GL_TRIANGLES );
00209             endEditCP(type, FieldBits::AllFields);
00210         }
00211 
00212         SimpleMaterialPtr mat = SimpleMaterial::create();
00213         beginEditCP(mat, FieldBits::AllFields);
00214         mat->setDiffuse( Color3f( .8, .8, .8 ) );
00215         mat->setSpecular( Color3f( 1, 1, 1 ) );
00216         mat->setShininess( 20 );
00217         endEditCP(mat, FieldBits::AllFields);
00218 
00219         geo->setMaterial( mat );
00220         endEditCP(geo, FieldBits::AllFields);
00221     }
00222 
00223     if (triCount)
00224         SNOTICE << triCount << " triangle read " << std::endl;
00225 
00226     return root;
00227 }
00228 
00229 #ifdef __sgi
00230 #pragma reset woff 1209
00231 #endif
00232 
00233 /******************************
00234 *protected
00235 ******************************/
00236 
00237 
00238 /******************************
00239 *private
00240 ******************************/
00241 
00242 
00243 /***************************
00244 *instance methodes
00245 ***************************/
00246 
00247 
00248 /***************************
00249 *public
00250 ***************************/
00251 
00252 
00256 //----------------------------
00257 // Function name: RAWSceneFileType
00258 //----------------------------
00259 //
00260 //Parameters:
00261 //p: const char *suffixArray[], UInit16 suffixByteCount
00262 //GlobalVars:
00263 //g:
00264 //Returns:
00265 //r:
00266 // Caution
00267 //c:
00268 //Assumations:
00269 //a:
00270 //Describtions:
00271 //d: Default Constructor
00272 //SeeAlso:
00273 //s:
00274 //
00275 //------------------------------
00276 
00277 RAWSceneFileType::RAWSceneFileType(const Char8  *suffixArray[],
00278                                          UInt16  suffixByteCount,
00279                                          bool    override,
00280                                          UInt32  overridePriority,
00281                                          UInt32  flags) :
00282     SceneFileType(suffixArray,
00283                   suffixByteCount,
00284                   override,
00285                   overridePriority,
00286                   flags)
00287 {
00288 }
00289 
00290 RAWSceneFileType &RAWSceneFileType::the(void)
00291 {
00292     return _the;
00293 }
00294 
00295 const Char8 *RAWSceneFileType::getName(void) const
00296 {
00297     return "RAW GEOMETRY";
00298 }
00299 
00300 //----------------------------
00301 // Function name: RAWSceneFileType
00302 //----------------------------
00303 //
00304 //Parameters:
00305 //p: const RAWSceneFileType &obj
00306 //GlobalVars:
00307 //g:
00308 //Returns:
00309 //r:
00310 // Caution
00311 //c:
00312 //Assumations:
00313 //a:
00314 //Describtions:
00315 //d: Copy Constructor
00316 //SeeAlso:
00317 //s:
00318 //
00319 //------------------------------
00320 
00321 RAWSceneFileType::RAWSceneFileType(const RAWSceneFileType &obj) :
00322     SceneFileType(obj)
00323 {
00324     return;
00325 }
00326 
00327 //----------------------------
00328 // Function name: ~RAWSceneFileType
00329 //----------------------------
00330 //
00331 //Parameters:
00332 //p: void
00333 //GlobalVars:
00334 //g:
00335 //Returns:
00336 //r:
00337 // Caution
00338 //c:
00339 //Assumations:
00340 //a:
00341 //Describtions:
00342 //d: Destructor
00343 //SeeAlso:
00344 //s:
00345 //
00346 //------------------------------
00347 
00348 RAWSceneFileType::~RAWSceneFileType (void )
00349 {
00350     return;
00351 }
00352 
00353 
00354 /*-------------------------------------------------------------------------*/
00355 /*                              cvs id's                                   */
00356 
00357 #ifdef __sgi
00358 #pragma set woff 1174
00359 #endif
00360 
00361 #ifdef OSG_LINUX_ICC
00362 #pragma warning( disable : 177 )
00363 #endif
00364 
00365 namespace
00366 {
00367     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00368     static Char8 cvsid_hpp[] = OSGRAWSCENEFILETYPE_HEADER_CVSID;
00369 }
00370 

Generated on Thu Aug 25 04:09:03 2005 for OpenSG by  doxygen 1.4.3