Skip to content

Commit f8303f0

Browse files
occt bounding box and bounding sphere implementation
1 parent 8148078 commit f8303f0

5 files changed

Lines changed: 282 additions & 1 deletion

File tree

packages/dev/occt-worker/lib/api/occt/operations.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,126 @@ export class OCCTOperations {
8080
return this.occWorkerManager.genericCallToWorkerPromise("operations.distancesToShapeFromPoints", inputs);
8181
}
8282

83+
/**
84+
* Computes bounding box parameters of the shape
85+
* @param inputs a shape
86+
* @returns Min, max center and size of the bounding box
87+
* @group measure
88+
* @shortname bbox of shape
89+
* @drawable false
90+
*/
91+
boundingBoxOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.OCCT.BoundingBoxPropsDto> {
92+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingBoxOfShape", inputs);
93+
}
94+
95+
/**
96+
* Get min point of the bounding box of the shape
97+
* @param inputs a shape
98+
* @returns Min point of the bounding box
99+
* @group measure
100+
* @shortname bbox min of shape
101+
* @drawable false
102+
*/
103+
boundingBoxMinOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.Base.Point3> {
104+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingBoxMinOfShape", inputs);
105+
}
106+
107+
/**
108+
* Get max point of the bounding box of the shape
109+
* @param inputs a shape
110+
* @returns Max point of the bounding box
111+
* @group measure
112+
* @shortname bbox max of shape
113+
* @drawable false
114+
*/
115+
boundingBoxMaxOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.Base.Point3> {
116+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingBoxMaxOfShape", inputs);
117+
}
118+
119+
/**
120+
* Get center point of the bounding box of the shape
121+
* @param inputs a shape
122+
* @returns Center point of the bounding box
123+
* @group measure
124+
* @shortname bbox center of shape
125+
* @drawable false
126+
*/
127+
boundingBoxCenterOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.Base.Point3> {
128+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingBoxCenterOfShape", inputs);
129+
}
130+
131+
/**
132+
* Get size point of the bounding box of the shape
133+
* @param inputs a shape
134+
* @returns Center point of the bounding box
135+
* @group measure
136+
* @shortname bbox size of shape
137+
* @drawable false
138+
*/
139+
boundingBoxSizeOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.Base.Vector3> {
140+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingBoxSizeOfShape", inputs);
141+
}
142+
143+
/**
144+
* Get bounding box shape of the shape
145+
* @param inputs a shape
146+
* @returns shape of the bounding box
147+
* @group measure
148+
* @shortname bbox shape of shape
149+
* @drawable true
150+
*/
151+
boundingBoxShapeOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.OCCT.TopoDSShapePointer> {
152+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingBoxShapeOfShape", inputs);
153+
}
154+
155+
/**
156+
* Computes bounding sphere parameters of the shape
157+
* @param inputs a shape
158+
* @returns Center and radius of the bounding sphere
159+
* @group measure
160+
* @shortname bsphere of shape
161+
* @drawable false
162+
*/
163+
boundingSphereOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.OCCT.BoundingSpherePropsDto> {
164+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingSphereOfShape", inputs);
165+
}
166+
167+
/**
168+
* Get center point of the bounding sphere of the shape
169+
* @param inputs a shape
170+
* @returns Center point of the bounding sphere
171+
* @group measure
172+
* @shortname bsphere center of shape
173+
* @drawable false
174+
*/
175+
boundingSphereCenterOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.Base.Point3> {
176+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingSphereCenterOfShape", inputs);
177+
}
178+
179+
/**
180+
* Get radius of the bounding sphere of the shape
181+
* @param inputs a shape
182+
* @returns Radius of the bounding sphere
183+
* @group measure
184+
* @shortname bsphere radius of shape
185+
* @drawable false
186+
*/
187+
boundingSphereRadiusOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<number> {
188+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingSphereRadiusOfShape", inputs);
189+
}
190+
191+
/**
192+
* Get bounding sphere shape of the shape
193+
* @param inputs a shape
194+
* @returns shape of the bounding sphere
195+
* @group measure
196+
* @shortname bsphere shape of shape
197+
* @drawable true
198+
*/
199+
boundingSphereShapeOfShape(inputs: Inputs.OCCT.ShapeDto<Inputs.OCCT.TopoDSShapePointer>): Promise<Inputs.OCCT.TopoDSShapePointer> {
200+
return this.occWorkerManager.genericCallToWorkerPromise("operations.boundingSphereShapeOfShape", inputs);
201+
}
202+
83203
/**
84204
* Extrudes the shape along direction - wire will produce shell, face will produce solid
85205
* @param inputs Shape to extrude and direction parameter with tolerance

packages/dev/occt/lib/api/inputs/occ-inputs.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,63 @@ export namespace OCCT {
490490
*/
491491
points: Base.Point3[];
492492
}
493+
export class BoundingBoxDto {
494+
constructor(bbox?: BoundingBoxPropsDto) {
495+
if (bbox !== undefined) { this.bbox = bbox; }
496+
}
497+
/**
498+
* Bounding box
499+
* @default undefined
500+
*/
501+
bbox?: BoundingBoxPropsDto;
502+
}
503+
export class BoundingBoxPropsDto {
504+
constructor(min?: Base.Point3, max?: Base.Point3, center?: Base.Point3, size?: Base.Vector3) {
505+
if (min !== undefined) { this.min = min; }
506+
if (max !== undefined) { this.max = max; }
507+
if (center !== undefined) { this.center = center; }
508+
if (size !== undefined) { this.size = size; }
509+
}
510+
/**
511+
* Minimum point of the bounding box
512+
* @default [0, 0, 0]
513+
*/
514+
min: Base.Point3 = [0, 0, 0];
515+
/**
516+
* Maximum point of the bounding box
517+
* @default [0, 0, 0]
518+
*/
519+
max: Base.Point3 = [0, 0, 0];
520+
/**
521+
* Center point of the bounding box
522+
* @default [0, 0, 0]
523+
*/
524+
center: Base.Point3 = [0, 0, 0];
525+
/**
526+
* Size of the bounding box
527+
* @default [0, 0, 0]
528+
*/
529+
size: Base.Vector3 = [0, 0, 0];
530+
}
531+
export class BoundingSpherePropsDto {
532+
constructor(center?: Base.Point3, radius?: number) {
533+
if (center !== undefined) { this.center = center; }
534+
if (radius !== undefined) { this.radius = radius; }
535+
}
536+
/**
537+
* Center point of the bounding box
538+
* @default [0, 0, 0]
539+
*/
540+
center: Base.Point3 = [0, 0, 0];
541+
/**
542+
* Radius of the bounding sphere
543+
* @default 0
544+
* @minimum 0
545+
* @maximum Infinity
546+
* @step 0.1
547+
*/
548+
radius = 0;
549+
}
493550
export class SplitWireOnPointsDto<T> {
494551
constructor(shape?: T, points?: Base.Point3[]) {
495552
if (shape !== undefined) { this.shape = shape; }

packages/dev/occt/lib/occ-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class OccHelper {
7676

7777
this.operationsService = new OperationsService(occ, this.enumService, this.entitiesService, this.converterService,
7878
this.booleansService, this.shapeGettersService, this.edgesService, this.transformsService,
79-
this.vecHelper, this.wiresService, this.facesService, this.shellsService);
79+
this.vecHelper, this.wiresService, this.facesService, this.solidsService, this.shellsService);
8080

8181
this.filletsService = new FilletsService(occ, this.vecHelper, this.iteratorService, this.converterService, this.entitiesService,
8282
this.transformsService, this.shapeGettersService, this.edgesService, this.operationsService, this.facesService);

packages/dev/occt/lib/services/base/operations.service.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { EdgesService } from "./edges.service";
1616
import { WiresService } from "./wires.service";
1717
import { FacesService } from "./faces.service";
1818
import { ShellsService } from "./shells.service";
19+
import { SolidsService } from "./solids.service";
1920

2021
export class OperationsService {
2122

@@ -31,6 +32,7 @@ export class OperationsService {
3132
private readonly vecHelper: VectorHelperService,
3233
private readonly wiresService: WiresService,
3334
private readonly facesService: FacesService,
35+
private readonly solidsService: SolidsService,
3436
private readonly shellsService: ShellsService,
3537

3638
) { }
@@ -151,6 +153,62 @@ export class OperationsService {
151153
});
152154
}
153155

156+
boundingBoxOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.OCCT.BoundingBoxPropsDto {
157+
const bbox = new this.occ.Bnd_Box_1();
158+
this.occ.BRepBndLib.Add(inputs.shape, bbox, false);
159+
const cornerMin = bbox.CornerMin();
160+
const cornerMax = bbox.CornerMax();
161+
const min = [cornerMin.X(), cornerMin.Y(), cornerMin.Z()] as Inputs.Base.Point3;
162+
const max = [cornerMax.X(), cornerMax.Y(), cornerMax.Z()] as Inputs.Base.Point3;
163+
const center = [
164+
(cornerMin.X() + cornerMax.X()) / 2,
165+
(cornerMin.Y() + cornerMax.Y()) / 2,
166+
(cornerMin.Z() + cornerMax.Z()) / 2
167+
] as Inputs.Base.Point3;
168+
const size = [
169+
cornerMax.X() - cornerMin.X(),
170+
cornerMax.Y() - cornerMin.Y(),
171+
cornerMax.Z() - cornerMin.Z()
172+
] as Inputs.Base.Vector3;
173+
bbox.delete();
174+
const result = {
175+
min,
176+
max,
177+
center,
178+
size
179+
};
180+
return result;
181+
}
182+
183+
boundingBoxShapeOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): TopoDS_Shape {
184+
const bbox = this.boundingBoxOfShape(inputs);
185+
return this.solidsService.createBoxFromCorner({
186+
corner: bbox.min,
187+
width: bbox.size[0],
188+
height: bbox.size[1],
189+
length: bbox.size[2],
190+
});
191+
}
192+
193+
boundingSphereOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.OCCT.BoundingSpherePropsDto {
194+
const bbox = this.boundingBoxOfShape(inputs);
195+
const center = bbox.center;
196+
const radius = this.vecHelper.distanceBetweenPoints(bbox.min, center);
197+
const result = {
198+
center,
199+
radius
200+
};
201+
return result;
202+
}
203+
204+
boundingSphereShapeOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): TopoDS_Shape {
205+
const bbox = this.boundingSphereOfShape(inputs);
206+
return this.solidsService.createSphere({
207+
center: bbox.center,
208+
radius: bbox.radius,
209+
});
210+
}
211+
154212
loft(inputs: Inputs.OCCT.LoftDto<TopoDS_Wire | TopoDS_Edge>) {
155213
const pipe = new this.occ.BRepOffsetAPI_ThruSections(inputs.makeSolid, false, 1.0e-06);
156214
inputs.shapes.forEach((wire) => {

packages/dev/occt/lib/services/operations.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,52 @@ export class OCCTOperations {
2828
return this.och.operationsService.distancesToShapeFromPoints(inputs);
2929
}
3030

31+
boundingBoxOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.OCCT.BoundingBoxPropsDto {
32+
return this.och.operationsService.boundingBoxOfShape(inputs);
33+
}
34+
35+
boundingBoxMinOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.Base.Point3 {
36+
const bbox = this.och.operationsService.boundingBoxOfShape(inputs);
37+
return bbox.min;
38+
}
39+
40+
boundingBoxMaxOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.Base.Point3 {
41+
const bbox = this.och.operationsService.boundingBoxOfShape(inputs);
42+
return bbox.max;
43+
}
44+
45+
boundingBoxCenterOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.Base.Point3 {
46+
const bbox = this.och.operationsService.boundingBoxOfShape(inputs);
47+
return bbox.center;
48+
}
49+
50+
boundingBoxSizeOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.Base.Vector3 {
51+
const bbox = this.och.operationsService.boundingBoxOfShape(inputs);
52+
return bbox.size;
53+
}
54+
55+
boundingBoxShapeOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): TopoDS_Shape {
56+
return this.och.operationsService.boundingBoxShapeOfShape(inputs);
57+
}
58+
59+
boundingSphereOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.OCCT.BoundingSpherePropsDto {
60+
return this.och.operationsService.boundingSphereOfShape(inputs);
61+
}
62+
63+
boundingSphereCenterOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.Base.Point3 {
64+
const sphere = this.och.operationsService.boundingSphereOfShape(inputs);
65+
return sphere.center;
66+
}
67+
68+
boundingSphereRadiusOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): number {
69+
const sphere = this.och.operationsService.boundingSphereOfShape(inputs);
70+
return sphere.radius;
71+
}
72+
73+
boundingSphereShapeOfShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): TopoDS_Shape {
74+
return this.och.operationsService.boundingSphereShapeOfShape(inputs);
75+
}
76+
3177
loft(inputs: Inputs.OCCT.LoftDto<TopoDS_Wire | TopoDS_Edge>) {
3278
return this.och.operationsService.loft(inputs);
3379
}

0 commit comments

Comments
 (0)