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