当前位置: 首页>>代码示例>>C++>>正文


C++ centroid函数代码示例

本文整理汇总了C++中centroid函数的典型用法代码示例。如果您正苦于以下问题:C++ centroid函数的具体用法?C++ centroid怎么用?C++ centroid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了centroid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fopen

void GeospatialBoundingBox::exportInformationFile()	{

	FILE *file_ptr = fopen(_format("%s.info",file_name.c_str()).c_str(), "w");
	fprintf(file_ptr, "centroid: %f %f %f\n", centroid(0), centroid(1), centroid(2));
	fprintf(file_ptr, "resolution: %f %f %f\n",resolution(0), resolution(1), resolution(2));
	fprintf(file_ptr, "min_pt: %f %f %f\n", min_pt(0), min_pt(1), min_pt(2));
	fprintf(file_ptr, "max_pt: %f %f %f\n", max_pt(0), max_pt(1), max_pt(2));
	fprintf(file_ptr, "points: %d\n", number_of_points);
	fclose(file_ptr);
	return;
}
开发者ID:charalambos,项目名称:StructurePointcloud,代码行数:11,代码来源:GeospatialBoundingBox.cpp

示例2: centroid

void particleScene::draw(float x, float y, float scale){
// moved here for convenience
    if (bGenerate) {
        for (int i = 0; i < flow->features.size(); i++) {
            if (flow->motion[i + flow->motion.size()/2].lengthSquared() > threshold) {
                ofVec2f featMapped;
                featMapped.x = ((flow->features[i].x - 160) * scale + 160 + x);
                featMapped.y = ((flow->features[i].y - 120) * scale + 120 + y);
                
                ofVec2f featVel;
                featVel.x = flow->motion[i + flow->motion.size()/2].x * scale;
                featVel.y = flow->motion[i + flow->motion.size()/2].y * scale;
                
                particles.add(featMapped, featVel * velMult);
                
            }
        }
        
    }
    else {
        if (flow->motion.size() > 0) {
            for (int i = 0; i < particles.particles.size(); i++) {
                ofVec2f featVel;
                featVel.x = flow->motion[i + flow->motion.size()/2].x * scale;
                featVel.y = flow->motion[i + flow->motion.size()/2].y * scale;
                
                
                if (bReverse) featVel *= -1;
                particles.particles[i]->vel+= featVel * velMult;
            }
        }
    }
    
    ofVec2f centroid(0,0);
    for (int i = 0; i < flow->features.size(); i++) {
        centroid+=flow->features[i];
    }
    centroid/=flow->features.size();
    
    particles.update(centroid.x, centroid.y);
    particles.draw(particleColor);
///draw
    
//    
//    ofPushMatrix();
//    ofTranslate(x, y);
//    ofTranslate(160, 120);
//    ofScale(scale, scale);
//    ofTranslate(-160, -120);
  
//    ofPopMatrix();

//    if (bDebug) {
//        for (int i = 0; i < particles.particles.size(); i++) {
//            cout << "particle[" << i << "].pos = " << particles.particles[i]->pos << endl;
//        }
//        bDebug = false;
//    }
//    bDebug = false;
}
开发者ID:jasonlevine,项目名称:kinect-dance-system,代码行数:60,代码来源:particleScene.cpp

示例3: step

tetra* step(const tetra *t, const  point *p, std::vector<tetra*> &branches) {

    tetra *step = nullptr;

    point centroid((t->p[0]->x + t->p[1]->x + t->p[2]->x + t->p[3]->x)/4,
                   (t->p[0]->y + t->p[1]->y + t->p[2]->y + t->p[3]->y)/4,
                   (t->p[0]->z + t->p[1]->z + t->p[2]->z + t->p[3]->z)/4
                  );

    for (unsigned int i = 0; i < 4; ++i) {

        if (!t->ngb[i])
            continue;

        unsigned int included = fast_triangle_ray_inclusion(t->f[i], &centroid, p);

        if (included != 0) {

            if (!step)
                step = t->ngb[i];
            else
                branches.push_back(t->ngb[i]);
        }
    }

    return step;
}
开发者ID:LeonineKing1199,项目名称:Regulus,代码行数:27,代码来源:tetra.cpp

示例4: localize_quad_for_ef

