Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | 1016x 724x 724x 724x 724x 724x 724x 724x 125x 125x 125x 125x 125x 125x 125x 125x 116x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 59x 59x 59x 59x 59x 623x 59x 8x 59x 24x 59x 591x 591x 591x 591x 59x 591x 591x 591x 591x 591x 59x 32x 32x 32x 231x 231x 231x 32x 3x 32x 21x 32x 207x 207x 207x 207x 207x 32x 42x 42x 42x 42x 42x 42x 41x 41x 41x 41x 41x 41x 8x 8x 8x 8x 8x 8x 8x | import { Adaptor3d_Curve, BRepAdaptor_CompCurve_2, Geom_Curve, OpenCascadeInstance, TopoDS_Shape } from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
import * as Inputs from "../../api/inputs/inputs";
import { Base } from "../../api/inputs/inputs";
import { VectorHelperService } from "../../api/vector-helper.service";
import { EntitiesService } from "./entities.service";
export class GeomService {
constructor(
public readonly occ: OpenCascadeInstance,
private readonly vecHelper: VectorHelperService,
private readonly entitiesService: EntitiesService
) { }
curveLength(inputs: Inputs.OCCT.ShapeDto<Adaptor3d_Curve>): number {
return this.occ.GCPnts_AbscissaPoint.Length_1(inputs.shape);
}
pointOnCurveAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<Geom_Curve | BRepAdaptor_CompCurve_2>): Base.Point3 {
const curve = inputs.shape;
const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
const param = this.vecHelper.remap(inputs.param, 0, 1, curve.FirstParameter(), curve.LastParameter());
curve.D0(param, gpPnt);
const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
gpPnt.delete();
return pt;
}
pointOnCurveAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<Adaptor3d_Curve>): Base.Point3 {
const absc = new this.occ.GCPnts_AbscissaPoint_2(inputs.shape, inputs.length, inputs.shape.FirstParameter());
const param = absc.Parameter();
const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
inputs.shape.D0(param, gpPnt);
const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
absc.delete();
gpPnt.delete();
return pt;
}
pointsOnCurveAtLengths(inputs: Inputs.OCCT.DataOnGeometryAtLengthsDto<Adaptor3d_Curve>): Base.Point3[] {
return inputs.lengths.map(length => this.pointOnCurveAtLength({ shape: inputs.shape, length }));
}
tangentOnCurveAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<Adaptor3d_Curve>): Base.Point3 {
const absc = new this.occ.GCPnts_AbscissaPoint_2(inputs.shape, inputs.length, inputs.shape.FirstParameter());
const param = absc.Parameter();
const vec = inputs.shape.DN(param, 1);
const pt: Base.Point3 = [vec.X(), vec.Y(), vec.Z()];
vec.delete();
absc.delete();
return pt;
}
tangentOnCurveAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<Geom_Curve | BRepAdaptor_CompCurve_2>): Base.Point3 {
const curve = inputs.shape;
const param = this.vecHelper.remap(inputs.param, 0, 1, curve.FirstParameter(), curve.LastParameter());
const vec = curve.DN(param, 1);
const pt: Base.Point3 = [vec.X(), vec.Y(), vec.Z()];
vec.delete();
return pt;
}
divideCurveByEqualLengthDistance(inputs: Inputs.OCCT.DivideDto<Adaptor3d_Curve>): Base.Point3[] {
const curve = inputs.shape;
const curveLength = this.occ.GCPnts_AbscissaPoint.Length_5(curve, curve.FirstParameter(), curve.LastParameter());
const step = curveLength / inputs.nrOfDivisions;
const lengths: number[] = [];
for (let i = 0; i <= curveLength + 0.000000001; i += step) {
lengths.push(i);
}
if (inputs.removeStartPoint) {
lengths.shift();
}
if (inputs.removeEndPoint) {
lengths.pop();
}
const paramsLength = lengths.map(l => {
const absc = new this.occ.GCPnts_AbscissaPoint_2(curve, l, curve.FirstParameter());
const param = absc.Parameter();
absc.delete();
return param;
});
const points = paramsLength.map(r => {
const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
curve.D0(r, gpPnt);
const pt = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()] as Base.Point3;
gpPnt.delete();
return pt;
});
return points;
}
divideCurveToNrSegments(inputs: Inputs.OCCT.DivideDto<Geom_Curve | BRepAdaptor_CompCurve_2>, uMin: number, uMax: number) {
const curve = inputs.shape;
const ranges: number[] = [];
for (let i = 0; i <= inputs.nrOfDivisions; i++) {
const param = (i / inputs.nrOfDivisions);
const paramMapped = this.vecHelper.remap(param, 0, 1, uMin, uMax);
ranges.push(paramMapped);
}
if (inputs.removeStartPoint) {
ranges.shift();
}
if (inputs.removeEndPoint) {
ranges.pop();
}
const points = ranges.map(r => {
const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
curve.D0(r, gpPnt);
const pt = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()] as Base.Point3;
gpPnt.delete();
return pt;
});
return points;
}
startPointOnCurve(inputs: Inputs.OCCT.ShapeDto<Geom_Curve | BRepAdaptor_CompCurve_2>): Inputs.Base.Point3 {
const curve = inputs.shape;
const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
curve.D0(curve.FirstParameter(), gpPnt);
const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
gpPnt.delete();
return pt;
}
endPointOnCurve(inputs: Inputs.OCCT.ShapeDto<Geom_Curve | BRepAdaptor_CompCurve_2>): Inputs.Base.Point3 {
const curve = inputs.shape;
const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
curve.D0(curve.LastParameter(), gpPnt);
const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
gpPnt.delete();
return pt;
}
getLinearCenterOfMass(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Base.Point3 {
const edge: TopoDS_Shape = inputs.shape;
const gprops = new this.occ.GProp_GProps_1();
this.occ.BRepGProp.LinearProperties(edge, gprops, false, false);
const gppnt = gprops.CentreOfMass();
const pt: Base.Point3 = [gppnt.X(), gppnt.Y(), gppnt.Z()];
gprops.delete();
return pt;
}
}
|