1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGDrawableStatsAttachment.h"
49 #include "OSGDrawable.h"
54 // Documentation for this class is emitted in the
55 // OSGDrawableStatsAttachmentBase.cpp file.
56 // To modify it, please change the .fcd file (OSGDrawableStatsAttachment.fcd) and
57 // regenerate the base file.
59 /***************************************************************************\
61 \***************************************************************************/
63 /***************************************************************************\
65 \***************************************************************************/
67 void DrawableStatsAttachment::initMethod(InitPhase ePhase
)
69 Inherited::initMethod(ePhase
);
71 if(ePhase
== TypeObject::SystemPost
)
77 /***************************************************************************\
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 DrawableStatsAttachment::DrawableStatsAttachment(void) :
92 DrawableStatsAttachment::DrawableStatsAttachment(const DrawableStatsAttachment
&source
) :
97 DrawableStatsAttachment::~DrawableStatsAttachment(void)
101 /*----------------------------- class specific ----------------------------*/
103 void DrawableStatsAttachment::changed(ConstFieldMaskArg whichField
,
107 Inherited::changed(whichField
, origin
, details
);
110 void DrawableStatsAttachment::dump( UInt32
,
111 const BitVector
) const
113 SLOG
<< "Dump DrawableStatsAttachment NI" << std::endl
;
116 void DrawableStatsAttachment::reset(void)
118 // Don't change it unless it's valid.
119 // Needed to protect intermediate results
128 setProcessedAttributeBytes(0);
129 setStoredAttributeBytes (0);
134 /*! Create a GeoStatsAttachment for the given Geometry
137 DrawableStatsAttachmentTransitPtr
DrawableStatsAttachment::calcStatic(
140 DrawableStatsAttachmentUnrecPtr st
= DrawableStatsAttachment::create();
142 if(pDrawable
!= NULL
)
145 return DrawableStatsAttachmentTransitPtr(st
);
148 /*! Add a new GeoStatsAttachment to the given \a obj.
151 DrawableStatsAttachmentTransitPtr
DrawableStatsAttachment::addTo(
152 AttachmentContainer
*obj
)
154 DrawableStatsAttachmentTransitPtr st
= DrawableStatsAttachment::create();
161 /*! Attach the current GeoStatsAttachment to the given \a obj.
164 void DrawableStatsAttachment::attachTo(AttachmentContainer
*obj
)
166 if(getMFParents()->size())
168 FNOTICE(("GeoStatsAttachment::attachTo: "
169 "already attached, detaching!\n"));
171 while(getMFParents()->size())
173 AttachmentContainer
*p
=
174 dynamic_cast<AttachmentContainer
*>(this->getParents(0));
176 p
->subChangedFunctor(&DrawableStatsAttachment::invalidateFunctor
);
177 p
->subAttachment (this );
181 obj
->addAttachment(this);
185 obj
->addChangedFunctor(&DrawableStatsAttachment::invalidateFunctor
,
186 "DrawableStats invalidator");
189 void DrawableStatsAttachment::validate(void)
193 // Still valid? Do nothing.
197 AttachmentContainer
*cont
=
198 dynamic_cast<AttachmentContainer
*>(this->getParents(0));
200 // Called on a non-AttachmentContainer?
207 Drawable
*g
= dynamic_cast<Drawable
*>(cont
);
216 Node
*n
= dynamic_cast<Node
*>(cont
);
220 g
= dynamic_cast<Drawable
*>(n
->getCore());
223 DrawableStatsAttachmentUnrecPtr s
= get(g
);
227 s
= DrawableStatsAttachment::addTo(g
);
233 setValid(false); // Not done yet.
236 // Validate all the children
237 for(UInt32 i
= 0; i
< n
->getNChildren(); ++i
)
239 Node
*c
= n
->getChild(i
);
241 DrawableStatsAttachmentUnrecPtr s
= get(c
);
245 s
= DrawableStatsAttachment::addTo(c
);
251 setValid(false); // Not done yet.
254 setValid(true); // Done!
257 void DrawableStatsAttachment::operator +=(DrawableStatsAttachment
*arg
)
259 setVertices (getVertices() + arg
->getVertices());
260 setPoints (getPoints() + arg
->getPoints());
261 setLines (getLines() + arg
->getLines());
262 setTriangles (getTriangles() + arg
->getTriangles());
263 setPatches (getPatches () + arg
->getPatches ());
264 setProcessedAttributeBytes(getProcessedAttributeBytes() +
265 arg
->getProcessedAttributeBytes());
266 setStoredAttributeBytes (getStoredAttributeBytes() +
267 arg
->getStoredAttributeBytes());
271 void DrawableStatsAttachment::operator -=(DrawableStatsAttachment
*arg
)
273 setVertices (getVertices() - arg
->getVertices());
274 setPoints (getPoints() - arg
->getPoints());
275 setLines (getLines() - arg
->getLines());
276 setTriangles (getTriangles() - arg
->getTriangles());
277 setPatches (getPatches () - arg
->getPatches ());
278 setProcessedAttributeBytes(getProcessedAttributeBytes() -
279 arg
->getProcessedAttributeBytes());
280 setStoredAttributeBytes (getStoredAttributeBytes() -
281 arg
->getStoredAttributeBytes());
287 void DrawableStatsAttachment::invalidateFunctor(
289 BitVector whichField
,
295 void DrawableStatsAttachment::invalidate(FieldContainer
*obj
)
300 AttachmentContainer
*cont
= dynamic_cast<AttachmentContainer
*>(obj
);
302 // Called on a non-AttachmentContainer?
306 // Find the attachment
307 DrawableStatsAttachment
*st
= get(cont
);
309 if(st
== NULL
) // Found the end of the chain
316 if(st
->getMFParents()->size())
318 // Can't have more than 1
320 dynamic_cast<FieldContainer
*>(st
->getParents(0));
322 // Is this attached to a NodeCore?
323 NodeCore
*c
= dynamic_cast<NodeCore
*>(p
);
326 MFParentFieldContainerPtr::const_iterator pnI
;
328 for( pnI
= c
->getMFParents()->begin();
329 pnI
!= c
->getMFParents()->end ();
332 Node
*node
= dynamic_cast<Node
*>(*pnI
);
338 // Is this attached to a Node?
339 Node
*n
= dynamic_cast<Node
*>(p
);
343 Node
*par
= n
->getParent();