Cortex  10.0.0-a4
FromHoudiniGeometryConverter.h
1 //
3 // Copyright 2010 Dr D Studios Pty Limited (ACN 127 184 954) (Dr. D Studios),
4 // its affiliates and/or its licensors.
5 //
6 // Copyright (c) 2010-2013, Image Engine Design Inc. All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // * Neither the name of Image Engine Design nor the names of any
20 // other contributors to this software may be used to endorse or
21 // promote products derived from this software without specific prior
22 // written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
37 
38 #ifndef IECOREHOUDINI_FROMHOUDINIGEOMETRYCONVERTER_H
39 #define IECOREHOUDINI_FROMHOUDINIGEOMETRYCONVERTER_H
40 
41 #include "GA/GA_AttributeRef.h"
42 #include "GU/GU_Detail.h"
43 #include "GU/GU_DetailHandle.h"
44 #include "SOP/SOP_Node.h"
45 #include "UT/UT_StringMMPattern.h"
46 
47 #include "IECore/Primitive.h"
48 #include "IECore/SimpleTypedData.h"
49 #include "IECore/SimpleTypedParameter.h"
50 #include "IECore/VectorTypedData.h"
51 
52 #include "IECoreHoudini/TypeIds.h"
53 #include "IECoreHoudini/FromHoudiniConverter.h"
54 
55 #include "IECoreHoudini/bindings/FromHoudiniGeometryConverterBinding.h" // to enable friend declaration for bindFromHoudiniGeometryConverter()
56 
57 namespace IECoreHoudini
58 {
59 
60 IE_CORE_FORWARDDECLARE( FromHoudiniGeometryConverter );
61 
66 {
67  public :
68 
69  IE_CORE_DECLARERUNTIMETYPEDEXTENSION( FromHoudiniGeometryConverter, FromHoudiniGeometryConverterTypeId, IECore::ToCoreConverter );
70 
73 
74  static FromHoudiniGeometryConverterPtr create( const GU_DetailHandle &handle, IECore::TypeId resultType=IECore::InvalidTypeId );
81  static FromHoudiniGeometryConverterPtr create( const GU_DetailHandle &handle, const std::set<IECore::TypeId> &resultTypes );
83 
86  static void supportedTypes( std::set<IECore::TypeId> &types );
87 
90  static GU_DetailHandle extract( const GU_Detail *geo, const UT_StringMMPattern &nameFilter );
91 
92  enum Convertability
93  {
94  Inapplicable = 0,
95  Ideal,
96  Suitable,
97  Admissible,
98  InvalidValue,
99  };
100 
101  protected :
102 
103  FromHoudiniGeometryConverter( const GU_DetailHandle &handle, const std::string &description );
104  FromHoudiniGeometryConverter( const SOP_Node *sop, const std::string &description );
105 
106  virtual ~FromHoudiniGeometryConverter();
107 
111  virtual IECore::ObjectPtr doConversion( IECore::ConstCompoundObjectPtr operands ) const;
113  virtual IECore::ObjectPtr doDetailConversion( const GU_Detail *geo, const IECore::CompoundObject *operands ) const = 0;
114 
115  typedef FromHoudiniGeometryConverterPtr (*CreatorFn)( const GU_DetailHandle &handle );
116  typedef Convertability (*ConvertabilityFn)( const GU_DetailHandle &handle );
117 
118  static void registerConverter( IECore::TypeId resultType, CreatorFn creator, ConvertabilityFn canConvert );
119 
122  template<class T>
124  {
125  public :
126  Description( IECore::TypeId resultType );
127  private :
128  static FromHoudiniGeometryConverterPtr creator( const GU_DetailHandle &handle );
129  static Convertability canConvert( const GU_DetailHandle &handle );
130  };
131 
133  const GU_DetailHandle &handle() const;
135  static const GU_DetailHandle handle( const SOP_Node *sop );
136 
139  void transferAttribs(
140  const GU_Detail *geo, IECore::Primitive *result, const IECore::CompoundObject *operands,
141  IECore::PrimitiveVariable::Interpolation vertexInterpolation = IECore::PrimitiveVariable::FaceVarying,
142  IECore::PrimitiveVariable::Interpolation primitiveInterpolation = IECore::PrimitiveVariable::Uniform,
143  IECore::PrimitiveVariable::Interpolation pointInterpolation = IECore::PrimitiveVariable::Vertex,
144  IECore::PrimitiveVariable::Interpolation detailInterpolation = IECore::PrimitiveVariable::Constant
145  ) const;
146 
149  struct RemapInfo
150  {
151  std::string name;
152  IECore::TypeId type;
154  int elementIndex;
155  };
156 
158  typedef std::map<std::string, std::vector<RemapInfo> > AttributeMap;
159  void remapAttributes( const GU_Detail *geo, AttributeMap &pointAttributeMap, AttributeMap &primitiveAttributeMap ) const;
160 
163  const GU_Detail *geo, const UT_StringMMPattern &attribFilter,
165  ) const;
166  void transferElementAttribs(
167  const GU_Detail *geo, const GA_Range &range, const GA_AttributeDict &attribs, const UT_StringMMPattern &attribFilter,
168  AttributeMap &attributeMap, IECore::Primitive *result, IECore::PrimitiveVariable::Interpolation interpolation
169  ) const;
170 
171  void transferAttribData(
173  const GA_ROAttributeRef &attrRef, const GA_Range &range, const RemapInfo *remapInfo = 0
174  ) const;
175 
178  template <typename T>
179  typename T::Ptr extractData( const GA_Attribute *attr, const GA_Range &range, int elementIndex = -1 ) const;
180 
181  template <typename T>
182  typename T::Ptr extractData( const GA_Attribute *attr ) const;
183 
184  IECore::DataPtr extractStringVectorData( const GA_Attribute *attr, const GA_Range &range, IECore::IntVectorDataPtr &indexData ) const;
185  IECore::DataPtr extractStringData( const GU_Detail *geo, const GA_Attribute *attr ) const;
186 
187  private :
188 
189  void constructCommon();
190 
191  // This extra factory function is provided for the python bindings
192  friend void bindFromHoudiniGeometryConverter();
193  static FromHoudiniGeometryConverterPtr create( const SOP_Node *sop, const std::string &nameFilter = "", IECore::TypeId resultType=IECore::InvalidTypeId );
194 
195  // function to map standard Houdini names to IECore PrimitiveVariable names
196  const std::string processPrimitiveVariableName( const std::string &name ) const;
197 
198  // the handle to the GU_Detail
199  GU_DetailHandle m_geoHandle;
200  IECore::StringParameterPtr m_attributeFilterParameter;
201  IECore::BoolParameterPtr m_convertStandardAttributesParameter;
202 
203  struct Types
204  {
205  Types( IECore::TypeId result );
206  IECore::TypeId resultType;
207  bool operator < ( const Types &other ) const;
208  };
209 
210  typedef std::map<Types, std::pair<CreatorFn, ConvertabilityFn> > TypesToFnsMap;
211  static TypesToFnsMap *typesToFns();
212 };
213 
214 }
215 
216 #include "FromHoudiniGeometryConverter.inl"
217 
218 #endif // IECOREHOUDINI_FROMHOUDINIGEOMETRYCONVERTER_H
static GU_DetailHandle extract(const GU_Detail *geo, const UT_StringMMPattern &nameFilter)
Definition: FromHoudiniGeometryConverter.h:149
virtual IECore::ObjectPtr doDetailConversion(const GU_Detail *geo, const IECore::CompoundObject *operands) const =0
Must be implemented by derived classes to return an IECore::Object created to represent the specified...
T::Ptr extractData(const GA_Attribute *attr, const GA_Range &range, int elementIndex=-1) const
void transferDetailAttribs(const GU_Detail *geo, const UT_StringMMPattern &attribFilter, IECore::Primitive *result, IECore::PrimitiveVariable::Interpolation interpolation) const
Utility functions for transfering each attrib type from Houdini onto the IECore::Primitive provided...
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.
void transferAttribs(const GU_Detail *geo, IECore::Primitive *result, const IECore::CompoundObject *operands, 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
Definition: FromHoudiniGeometryConverter.h:65
static FromHoudiniGeometryConverterPtr create(const GU_DetailHandle &handle, IECore::TypeId resultType=IECore::InvalidTypeId)
static void supportedTypes(std::set< IECore::TypeId > &types)
const GU_DetailHandle & handle() const
returns a reference to the GU_DetailHandle
TypeId
Definition: TypeIds.h:46
Definition: CompoundObject.h:46
Definition: FromHoudiniGeometryConverter.h:123
Interpolation
Definition: PrimitiveVariable.h:53
Definition: Primitive.h:54
virtual IECore::ObjectPtr doConversion(IECore::ConstCompoundObjectPtr operands) const
Definition: ToCoreConverter.h:49
Definition: FromHoudiniConverter.h:48
std::map< std::string, std::vector< RemapInfo > > AttributeMap
Attribute remapping.
Definition: FromHoudiniGeometryConverter.h:158