Cortex  10.0.0-a4
CurvesPrimitiveEvaluator.h
1 //
3 // Copyright (c) 2009-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 IECORE_CURVESPRIMITIVEEVALUATOR_H
36 #define IECORE_CURVESPRIMITIVEEVALUATOR_H
37 
38 #include "tbb/mutex.h"
39 
40 #include "IECore/Export.h"
41 #include "IECore/PrimitiveEvaluator.h"
42 #include "IECore/BoundedKDTree.h"
43 
44 namespace IECore
45 {
46 
47 IE_CORE_FORWARDDECLARE( CurvesPrimitive )
48 
49 class IECORE_API CurvesPrimitiveEvaluator : public PrimitiveEvaluator
53 {
54 
55  public :
56 
57  typedef CurvesPrimitive PrimitiveType;
58 
59  IE_CORE_DECLARERUNTIMETYPED( CurvesPrimitiveEvaluator, PrimitiveEvaluator );
60 
61  class IECORE_API Result : public PrimitiveEvaluator::Result
62  {
63  public :
64 
65  IE_CORE_DECLAREMEMBERPTR( Result );
66 
67  Imath::V3f point() const override;
69  Imath::V3f normal() const override;
71  Imath::V2f uv() const override;
73  Imath::V3f uTangent() const override;
74  Imath::V3f vTangent() const override;
75  unsigned curveIndex() const;
76 
77  Imath::V3f vectorPrimVar( const PrimitiveVariable &pv ) const override;
78  Imath::V2f vec2PrimVar( const PrimitiveVariable &pv ) const override;
79  float floatPrimVar( const PrimitiveVariable &pv ) const override;
80  int intPrimVar( const PrimitiveVariable &pv ) const override;
81  const std::string &stringPrimVar( const PrimitiveVariable &pv ) const override;
82  Imath::Color3f colorPrimVar( const PrimitiveVariable &pv ) const override;
83  half halfPrimVar( const PrimitiveVariable &pv ) const override;
84 
85  private :
86 
87  friend class CurvesPrimitiveEvaluator;
88 
89  Result( PrimitiveVariable p, bool linear, bool periodic );
90 
91  typedef void (Result::*InitFunction)( unsigned curveIndex, float v, const CurvesPrimitiveEvaluator *evaluator );
92 
93  template<bool linear, bool periodic>
94  void init( unsigned curveIndex, float v, const CurvesPrimitiveEvaluator *evaluator );
95 
96  template<typename T>
97  T primVar( const PrimitiveVariable &pv, const float *coefficients ) const;
98 
99  unsigned m_curveIndex;
100  float m_v;
101  float m_segmentV;
102  float m_coefficients[4];
103  float m_derivativeCoefficients[4];
104  unsigned m_vertexDataIndices[4];
105  unsigned m_varyingDataIndices[2];
106  PrimitiveVariable m_p;
107  bool m_linear;
108  InitFunction m_init;
109 
110 
111  };
112  IE_CORE_DECLAREPTR( Result );
113 
114  CurvesPrimitiveEvaluator( ConstCurvesPrimitivePtr curves );
115  ~CurvesPrimitiveEvaluator() override;
116 
117  ConstPrimitivePtr primitive() const override;
118 
119  PrimitiveEvaluator::ResultPtr createResult() const override;
120  void validateResult( PrimitiveEvaluator::Result *result ) const override;
121 
124 
125  float surfaceArea() const override;
128  float volume() const override;
130  Imath::V3f centerOfGravity() const override;
131  bool closestPoint( const Imath::V3f &p, PrimitiveEvaluator::Result *result ) const override;
133  bool pointAtUV( const Imath::V2f &uv, PrimitiveEvaluator::Result *result ) const override;
135  bool intersectionPoint( const Imath::V3f &origin, const Imath::V3f &direction,
136  PrimitiveEvaluator::Result *result, float maxDistance = Imath::limits<float>::max() ) const override;
138  int intersectionPoints( const Imath::V3f &origin, const Imath::V3f &direction,
139  std::vector<PrimitiveEvaluator::ResultPtr> &results, float maxDistance = Imath::limits<float>::max() ) const override;
141 
144 
145  bool pointAtV( unsigned curveIndex, float v, PrimitiveEvaluator::Result *result ) const;
148  float curveLength( unsigned curveIndex, float vStart=0.0f, float vEnd=1.0f ) const;
150 
155 
156  const std::vector<int> &verticesPerCurve() const;
161  const std::vector<int> &vertexDataOffsets() const;
163  const std::vector<int> &varyingDataOffsets() const;
165 
166  protected :
167 
170  static PrimitiveEvaluatorPtr create( ConstPrimitivePtr primitive );
171  friend struct PrimitiveEvaluator::Description<CurvesPrimitiveEvaluator>;
172  static PrimitiveEvaluator::Description<CurvesPrimitiveEvaluator> g_evaluatorDescription;
173 
174  private :
175 
176  friend class Result;
177 
178  float integrateCurve( unsigned curveIndex, float vStart, float vEnd, int samples, Result& typedResult ) const;
179 
180  CurvesPrimitivePtr m_curvesPrimitive;
181  const std::vector<int> &m_verticesPerCurve;
182  std::vector<int> m_vertexDataOffsets; // one value per curve
183  std::vector<int> m_varyingDataOffsets; // one value per curve
184  PrimitiveVariable m_p;
185 
186  void buildTree();
187  bool m_haveTree;
188  typedef tbb::mutex TreeMutex;
189  TreeMutex m_treeMutex;
190  Box3fTree m_tree;
191  std::vector<Imath::Box3f> m_treeBounds;
192  struct Line;
193  std::vector<Line> m_treeLines;
194 
195  void closestPointWalk( Box3fTree::NodeIndex nodeIndex, const Imath::V3f &p, unsigned &curveIndex, float &v, float &closestDistSquared ) const;
196 
197 };
198 
199 IE_CORE_DECLAREPTR( CurvesPrimitiveEvaluator );
200 
201 } // namespace IECore
202 
203 #endif // IECORE_CURVESPRIMITIVEEVALUATOR_H
IECOREGL_API void init(bool glAlreadyInitialised=false)
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43