IfcSchema::IfcProductDefinitionShape* IfcGeom::tesselate(const TopoDS_Shape& shape, double deflection) {
	BRepMesh_IncrementalMesh(shape, deflection);

	IfcSchema::IfcFace::list::ptr faces(new IfcSchema::IfcFace::list);

	for (TopExp_Explorer exp(shape, TopAbs_FACE); exp.More(); exp.Next()) {
		const TopoDS_Face& face = TopoDS::Face(exp.Current());
		TopLoc_Location loc;
		Handle(Poly_Triangulation) tri = BRep_Tool::Triangulation(face, loc);

		if (!tri.IsNull()) {
			const TColgp_Array1OfPnt& nodes = tri->Nodes();
			std::vector<IfcSchema::IfcCartesianPoint*> vertices;
			for (int i = 1; i <= nodes.Length(); ++i) {
				gp_Pnt pnt = nodes(i).Transformed(loc);
				std::vector<double> xyz; xyz.push_back(pnt.X()); xyz.push_back(pnt.Y()); xyz.push_back(pnt.Z());
				IfcSchema::IfcCartesianPoint* cpnt = new IfcSchema::IfcCartesianPoint(xyz);
				vertices.push_back(cpnt);
			}
			const Poly_Array1OfTriangle& triangles = tri->Triangles();
			for (int i = 1; i <= triangles.Length(); ++i) {
				int n1, n2, n3;
				triangles(i).Get(n1, n2, n3);
				IfcSchema::IfcCartesianPoint::list::ptr points(new IfcSchema::IfcCartesianPoint::list);
				points->push(vertices[n1 - 1]);
				points->push(vertices[n2 - 1]);
				points->push(vertices[n3 - 1]);
				IfcSchema::IfcPolyLoop* loop = new IfcSchema::IfcPolyLoop(points);
				IfcSchema::IfcFaceOuterBound* bound = new IfcSchema::IfcFaceOuterBound(loop, face.Orientation() != TopAbs_REVERSED);
				IfcSchema::IfcFaceBound::list::ptr bounds(new IfcSchema::IfcFaceBound::list);
				bounds->push(bound);
				IfcSchema::IfcFace* face2 = new IfcSchema::IfcFace(bounds);
				faces->push(face2);
			}
		}
	}
	IfcSchema::IfcOpenShell* shell = new IfcSchema::IfcOpenShell(faces);
	IfcSchema::IfcConnectedFaceSet::list::ptr shells(new IfcSchema::IfcConnectedFaceSet::list);
	shells->push(shell);
	IfcSchema::IfcFaceBasedSurfaceModel* surface_model = new IfcSchema::IfcFaceBasedSurfaceModel(shells);

	IfcSchema::IfcRepresentation::list::ptr reps(new IfcSchema::IfcRepresentation::list);
	IfcSchema::IfcRepresentationItem::list::ptr items(new IfcSchema::IfcRepresentationItem::list);

	items->push(surface_model);

	IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(
		0, std::string("Facetation"), std::string("SurfaceModel"), items);

	reps->push(rep);
	IfcSchema::IfcProductDefinitionShape* shapedef = new IfcSchema::IfcProductDefinitionShape(boost::none, boost::none, reps);

	return shapedef;
}
std::vector<bool> BasisSet::MapGridBasis(cartGP pt){
//  Set map_[ishell] to be avaluated (true) or not (false)
//  note: radCutSh_ has to be already populated by calling before radcut
//bool * map_ = new bool[this->nShell()+1];
  std::vector<bool> map_(this->nShell()+1);
  double x ;
  double y ;
  double z ;
  double r ;
  bool   nodens = true;  //becomes truee if at least one shell hs to evaluated and it is stored in map_[0]
  for(auto s1=0l; s1 < this->nShell(); s1++){  //loop over shells
    auto center = shells(s1).O;
    x = bg::get<0>(pt) - center[0];
    y = bg::get<1>(pt) - center[1];
    z = bg::get<2>(pt) - center[2];
    r = std::pow((x*x + y*y + z*z),(0.5));
    map_[s1+1] = false;        
    if (r < this->radCutSh_[s1]) {
      map_[s1+1] = true;
      nodens = false;
      }
    } //End loop over shells
  map_[0] = nodens;
  return map_;
}
void BasisSet::radcut(double thr, int maxiter, double epsConv){
  this->radCutSh_ = new double[this->nShell()];
  double alphaMin;
//  double *s1Eval = basisEval(s1,pt);
  for(auto s1=0l; s1 < this->nShell(); s1++){
//    find smallest alpha coeff for each shell
      auto contDepth = this->shells(s1).alpha.size(); 
      alphaMin = 1.0e15;
      for(auto k = 0; k < contDepth; k++){
        if (this->shells(s1).alpha[k] <= alphaMin){
        alphaMin = this->shells(s1).alpha[k];
        }
      }
//       cout << "s1 " << s1 << endl;
//       this->fSpAv (2, shells(s1).contr[0].l, alphaMin, 1.0e-5);
//       this->fSpAv (1, shells(s1).contr[0].l, alphaMin, 3);
//     Populate a Vector storing all the cut off radius (Av_xi(r_cut)<thr)
       radCutSh_[s1] = this->fRmax (shells(s1).contr[0].l, alphaMin, thr, epsConv, maxiter);

  }
  return ;
}
Beispiel #4
0
CubitStatus FacetLump::mass_properties( CubitVector& centroid, double& volume )
{
  int i;
  
  DLIList<FacetShell*> shells( myShells.size() );
  CAST_LIST( myShells, shells, FacetShell );
  assert( myShells.size() == shells.size() );
  
  DLIList<FacetSurface*> surfaces;
  DLIList<FacetShell*> surf_shells;
  get_surfaces( surfaces );
  
  DLIList<CubitFacet*> facets, surf_facets;
  DLIList<CubitPoint*> junk;
  DLIList<CubitSense> senses;
  for (i = surfaces.size(); i--; )
  {
    FacetSurface* surf = surfaces.step_and_get();
    surf_shells.clean_out();
    surf->get_shells( surf_shells );
    surf_shells.intersect( shells );
    assert( surf_shells.size() );
    CubitSense sense = surf->get_shell_sense( surf_shells.get() );
    if (surf_shells.size() == 1 && CUBIT_UNKNOWN != sense)
    {
      surf_facets.clean_out();
      junk.clean_out();
      surf->get_my_facets( surf_facets, junk );
      facets += surf_facets;
      
      for (int j = surf_facets.size(); j--; )
        senses.append(sense);
    }
  }
  
  const CubitVector p0 = bounding_box().center();
  CubitVector p1, p2, p3, normal;
  centroid.set( 0.0, 0.0, 0.0 );
  volume = 0.0;
  
  facets.reset();
  senses.reset();
  for (i = facets.size(); i--; )
  {
    CubitFacet* facet = facets.get_and_step();
    CubitSense sense = senses.get_and_step();
    p1 = facet->point(0)->coordinates();
    p2 = facet->point(1)->coordinates();
    p3 = facet->point(2)->coordinates();
    normal = (p3 - p1) * (p2 - p1);

    double two_area = normal.length();
    if (two_area > CUBIT_RESABS )
    {
      if (CUBIT_REVERSED == sense)
        normal = -normal;

      normal /= two_area;

      double height = normal % (p0 - p1);
      double vol = two_area * height;

      volume += vol;
      centroid += vol * (p0 + p1 + p2 + p3);
    }
  }
  
  if (volume > CUBIT_RESABS)
    centroid /= 4.0 * volume;
  volume /= 6.0;
  return CUBIT_SUCCESS;
}
IfcSchema::IfcProductDefinitionShape* IfcGeom::serialise(const TopoDS_Shape& shape, bool advanced) {
#ifndef USE_IFC4
	advanced = false;
#endif

	for (TopExp_Explorer exp(shape, TopAbs_COMPSOLID); exp.More();) {
		/// @todo CompSolids are not supported
		return 0;
	}

	IfcSchema::IfcRepresentation* rep = 0;
	IfcSchema::IfcRepresentationItem::list::ptr items(new IfcSchema::IfcRepresentationItem::list);

	// First check if there is a solid with one or more shells
	for (TopExp_Explorer exp(shape, TopAbs_SOLID); exp.More(); exp.Next()) {
		IfcSchema::IfcClosedShell* outer = 0;
		IfcSchema::IfcClosedShell::list::ptr inner(new IfcSchema::IfcClosedShell::list);
		for (TopExp_Explorer exp2(exp.Current(), TopAbs_SHELL); exp2.More(); exp2.Next()) {
			IfcSchema::IfcClosedShell* shell;
			if (!convert_to_ifc(exp2.Current(), shell, advanced)) {
				return 0;
			}
			/// @todo Are shells always in this order or does Orientation() needs to be checked?
			if (outer) {
				inner->push(shell);
			} else {
				outer = shell;
			}
		}

#ifdef USE_IFC4
		if (advanced) {
			if (inner->size()) {
				items->push(new IfcSchema::IfcAdvancedBrepWithVoids(outer, inner));
			} else {
				items->push(new IfcSchema::IfcAdvancedBrep(outer));
			}
		} else
#endif

			/// @todo this is not necessarily correct as the shell is not necessarily facetted.
			if (inner->size()) {
				items->push(new IfcSchema::IfcFacetedBrepWithVoids(outer, inner));
			} else {
				items->push(new IfcSchema::IfcFacetedBrep(outer));
			}

	}

	if (items->size() > 0) {
		rep = new IfcSchema::IfcShapeRepresentation(0, std::string("Body"), std::string("Brep"), items);
	} else {

		// If not, see if there is a shell
		IfcSchema::IfcOpenShell::list::ptr shells(new IfcSchema::IfcOpenShell::list);
		for (TopExp_Explorer exp(shape, TopAbs_SHELL); exp.More(); exp.Next()) {
			IfcSchema::IfcOpenShell* shell;
			if (!convert_to_ifc(exp.Current(), shell, advanced)) {
				return 0;
			}
			shells->push(shell);
		}

		if (shells->size() > 0) {
			items->push(new IfcSchema::IfcShellBasedSurfaceModel(shells->generalize()));
			rep = new IfcSchema::IfcShapeRepresentation(0, std::string("Body"), std::string("Brep"), items);
		} else {

			// If not, see if there is are one of more faces. Note that they will be grouped into a shell.
			IfcSchema::IfcOpenShell* shell;
			int face_count = convert_to_ifc(shape, shell, advanced);

			if (face_count > 0) {
				items->push(shell);
				rep = new IfcSchema::IfcShapeRepresentation(0, std::string("Body"), std::string("Brep"), items);
			} else {

				// If not, see if there are any edges. Note that wires are skipped as
				// they are not commonly top-level geometrical descriptions in IFC.
				// Also note that edges are written as trimmed curves rather than edges.

				IfcEntityList::ptr edges(new IfcEntityList);

				for (TopExp_Explorer exp(shape, TopAbs_EDGE); exp.More(); exp.Next()) {
					IfcSchema::IfcCurve* c;
					if (!convert_to_ifc(TopoDS::Edge(exp.Current()), c, advanced)) {
						return 0;
					}
					edges->push(c);
				}

				if (edges->size() == 0) {
					return 0;
				} else if (edges->size() == 1) {
					rep = new IfcSchema::IfcShapeRepresentation(0, std::string("Axis"), std::string("Curve2D"), edges->as<IfcSchema::IfcRepresentationItem>());
				} else {
					// A geometric set is created as that probably (?) makes more sense in IFC
					IfcSchema::IfcGeometricCurveSet* curves = new IfcSchema::IfcGeometricCurveSet(edges);
					items->push(curves);
					rep = new IfcSchema::IfcShapeRepresentation(0, std::string("Axis"), std::string("GeometricCurveSet"), items->as<IfcSchema::IfcRepresentationItem>());
				}

			}
		}
	}

	IfcSchema::IfcRepresentation::list::ptr reps(new IfcSchema::IfcRepresentation::list);
	reps->push(rep);
	return new IfcSchema::IfcProductDefinitionShape(boost::none, boost::none, reps);
}