OSG::GeoBuilder Class Reference

A helper class to simplify building geometry.

#include <OSGGeoBuilder.h>

List of all members.


Public Member Functions

Con/Destructors


 GeoBuilder (void)
 ~GeoBuilder ()
void reset (void)
Property Access


template<class Type>
UInt32 vertex (Type data)
template<class Type>
void normal (Type data)
template<class Type>
void color (Type data)
template<class Type>
void texcoord (UInt16 unit, Type data)
template<class Type>
UInt32 prop (UInt16 index, Type data)
template<class VType, class NType>
UInt32 fullVertex (VType vert, NType norm)
template<class VType, class NType, class CType>
UInt32 fullVertex (VType vert, NType norm, CType col)
template<class VType, class NType, class CType, class TType>
UInt32 fullVertex (VType vert, NType norm, CType col, TType tc)
Face Creation


void begin (UInt32 type)
void index (UInt32 index)
void end (void)
void line (UInt32 start)
void line (UInt32 i1, UInt32 i2)
void tri (UInt32 start)
void tri (UInt32 i1, UInt32 i2, UInt32 i3)
void quad (UInt32 start)
void quad (UInt32 i1, UInt32 i2, UInt32 i3, UInt32 i4)
Object Access


GeometryPtr getGeometry (void)

Protected Member Functions

Property Helper


GeoVectorPropertyPtr getProperty (UInt32 index)
UInt32 finishVertex (void)
void addType (Int32 type)
void addLength (UInt32 length)

Private Attributes

GeometryPtr _geo
UInt32 _actLen
Int32 _actType

Static Private Attributes

static char * _defaultPropTypes [Geometry::MaxAttribs]

Detailed Description

Definition at line 53 of file OSGGeoBuilder.h.


Constructor & Destructor Documentation

GeoBuilder::GeoBuilder ( void   ) 

Definition at line 88 of file OSGGeoBuilder.cpp.

References reset().

00088                            :
00089     _geo()
00090 {
00091     reset();
00092 }

GeoBuilder::~GeoBuilder (  ) 

Definition at line 94 of file OSGGeoBuilder.cpp.

References _geo, NullFC, and OSG::subRef().

00095 {
00096     if(_geo != NullFC)
00097         subRef(_geo);
00098 }


Member Function Documentation

void GeoBuilder::reset ( void   ) 

Definition at line 100 of file OSGGeoBuilder.cpp.

References _actLen, _actType, _geo, OSG::addRef(), OSG::GeometryBase::create(), OSG::getDefaultMaterial(), NullFC, and OSG::subRef().

Referenced by GeoBuilder().

00101 {
00102     if(_geo != NullFC)
00103         subRef(_geo);
00104 
00105     _geo = Geometry::create();
00106     addRef(_geo);
00107 
00108     MaterialPtr mat = getDefaultMaterial();
00109 
00110     _geo->setMaterial(mat);
00111 
00112     _actLen = 0;
00113     _actType = -1;
00114 }

template<class Type>
UInt32 OSG::GeoBuilder::vertex ( Type  data  )  [inline]

Definition at line 73 of file OSGGeoBuilder.h.

00074     {
00075         getProperty(Geometry::PositionsIndex)->addValue(data);
00076 
00077         return finishVertex();
00078     }

template<class Type>
void OSG::GeoBuilder::normal ( Type  data  )  [inline]

Definition at line 81 of file OSGGeoBuilder.h.

00082     {
00083         getProperty(Geometry::NormalsIndex)->addValue(data);
00084     }

template<class Type>
void OSG::GeoBuilder::color ( Type  data  )  [inline]

Definition at line 87 of file OSGGeoBuilder.h.

00088     {
00089         getProperty(Geometry::ColorsIndex)->addValue(data);
00090     }

template<class Type>
void OSG::GeoBuilder::texcoord ( UInt16  unit,
Type  data 
) [inline]

Definition at line 93 of file OSGGeoBuilder.h.

00094     {
00095         getProperty(Geometry::TexCoordsIndex + unit)->addValue(data);
00096     }

template<class Type>
UInt32 OSG::GeoBuilder::prop ( UInt16  index,
Type  data 
) [inline]

Definition at line 99 of file OSGGeoBuilder.h.

00100     {
00101         getProperty(index)->addValue(data);
00102 
00103         if(index == 0)
00104             return finishVertex();
00105         else
00106             return 0;
00107     }

