diff --git a/ttcr/Cell.h b/ttcr/Cell.h index ea114ece..6564c06b 100644 --- a/ttcr/Cell.h +++ b/ttcr/Cell.h @@ -102,6 +102,11 @@ namespace ttcr { const size_t cellNo) const { return slowness[cellNo] * source.getDistance( node ); } + + void computeDistance(const NODE& source, const S& node, + siv& cell) const { + cell.v = source.getDistance( node ); + } void computeDistance(const NODE& source, const S& node, siv2& cell) const { cell.v = source.getDistance( node ); @@ -188,6 +193,13 @@ namespace ttcr { T lz = node.getZ() - source.getZ(); return slowness[cellNo] * std::sqrt( lx*lx + xi[cellNo]*lz*lz ); } + + void computeDistance(const NODE& source, const S& node, + siv& cell) const { + assert(false); // we should not end up here + cell.v = std::sqrt((node.x - source.getX())*(node.x - source.getX()) + + (node.z - source.getZ())*(node.z - source.getZ())); + } void computeDistance(const NODE& source, const S& node, siv2& cell) const { cell.v = std::abs(node.x - source.getX()); @@ -296,6 +308,12 @@ namespace ttcr { return slowness[cellNo] * std::sqrt( t1*t1 + xi[cellNo]*t2*t2 ); } + void computeDistance(const NODE& source, const S& node, + siv& cell) const { + assert(false); // we should not end up here + cell.v = std::sqrt((node.x - source.getX())*(node.x - source.getX()) + + (node.z - source.getZ())*(node.z - source.getZ())); + } void computeDistance(const NODE& source, const S& node, siv2& cell) const { cell.v = std::abs(node.x - source.getX()); @@ -431,6 +449,12 @@ namespace ttcr { return source.getDistance( node ) / v; } + void computeDistance(const NODE& source, const S& node, + siv& cell) const { + assert(false); // we should not end up here + cell.v = std::sqrt((node.x - source.getX())*(node.x - source.getX()) + + (node.z - source.getZ())*(node.z - source.getZ())); + } void computeDistance(const NODE& source, const S& node, siv2& cell) const { cell.v = std::abs(node.x - source.getX()); @@ -526,6 +550,12 @@ namespace ttcr { return source.getDistance( node ) / v; } + void computeDistance(const NODE& source, const S& node, + siv& cell) const { + assert(false); // we should not end up here + cell.v = std::sqrt((node.x - source.getX())*(node.x - source.getX()) + + (node.z - source.getZ())*(node.z - source.getZ())); + } void computeDistance(const NODE& source, const S& node, siv2& cell) const { cell.v = std::abs(node.x - source.getX()); diff --git a/ttcr/Grid2Drcsp.h b/ttcr/Grid2Drcsp.h index b3c35680..f64ee9d9 100644 --- a/ttcr/Grid2Drcsp.h +++ b/ttcr/Grid2Drcsp.h @@ -91,7 +91,15 @@ namespace ttcr { std::vector*>& traveltimes, std::vector>*>& r_data, const size_t threadNo=0) const; - + + void raytrace(const std::vector& Tx, + const std::vector& t0, + const std::vector& Rx, + std::vector& traveltimes, + std::vector>& r_data, + std::vector>>& l_data, + const size_t threadNo) const; + void raytrace(const std::vector& Tx, const std::vector& t0, const std::vector& Rx, @@ -346,7 +354,6 @@ namespace ttcr { } - template void Grid2Drcsp::initQueue(const std::vector& Tx, const std::vector& t0, @@ -777,7 +784,139 @@ namespace ttcr { (*r_data[nr])[n][nn].x = r_tmp[ iParent-1-nn ].x; (*r_data[nr])[n][nn].z = r_tmp[ iParent-1-nn ].z; } + } + } + } + + template + void Grid2Drcsp::raytrace(const std::vector& Tx, + const std::vector& t0, + const std::vector& Rx, + std::vector& traveltimes, + std::vector>& r_data, + std::vector>>& l_data, + const size_t threadNo) const { + this->checkPts(Tx); + this->checkPts(Rx); + + for ( size_t n=0; nnodes.size(); ++n ) { + this->nodes[n].reinit( threadNo ); + } + + CompareNodePtr cmp(threadNo); + std::priority_queue< Node2Dcsp*, std::vector*>, + CompareNodePtr> queue( cmp ); + std::vector> txNodes; + std::vector inQueue( this->nodes.size(), false ); + std::vector frozen( this->nodes.size(), false ); + + initQueue(Tx, t0, queue, txNodes, inQueue, frozen, threadNo); + + propagate(queue, inQueue, frozen, threadNo); + + if ( traveltimes.size() != Rx.size() ) { + traveltimes.resize( Rx.size() ); + } + if ( l_data.size() != Rx.size() ) { + l_data.resize( Rx.size() ); + } + for ( size_t ni=0; ninodes, nodeParentRx, cellParentRx, + threadNo); + + // Rx are in nodes (not txNodes) + std::vector> *node_p; + node_p = &(this->nodes); + + std::vector> r_tmp; + T2 iChild, iParent = nodeParentRx; + sxz child; + siv cell; + + // store the son's coord + child.x = Rx[n].x; + child.z = Rx[n].z; + cell.i = cellParentRx; + while ( (*node_p)[iParent].getNodeParent(threadNo) != std::numeric_limits::max() ) { + + r_tmp.push_back( child ); + + //cell.v = (*node_p)[iParent].getDistance( child ); + this->cells.computeDistance( (*node_p)[iParent], child, cell); + bool found=false; + for (size_t nc=0; nc= this->nodes.size() ) { + node_p = &txNodes; + iParent -= this->nodes.size(); + } + else { + node_p = &(this->nodes); + } + } + + // parent is now at Tx + r_tmp.push_back( child ); + + //cell.v = (*node_p)[iParent].getDistance( child ); + this->cells.computeDistance( (*node_p)[iParent], child, cell); + bool found=false; + for (size_t nc=0; nc()); + + // the order should be from Tx to Rx, so we reorder... + iParent = static_cast(r_tmp.size()); + r_data[n].resize( r_tmp.size() ); + for ( size_t nn=0; nn