/*! 
  moves and rotates the quad such that it enables us to 
  use components of ef's
*/
void localize_quad_for_ef( VerdictVector node_pos[4])
{

  VerdictVector centroid(node_pos[0]);
  centroid += node_pos[1];
  centroid += node_pos[2];
  centroid += node_pos[3];
  
  centroid /= 4.0;

  node_pos[0] -= centroid;
  node_pos[1] -= centroid;
  node_pos[2] -= centroid;
  node_pos[3] -= centroid;

  VerdictVector rotate = node_pos[1] + node_pos[2] - node_pos[3] - node_pos[0];
  rotate.normalize();

  double cosine = rotate.x();
  double   sine = rotate.y();
 
  double xnew;
 
  for (int i=0; i < 4; i++) 
  {
    xnew =  cosine * node_pos[i].x() +   sine * node_pos[i].y();
    node_pos[i].y( -sine * node_pos[i].x() + cosine * node_pos[i].y() );
    node_pos[i].x(xnew);
  }
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:34,代码来源:V_QuadMetric.C

示例5: calculateCentroid

   double_xy calculateCentroid( tBlob& bo ) {
      struct centroid {
         uint32_t icount;
         uint32_t xsum;
         uint32_t ysum;
         centroid(): icount( 0 ), xsum( 0 ), ysum( 0 ) {}
         void operator()( tStreak const& s ) {
            int l = s.length();

            // -- add y coordinates
            ysum += s.y() * l;

            // -- add x coordinates
            int ix    = s.x();
            icount += l;

            while( l-- ) {
               xsum +=  ix;
               ix++;
            }

         }

      };
      centroid const& s = for_each( bo.streaks().begin(), bo.streaks().end(), centroid() );
      double x = static_cast<double>(s.xsum) / static_cast<double>(s.icount);
      double y = static_cast<double>(s.ysum) / static_cast<double>(s.icount);
      bo._centerOfMass = double_xy( x, y );
      return bo._centerOfMass;

   }
开发者ID:JolinZh,项目名称:previewbox,代码行数:31,代码来源:rlf_blob.cpp

示例6: foreach

/*!
 * \brief BestFitPlane::setUpResult
 * \param plane
 * \return
 */
bool BestFitPlane::setUpResult(Plane &plane){

    //get and check input observations
    if(!this->inputElements.contains(0) || this->inputElements[0].size() < 3){
        emit this->sendMessage(QString("Not enough valid observations to fit the plane %1").arg(plane.getFeatureName()), eWarningMessage);
        return false;
    }
    QList<QPointer<Observation> > inputObservations;
    foreach(const InputElement &element, this->inputElements[0]){
        if(!element.observation.isNull() && element.observation->getIsSolved() && element.observation->getIsValid()
                && element.shouldBeUsed){
            inputObservations.append(element.observation);
            this->setIsUsed(0, element.id, true);
            continue;
        }
        this->setIsUsed(0, element.id, false);
    }
    if(inputObservations.size() < 3){
        emit this->sendMessage(QString("Not enough valid observations to fit the plane %1").arg(plane.getFeatureName()), eWarningMessage);
        return false;
    }

    //centroid
    OiVec centroid(4);
    foreach(const QPointer<Observation> &obs, inputObservations){
        centroid = centroid + obs->getXYZ();
    }
开发者ID:OpenIndy,项目名称:OpenIndy-DefaultPlugin,代码行数:32,代码来源:p_bestfitplane.cpp

示例7: centroid

Vector3 Winding::centroid(const Plane3& plane) const
{
	Vector3 centroid(0,0,0);

	float area2 = 0, x_sum = 0, y_sum = 0;
	const ProjectionAxis axis = projectionaxis_for_normal(plane.normal());
	const indexremap_t remap = indexremap_for_projectionaxis(axis);

	for (std::size_t i = size() - 1, j = 0; j < size(); i = j, ++j)
	{
		const float ai = (*this)[i].vertex[remap.x]
				* (*this)[j].vertex[remap.y] - (*this)[j].vertex[remap.x]
				* (*this)[i].vertex[remap.y];

		area2 += ai;

		x_sum += ((*this)[j].vertex[remap.x] + (*this)[i].vertex[remap.x]) * ai;
		y_sum += ((*this)[j].vertex[remap.y] + (*this)[i].vertex[remap.y]) * ai;
	}

	centroid[remap.x] = x_sum / (3 * area2);
	centroid[remap.y] = y_sum / (3 * area2);
	{
		Ray ray(Vector3(0, 0, 0), Vector3(0, 0, 0));
		ray.origin[remap.x] = centroid[remap.x];
		ray.origin[remap.y] = centroid[remap.y];
		ray.direction[remap.z] = 1;
		centroid[remap.z] = ray.getDistance(plane);
	}

	return centroid;
}
开发者ID:BielBdeLuna,项目名称:DarkRadiant,代码行数:32,代码来源:Winding.cpp

示例8: yforx

	float Correlator::yforx(float x) {
//	  float a=angle();
	  float g=grad();
	  V2d cen=centroid();
	  float b=cen.y-g*cen.x;
	  return g*x+b;
	}
开发者ID:10crimes,项目名称:code,代码行数:7,代码来源:maths2.c

示例9: lumps

//-------------------------------------------------------------------------
// Purpose       : 
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 05/10/04
//-------------------------------------------------------------------------
CubitStatus PartitionBody::mass_properties( CubitVector& result, double& volume )
{
  DLIList<Lump*> lump_list;
  lumps( lump_list );
  
  DLIList<PartitionLump*> part_list;
  CAST_LIST( lump_list, part_list, PartitionLump );
  if (part_list.size() < lump_list.size())
    return real_body()->mass_properties( result, volume );
  
  CubitVector centroid(0.0, 0.0, 0.0), tmp_centroid;
  volume = 0.0;
  double tmp_volume;
  for (int i = part_list.size(); i--; )
  {
    if (CUBIT_FAILURE == 
        part_list.get_and_step()->mass_properties( tmp_centroid, tmp_volume ))
      return CUBIT_FAILURE;
    
    centroid += tmp_volume * tmp_centroid;
    volume += tmp_volume;
  }
  
  if (volume > CUBIT_RESABS)
  {
    result = centroid / volume;
  }
  else
  {
    result.set( 0.0, 0.0, 0.0 );
    volume = 0.0;
  }
  return CUBIT_SUCCESS;
}
开发者ID:chrismullins,项目名称:cgma,代码行数:43,代码来源:PartitionBody.cpp

示例10: compute_centroid

// Computes the centroid of a given cloud
Eigen::Vector4f compute_centroid(pcl::PointCloud<pcl::PointXYZ> cloud)
{
  Eigen::Vector4f centroid(4);
  centroid.setZero ();
  // For each point in the cloud
  int cp = 0;

  // If the data is dense, we don't need to check for NaN
  if (cloud.is_dense)
  {
    for (size_t i = 0; i < cloud.points.size (); ++i)
      centroid += cloud.points[i].getVector4fMap ();
    centroid[3] = 0;
    centroid /= cloud.points.size ();
  }
  // NaN or Inf values could exist => check for them
  else
  {
    for (size_t i = 0; i < cloud.points.size (); ++i)
    {
      // Check if the point is invalid
      if (!pcl_isfinite (cloud.points[i].x) ||
          !pcl_isfinite (cloud.points[i].y) ||
          !pcl_isfinite (cloud.points[i].z))
        continue;

      centroid += cloud.points[i].getVector4fMap ();
      cp++;
    }
    centroid[3] = 0;
    centroid /= cp;
  }

  return centroid;
}
开发者ID:deedeethan,项目名称:Tracking_Node,代码行数:36,代码来源:matrix_transform.cpp

示例11: newCentroid

	Garbage * GarbageHistoric::guessPosition(){
		//assumes linear movement using last known delta/position
		std::vector<int> newCentroid (2,0);
		std::vector<int> centroid (this->garbage->getCentroid());
		std::vector<int> delta (this->deltaPos);
		int factor=(this->age - this->lastAppeareance);
		
		if(factor<=1){
			return this->garbage;
		}

		int deltax=(factor-1)*delta[0];
		int deltay=(factor-1)*delta[1];
		newCentroid[0]=centroid[0] +deltax;
		newCentroid[1]=centroid[1] +deltay;
	
		MinimalBoundingRectangle * oldMbr=this->garbage->boundingBox();
		int x=oldMbr->x;
		int y=oldMbr->y;
		int h=oldMbr->getHeight();
		int w=oldMbr->getWidth();
		
		MinimalBoundingRectangle * mbr= new MinimalBoundingRectangle(x+deltax,y+deltay,w,h);
		Garbage * newGarbage=new  Garbage(mbr,newCentroid);
	
		//benchmark purposes
		newGarbage->isFocused=this->garbage->isFocused;
		newGarbage->isPredicted=this->garbage->isPredicted;
		newGarbage->isVisualized=this->garbage->isVisualized;
		
		
		return newGarbage;
	}
开发者ID:margguo,项目名称:tpf-robotica,代码行数:33,代码来源:GarbageHistoric.cpp

示例12: centroid

void
MoGES::missing::sortCircular
(
  std::vector<Point>& pointsA
)
{
  // Compute the center of gravity.
  Point centroidL = centroid(pointsA);

  // Copy points to the more suitable list container and make them mean free.
  std::list<Point> pointsL;
  for
  ( std::vector<Point>::const_iterator pointItL = pointsA.begin();
    pointItL < pointsA.end();
    ++pointItL )
  {
    pointsL.push_back(*pointItL - centroidL);
  }

  // Sort points counter-clockwise.
  pointsL.sort(smallerAngleToXAxis<Point>);

  // Copy points to vector and restore their original position in space.
  std::list<Point>::const_iterator pointItL = pointsL.begin();
  std::vector<Point>::iterator resultItL = pointsA.begin();
  while (pointItL != pointsL.end())
  {
    *resultItL = *pointItL + centroidL;

    ++resultItL;  ++pointItL;
  }
}
开发者ID:SfMResearch,项目名称:boxes,代码行数:32,代码来源:missing.cpp

示例13: ComputeWeightedCovariance

Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weights, Vec3::Arg metric )
{
	// compute the centroid
	float total = 0.0f;
	Vec3 centroid( 0.0f );
	for( int i = 0; i < n; ++i )
	{
		total += weights[i];
		centroid += weights[i]*points[i];
	}
	centroid /= total;

	// accumulate the covariance matrix
	Sym3x3 covariance( 0.0f );
	for( int i = 0; i < n; ++i )
	{
		Vec3 a = (points[i] - centroid) * metric;
		Vec3 b = weights[i]*a;
		
		covariance[0] += a.X()*b.X();
		covariance[1] += a.X()*b.Y();
		covariance[2] += a.X()*b.Z();
		covariance[3] += a.Y()*b.Y();
		covariance[4] += a.Y()*b.Z();
		covariance[5] += a.Z()*b.Z();
	}
	
	// return it
	return covariance;
}
开发者ID:TraurigeNarr,项目名称:dava.framework,代码行数:30,代码来源:maths.cpp

示例14: centroid

double YARPOrientation::Apply(const YARPImageOf<YarpPixelMono> &image)
{
    double
        x = 0.0,
        y = 0.0 ;

    centroid(image, x, y) ;
    
    double
        argsin = 0.0,
        argcos = 0.0 ;

    arguments(image, x, y, argsin, argcos) ;
	        
    double
        angle = 0.0 ;

    if (argsin > 0.0 && argcos > 0.0)
        angle = (asin(argsin)) / 2.0 ;
    else if (argsin > 0.0 && argcos < 0.0)
        angle = (acos(argcos)) / 2.0 ;
    else if (argsin < 0.0 && argcos < 0.0)
        angle = (-1.0) * (acos(argcos)) / 2.0;
    else if (argsin < 0.0 && argcos > 0.0)
        angle = (asin(argsin)) / 2.0 ;
    
#ifdef __WIN32__
    return angle == numeric_limits<double>::signaling_NaN() ? 0 : - angle ;
#else
	//should check for error using ERRNO kind of stuff.
	return -angle;
#endif
}
开发者ID:paulfitz,项目名称:poker,代码行数:33,代码来源:YARPOrientation.cpp

示例15: centroid

void
FeatureFloodCount::flood(const DofObject * dof_object, unsigned long current_idx, FeatureData * feature)
{
  if (dof_object == nullptr)
    return;

  // Retrieve the id of the current entity
  auto entity_id = dof_object->id();

  // Has this entity already been marked? - if so move along
  if (_entities_visited[current_idx].find(entity_id) != _entities_visited[current_idx].end())
    return;

  // Mark this entity as visited
  _entities_visited[current_idx][entity_id] = true;

  // Determine which threshold to use based on whether this is an established region
  auto threshold = feature ? _step_connecting_threshold : _step_threshold;

  // Get the value of the current variable for the current entity
  Real entity_value;
  if (_is_elemental)
  {
    const Elem * elem = static_cast<const Elem *>(dof_object);
    std::vector<Point> centroid(1, elem->centroid());
    _subproblem.reinitElemPhys(elem, centroid, 0);
    entity_value = _vars[current_idx]->sln()[0];
  }
  else
    entity_value = _vars[current_idx]->getNodalValue(*static_cast<const Node *>(dof_object));

  // This node hasn't been marked, is it in a feature?  We must respect
  // the user-selected value of _use_less_than_threshold_comparison.
  if (_use_less_than_threshold_comparison && (entity_value < threshold))
    return;

  if (!_use_less_than_threshold_comparison && (entity_value > threshold))
    return;

  /**
   * If we reach this point (i.e. we haven't returned early from this routine),
   * we've found a new mesh entity that's part of a feature.
   */
  auto map_num = _single_map_mode ? decltype(current_idx)(0) : current_idx;

  // New Feature (we need to create it and add it to our data structure)
  if (!feature)
    _partial_feature_sets[map_num].emplace_back(current_idx);

  // Get a handle to the feature we will update (always the last feature in the data structure)
  feature = &_partial_feature_sets[map_num].back();

  // Insert the current entity into the local ids map
  feature->_local_ids.insert(entity_id);

  if (_is_elemental)
    visitElementalNeighbors(static_cast<const Elem *>(dof_object), current_idx, feature, /*expand_halos_only =*/false);
  else
    visitNodalNeighbors(static_cast<const Node *>(dof_object), current_idx, feature, /*expand_halos_only =*/false);
}
开发者ID:ivance00,项目名称:moose,代码行数:60,代码来源:FeatureFloodCount.C


注:本文中的centroid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。