template<class VType, class NType>
UInt32 OSG::GeoBuilder::fullVertex ( VType  vert,
NType  norm 
) [inline]

Definition at line 110 of file OSGGeoBuilder.h.

00111     {
00112         normal(norm);
00113         return vertex(vert);
00114     }

template<class VType, class NType, class CType>
UInt32 OSG::GeoBuilder::fullVertex ( VType  vert,
NType  norm,
CType  col 
) [inline]

Definition at line 117 of file OSGGeoBuilder.h.

00118     {
00119         color(col);
00120         normal(norm);
00121         return vertex(vert);
00122     }

template<class VType, class NType, class CType, class TType>
UInt32 OSG::GeoBuilder::fullVertex ( VType  vert,
NType  norm,
CType  col,
TType  tc 
) [inline]

Definition at line 125 of file OSGGeoBuilder.h.

00126     {
00127         color(col);
00128         normal(norm);
00129         texcoord(0, tc);
00130         return vertex(vert);
00131     }

void GeoBuilder::begin ( UInt32  type  ) 

Definition at line 212 of file OSGGeoBuilder.cpp.

References _actLen, _actType, and addType().

Referenced by line(), quad(), and tri().

00213 {
00214     _actLen = 0;
00215     _actType = type;
00216 
00217     addType(type);
00218 }

void GeoBuilder::index ( UInt32  index  ) 

Definition at line 192 of file OSGGeoBuilder.cpp.

References _actType, _geo, FWARNING, and NullFC.

Referenced by finishVertex(), line(), quad(), and tri().

00193 {
00194     if(_actType == -1)
00195     {
00196         FWARNING(("GeoBuilder::index: called outside begin/end block!\n"));
00197         return;
00198     }
00199 
00200     if(_geo->getIndices() == NullFC)
00201     {
00202         GeoIntegralPropertyPtr i = GeoUInt32Property::create();
00203         _geo->setIndices(i);
00204     }
00205 
00206     _geo->getIndices()->push_back(index);
00207 }

void GeoBuilder::end ( void   ) 

Definition at line 220 of file OSGGeoBuilder.cpp.

References _actLen, _actType, and addLength().

Referenced by line(), quad(), and tri().

00221 {
00222     addLength(_actLen);
00223 
00224     _actLen = 0;
00225     _actType = -1;
00226 }

void GeoBuilder::line ( UInt32  start  ) 

Definition at line 228 of file OSGGeoBuilder.cpp.

References _actLen, begin(), end(), and index().

00229 {
00230     begin(GL_LINES);
00231 
00232     index(start    );
00233     index(start + 1);
00234 
00235     _actLen += 2;
00236 
00237     end();
00238 }

void GeoBuilder::line ( UInt32  i1,
UInt32  i2 
)

Definition at line 240 of file OSGGeoBuilder.cpp.

References _actLen, begin(), end(), and index().

00241 {
00242     begin(GL_LINES);
00243 
00244     index(i1);
00245     index(i2);
00246 
00247     _actLen += 2;
00248 
00249     end();
00250 }

void GeoBuilder::tri ( UInt32  start  ) 

Definition at line 252 of file OSGGeoBuilder.cpp.

References _actLen, begin(), end(), and index().

00253 {
00254     begin(GL_TRIANGLES);
00255 
00256     index(start    );
00257     index(start + 1);
00258     index(start + 2);
00259 
00260     _actLen += 3;
00261 
00262     end();
00263 }

void GeoBuilder::tri ( UInt32  i1,
UInt32  i2,
UInt32  i3 
)

Definition at line 265 of file OSGGeoBuilder.cpp.

References _actLen, begin(), end(), and index().

00266 {
00267     begin(GL_TRIANGLES);
00268 
00269     index(i1);
00270     index(i2);
00271     index(i3);
00272 
00273     _actLen += 3;
00274 
00275     end();
00276 }

void GeoBuilder::quad ( UInt32  start  ) 

Definition at line 278 of file OSGGeoBuilder.cpp.

References _actLen, begin(), end(), and index().

00279 {
00280     begin(GL_QUADS);
00281 
00282     index(start    );
00283     index(start + 1);
00284     index(start + 2);
00285     index(start + 3);
00286 
00287     _actLen += 4;
00288 
00289     end();
00290 }

void GeoBuilder::quad ( UInt32  i1,
UInt32  i2,
UInt32  i3,
UInt32  i4 
)

Definition at line 292 of file OSGGeoBuilder.cpp.

