35 #ifndef IE_CORE_MESHPRIMITIVEEVALUATOR_H
36 #define IE_CORE_MESHPRIMITIVEEVALUATOR_H
40 #include "tbb/mutex.h"
42 #include "IECore/Export.h"
43 #include "IECore/PrimitiveEvaluator.h"
44 #include "IECore/MeshPrimitive.h"
45 #include "IECore/BoundedKDTree.h"
66 IE_CORE_DECLAREMEMBERPTR( Result );
70 Imath::V3f point()
const override;
71 Imath::V3f normal()
const override;
72 Imath::V2f uv()
const override;
73 Imath::V3f uTangent()
const override;
74 Imath::V3f vTangent()
const override;
84 unsigned int triangleIndex()
const;
85 const Imath::V3f &barycentricCoordinates()
const;
86 const Imath::V3i &vertexIds()
const;
90 Imath::V3i m_vertexIds;
97 unsigned int m_triangleIdx;
104 IE_CORE_DECLAREPTR( Result );
106 static PrimitiveEvaluatorPtr create( ConstPrimitivePtr primitive );
112 ConstPrimitivePtr primitive()
const override;
113 MeshPrimitive::ConstPtr mesh()
const;
115 PrimitiveEvaluator::ResultPtr createResult()
const override;
123 bool intersectionPoint(
const Imath::V3f &origin,
const Imath::V3f &direction,
126 int intersectionPoints(
const Imath::V3f &origin,
const Imath::V3f &direction,
127 std::vector<PrimitiveEvaluator::ResultPtr> &results,
float maxDistance = Imath::limits<float>::max() )
const override;
130 bool barycentricPosition(
unsigned int triangleIndex,
const Imath::V3f &barycentricCoordinates,
PrimitiveEvaluator::Result *result )
const;
134 float volume()
const override;
136 Imath::V3f centerOfGravity()
const override;
138 float surfaceArea()
const override;
142 const Imath::Box2f uvBound()
const;
157 const TriangleBoundVector *triangleBounds()
const;
160 const TriangleBoundTree *triangleBoundTree()
const;
170 const UVBoundVector *uvBounds()
const;
174 const UVBoundTree *uvBoundTree()
const;
179 ConstMeshPrimitivePtr m_mesh;
180 ConstV3fVectorDataPtr m_verts;
181 const std::vector<int> *m_meshVertexIds;
183 TriangleBoundVector m_triangles;
184 TriangleBoundTree *m_tree;
186 UVBoundVector m_uvTriangles;
187 UVBoundTree *m_uvTree;
189 bool pointAtUVWalk( UVBoundTree::NodeIndex nodeIndex,
const Imath::V2f &targetUV, Result *result )
const;
190 void closestPointWalk( TriangleBoundTree::NodeIndex nodeIndex,
const Imath::V3f &p,
float &closestDistanceSqrd, Result *result )
const;
191 bool intersectionPointWalk( TriangleBoundTree::NodeIndex nodeIndex,
const Imath::Line3f &ray,
float &maxDistSqrd, Result *result,
bool &hit )
const;
192 void intersectionPointsWalk( TriangleBoundTree::NodeIndex nodeIndex,
const Imath::Line3f &ray,
float maxDistSqrd, std::vector<PrimitiveEvaluator::ResultPtr> &results )
const;
194 void calculateMassProperties()
const;
195 void calculateAverageNormals()
const;
197 void triangleUVs(
size_t triangleIndex,
const Imath::V3i &vertexIds, Imath::V2f uv[3] )
const;
200 mutable bool m_haveMassProperties;
201 mutable float m_volume;
202 mutable Imath::V3f m_centerOfGravity;
203 mutable Imath::M33f m_inertia;
205 mutable bool m_haveSurfaceArea;
206 mutable float m_surfaceArea;
208 typedef tbb::mutex NormalsMutex;
209 mutable NormalsMutex m_normalsMutex;
210 mutable bool m_haveAverageNormals;
211 typedef int VertexIndex;
212 typedef int TriangleIndex;
213 typedef std::pair<VertexIndex, VertexIndex> Edge;
215 typedef std::map< Edge, Imath::V3f > EdgeAverageNormals;
216 mutable EdgeAverageNormals m_edgeAverageNormals;
218 mutable V3fVectorDataPtr m_vertexAngleWeightedNormals;
226 #endif // IE_CORE_MESHPRIMITIVEEVALUATOR_H
Imath::Box2f UVBound
A type for storing the uv bounding box for a triangle.
Definition: MeshPrimitiveEvaluator.h:163
Definition: BoundedKDTree.h:50
Definition: PrimitiveVariable.h:47
Definition: PrimitiveEvaluator.h:57
Definition: MeshPrimitive.h:56
Definition: MeshPrimitiveEvaluator.h:52
std::vector< UVBound > UVBoundVector
A type for storing an array of uv bounds, one per triangle.
Definition: MeshPrimitiveEvaluator.h:165
Definition: PrimitiveEvaluator.h:68
std::vector< TriangleBound > TriangleBoundVector
A type for storing an array of bounding boxes, one per triangle.
Definition: MeshPrimitiveEvaluator.h:153
BoundedKDTree< TriangleBoundVector::iterator > TriangleBoundTree
A BoundedKDTree providing accelerated lookups of triangles using their bounding boxes.
Definition: MeshPrimitiveEvaluator.h:155
Imath::Box3f TriangleBound
A type for storing the bounding box for a triangle.
Definition: MeshPrimitiveEvaluator.h:151
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43
BoundedKDTree< UVBoundVector::iterator > UVBoundTree
A BoundedKDTree providing accelerated lookups of triangles using their uv bounds. ...
Definition: MeshPrimitiveEvaluator.h:167