Search in sources :

Example 11 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class XviImporter method getSketch.

public static Sketch getSketch(File file) throws Exception {
    Sketch sketch = new Sketch();
    String contents = Loader.slurpFile(file);
    Grid grid = instance.parseGrid(contents);
    double scale = grid.dy;
    List<PathDetail> pathDetails = parseSketchlineBlock(scale, contents);
    sketch.setPathDetails(pathDetails);
    return sketch;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch)

Example 12 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class GraphView method drawSketch.

private void drawSketch(Canvas canvas, Sketch sketch, int alpha) {
    if (!getDisplayPreference(GraphActivity.DisplayPreference.SHOW_SKETCH)) {
        return;
    }
    Colour lastColour = Colour.BLACK;
    drawPaint.setColor(lastColour.intValue);
    drawPaint.setAlpha(alpha);
    boolean isDebugMode = activity.isDebugMode();
    for (PathDetail pathDetail : sketch.getPathDetails()) {
        if (!couldBeOnScreen(pathDetail)) {
            continue;
        }
        // are unordered collections
        if (pathDetail.getColour() != lastColour) {
            lastColour = pathDetail.getColour();
            drawPaint.setColor(lastColour.intValue);
        }
        List<Coord2D> path = pathDetail.getPath();
        int lineIndex = 0;
        float fromX = -1, fromY = -1;
        float[] lines = new float[path.size() * 4];
        // constructing many thousands of Coord2D objects (approx. 10% of sketch draw time)
        for (Coord2D point : path) {
            if (fromX == -1) {
                // from = surveyCoordsToViewCoords(point);
                fromX = (point.x - viewpointOffset.x) * surveyToViewScale;
                fromY = (point.y - viewpointOffset.y) * surveyToViewScale;
                if (isDebugMode) {
                    canvas.drawCircle(fromX, fromY, 3, drawPaint);
                }
            } else {
                // Coord2D to = surveyCoordsToViewCoords(point);
                float toX = (point.x - viewpointOffset.x) * surveyToViewScale;
                float toY = (point.y - viewpointOffset.y) * surveyToViewScale;
                lines[lineIndex++] = fromX;
                lines[lineIndex++] = fromY;
                lines[lineIndex++] = toX;
                lines[lineIndex++] = toY;
                if (isDebugMode) {
                    canvas.drawCircle(toX, toY, 3, drawPaint);
                }
                fromX = toX;
                fromY = toY;
            }
        }
        canvas.drawLines(lines, drawPaint);
    }
    labelPaint.setAlpha(alpha);
    for (TextDetail textDetail : sketch.getTextDetails()) {
        Coord2D location = surveyCoordsToViewCoords(textDetail.getPosition());
        float x = location.x, y = location.y;
        String text = textDetail.getText();
        labelPaint.setColor(textDetail.getColour().intValue);
        labelPaint.setTextSize(textDetail.getSize() * surveyToViewScale);
        for (String line : text.split("\n")) {
            canvas.drawText(line, x, y, labelPaint);
            y += labelPaint.descent() - labelPaint.ascent();
        }
    }
    for (SymbolDetail symbolDetail : sketch.getSymbolDetails()) {
        if (!couldBeOnScreen(symbolDetail)) {
            continue;
        }
        Coord2D location = surveyCoordsToViewCoords(symbolDetail.getPosition());
        Bitmap bitmap = symbolDetail.getSymbol().getBitmap();
        int size = (int) (symbolDetail.getSize() * surveyToViewScale);
        if (size == 0) {
            continue;
        }
        bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);
        float x = location.x, y = location.y;
        canvas.drawBitmap(bitmap, x, y, labelPaint);
    }
}
Also used : SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) Bitmap(android.graphics.Bitmap) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Colour(org.hwyl.sexytopo.model.sketch.Colour) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour)

Example 13 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class SketchJsonTranslater method toPathDetail.

