コード例 #1
0
ファイル: FacetParamTool.cpp プロジェクト: chrismullins/cgma
//===================================================================================
// Function: locate_point_in_uv (Public)
// Description: same as title (the_point must have coords (u,v,0.0))
// Author: chynes
// Date: 7/10/02
//===================================================================================
CubitStatus FacetParamTool::
locate_point_in_uv(FacetSurface *surf, const CubitVector &the_point, CubitFacet *&tri_ptr) 
{
	CubitStatus rv = CUBIT_SUCCESS;

	DLIList<CubitFacet *> facet_list;
	int tool_id = surf->get_eval_tool()->tool_id();
	surf->get_eval_tool()->get_facets(facet_list);
	tri_ptr = facet_list.get();

	// loop until we find something

	CubitPoint *p0, *p1, *p2;
	double aa, bb, cc;
	double u0, u1, u2, v0, v1, v2;
	CubitBoolean found = CUBIT_FALSE;
	while(!found && rv == CUBIT_SUCCESS)
	{
		tri_ptr->points(p0, p1, p2);
		p0->get_uv(tri_ptr, u0, v0);
		p1->get_uv(tri_ptr, u1, v1);
		p2->get_uv(tri_ptr, u2, v2);
		aa = DETERM(the_point.x(), the_point.y(), u1, v1, u2, v2);
		bb = DETERM(u0, v0, the_point.x(), the_point.y(), u2, v2);
		cc = DETERM(u0, v0, u1, v1, the_point.x(), the_point.y());
		if (aa > -INSIDE_TOL &&
			bb > -INSIDE_TOL &&
			cc > -INSIDE_TOL)
		{
			found = CUBIT_TRUE;  // this is the one
		}
		else
		{
			// set up to check the next logical neighbor
			if (aa <= bb && aa <= cc) {
				int edge_index = 1;
				tri_ptr = tri_ptr->adjacent( edge_index, &tool_id );
			}
			else if (bb <= aa && bb <= cc) {
				int edge_index = 2;
				tri_ptr = tri_ptr->adjacent( edge_index, &tool_id );
			}
			else {
				int edge_index = 0;
				tri_ptr = tri_ptr->adjacent( edge_index, &tool_id);
			}
			// check to see if we've left the triangulation
      
			if (tri_ptr == NULL)
			{
				rv = exhaustive_locate_point_in_uv(surf, the_point, tri_ptr );
				found = CUBIT_TRUE;
			}
		}
	}

	return rv;
}
コード例 #2
0
ファイル: CubitFacetEdge.cpp プロジェクト: chrismullins/cgma
 //=========================================================================== 
