| 967 | } |
| 968 | |
| 969 | Imath::Box3f IECoreScene::MeshAlgo::MeshSplitter::bound( int segmentId, const IECore::Canceller *canceller ) const |
| 970 | { |
| 971 | if( segmentId < 0 || segmentId > (int)m_meshIndices.size() ) |
| 972 | { |
| 973 | throw IECore::Exception( "Invalid segment id " + std::to_string( segmentId ) ); |
| 974 | } |
| 975 | |
| 976 | Box3f result; |
| 977 | PrimitiveVariableMap::const_iterator it = m_mesh->variables.find( "P" ); |
| 978 | if( it == m_mesh->variables.end() ) |
| 979 | { |
| 980 | return result; |
| 981 | } |
| 982 | |
| 983 | ConstV3fVectorDataPtr pData = runTimeCast<const V3fVectorData>( it->second.data ); |
| 984 | if( !pData ) |
| 985 | { |
| 986 | return result; |
| 987 | } |
| 988 | |
| 989 | const std::vector<V3f> &p = pData->readable(); |
| 990 | |
| 991 | // Based on our index, and the index of the next mesh in m_meshIndices, we know how many faces to scan |
| 992 | const int startIndex = m_meshIndices[ segmentId ]; |
| 993 | const int endIndex = ( segmentId + 1 < (int)m_meshIndices.size() ) ? m_meshIndices[ segmentId + 1 ] : m_faceRemap.size(); |
| 994 | |
| 995 | const std::vector<int> &sourceVertexIds = m_mesh->vertexIds()->readable(); |
| 996 | const std::vector<int> &sourceVerticesPerFace = m_mesh->verticesPerFace()->readable(); |
| 997 | |
| 998 | Canceller::check( canceller ); |
| 999 | |
| 1000 | // Loop through every face in this output, and all the vertices in each face, and extend the result |
| 1001 | // by the position for each vertex index |
| 1002 | for( int i = startIndex; i < endIndex; i++ ) |
| 1003 | { |
| 1004 | if( i % 10000 == 0 ) |
| 1005 | { |
| 1006 | Canceller::check( canceller ); |
| 1007 | } |
| 1008 | |
| 1009 | int originalFaceIndex = m_faceRemap[i]; |
| 1010 | int faceVerts = sourceVerticesPerFace[ originalFaceIndex ]; |
| 1011 | int faceStart = m_faceIndices[ originalFaceIndex ]; |
| 1012 | for( int j = 0; j < faceVerts; j++ ) |
| 1013 | { |
| 1014 | result.extendBy( p[ sourceVertexIds[ faceStart + j ] ] ); |
| 1015 | } |
| 1016 | } |
| 1017 | return result; |
| 1018 | } |