1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #ifndef TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_GL_UTILS_H_
17 #define TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_GL_UTILS_H_
18
19 #include <GLES/gl.h>
20 #include <GLES/glext.h>
21
22 #include "tensorflow/examples/android/jni/object_tracking/geom.h"
23
24 namespace tf_tracking {
25
26 // Draws a box at the given position.
DrawBox(const BoundingBox & bounding_box)27 inline static void DrawBox(const BoundingBox& bounding_box) {
28 const GLfloat line[] = {
29 bounding_box.left_, bounding_box.bottom_,
30 bounding_box.left_, bounding_box.top_,
31 bounding_box.left_, bounding_box.top_,
32 bounding_box.right_, bounding_box.top_,
33 bounding_box.right_, bounding_box.top_,
34 bounding_box.right_, bounding_box.bottom_,
35 bounding_box.right_, bounding_box.bottom_,
36 bounding_box.left_, bounding_box.bottom_
37 };
38
39 glVertexPointer(2, GL_FLOAT, 0, line);
40 glEnableClientState(GL_VERTEX_ARRAY);
41
42 glDrawArrays(GL_LINES, 0, 8);
43 }
44
45
46 // Changes the coordinate system such that drawing to an arbitrary square in
47 // the world can thereafter be drawn to using coordinates 0 - 1.
MapWorldSquareToUnitSquare(const BoundingSquare & square)48 inline static void MapWorldSquareToUnitSquare(const BoundingSquare& square) {
49 glScalef(square.size_, square.size_, 1.0f);
50 glTranslatef(square.x_ / square.size_, square.y_ / square.size_, 0.0f);
51 }
52
53 } // namespace tf_tracking
54
55 #endif // TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_GL_UTILS_H_
56