public static PathDetail toPathDetail(JSONObject json) throws JSONException {
    Colour colour = Colour.valueOf(json.getString(COLOUR_TAG));
    JSONArray array = json.getJSONArray(POINTS_TAG);
    List<Coord2D> path = new ArrayList<>();
    for (JSONObject object : Util.toList(array)) {
        path.add(toCoord2D(object));
    }
    PathDetail pathDetail = new PathDetail(path, colour);
    float epsilon = Space2DUtils.simplificationEpsilon(pathDetail);
    List<Coord2D> simplifiedPath = Space2DUtils.simplify(path, epsilon);
    pathDetail.setPath(simplifiedPath);
    return pathDetail;
}
Also used : JSONObject(org.json.JSONObject) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Example 14 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class SketchJsonTranslater method toSketch.

public static Sketch toSketch(Survey survey, JSONObject json) {
    Sketch sketch = new Sketch();
    try {
        JSONArray pathsArray = json.getJSONArray(PATHS_TAG);
        List<PathDetail> pathDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(pathsArray)) {
            pathDetails.add(toPathDetail(object));
        }
        sketch.setPathDetails(pathDetails);
    } catch (JSONException e) {
        Log.e("Failed to load sketch paths: " + e);
    }
    try {
        JSONArray symbolsArray = json.getJSONArray(SYMBOLS_TAG);
        List<SymbolDetail> symbolDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(symbolsArray)) {
            symbolDetails.add(toSymbolDetail(object));
        }
        sketch.setSymbolDetails(symbolDetails);
    } catch (JSONException e) {
        Log.e("Failed to load symbols: " + e);
    }
    try {
        JSONArray labelsArray = json.getJSONArray(LABELS_TAG);
        List<TextDetail> textDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(labelsArray)) {
            textDetails.add(toTextDetail(object));
        }
        sketch.setTextDetails(textDetails);
    } catch (JSONException e) {
        Log.e("Failed to load sketch labels: " + e);
    }
    try {
        JSONArray crossSectionsArray = json.getJSONArray(CROSS_SECTIONS_TAG);
        List<CrossSectionDetail> crossSectionDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(crossSectionsArray)) {
            crossSectionDetails.add(toCrossSectionDetail(survey, object));
        }
        sketch.setCrossSectionDetails(crossSectionDetails);
    } catch (JSONException e) {
        Log.e("Failed to load cross-sections: " + e);
    }
    return sketch;
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) JSONException(org.json.JSONException) SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) JSONObject(org.json.JSONObject) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail)

Example 15 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail in project sexytopo by richsmith.

the class SketchJsonTranslater method toJson.

public static synchronized JSONObject toJson(Sketch sketch) throws JSONException {
    JSONObject json = new JSONObject();
    JSONArray pathDetailArray = new JSONArray();
    for (PathDetail pathDetail : sketch.getPathDetails()) {
        pathDetailArray.put(toJson(pathDetail));
    }
    json.put(PATHS_TAG, pathDetailArray);
    JSONArray textDetailArray = new JSONArray();
    for (TextDetail textDetail : sketch.getTextDetails()) {
        textDetailArray.put(toJson(textDetail));
    }
    json.put(LABELS_TAG, textDetailArray);
    JSONArray symbolDetailArray = new JSONArray();
    for (SymbolDetail symbolDetail : sketch.getSymbolDetails()) {
        symbolDetailArray.put(toJson(symbolDetail));
    }
    json.put(SYMBOLS_TAG, symbolDetailArray);
    JSONArray crossSectionDetailArray = new JSONArray();
    for (CrossSectionDetail crossSectionDetail : sketch.getCrossSectionDetails()) {
        crossSectionDetailArray.put(toJson(crossSectionDetail));
    }
    json.put(CROSS_SECTIONS_TAG, crossSectionDetailArray);
    return json;
}
Also used : SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) JSONObject(org.json.JSONObject) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) JSONArray(org.json.JSONArray) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail)

Aggregations

PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)19 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Colour (org.hwyl.sexytopo.model.sketch.Colour)5 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)5 SymbolDetail (org.hwyl.sexytopo.model.sketch.SymbolDetail)3 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 BrushColour (org.hwyl.sexytopo.model.sketch.BrushColour)2 CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 HashSet (java.util.HashSet)1 List (java.util.List)1 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)1 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)1 Space (org.hwyl.sexytopo.model.graph.Space)1