Added CVProcessor interface.

This commit is contained in:
2014-03-11 18:32:46 -04:30
parent 6690d7b3fc
commit c7ee0e0af6
3 changed files with 51 additions and 2 deletions

View File

@@ -15,6 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar;
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor;
import ve.ucv.ciens.ccg.nxtar.interfaces.MulticastEnabler;
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
import ve.ucv.ciens.ccg.nxtar.interfaces.Toaster;
@@ -90,6 +91,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
// Assorted fields.
public SpriteBatch batch;
public CVProcessor cvProc;
private Toaster toaster;
// Networking related fields.
@@ -130,6 +132,13 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement MulticastEnabler. Quitting.");
Gdx.app.exit();
}
try{
this.cvProc = (CVProcessor)concreteApp;
}catch(ClassCastException cc){
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the CVProcessor interface. Quitting.");
Gdx.app.exit();
}
}
public void create(){

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2014 Miguel Angel Astor Romero
*
* 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 ve.ucv.ciens.ccg.nxtar.interfaces;
public interface CVProcessor {
public class CVData{
public byte[] outFrame;
public int[] markerCodes;
// TODO: Add marker location data.
}
public CVData processFrame(byte[] frame, int w, int h);
}

View File

@@ -21,6 +21,7 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor.CVData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -152,9 +153,11 @@ public class InGameState extends BaseState{
@Override
public void render(float delta){
int fW, fH;
byte[] frame;
byte[] prevFrame = null;
Size dimensions = null;
CVData data;
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
@@ -170,9 +173,20 @@ public class InGameState extends BaseState{
}core.batch.end();
frame = frameMonitor.getCurrentFrame();
if(frame != null && !Arrays.equals(frame, prevFrame)){
fW = frameMonitor.getFrameDimensions().getWidth();
fH = frameMonitor.getFrameDimensions().getHeight();
data = core.cvProc.processFrame(frame, fW, fH);
if(data != null){
for(int i = 0; i < data.markerCodes.length; i++){
Gdx.app.log(TAG, CLASS_NAME + String.format(".render(): Marker code[%d] = %d", i, data.markerCodes[i]));
}
}
if(data != null && data.outFrame != null && !Arrays.equals(frame, prevFrame)){
dimensions = frameMonitor.getFrameDimensions();
videoFrame = new Pixmap(frame, 0, dimensions.getWidth() * dimensions.getHeight());
videoFrame = new Pixmap(data.outFrame, 0, dimensions.getWidth() * dimensions.getHeight());
videoFrameTexture = new Texture(videoFrame);
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
videoFrame.dispose();