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 "OSGPruneGraphOp.h"
45 #include "OSGGraphOpFactory.h"
49 /***************************************************************************\
51 \***************************************************************************/
53 /*! \class OSG::PruneGraphOp
54 \ingroup GrpSystemNodeCoresDrawablesGeometry
56 Removes nodes of size smaller than a given threshold from the scene.
61 //! Register the GraphOp with the factory
62 static bool registerOp(void)
64 GraphOpRefPtr newOp
= PruneGraphOp::create();
66 GraphOpFactory::the()->registerOp(newOp
);
70 static OSG::StaticInitFuncWrapper
registerOpWrapper(registerOp
);
75 PruneGraphOp::PruneGraphOp(float size
, Method method
, const char* name
)
82 PruneGraphOp::~PruneGraphOp(void)
86 PruneGraphOpTransitPtr
87 PruneGraphOp::create(float size
, Method method
)
89 return PruneGraphOpTransitPtr(new PruneGraphOp(size
, method
));
92 GraphOpTransitPtr
PruneGraphOp::clone(void)
94 return GraphOpTransitPtr(new PruneGraphOp(_size
, _method
));
97 void PruneGraphOp::setParams(const std::string params
)
108 if(m
.find("volume") || m
.find("VOLUME"))
112 else if(m
.find("sum_of_dimensions") || m
.find("SUM_OF_DIMENSIONS") ||
115 _method
= SUM_OF_DIMENSIONS
;
119 FWARNING(("GeoTypeGraphOp: method '%s' unknown.\n", m
.c_str()));
123 std::string out
= ps
.getUnusedParams();
126 FWARNING(("PruneGraphOp doesn't have parameters '%s'.\n",
131 std::string
PruneGraphOp::usage(void)
134 "Prune: Remove small objects\n"
135 " Removes nodes of size smaller than a given threshold from the scene\n"
136 "Params: name (type, default)\n"
137 " method (string, SUM_OF_DIMENSIONS): \n"
138 " VOLUME: measure volume of Node\n"
139 " SUM_OF_DIMENSIONS: add upp the individual dims\n"
140 " size (Real32, 1.0f): \n"
141 " threshold value. Nodes smaller than this will be\n"
145 Action::ResultE
PruneGraphOp::traverseEnter(Node
* const node
)
147 return isTooSmall(node
) ? Action::Skip
: Action::Continue
;
150 Action::ResultE
PruneGraphOp::traverseLeave(Node
* const node
, Action::ResultE res
)
152 for(UInt32 i
= 0; i
< node
->getNChildren(); ++i
)
154 if(isTooSmall(node
->getChild(i
)))
164 bool PruneGraphOp::isTooSmall(Node
* const node
)
166 return getSize(node
) < _size
;
169 float PruneGraphOp::getSize(Node
* const node
)
171 const BoxVolume
& bv
= node
->editVolume(true);
173 if(_method
== VOLUME
)
175 return bv
.getScalarVolume();
177 else if(_method
== SUM_OF_DIMENSIONS
)
180 bv
.getBounds(min
, max
);
181 Vec3f diff
= max
- min
;
182 return diff
[0] + diff
[1] + diff
[2];
186 SWARNING
<< "Unknown size calculation method" << std::endl
;