Search in sources :

Example 1 with PCPoint

use of org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint in project JWildfire by thargor6.

the class FlameRenderer method renderPointCloud.

public void renderPointCloud(PointCloudRenderInfo pPointCloudRenderInfo, String pFilename) {
    if (!flame.isRenderable())
        throw new RuntimeException("Point clouds can not be created of empty flames");
    renderInfo = pPointCloudRenderInfo.createRenderInfo();
    progressDisplayPhaseCount = 1;
    progressDisplayPhase = 0;
    double zmin = pPointCloudRenderInfo.getZmin() < pPointCloudRenderInfo.getZmax() ? pPointCloudRenderInfo.getZmin() : pPointCloudRenderInfo.getZmax();
    double zmax = pPointCloudRenderInfo.getZmin() < pPointCloudRenderInfo.getZmax() ? pPointCloudRenderInfo.getZmax() : pPointCloudRenderInfo.getZmin();
    Flame currFlame = flame.makeCopy();
    prepareFlameForPointCloudRendering(currFlame);
    initRasterSizes(pPointCloudRenderInfo.getImageWidth(), pPointCloudRenderInfo.getImageHeight());
    RasterPointCloud pcraster = new RasterPointCloud(zmin, zmax, pPointCloudRenderInfo.getMaxOctreeCellSize());
    raster = pcraster;
    raster.allocRaster(flame, rasterWidth, rasterHeight, flame.getSpatialOversampling(), flame.getSampleDensity());
    List<List<RenderPacket>> renderFlames = new ArrayList<List<RenderPacket>>();
    for (int t = 0; t < prefs.getTinaRenderThreads(); t++) {
        renderFlames.add(createRenderPackets(flame, flame.getFrame()));
    }
    iterate(0, 1, renderFlames, null);
    raster.finalizeRaster();
    List<PCPoint> points = pcraster.getGeneratedPoints();
    if (points != null && !points.isEmpty()) {
        if (Tools.getFileExt(pFilename).isEmpty()) {
            pFilename = pFilename + "." + Tools.FILEEXT_PLY;
        }
        if (Tools.FILEEXT_PLY.equalsIgnoreCase(Tools.getFileExt(pFilename))) {
            new PointCloudPLYWriter().writePLY(points, pFilename);
        } else if (Tools.FILEEXT_OBJ.equalsIgnoreCase(Tools.getFileExt(pFilename))) {
            new PointCloudOBJWriter().writeOBJ(points, pFilename);
        } else {
            throw new RuntimeException("Unvalid file extension <" + Tools.getFileExt(pFilename) + ">");
        }
    }
}
Also used : PointCloudPLYWriter(org.jwildfire.create.tina.base.raster.PointCloudPLYWriter) ArrayList(java.util.ArrayList) RasterPointCloud(org.jwildfire.create.tina.base.raster.RasterPointCloud) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) ArrayList(java.util.ArrayList) List(java.util.List) Flame(org.jwildfire.create.tina.base.Flame) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) PointCloudOBJWriter(org.jwildfire.create.tina.base.raster.PointCloudOBJWriter)

Example 2 with PCPoint

use of org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint in project JWildfire by thargor6.

the class PointCloudPLYWriter method writePLY.

public void writePLY(List<PCPoint> pPoints, String pFilename) {
    StringBuilder sb = new StringBuilder();
    sb.append("ply\r\n" + "format ascii 1.0\r\n" + "comment " + Tools.APP_TITLE + " generated\r\n" + "element vertex " + pPoints.size() + "\r\n" + "property float x\r\n" + "property float y\r\n" + "property float z\r\n" + "property uchar red\r\n" + "property uchar green\r\n" + "property uchar blue\r\n" + "property uchar alpha\r\n" + "element face 0\r\n" + "property list uchar int vertex_indices\r\n" + "end_header\r\n");
    for (PCPoint p : pPoints) {
        sb.append(p.x + " " + p.y + " " + p.z + " " + Tools.roundColor(p.r) + " " + Tools.roundColor(p.g) + " " + Tools.roundColor(p.b) + " " + Tools.roundColor(p.intensity * 255.0) + "\r\n");
    }
    try {
        Tools.writeUTF8Textfile(pFilename, sb.toString());
    } catch (Exception ex) {
        Unchecker.rethrow(ex);
    }
}
Also used : PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)

Example 3 with PCPoint

use of org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint in project JWildfire by thargor6.

the class PointCloudOBJWriter method writeOBJ.

public void writeOBJ(List<PCPoint> pPoints, String pFilename) {
    StringBuilder sb = new StringBuilder();
    sb.append("####\r\n" + "#\r\n" + "# OBJ File Generated by " + Tools.APP_TITLE + "\r\n" + "#\r\n" + "####\r\n" + "# Object testc.obj\r\n" + "#\r\n" + "# Vertices: " + pPoints.size() + "\r\n" + "# Faces: " + (with1PointPolyGons ? pPoints.size() : 0) + "\r\n" + "#\r\n" + "####\r\n");
    for (PCPoint p : pPoints) {
        sb.append("v " + p.x + " " + p.y + " " + p.z + " " + p.r / 255.0 + " " + p.g / 255.0 + " " + p.b / 255.0 + "\r\n");
    }
    sb.append("# " + pPoints.size() + " vertices, 0 vertices normals\r\n");
    if (with1PointPolyGons) {
        for (int i = 0; i < pPoints.size(); i++) {
            sb.append("f " + (i + 1) + "\r\n");
        }
    }
    sb.append("# " + (with1PointPolyGons ? pPoints.size() : 0) + " faces, 0 coords texture\r\n");
    sb.append("# End of File\r\n");
    try {
        Tools.writeUTF8Textfile(pFilename, sb.toString());
    } catch (Exception ex) {
        Unchecker.rethrow(ex);
    }
}
Also used : PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)

Aggregations

PCPoint (org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Flame (org.jwildfire.create.tina.base.Flame)1 PointCloudOBJWriter (org.jwildfire.create.tina.base.raster.PointCloudOBJWriter)1 PointCloudPLYWriter (org.jwildfire.create.tina.base.raster.PointCloudPLYWriter)1 RasterPointCloud (org.jwildfire.create.tina.base.raster.RasterPointCloud)1