IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
	: Representation(brep.settings())
	, _id(brep.getId())
{
	TopoDS_Compound compound;
	BRep_Builder builder;
	builder.MakeCompound(compound);
	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = brep.begin(); it != brep.end(); ++ it) {
		const TopoDS_Shape& s = it->Shape();
		gp_GTrsf trsf = it->Placement();
		if (settings().convert_back_units()) {
			gp_Trsf scale;
			scale.SetScaleFactor(1.0 / settings().unit_magnitude());
			trsf.PreMultiply(scale);
		}
		bool trsf_valid = false;
		gp_Trsf _trsf;
		try {
			_trsf = trsf.Trsf();
			trsf_valid = true;
		} catch (...) {}
		const TopoDS_Shape moved_shape = trsf_valid ? s.Moved(_trsf) :
			BRepBuilderAPI_GTransform(s,trsf,true).Shape();
		builder.Add(compound,moved_shape);
	}
	std::stringstream sstream;
	BRepTools::Write(compound,sstream);
	_brep_data = sstream.str();
}
void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<real_t>* o) {
	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
		gp_GTrsf gtrsf = it->Placement();

		const gp_Trsf& o_trsf = o->transformation().data();
		gtrsf.PreMultiply(o_trsf);

        if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) {
			gp_Trsf scale;
			scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude());
			gtrsf.PreMultiply(scale);
		}
		
		const TopoDS_Shape& s = it->Shape();			
			
		bool trsf_valid = false;
		gp_Trsf trsf;
		try {
			trsf = gtrsf.Trsf();
			trsf_valid = true;
		} catch (...) {}
			
		const TopoDS_Shape moved_shape = trsf_valid
			? BRepBuilderAPI_Transform(s, trsf, true).Shape()
			: BRepBuilderAPI_GTransform(s, gtrsf, true).Shape();
			
		writeShape(moved_shape);
	}
}
示例#3
0
文件: BIM.cpp 项目: lorinma/EaSTBIM
BldElement::BldElement(int id, string guid, string name, string type,
                       const IfcGeomObjects::IfcGeomShapeModelObject *o):id(id),guid(guid),name(name),type(type),geomtool(new Geometry){
    BRep_Builder builder;
    builder.MakeCompound(shape);
    for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->mesh().begin(); it != o->mesh().end(); ++ it) {
        TopoDS_Shape brep = it->Shape();
        gp_Trsf trsf = it->Placement().Trsf();
        brep.Move(trsf);
//        FIXME are the shells in the shape fixed by ifcopenshell?
        builder.Add(shape,brep);
    }
    shape_original=shape;
}
void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<real_t>* o) {
	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
		gp_GTrsf gtrsf = it->Placement();

		const gp_Trsf& o_trsf = o->transformation().data();
		gtrsf.PreMultiply(o_trsf);

        if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) {
			gp_Trsf scale;
			scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude());
			gtrsf.PreMultiply(scale);
		}
		
		const TopoDS_Shape& s = it->Shape();
		const TopoDS_Shape moved_shape = IfcGeom::Kernel::apply_transformation(s, gtrsf);
			
		writeShape(moved_shape);
	}
}
IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
	: Representation(brep.settings())
	, _id(brep.getId())
{
	TopoDS_Compound compound;
	BRep_Builder builder;
	builder.MakeCompound(compound);
	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = brep.begin(); it != brep.end(); ++ it) {
		const TopoDS_Shape& s = it->Shape();
		gp_GTrsf trsf = it->Placement();
		
		if (it->hasStyle() && it->Style().Diffuse()) {
			const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse();
			_surface_styles.push_back(clr.R());
			_surface_styles.push_back(clr.G());
			_surface_styles.push_back(clr.B());
		} else {
			_surface_styles.push_back(-1.);
			_surface_styles.push_back(-1.);
			_surface_styles.push_back(-1.);
		}
		if (it->hasStyle() && it->Style().Transparency()) {
			_surface_styles.push_back(1. - *it->Style().Transparency());
		} else {
			_surface_styles.push_back(1.);
		}
		
		if (settings().get(IteratorSettings::CONVERT_BACK_UNITS)) {
			gp_Trsf scale;
			scale.SetScaleFactor(1.0 / settings().unit_magnitude());
			trsf.PreMultiply(scale);
		}
		bool trsf_valid = false;
		gp_Trsf _trsf;
		try {
			_trsf = trsf.Trsf();
			trsf_valid = true;
		} catch (...) {}
		const TopoDS_Shape moved_shape = trsf_valid ? s.Moved(_trsf) :
			BRepBuilderAPI_GTransform(s,trsf,true).Shape();
		builder.Add(compound,moved_shape);
	}
	std::stringstream sstream;
	BRepTools::Write(compound,sstream);
	_brep_data = sstream.str();
}
示例#6
0
void SvgSerializer::write(const IfcGeom::BRepElement<double>* o) {
	IfcSchema::IfcBuildingStorey* storey = 0;
	IfcSchema::IfcObjectDefinition* obdef = static_cast<IfcSchema::IfcObjectDefinition*>(file->entityById(o->id()));

#ifndef USE_IFC4
	typedef IfcSchema::IfcRelDecomposes decomposition_element;
#else
	typedef IfcSchema::IfcRelAggregates decomposition_element;
#endif

	while (true) {
		// Iterate over the decomposing element to find the parent IfcBuildingStorey
		decomposition_element::list::ptr decomposes = obdef->Decomposes();
		if (!decomposes->size()) {
			if (obdef->is(IfcSchema::Type::IfcElement)) {
				IfcSchema::IfcRelContainedInSpatialStructure::list::ptr containment = ((IfcSchema::IfcElement*)obdef)->ContainedInStructure();
				if (!containment->size()) {
					break;
				}
				for (IfcSchema::IfcRelContainedInSpatialStructure::list::it it = containment->begin(); it != containment->end(); ++it) {
					IfcSchema::IfcRelContainedInSpatialStructure* container = *it;
					if (container->RelatingStructure() != obdef) {
						obdef = container->RelatingStructure();
					}
				}
			} else {
				break;
			}
		} else {
			for (decomposition_element::list::it it = decomposes->begin(); it != decomposes->end(); ++it) {
				decomposition_element* decompose = *it;
				if (decompose->RelatingObject() != obdef) {
					obdef = decompose->RelatingObject();
				}
			}
		}
		if (obdef->is(IfcSchema::Type::IfcBuildingStorey)) {
			storey = static_cast<IfcSchema::IfcBuildingStorey*>(obdef);
			break;
		}
	}

	if (!storey) return;

	path_object& p = start_path(storey, nameElement(o));

	for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
		gp_GTrsf gtrsf = it->Placement();
		
		gp_Trsf o_trsf;
		const std::vector<double>& matrix = o->transformation().matrix().data();
		o_trsf.SetValues(
			matrix[0], matrix[3], matrix[6], matrix[ 9],
			matrix[1], matrix[4], matrix[7], matrix[10], 
			matrix[2], matrix[5], matrix[8], matrix[11]
#if OCC_VERSION_HEX < 0x60800
			, Precision::Angular(), Precision::Confusion()
#endif
		);
		gtrsf.PreMultiply(o_trsf);
		const TopoDS_Shape& s = it->Shape();			
			
		bool trsf_valid = false;
		gp_Trsf trsf;
		try {
			trsf = gtrsf.Trsf();
			trsf_valid = true;
		} catch (...) {}
			
		const TopoDS_Shape moved_shape = trsf_valid
			? BRepBuilderAPI_Transform(s, trsf, true).Shape()
			: BRepBuilderAPI_GTransform(s, gtrsf, true).Shape();
			
		const double inf = std::numeric_limits<double>::infinity();
		double zmin = inf;
		double zmax = -inf;
		{TopExp_Explorer exp(moved_shape, TopAbs_VERTEX);
		for (; exp.More(); exp.Next()) {
			const TopoDS_Vertex& vertex = TopoDS::Vertex(exp.Current());
			gp_Pnt pnt = BRep_Tool::Pnt(vertex);
			if (pnt.Z() < zmin) { zmin = pnt.Z(); }
			if (pnt.Z() > zmax) { zmax = pnt.Z(); }
		}}

		if (section_height) {
			if (zmin > section_height || zmax < section_height) continue;
		} else {
			if (zmin == inf || (zmax - zmin) < 1.) continue;
		}

		const double cut_z = section_height.get_value_or(zmin + 1.);

		// Create a horizontal cross section 1 meter above the bottom point of the shape		
		TopoDS_Shape result = BRepAlgoAPI_Section(moved_shape, gp_Pln(gp_Pnt(0, 0, cut_z), gp::DZ()));

		Handle(TopTools_HSequenceOfShape) edges = new TopTools_HSequenceOfShape();
		Handle(TopTools_HSequenceOfShape) wires = new TopTools_HSequenceOfShape();
		{TopExp_Explorer exp(result, TopAbs_EDGE);
		for (; exp.More(); exp.Next()) {
			 edges->Append(exp.Current());
		}}
		ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edges, 1e-5, false, wires);

		gp_Pnt prev;

		for (int i = 1; i <= wires->Length(); ++i) {
			const TopoDS_Wire& wire = TopoDS::Wire(wires->Value(i));
			write(p, wire);
		}
	}	
}