follow Panda coding styles

This commit is contained in:
David Rose 2005-09-15 22:46:49 +00:00
parent b9f5dfd75d
commit 66e917877d
3 changed files with 214 additions and 167 deletions

View File

@ -1,4 +1,20 @@
#ifdef HAVE_CV // Filename: aviTexture.I
// Created by: zacpavlov (19Aug05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -7,14 +23,14 @@
// Description: Grabs a fresh ram buffer to mess with // Description: Grabs a fresh ram buffer to mess with
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool AviTexture::obtain_ram() INLINE bool AviTexture::
{ obtain_ram() {
_buf=modify_ram_image(); _buf = modify_ram_image();
if(_buf)
{ if (_buf) {
return true; return true;
} }
return 0; return false;
} }
@ -25,11 +41,12 @@ INLINE bool AviTexture::obtain_ram()
// positioned at. Disabled for camera input // positioned at. Disabled for camera input
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE float AviTexture::get_time() INLINE float AviTexture::
{ get_time() {
if(!_isCamera) if (!_isCamera) {
return _time; return _time;
return 0; }
return 0.0f;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -39,36 +56,37 @@ INLINE float AviTexture::get_time()
// for camera input // for camera input
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_time(float t) INLINE void AviTexture::
{ set_time(float t) {
if(_isCamera) if (_isCamera) {
return; return;
if(t>=0 && t<=1) }
{ if (t >= 0 && t <= 1) {
_time=t; _time=t;
} }
if(_capture) if (_capture) {
{
cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO,t); cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO,t);
_current_frame=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES); _current_frame = cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES);
} }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AviTexture::set_fps // Function: AviTexture::set_fps
// Access: Published // Access: Published
// Description: sets the fps for the movie, and affects frame recieves // Description: sets the fps for the movie, and affects frame receives
// from camera. Note, since frame update is controlled // from camera. Note, since frame update is controlled
// by python, this item is sort of arbitrary // by python, this item is sort of arbitrary
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_fps(float fps) INLINE void AviTexture::
{ set_fps(float fps) {
if(fps>=0) if (fps >= 0) {
_fps=fps; _fps = fps;
else } else {
return; return;
if(_isCamera && _capture) }
if (_isCamera && _capture) {
cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,int(fps)); cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,int(fps));
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -76,8 +94,8 @@ INLINE void AviTexture::set_fps(float fps)
// Access: Published // Access: Published
// Description: returns the fps as recieved from movie // Description: returns the fps as recieved from movie
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE float AviTexture::get_fps() INLINE float AviTexture::
{ get_fps() {
return _fps; return _fps;
} }
@ -86,8 +104,8 @@ INLINE float AviTexture::get_fps()
// Access: Published // Access: Published
// Description: returns the total amount of frames // Description: returns the total amount of frames
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int AviTexture::get_total_frames() INLINE int AviTexture::
{ get_total_frames() {
return _total_frames; return _total_frames;
} }
@ -96,8 +114,8 @@ INLINE int AviTexture::get_total_frames()
// Access: Published // Access: Published
// Description: returns current frame (base 0) // Description: returns current frame (base 0)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int AviTexture::get_current_frame() INLINE int AviTexture::
{ get_current_frame() {
return _current_frame; return _current_frame;
} }
@ -106,15 +124,11 @@ INLINE int AviTexture::get_current_frame()
// Access: Published // Access: Published
// Description: sets the current frame (base 0) // Description: sets the current frame (base 0)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void AviTexture::set_current_frame(int frame) INLINE void AviTexture::
{ set_current_frame(int frame) {
if(frame>=0 && frame<_total_frames) if (frame>=0 && frame<_total_frames) {
{ _current_frame = frame;
_current_frame=frame;
cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES,_current_frame); cvSetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES,_current_frame);
_time=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO); _time = cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO);
} }
} }
#endif

View File

