Skip to content

Commit

Permalink
Added a Prune node.
Browse files Browse the repository at this point in the history
This removes entire branches from the scene according to a filter. Factored out the "having a filter" from SceneElementProcessor into a new FilteredSceneProcessor base class to allow Prune to shared the filtering logic (acceptsInput etc). Addresses issue GafferHQ#70.
  • Loading branch information
johnhaddon committed Apr 4, 2013
1 parent 37c8c85 commit 9839d16
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 54 deletions.
73 changes: 73 additions & 0 deletions include/GafferScene/FilteredSceneProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, John Haddon. All rights reserved.
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFERSCENE_FILTEREDSCENEPROCESSOR_H
#define GAFFERSCENE_FILTEREDSCENEPROCESSOR_H

#include "GafferScene/SceneProcessor.h"
#include "GafferScene/Filter.h"

namespace GafferScene
{

/// The FilteredSceneProcessor provides a base class for limiting the processing of scenes
/// to certain locations using a Filter node.
class FilteredSceneProcessor : public SceneProcessor
{

public :

FilteredSceneProcessor( const std::string &name=staticTypeName(), Filter::Result filterDefault = Filter::Match );
virtual ~FilteredSceneProcessor();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( FilteredSceneProcessor, FilteredSceneProcessorTypeId, SceneProcessor );

Gaffer::IntPlug *filterPlug();
const Gaffer::IntPlug *filterPlug() const;

protected :

/// Implemented to prevent non-Filter nodes being connected to the filter plug.
virtual bool acceptsInput( const Gaffer::Plug *plug, const Gaffer::Plug *inputPlug ) const;

static size_t g_firstPlugIndex;

};

} // namespace GafferScene

#endif // GAFFERSCENE_FILTEREDSCENEPROCESSOR_H
84 changes: 84 additions & 0 deletions include/GafferScene/Prune.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFERSCENE_PRUNE_H
#define GAFFERSCENE_PRUNE_H

#include "GafferScene/FilteredSceneProcessor.h"

namespace GafferScene
{

class Prune : public FilteredSceneProcessor
{

public :

Prune( const std::string &name=staticTypeName() );
virtual ~Prune();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( Prune, PruneTypeId, FilteredSceneProcessor );

Gaffer::BoolPlug *adjustBoundsPlug();
const Gaffer::BoolPlug *adjustBoundsPlug() const;

void affects( const Gaffer::ValuePlug *input, AffectedPlugsContainer &outputs ) const;

protected :

virtual void hashBound( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;
virtual void hashTransform( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;
virtual void hashAttributes( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;
virtual void hashObject( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;
virtual void hashChildNames( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;
virtual void hashGlobals( const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;

virtual Imath::Box3f computeBound( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const;
virtual Imath::M44f computeTransform( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const;
virtual IECore::ConstCompoundObjectPtr computeAttributes( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const;
virtual IECore::ConstObjectPtr computeObject( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const;
virtual IECore::ConstInternedStringVectorDataPtr computeChildNames( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const;
virtual IECore::ConstCompoundObjectPtr computeGlobals( const Gaffer::Context *context, const ScenePlug *parent ) const;

private :

static size_t g_firstPlugIndex;

};

} // namespace GafferScene

#endif // GAFFERSCENE_PRUNE_H
15 changes: 4 additions & 11 deletions include/GafferScene/SceneElementProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,28 @@
#ifndef GAFFERSCENE_SCENEELEMENTPROCESSOR_H
#define GAFFERSCENE_SCENEELEMENTPROCESSOR_H

#include "GafferScene/SceneProcessor.h"
#include "GafferScene/Filter.h"
#include "GafferScene/FilteredSceneProcessor.h"

namespace GafferScene
{

/// The SceneElementProcessor class provides a base class for modifying elements of an input
/// scene while leaving the scene hierarchy unchanged.
class SceneElementProcessor : public SceneProcessor
class SceneElementProcessor : public FilteredSceneProcessor
{

public :

SceneElementProcessor( const std::string &name=staticTypeName(), Filter::Result filterDefault = Filter::Match );
virtual ~SceneElementProcessor();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( SceneElementProcessor, SceneElementProcessorTypeId, SceneProcessor );

Gaffer::IntPlug *filterPlug();
const Gaffer::IntPlug *filterPlug() const;

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( SceneElementProcessor, SceneElementProcessorTypeId, FilteredSceneProcessor );

/// Implemented so that each child of inPlug() affects the corresponding child of outPlug()
virtual void affects( const Gaffer::ValuePlug *input, AffectedPlugsContainer &outputs ) const;

protected :

/// Implemented to prevent non-Filter nodes being connected to the filter plug.
virtual bool acceptsInput( const Gaffer::Plug *plug, const Gaffer::Plug *inputPlug ) const;

/// Implemented to call hashProcessedBound() where appropriate.
virtual void hashBound( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const;
/// Implemented to call hashProcessedTransform() where appropriate.
Expand Down
2 changes: 2 additions & 0 deletions include/GafferScene/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ enum TypeId
ConstraintTypeId = 110542,
AimConstraintTypeId = 110543,
MeshTypeTypeId = 110544,
FilteredSceneProcessorTypeId = 110545,
PruneTypeId = 110546,

LastTypeId = 110650
};
Expand Down
Loading

0 comments on commit 9839d16

Please sign in to comment.