fixed: compile issue
[opensg.git] / Source / System / GraphOp / OSGStripeGraphOp.cpp
blob2877f54b5939f9a88676d32f42e0262a514a604e
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 \*---------------------------------------------------------------------------*/
40 /***************************************************************************\
41 * Includes *
42 \***************************************************************************/
44 #include "OSGStripeGraphOp.h"
45 #include "OSGTypedGeoIntegralProperty.h"
46 #include "OSGGeoFunctions.h"
47 #include "OSGGraphOpFactory.h"
49 OSG_USING_NAMESPACE
51 /***************************************************************************\
52 * Description *
53 \***************************************************************************/
55 /*! \class OSG::StripeGraphOp
56 \ingroup GrpSystemNodeCoresDrawablesGeometry
58 A base class used to traverse geometries.
62 namespace
64 //! Register the GraphOp with the factory
65 static bool registerOp(void)
67 GraphOpRefPtr newOp = StripeGraphOp::create();
69 GraphOpFactory::the()->registerOp(newOp);
70 return true;
73 static OSG::StaticInitFuncWrapper registerOpWrapper(registerOp);
75 } // namespace
78 /***************************************************************************\
79 * Instance methods *
80 \***************************************************************************/
82 /*-------------------------------------------------------------------------*\
83 - public -
84 \*-------------------------------------------------------------------------*/
87 /*------------- constructors & destructors --------------------------------*/
89 StripeGraphOp::StripeGraphOp(const char* name) :
90 Inherited(name),
91 _force (false),
92 _stitch (false),
93 _singleIndex(false)
97 StripeGraphOp::~StripeGraphOp(void)
101 StripeGraphOpTransitPtr
102 StripeGraphOp::create(void)
104 return StripeGraphOpTransitPtr(new StripeGraphOp);
107 GraphOpTransitPtr StripeGraphOp::clone(void)
109 return GraphOpTransitPtr(new StripeGraphOp);
112 void StripeGraphOp::setParams(const std::string params)
114 ParamSet ps(params);
116 ps("force", _force);
117 ps("stitch", _stitch);
118 ps("singleindex", _singleIndex);
120 std::string out = ps.getUnusedParams();
121 if(out.length())
123 FWARNING(("StripeGraphOp doesn't have parameters '%s'\n.",
124 out.c_str()));
128 std::string StripeGraphOp::usage(void)
130 return
131 "Stripe: Stripe Geometries\n"
132 "Params: name (type, default)\n"
133 " force (bool, false): force striping even if already striped\n"
134 " stitch (bool, false): stitch strips using degenerate triangles\n"
135 " singleIndex (bool, false): create single index before striping\n";
138 bool StripeGraphOp::travNodeEnter(Node *node)
140 Geometry *geo = dynamic_cast<Geometry *>(node->getCore());
142 if(geo != NULL)
144 // Check if it's striped already
145 if (!_force)
147 GeoIntegralProperty *t = geo->getTypes();
149 if(t != NULL)
151 bool gotNonTriangles = false;
152 bool gotTriStrips = false;
154 for(UInt32 i = 0; i < t->size(); ++i)
156 switch(t->getValue(i))
158 case GL_TRIANGLE_STRIP:
159 case GL_TRIANGLE_FAN:
160 gotTriStrips = true;
161 break;
163 case GL_QUADS:
164 case GL_QUAD_STRIP:
165 case GL_POLYGON:
166 gotNonTriangles = true;
167 break;
169 default:
170 break;
173 if(gotNonTriangles == true)
174 break;
177 if(gotNonTriangles == false &&
178 gotTriStrips == true )
180 return true;
185 createSharedIndex(geo);
187 if(_singleIndex == true)
189 createSingleIndex(geo);
192 createOptimizedPrimitives(geo, 1, true, true, 16, false, _stitch);
195 return true;
198 bool StripeGraphOp::travNodeLeave(Node *)
200 return true;
203 /*-------------------------------------------------------------------------*\
204 - protected -
205 \*-------------------------------------------------------------------------*/