siren2 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +36 -0
- data/Rakefile +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/siren2/extconf.rb +66 -0
- data/ext/siren2/inc/bndbox.h +51 -0
- data/ext/siren2/inc/bo.h +20 -0
- data/ext/siren2/inc/brep.h +17 -0
- data/ext/siren2/inc/common.h +98 -0
- data/ext/siren2/inc/curve.h +65 -0
- data/ext/siren2/inc/curve/bscurve.h +22 -0
- data/ext/siren2/inc/curve/bzcurve.h +17 -0
- data/ext/siren2/inc/curve/circle.h +29 -0
- data/ext/siren2/inc/curve/ellipse.h +15 -0
- data/ext/siren2/inc/curve/hyperbola.h +15 -0
- data/ext/siren2/inc/curve/line.h +17 -0
- data/ext/siren2/inc/curve/offsetcurve.h +15 -0
- data/ext/siren2/inc/curve/parabola.h +15 -0
- data/ext/siren2/inc/filler.h +26 -0
- data/ext/siren2/inc/heal.h +19 -0
- data/ext/siren2/inc/io/iges.h +19 -0
- data/ext/siren2/inc/io/step.h +18 -0
- data/ext/siren2/inc/io/stl.h +13 -0
- data/ext/siren2/inc/offset.h +35 -0
- data/ext/siren2/inc/shape.h +140 -0
- data/ext/siren2/inc/shape/chunk.h +26 -0
- data/ext/siren2/inc/shape/compound.h +22 -0
- data/ext/siren2/inc/shape/edge.h +50 -0
- data/ext/siren2/inc/shape/face.h +67 -0
- data/ext/siren2/inc/shape/shell.h +21 -0
- data/ext/siren2/inc/shape/solid.h +41 -0
- data/ext/siren2/inc/shape/vertex.h +23 -0
- data/ext/siren2/inc/shape/wire.h +31 -0
- data/ext/siren2/inc/siren.h +39 -0
- data/ext/siren2/inc/surface/dummy +0 -0
- data/ext/siren2/inc/topalgo.h +52 -0
- data/ext/siren2/inc/trans.h +48 -0
- data/ext/siren2/inc/vec.h +65 -0
- data/ext/siren2/src/bndbox.cpp +343 -0
- data/ext/siren2/src/bo.cpp +66 -0
- data/ext/siren2/src/brep.cpp +69 -0
- data/ext/siren2/src/common.cpp +18 -0
- data/ext/siren2/src/curve.cpp +75 -0
- data/ext/siren2/src/curve/bscurve.cpp +118 -0
- data/ext/siren2/src/curve/bzcurve.cpp +55 -0
- data/ext/siren2/src/curve/circle.cpp +146 -0
- data/ext/siren2/src/curve/ellipse.cpp +17 -0
- data/ext/siren2/src/curve/hyperbola.cpp +17 -0
- data/ext/siren2/src/curve/line.cpp +24 -0
- data/ext/siren2/src/curve/offsetcurve.cpp +17 -0
- data/ext/siren2/src/curve/parabola.cpp +17 -0
- data/ext/siren2/src/filler.cpp +191 -0
- data/ext/siren2/src/heal.cpp +92 -0
- data/ext/siren2/src/io/iges.cpp +85 -0
- data/ext/siren2/src/io/step.cpp +47 -0
- data/ext/siren2/src/io/stl.cpp +22 -0
- data/ext/siren2/src/offset.cpp +256 -0
- data/ext/siren2/src/shape.cpp +617 -0
- data/ext/siren2/src/shape/chunk.cpp +65 -0
- data/ext/siren2/src/shape/compound.cpp +96 -0
- data/ext/siren2/src/shape/edge.cpp +254 -0
- data/ext/siren2/src/shape/face.cpp +366 -0
- data/ext/siren2/src/shape/shell.cpp +41 -0
- data/ext/siren2/src/shape/solid.cpp +256 -0
- data/ext/siren2/src/shape/vertex.cpp +68 -0
- data/ext/siren2/src/shape/wire.cpp +100 -0
- data/ext/siren2/src/siren.cpp +80 -0
- data/ext/siren2/src/surface/dummy +0 -0
- data/ext/siren2/src/topalgo.cpp +246 -0
- data/ext/siren2/src/trans.cpp +330 -0
- data/ext/siren2/src/vec.cpp +454 -0
- data/lib/io/dxf.rb +68 -0
- data/lib/io/plot.rb +38 -0
- data/lib/io/ply.rb +57 -0
- data/lib/io/stl.rb +35 -0
- data/lib/io/svg.rb +44 -0
- data/lib/kernel/array.rb +133 -0
- data/lib/kernel/float.rb +15 -0
- data/lib/shape.rb +157 -0
- data/lib/shape/compound.rb +11 -0
- data/lib/shape/edge.rb +15 -0
- data/lib/shape/face.rb +7 -0
- data/lib/shape/shell.rb +21 -0
- data/lib/shape/solid.rb +10 -0
- data/lib/shape/vertex.rb +7 -0
- data/lib/shape/wire.rb +14 -0
- data/lib/shapes.rb +52 -0
- data/lib/siren.rb +166 -0
- data/lib/siren2/version.rb +3 -0
- data/lib/vec.rb +81 -0
- data/siren2.gemspec +28 -0
- metadata +195 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#include "siren.h"
|
|
2
|
+
|
|
3
|
+
#include "vec.h"
|
|
4
|
+
#include "trans.h"
|
|
5
|
+
#include "bndbox.h"
|
|
6
|
+
#include "shape.h"
|
|
7
|
+
#include "brep.h"
|
|
8
|
+
#include "topalgo.h"
|
|
9
|
+
#include "curve.h"
|
|
10
|
+
#include "filler.h"
|
|
11
|
+
|
|
12
|
+
#ifdef SR_ENABLE_BO
|
|
13
|
+
#include "bo.h"
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#ifdef SR_ENABLE_SHHEALING
|
|
17
|
+
#include "heal.h"
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#ifdef SR_ENABLE_OFFSET
|
|
21
|
+
#include "offset.h"
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#ifdef SR_ENABLE_IGES
|
|
25
|
+
#include "io/iges.h"
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#ifdef SR_ENABLE_STL
|
|
29
|
+
#include "io/stl.h"
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#ifdef SR_ENABLE_STEP
|
|
33
|
+
#include "io/step.h"
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
VALUE sr_mSiren;
|
|
37
|
+
|
|
38
|
+
extern "C" {
|
|
39
|
+
|
|
40
|
+
// initializer
|
|
41
|
+
void Init_siren2()
|
|
42
|
+
{
|
|
43
|
+
// Siren module
|
|
44
|
+
sr_mSiren = rb_define_module("Siren");
|
|
45
|
+
|
|
46
|
+
// Class
|
|
47
|
+
siren_vec_install ();
|
|
48
|
+
siren_trans_install ();
|
|
49
|
+
siren_bndbox_install ();
|
|
50
|
+
siren_shape_install ();
|
|
51
|
+
siren_curve_install ();
|
|
52
|
+
siren_topalgo_install();
|
|
53
|
+
siren_brep_install ();
|
|
54
|
+
siren_filler_install ();
|
|
55
|
+
#ifdef SR_ENABLE_OFFSET
|
|
56
|
+
siren_offset_install ();
|
|
57
|
+
#endif
|
|
58
|
+
#ifdef SR_ENABLE_BO
|
|
59
|
+
siren_bo_install ();
|
|
60
|
+
#endif
|
|
61
|
+
#ifdef SR_ENABLE_IGES
|
|
62
|
+
siren_iges_install ();
|
|
63
|
+
#endif
|
|
64
|
+
#ifdef SR_ENABLE_STL
|
|
65
|
+
siren_stl_install ();
|
|
66
|
+
#endif
|
|
67
|
+
#ifdef SR_ENABLE_STEP
|
|
68
|
+
siren_step_install ();
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// finalizer
|
|
75
|
+
void rb_mruby_siren_gem_final()
|
|
76
|
+
{
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
} // extern "C" {
|
|
File without changes
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#include "topalgo.h"
|
|
2
|
+
|
|
3
|
+
bool siren_topalgo_install()
|
|
4
|
+
{
|
|
5
|
+
// Class method
|
|
6
|
+
#if 0
|
|
7
|
+
rb_define_class_method(sr_mSiren, "copy", RUBY_METHOD_FUNC(siren_topalgo_copy), -1);
|
|
8
|
+
rb_define_class_method(sr_mSiren, "line", RUBY_METHOD_FUNC(siren_topalgo_line), -1);
|
|
9
|
+
rb_define_class_method(sr_mSiren, "infline", RUBY_METHOD_FUNC(siren_topalgo_infline), -1);
|
|
10
|
+
rb_define_class_method(sr_mSiren, "polyline", RUBY_METHOD_FUNC(siren_topalgo_polyline), -1);
|
|
11
|
+
rb_define_class_method(sr_mSiren, "interpolate",RUBY_METHOD_FUNC(siren_topalgo_interpolate), -1);
|
|
12
|
+
rb_define_class_method(sr_mSiren, "arc", RUBY_METHOD_FUNC(siren_topalgo_arc), -1);
|
|
13
|
+
rb_define_class_method(sr_mSiren, "arc3p", RUBY_METHOD_FUNC(siren_topalgo_arc3p), -1);
|
|
14
|
+
rb_define_class_method(sr_mSiren, "circle", RUBY_METHOD_FUNC(siren_topalgo_circle), -1);
|
|
15
|
+
rb_define_class_method(sr_mSiren, "circle3p", RUBY_METHOD_FUNC(siren_topalgo_circle3p), -1);
|
|
16
|
+
#endif
|
|
17
|
+
// For mix-in
|
|
18
|
+
rb_define_method(sr_mSiren, "copy", RUBY_METHOD_FUNC(siren_topalgo_copy), -1);
|
|
19
|
+
rb_define_method(sr_mSiren, "line", RUBY_METHOD_FUNC(siren_topalgo_line), -1);
|
|
20
|
+
rb_define_method(sr_mSiren, "infline", RUBY_METHOD_FUNC(siren_topalgo_infline), -1);
|
|
21
|
+
rb_define_method(sr_mSiren, "polyline", RUBY_METHOD_FUNC(siren_topalgo_polyline), -1);
|
|
22
|
+
rb_define_method(sr_mSiren, "interpolate", RUBY_METHOD_FUNC(siren_topalgo_interpolate), -1);
|
|
23
|
+
rb_define_method(sr_mSiren, "arc", RUBY_METHOD_FUNC(siren_topalgo_arc), -1);
|
|
24
|
+
rb_define_method(sr_mSiren, "arc3p", RUBY_METHOD_FUNC(siren_topalgo_arc3p), -1);
|
|
25
|
+
rb_define_method(sr_mSiren, "circle", RUBY_METHOD_FUNC(siren_topalgo_circle), -1);
|
|
26
|
+
rb_define_method(sr_mSiren, "circle3p", RUBY_METHOD_FUNC(siren_topalgo_circle3p), -1);
|
|
27
|
+
rb_define_method(sr_cShape, "cog", RUBY_METHOD_FUNC(siren_topalgo_cog), -1);
|
|
28
|
+
rb_define_method(sr_cShape, "area", RUBY_METHOD_FUNC(siren_topalgo_area), -1);
|
|
29
|
+
rb_define_method(sr_cShape, "volume", RUBY_METHOD_FUNC(siren_topalgo_volume), -1);
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
VALUE siren_topalgo_copy(int argc, VALUE* argv, VALUE self)
|
|
35
|
+
{
|
|
36
|
+
VALUE target;
|
|
37
|
+
VALUE copy_geom = Standard_True;
|
|
38
|
+
|
|
39
|
+
rb_scan_args(argc, argv, "11", &target, ©_geom);
|
|
40
|
+
|
|
41
|
+
TopoDS_Shape* src = siren_shape_get(target);
|
|
42
|
+
TopoDS_Shape res = BRepBuilderAPI_Copy(*src, (Standard_Boolean)copy_geom);
|
|
43
|
+
return siren_shape_new(res);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
VALUE siren_topalgo_line(int argc, VALUE* argv, VALUE self)
|
|
47
|
+
{
|
|
48
|
+
VALUE sp, tp;
|
|
49
|
+
rb_scan_args(argc, argv, "02", &sp, &tp);
|
|
50
|
+
gp_Pnt S(0., 0., 0.);
|
|
51
|
+
gp_Pnt T(1., 1., 1.);
|
|
52
|
+
if (argc > 0) {
|
|
53
|
+
S = siren_ary_to_pnt(sp);
|
|
54
|
+
}
|
|
55
|
+
if (argc > 1) {
|
|
56
|
+
T = siren_ary_to_pnt(tp);
|
|
57
|
+
}
|
|
58
|
+
Standard_Real linear_tolerance = 1.0e-7;
|
|
59
|
+
if (S.IsEqual(T, linear_tolerance)) {
|
|
60
|
+
rb_raise(Qnil,
|
|
61
|
+
"Specified terminal point same as the start point.");
|
|
62
|
+
}
|
|
63
|
+
TopoDS_Shape shape = BRepBuilderAPI_MakeEdge(S, T);
|
|
64
|
+
return siren_shape_new(shape);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
VALUE siren_topalgo_infline(int argc, VALUE* argv, VALUE self)
|
|
68
|
+
{
|
|
69
|
+
VALUE orig, dir;
|
|
70
|
+
rb_scan_args(argc, argv, "02", &orig, &dir);
|
|
71
|
+
gp_Pnt p(0., 0., 0.);
|
|
72
|
+
gp_Dir d(1., 0., 0.);
|
|
73
|
+
if (argc > 0) {
|
|
74
|
+
p = siren_ary_to_pnt(orig);
|
|
75
|
+
}
|
|
76
|
+
if (argc > 1) {
|
|
77
|
+
d = siren_ary_to_dir(dir);
|
|
78
|
+
}
|
|
79
|
+
TopoDS_Shape shape = BRepBuilderAPI_MakeEdge(gp_Lin(p, d));
|
|
80
|
+
return siren_shape_new(shape);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
VALUE siren_topalgo_polyline(int argc, VALUE* argv, VALUE self)
|
|
84
|
+
{
|
|
85
|
+
VALUE ary;
|
|
86
|
+
rb_scan_args(argc, argv, "1", &ary);
|
|
87
|
+
BRepBuilderAPI_MakePolygon poly;
|
|
88
|
+
for (int i = 0; i < RARRAY_LEN(ary); i++) {
|
|
89
|
+
poly.Add(siren_ary_to_pnt(RARRAY_AREF(ary, i)));
|
|
90
|
+
}
|
|
91
|
+
TopoDS_Shape shape = poly.Wire();
|
|
92
|
+
return siren_shape_new(shape);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
VALUE siren_topalgo_interpolate(int argc, VALUE* argv, VALUE self)
|
|
96
|
+
{
|
|
97
|
+
VALUE pts, vecs;
|
|
98
|
+
rb_scan_args(argc, argv, "11", &pts, &vecs);
|
|
99
|
+
|
|
100
|
+
int psize = RARRAY_LEN(pts);
|
|
101
|
+
opencascade::handle<TColgp_HArray1OfPnt> pary = new TColgp_HArray1OfPnt(1, psize);
|
|
102
|
+
for (int i=0; i<psize; i++) {
|
|
103
|
+
pary->SetValue(i+1, siren_ary_to_pnt(RARRAY_AREF(pts, i)));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
Standard_Real tolerance = 1.0e-7;
|
|
108
|
+
Standard_Boolean periodic_flag = Standard_False;
|
|
109
|
+
|
|
110
|
+
// Raise exception when got pary has same points.
|
|
111
|
+
GeomAPI_Interpolate intp(pary, periodic_flag, tolerance);
|
|
112
|
+
|
|
113
|
+
if (argc == 2) {
|
|
114
|
+
TColgp_Array1OfVec vec(1, psize);
|
|
115
|
+
opencascade::handle<TColStd_HArray1OfBoolean> use = new TColStd_HArray1OfBoolean(1, psize);
|
|
116
|
+
|
|
117
|
+
for (int i=0; i<psize; i++) {
|
|
118
|
+
VALUE avec = RARRAY_AREF(vecs, i);
|
|
119
|
+
if (NIL_P(avec)) {
|
|
120
|
+
use->SetValue(i+1, Standard_False);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
vec.SetValue(i+1, siren_ary_to_vec(avec));
|
|
124
|
+
use->SetValue(i+1, Standard_True);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
intp.Load(vec, use, Standard_True);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
intp.Perform();
|
|
131
|
+
if (!intp.IsDone()) {
|
|
132
|
+
rb_raise(Qnil, "Failed to make a curve.");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
opencascade::handle<Geom_BSplineCurve> geSpl = intp.Curve();
|
|
136
|
+
if (geSpl.IsNull()) {
|
|
137
|
+
rb_raise(Qnil, "Failed to make a curve.");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
TopoDS_Shape shape = BRepBuilderAPI_MakeEdge(geSpl);
|
|
141
|
+
return siren_shape_new(shape);
|
|
142
|
+
}
|
|
143
|
+
catch (...) {
|
|
144
|
+
rb_raise(Qnil, "Failed to make a curve. Incorrect points specified.");
|
|
145
|
+
}
|
|
146
|
+
return Qnil;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
VALUE siren_topalgo_arc(int argc, VALUE* argv, VALUE self)
|
|
150
|
+
{
|
|
151
|
+
VALUE orig, dir, vx;
|
|
152
|
+
VALUE r, start_ang, term_ang;
|
|
153
|
+
rb_scan_args(argc, argv, "6", &orig, &dir, &vx, &r, &start_ang, &term_ang);
|
|
154
|
+
gp_Circ circle = gp_Circ(gp_Ax2(siren_ary_to_pnt(orig), siren_ary_to_dir(dir), siren_ary_to_dir(vx)), NUM2DBL(r));
|
|
155
|
+
opencascade::handle<Geom_TrimmedCurve> gc = GC_MakeArcOfCircle(circle, NUM2DBL(start_ang), NUM2DBL(term_ang), Standard_True);
|
|
156
|
+
if (gc.IsNull()) {
|
|
157
|
+
rb_raise(Qnil, "Failed to make a curve.");
|
|
158
|
+
return Qnil;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gc);
|
|
162
|
+
return siren_shape_new(E);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
VALUE siren_topalgo_arc3p(int argc, VALUE* argv, VALUE self)
|
|
167
|
+
{
|
|
168
|
+
VALUE p1, p2, p3;
|
|
169
|
+
rb_scan_args(argc, argv, "3", &p1, &p2, &p3);
|
|
170
|
+
opencascade::handle<Geom_TrimmedCurve> gc = GC_MakeArcOfCircle(
|
|
171
|
+
siren_ary_to_pnt(p1),
|
|
172
|
+
siren_ary_to_pnt(p2),
|
|
173
|
+
siren_ary_to_pnt(p3));
|
|
174
|
+
if (gc.IsNull()) {
|
|
175
|
+
rb_raise(Qnil, "Failed to make a curve.");
|
|
176
|
+
return Qnil;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gc);
|
|
180
|
+
return siren_shape_new(E);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
VALUE siren_topalgo_circle(int argc, VALUE* argv, VALUE self)
|
|
185
|
+
{
|
|
186
|
+
VALUE orig, dir;
|
|
187
|
+
VALUE r;
|
|
188
|
+
rb_scan_args(argc, argv, "3", &orig, &dir, &r);
|
|
189
|
+
opencascade::handle<Geom_Circle> gc = GC_MakeCircle(
|
|
190
|
+
siren_ary_to_pnt(orig),
|
|
191
|
+
siren_ary_to_dir(dir),
|
|
192
|
+
NUM2DBL(r));
|
|
193
|
+
if (gc.IsNull()) {
|
|
194
|
+
rb_raise(Qnil, "Failed to make a curve.");
|
|
195
|
+
return Qnil;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gc);
|
|
199
|
+
return siren_shape_new(E);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
VALUE siren_topalgo_circle3p(int argc, VALUE* argv, VALUE self)
|
|
204
|
+
{
|
|
205
|
+
VALUE p1, p2, p3;
|
|
206
|
+
rb_scan_args(argc, argv, "3", &p1, &p2, &p3);
|
|
207
|
+
opencascade::handle<Geom_Circle> gc = GC_MakeCircle(
|
|
208
|
+
siren_ary_to_pnt(p1),
|
|
209
|
+
siren_ary_to_pnt(p2),
|
|
210
|
+
siren_ary_to_pnt(p3));
|
|
211
|
+
if (gc.IsNull()) {
|
|
212
|
+
rb_raise(Qnil, "Failed to make a curve.");
|
|
213
|
+
return Qnil;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gc);
|
|
217
|
+
return siren_shape_new(E);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
VALUE siren_topalgo_volume(int argc, VALUE* argv, VALUE self)
|
|
222
|
+
{
|
|
223
|
+
TopoDS_Shape* shape = siren_shape_get(self);
|
|
224
|
+
GProp_GProps gprops;
|
|
225
|
+
BRepGProp::VolumeProperties(*shape, gprops);
|
|
226
|
+
Standard_Real vol = gprops.Mass();
|
|
227
|
+
return DBL2NUM(vol);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
VALUE siren_topalgo_cog(int argc, VALUE* argv, VALUE self)
|
|
231
|
+
{
|
|
232
|
+
TopoDS_Shape* shape = siren_shape_get(self);
|
|
233
|
+
GProp_GProps gprops;
|
|
234
|
+
BRepGProp::VolumeProperties(*shape, gprops);
|
|
235
|
+
gp_Pnt cog = gprops.CentreOfMass();
|
|
236
|
+
return siren_pnt_to_ary(cog);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
VALUE siren_topalgo_area(int argc, VALUE* argv, VALUE self)
|
|
240
|
+
{
|
|
241
|
+
TopoDS_Shape* shape = siren_shape_get(self);
|
|
242
|
+
GProp_GProps gprops;
|
|
243
|
+
BRepGProp::SurfaceProperties(*shape, gprops);
|
|
244
|
+
Standard_Real area = gprops.Mass();
|
|
245
|
+
return DBL2NUM(area);
|
|
246
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
#include "trans.h"
|
|
2
|
+
|
|
3
|
+
VALUE sr_cTrans;
|
|
4
|
+
|
|
5
|
+
gp_Trsf* siren_trans_get(VALUE obj)
|
|
6
|
+
{
|
|
7
|
+
gp_Trsf* m;
|
|
8
|
+
Data_Get_Struct(obj, gp_Trsf, m);
|
|
9
|
+
return m;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static VALUE siren_trans_allocate(VALUE klass)
|
|
13
|
+
{
|
|
14
|
+
void* p = ruby_xmalloc(sizeof(gp_Trsf));
|
|
15
|
+
new(p) gp_Trsf();
|
|
16
|
+
return Data_Wrap_Struct(klass, NULL, siren_trans_final, p);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
VALUE siren_trans_new(const gp_Trsf& src)
|
|
20
|
+
{
|
|
21
|
+
VALUE t = siren_trans_allocate(sr_cTrans);
|
|
22
|
+
gp_Trsf* pt = siren_trans_get(t);
|
|
23
|
+
*pt = src;
|
|
24
|
+
return t;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
bool siren_trans_install()
|
|
28
|
+
{
|
|
29
|
+
sr_cTrans = rb_define_class_under(sr_mSiren, "Trans", rb_cObject);
|
|
30
|
+
rb_define_alloc_func(sr_cTrans, siren_trans_allocate);
|
|
31
|
+
rb_define_method(sr_cTrans, "initialize" , RUBY_METHOD_FUNC(siren_trans_init ), -1);
|
|
32
|
+
rb_define_method(sr_cTrans, "to_s" , RUBY_METHOD_FUNC(siren_trans_to_s ), -1);
|
|
33
|
+
rb_define_method(sr_cTrans, "to_a" , RUBY_METHOD_FUNC(siren_trans_matrix ), -1);
|
|
34
|
+
rb_define_method(sr_cTrans, "matrix" , RUBY_METHOD_FUNC(siren_trans_matrix ), -1);
|
|
35
|
+
rb_define_method(sr_cTrans, "matrix=" , RUBY_METHOD_FUNC(siren_trans_set_matrix ), -1);
|
|
36
|
+
rb_define_method(sr_cTrans, "multiply" , RUBY_METHOD_FUNC(siren_trans_multiply ), -1);
|
|
37
|
+
rb_define_method(sr_cTrans, "multiply!" , RUBY_METHOD_FUNC(siren_trans_multiply_bang ), -1);
|
|
38
|
+
rb_define_method(sr_cTrans, "power" , RUBY_METHOD_FUNC(siren_trans_power ), -1);
|
|
39
|
+
rb_define_method(sr_cTrans, "power!" , RUBY_METHOD_FUNC(siren_trans_power_bang ), -1);
|
|
40
|
+
rb_define_method(sr_cTrans, "translate!" , RUBY_METHOD_FUNC(siren_trans_translate_bang ), -1);
|
|
41
|
+
rb_define_method(sr_cTrans, "translatef" , RUBY_METHOD_FUNC(siren_trans_translatef ), -1);
|
|
42
|
+
rb_define_method(sr_cTrans, "translatef=" , RUBY_METHOD_FUNC(siren_trans_set_translatef ), -1);
|
|
43
|
+
rb_define_method(sr_cTrans, "mirror" , RUBY_METHOD_FUNC(siren_trans_mirror ), -1);
|
|
44
|
+
rb_define_method(sr_cTrans, "mirror!" , RUBY_METHOD_FUNC(siren_trans_mirror_bang ), -1);
|
|
45
|
+
rb_define_method(sr_cTrans, "rotate!" , RUBY_METHOD_FUNC(siren_trans_rotate_bang ), -1);
|
|
46
|
+
rb_define_method(sr_cTrans, "scale!" , RUBY_METHOD_FUNC(siren_trans_scale_bang ), -1);
|
|
47
|
+
rb_define_method(sr_cTrans, "scalef" , RUBY_METHOD_FUNC(siren_trans_scalef ), -1);
|
|
48
|
+
rb_define_method(sr_cTrans, "scalef=" , RUBY_METHOD_FUNC(siren_trans_set_scalef ), -1);
|
|
49
|
+
rb_define_method(sr_cTrans, "invert" , RUBY_METHOD_FUNC(siren_trans_invert ), -1);
|
|
50
|
+
rb_define_method(sr_cTrans, "invert!" , RUBY_METHOD_FUNC(siren_trans_invert_bang ), -1);
|
|
51
|
+
rb_define_method(sr_cTrans, "reverse" , RUBY_METHOD_FUNC(siren_trans_invert ), -1);
|
|
52
|
+
rb_define_method(sr_cTrans, "reverse!" , RUBY_METHOD_FUNC(siren_trans_invert_bang ), -1);
|
|
53
|
+
rb_define_method(sr_cTrans, "negative?" , RUBY_METHOD_FUNC(siren_trans_is_negative ), -1);
|
|
54
|
+
rb_define_method(sr_cTrans, "transform!" , RUBY_METHOD_FUNC(siren_trans_transform_bang ), -1);
|
|
55
|
+
rb_define_method(sr_cTrans, "move_point" , RUBY_METHOD_FUNC(siren_trans_move_point ), -1);
|
|
56
|
+
// rb_define_method(sr_cTrans, "rotatef" , siren_trans_rotatef , -1);
|
|
57
|
+
// rb_define_method(sr_cTrans, "rotatef=" , siren_trans_set_rotatef , -1);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
VALUE siren_trans_init(int argc, VALUE* argv, VALUE self)
|
|
62
|
+
{
|
|
63
|
+
return self;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void siren_trans_final(void* p)
|
|
67
|
+
{
|
|
68
|
+
gp_Trsf* t = static_cast<gp_Trsf*>(p);
|
|
69
|
+
ruby_xfree(t);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
VALUE siren_trans_to_s(int argc, VALUE* argv, VALUE self)
|
|
73
|
+
{
|
|
74
|
+
char str[256];
|
|
75
|
+
Standard_Real a11 = siren_trans_get(self)->Value(1, 1);
|
|
76
|
+
Standard_Real a12 = siren_trans_get(self)->Value(1, 2);
|
|
77
|
+
Standard_Real a13 = siren_trans_get(self)->Value(1, 3);
|
|
78
|
+
Standard_Real a14 = siren_trans_get(self)->Value(1, 4);
|
|
79
|
+
Standard_Real a21 = siren_trans_get(self)->Value(2, 1);
|
|
80
|
+
Standard_Real a22 = siren_trans_get(self)->Value(2, 2);
|
|
81
|
+
Standard_Real a23 = siren_trans_get(self)->Value(2, 3);
|
|
82
|
+
Standard_Real a24 = siren_trans_get(self)->Value(2, 4);
|
|
83
|
+
Standard_Real a31 = siren_trans_get(self)->Value(3, 1);
|
|
84
|
+
Standard_Real a32 = siren_trans_get(self)->Value(3, 2);
|
|
85
|
+
Standard_Real a33 = siren_trans_get(self)->Value(3, 3);
|
|
86
|
+
Standard_Real a34 = siren_trans_get(self)->Value(3, 4);
|
|
87
|
+
snprintf(str, sizeof(str),
|
|
88
|
+
"#<Trans:0x%x\n"
|
|
89
|
+
" X = % 2.6f, % 2.6f, % 2.6f\n"
|
|
90
|
+
" Y = % 2.6f, % 2.6f, % 2.6f\n"
|
|
91
|
+
" Z = % 2.6f, % 2.6f, % 2.6f\n"
|
|
92
|
+
" T = % 2.6f, % 2.6f, % 2.6f>",
|
|
93
|
+
-1, // (unsigned int)(uintptr_t)rb_cptr(self),
|
|
94
|
+
a11, a21, a31,
|
|
95
|
+
a12, a22, a32,
|
|
96
|
+
a13, a23, a33,
|
|
97
|
+
a14, a24, a34
|
|
98
|
+
);
|
|
99
|
+
return rb_str_new_cstr(str);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
VALUE siren_trans_translate_bang(int argc, VALUE* argv, VALUE self)
|
|
103
|
+
{
|
|
104
|
+
VALUE v;
|
|
105
|
+
rb_scan_args(argc, argv, "1", &v);
|
|
106
|
+
gp_Vec vec = siren_ary_to_vec(v);
|
|
107
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
108
|
+
trans->SetTranslation(vec);
|
|
109
|
+
return self;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
VALUE siren_trans_rotate_bang(int argc, VALUE* argv, VALUE self)
|
|
113
|
+
{
|
|
114
|
+
VALUE op, norm;
|
|
115
|
+
VALUE angle;
|
|
116
|
+
rb_scan_args(argc, argv, "3", &op, &norm, &angle);
|
|
117
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
118
|
+
trans->SetRotation(siren_ary_to_ax1(op, norm), angle);
|
|
119
|
+
return self;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
VALUE siren_trans_rotatef(int argc, VALUE* argv, VALUE self)
|
|
124
|
+
{
|
|
125
|
+
gp_XYZ axis;
|
|
126
|
+
Standard_Real angle;
|
|
127
|
+
if (siren_trans_get(self)->GetRotation(axis, angle) == Standard_False) {
|
|
128
|
+
return Qnil;
|
|
129
|
+
}
|
|
130
|
+
VALUE res[] = {
|
|
131
|
+
siren_pnt_new(axis.X(), axis.Y(), axis.Z()),
|
|
132
|
+
(angle)
|
|
133
|
+
};
|
|
134
|
+
return rb_ary_new_from_values(2, res);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
VALUE siren_trans_set_rotatef(int argc, VALUE* argv, VALUE self)
|
|
138
|
+
{
|
|
139
|
+
return Qnil;
|
|
140
|
+
}
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
VALUE siren_trans_scale_bang(int argc, VALUE* argv, VALUE self)
|
|
144
|
+
{
|
|
145
|
+
VALUE op;
|
|
146
|
+
VALUE factor;
|
|
147
|
+
rb_scan_args(argc, argv, "2", &op, &factor);
|
|
148
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
149
|
+
trans->SetScale(siren_ary_to_pnt(op), factor);
|
|
150
|
+
return self;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
VALUE siren_trans_scalef(int argc, VALUE* argv, VALUE self)
|
|
154
|
+
{
|
|
155
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
156
|
+
Standard_Real f = trans->ScaleFactor();
|
|
157
|
+
return (f);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
VALUE siren_trans_set_scalef(int argc, VALUE* argv, VALUE self)
|
|
161
|
+
{
|
|
162
|
+
VALUE f;
|
|
163
|
+
rb_scan_args(argc, argv, "1", &f);
|
|
164
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
165
|
+
trans->SetScaleFactor(f);
|
|
166
|
+
return (f);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
VALUE siren_trans_mirror(int argc, VALUE* argv, VALUE self)
|
|
170
|
+
{
|
|
171
|
+
VALUE op, norm, vx;
|
|
172
|
+
rb_scan_args(argc, argv, "12", &op, &norm, &vx);
|
|
173
|
+
auto res = siren_trans_new(*siren_trans_get(self));
|
|
174
|
+
auto p = siren_trans_get(res);
|
|
175
|
+
switch (argc) {
|
|
176
|
+
case 1:
|
|
177
|
+
p->SetMirror(siren_ary_to_pnt(op));
|
|
178
|
+
break;
|
|
179
|
+
case 2:
|
|
180
|
+
p->SetMirror(siren_ary_to_ax1(op, norm));
|
|
181
|
+
break;
|
|
182
|
+
case 3:
|
|
183
|
+
p->SetMirror(siren_ary_to_ax2(op, norm, vx));
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
return res;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
VALUE siren_trans_mirror_bang(int argc, VALUE* argv, VALUE self)
|
|
190
|
+
{
|
|
191
|
+
VALUE op, norm, vx;
|
|
192
|
+
rb_scan_args(argc, argv, "12", &op, &norm, &vx);
|
|
193
|
+
switch (argc) {
|
|
194
|
+
case 1:
|
|
195
|
+
siren_trans_get(self)->SetMirror(siren_ary_to_pnt(op));
|
|
196
|
+
break;
|
|
197
|
+
case 2:
|
|
198
|
+
siren_trans_get(self)->SetMirror(siren_ary_to_ax1(op, norm));
|
|
199
|
+
break;
|
|
200
|
+
case 3:
|
|
201
|
+
siren_trans_get(self)->SetMirror(siren_ary_to_ax2(op, norm, vx));
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
return self;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
VALUE siren_trans_multiply(int argc, VALUE* argv, VALUE self)
|
|
208
|
+
{
|
|
209
|
+
VALUE other;
|
|
210
|
+
rb_scan_args(argc, argv, "1", &other);
|
|
211
|
+
gp_Trsf* trans_me = siren_trans_get(self);
|
|
212
|
+
gp_Trsf* trans_other = siren_trans_get(other);
|
|
213
|
+
gp_Trsf t = trans_me->Multiplied(*trans_other);
|
|
214
|
+
return siren_trans_new(t);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
VALUE siren_trans_multiply_bang(int argc, VALUE* argv, VALUE self)
|
|
218
|
+
{
|
|
219
|
+
VALUE other;
|
|
220
|
+
rb_scan_args(argc, argv, "1", &other);
|
|
221
|
+
gp_Trsf* trans_me = siren_trans_get(self);
|
|
222
|
+
gp_Trsf* trans_other = siren_trans_get(other);
|
|
223
|
+
trans_me->Multiply(*trans_other);
|
|
224
|
+
return self;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
VALUE siren_trans_power(int argc, VALUE* argv, VALUE self)
|
|
228
|
+
{
|
|
229
|
+
VALUE n;
|
|
230
|
+
rb_scan_args(argc, argv, "1", &n);
|
|
231
|
+
return siren_trans_new(siren_trans_get(self)->Powered(n));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
VALUE siren_trans_power_bang(int argc, VALUE* argv, VALUE self)
|
|
235
|
+
{
|
|
236
|
+
VALUE n;
|
|
237
|
+
rb_scan_args(argc, argv, "1", &n);
|
|
238
|
+
siren_trans_get(self)->Power(n);
|
|
239
|
+
return self;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
VALUE siren_trans_invert(int argc, VALUE* argv, VALUE self)
|
|
243
|
+
{
|
|
244
|
+
return siren_trans_new(siren_trans_get(self)->Inverted());
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
VALUE siren_trans_invert_bang(int argc, VALUE* argv, VALUE self)
|
|
248
|
+
{
|
|
249
|
+
siren_trans_get(self)->Invert();
|
|
250
|
+
return self;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
VALUE siren_trans_is_negative(int argc, VALUE* argv, VALUE self)
|
|
254
|
+
{
|
|
255
|
+
return siren_trans_get(self)->IsNegative() ? Qtrue : Qfalse;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
VALUE siren_trans_transform_bang(int argc, VALUE* argv, VALUE self)
|
|
259
|
+
{
|
|
260
|
+
VALUE pos1, norm1, vdir1;
|
|
261
|
+
VALUE pos2, norm2, vdir2;
|
|
262
|
+
rb_scan_args(argc, argv, "33", &pos1, &norm1, &vdir1, &pos2, &norm2, &vdir2);
|
|
263
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
264
|
+
if (argc == 3) {
|
|
265
|
+
trans->SetTransformation(siren_ary_to_ax3(pos1, norm1, vdir1));
|
|
266
|
+
}
|
|
267
|
+
else if (argc == 6) {
|
|
268
|
+
trans->SetTransformation(siren_ary_to_ax3(pos1, norm1, vdir1), siren_ary_to_ax3(pos2, norm2, vdir2));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
rb_raise(Qnil, "Number of arguments is wrong.");
|
|
272
|
+
}
|
|
273
|
+
return self;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
VALUE siren_trans_matrix(int argc, VALUE* argv, VALUE self)
|
|
277
|
+
{
|
|
278
|
+
VALUE result[4];
|
|
279
|
+
for (int row = 1; row <= 4; row++) {
|
|
280
|
+
result[row - 1] = rb_ary_new();
|
|
281
|
+
for (int col = 1; col <= 3; col++) {
|
|
282
|
+
rb_ary_push(result[row - 1], DBL2NUM(siren_trans_get(self)->Value(col, row)));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return rb_ary_new_from_values(4, result);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
VALUE siren_trans_set_matrix(int argc, VALUE* argv, VALUE self)
|
|
289
|
+
{
|
|
290
|
+
VALUE ary;
|
|
291
|
+
rb_scan_args(argc, argv, "1", &ary);
|
|
292
|
+
if (RARRAY_LEN(ary) != 4) {
|
|
293
|
+
rb_raise(Qnil, "Number of items of specified array is wrong.");
|
|
294
|
+
}
|
|
295
|
+
gp_Vec x = siren_ary_to_vec(RARRAY_AREF(ary, 0));
|
|
296
|
+
gp_Vec y = siren_ary_to_vec(RARRAY_AREF(ary, 1));
|
|
297
|
+
gp_Vec z = siren_ary_to_vec(RARRAY_AREF(ary, 2));
|
|
298
|
+
gp_Vec t = siren_ary_to_vec(RARRAY_AREF(ary, 3));
|
|
299
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
300
|
+
trans->SetValues(
|
|
301
|
+
x.X(), y.X(), z.X(), t.X(),
|
|
302
|
+
x.Y(), y.Y(), z.Y(), t.Y(),
|
|
303
|
+
x.Z(), y.Z(), z.Z(), t.Z());
|
|
304
|
+
return self;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
VALUE siren_trans_translatef(int argc, VALUE* argv, VALUE self)
|
|
308
|
+
{
|
|
309
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
310
|
+
gp_XYZ xyz = trans->TranslationPart();
|
|
311
|
+
return siren_pnt_new(xyz.X(), xyz.Y(), xyz.Z());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
VALUE siren_trans_set_translatef(int argc, VALUE* argv, VALUE self)
|
|
315
|
+
{
|
|
316
|
+
VALUE v;
|
|
317
|
+
rb_scan_args(argc, argv, "1", &v);
|
|
318
|
+
siren_trans_get(self)->SetTranslationPart(siren_ary_to_vec(v));
|
|
319
|
+
return Qnil;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
VALUE siren_trans_move_point(int argc, VALUE* argv, VALUE self)
|
|
323
|
+
{
|
|
324
|
+
VALUE ary;
|
|
325
|
+
rb_scan_args(argc, argv, "1", &ary);
|
|
326
|
+
gp_Pnt point = siren_ary_to_pnt(ary);
|
|
327
|
+
gp_Trsf* trans = siren_trans_get(self);
|
|
328
|
+
point.Transform(*trans);
|
|
329
|
+
return siren_pnt_to_ary(point);
|
|
330
|
+
}
|