+
+ // add not split hexadrons to the mesh
+ int nbAdded = 0;
+ vector<int> intHexInd( nbIntHex );
+ nbIntHex = 0;
+ for ( size_t i = 0; i < intersectedHex.size(); ++i )
+ {
+ Hexahedron * & hex = intersectedHex[ i ];
+ if ( hex )
+ {
+ intHexInd[ nbIntHex++ ] = i;
+ if ( hex->_nbIntNodes > 0 ) continue;
+ init( hex->_i, hex->_j, hex->_k );
+ }
+ else
+ {
+ init( i );
+ }
+ if ( _nbCornerNodes == 8 && ( _nbBndNodes < _nbCornerNodes || !isInHole() ))
+ {
+ // order of _hexNodes is defined by enum SMESH_Block::TShapeID
+ SMDS_MeshElement* el =
+ mesh->AddVolume( _hexNodes[0].Node(), _hexNodes[2].Node(),
+ _hexNodes[3].Node(), _hexNodes[1].Node(),
+ _hexNodes[4].Node(), _hexNodes[6].Node(),
+ _hexNodes[7].Node(), _hexNodes[5].Node() );
+ mesh->SetMeshElementOnShape( el, helper.GetSubShapeID() );
+ ++nbAdded;
+ if ( hex )
+ {
+ delete hex;
+ intersectedHex[ i ] = 0;
+ --nbIntHex;
+ }
+ }
+ else if ( _nbCornerNodes > 3 && !hex )
+ {
+ // all intersection of hex with geometry are at grid nodes
+ hex = new Hexahedron( *this );
+ hex->init( i );
+ intHexInd.push_back(0);
+ intHexInd[ nbIntHex++ ] = i;
+ }
+ }
+
+ // add elements resulted from hexadron intersection
+#ifdef WITH_TBB
+ intHexInd.resize( nbIntHex );
+ tbb::parallel_for ( tbb::blocked_range<size_t>( 0, nbIntHex ),
+ ParallelHexahedron( intersectedHex, intHexInd ),
+ tbb::simple_partitioner()); // ComputeElements() is called here
+ for ( size_t i = 0; i < intHexInd.size(); ++i )
+ if ( Hexahedron * hex = intersectedHex[ intHexInd[ i ]] )
+ nbAdded += hex->addElements( helper );
+#else
+ for ( size_t i = 0; i < intHexInd.size(); ++i )
+ if ( Hexahedron * hex = intersectedHex[ intHexInd[ i ]] )
+ {
+ hex->ComputeElements();
+ nbAdded += hex->addElements( helper );
+ }
+#endif
+
+ for ( size_t i = 0; i < intersectedHex.size(); ++i )
+ if ( intersectedHex[ i ] )
+ delete intersectedHex[ i ];
+
+ return nbAdded;