Cortex  10.0.0-a4
ToHoudiniGeometryConverter.h
1 //
3 // Copyright (c) 2010-2013, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IECOREHOUDINI_TOHOUDINIGEOMETRYCONVERTER_H
36 #define IECOREHOUDINI_TOHOUDINIGEOMETRYCONVERTER_H
37 
38 #include "GU/GU_Detail.h"
39 #include "GU/GU_DetailHandle.h"
40 
41 #include "IECore/Primitive.h"
42 #include "IECore/SimpleTypedParameter.h"
43 #include "IECore/VectorTypedData.h"
44 #include "IECore/VisibleRenderable.h"
45 
46 #include "IECoreHoudini/TypeIds.h"
47 #include "IECoreHoudini/ToHoudiniConverter.h"
48 
49 namespace IECoreHoudini
50 {
51 
52 IE_CORE_FORWARDDECLARE( ToHoudiniGeometryConverter );
53 
57 {
58 
59  public :
60 
61  IE_CORE_DECLARERUNTIMETYPEDEXTENSION( ToHoudiniGeometryConverter, ToHoudiniGeometryConverterTypeId, ToHoudiniConverter );
62 
66  bool convert( GU_DetailHandle handle ) const;
67 
71  virtual void transferAttribs( GU_Detail *geo, const GA_Range &points, const GA_Range &prims ) const;
72 
75  static ToHoudiniGeometryConverterPtr create( const IECore::Object *object );
76 
79  static void supportedTypes( std::set<IECore::TypeId> &types );
80 
81  IECore::StringParameter *nameParameter();
82  const IECore::StringParameter *nameParameter() const;
83 
84  IECore::StringParameter *attributeFilterParameter();
85  const IECore::StringParameter *attributeFilterParameter() const;
86 
87  IECore::BoolParameter *convertStandardAttributesParameter();
88  const IECore::BoolParameter *convertStandardAttributesParameter() const;
89 
90  protected :
91 
92  ToHoudiniGeometryConverter( const IECore::Object *object, const std::string &description );
93 
94  virtual ~ToHoudiniGeometryConverter();
95 
97  virtual bool doConversion( const IECore::Object *object, GU_Detail *geo ) const = 0;
98 
101  void setName( GU_Detail *geo, const GA_Range &prims ) const;
102 
105  virtual IECore::PrimitiveVariable processPrimitiveVariable( const IECore::Primitive *primitive, const IECore::PrimitiveVariable &primVar ) const;
106 
107  typedef ToHoudiniGeometryConverterPtr (*CreatorFn)( const IECore::Object *object );
108 
109  static void registerConverter( IECore::TypeId fromType, CreatorFn creator );
110 
113  template<class T>
115  {
116  public :
117  Description( IECore::TypeId fromType );
118  private :
119  static ToHoudiniGeometryConverterPtr creator( const IECore::Object *object );
120  };
121 
123  GA_Range appendPoints( GA_Detail *geo, size_t numPoints ) const;
124 
128  const IECore::Primitive *primitive, GU_Detail *geo, const GA_Range &points, const GA_Range &prims,
129  IECore::PrimitiveVariable::Interpolation vertexInterpolation = IECore::PrimitiveVariable::FaceVarying,
130  IECore::PrimitiveVariable::Interpolation primitiveInterpolation = IECore::PrimitiveVariable::Uniform,
131  IECore::PrimitiveVariable::Interpolation pointInterpolation = IECore::PrimitiveVariable::Vertex,
132  IECore::PrimitiveVariable::Interpolation detailInterpolation = IECore::PrimitiveVariable::Constant
133  ) const;
134 
135  private :
136 
137  IECore::StringParameterPtr m_nameParameter;
138  IECore::StringParameterPtr m_attributeFilterParameter;
139  IECore::BoolParameterPtr m_convertStandardAttributesParameter;
140 
141  // function to handle the special case for P
142  void transferP( const IECore::V3fVectorData *positions, GU_Detail *geo, const GA_Range &points ) const;
143 
144  // function to map standard IECore PrimitiveVariable names to Houdini names
145  const std::string processPrimitiveVariableName( const std::string &name ) const;
146 
148  struct Types
149  {
150  Types( IECore::TypeId from );
151  IECore::TypeId fromType;
152  bool operator < ( const Types &other ) const;
153  };
154 
155  typedef std::map<Types, CreatorFn> TypesToFnsMap;
156  static TypesToFnsMap *typesToFns();
157 
158 };
159 
160 } // namespace IECoreHoudini
161 
162 #include "ToHoudiniGeometryConverter.inl"
163 
164 #endif // IECOREHOUDINI_TOHOUDINIGEOMETRYCONVERTER_H
virtual bool doConversion(const IECore::Object *object, GU_Detail *geo) const =0
Must be implemented by derived classes to fill the given GU_Detail with data from the IECore::Object...
virtual void transferAttribs(GU_Detail *geo, const GA_Range &points, const GA_Range &prims) const
Definition: PrimitiveVariable.h:47
GA_Range appendPoints(GA_Detail *geo, size_t numPoints) const
Appends points to the GA_Detail. Returns a GA_Range containing the GA_Offsets for the newly added poi...
The IECoreHoudini namespace holds all the functionality of libIECoreHoudini.
Definition: CoreHoudini.h:51
const std::string & description() const
Returns a description for this parameterised object.
Definition: ToHoudiniConverter.h:47
Definition: TypedParameter.h:48
Definition: ToHoudiniGeometryConverter.h:56
Definition: Object.h:104
static ToHoudiniGeometryConverterPtr create(const IECore::Object *object)
TypeId
Definition: TypeIds.h:46
Interpolation
Definition: PrimitiveVariable.h:53
Definition: Primitive.h:54
void transferAttribValues(const IECore::Primitive *primitive, GU_Detail *geo, const GA_Range &points, const GA_Range &prims, IECore::PrimitiveVariable::Interpolation vertexInterpolation=IECore::PrimitiveVariable::FaceVarying, IECore::PrimitiveVariable::Interpolation primitiveInterpolation=IECore::PrimitiveVariable::Uniform, IECore::PrimitiveVariable::Interpolation pointInterpolation=IECore::PrimitiveVariable::Vertex, IECore::PrimitiveVariable::Interpolation detailInterpolation=IECore::PrimitiveVariable::Constant) const
static void supportedTypes(std::set< IECore::TypeId > &types)
bool convert(GU_DetailHandle handle) const
virtual IECore::PrimitiveVariable processPrimitiveVariable(const IECore::Primitive *primitive, const IECore::PrimitiveVariable &primVar) const
Definition: ToHoudiniGeometryConverter.h:114
void setName(GU_Detail *geo, const GA_Range &prims) const