// Case by case normalization
//Rescale all Z for Graffiti Analysis 2.0: DustTag
// Get BoundingBox
AABB boundingBox = gml.getBoundingBox();
LOGGER.log(Level.FINEST, "bounding box before scaling"+ boundingBox.getMin() + " " + boundingBox.getMax());
// Get bounding box min for later substraction
Vec3D originShift = boundingBox.getMin();
// Original aspect ratio of the tag
Vec3D originalAspectRatio = boundingBox.getExtent().scale(2);
// Used to scale the tag to a max of 1 on the longest axis
Vec3D scaling = originalAspectRatio.getReciprocal();
// Remap all points to fit within a min of 0, 0, 0 and a max of 1, 1, 1
List<GmlStroke> strokes = (List<GmlStroke>) gml.getStrokes();
for (GmlStroke stroke : strokes) {
List<GmlPoint> points = stroke.getPoints();
//for(GmlPoint point: points) {
//point.subSelf(originShift);
//point.scaleSelf(scaling);
// Fix NaN
//if (point.x != point.x) point.x = 0;
//if (point.y != point.y) point.y = 0;
//if (point.z != point.z) point.z = 0;
//}
for(int i=0; i<points.size(); i++) {
GmlPoint p = points.get(i);
p.subSelf(originShift);
p.scaleSelf(scaling);
// Fix NaN
if (p.x != p.x || p.y != p.y || p.z != p.z) {
points.remove(i);
}
else {
points.set(i, p);
}
}
stroke.replacePoints(points);
}
gml.replaceStrokes(strokes);
// Normalize z axis
// Get max z
boundingBox = gml.getBoundingBox();
LOGGER.log(Level.FINEST, "bounding box after rescale"+ boundingBox.getMin() + " " + boundingBox.getMax());
float maxZ = boundingBox.getMax().z;
if(maxZ > 1) {
LOGGER.log(Level.FINEST, "Z axis too long. Rescaling to fit 0-1");
// Else remap between 0 and 1
for (GmlStroke strok : gml.getStrokes()) {
float nPoints = strok.getPoints().size();
for (int i=0; i<nPoints; i++) {
strok.getPoints().get(i).z = strok.getPoints().get(i).z/maxZ;
}
}
}
boundingBox = gml.getBoundingBox();
LOGGER.log(Level.FINEST, "bounding box after z axis correction"+ boundingBox.getMin() + " " + boundingBox.getMax());
// Store the aspect ratio and origin for reverse scaling
// Any point can then be rescaled to original value by doing:
//(point.scaleSelf(originalAspectRatio).addSelf(originShift);