1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.rs.vr.loaders; 18 19 import android.renderscript.Allocation; 20 import android.renderscript.RenderScript; 21 import android.renderscript.Type; 22 import android.util.Log; 23 24 import com.example.android.rs.vr.engine.ScriptC_bugdroid; 25 import com.example.android.rs.vr.engine.Volume; 26 27 /** 28 * Provides a simple an example of a computed data set and allows the application to 29 * be run without any data sets. 30 */ 31 public class Droid { 32 private static final String LOGTAG = "RawLoader"; 33 private static final String simpleLook = "simple"; 34 private static final int[][] simpleOpacity = {{120, 0x0}, {150, 0xFF}}; 35 private static final int[][] simpleColor = { 36 {144, 0xA4C639, 10, 80, 0}, 37 {155, 0xA4C639, 10, 80, 0}, 38 {200, 0x5555CC, 10, 80, 0}, 39 {300, 0xAA5555, 40, 60, 0}, 40 {255, 0xAAAAAA, 10, 80, 0}}; 41 42 private static final String internalLook = "internal"; 43 private static final int[][] internalOpacity = {{300, 0x0}, {400, 0xFF}}; 44 private static final int[][] internalColor = { 45 {200, 0x44AA44, 70, 30, 30}, 46 {230, 0xAA44AA, 70, 30, 20}, 47 {300, 0xAA5555, 70, 30, 20}, 48 {400, 0xAAAAAA, 70, 30, 20}}; 49 private static final String tranlLook = "translucent"; 50 private static final int[][] tranOpacity = {{110, 0x0},{140, 0x13},{143, 0x0}, {400, 0xFF}}; 51 private static final int[][] tranColor = { 52 {144, 0xA4C639, 70, 30, 0}, 53 {230, 0xAA44AA, 70, 30, 0}, 54 {300, 0xAA5555, 70, 30, 20}, 55 {400, 0xAAAAAA, 70, 30, 20}}; 56 57 private static final int SIZE = 256; 58 public static final String NAME = "A Droid"; 59 buildRSVolume(RenderScript rs, final VolumeLoader.ProgressListener listener)60 public static Volume buildRSVolume(RenderScript rs, 61 final VolumeLoader.ProgressListener listener) { 62 ScriptC_bugdroid scriptC_bricked = new ScriptC_bugdroid(rs); 63 64 Volume v = new Volume(); 65 v.mDimx = v.mDimy = v.mDimz = SIZE; 66 v.mVoxelDim[0] = v.mVoxelDim[1] = v.mVoxelDim[2] = 1.f; 67 68 v.addLook(internalLook, internalColor, internalOpacity); 69 v.addLook(tranlLook, tranColor, tranOpacity); 70 v.addLook(simpleLook, simpleColor, simpleOpacity); 71 72 Type.Builder b = new Type.Builder(rs, android.renderscript.Element.I16(rs)); 73 b.setX(v.mDimx).setY(v.mDimy); 74 Allocation tmp = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT); 75 b.setZ(v.mDimz); 76 b.setX(v.mDimx).setY(v.mDimy).setZ(v.mDimz); 77 v.mVolumeAllocation = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT); 78 79 scriptC_bricked.set_volume(v.mVolumeAllocation); 80 scriptC_bricked.set_size(SIZE); 81 long time = System.nanoTime(); 82 for (int z = 0; z < v.mDimz; z++) { 83 scriptC_bricked.set_z(z); 84 scriptC_bricked.forEach_andy(tmp); 85 scriptC_bricked.forEach_copy(tmp); 86 rs.finish(); 87 listener.progress(z, v.mDimz); 88 } 89 90 Log.v(LOGTAG, "compute Droid in" + ((System.nanoTime() - time) / 1E9f) + "seconds"); 91 tmp.destroy(); 92 scriptC_bricked.destroy(); 93 return v; 94 } 95 96 } 97