//=======================================================================
//function : PointProperties
//purpose  :
//=======================================================================
void PointProperties(const TopoDS_Shape& aS, GProp_GProps& aGProps)
{
  Standard_Integer i, aNbS;
  Standard_Real aDensity;
  gp_Pnt aPX;
  TopTools_IndexedMapOfShape aMS;
  //
  aDensity=1.;
  //
  TopExp::MapShapes(aS, TopAbs_VERTEX, aMS);
  aNbS=aMS.Extent();
  for (i=1; i<=aNbS; ++i) {
    GEOMAlgo_GProps aGPropsX;
    //
    const TopoDS_Vertex& aVX=*((TopoDS_Vertex*)&aMS(i));
    aPX=BRep_Tool::Pnt(aVX);
    aGPropsX.SetMass(1.);
    aGPropsX.SetCG(aPX);
    aGProps.Add(aGPropsX, aDensity);
  }
}
Base::Vector3d Measurement::massCenter() const
{

    int numRefs =  References3D.getSize();
    if(!numRefs || measureType == Invalid)
        throw Base::Exception("Measurement - massCenter - Invalid References3D Provided");

    const std::vector<App::DocumentObject*> &objects = References3D.getValues();
    const std::vector<std::string> &subElements = References3D.getSubValues();


    GProp_GProps gprops = GProp_GProps();

    if(measureType == Volumes) {
        // Iterate through edges and calculate each length
        std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
        std::vector<std::string>::const_iterator subEl = subElements.begin();

        for (;obj != objects.end(); ++obj, ++subEl) {
            //const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
            //const Part::TopoShape& refShape = refObj->Shape.getShape();

            // Compute inertia properties

            GProp_GProps props = GProp_GProps();
            BRepGProp::VolumeProperties(getShape((*obj), ""), props);
            gprops.Add(props);
            // Get inertia properties
        }

        //double mass = gprops.Mass();
        gp_Pnt cog = gprops.CentreOfMass();

        return Base::Vector3d(cog.X(), cog.Y(), cog.Z());

      } else {
          throw Base::Exception("Measurement - massCenter - Invalid References3D Provided");
      }
}
Exemplo n.º 3
0
bool ChCascadeDoc::GetVolumeProperties(const TopoDS_Shape& mshape,	///< pass the shape here
						const double density,				///< pass the density here 
						ChVector<>& center_position,		///< get the position center, respect to shape pos.
						ChVector<>& inertiaXX,				///< get the inertia diagonal terms
						ChVector<>& inertiaXY,				///< get the inertia extradiagonal terms
						double& volume,						///< get the volume
						double& mass						///< get the mass
						)
{
	if (mshape.IsNull()) 
		return false;

	GProp_GProps mprops;
	GProp_GProps vprops;
	BRepGProp::VolumeProperties(mshape,mprops);
	BRepGProp::VolumeProperties(mshape,vprops);

	mprops.Add(mprops, density);

	mass = mprops.Mass();
	volume = vprops.Mass();
	gp_Pnt G = mprops.CentreOfMass ();
	gp_Mat I = mprops.MatrixOfInertia();

	center_position.x = G.X();
	center_position.y = G.Y();
	center_position.z = G.Z();

	inertiaXX.x = I(1,1);
	inertiaXX.y = I(2,2);
	inertiaXX.z = I(3,3);
	inertiaXY.x = I(1,2);
	inertiaXY.y = I(1,3);
	inertiaXY.z = I(2,3);

	return true;
}