1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
40 /***************************************************************************\
42 \***************************************************************************/
44 #include "OSGStripeGraphOp.h"
45 #include "OSGTypedGeoIntegralProperty.h"
46 #include "OSGGeoFunctions.h"
47 #include "OSGGraphOpFactory.h"
51 /***************************************************************************\
53 \***************************************************************************/
55 /*! \class OSG::StripeGraphOp
56 \ingroup GrpSystemNodeCoresDrawablesGeometry
58 A base class used to traverse geometries.
64 //! Register the GraphOp with the factory
65 static bool registerOp(void)
67 GraphOpRefPtr newOp
= StripeGraphOp::create();
69 GraphOpFactory::the()->registerOp(newOp
);
73 static OSG::StaticInitFuncWrapper
registerOpWrapper(registerOp
);
78 /***************************************************************************\
80 \***************************************************************************/
82 /*-------------------------------------------------------------------------*\
84 \*-------------------------------------------------------------------------*/
87 /*------------- constructors & destructors --------------------------------*/
89 StripeGraphOp::StripeGraphOp(const char* name
) :
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
)
117 ps("stitch", _stitch
);
118 ps("singleindex", _singleIndex
);
120 std::string out
= ps
.getUnusedParams();
123 FWARNING(("StripeGraphOp doesn't have parameters '%s'\n.",
128 std::string
StripeGraphOp::usage(void)
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());
144 // Check if it's striped already
147 GeoIntegralProperty
*t
= geo
->getTypes();
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
:
166 gotNonTriangles
= true;
173 if(gotNonTriangles
== true)
177 if(gotNonTriangles
== false &&
178 gotTriStrips
== true )
185 createSharedIndex(geo
);
187 if(_singleIndex
== true)
189 createSingleIndex(geo
);
192 createOptimizedPrimitives(geo
, 1, true, true, 16, false, _stitch
);
198 bool StripeGraphOp::travNodeLeave(Node
*)
203 /*-------------------------------------------------------------------------*\
205 \*-------------------------------------------------------------------------*/