use of javax.vecmath.Matrix4d in project chordatlas by twak.
the class Tweed method addGML.
public void addGML(File gmlFile, String guessCRS) throws Exception {
double[] lastOffset = new double[] { Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY };
if (guessCRS == null)
guessCRS = Files.readLines(gmlFile, Charset.forName("UTF-8"), new LineProcessor<String>() {
String crs;
@Override
public boolean processLine(String line) throws IOException {
Matcher m = SRS_EX.matcher(line);
if (m.matches()) {
crs = m.group(1);
return false;
}
m = OFFSET_EX.matcher(line);
if (m.matches() && lastOffset[0] == Double.POSITIVE_INFINITY) {
// bounds def before we see a CRS...
lastOffset[0] = Double.parseDouble(m.group(1));
lastOffset[1] = Double.parseDouble(m.group(2));
}
return true;
}
@Override
public String getResult() {
return crs;
}
});
if (guessCRS == null || lastOffset[0] == Double.POSITIVE_INFINITY) {
JOptionPane.showMessageDialog(frame.frame, "Failed to guess coordinate system for " + gmlFile.getName());
return;
}
// if (TweedSettings.settings.trans != null) {
// lastOffset[0] = TweedSettings.settings.trans[0];
// lastOffset[1] = TweedSettings.settings.trans[1];
// }
// else
TweedSettings.settings.trans = lastOffset;
TweedSettings.settings.gmlCoordSystem = guessCRS;
System.out.println("Assuming CRS " + guessCRS + " for all of " + gmlFile.getName());
MathTransform transform = CRS.findMathTransform(CRS.decode(guessCRS), DefaultGeocentricCRS.CARTESIAN, true);
System.out.println("Using CRS --> World space offset of " + lastOffset[0] + ", " + lastOffset[1]);
TweedSettings.settings.toOrigin = buildOrigin(lastOffset[0], lastOffset[1], transform);
TweedSettings.settings.fromOrigin = new Matrix4d(TweedSettings.settings.toOrigin);
TweedSettings.settings.fromOrigin.invert();
frame.addGen(new GISGen(makeWorkspaceRelative(gmlFile).toString(), TweedSettings.settings.toOrigin, guessCRS, this), true);
}
use of javax.vecmath.Matrix4d in project chordatlas by twak.
the class TweedSettings method resetTrans.
public void resetTrans() {
this.trans = new double[] { 0, 0 };
this.gmlCoordSystem = null;
this.toOrigin = new Matrix4d();
this.toOrigin.setIdentity();
this.fromOrigin = new Matrix4d();
this.fromOrigin.setIdentity();
}
use of javax.vecmath.Matrix4d in project ffx by mjschnie.
the class MouseOrbit method processStimulus.
/**
* {@inheritDoc}
*/
public void processStimulus(Enumeration criteria) {
WakeupCriterion wakeup;
AWTEvent[] event;
int id;
int dx, dy;
while (criteria.hasMoreElements()) {
wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent) {
event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
for (int i = 0; i < event.length; i++) {
processMouseEvent((MouseEvent) event[i]);
if (((buttonPress) && ((flags & MANUAL_WAKEUP) == 0)) || ((wakeUp) && ((flags & MANUAL_WAKEUP) != 0))) {
id = event[i].getID();
if ((id == MouseEvent.MOUSE_DRAGGED)) {
x = ((MouseEvent) event[i]).getX();
y = ((MouseEvent) event[i]).getY();
dx = x - x_last;
dy = y - y_last;
if (!reset) {
Transform3D tempT3D = new Transform3D();
Transform3D orbitT3D = new Transform3D();
tempT3D.rotX(-dy * y_factor);
orbitT3D.mul(tempT3D);
tempT3D.rotY(-dx * x_factor);
orbitT3D.mul(tempT3D);
Transform3D tg_ghost_T3D = new Transform3D();
tg_ghost.getTransform(tg_ghost_T3D);
Vector3f tg_ghost_vec3f = new Vector3f();
tg_ghost_T3D.get(tg_ghost_vec3f);
Matrix4d tg_ghost_mat4d = new Matrix4d();
tg_ghost_T3D.get(tg_ghost_mat4d);
Transform3D VPTG_ghost_T3D_inverted = new Transform3D();
Transform3D VPTG_ghost_T3D_noninverted = new Transform3D();
// (super.ViewerTG).getTransform(VPTG_ghost_T3D_inverted);
ViewerTG.getTransform(VPTG_ghost_T3D_inverted);
// (super.ViewerTG).getTransform(VPTG_ghost_T3D_noninverted);
ViewerTG.getTransform(VPTG_ghost_T3D_noninverted);
VPTG_ghost_T3D_inverted.setTranslation(new Vector3d(0.0, 0.0, 0.0));
VPTG_ghost_T3D_noninverted.setTranslation(new Vector3d(0.0, 0.0, 0.0));
VPTG_ghost_T3D_inverted.invert();
tg_ghost_T3D.mul(VPTG_ghost_T3D_inverted, tg_ghost_T3D);
tg_ghost_T3D.setTranslation(new Vector3d(0.0, 0.0, 0.0));
if (invert) {
tg_ghost_T3D.mul(tg_ghost_T3D, orbitT3D);
} else {
tg_ghost_T3D.mul(orbitT3D, tg_ghost_T3D);
}
tg_ghost_T3D.mul(VPTG_ghost_T3D_noninverted, tg_ghost_T3D);
tg_ghost_T3D.setTranslation(tg_ghost_vec3f);
tg_ghost.setTransform(tg_ghost_T3D);
VPTG_ghost_T3D = new Transform3D();
// (super.ViewerTG).getTransform(VPTG_ghost_T3D);
ViewerTG.getTransform(VPTG_ghost_T3D);
Vector3f VPTG_ghost_vec3f = new Vector3f();
VPTG_ghost_T3D.get(VPTG_ghost_vec3f);
Vector3f temp_vec3f = new Vector3f();
temp_vec3f.x = VPTG_ghost_vec3f.x - tg_ghost_vec3f.x;
temp_vec3f.y = VPTG_ghost_vec3f.y - tg_ghost_vec3f.y;
temp_vec3f.z = VPTG_ghost_vec3f.z - tg_ghost_vec3f.z;
VPTG_ghost_T3D.setTranslation(temp_vec3f);
VPTG_ghost_T3D.mul(VPTG_ghost_T3D_inverted, VPTG_ghost_T3D);
if (invert) {
VPTG_ghost_T3D.mul(VPTG_ghost_T3D, orbitT3D);
} else {
VPTG_ghost_T3D.mul(orbitT3D, VPTG_ghost_T3D);
}
VPTG_ghost_T3D.mul(VPTG_ghost_T3D_noninverted, VPTG_ghost_T3D);
VPTG_ghost_T3D.get(temp_vec3f);
temp_vec3f.x = temp_vec3f.x + tg_ghost_vec3f.x;
temp_vec3f.y = temp_vec3f.y + tg_ghost_vec3f.y;
temp_vec3f.z = temp_vec3f.z + tg_ghost_vec3f.z;
VPTG_ghost_T3D.setTranslation(temp_vec3f);
// (super.ViewerTG).setTransform(VPTG_ghost_T3D);
ViewerTG.setTransform(VPTG_ghost_T3D);
transformChanged(currXform);
if (callback != null) {
callback.transformChanged(MouseBehaviorCallback.ORBIT, currXform);
}
} else {
reset = false;
}
x_last = x;
y_last = y;
} else if (id == MouseEvent.MOUSE_PRESSED) {
x_last = ((MouseEvent) event[i]).getX();
y_last = ((MouseEvent) event[i]).getY();
}
}
}
}
}
wakeupOn(mouseCriterion);
}
Aggregations