@ -1,74 +1,97 @@
// Filename: aviTexture.cxx
// Created by: zacpavlov (19Aug05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#include "pandabase.h" #include "pandabase.h"
#ifdef HAVE_CV #ifdef HAVE_CV
#include "texture.h"
#include "aviTexture.h" #include "aviTexture.h"
#include <stdio.h>
TypeHandle AviTexture::_type_handle; TypeHandle AviTexture::_type_handle;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AviTexture::AviTexture // Function: AviTexture::Constructor
// Access: Published // Access: Published
// Description: Sets up the texture to read frames from a camera // Description: Sets up the texture to read frames from a camera
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
AviTexture::AviTexture() AviTexture::
{ AviTexture() {
_isCamera=true; _isCamera = true;
_capture = cvCaptureFromCAM(0); _capture = cvCaptureFromCAM(0);
_buf=0; _buf = NULL;
_magicNum=0; _magicNum = 0;
_time=0; _time = 0.0f;
_fps=30; _fps = 30.0f;
_total_frames=0; _total_frames = 0;
_current_frame=0; _current_frame = 0;
if(_capture) if (_capture) {
{ cvSetCaptureProperty(_capture, CV_CAP_PROP_FPS,_fps);
cvSetCaptureProperty(_capture,CV_CAP_PROP_FPS,_fps); _width = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
_width=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_WIDTH); _height = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
_height=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_HEIGHT);
if(_width<_height) if (_width < _height) {
gen_tex(_width); gen_tex(_width);
else } else {
gen_tex(_height); gen_tex(_height);
}
} }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AviTexture::AviTexture // Function: AviTexture::Constructor
// Access: Published // Access: Published
// Description: Defines the texture as a movie texture. // Description: Defines the texture as a movie texture.
// TODO: Make this search the panda paths // TODO: Make this search the panda paths
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
AviTexture::AviTexture(const string &filename) AviTexture::
{ AviTexture(const string &filename) {
_isCamera=false; _isCamera = false;
_capture = cvCaptureFromFile(filename.c_str()); _capture = cvCaptureFromFile(filename.c_str());
_buf=0; _buf = NULL;
_magicNum=0; _magicNum = 0;
_current_frame=0; _time = 0.0f;
if(_capture) _fps = 30.0f;
{ _total_frames = 0;
_fps=cvGetCaptureProperty(_capture,CV_CAP_PROP_FPS); _current_frame = 0;
_total_frames=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_COUNT);
_width=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_WIDTH); if (_capture) {
_height=cvGetCaptureProperty(_capture,CV_CAP_PROP_FRAME_HEIGHT); _fps = cvGetCaptureProperty(_capture, CV_CAP_PROP_FPS);
if(_width<_height) _total_frames = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_COUNT);
gen_tex(_width); _width = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
else _height = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
gen_tex(_height);
} if (_width < _height) {
gen_tex(_width);
} else {
gen_tex(_height);
}
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AviTexture::~AviTexture // Function: AviTexture::Destructor
// Access: Published // Access: Published
// Description: Destructor. Release the camera or video stream // Description: Destructor. Release the camera or video stream
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
AviTexture::~AviTexture() AviTexture::
{ ~AviTexture() {
cvReleaseCapture(&_capture); cvReleaseCapture(&_capture);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -77,36 +100,12 @@ AviTexture::~AviTexture()
// Description: Tries to find the largest texture that will fit // Description: Tries to find the largest texture that will fit
// inside the video stream. TODO: allow for fit around // inside the video stream. TODO: allow for fit around
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void AviTexture::gen_tex(int magicNum) void AviTexture::
{ gen_tex(int magicNum) {
if(magicNum<32) int size = down_to_power_2(magicNum);
{
magicNum=16; setup_2d_texture(size, size, Texture::T_unsigned_byte, Texture::F_rgb8);
} _magicNum = size;
else if(magicNum<64)
{
magicNum=32;
}
else if(magicNum<128)
{
magicNum=64;
}
else if(magicNum<256)
{
magicNum=128;
}
else if(magicNum<512)
{
magicNum=256;
}
else if(magicNum<1024)
{
magicNum=512;
}
else
magicNum=1024;
setup_2d_texture(magicNum,magicNum, Texture::T_unsigned_byte,Texture::F_rgb8);
_magicNum=magicNum;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -115,45 +114,50 @@ void AviTexture::gen_tex(int magicNum)
// Description: Grabs the next frame off the camera or avi file // Description: Grabs the next frame off the camera or avi file
// Returns false if the capture fails or reached EOF // Returns false if the capture fails or reached EOF
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool AviTexture::
update() {
int begx, endx, begy, endy;
IplImage *frame = 0;
int xs, ys;
bool AviTexture::update() if (_capture) {
{ if (_time == 1.0f) {
int begx,endx,begy,endy;
IplImage* frame = 0;
int xs,ys;
if(_capture)
{
if(_time==1)
return false; return false;
}
frame = cvQueryFrame( _capture ); frame = cvQueryFrame( _capture );
if(frame)
{ if (frame) {
_time=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_AVI_RATIO); _time = cvGetCaptureProperty(_capture, CV_CAP_PROP_POS_AVI_RATIO);
_current_frame=cvGetCaptureProperty(_capture,CV_CAP_PROP_POS_FRAMES); _current_frame = cvGetCaptureProperty(_capture, CV_CAP_PROP_POS_FRAMES);
if(!obtain_ram()) if (!obtain_ram()) {
return false; return false;
begx=(_width-_magicNum)/2.0; }
endx=_width-begx; begx = (_width - _magicNum) / 2.0;
begy=(_height-_magicNum)/2.0; endx = _width - begx;
endy=_height-begy; begy = (_height - _magicNum) / 2.0;
endy = _height - begy;
if(_buf) if (_buf) {
{ xs = get_x_size();
ys = get_y_size();
xs=get_x_size(); if (get_num_components() != 3) {
ys=get_y_size();
if(get_num_components()!=3)
return false; return false;
}
for(int i=begy;i<endy;i++) for (int i = begy; i < endy; ++i) {
memcpy(_buf+((i-begy)*xs*3),frame->imageData+i*+_width*3+begx*3,xs*3); memcpy(_buf + ((i - begy) * xs * 3),
frame->imageData + i * _width * 3 + begx * 3,
xs * 3);
}
return true; return true;
} }
} }
} }
return false; return false;
} }
#endif #endif // HAVE_CV

View File

@ -1,3 +1,21 @@
// Filename: aviTexture.h
// Created by: zacpavlov (19Aug05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
#ifndef AVITEXTURE_H #ifndef AVITEXTURE_H
#define AVITEXTURE_H #define AVITEXTURE_H
@ -9,36 +27,47 @@
#include <cv.h> #include <cv.h>
#include <highgui.h> #include <highgui.h>
////////////////////////////////////////////////////////////////////
// Class : AviTexture
// Description : A specialization on Texture that takes its input
// using the CV library, to produce an animated texture,
// with its source taken from an .avi file or from a
// camera input.
//
// Presently, it is necessary for the application to
// call update() periodically to advance to the next
// frame.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA AviTexture : public Texture { class EXPCL_PANDA AviTexture : public Texture {
PUBLISHED: PUBLISHED:
AviTexture(); AviTexture();
AviTexture(const string &filename); AviTexture(const string &filename);
INLINE void set_time(float t); ~AviTexture();
INLINE float get_time();
INLINE float get_fps();
INLINE void set_fps(float fps);
INLINE int get_total_frames();
INLINE int get_current_frame();
INLINE void set_current_frame(int frame);
bool update();
public:
~AviTexture();
private:
void gen_tex(int magicNum);
INLINE bool obtain_ram();
int _magicNum;
PTA_uchar _buf;
CvCapture * _capture;
float _time;
bool _isCamera;
float _fps;
int _total_frames;
int _current_frame;
int _width;
int _height;
INLINE void set_time(float t);
INLINE float get_time();
INLINE float get_fps();
INLINE void set_fps(float fps);
INLINE int get_total_frames();
INLINE int get_current_frame();
INLINE void set_current_frame(int frame);
bool update();
private:
void gen_tex(int magicNum);
INLINE bool obtain_ram();
int _magicNum;
PTA_uchar _buf;
CvCapture * _capture;
float _time;
bool _isCamera;
float _fps;
int _total_frames;
int _current_frame;
int _width;
int _height;
public: public:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {
return _type_handle; return _type_handle;
@ -60,6 +89,6 @@ private:
#include "aviTexture.I" #include "aviTexture.I"
#endif #endif // HAVE_CV
#endif #endif