use of spacegraph.space2d.Surface in project narchy by automenta.
the class SpaceWidget method onTouch.
@Override
public Surface onTouch(Finger finger, Collidable body, ClosestRay hitPoint, short[] buttons, SpaceGraphPhys3D space) {
Surface s = super.onTouch(finger, body, hitPoint, buttons, space);
// if (s != null) {
// }
touched = true;
return s;
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class Cuboid method onTouch.
@Override
public Surface onTouch(Finger finger, Collidable body, ClosestRay r, short[] buttons, SpaceGraphPhys3D space) {
if (body != null) {
// rotate to match camera's orientation (billboarding)
Object d = body.data();
if (d instanceof SimpleSpatial) {
SimpleSpatial sd = (SimpleSpatial) d;
// Quat4f target = Quat4f.angle(-space.camFwd.x, -space.camFwd.y, -space.camFwd.z, 0);
// Quat4f target = new Quat4f();
// sd.rotate( -space.camFwd.x, -space.camFwd.y, -space.camFwd.z, 0, 0.2f);
// com.jogamp.common.util.SyncedRingbuffer
// Transform bt = body.worldTransform;
// // TODO somehow use the object's local transformation ? sd.transform().getRotation(...);
// target.setAngle(
// space.camFwd.x-bt.x,
// space.camFwd.y - bt.y,
// space.camFwd.z -bt.z,
// (float) Math.PI
// );
//
// target.normalize();
//
// sd.rotate(target, 0.2f); //new Quat4f());
// //System.out.println(" : " + sd.transform().getRotation(new Quat4f()));
}
//
Surface s0 = super.onTouch(finger, body, r, buttons, space);
if (s0 != null)
return s0;
}
if (front != null) {
Transform it = Transform.t(transform).inverse();
v3 localPoint = it.transform(v(r.hitPointWorld));
if (body != null && body.shape() instanceof SimpleBoxShape) {
SimpleBoxShape shape = (SimpleBoxShape) body.shape();
float frontZ = shape.z() / 2;
float zTolerance = frontZ / 4f;
if (Util.equals(localPoint.z, frontZ, zTolerance)) {
// top surface only, ignore sides and back
this.mousePick = r.hitPointWorld;
fingered = finger;
return fingered.on(front, localPoint.x / shape.x() + 0.5f, localPoint.y / shape.y() + 0.5f, buttons);
// return mouseFront.update(null, localPoint.x, localPoint.y, buttons);
}
} else {
if (fingered != null && fingered.off()) {
fingered = null;
}
}
}
return null;
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class TsneTest method test1.
@Disabled
@Test
public void test1() {
// double[][] data = new double[][]{
// {-21.30234718322754, 0.48, -16.0, 1.0, 1.0, 0.0, -912.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, -64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {21.30234718322754, 0.48, 16.0, 1.0, 1.0, 0.0, 912.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, 64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {21.30234718322754, 0.49, 16.0, 1.0, 1.0, 0.0, 812.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, 64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {21.30234718322754, 0.5, 16.0, 1.0, 1.0, 0.0, 712.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, 64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {21.30234718322754, 0.48, 16.0, 1.0, 1.0, 0.0, 512.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, 64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {21.30234718322754, 0.49, 16.0, 1.0, 1.0, 0.0, 512.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, 64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {21.30234718322754, 0.5, 16.0, 1.0, 1.0, 0.0, 512.0, 0.5, 2.0, 2.0, 15.0, 42.0, 30.0, 10.0, 28.0, 0.5, 0.20412415266036987, 0.0, 64.0, 64.0, 0.004999999888241291, 0.0, 0.5, 0.5, 0.5, 0.5, 0.8999999761581421, 0.8999999761581421, 0.0, 0.0},
// {20.95846176147461, 0.4808186888694763, 22.0, 0.38132792711257935, 1.0, 0.0, 471.0, 0.43011003732681274, 4.0, 0.0, 18.0, 47.0, 51.0, 17.0, 17.0, 0.595743715763092, 0.22977818548679352, 0.3948138356208801, 64.0, 69.0, 0.26262563467025757, 0.0, 1.0, 0.4571904242038727, 0.7489378452301025, 0.3581550717353821, 0.7983626127243042, 0.9577770829200745, -0.15979236364364624, -0.05524653196334839},
// {21.331466674804688, 0.5, 13.0, 1.7480535507202148, 0.0, 0.0, 371.0, 1.947072148323059, 2.0, 3.0, 0.0, 47.0, 43.0, 16.0, 48.0, 0.60486900806427, 0.15891163051128387, 2.2695131301879883, 57.0, 80.0, 0.1700606346130371, 0.0, 0.47173094749450684, 0.24554623663425446, 0.5809586644172668, 1.0, 0.9306663870811462, 0.9950000047683716, -0.4445379078388214, -0.18973657488822937},
// {20.75196647644043, 0.5, 17.0, 0.6735842227935791, 0.0, 0.0, 730.0, 0.0, 2.0, 4.0, 31.0, 45.0, 23.0, 16.0, 26.0, 0.41474899649620056, 0.06916480511426926, 1.0010837316513062, 73.0, 62.0, 0.2565132677555084, 0.10401569306850433, 0.5961753129959106, 0.24852895736694336, 0.2871387004852295, 0.533154308795929, 0.9908100366592407, 0.7967885732650757, 0.13373760879039764, -0.2136838138103485},
// {20.99671173095703, 0.5, 18.0, 0.27828070521354675, 0.0, 0.0, 522.0, 5.928876876831055, 5.0, 0.0, 12.0, 55.0, 35.0, 7.0, 22.0, 0.4373595714569092, 0.011883316561579704, 0.0, 76.0, 96.0, 0.12904536724090576, 0.05639180168509483, 0.5879765748977661, 0.5081198215484619, 0.16028539836406708, 0.4688444435596466, 0.8602891564369202, 0.8782417178153992, 0.2320031225681305, 0.2398255616426468},
// {21.354524612426758, 0.35868242383003235, 22.0, 1.027350664138794, 0.0, 0.0, 128.0, 0.0, 1.0, 0.0, 24.0, 12.0, 14.0, 0.0, 31.0, 0.26928645372390747, 0.11535469442605972, 0.0, 90.0, 35.0, 0.14928138256072998, 0.4440792202949524, 0.444633424282074, 0.42132723331451416, 0.9632992148399353, 0.7085565328598022, 0.9950000047683716, 0.9950000047683716, 0.340460866689682, -0.0960044264793396},
// {17.393003463745117, 0.5, 18.0, 0.9550491571426392, 0.0, 0.0, 422.0, 2.0188231468200684, 12.0, 18.0, 32.0, 42.0, 26.0, 8.0, 39.0, 0.27758824825286865, 0.3836873471736908, 0.0, 83.0, 91.0, 0.004999999888241291, 0.0, 0.7157235741615295, 0.4657387137413025, 0.5226057767868042, 0.433219850063324, 0.8557721376419067, 0.7977447509765625, -0.2824641168117523, -0.06786750257015228},
// {21.325220108032227, 0.38710877299308777, 16.0, 0.3573422431945801, 0.0, 0.0, 352.0, 0.0, 4.0, 0.0, 5.0, 50.0, 32.0, 15.0, 34.0, 0.4063739478588104, 0.2373967319726944, 0.0, 10.0, 59.0, 0.14747190475463867, 0.4210653603076935, 0.30484676361083984, 0.13044172525405884, 0.035849615931510925, 0.7536658644676208, 0.8851500153541565, 0.9950000047683716, 0.2435918152332306, 0.03520814701914787},
// {21.11952018737793, 0.4024233818054199, 5.0, 1.4047718048095703, 0.0, 0.0, 260.0, 0.0, 0.0, 14.0, 0.0, 59.0, 38.0, 0.0, 12.0, 0.6892735362052917, 0.0, 0.0, 92.0, 104.0, 0.004999999888241291, 0.08096777647733688, 0.3692743480205536, 0.539433479309082, 0.3484911620616913, 0.204197958111763, 0.7651103734970093, 0.9950000047683716, -0.4875887632369995, -0.3541417419910431},
// {21.047746658325195, 0.42637497186660767, 19.0, 0.23525908589363098, 0.0, 0.0, 755.0, 1.892948031425476, 0.0, 15.0, 0.0, 41.0, 42.0, 16.0, 29.0, 0.6284916996955872, 0.026182837784290314, 0.0, 37.0, 48.0, 0.004999999888241291, 0.010293583385646343, 0.3633580505847931, 0.462786465883255, 0.7083271145820618, 0.5576268434524536, 0.9950000047683716, 0.9950000047683716, 0.19580957293510437, 0.1489206701517105},
// {18.66234588623047, 0.42469656467437744, 1.0, 0.8662810921669006, 0.0, 1.0, 489.0, 1.4751911163330078, 2.0, 29.0, 20.0, 46.0, 35.0, 26.0, 29.0, 0.28958332538604736, 0.36895209550857544, 0.0, 72.0, 50.0, 0.004999999888241291, 0.01774885132908821, 0.5444626212120056, 0.3307981789112091, 0.6434126496315002, 0.5588428378105164, 0.8543636798858643, 0.8011282086372375, -0.1126488670706749, -0.0884719043970108},
// {21.1657772064209, 0.5, 22.0, 0.4553397595882416, 1.0, 0.0, 340.0, 0.0, 0.0, 11.0, 3.0, 34.0, 15.0, 23.0, 15.0, 0.3557361960411072, 0.0, 0.7408908009529114, 38.0, 71.0, 0.004999999888241291, 0.36444559693336487, 0.13318665325641632, 0.449336439371109, 0.7942307591438293, 0.38276150822639465, 0.6336342096328735, 0.9950000047683716, -0.20416949689388275, -0.6312856078147888},
// {20.192710876464844, 0.41596096754074097, 20.0, 1.1024030447006226, 0.0, 0.0, 444.0, 0.36758625507354736, 0.0, 16.0, 39.0, 26.0, 27.0, 12.0, 24.0, 0.3936900794506073, 0.16099324822425842, 0.7797319293022156, 99.0, 91.0, 0.004999999888241291, 0.15895120799541473, 0.38645583391189575, 0.9601192474365234, 0.5533197522163391, 0.4685037136077881, 0.7505260705947876, 0.9136349558830261, 0.09462402760982513, 0.18027643859386444},
// {21.56418800354004, 0.5, 12.0, 1.00830078125, 0.0, 0.0, 646.0, 1.2616074085235596, 0.0, 6.0, 30.0, 50.0, 38.0, 12.0, 0.0, 0.4270869493484497, 0.33934077620506287, 0.0, 65.0, 53.0, 0.004999999888241291, 0.0, 0.4538559317588806, 0.5412663817405701, 0.6233492493629456, 0.3307473361492157, 0.9950000047683716, 0.5428341627120972, -0.30709201097488403, -0.06266357749700546},
// };
int DIM = 4;
int N = 128;
double[][] data = new double[N][DIM];
int j = 0;
for (int i = 0; i < N / 2; i++) {
data[j++] = new double[] { 0, 0, 1 + Math.random() / 2f, 1 + Math.random() / 2f };
}
for (int i = 0; i < N / 2; i++) {
data[j++] = new double[] { 1, 0, -1 + Math.random() / 2f, -1 + Math.random() / 2f };
}
SimpleTSne t = new SimpleTSne() {
Surface plot = new Surface() {
@Override
protected void paint(GL2 gl, int dtMS) {
Draw.bounds(gl, bounds, this::paint);
}
protected void paint(GL2 gl) {
double[][] vv = Y;
if (vv == null)
return;
vv = vv.clone();
// for (int i = 0, yLength = vv.length; i < yLength; i++) {
//
// }
float scale = 0.1f;
float w, h;
w = h = 1f / vv.length;
for (int i = 0, yLength = vv.length; i < yLength; i++) {
double[] v = vv[i];
float x = (float) (v[0]);
float y = (float) (((v.length > 1) ? v[1] : 0));
x *= scale;
y *= scale;
Draw.colorHash(gl, i, 0.75f);
Draw.rect(gl, x, y, w, h);
}
}
};
{
SpaceGraph.window(plot, 800, 800);
}
@Override
protected void next(int iter) {
super.next(iter);
Util.sleep(50);
}
};
double[][] y = t.tsne(new TSneConfig(data, 2, -1, 5f, 1000, false, 0.5, false, true));
System.out.println(MatrixOps.doubleArrayToPrintString(y));
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class NAgentX method chart.
public static void chart(NAgent a) {
NAR nar = a.nar();
nar.runLater(() -> {
SpaceGraph.window(grid(new AutoSurface(a), Vis.beliefCharts(nar.dur() * 64, a.actions.keySet(), a.nar()), new EmotionPlot(64, a), grid(// concept query box
new TextEdit() {
@Override
protected void onKeyEnter() {
String s = text();
text("");
try {
nar.conceptualize(s);
} catch (Narsese.NarseseException e) {
e.printStackTrace();
}
Vis.conceptWindow(s, nar);
}
}.surface(), // new WindowButton("log", () -> Vis.logConsole(nar, 80, 25, new FloatParam(0f))),
new PushButton("dump", () -> {
try {
nar.output(Files.createTempFile(a.toString(), "" + System.currentTimeMillis()).toFile(), false);
} catch (IOException e) {
e.printStackTrace();
}
}), new PushButton("clear", () -> {
nar.runLater(NAR::clear);
}), new PushButton("prune", () -> {
nar.runLater(() -> {
DoubleHistogram i = new DoubleHistogram(2);
nar.tasks(true, false, false, false).forEach(t -> i.recordValue(t.conf()));
float confThresh = (float) i.getValueAtPercentile(25);
nar.tasks(true, false, false, false).filter(t -> t.conf() < confThresh).forEach(Task::delete);
});
}), new WindowToggleButton("top", () -> new ConsoleTerminal(new nars.TextUI(nar).session(10f))), new WindowToggleButton("concept graph", () -> {
DynamicConceptSpace sg;
SpaceGraphPhys3D s = new SpaceGraphPhys3D<>(sg = new DynamicConceptSpace(nar, () -> nar.exe.active().iterator(), 128, 16));
EdgeDirected fd = new EdgeDirected();
s.dyn.addBroadConstraint(fd);
fd.attraction.set(fd.attraction.get() * 8);
s.add(new SubOrtho(// window(
grid(new AutoSurface<>(fd), new AutoSurface<>(sg.vis))) {
}.posWindow(0, 0, 1f, 0.2f));
// , 400, 400);
// .pos(0, 0, 0.5f, 0.5f)
s.camPos(0, 0, 90);
return s;
}), a instanceof NAgentX ? new WindowToggleButton("vision", () -> grid(((NAgentX) a).sensorCam.stream().map(cs -> new AspectAlign(new CameraSensorView(cs, a).withControls(), AspectAlign.Align.Center, cs.width, cs.height)).toArray(Surface[]::new))) : grid())), //
900, 600);
});
}
use of spacegraph.space2d.Surface in project narchy by automenta.
the class Gridding method layoutGrid.
private void layoutGrid(Surface[] children, int nx, int ny, float margin) {
int i = 0;
float hm = margin / 2f;
float mx = (1 + 1 + nx / 2f) * hm;
float my = (1 + 1 + ny / 2f) * hm;
float dx = nx > 0 ? (1f - hm) / nx : 0;
float dxc = (1f - mx) / nx;
float dy = ny > 0 ? (1f - hm) / ny : 0;
float dyc = (1f - my) / ny;
int n = children.length;
float X = x();
float Y = y();
float W = w();
float H = h();
for (int y = 0; y < ny; y++) {
// margin / 2f;
float px = hm;
final float py = (((ny - 1) - y) * dy) + hm;
float y1 = py * H;
for (int x = 0; x < nx; x++) {
// System.out.println("\t" + px + " " + py);
Surface c = children[i++];
float x1 = px * W;
c.pos(X + x1, Y + y1, X + x1 + dxc * W, Y + y1 + dyc * H);
c.layout();
px += dx;
if (i >= n)
break;
}
if (i >= n)
break;
}
}
Aggregations