Cortex  10.0.0-a4
PrimitiveEvaluator.h
1 //
3 // Copyright (c) 2008-2011, 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 IE_CORE_PRIMITIVEEVALUATOR_H
36 #define IE_CORE_PRIMITIVEEVALUATOR_H
37 
38 #include <string>
39 
40 #include "OpenEXR/ImathVec.h"
41 #include "OpenEXR/ImathColor.h"
42 
43 #include "IECore/Export.h"
44 #include "IECore/RunTimeTyped.h"
45 #include "IECore/Primitive.h"
46 
47 namespace IECore
48 {
49 
50 IE_CORE_FORWARDDECLARE( PrimitiveEvaluator );
51 
57 class IECORE_API PrimitiveEvaluator : public RunTimeTyped
58 {
59  public:
60 
61  typedef PrimitiveEvaluatorPtr ( *CreatorFn )( ConstPrimitivePtr );
62 
63  IE_CORE_DECLARERUNTIMETYPED( PrimitiveEvaluator, RunTimeTyped );
64 
68  class Result : public RefCounted
69  {
70  public:
71 
72  IE_CORE_DECLAREMEMBERPTR( Result );
73 
74  ~Result() override;
75 
77  virtual Imath::V3f point() const =0;
78 
81  virtual Imath::V3f normal() const =0;
82 
84  virtual Imath::V2f uv() const =0;
85 
87  virtual Imath::V3f uTangent() const =0;
88 
90  virtual Imath::V3f vTangent() const =0;
91 
95 
96  virtual Imath::V3f vectorPrimVar( const PrimitiveVariable &pv ) const =0;
97  virtual Imath::V2f vec2PrimVar ( const PrimitiveVariable &pv ) const =0;
98  virtual float floatPrimVar ( const PrimitiveVariable &pv ) const =0;
99  virtual int intPrimVar ( const PrimitiveVariable &pv ) const =0;
100  virtual const std::string &stringPrimVar( const PrimitiveVariable &pv ) const =0;
101  virtual Imath::Color3f colorPrimVar ( const PrimitiveVariable &pv ) const =0;
102  virtual half halfPrimVar ( const PrimitiveVariable &pv ) const =0;
104  };
105  IE_CORE_DECLAREPTR( Result );
106 
109  static PrimitiveEvaluatorPtr create( ConstPrimitivePtr primitive );
110 
111  ~PrimitiveEvaluator() override;
112 
114  virtual ResultPtr createResult() const = 0;
115 
117  virtual ConstPrimitivePtr primitive() const = 0;
118 
128 
129 
133  virtual bool signedDistance( const Imath::V3f &p, float &distance, Result *result ) const;
134 
136  virtual float surfaceArea() const=0;
137 
139  virtual float volume() const=0;
140 
142  virtual Imath::V3f centerOfGravity() const=0;
143 
146  virtual bool closestPoint( const Imath::V3f &p, Result *result ) const =0;
147 
149  virtual bool pointAtUV( const Imath::V2f &uv, Result *result ) const =0;
150 
153  virtual bool intersectionPoint( const Imath::V3f &origin, const Imath::V3f &direction,
154  Result *result, float maxDistance = Imath::limits<float>::max() ) const =0;
155 
158  virtual int intersectionPoints( const Imath::V3f &origin, const Imath::V3f &direction,
159  std::vector<ResultPtr> &results, float maxDistance = Imath::limits<float>::max() ) const =0;
160 
162 
164  virtual void validateResult( Result *result ) const =0;
165 
168  template< typename E, typename P = typename E::PrimitiveType >
169  struct Description
170  {
171  Description()
172  {
173  registerCreator( P::staticTypeId(), & E::create );
174  }
175  };
176 
177  private:
178 
179  static void registerCreator( TypeId id, CreatorFn f );
180 
181  typedef std::map< TypeId, CreatorFn > CreatorMap;
182 
183  static CreatorMap &getCreateFns();
184 
185 };
186 
187 IE_CORE_DECLAREPTR( PrimitiveEvaluator );
188 
189 } // namespace IECore
190 
191 #endif // IE_CORE_PRIMITIVEEVALUATOR_H
Definition: PrimitiveVariable.h:47
Definition: PrimitiveEvaluator.h:57
Definition: PrimitiveEvaluator.h:169
TypeId
Definition: TypeIds.h:46
Definition: PrimitiveEvaluator.h:68
Definition: RefCounted.h:124
Definition: RunTimeTyped.h:211
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43