use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class UpperLefthandOpeningFeature method checkInternal.
@Override
public FeatureResult<Boolean> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
int lowerPoint = (int) ((double) shape.getHeight() * (2.0 / 3.0));
int upperPoint = shape.getHeight() / 8;
int openingThreshold = shape.getWidth() / 2;
int wallThreshold = shape.getWidth() / 4;
if (LOG.isTraceEnabled()) {
LOG.trace("lowerPoint: " + lowerPoint);
LOG.trace("upperPoint: " + upperPoint);
LOG.trace("openingThreshold: " + openingThreshold);
LOG.trace("wallThreshold: " + wallThreshold);
}
boolean foundWall = false;
boolean foundOpening = false;
boolean foundAnotherWall = false;
for (int y = lowerPoint; y >= upperPoint; y--) {
for (int x = 0; x <= openingThreshold; x++) {
if (!foundWall && x > wallThreshold) {
break;
} else if (!foundWall && shape.isPixelBlack(x, y, shape.getJochreImage().getBlackThreshold())) {
foundWall = true;
if (LOG.isTraceEnabled())
LOG.trace("foundWall y=" + y + ", x=" + x);
break;
} else if (foundWall && !foundOpening && shape.isPixelBlack(x, y, shape.getJochreImage().getBlackThreshold())) {
break;
} else if (foundWall && !foundOpening && x == openingThreshold) {
foundOpening = true;
if (LOG.isTraceEnabled())
LOG.trace("foundOpening y=" + y + ", x=" + x);
break;
} else if (foundOpening && !foundAnotherWall && x >= wallThreshold) {
break;
} else if (foundOpening && !foundAnotherWall && shape.isPixelBlack(x, y, shape.getJochreImage().getBlackThreshold())) {
foundAnotherWall = true;
if (LOG.isTraceEnabled())
LOG.trace("foundAnotherWall y=" + y + ", x=" + x);
break;
}
}
if (foundAnotherWall)
break;
}
FeatureResult<Boolean> outcome = this.generateResult(foundAnotherWall);
return outcome;
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class VerticalSizeFeature method checkInternal.
@Override
public FeatureResult<Double> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
double ratio = (double) shape.getHeight() / (double) (shape.getBaseLine() - shape.getMeanLine());
FeatureResult<Double> outcome = this.generateResult(ratio);
return outcome;
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class WidthFeature method checkInternal.
@Override
public FeatureResult<Double> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
double ratio = (double) shape.getWidth() / (double) (shape.getBaseLine() - shape.getMeanLine());
FeatureResult<Double> outcome = this.generateResult(ratio);
return outcome;
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class AbstractShapeFeature method putInCache.
@Override
protected void putInCache(ShapeWrapper shapeWrapper, FeatureResult<Y> featureResult, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
shape.putResultInCache(this, featureResult, env);
}
use of com.joliciel.jochre.graphics.Shape in project jochre by urieli.
the class BaselineDistanceFeature method checkInternal.
@Override
public FeatureResult<Double> checkInternal(ShapeWrapper shapeWrapper, RuntimeEnvironment env) {
Shape shape = shapeWrapper.getShape();
int lineHeight = shape.getBaseLine() - shape.getMeanLine();
int zeroPoint = (shape.getTop() + shape.getBaseLine());
int onePoint = (shape.getTop() + shape.getBaseLine()) + lineHeight;
double relativeBottom = 0;
if (shape.getBottom() <= zeroPoint)
relativeBottom = 0;
else if (shape.getBottom() >= onePoint)
relativeBottom = 1;
else {
relativeBottom = ((double) (shape.getBottom() - zeroPoint) / (onePoint - zeroPoint));
}
FeatureResult<Double> outcome = this.generateResult(relativeBottom);
return outcome;
}
Aggregations