VolumeObject.cpp
/** Returns true if the given point is inside the mesh.
    Shoot a ray from the point: if it crosses an odd number of faces, it is inside.*/
Returns true if the given point is inside the mesh.
Shoot a ray from the point: if it crosses an odd number of faces, it is inside.
Returns true if the given point is inside the mesh . Shoot a ray from the point : if it crosses an odd number of faces it is inside .
static bool pointInsideMesh(const Vector3& point,
                            const std::vector<uint32_t>& indices,
                            const std::vector<Vector3>& vertices)
{  
    const Vector3 rayDirection(0, 1, 0);
    const uint32_t faceCount = indices.size() / 3;
    uint32_t intersectionsWithFaces = 0;
    for (uint32_t face = 0; face < faceCount; ++face) {
      const uint32_t baseForFace = face * 3;
      const size_t indexV0 = indices.at(baseForFace);
      const size_t indexV1 = indices.at(baseForFace + 1);
      const size_t indexV2 = indices.at(baseForFace + 2);
      const auto& V0 = vertices.at(indexV0);
      const auto& V1 = vertices.at(indexV1);
      const auto& V2 = vertices.at(indexV2);
      Vector3 intersectionPointIDoNotCareAbout;  
      if (1 == intersect3D_RayTriangle(std::make_tuple(point, rayDirection + point),
                                       std::make_tuple(V0, V1, V2),
                                       intersectionPointIDoNotCareAbout))
        intersectionsWithFaces++;
    }
    return (intersectionsWithFaces % 2) == 1;
}
static bool pointInsideMesh ( const Vector3 & point , const std :: vector < uint32_t > & indices , const std :: vector < Vector3 > & vertices ) { const Vector3 rayDirection ( 0 , 1 , 0 ) ; const uint32_t faceCount = indices . size ( ) / 3 ; uint32_t intersectionsWithFaces = 0 ; for ( uint32_t face = 0 ; face < faceCount ; ++ face ) { const uint32_t baseForFace = face * 3 ; const size_t indexV0 = indices . at ( baseForFace ) ; const size_t indexV1 = indices . at ( baseForFace + 1 ) ; const size_t indexV2 = indices . at ( baseForFace + 2 ) ; const auto & V0 = vertices . at ( indexV0 ) ; const auto & V1 = vertices . at ( indexV1 ) ; const auto & V2 = vertices . at ( indexV2 ) ; Vector3 intersectionPointIDoNotCareAbout ; if ( 1 == intersect3D_RayTriangle ( std :: make_tuple ( point , rayDirection + point ) , std :: make_tuple ( V0 , V1 , V2 ) , intersectionPointIDoNotCareAbout ) ) intersectionsWithFaces ++ ; } return ( intersectionsWithFaces % 2 ) == 1 ; }
Returns true if the given point is inside the mesh.
Returns true if the given point is inside the mesh .
// Define the ray for this point. In theory The direction does not matter, so the ray goes straight up. // In practice there are approximations and the results depend (a lot!) on the direction. // There must be a smarter way... //But the code of the library computes it anyway...