コード例 #1
0
ファイル: HomogeneousMath.cpp プロジェクト: ethz-asl/iclcv
 float dist_point_linesegment(const Vec4 &p,const Vec4 &lineStart,const Vec4 &lineEnd,Vec4 *nearestPoint){
   Vec4  d1(p-lineStart);
   Vec4  d2(lineEnd-lineStart);
   Vec4  min_v(lineStart);
   float t = sprod3(d2,d2);
 
   if(t > std::numeric_limits<float>::min()){
     t = sprod3(d1,d2)/t;
     if(t > 1.0){
       d1 = p - (min_v = lineEnd);
     }else if(t > 0.f){
       d1 = p - (min_v = lineStart + d2*t);
     }
   }
 
   if(nearestPoint) *nearestPoint = min_v;
   return norm3(d1);
 }
コード例 #2
0
ファイル: Rocface.C プロジェクト: xyuan/IMPACT
void Rocface::transfer( const COM::DataItem *src, COM::DataItem *trg,
			const Real alpha, const int order, 
			Real *tol, int *iter, bool load) {
  typedef Transfer_traits<Source_type, Target_type, conserv>  Traits;

  std::string n1 = src->window()->name();
  std::string n2 = trg->window()->name();

  std::string wn1, wn2;
  get_name( n1, n2, wn1); get_name( n2, n1, wn2);
  
  TRS_Windows::iterator it1 = _trs_windows.find( wn1);
  TRS_Windows::iterator it2 = _trs_windows.find( wn2);

  if ( it1 == _trs_windows.end() || it2 == _trs_windows.end()) {
    std::cerr << "ROCFACE::ERROR: The overlay of window \"" << n1 
	      << "\" and window \"" << n2 << "\" does not exist"
	      << std::endl;
    RFC_assertion( false); MPI_Abort( MPI_COMM_WORLD, -1);
  }

  if ( !it1->second->replicated()) {
    it1->second->replicate_metadata( *it2->second);
  }

  Target_type tf( trg);
  Source_type sf( src);

  RFC_Window_transfer *w1=it1->second, *w2=it2->second;
  typename Traits::Transfer_type trans( w1, w2);

  // Print min, max, and integral before transfer
  if ( _ctrl.verb) {
    if ( w2->comm_rank()==0) {
      if (conserv) 
	std::cout << "ROCFACE: Conservatively transferring "; 
      else
	std::cout << "ROCFACE: Interpolating "; 
      std::cout << " from " << w1->name()+"."+src->name() 
		<< " to " << w2->name()+"."+trg->name() << std::endl; 
    }
    Vector_n min_v( sf.dimension()), max_v(sf.dimension());
    trans.minmax( *w1, sf, min_v, max_v);
    
    Vector_n integral(sf.dimension(),0);
    trans.integrate( *w1, sf, integral, order);
    
    if ( w1->comm_rank()==0) {
      std::cout << "ROCFACE: Before transfer\nROCFACE:\tminimum:  " << min_v
		<< "\nROCFACE:\tmaximum:  " << max_v;
      if ( !load) 
	std::cout << "\nROCFACE:\tintegral: " << std::setprecision(10)
		  << integral;
      std::cout << std::endl;
    }
  }

  // Perform data transfer
  Traits::transfer( trans, sf, tf, alpha, order, tol, iter, _ctrl.verb, load);

  // Print min, max, and integral after transfer
  if ( _ctrl.verb) {
    Vector_n min_v( sf.dimension()), max_v(sf.dimension());	
    trans.minmax( *w2, tf, min_v, max_v);
    
    Vector_n integral(sf.dimension(),0);			
    trans.integrate( *w2, tf, integral, order);
    
    if ( w2->comm_rank()==0) {
      std::cout << "ROCFACE: After transfer\nROCFACE:\tminimum:  " << min_v
		<< "\nROCFACE:\tmaximum:  " << max_v;
      if ( !load) 
	std::cout << "\nROCFACE:\tintegral: " << std::setprecision(10)
		  << integral;
      std::cout << std::endl;
    }
  }

  // Reset the tags, which indicate which nodes/elements should receive values
  w2->set_tags( NULL);
}