15ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford/* 25ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * Copyright (C) 2015 The Android Open Source Project 35ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * 45ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 55ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * you may not use this file except in compliance with the License. 65ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * You may obtain a copy of the License at 75ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * 85ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * http://www.apache.org/licenses/LICENSE-2.0 95ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * 105ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * Unless required by applicable law or agreed to in writing, software 115ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 125ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * See the License for the specific language governing permissions and 145ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * limitations under the License. 155ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford */ 165ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 175ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordpackage com.example.android.rs.vr.loaders; 185ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 195ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordimport android.renderscript.Allocation; 205ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordimport android.renderscript.RenderScript; 215ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordimport android.renderscript.Type; 225ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordimport android.util.Log; 235ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 245ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordimport com.example.android.rs.vr.engine.ScriptC_bugdroid; 255ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordimport com.example.android.rs.vr.engine.Volume; 265ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 275ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford/** 285ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * Provides a simple an example of a computed data set and allows the application to 295ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford * be run without any data sets. 305ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford */ 315ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hofordpublic class Droid { 325ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final String LOGTAG = "RawLoader"; 335ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final String simpleLook = "simple"; 345ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int[][] simpleOpacity = {{120, 0x0}, {150, 0xFF}}; 355ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int[][] simpleColor = { 365ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {144, 0xA4C639, 10, 80, 0}, 375ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {155, 0xA4C639, 10, 80, 0}, 385ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {200, 0x5555CC, 10, 80, 0}, 395ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {300, 0xAA5555, 40, 60, 0}, 405ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {255, 0xAAAAAA, 10, 80, 0}}; 415ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 425ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final String internalLook = "internal"; 435ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int[][] internalOpacity = {{300, 0x0}, {400, 0xFF}}; 445ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int[][] internalColor = { 455ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {200, 0x44AA44, 70, 30, 30}, 465ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {230, 0xAA44AA, 70, 30, 20}, 475ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {300, 0xAA5555, 70, 30, 20}, 485ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {400, 0xAAAAAA, 70, 30, 20}}; 495ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final String tranlLook = "translucent"; 505ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int[][] tranOpacity = {{110, 0x0},{140, 0x13},{143, 0x0}, {400, 0xFF}}; 515ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int[][] tranColor = { 525ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {144, 0xA4C639, 70, 30, 0}, 535ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {230, 0xAA44AA, 70, 30, 0}, 545ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {300, 0xAA5555, 70, 30, 20}, 555ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford {400, 0xAAAAAA, 70, 30, 20}}; 565ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 575ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford private static final int SIZE = 256; 585ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford public static final String NAME = "A Droid"; 595ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 605ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford public static Volume buildRSVolume(RenderScript rs, 615ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford final VolumeLoader.ProgressListener listener) { 625ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford ScriptC_bugdroid scriptC_bricked = new ScriptC_bugdroid(rs); 635ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 645ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford Volume v = new Volume(); 655ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford v.mDimx = v.mDimy = v.mDimz = SIZE; 665ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford v.mVoxelDim[0] = v.mVoxelDim[1] = v.mVoxelDim[2] = 1.f; 675ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 685ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford v.addLook(internalLook, internalColor, internalOpacity); 695ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford v.addLook(tranlLook, tranColor, tranOpacity); 705ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford v.addLook(simpleLook, simpleColor, simpleOpacity); 715ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 725ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford Type.Builder b = new Type.Builder(rs, android.renderscript.Element.I16(rs)); 735ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford b.setX(v.mDimx).setY(v.mDimy); 745ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford Allocation tmp = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT); 755ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford b.setZ(v.mDimz); 765ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford b.setX(v.mDimx).setY(v.mDimy).setZ(v.mDimz); 775ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford v.mVolumeAllocation = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT); 785ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 795ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford scriptC_bricked.set_volume(v.mVolumeAllocation); 805ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford scriptC_bricked.set_size(SIZE); 815ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford long time = System.nanoTime(); 825ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford for (int z = 0; z < v.mDimz; z++) { 835ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford scriptC_bricked.set_z(z); 845ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford scriptC_bricked.forEach_andy(tmp); 855ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford scriptC_bricked.forEach_copy(tmp); 865ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford rs.finish(); 875ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford listener.progress(z, v.mDimz); 885ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford } 895ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 905ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford Log.v(LOGTAG, "compute Droid in" + ((System.nanoTime() - time) / 1E9f) + "seconds"); 915ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford tmp.destroy(); 925ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford scriptC_bricked.destroy(); 935ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford return v; 945ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford } 955ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford 965ee349cd7a75079b6bac1d8ace66455ecd1afb17John Hoford} 97