diff --git a/panda/src/grutil/Sources.pp b/panda/src/grutil/Sources.pp index 938ea6bb6c..0df172b127 100644 --- a/panda/src/grutil/Sources.pp +++ b/panda/src/grutil/Sources.pp @@ -13,6 +13,7 @@ #define SOURCES \ pipeOcclusionCullTraverser.I pipeOcclusionCullTraverser.h \ cardMaker.I cardMaker.h \ + arToolKit.I arToolKit.h \ config_grutil.h \ ffmpegTexture.I ffmpegTexture.h \ movieTexture.I movieTexture.h \ @@ -27,6 +28,7 @@ #define INCLUDED_SOURCES \ cardMaker.cxx \ + arToolKit.cxx \ ffmpegTexture.cxx \ movieTexture.cxx \ fisheyeMaker.cxx \ @@ -42,6 +44,7 @@ #define INSTALL_HEADERS \ cardMaker.I cardMaker.h \ + arToolKit.I arToolKit.h \ ffmpegTexture.I ffmpegTexture.h \ movieTexture.I movieTexture.h \ fisheyeMaker.I fisheyeMaker.h \ diff --git a/panda/src/grutil/arToolKit.I b/panda/src/grutil/arToolKit.I new file mode 100644 index 0000000000..1249f27ae1 --- /dev/null +++ b/panda/src/grutil/arToolKit.I @@ -0,0 +1,19 @@ +// Filename: arToolKit.I +// Created by: jyelon (01Nov2007) +// +//////////////////////////////////////////////////////////////////// +// +// 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 . +// +//////////////////////////////////////////////////////////////////// + + diff --git a/panda/src/grutil/arToolKit.cxx b/panda/src/grutil/arToolKit.cxx new file mode 100644 index 0000000000..1cda0834bf --- /dev/null +++ b/panda/src/grutil/arToolKit.cxx @@ -0,0 +1,169 @@ +// Filename: arToolKit.cxx +// Created by: jyelon (01Nov2007) +// +//////////////////////////////////////////////////////////////////// +// +// 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 . +// +//////////////////////////////////////////////////////////////////// + +#ifdef HAVE_ARTOOLKIT + +#include "arToolKit.h" +#include "pandaNode.h" +#include "camera.h" +#include "config_grutil.h" +extern "C" { + #include "artools.h" +}; + +ARToolKit::PatternTable ARToolKit::_pattern_table; + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::Constructor +// Access: Private +// Description: +//////////////////////////////////////////////////////////////////// +ARToolKit *ARToolKit:: +make(NodePath camera, const Filename ¶mfile) { + if (camera.is_empty()) { + grutil_cat.error() << "ARToolKit: invalid camera nodepath\n"; + return 0; + } + PandaNode *node = camera.node(); + if ((node == 0) || (node->get_type() != Camera::get_class_type())) { + grutil_cat.error() << "ARToolKit: invalid camera nodepath\n"; + return 0; + } + + ARParam wparam; + string fn = paramfile.to_os_specific(); + if( arParamLoad(fn.c_str(), 1, &wparam) < 0 ) { + grutil_cat.error() << "Cannot load ARToolKit camera config\n"; + return 0; + } + + ARToolKit *result = new ARToolKit(); + result->_camera = camera; + result->_camera_param = new ARParam; + memcpy(result->_camera_param, &wparam, sizeof(wparam)); + return result; +} + + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::cleanup +// Access: private +// Description: Pre-destructor deallocation and cleanup. +//////////////////////////////////////////////////////////////////// +void ARToolKit:: +cleanup() { + if (_camera_param) { + ARParam *param = (ARParam *)_camera_param; + delete param; + _camera_param = 0; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::Constructor +// Access: Private +// Description: Use ARToolKit::make to create an ARToolKit. +//////////////////////////////////////////////////////////////////// +ARToolKit:: +ARToolKit() { +} + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +ARToolKit:: +~ARToolKit() { + cleanup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::get_pattern +// Access: Private +// Description: Load the specified pattern into the toolkit, and +// return the pattern index. Initially, the pattern +// is inactive. +//////////////////////////////////////////////////////////////////// +int ARToolKit:: +get_pattern(const Filename &filename) { + PatternTable::iterator ptf = _pattern_table.find(filename); + if (ptf != _pattern_table.end()) { + return (*ptf).second; + } + + string fn = filename.to_os_specific(); + int id = arLoadPatt(fn.c_str()); + if (id < 0) { + grutil_cat.error() << "Could not load AR ToolKit Pattern: " << fn << "\n"; + return -1; + } + arDeactivatePatt(id); + _pattern_table[filename] = id; + return id; +} + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::attach_pattern +// Access: Public +// Description: Associates the specified glyph with the specified +// NodePath. Each time you call analyze, ARToolKit +// will update the NodePath's transform. If the node +// is not visible, its scale will be set to zero. +//////////////////////////////////////////////////////////////////// +void ARToolKit:: +attach_pattern(const Filename &filename, NodePath path) { + int patt = get_pattern(filename); + if (patt < 0) return; + _controls[patt] = path; +} + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::detach_patterns +// Access: Public +// Description: Dissociates all patterns from all NodePaths. +//////////////////////////////////////////////////////////////////// +void ARToolKit:: +detach_patterns() { + _controls.clear(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ARToolKit::analyze +// Access: Public +// Description: Analyzes the non-pad region of the specified texture. +//////////////////////////////////////////////////////////////////// +void ARToolKit:: +analyze(Texture *tex, double thresh) { + nassertv(tex->get_texture_type() == Texture::TT_2d_texture); + nassertv(tex->get_component_type() == Texture::T_unsigned_byte); + nassertv(tex->get_num_components() >= 3); + + int xsize = tex->get_x_size() - tex->get_pad_x_size(); + int ysize = tex->get_y_size() - tex->get_pad_y_size(); + nassertv((xsize > 0) && (ysize > 0)); + + ARParam cparam; + arParamChangeSize( (ARParam*)_camera_param, xsize, ysize, &cparam ); + arInitCparam( &cparam ); + + cerr << "Analyze video " << xsize << " x " << ysize << "\n"; +} + + +#endif // HAVE_ARTOOLKIT diff --git a/panda/src/grutil/arToolKit.h b/panda/src/grutil/arToolKit.h new file mode 100644 index 0000000000..d7d20b60ff --- /dev/null +++ b/panda/src/grutil/arToolKit.h @@ -0,0 +1,74 @@ +// Filename: arToolKit.h +// Created by: jyelon (01Nov2007) +// +//////////////////////////////////////////////////////////////////// +// +// 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 ARTOOLKIT_H +#define ARTOOLKIT_H + +#ifdef HAVE_ARTOOLKIT + +#include "pandabase.h" +#include "nodePath.h" +#include "texture.h" + +//////////////////////////////////////////////////////////////////// +// Class : ARToolKit +// Description : ARToolKit is a software library for building +// Augmented Reality (AR) applications. These are +// applications that involve the overlay of virtual +// imagery on the real world. It was developed by +// Dr. Hirokazu Kato. Its ongoing development is +// being supported by the Human Interface Technology +// Laboratory (HIT Lab) at the University of +// Washington, HIT Lab NZ at the University of +// Canterbury, New Zealand, and ARToolworks, Inc, +// Seattle. It is available under a GPL license. +// It is also possible to negotiate other licenses +// with the copyright holders. +// +// This class is a wrapper around the ARToolKit +// library. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA_GRUTIL ARToolKit { + +PUBLISHED: + static ARToolKit *make(NodePath camera, const Filename ¶mfile); + ~ARToolKit(); + + void attach_pattern(const Filename &pattern, NodePath path); + void detach_patterns(); + void analyze(Texture *tex, double thresh); + +private: + static int get_pattern(const Filename &pattern); + ARToolKit(); + void cleanup(); + + typedef pmap PatternTable; + static PatternTable _pattern_table; + + typedef pmap Controls; + Controls _controls; + + NodePath _camera; + void *_camera_param; +}; + +#include "arToolKit.I" + +#endif // HAVE_ARTOOLKIT +#endif // ARTOOLKIT_H diff --git a/panda/src/grutil/grutil_composite1.cxx b/panda/src/grutil/grutil_composite1.cxx index a354d5d355..2fcbbc2ad2 100644 --- a/panda/src/grutil/grutil_composite1.cxx +++ b/panda/src/grutil/grutil_composite1.cxx @@ -1,4 +1,5 @@ #include "cardMaker.cxx" +#include "arToolKit.cxx" #include "heightfieldTesselator.cxx" #include "config_grutil.cxx" #include "lineSegs.cxx" diff --git a/panda/src/grutil/movieTexture.cxx b/panda/src/grutil/movieTexture.cxx index a4ec17ec73..cc4aa050c4 100644 --- a/panda/src/grutil/movieTexture.cxx +++ b/panda/src/grutil/movieTexture.cxx @@ -232,7 +232,9 @@ recalculate_image_properties(CDWriter &cdata) { if (x_max > y_max) y_max = x_max; if (y_max > x_max) x_max = y_max; } - + + int x_size = x_max; + int y_size = y_max; if (textures_power_2 != ATS_none) { x_max = up_to_power_2(x_max); y_max = up_to_power_2(y_max); @@ -240,6 +242,7 @@ recalculate_image_properties(CDWriter &cdata) { reconsider_image_properties(x_max, y_max, alpha?4:3, T_unsigned_byte, cdata->_pages.size()); + set_pad_size(x_max - x_size, y_max - y_size); } ////////////////////////////////////////////////////////////////////