//Function Name: intersect 
// 
//Member Type:  PUBLIC 
//Description:  intersect the edge with a segment.  Assumes segment and edge
//              are on the same plane (project to facet plane first) 
//=========================================================================== 
CubitStatus CubitFacetEdge::intersect(
  CubitVector &aa, CubitVector &bb, // end point of segment
  CubitVector &norm,  // normal of the common plane
  CubitVector &qq,  // return the intersection point 
  CubitBoolean &does_intersect ) // return status of intersection
{  
 
  CubitPoint *pt0 = this->point(0); 
  CubitPoint *pt1 = this->point(1); 

  double P0[2], P1[2], AA[2], BB[2];
  CubitVector absnorm(fabs(norm.x()), fabs(norm.y()), fabs(norm.z()));
  if (absnorm.x() >= absnorm.y() && absnorm.x() >= absnorm.z())
  {
    P0[0] = pt0->coordinates().y();  P0[1] = pt0->coordinates().z();
    P1[0] = pt1->coordinates().y();  P1[1] = pt1->coordinates().z();
    AA[0] = aa.y();                  AA[1] = aa.z();
    BB[0] = bb.y();                  BB[1] = bb.z();
  }
  else if (absnorm.y() >= absnorm.x() && absnorm.y() >= absnorm.z())
  {
    P0[0] = pt0->coordinates().z();  P0[1] = pt0->coordinates().x();
    P1[0] = pt1->coordinates().z();  P1[1] = pt1->coordinates().x();
    AA[0] = aa.z();                  AA[1] = aa.x();
    BB[0] = bb.z();                  BB[1] = bb.x();
  }
  else
  {
    P0[0] = pt0->coordinates().x();  P0[1] = pt0->coordinates().y();
    P1[0] = pt1->coordinates().x();  P1[1] = pt1->coordinates().y();
    AA[0] = aa.x();                  AA[1] = aa.y();
    BB[0] = bb.x();                  BB[1] = bb.y();
  }

  double QQ[4], s;
  int ninter = intersect_2D_segments(P0, P1, AA, BB, QQ);

  if (ninter != 1)
  {
    does_intersect = CUBIT_FALSE;
    return CUBIT_SUCCESS;
  }
  does_intersect = CUBIT_TRUE;
 
  double dx = P1[0] - P0[0];
  double dy = P1[1] - P0[1];
  if (fabs(dx) > fabs(dy))
    s = (QQ[0] - P0[0]) / dx;
  else
    s = (QQ[1] - P0[1]) / dy;
  
  qq = pt0->coordinates() + s * (pt1->coordinates() - pt0->coordinates());
 
  return CUBIT_SUCCESS; 
}  
コード例 #3
0
ファイル: KDDTree.cpp プロジェクト: tenpercent/cp-sandbox
template <class Z> KDDTreeNode<Z> *KDDTree<Z>::recursive_balance
 (DIMENSION dim, int left, int right, KDDTreeNode<Z>** array, KDDTreeNode<Z>* parent)
{
  if (left > right)
  {
    return NULL;
  }
  else
  {
    KDDTreeNode<Z>* P;
    int K;

    if (left != right)
    {
      K = modifind (dim, left, right, array);
      P = array[K];
    }
    else
    {
      K = left;
      P = array[left];
    }

    myNodeList.push (P);

    P->safetyBox.reset (P->boundingBox);
    for (int i = left; i <= right; i++)
    {
      CubitVector imin = array[i]->safetyBox.minimum();
      CubitVector imax = array[i]->safetyBox.maximum();
      CubitVector pmin = P->safetyBox.minimum();
      CubitVector pmax = P->safetyBox.maximum();

      if (imin.x() < pmin.x()) pmin.x (imin.x());
      if (imin.y() < pmin.y()) pmin.y (imin.y());
      if (imin.z() < pmin.z()) pmin.z (imin.z());
      if (imax.x() > pmax.x()) pmax.x (imax.x());
      if (imax.y() > pmax.y()) pmax.y (imax.y());
      if (imax.z() > pmax.z()) pmax.z (imax.z());

      P->safetyBox.reset (pmin, pmax);
    }

    DIMENSION nextDim;
    switch (dim)
    {
      case DIMX: nextDim = DIMY; break;
      case DIMY: nextDim = DIMZ; break;
      default:   nextDim = DIMX;
    }

    P->set_disc (dim);
    P->parent = parent;

    P->left = recursive_balance (nextDim, left, K - 1, array, P);
    P->right = recursive_balance (nextDim, K + 1, right, array, P);

    return P;
  }
}
コード例 #4
0
ファイル: SphereEvaluator.cpp プロジェクト: chrismullins/cgma
//-------------------------------------------------------------------------
// Purpose       : Compute and return the bounding box for this sphere.
//
// Special Notes :
//
//-------------------------------------------------------------------------
CubitBox SphereEvaluator::bounding_box( void ) const
{
    CubitVector center = mTmatrix * mEvalData.center;
            
    CubitVector min( center.x() - mEvalData.radius,
                     center.y() - mEvalData.radius,
                     center.z() - mEvalData.radius );
    CubitVector max( center.x() + mEvalData.radius,
                     center.y() + mEvalData.radius,
                     center.z() + mEvalData.radius );

    CubitBox thebbox( min, max );

    return thebbox;
}
コード例 #5
0
ファイル: OCCSurface.cpp プロジェクト: tenpercent/cp-sandbox
CubitStatus OCCSurface::principal_curvatures(
  CubitVector const& location, 
  double& curvature_1,
  double& curvature_2,
  CubitVector* closest_location )
{
  BRepAdaptor_Surface asurface(*myTopoDSFace);
  gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0);
  double minDist=0.0, u, v;
  int i;
  BRepLProp_SLProps SLP(asurface, 2, Precision::PConfusion());
  Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation());
  if (ext.IsDone() && (ext.NbExt() > 0)) {
	  for ( i = 1 ; i <= ext.NbExt() ; i++ ) {
		  if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) {
			  minDist = p.Distance(ext.Point(i).Value());
			  newP = ext.Point(i).Value();
			  ext.Point(i).Parameter(u, v);
			  SLP.SetParameters(u, v);
		  }
	  }
  }
  if (closest_location != NULL)
    *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z());

  if (SLP.IsCurvatureDefined())
  {
    curvature_1 = SLP.MinCurvature();
    curvature_2 = SLP.MaxCurvature();
  }
  return CUBIT_SUCCESS;
}
コード例 #6
0
ファイル: OCCSurface.cpp プロジェクト: tenpercent/cp-sandbox
CubitPointContainment OCCSurface::point_containment( const CubitVector &point )
{
   TopoDS_Face *face = get_TopoDS_Face();
   gp_Pnt p(point.x(), point.y(), point.z());
   double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance();

   //It's checking the state of the projected point of THIS Point
   BRepClass_FaceClassifier face_classifier;
   face_classifier.Perform(*face, p, tol);
   TopAbs_State state = face_classifier.State();
   
   //if surface is part of a periodic TopoDS_Face, it'll check the point
   //againt the whole periodic Face, even it outside the occsurface 
   //boundary, if it's on its periodic extension, it'll return as in. 
   if (state == TopAbs_IN)
   {
     //double check if the point is projected on the surface
     CubitVector closest_point;
     this->closest_point_trimmed(point, closest_point);
     if(point.distance_between(closest_point) < tol) 
       return CUBIT_PNT_INSIDE;
     else
       return CUBIT_PNT_OUTSIDE;
   }
   else if (state == TopAbs_OUT)
     return CUBIT_PNT_OUTSIDE;
   else if (state == TopAbs_ON)
     return CUBIT_PNT_BOUNDARY;

   return CUBIT_PNT_UNKNOWN;
}
コード例 #7
0
ファイル: LoopParamTool.cpp プロジェクト: chrismullins/cgma
//===================================================================================
// Function: transform_to_xyz_local (Priavate)
// Description: same as title
// Author: Shiraj Khan
// Date: 1/21/2003
//===================================================================================
CubitStatus LoopParamTool::transform_to_xyz_local(CubitVector &xyz_location, CubitVector &uv_location) 
{
// Multiply by transformation matrix

  CubitVector vect;
  vect.x( uv_location.x() * Du.x() +
          uv_location.y() * Dv.x() );
  vect.y( uv_location.x() * Du.y() +
          uv_location.y() * Dv.y() );
  vect.z( uv_location.x() * Du.z() +
          uv_location.y() * Dv.z() );

    // Translate from origin

  xyz_location = vect + uvCenter;

  return CUBIT_SUCCESS;
}
コード例 #8
0
double SurfaceOverlapFacet::distance_from_position( CubitVector &position )
{
  double s,t;  
  Point3 tmp_point;
  tmp_point.x = position.x();
  tmp_point.y = position.y();
  tmp_point.z = position.z();
  return agt->MinPointTriangle( tmp_point, this->t, s, t );
} 
コード例 #9
0
ファイル: RStarTree.cpp プロジェクト: chrismullins/cgma
//--------------------------------------------------------------------------
//Algorithm: min_dist_sq
//Description:  Finds the minimum distance squared between the given
//              point and the box. If the point is on or in the box, the
//              min distance is zero.
//--------------------------------------------------------------------------
template <class Z> MY_INLINE
double RStarTree<Z>::min_dist_sq(CubitVector &q,
                             CubitBox &b_box)
{
  CubitVector b_min, b_max;
  b_min = b_box.minimum();
  b_max = b_box.maximum();
  double dist;
  CubitVector r;

  if ( q.x() < b_min.x() )
    r.x(b_min.x());
  else if ( q.x() > b_max.x() )
    r.x(b_max.x());
  else
    r.x(q.x());
  
  if ( q.y() < b_min.y() )
    r.y(b_min.y());
  else if ( q.y() > b_max.y() )
    r.y(b_max.y());
  else
    r.y(q.y());
  
  if ( q.z() < b_min.z() )
    r.z(b_min.z());
  else if ( q.z() > b_max.z() )
    r.z(b_max.z());
  else
    r.z(q.z());
  
  dist = (q-r).length_squared();

  return dist;
}
コード例 #10
0
ファイル: CubitFacetEdge.cpp プロジェクト: chrismullins/cgma
//=========================================================================== 
//Function Name: closest_point 
// 
//Member Type:  PUBLIC 
//Description:  return the closest point on segment defined by the edge 
//=========================================================================== 
CubitStatus CubitFacetEdge::closest_point(const CubitVector &point,  
                                          CubitVector &closest_point ) 
{  
  //CubitStatus rv = CUBIT_SUCCESS; 
  CubitPoint *pt0 = this->point(0); 
  CubitPoint *pt1 = this->point(1); 
 
  // the edge vector 
 
  CubitVector e0 ( pt1->x() - pt0->x(), 
                   pt1->y() - pt0->y(), 
                   pt1->z() - pt0->z() ); 
  double elen = e0.normalize(); 
   
  // vector from vert0 to point 
 
  CubitVector v0 ( point.x() - pt0->x(), 
                   point.y() - pt0->y(), 
                   point.z() - pt0->z() ); 
   
  // project to edge 
 
  double len = v0%e0; 
  if (len <= 0.0) 
  { 
    closest_point = pt0->coordinates(); 
  } 
  else if( len >= elen ) 
  { 
    closest_point = pt1->coordinates(); 
  } 
  else 
  { 
    closest_point.x ( pt0->x() + e0.x() * len ); 
    closest_point.y ( pt0->y() + e0.y() * len ); 
    closest_point.z ( pt0->z() + e0.z() * len ); 
  } 
 
  return CUBIT_SUCCESS; 
}
コード例 #11
0
ファイル: FacetParamTool.cpp プロジェクト: chrismullins/cgma
//===================================================================================
// Function: exhaustive_locate_point_in_uv (Public)
// Description: same as title
// Author: chynes
// Date: 7/10/02
//===================================================================================
CubitStatus FacetParamTool::
exhaustive_locate_point_in_uv(FacetSurface *surf, const CubitVector &the_point, CubitFacet *&tri_ptr) 
{
	CubitStatus rv = CUBIT_SUCCESS;

	DLIList<CubitFacet *> facet_list;
	surf->get_eval_tool()->get_facets(facet_list);

	// loop until we find something

	CubitPoint *p0, *p1, *p2;
	int ii;
	double aa, bb, cc;
	double u0, u1, u2, v0, v1, v2;
	CubitBoolean found = CUBIT_FALSE;
	for(ii = 0; ii < facet_list.size() && !found; ii++)
	{
		tri_ptr = facet_list.get_and_step();
		tri_ptr->points(p0, p1, p2);
		p0->get_uv(tri_ptr, u0, v0);
		p1->get_uv(tri_ptr, u1, v1);
		p2->get_uv(tri_ptr, u2, v2);
		aa = DETERM(the_point.x(), the_point.y(), u1, v1, u2, v2);
		bb = DETERM(u0, v0, the_point.x(), the_point.y(), u2, v2);
		cc = DETERM(u0, v0, u1, v1, the_point.x(), the_point.y());
		if (aa > -INSIDE_TOL &&
			bb > -INSIDE_TOL &&
			cc > -INSIDE_TOL)
		{
			found = CUBIT_TRUE;  // this is the one
		}
	}
	if (!found)
	{
		rv = CUBIT_FAILURE;
		tri_ptr = NULL;
	}
	return rv;
}
コード例 #12
0
ファイル: ParamCubitPlane.cpp プロジェクト: chrismullins/cgma
//-------------------------------------------------------------------------
// Purpose       : make arbitrary parameterization
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck 
//
// Creation Date : 07/06/98
//-------------------------------------------------------------------------
void ParamCubitPlane::make_parameterization()
{
	//Choose the zero-point for the parameterization
	//as close to the origin as possible.
//	p_.set( 0.0, 0.0, 0.0);
//	move_to_plane( p_ );
	is_plane_valid_ = CUBIT_TRUE;
	
	const CubitVector temp_p(0.0, 0.0, 0.0);
	CubitStatus s = closest_point( temp_p, p_ );
	assert( s == CUBIT_SUCCESS );
	
	CubitVector n = normal();
	CubitVector p1;
	
	p1 = p_;
	double x = fabs( n.x() );
	double y = fabs( n.y() );
	double z = fabs( n.z() );
	
	//Choose a direction from the zero point (p_) for
	//the second point as the direction of the smallest
	//component of the normal.  The third point defining
	//the plane will be defined by the cross product of
	//the vector from the zero_point to this point and
	//the normal vector of the plane.
	if( (x <= y) && (x <= z) )
	{
		p1.x( p1.x() + 1 );
	}
	else if( (y <= x) && (y <= z) )
	{
		p1.y( p1.y() + 1 );
	}
	else
	{
		p1.z( p1.z() + 1 );
	}
	
	move_to_plane( p1 );
	s_ = p1 - p_;
	t_ = -(s_ * n);
	n_ = s_ * t_;
	
	double n_len = n_.length();
	if( 1000 * CUBIT_DBL_MIN > n_len ) n_epsilon_ = CUBIT_DBL_MIN;
	else n_epsilon_ = n_len / 1000;
	
 
 	is_plane_valid_= CUBIT_TRUE;
}
コード例 #13
0
ファイル: LoopParamTool.cpp プロジェクト: chrismullins/cgma
//===================================================================================
// Function: transform_to_uv_local (Private)
// Description: It transforms points from the Best Fit plane plane to UV space
// Author: Shiraj Khan
// Date: 1/21/2003
//===================================================================================
CubitStatus LoopParamTool::transform_to_uv_local(CubitVector &xyz_location, CubitVector &uv_location) 
{
    // Translate to local origin at center

  CubitVector vect = xyz_location - uvCenter;

    // Multiply by transpose (inverse) of transformation vector

  uv_location.x( vect % Du );
  uv_location.y( vect % Dv );
  uv_location.z( 1.0 );

  return CUBIT_SUCCESS;
}
コード例 #14
0
ファイル: OCCSurface.cpp プロジェクト: tenpercent/cp-sandbox
//-------------------------------------------------------------------------
// Purpose       : Computes the closest_point on the surface to the input 
//                 location.  Optionally, it also computes and returns
//                 the normal to the surface at closest_location and the 
//                 principal curvatures(1-min, 2-max)
//
//-------------------------------------------------------------------------
CubitStatus OCCSurface::closest_point( CubitVector const& location, 
                                         CubitVector* closest_location,
                                         CubitVector* unit_normal_ptr,
                                         CubitVector* curvature_1,
                                         CubitVector* curvature_2)
{
  BRepAdaptor_Surface asurface(*myTopoDSFace);
  gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0);
  double minDist=0.0, u, v;
  int i;
  BRepLProp_SLProps SLP(asurface, 2, Precision::PConfusion());
  Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation());
  if (ext.IsDone() && (ext.NbExt() > 0)) {
	  for ( i = 1 ; i <= ext.NbExt() ; i++ ) {
		  if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) {
			  minDist = p.Distance(ext.Point(i).Value());
			  newP = ext.Point(i).Value();
			  ext.Point(i).Parameter(u, v);
			  SLP.SetParameters(u, v);
		  }
	  }
  
	if (closest_location != NULL)
 	 	*closest_location = CubitVector(newP.X(), newP.Y(), newP.Z());
  	if (unit_normal_ptr != NULL) {
	  gp_Dir normal;
          //normal of a RefFace point to outside of the material
	  if (SLP.IsNormalDefined()) {
	    normal = SLP.Normal();
            CubitSense sense = get_geometry_sense();
            if(sense == CUBIT_REVERSED)
              normal.Reverse() ;
	      *unit_normal_ptr = CubitVector(normal.X(), normal.Y(), normal.Z()); 
	  }
  	}
  
        gp_Dir MaxD, MinD;
        if (SLP.IsCurvatureDefined())
        {
	   SLP.CurvatureDirections(MaxD, MinD);
           if (curvature_1 != NULL)
              *curvature_1 = CubitVector(MinD.X(), MinD.Y(), MinD.Z());
           if (curvature_2 != NULL)
              *curvature_2 = CubitVector(MaxD.X(), MaxD.Y(), MaxD.Z());
        }
  }
  return CUBIT_SUCCESS;
}
コード例 #15
0
ファイル: KDDTree.cpp プロジェクト: tenpercent/cp-sandbox
//- "insert_node"
//- Dynamically insert the data into the k-d tree 
//- 
//- Algorithm INSERT (From Bentley):
//-   This algoritm is passed an object "data" of class "Z",
//-   which has a bounding_box() method.  If there is already
//-   a node in the tree with equal bounding box center point,
//-   it is put in the right subtree.
//-   I0. [Create new node] Create a node P with the bounding box
//-       specified, and set P.LEFT <- null, P.RIGHT <- null, and
//-       P.DISC <- null.
//-   I1. [Check for null tree] If ROOT = null, then set ROOT <- P
//-       and return CUBIT_SUCCESS; otherwise, set Q <- ROOT (Q
//-       will move down the tree).
//-   I2. [Compare] Compare the nodes and set the child in the
//-       correct direction to T.
//-   I3. [Move down] Set Q <- child of Q and go to I2.
//-   I4. [Insert new node in tree] Set the child of Q to P, then
//-       set the children of P to null. Set the discriminator of
//-       P to be the discriminator after that in Q.
//-
template <class Z> CubitStatus KDDTree<Z>::insert_node (KDDTreeNode<Z>* P)
{
  KDDTreeNode<Z> *F = NULL;      // father node
  KDDTreeNode<Z> *T;             // temp node

  if (root == NULL)
  {
    root = P;
    P->set_disc (DIMX);
  }
  else
  {
    T = root;
    DIRECTION direction = DIR_NULL;

    while (T != NULL)
    {
      F = T; // remember the father
      direction = P->compare (T);

      CubitVector tmin = T->safetyBox.minimum();
      CubitVector tmax = T->safetyBox.maximum();
      CubitVector pmin = P->safetyBox.minimum();
      CubitVector pmax = P->safetyBox.maximum();

      if (pmin.x() < tmin.x()) tmin.x (pmin.x());
      if (pmin.y() < tmin.y()) tmin.y (pmin.y());
      if (pmin.z() < tmin.z()) tmin.z (pmin.z());
      if (pmax.x() > tmax.x()) tmax.x (pmax.x());
      if (pmax.y() > tmax.y()) tmax.y (pmax.y());
      if (pmax.z() > tmax.z()) tmax.z (pmax.z());

      T->safetyBox.reset (tmin, tmax);

      T = T->get_child (direction);
    }

    F->set_child (P, direction);
    P->set_disc (F->next_disc());
    P->parent = F;
  }
  myNodeList.push (P);

  return CUBIT_SUCCESS;      
}
コード例 #16
0
ファイル: OCCSurface.cpp プロジェクト: tenpercent/cp-sandbox
//-------------------------------------------------------------------------
// Purpose       : Computes the closest_point on the trimmed surface to the 
//                 input location. 
//
// Special Notes : 
//-------------------------------------------------------------------------
void OCCSurface::closest_point_trimmed( CubitVector from_point, 
                                         CubitVector& point_on_surface)
{
  BRepAdaptor_Surface asurface(*myTopoDSFace);
  gp_Pnt p(from_point.x(), from_point.y(), from_point.z()), newP(0.0, 0.0, 0.0);
  double minDist=0.0;
  int i;
  Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation());
  if (ext.IsDone() && (ext.NbExt() > 0)) {
	  for ( i = 1 ; i <= ext.NbExt() ; i++ ) {
		  if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) {
			  minDist = p.Distance(ext.Point(i).Value());
			  newP = ext.Point(i).Value();
		  }
	  }
  }
  point_on_surface = CubitVector(newP.X(), newP.Y(), newP.Z());
}
コード例 #17
0
ファイル: KDDTree.cpp プロジェクト: tenpercent/cp-sandbox
//- Finds the minimum distance squared between the given point and the box. If
//-  the point is on or in the box, the min distance is zero.
template <class Z> double KDDTree<Z>::min_dist_sq (CubitVector &q, CubitBox &b_box)
{
  CubitVector b_min = b_box.minimum();
  CubitVector b_max = b_box.maximum();
  CubitVector r;

  //// set "r" in the x-dim
  if (q.x () < b_min.x ())
  {
    r.x (b_min.x ());
  }
  else if (q.x () > b_max.x ())
  {
    r.x (b_max.x ());
  }
  else
  {
    r.x (q.x ());
  }
  
  //// set "r" in the y-dim
  if (q.y () < b_min.y ())
  {
    r.y (b_min.y ());
  }
  else if (q.y () > b_max.y ())
  {
    r.y (b_max.y ());
  }
  else
  {
    r.y (q.y ());
  }
  
  //// set "r" in the z-dim
  if (q.z () < b_min.z ())
  {
    r.z (b_min.z ());
  }
  else if (q.z () > b_max.z ())
  {
    r.z (b_max.z ());
  }
  else
  {
    r.z (q.z ());
  }
  
  double dist = (q-r).length_squared();

  return dist;
}
コード例 #18
0
ファイル: CompositePoint.cpp プロジェクト: chrismullins/cgma
void CompositePoint::print_debug_info( const char* prefix, bool brief ) const
{
  if( prefix == 0 ) prefix = "";

#ifdef TOPOLOGY_BRIDGE_IDS
  PRINT_INFO("%sCompositePoint %d : %s %d\n", prefix, get_id(),
    realPoint ? fix_type_name(typeid(*realPoint).name()) : "NO REAL POINT", 
    realPoint ? realPoint->get_id() : 0 );
#else  
  PRINT_INFO("%sCompositePoint %p : %s %p\n", prefix, this,
    realPoint ? fix_type_name(typeid(*realPoint).name()) : "NO REAL POINT", 
    realPoint);
#endif
  
  if ( !brief )
  {  
    CubitVector p = coordinates();
    PRINT_INFO("%s  (%f,%f,%f)\n", prefix, p.x(), p.y(), p.z() );
  }
}
コード例 #19
0
//===================================================================================
// Function: transform_to_xyz (Public)
// Description: same as title
// Author: chynes
// Date: 7/10/02
//===================================================================================
CubitStatus PeriodicParamTool::transform_to_xyz(CubitVector &xyz_location, const CubitVector &uv_location) 
{
	double u = uv_location.x();	
  if (mirrorSurface)
  {
    u = -u;
  }
	if (u > uPeriod)
	{
		u = u - uPeriod;
	}
	double v = uv_location.y();
	if (v > vPeriod)
	{
		v = v - vPeriod;
	}
	xyz_location = refSurf->position_from_u_v(u,v);


	return CUBIT_SUCCESS;
}
コード例 #20
0
ファイル: OCCSurface.cpp プロジェクト: tenpercent/cp-sandbox
//-------------------------------------------------------------------------
// Purpose       : This function returns the {u, v} coordinates of the point 
//                 on the Surface closest to the input point (specified in 
//                 global space). The closest_location is also returned.
//
// Special Notes :
//
//-------------------------------------------------------------------------
CubitStatus OCCSurface::u_v_from_position( CubitVector const& location,
                                             double& u,
                                             double& v,
                                             CubitVector* closest_location )
{
  BRepAdaptor_Surface asurface(*myTopoDSFace);
  Handle(Geom_Surface) surface = BRep_Tool::Surface(*myTopoDSFace);
  gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0);

  GeomAPI_ProjectPointOnSurf projection( p, surface);
 
  if(projection.NbPoints() > 0)
  {               
      if(projection.LowerDistance() < Precision::Confusion() )
      {
	  projection.LowerDistanceParameters(u, v);
	  return CUBIT_SUCCESS;
      }
  }
  double minDist=0.0;
  int i;
  Extrema_ExtPS ext(p, asurface, Precision::Confusion(), Precision::Confusion());
  if (ext.IsDone() && (ext.NbExt() > 0)) {
	  for ( i = 1 ; i <= ext.NbExt() ; i++ ) {
		  if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) {
			  minDist = p.Distance(ext.Point(i).Value());
			  newP = ext.Point(i).Value();
			  ext.Point(i).Parameter(u, v);
		  }
	  }
  }
  if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z());
  if (ext.IsDone() && (ext.NbExt() > 0))  return CUBIT_SUCCESS;
  Handle(ShapeAnalysis_Surface) su = new ShapeAnalysis_Surface(surface);
  gp_Pnt2d suval = su->ValueOfUV(p, BRep_Tool::Tolerance(*myTopoDSFace));
  suval.Coord(u, v);
  return CUBIT_SUCCESS;
}
コード例 #21
0
bool CamalPaveDriver::prepareCGMEvaluator()
{
	//
	// we will have to mesh every geo edge separately, and we have to ensure that the number of mesh edges
	// for a face is even.
	// pretty tough to do. Initially, we have to decide loops, number of edges on each face, etc
	// first build
	//int err;
	// get the triangles and the vertices from moab set

	/*iBase_EntityHandle *triangles = NULL;
	int triangles_alloc = 0;
	iBase_EntityHandle *vert_adj = NULL;
	int vert_adj_alloc = 0, vert_adj_size;
	int numTriangles;
	int * offsets = NULL, offsets_alloc = 0, indices_size;
	int * indices = NULL, indices_alloc = 0, offsets_size;
	iMesh_getAdjEntIndices(_meshIface, _set, iBase_FACE, iMesh_TRIANGLE,
			iBase_VERTEX, &triangles, &triangles_alloc, &numTriangles,
			&vert_adj, &vert_adj_alloc, &vert_adj_size, &indices,
			&indices_alloc, &indices_size, &offsets, &offsets_alloc,
			&offsets_size, &err);
	ERRORR("Couldn't get connectivity for triangles.", 1);*/

	MBRange triangles;
	MBErrorCode rval = _mb->get_entities_by_type( 0 /* root set, as above, we know */,
											   MBTRI, triangles);
	// get all the nodes
	MBRange vertices;
	rval = _mb->get_adjacencies(triangles, 0, false, vertices, MBInterface::UNION);

	// first, create CubitPointData list, from the coordinates in one array
	/* get the coordinates in one array */

	/*int vert_coords_alloc = 0, vertex_coord_size;
	double * xyz = NULL;
	iMesh_getVtxArrCoords(_meshIface, vert_adj, vert_adj_size,
			iBase_INTERLEAVED, &xyz, &vert_coords_alloc, &vertex_coord_size,
			&err);
	ERRORR("Couldn't get coordinates for vertices.", 1);*/

	// here, we use Cholla from CGM
	// we need to replace it with something equivalent, but simpler
	// the first try would be some tags in MOAB
	// create the cubit point data
	// initialize CGM
	AppUtil::instance()->startup(0, NULL);
	CGMApp::instance()->startup(0, NULL);

	// Initialize the GeometryTool
	GeometryQueryTool *gqt = GeometryQueryTool::instance();
	FacetModifyEngine *fme = FacetModifyEngine::instance();

	int vert_adj_size =  vertices.size();
	int numTriangles = triangles.size();
	DLIList<CubitFacet*> f_list(numTriangles);
	DLIList<CubitPoint*> p_list(vert_adj_size);
	double * xyz = new double [3*vert_adj_size];
	rval = _mb->  get_coords(vertices, xyz);
	//std::map<MBEntityHandle, CubitPoint *> mapPoints;
	//MBRange::iterator it = vertices.begin();
	for (int i = 0; i < vert_adj_size; i++/*, it++*/) {
		double * pCoord = &xyz[3 * i];
		CubitPointData * newPoint = new CubitPointData(pCoord[0], pCoord[1],
				pCoord[2]);
		p_list.append(newPoint);
		//mapPoints[*it] = newPoint;// or maybe we should use finding the index in MBRange??
	}

	// yes
	// define all the triangles, to see what we have
	for (MBRange::iterator it = triangles.begin(); it!=triangles.end(); it++) {
		MBEntityHandle tri = *it;
		int nnodes;
		const MBEntityHandle * conn3;//
		_mb->get_connectivity(tri, conn3, nnodes);
		assert(nnodes == 3);
		int vtri[3];// indices for triangles
		int ii = 0;
		for (ii = 0; ii < 3; ii++)
			vtri[ii] = vertices.index(conn3[ii]); // vtri[ii] = indices[offsets[j] + ii];
		CubitFacetData * triangle = new CubitFacetData(p_list[vtri[0]],
				p_list[vtri[1]], p_list[vtri[2]]);
		f_list.append(triangle);
	}

	DLIList<LoopSM*> my_loops;

	DLIList<Surface*> surf_list;
	CubitStatus result;
	//double angle = 0.01;// very small, negligible; is this radians or degrees?
	result = fme->build_facet_surface(NULL, f_list, p_list, _angle, 4, true,
			false, surf_list);

	if (surf_list.size() == 0 || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based surfaces.\n");
		return result;
	} else
		PRINT_INFO("Constructed %d surfaces.\n", surf_list.size());

	//Now build the shell.  If we had it set up right this would be
	//in a loop.  We need to store list of DLBlockSurfaceLists on each
	//blockvolumemesh to store the shell information.  But that will
	//be saved for later.
	ShellSM *shell_ptr;
	result = fme->make_facet_shell(surf_list, shell_ptr);

	if (shell_ptr == NULL || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based shell entity.\n");
		return result;
	}
#if 1
	DLIList<ShellSM*> shell_list;
	shell_list.append(shell_ptr);
	Lump *lump_ptr;
	result = fme->make_facet_lump(shell_list, lump_ptr);

	if (lump_ptr == NULL || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based lump entity.\n");
		return result;
	}
	DLIList<Lump*> lump_list;
	lump_list.append(lump_ptr);

	BodySM *bodysm_ptr;
	Body *body_ptr;
	result = fme->make_facet_body(lump_list, bodysm_ptr);

	body_ptr = GeometryQueryTool::instance()->make_Body(bodysm_ptr);

	if (body_ptr == NULL || result != CUBIT_SUCCESS) {
		PRINT_ERROR("Problems building mesh based body entity.\n");
		return result;
	}

	if (!body_ptr) {
		exit(1);
	}

	PRINT_INFO("Body successfully created.\n");
#endif
	PRINT_INFO("Number of vertices = %d\n", gqt->num_ref_vertices());
	PRINT_INFO("Number of edges = %d\n", gqt->num_ref_edges());
	PRINT_INFO("Number of faces = %d\n", gqt->num_ref_faces());

	// print vertex positions
	DLIList<RefVertex*> verts;
	gqt->ref_vertices(verts);

	int i;
	for (i = 0; i < verts.size(); i++) {
		RefVertex * vert = verts[i];
		CubitVector coords = vert->coordinates();
		PRINT_INFO("Vertex %d: %4.2f, %4.2f, %4.2f.\n", vert->id(), coords.x(),
				coords.y(), coords.z());
	}
	// print edges and faces

	DLIList<RefEdge*> refEdges;
	gqt->ref_edges(refEdges);

	for (i = 0; i < refEdges.size(); i++) {
		RefEdge * edg = refEdges[i];
		PRINT_INFO("Edge %d: %d %d\n", edg->id(), edg->start_vertex()->id(), edg->end_vertex ()->id() );
	}

	DLIList<RefFace*> refFaces;
	gqt->ref_faces(refFaces);

	for (i = 0; i < refFaces.size(); i++) {
		RefFace * face = refFaces[i];
		DLIList<  Loop * >  loop_list  ;
		face->ordered_loops (loop_list ) ;
		DLIList<  RefEdge  * > ordered_edge_list;
		loop_list[0]->ordered_ref_edges  (ordered_edge_list);

		//DLIList<  RefVertex* >  *listV = ref_vert_loop_list[0];
		PRINT_INFO("face %d: loop 0 size %d\n", face->id(),  ordered_edge_list.size() );
		for (int j=0; j<ordered_edge_list.size(); j++)
		{
			PRINT_INFO("  %d", ordered_edge_list[j]->id() );
		}
		PRINT_INFO("\n");
	}
	return true;
}