References _actLen, begin(), end(), and index().

00293 {
00294     begin(GL_QUADS);
00295 
00296     index(i1);
00297     index(i2);
00298     index(i3);
00299     index(i4);
00300 
00301     _actLen += 4;
00302 
00303     end();
00304 }

GeometryPtr GeoBuilder::getGeometry ( void   ) 

Definition at line 307 of file OSGGeoBuilder.cpp.

References _geo.

00308 {
00309     return _geo;
00310 }

GeoVectorPropertyPtr GeoBuilder::getProperty ( UInt32  index  )  [protected]

Definition at line 117 of file OSGGeoBuilder.cpp.

References _defaultPropTypes, _geo, NullFC, and OSG::SingletonHolder< SingletonT >::the().

00118 {
00119     GeoVectorPropertyPtr att;
00120 
00121     if(index >= _geo->getProperties().size() ||
00122        _geo->getProperty(index) == NullFC)
00123     {
00124         att = dynamic_cast<GeoVectorPropertyPtr>(
00125                 FieldContainerFactory::the()->createContainer(
00126                     _defaultPropTypes[index]));
00127 
00128         _geo->setProperty(att, index);
00129     }
00130     else
00131     {
00132         att = _geo->getProperty(index);
00133     }
00134 
00135     return att;
00136 }

UInt32 GeoBuilder::finishVertex ( void   )  [protected]

Definition at line 140 of file OSGGeoBuilder.cpp.

References _actLen, _actType, _geo, index(), NullFC, and OSG::Geometry::PositionsIndex.

00141 {
00142     UInt32 possize = _geo->getProperty(Geometry::PositionsIndex)->size();
00143 
00144     for(UInt16 i = 1; i < _geo->getProperties().size(); ++i)
00145     {
00146         if(_geo->getProperty(i) != NullFC)
00147         {
00148             GeoVectorProperty::MaxTypeT val;
00149 
00150             _geo->getProperty(i)->getValue(val,
00151                         _geo->getProperty(i)->size() - 1);
00152 
00153             for(UInt32 propsize = _geo->getProperty(i)->size();
00154                 propsize < possize;
00155                 ++propsize)
00156             {
00157                 _geo->getProperty(i)->addValue(val);
00158             }
00159         }
00160     }
00161 
00162     // Are we in a begin/end loop? Then add current vertex to index
00163     if(_actType != -1)
00164         index(possize - 1);
00165 
00166     _actLen++;
00167     return possize - 1;
00168 }

void GeoBuilder::addType ( Int32  type  )  [protected]

Definition at line 171 of file OSGGeoBuilder.cpp.

References _geo, and NullFC.

Referenced by begin().

00172 {
00173     if(_geo->getTypes() == NullFC)
00174     {
00175         GeoIntegralPropertyPtr t = GeoUInt8Property::create();
00176         _geo->setTypes(t);
00177 
00178     }
00179     _geo->getTypes()->addValue(type);
00180 }

void GeoBuilder::addLength ( UInt32  length  )  [protected]

Definition at line 182 of file OSGGeoBuilder.cpp.

References _geo, and NullFC.

Referenced by end().

00183 {
00184     if(_geo->getLengths() == NullFC)
00185     {
00186         GeoIntegralPropertyPtr l = GeoUInt32Property::create();
00187         _geo->setLengths(l);
00188     }
00189     _geo->getLengths()->addValue(length);
00190 }


Member Data Documentation

GeometryPtr OSG::GeoBuilder::_geo [private]

UInt32 OSG::GeoBuilder::_actLen [private]

Definition at line 180 of file OSGGeoBuilder.h.

Referenced by begin(), end(), finishVertex(), line(), quad(), reset(), and tri().

Int32 OSG::GeoBuilder::_actType [private]

Definition at line 181 of file OSGGeoBuilder.h.

Referenced by begin(), end(), finishVertex(), index(), and reset().

char * GeoBuilder::_defaultPropTypes [static, private]

Initial value:

{
    "GeoPnt3fProperty",  
    "GeoVec3fProperty",  
    "GeoVec3fProperty",  
    "GeoColor4fProperty",
    "GeoColor4fProperty",
    "GeoVec3fProperty",  
    "GeoVec3fProperty",  
    "GeoVec3fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
    "GeoVec2fProperty",  
}

Definition at line 183 of file OSGGeoBuilder.h.

Referenced by getProperty().


The documentation for this class was generated from the following files: