7 import java.nio.FloatBuffer;
8 import java.nio.ShortBuffer;
30 private int[] _color_off;
35 private int _faces_off = 0;
40 private int _indexwf_off = 0;
45 private int[] _normal_off;
50 private int[] _vertex_off;
60 private int currentColorField = 0;
62 private int currentFrame = 0;
64 private float currentFramef = 0f;
78 private boolean ispaused =
false;
80 private String[] names;
82 private float pos[] = null;
87 private float scaleFactor = 1.0f;
89 private float[] orthoproj = null;
103 this(vData, 700, 400);
117 updateOrthographicProjection();
127 pos =
new float[] { 0f, 0f };
133 private void updateOrthographicProjection() {
134 float exrat, ax = 0, ay = 0;
139 switch (orientation) {
142 ay = (float) w / (
float)
h;
145 ax = (float)
h / (
float) w;
148 orthoproj =
new float[] { -exrat / ax, exrat / ax, -exrat / ay, exrat / ay, -100, 100 };
156 public void addPos(
float posx,
float posy) {
169 private float[] elementToVertexColors(
float[] faceCol) {
171 int numTimeSteps = faceCol.length / (4 * gData.numFaces);
172 float[] nodeCol =
new float[numTimeSteps * gData.getNumVertices() * 4];
182 for (
int ts = 0; ts < numTimeSteps; ts++) {
183 int face_off = ts * 4 * gData.numFaces;
184 int node_off = ts * 4 * gData.getNumVertices();
185 float[] valuesAdded =
new float[gData.getNumVertices()];
186 for (
int f = 0; f < gData.numFaces; f++) {
188 int n1 = gData.faces[3 * f];
189 nodeCol[node_off + 4 * n1] += faceCol[face_off + 4 * f];
190 nodeCol[node_off + 4 * n1 + 1] += faceCol[face_off + 4 * f + 1];
191 nodeCol[node_off + 4 * n1 + 2] += faceCol[face_off + 4 * f + 2];
192 nodeCol[node_off + 4 * n1 + 3] += faceCol[face_off + 4 * f + 3];
195 int n2 = gData.faces[3 * f + 1];
196 nodeCol[node_off + 4 * n2] += faceCol[face_off + 4 * f];
197 nodeCol[node_off + 4 * n2 + 1] += faceCol[face_off + 4 * f + 1];
198 nodeCol[node_off + 4 * n2 + 2] += faceCol[face_off + 4 * f + 2];
199 nodeCol[node_off + 4 * n2 + 3] += faceCol[face_off + 4 * f + 3];
202 int n3 = gData.faces[3 * f + 2];
203 nodeCol[node_off + 4 * n3] += faceCol[face_off + 4 * f];
204 nodeCol[node_off + 4 * n3 + 1] += faceCol[face_off + 4 * f + 1];
205 nodeCol[node_off + 4 * n3 + 2] += faceCol[face_off + 4 * f + 2];
206 nodeCol[node_off + 4 * n3 + 3] += faceCol[face_off + 4 * f + 3];
210 for (
int n = 0; n < gData.getNumVertices(); n++) {
211 nodeCol[node_off + 4 * n] /= valuesAdded[n];
212 nodeCol[node_off + 4 * n + 1] /= valuesAdded[n];
213 nodeCol[node_off + 4 * n + 2] /= valuesAdded[n];
214 nodeCol[node_off + 4 * n + 3] /= valuesAdded[n];
220 private String getShortFillState(
int curFloatBufOffset) {
221 return Math.round((curFloatBufOffset / (double)
shortBuf.capacity()) * 100) +
"%";
224 private String getFloatFillState(
int off) {
225 return Math.round((off / (double)
floatBuf.capacity()) * 100) +
"%";
232 if (!ispaused && (vData.
numFrames > 1 || _vertex_off.length > 1)) {
234 currentFrame = (int) Math.floor(currentFramef);
245 camera.SetRotation(-pos[0], -pos[1]);
250 float minrot = 0.16f / scaleFactor;
251 float sgnx = Math.signum(pos[0]), sgny = Math.signum(pos[1]);
252 pos[0] = sgnx * Math.max(minrot, Math.min(24.00f, sgnx * pos[0] * 0.95f));
253 pos[1] = sgny * Math.max(minrot, Math.min(24.00f, sgny * pos[1] * 0.95f));
259 return vData.getGeometryData().boxsize;
263 return _color_off[currentColorField] + (currentFrame) * (vData.
getGeometryData().getNumVertices() * 4);
267 return _normal_off[currentFrame];
271 return _vertex_off[currentFrame];
291 return vData.getGeometryData().numFaces;
299 return camera.getRotationMatrix();
338 currentFramef = 0.0f;
345 int curShortBufOffset = 0;
346 int curFloatBufOffset = 0;
351 float[][] v = gData.getVertices();
352 _vertex_off =
new int[v.length];
353 for (
int i = 0; i < v.length; i++) {
354 _vertex_off[i] = curFloatBufOffset;
356 curFloatBufOffset += v[i].length;
357 Log.d(
"OpenGLBase",
"FloatBuffer: Added " + v[i].length +
" float values for " + gData.getNumVertices()
358 +
" vertices in set " + (i + 1) +
". Fill state: " + getFloatFillState(curFloatBufOffset));
364 _faces_off = curShortBufOffset;
365 shortBuf.put(gData.faces);
366 curShortBufOffset += gData.faces.length;
367 Log.d(
"OpenGLBase",
"ShortBuffer: Added " + gData.faces.length +
" short values for " + gData.numFaces
368 +
" element faces. Fill state: " + getShortFillState(curShortBufOffset));
373 _indexwf_off = curShortBufOffset;
374 shortBuf.put(gData.faceWireframe);
375 curShortBufOffset += gData.faceWireframe.length;
376 Log.d(
"OpenGLBase",
"ShortBuffer: Added " + gData.faceWireframe.length
377 +
" short values for faces wireframe. Fill state: " + getShortFillState(curShortBufOffset));
384 _color_off =
new int[vData.getNumVisFeatures()];
385 names =
new String[_color_off.length];
386 for (
int i = 0; i < vData.getNumVisFeatures(); i++) {
387 _color_off[i] = curFloatBufOffset;
389 float[] col = vf.Colors;
392 col = elementToVertexColors(col);
395 curFloatBufOffset += col.length;
396 Log.d(
"OpenGLBase",
"FloatBuffer: Added " + col.length +
" floats for color field '" + vf.Name +
"' ("
397 + (i + 1) +
"). Fill state: " + getFloatFillState(curFloatBufOffset));
402 _normal_off =
new int[gData.normal.length];
403 for (
int i = 0; i < _normal_off.length; i++) {
404 _normal_off[i] = curFloatBufOffset;
405 floatBuf.put(gData.normal[i]);
406 curFloatBufOffset += gData.normal[i].length;
407 Log.d(
"OpenGLBase",
"FloatBuffer: Added " + gData.normal[i].length
408 +
" floats for 3D normal data. Fill state: " + getFloatFillState(curFloatBufOffset));
414 return vData.getGeometryData().
is2D();
426 currentColorField %= vData.getNumVisFeatures();
427 Log.d(
"OpenGLBase",
"Next color field '" + names[currentColorField] +
"' (" + (currentColorField + 1) +
"/"
428 + _color_off.length +
")");
435 if (--currentColorField == -1)
436 currentColorField = vData.getNumVisFeatures() - 1;
437 Log.d(
"OpenGLBase",
"Previous color field '" + names[currentColorField] +
"' (" + (currentColorField + 1) +
"/"
438 + _color_off.length +
")");
445 ispaused = !ispaused;
454 Log.d(
"OpenGLBase",
"set orientation:" + o.toString());
456 updateOrthographicProjection();
478 scaleFactor = Math.max(scaleFactor * 0.9f, 0.15f);
void initRendering()
Initializes the rendering process (Vertex, face, color and normal openGL buffers) ...
int getCurrentVertexOffset()
int getCurrentColorOffset()
FieldMapping Mapping
Unused so far, as mixed field mappings are not yet implemented.
int getCurrentWireframeOffset()
FieldDescriptor descriptor
void setSize(int width, int height)
void setOrientation(Orientation o)
Sets the current orientation.
static final float FRAME_INCREASE
void prevColorField()
Shows the next color field, if available.
boolean isFrontFace
Flag that indicates whether the front face should be rendered or not.
boolean isContinuousRotation
Flag that indicates whether the object rotates continuously in the 3D case.
Simple class for feature that can be visualized.
void nextColorField()
Shows the next color field, if available.
float[] getRotationMatrix()
LogicSolutionField Source
GeometryData getGeometryData()
ELEMENT
The field variables are to be mapped to geometry elements, e.g.
A container class for all model visual data.
float[] getOrtographicProj()
void togglePause()
pause the animation if there is any
The field mapping determines how the DoF of the solution are mapped into the given geometry...
Provides a Log class imitating the Android Log class when not used on android systems.
int getCurrentNormalsOffset()
OpenGLBase(VisualizationData vData)
Creates an OpenGLBase with the default size.
Extracted the Camera class from GLRenderer.
This is a container class for all geometry-related data of a reduced model.
void addPos(float posx, float posy)
OpenGLBase(VisualizationData vData, int width, int height)
Base class for OpenGL visualisation.
void resetView()
Sets the initial position away from the model in the y-direction looking toward the center of the mod...