From: <kon...@us...> - 2009-06-16 06:50:49
|
Revision: 65 http://mevislabmodules.svn.sourceforge.net/mevislabmodules/?rev=65&view=rev Author: konrad79 Date: 2009-06-16 06:50:44 +0000 (Tue, 16 Jun 2009) Log Message: ----------- METK: first submission for testing (sources) Added Paths: ----------- trunk/Community/METK/Sources/ trunk/Community/METK/Sources/Inventor/ trunk/Community/METK/Sources/Inventor/UMDVisLogo/ trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.cpp trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.h trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.bat trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.pro trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.cpp trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.h trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoSystem.h trunk/Community/METK/Sources/common/ trunk/Community/METK/Sources/common/HashTable.h trunk/Community/METK/Sources/common/ObjMgrCommunicator.cpp trunk/Community/METK/Sources/common/ObjMgrCommunicator.h trunk/Community/METK/Sources/common/StdAfx.cpp trunk/Community/METK/Sources/common/StdAfx.h trunk/Community/METK/Sources/common/StrList.h trunk/Community/METK/Sources/common/XMLParser.cpp trunk/Community/METK/Sources/common/XMLParser.h trunk/Community/METK/Sources/common/common.bat trunk/Community/METK/Sources/common/common.pro trunk/Community/METK/Sources/common/image_basic.cpp trunk/Community/METK/Sources/common/image_basic.h trunk/Community/METK/Sources/common/kBasics.cpp trunk/Community/METK/Sources/common/kBasics.h trunk/Community/METK/Sources/common/kCamera.cpp trunk/Community/METK/Sources/common/kCamera.h trunk/Community/METK/Sources/common/kDebug.cpp trunk/Community/METK/Sources/common/kDebug.h trunk/Community/METK/Sources/common/kSphere.cpp trunk/Community/METK/Sources/common/kSphere.h trunk/Community/METK/Sources/common/matrix.h Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.cpp =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.cpp (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.cpp 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,408 @@ +//---------------------------------------------------------------------------------- +//! The Inventor module class SoVisLogo +/*! +// \file SoVisLogo.cpp +// \author Konrad M\xFChler +// \date 2007-06-12 +// +// +*/ +//---------------------------------------------------------------------------------- + +// Local includes +#include "SoVisLogo.h" + +// Wrap inventor includes into XVEnterScope and XVLeaveScope to avoid +// collisions between OpenInventor and Windows headers. +#include "XVEnterScope.h" +#if defined(SGI_VERSION) && SGI_VERSION >= 20200 +# include <Inventor/SoTrace.h> +#endif +#ifndef SO_TRACE_IN +# define SO_TRACE_IN(__classAndMethod___) +#endif +#include <Inventor/actions/SoGLRenderAction.h> +// TODO: include more inventor things here +#include "XVLeaveScope.h" + +#include <GL/glaux.h> +#pragma warning( disable : 4611 ) +#include "png.h" + +SO_NODE_SOURCE(SoVisLogo) + + +// -------------------------------------------------------------------------- +//! Initializes this class. Called on dll initialization. +// -------------------------------------------------------------------------- +void SoVisLogo::initClass() +{ + SO_NODE_INIT_CLASS(SoVisLogo, SoShape, "Shape"); +} + +// -------------------------------------------------------------------------- +//! Constructor, creates fields +// -------------------------------------------------------------------------- +SoVisLogo::SoVisLogo() +{ + SO_TRACE_IN("SoVisLogo::SoVisLogo") + + // Execute inventor internal stuff for node construction. + SO_NODE_CONSTRUCTOR(SoVisLogo); + + SO_NODE_ADD_FIELD(fldLocalPath, ("")); + + SO_NODE_ADD_FIELD(fldFilename, (vislogo)); + SO_NODE_DEFINE_ENUM_VALUE(logoNames, vislogo); + SO_NODE_DEFINE_ENUM_VALUE(logoNames, otto); + SO_NODE_DEFINE_ENUM_VALUE(logoNames, otto2); + SO_NODE_DEFINE_ENUM_VALUE(logoNames, lst); + SO_NODE_DEFINE_ENUM_VALUE(logoNames, neck); + SO_NODE_SET_SF_ENUM_TYPE(fldFilename, logoNames); + + SO_NODE_ADD_FIELD(fldCorner, (topright)); + SO_NODE_DEFINE_ENUM_VALUE(corners, topright); + SO_NODE_DEFINE_ENUM_VALUE(corners, topleft); + SO_NODE_DEFINE_ENUM_VALUE(corners, bottomright); + SO_NODE_DEFINE_ENUM_VALUE(corners, bottomleft); + SO_NODE_SET_SF_ENUM_TYPE(fldCorner, corners); + + + // Create a sensor calling _nodeChangedCB if any field changes. Use a priority 0 + // sensor to be sure that changes are not delayed or collected. + _nodeSensor = new SoNodeSensor(SoVisLogo::nodeChangedCB, this); + _nodeSensor->setPriority(0); + _nodeSensor->attach(this); + + filenameSensor = new SoFieldSensor(filenameChangedCB, this); + filenameSensor->setPriority(0); + filenameSensor->attach(&fldLocalPath); + localPathSensor = new SoFieldSensor(filenameChangedCB, this); + localPathSensor->setPriority(0); + localPathSensor->attach(&fldFilename); +} + +// -------------------------------------------------------------------------- +//! Protected destructor to cleans up internally created nodes and node sensor. +// -------------------------------------------------------------------------- +SoVisLogo::~SoVisLogo() +{ + SO_TRACE_IN("SoVisLogo::~SoVisLogo") + // Remove the node sensor. + if (_nodeSensor){ delete _nodeSensor; _nodeSensor = NULL; } +} + +//----------------------------------------------------------------------------- +// Called by nodeSensor when any field in node changes. Only redirect the call +// of this static function to the nodeChanged method. +//----------------------------------------------------------------------------- +void SoVisLogo::nodeChangedCB(void *data, SoSensor* sens) +{ + SO_TRACE_IN("SoVisLogo::nodeChangedCB") + + ((SoVisLogo*) data)->nodeChanged((SoNodeSensor*)sens); +} + +//----------------------------------------------------------------------------- +//! Called on any change on the node, field might by also NULL +//----------------------------------------------------------------------------- +void SoVisLogo::nodeChanged(SoNodeSensor* /*sensor*/) +{ + SO_TRACE_IN("SoVisLogo::nodeChanged") + + // Get the field which caused the notification. + //SoField* field = sensor->getTriggerField(); + + // Handle changed fields here +} + + +//! called whenever the scene is rendered +void SoVisLogo::GLRender(SoGLRenderAction *action) +{ + SO_TRACE_IN("SoVisLogo::GLRender") + + // Save the current transformation and attribute state of OpenGL. + glMatrixMode (GL_PROJECTION); + glPushMatrix(); + glMatrixMode (GL_MODELVIEW); + glPushMatrix(); + glPushAttrib(GL_ALL_ATTRIB_BITS); + glDisable(GL_LIGHTING); + + SoState * state = action->getState(); + const SbViewportRegion & vp = SoViewportRegionElement::get(state); + + glDisable(GL_DEPTH_TEST); + + glMatrixMode (GL_MODELVIEW); + glLoadIdentity(); //Einheitsmatrix + glMatrixMode(GL_PROJECTION); //"2D"-Modus + glLoadIdentity(); //Einheitsmatrix + + if (load_result!=NULL && png_image!=NULL) + { + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + GLuint textureID; + glGenTextures( 1, &textureID ); + glBindTexture( GL_TEXTURE_2D, textureID ); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img_width, img_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, png_image); + + glBegin(GL_POLYGON); + float border = 10.0; + float scale = 1.0; + if (fldCorner.getValue()==bottomleft) + { + glTexCoord2f(0.0, 0.0);glVertex2f(-1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[0], -1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 0.0);glVertex2f(-1.0f + 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], -1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 1.0);glVertex2f(-1.0f + 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], -1.0f+2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(0.0, 1.0);glVertex2f(-1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[0],-1.0f + 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + } + else if (fldCorner.getValue()==bottomright) + { + glTexCoord2f(0.0, 0.0);glVertex2f(1.0f - 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], -1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 0.0);glVertex2f(1.0f - (float)(border)/(float)vp.getWindowSize()[0], -1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 1.0);glVertex2f(1.0f - (float)(border)/(float)vp.getWindowSize()[0], -1.0f + 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(0.0, 1.0);glVertex2f(1.0f - 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0],-1.0f + 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + } + else if (fldCorner.getValue()==topright) + { + glTexCoord2f(0.0, 0.0);glVertex2f(1.0f - 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 0.0);glVertex2f(1.0f - (float)(border)/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 1.0);glVertex2f(1.0f - (float)(border)/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)(border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(0.0, 1.0);glVertex2f(1.0f - 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)border/(float)vp.getWindowSize()[1]); + } + else if (fldCorner.getValue()==topleft) + { + glTexCoord2f(0.0, 0.0);glVertex2f(-1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 0.0);glVertex2f(-1.0f + 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)(img_height*scale+border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(1.0, 1.0);glVertex2f(-1.0f + 2.0f*(float)(img_width*scale+border)/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)(border)/(float)vp.getWindowSize()[1]); + glTexCoord2f(0.0, 1.0);glVertex2f(-1.0f + 2.0f*(float)border/(float)vp.getWindowSize()[0], 1.0f - 2.0f*(float)border/(float)vp.getWindowSize()[1]); + } + //std::cout << "img_w:" << img_width << " windowSize[0]" << vp.getWindowSize()[0] << std::endl; + //std::cout << "x:" << -1.0f+2.0f*(float)img_width/(float)vp.getWindowSize()[0] << " y:" << -1.0f+2.0f*(float)img_height/(float)vp.getWindowSize()[1] << std::endl; + glEnd(); + glEnable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); + } + //else std::cout << "result!=NULL oder image!=NULL" << std::endl; + + glFlush(); + + // Restore the transformation and attribute state of OpenGL. + glPopAttrib(); + glMatrixMode (GL_MODELVIEW); + glPopMatrix(); + glMatrixMode (GL_PROJECTION); + glPopMatrix(); + glMatrixMode (GL_MODELVIEW); +} + +//! called when an SoEvent is passed through the scene +void SoVisLogo::handleEvent(SoHandleEventAction* /*action*/) +{ + SO_TRACE_IN("SoVisLogo::handleEvent") + // TODO +} + +//! called when a scene bounding box is computed +void SoVisLogo::computeBBox(SoAction* /*action*/, SbBox3f& /*box*/, SbVec3f& /*center*/) +{ + SO_TRACE_IN("SoVisLogo::computeBBox") + // TODO +} + +//! called by the generate primitives action +void SoVisLogo::generatePrimitives(SoAction* /*action*/) +{ + SO_TRACE_IN("SoVisLogo::generatePrimitives") + // TODO +} + +//! called by the ray pick action +void SoVisLogo::rayPick(SoRayPickAction* /*action*/) +{ + SO_TRACE_IN("SoVisLogo::rayPick") + // TODO +} + + + +int SoVisLogo::pngLoad(const char *file, unsigned long &pwidth, unsigned long &pheight, char* &image_data_ptr) +{ + FILE *infile; /* PNG file pointer */ + png_structp png_ptr; /* internally used by libpng */ + png_infop info_ptr; /* user requested transforms */ + + char *image_data; /* raw png image data */ + char sig[8]; /* PNG signature array */ + + int bit_depth; + int color_type; + + unsigned long width; /* PNG image width in pixels */ + unsigned long height; /* PNG image height in pixels */ + unsigned int rowbytes; /* raw bytes at row n in image */ + + image_data = NULL; + png_bytepp row_pointers = NULL; + + /* Open the file. */ + infile = fopen(file, "rb"); + if (!infile) return 0; + + /* + * 13.3 readpng_init() + */ + + /* Check for the 8-byte signature */ + fread(sig, 1, 8, infile); + + if (!png_check_sig((unsigned char *) sig, 8)) { + fclose(infile); + return 0; + } + + /* + * Set up the PNG structs + */ + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) { + fclose(infile); + return 4; /* out of memory */ + } + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); + fclose(infile); + return 4; /* out of memory */ + } + + + /* + * block to handle libpng errors, + * then check whether the PNG file had a bKGD chunk + */ + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + fclose(infile); + return 0; + } + + /* + * takes our file stream pointer (infile) and + * stores it in the png_ptr struct for later use. + */ + /* png_ptr->io_ptr = (png_voidp)infile;*/ + png_init_io(png_ptr, infile); + + /* + * lets libpng know that we already checked the 8 + * signature bytes, so it should not expect to find + * them at the current file pointer location + */ + png_set_sig_bytes(png_ptr, 8); + + /* Read the image info.*/ + + /* + * reads and processes not only the PNG file's IHDR chunk + * but also any other chunks up to the first IDAT + * (i.e., everything before the image data). + */ + + /* read all the info up to the image data */ + png_read_info(png_ptr, info_ptr); + + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, + &color_type, NULL, NULL, NULL); + + pwidth = width; + pheight = height; + + /* Set up some transforms. */ + if (color_type & PNG_COLOR_MASK_ALPHA) { +// std::cout << "ALPHA1" << std::endl; + png_set_strip_alpha(png_ptr); + } + if (bit_depth > 8) { + png_set_strip_16(png_ptr); +// std::cout << "RGB>8" << std::endl; + } + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { + png_set_gray_to_rgb(png_ptr); +// std::cout << "GRAY" << std::endl; + } + if (color_type == PNG_COLOR_TYPE_PALETTE) { + png_set_palette_to_rgb(png_ptr); +// std::cout << "PALETTE" << std::endl; + } + + /* Update the png info struct.*/ + png_read_update_info(png_ptr, info_ptr); + + /* Rowsize in bytes. */ + rowbytes = png_get_rowbytes(png_ptr, info_ptr); + + + /* Allocate the image_data buffer. */ + if ((image_data = (char *) malloc(rowbytes * height))==NULL) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return 4; + } + + if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + free(image_data); + image_data = NULL; + return 4; + } + + /* set the individual row_pointers to point at the correct offsets */ + unsigned int i; + for (i = 0; i < height; ++i) + row_pointers[height - 1 - i] = (png_byte * ) image_data + i*rowbytes; + + /* now we can go ahead and just read the whole image */ + png_read_image(png_ptr, row_pointers); + + /* and we're done! (png_read_end() can be omitted if no processing of + * post-IDAT text/time/etc. is desired) */ + + /* Clean up. */ + free(row_pointers); + + /* Clean up. */ + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + fclose(infile); + + image_data_ptr = image_data; + + return 1; +} + + +void SoVisLogo::filenameChangedCB(void *data, SoSensor* ) +{ + std::string logoNamesStr[5] = {"vislogo.png", "otto.png", "otto2.png", "lst.png", "neck.png"}; + SoVisLogo *myself = (SoVisLogo *)data; + if (myself->fldFilename.getValue()>=5) return; + std::string filename = std::string(myself->fldLocalPath.getValue().getString())+"/"+logoNamesStr[myself->fldFilename.getValue()]; + //std::cout << filename << std::endl; + myself->load_result = myself->pngLoad(filename.c_str(), myself->img_width, myself->img_height, myself->png_image); +} + + +void SoVisLogo::activateAttachments() +{ + fldFilename.touch(); +} \ No newline at end of file Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.h =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.h (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/SoVisLogo.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,101 @@ +//---------------------------------------------------------------------------------- +//! The Inventor module class SoVisLogo derived from SoShape +/*! +// \file SoVisLogo.h +// \author Konrad M\xFChler +// \date 2007-06-12 +// +// +*/ +//---------------------------------------------------------------------------------- + +#ifndef __SOVISLOGO_H__ +#define __SOVISLOGO_H__ + + +// Local includes +#include "UMDVisLogoSystem.h" + +// Wrap inventor includes into XVEnterScope and XVLeaveScope to avoid +// collisions between OpenInventor and Windows headers. +#include "XVEnterScope.h" +#include <Inventor/nodes/SoSubNode.h> +#include <Inventor/nodes/SoShape.h> + +#include <Inventor/elements/SoViewportRegionElement.h> + +// include used fields +#include <Inventor/fields/SoSFString.h> +#include <Inventor/fields/SoSFEnum.h> +#include <Inventor/sensors/SoNodeSensor.h> +#include <Inventor/sensors/SoFieldSensor.h> +#include "XVLeaveScope.h" + +//! +class UMDVISLOGO_EXPORT SoVisLogo : public SoShape +{ + //! Implements the runtime type system interface of this new node. + SO_NODE_HEADER(SoVisLogo); + +public: + //! Constructor + SoVisLogo(); + + //! Initializes this class (called on dll initialization). + static void initClass(); + + //@{! Fields + + SoSFString fldLocalPath; + SoSFEnum fldFilename; + SoSFEnum fldCorner; + + //@} + + //! called whenever the scene is rendered + virtual void GLRender(SoGLRenderAction *action); + //! called when an SoEvent is passed through the scene + virtual void handleEvent(SoHandleEventAction *action); + //! called when a scene bounding box is computed + virtual void computeBBox(SoAction * action, SbBox3f &box, SbVec3f ¢er); + //! called by the generate primitives action + virtual void generatePrimitives(SoAction *action); + //! called by the ray pick action + virtual void rayPick(SoRayPickAction *action); + +protected: + //! Protected destructor + virtual ~SoVisLogo(); + + //! Sensor to detect changes in node's fields. + SoNodeSensor* _nodeSensor; + + //! Called by \c _nodeSensor when any field in node changes. + //! Only redirects the call of this static function to the + //! class method \c nodeChanged. + static void nodeChangedCB(void *data, SoSensor* sens); + + //! Called by the static function \c _nodeChangedCB to notify node changes. + void nodeChanged(SoNodeSensor* sensor); + + SoFieldSensor* filenameSensor; + SoFieldSensor* localPathSensor; + static void filenameChangedCB(void *, SoSensor *); + + enum logoNames {vislogo, otto, otto2, lst, neck}; //Defintion der Filenames in filenameChangedCB + enum corners {topleft, topright, bottomleft, bottomright}; + +private: + + unsigned long load_result, img_width, img_height; + char* png_image; + char *filename; + + int pngLoad(const char *file, unsigned long &pwidth, unsigned long &pheight, char* &image_data_ptr); + + void activateAttachments(); +}; + +#endif // __SOVISLOGO_H + + Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.bat =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.bat (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.bat 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1 @@ +"%MLAB_ROOT%\MeVis\Foundation\BuildTools\Scripts\createProject.bat" UMDVisLogo \ No newline at end of file Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.pro =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.pro (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogo.pro 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,41 @@ +# ----------------------------------------------------------------------------- +# UMDVisLogo project profile +# +# \file UMDVisLogo.pro +# \author Konrad M\xFChler +# \date 2007-06-12 +# ----------------------------------------------------------------------------- + +TEMPLATE = lib + +TARGET = UMDVisLogo + +DESTDIR = ../../../lib +DLLDESTDIR = ../../../lib + + +# add used packages here (see stdPackages.pro for packages): +CONFIG += dll inventor MLOpenGL png + +MLAB_PACKAGES += UMD_METK \ + MeVisLab_Standard + + +# set high warn level (warn 4 on MSCV) +WARN = HIGH + +# DONT REMOVE THE FOLLOWING LINE: +include ($(MLAB_MeVis_Foundation)/Configuration/IncludePackages.pri) + + +DEFINES += UMDVISLOGO_EXPORTS + +HEADERS += \ + UMDVisLogoInit.h \ + UMDVisLogoSystem.h \ + SoVisLogo.h \ + +SOURCES += \ + UMDVisLogoInit.cpp \ + SoVisLogo.cpp \ + Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.cpp =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.cpp (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.cpp 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,26 @@ +//---------------------------------------------------------------------------------- +//! Dynamic library and runtime type system initialization +/*! +// \file UMDVisLogoInit.cpp +// \author Konrad M\xFChler +// \date 2007-06-12 +*/ +//---------------------------------------------------------------------------------- + +// Local includes +#include "UMDVisLogoSystem.h" +#include <XVBasics.h> +#include "SoVisLogo.h" + + +// Called on initialization time of this dll. Register all new stuff. +void UMDVisLogoInit() +{ + // Register the class in the inventor runtime type system. + SoVisLogo::initClass(); +}; + +// Macro implementing the platform independent dll initialization +XV_INIT_LIBRARY(UMDVisLogoInit) + + Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.h =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.h (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoInit.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,18 @@ +//---------------------------------------------------------------------------------- +//! Dynamic library and runtime type system initialization +/*! +// \file UMDVisLogoInit.h +// \author Konrad M\xFChler +// \date 2007-06-12 +*/ +//---------------------------------------------------------------------------------- + + +#ifndef __UMDVISLOGOINIT_H__ +#define __UMDVISLOGOINIT_H__ + +void UMDVisLogoInit(); + +#endif +// __UMDVISLOGOINIT_H__ + Added: trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoSystem.h =================================================================== --- trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoSystem.h (rev 0) +++ trunk/Community/METK/Sources/Inventor/UMDVisLogo/UMDVisLogoSystem.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,35 @@ +//---------------------------------------------------------------------------------- +//! Project global and OS specific declarations +/*! +// \file UMDVisLogoSystem.h +// \author Konrad M\xFChler +// \date 2007-06-12 +*/ +//---------------------------------------------------------------------------------- + + +#ifndef __UMDVISLOGOSYSTEM_H__ +#define __UMDVISLOGOSYSTEM_H__ + +// include MeVis OpenGL headers first (includes GL/glew.h) +#include <mlOpenGL.h> + +// DLL export macro definition +#ifdef WIN32 +#ifdef UMDVISLOGO_EXPORTS +// Use the UMDVISLOGO_EXPORT macro to export classes and functions +#define UMDVISLOGO_EXPORT __declspec(dllexport) +#else +// If included by external modules, exported symbols are declared as import symbols +#define UMDVISLOGO_EXPORT __declspec(dllimport) +#endif + +#else +// No export declarations are necessary for non-Windows systems +#define UMDVISLOGO_EXPORT +#endif + + +#endif +// __UMDVISLOGOSYSTEM_H__ + Added: trunk/Community/METK/Sources/common/HashTable.h =================================================================== --- trunk/Community/METK/Sources/common/HashTable.h (rev 0) +++ trunk/Community/METK/Sources/common/HashTable.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,135 @@ +//---------------------------------------------------------------------------------- +/*! +// \file HashTable.h +// \author HashTable, Copyright (c) 1998 by Michael Neumann +// \author (Konrad M\xFChler) +// \date 03.06.1998, implemented by Michael Neumann +// \date 2005-07-05 +// +*/ +//---------------------------------------------------------------------------------- + + +# ifndef __HASHTABLE_HEADER__ +# define __HASHTABLE_HEADER__ + + +#include <string> +#include <list> + +#pragma warning (disable : 4706) + +template<class attrType> +class HashTable { +public: + + struct R + { + R() {} + R(const std::string& s, const attrType& a) : str(s), attr(a) {} + std::string str; + attrType attr; + bool operator <(const R& r) {return r.str < str;} + bool operator ==(const R& r) {return r.str == str;} + }; + + + HashTable(int sz=2017) // sz should be a prime + { + table = new list<R>[size=sz]; + if(!table) throw MemoryException(); + } + + + ~HashTable() + { + delete[] table; + } + + + bool insert(const std::string& str, const attrType& attr) + { + + int i=hash(str); + list<R>::iterator b = table[i].begin(); + while( b != table[i].end() ) + { + if( (*b).str == str ) return false; + ++b; + } + table[i].push_front(R(str,attr)); + return true; + } + + + bool remove(const std::string& str) + { + int i=hash(str); + list<R>::iterator b = table[i].begin(); + while( b != table[i].end() ) + { + if( (*b).str == str ) + { + table[i].erase(b); + return true; + } + ++b; + } + return false; + } + + + attrType* find(const std::string& str) + { + int i=hash(str); + list<R>::iterator b = table[i].begin(); + while( b != table[i].end() ) + { + if( (*b).str == str ) return &(*b).attr; + ++b; + } + return 0; + } + + + list<R> *getTable() + { + return table; + } + + + int getSize() + { + return size; + } + + class MemoryException {}; + + + +private: + + int size; + list<R> *table; + + + int hash(const std::string& str) + { + unsigned h=0, g; + for(size_t i=0;i<str.length();++i) + { + h = (h << 4)+ str[i]; + if(g=h&0xf0000000) + { + h ^= g>>24; + h ^= g; + } + } + return h%size; // size is table-size + } + +}; + +#pragma warning ( default : 4706) + +#endif \ No newline at end of file Added: trunk/Community/METK/Sources/common/ObjMgrCommunicator.cpp =================================================================== --- trunk/Community/METK/Sources/common/ObjMgrCommunicator.cpp (rev 0) +++ trunk/Community/METK/Sources/common/ObjMgrCommunicator.cpp 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,251 @@ +// Local includes +#include "ObjMgrCommunicator.h" + +ML_START_NAMESPACE + +//! Implements code for the runtime type system of the ML +ML_CLASS_SOURCE(ObjMgrCommunicator,ObjMgrClient); + + +ObjMgrCommunicator::ObjMgrCommunicator(void) : inherited(0,0,ObjMgrClient::EVENTS_NONE) +{ + +} + + +void ObjMgrCommunicator::handleObjMgrNotification() +{ + omEventContainer myEventList = getEventContainer(); + + //Durchiterieren der EventList + omEventContainer::const_iterator iter; + for ( iter = myEventList.begin();iter!=myEventList.end(); iter++) + { + ObjMgrEvent myEvent = (*iter); + + //if (myEvent.objectID==fldAnimationViewerName->getStringValue() && myEvent.layerID==LAY_VIEWER_PROPERTIES && myEvent.infoID==INF_VIEWER_PROPERTIES_VIEWERSTATUS) + } + clearEventContainer(); +} + +//!Set the value of an attribute in the ObjMgr-DB - no Notification will be send +void ObjMgrCommunicator::setObjAttribute(const string ObjID, const string LayerID, const string InfoID, void* value, const string omInfoType, const bool createIfNotExists, const bool persistent, const bool ignoreType) +{ + // Get writable access to object container + bool attrCreated = false; + omObjectContainer* oc = getObjContainer(); + if(oc == NULL) + { + kDebug::Debug("ObjContainer not found!",kDebug::DL_LOW); + } + else + { + if (!(*oc).exists(ObjID) && !createIfNotExists) + { + kDebug::Debug("invalidObject "+ObjID,kDebug::DL_LOW); + } + else + { + omObject& obj = (*oc)[ObjID]; + + + omAttribute& attr = obj.getAttribute(LayerID,InfoID); + + if (!obj.hasAttribute(LayerID,InfoID) && createIfNotExists) + { + attr.createDataType(omInfoType); + attrCreated = true; + } + if (obj.hasAttribute(LayerID,InfoID)) + { + if (string(attr.getDataType()->getName())!=omInfoType && !ignoreType) + { + obj.removeAttribute(LayerID,InfoID); + attr.createDataType(omInfoType); + attrCreated = true; + } + } + + attr.flags().markPersistent(persistent); + + //Diese Sache mit den void*-Pointern zur Verallgemeinerung wird uns irgendwann mal m\xE4chtig um die Ohren fliegen ... + if (omInfoType == omINFOTYPE_STRING) + { + obj[LayerID][InfoID].setStringValue(*((string *)value)); + } + else if (omInfoType == omINFOTYPE_DOUBLE) + { + const double oldV = obj[LayerID][InfoID]; + const double newV = *((double *)value); + if (fabs(oldV-newV)>=0.000001f || attrCreated) + obj[LayerID][InfoID] = *((double *)value); + } + else if (omInfoType == omINFOTYPE_INT32) + { + const double oldV = obj[LayerID][InfoID]; + const double newV = *((int *)value); + if (fabs(oldV-newV)>=0 || attrCreated) + obj[LayerID][InfoID] = *((int *)value); + } + else if (omInfoType == omINFOTYPE_VEC3) + { + const vec3 tempVec3 = *(vec3*)value; + const SbVec3f oldV = SbVec3f(double(((vec3)obj[LayerID][InfoID])[0]),double(((vec3)obj[LayerID][InfoID])[1]),double(((vec3)obj[LayerID][InfoID])[2])); + const SbVec3f newV = SbVec3f(double(tempVec3[0]),double(tempVec3[1]),double(tempVec3[2])); + + if(kBasics::maxDiff(oldV,newV)>=0.000001f || attrCreated) + { + obj[LayerID][InfoID] = tempVec3; + } + } + else if (omInfoType == omINFOTYPE_VEC4) + { + const vec4 tempVec4 = *(vec4*)value; + const SbVec4f oldV = SbVec4f(((vec4)obj[LayerID][InfoID])[0],((vec4)obj[LayerID][InfoID])[1],((vec4)obj[LayerID][InfoID])[2],((vec4)obj[LayerID][InfoID])[3]); + const SbVec4f newV = SbVec4f(tempVec4[0],tempVec4[1],tempVec4[2],tempVec4[3]); + + if (kBasics::maxDiff(oldV,newV)>=0.000001f || attrCreated) + obj[LayerID][InfoID] = tempVec4; + } + else if (omInfoType == omINFOTYPE_BOOL) + { + const bool oldV = obj[LayerID][InfoID]; + if (oldV!=*(bool *)value || attrCreated) + obj[LayerID][InfoID] = *(bool *)value; + } + else if (omInfoType == omINFOTYPE_MESSAGE) + { + obj[LayerID][InfoID] = *((omMessage *)value); + } + } + + } +} + + +bool ObjMgrCommunicator::getObjAttribute(const string ObjID, const string LayerID, const string InfoID, omAttribute& attr) +{ + const omObjectContainer *oc= getConstObjContainer(); + if(oc == NULL) + { + kDebug::Debug("ObjContainer not found!",kDebug::DL_LOW); + } + else + { + if (!(*oc).exists(ObjID)) + { + kDebug::Debug("invalidObject",kDebug::DL_LOW); + } + else + { + // Get read-only access to object with given ID. + const omObject &obj= (*oc)[ObjID]; + if (obj.hasAttribute(LayerID,InfoID)) + { + attr = obj.getAttribute(LayerID,InfoID); + return true; + } + } + } + return false; +} + + + +bool ObjMgrCommunicator::getObjAttributeVec3f(const string ObjID, const string LayerID, const string InfoID, SbVec3f& vec3f) +{ + omAttribute attr; + if (getObjAttribute(ObjID,LayerID,InfoID, attr)) + { + vector<string> VecSplit; + kBasics::split(attr.getStringValue(),' ',3,&VecSplit); + + if (VecSplit.size()!=3) + { + kDebug::Debug("WrongSplitSize: " + kBasics::IntToString(VecSplit.size()),kDebug::DL_HIGH); + return false; + } + + vec3f.setValue(kBasics::StringToFloat(VecSplit[0]),kBasics::StringToFloat(VecSplit[1]),kBasics::StringToFloat(VecSplit[2])); + return true; + } + return false; +} + + + +bool ObjMgrCommunicator::getObjAttributeVec4f(const string ObjID, const string LayerID, const string InfoID, SbVec4f& vec4f) +{ + omAttribute attr; + if (getObjAttribute(ObjID,LayerID,InfoID, attr)) + { + vector<string> VecSplit; + kBasics::split(attr.getStringValue(),' ',4,&VecSplit); + + if (VecSplit.size()!=4) + { + kDebug::Debug("WrongSplitSize: " + kBasics::IntToString(VecSplit.size()),kDebug::DL_HIGH); + return false; + } + + vec4f.setValue(kBasics::StringToFloat(VecSplit[0]),kBasics::StringToFloat(VecSplit[1]),kBasics::StringToFloat(VecSplit[2]),kBasics::StringToFloat(VecSplit[3])); + return true; + } + return false; +} + + + +bool ObjMgrCommunicator::getObjAttributeString(const string ObjID, const string LayerID, const string InfoID, string& value) +{ + omAttribute attr; + if (getObjAttribute(ObjID,LayerID,InfoID, attr)) + { + value = attr.getStringValue(); + return true; + } + return false; +} + + + +bool ObjMgrCommunicator::getObjAttributeFloat(const string ObjID, const string LayerID, const string InfoID, float& value) +{ + omAttribute attr; + if (getObjAttribute(ObjID,LayerID,InfoID, attr)) + { + value = kBasics::StringToFloat(attr.getStringValue()); + return true; + } + return false; +} + + + +bool ObjMgrCommunicator::getObjAttributeInt(const string ObjID, const string LayerID, const string InfoID, int& value) +{ + omAttribute attr; + if (getObjAttribute(ObjID,LayerID,InfoID, attr)) + { + value = kBasics::StringToInt(attr.getStringValue()); + return true; + } + return false; +} + + + +bool ObjMgrCommunicator::getObjAttributeBool(const string ObjID, const string LayerID, const string InfoID, bool& value) +{ + omAttribute attr; + value = false; + if (getObjAttribute(ObjID,LayerID,InfoID, attr)) + { + value = kBasics::StringToBool(attr.getStringValue()); + return true; + } + return false; +} + + +ML_END_NAMESPACE Added: trunk/Community/METK/Sources/common/ObjMgrCommunicator.h =================================================================== --- trunk/Community/METK/Sources/common/ObjMgrCommunicator.h (rev 0) +++ trunk/Community/METK/Sources/common/ObjMgrCommunicator.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,72 @@ +//---------------------------------------------------------------------------------- +//! Class to handle communication with ObjMgr via get and set functions +/*! +// \file ObjMgrCommunicator.h +// \author Konrad M\xFChler +// \date 2006-11-02 +// +// +*/ +//---------------------------------------------------------------------------------- + + +#ifndef __ObjMgrCommunicator_H +#define __ObjMgrCommunicator_H + + +#pragma warning(disable:4251) +#ifndef common_EXPORTS +#define __COMMON_IMPORTEXPORT __declspec(dllimport) +#else +#define __COMMON_IMPORTEXPORT __declspec(dllexport) +#endif + +// ML includes +#ifndef __mlOperatorIncludes_H +#include "mlOperatorIncludes.h" +#endif + +#include "XVEnterScope.h" +#include <Inventor/nodes/SoCube.h> +#include <Inventor/nodes/SoPerspectiveCamera.h> +#include <Inventor/sensors/SoTimerSensor.h> +#include <Inventor/sensors/SoNodeSensor.h> +#include "XVLeaveScope.h" + +#include <ObjMgr/mlObjMgrClient.h> + +#include "kBasics.h" +#include "kDebug.h" + +ML_START_NAMESPACE + +class __COMMON_IMPORTEXPORT ObjMgrCommunicator : public ObjMgrClient +{ +public: + + ObjMgrCommunicator (void); + + virtual void handleObjMgrNotification(); + + void setObjAttribute(const string ObjID, const string LayerID, const string InfoID, void* value, const string omInfoType, const bool createIfNotExists, const bool persistent, const bool ignoreType=false); + bool getObjAttribute(const string ObjID, const string LayerID, const string InfoID, omAttribute& attr); + bool getObjAttributeVec3f(const string ObjID, const string LayerID, const string InfoID, SbVec3f& vec3f); + bool getObjAttributeVec4f(const string ObjID, const string LayerID, const string InfoID, SbVec4f& vec4f); + bool getObjAttributeString(const string ObjID, const string LayerID, const string InfoID, string& value); + bool getObjAttributeFloat(const string ObjID, const string LayerID, const string InfoID, float& value); + bool getObjAttributeInt(const string ObjID, const string LayerID, const string InfoID, int& value); + bool getObjAttributeBool(const string ObjID, const string LayerID, const string InfoID, bool& value); + +private: + + typedef ObjMgrClient inherited; + + ML_CLASS_HEADER(ObjMgrCommunicator) + +}; + + +ML_END_NAMESPACE + + +#endif // __ObjMgrCommunicator_H \ No newline at end of file Added: trunk/Community/METK/Sources/common/StdAfx.cpp =================================================================== --- trunk/Community/METK/Sources/common/StdAfx.cpp (rev 0) +++ trunk/Community/METK/Sources/common/StdAfx.cpp 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,8 @@ +// stdafx.cpp : Quelltextdatei, die nur die Standard-Includes einbindet +// AnimationParserDLL.pch ist die vorkompilierte Header-Datei +// stdafx.obj enth\xE4lt die vorkompilierte Typinformation + +#include "stdafx.h" + +// ZU ERLEDIGEN: Verweis auf alle zus\xE4tzlichen Header-Dateien, die Sie in STDAFX.H +// und nicht in dieser Datei ben\xF6tigen Added: trunk/Community/METK/Sources/common/StdAfx.h =================================================================== --- trunk/Community/METK/Sources/common/StdAfx.h (rev 0) +++ trunk/Community/METK/Sources/common/StdAfx.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,24 @@ +// stdafx.h : Include-Datei f\xFCr Standard-System-Include-Dateien, +// oder projektspezifische Include-Dateien, die h\xE4ufig benutzt, aber +// in unregelm\xE4\xDFigen Abst\xE4nden ge\xE4ndert werden. +// + +#if !defined(AFX_STDAFX_H__B4C4A995_C8B1_40C7_9A03_30372D9ACD0A__INCLUDED_) +#define AFX_STDAFX_H__B4C4A995_C8B1_40C7_9A03_30372D9ACD0A__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +// F\xFCgen Sie hier Ihre Header-Dateien ein +#define WIN32_LEAN_AND_MEAN // Selten benutzte Teile der Windows-Header nicht einbinden + +#include <windows.h> + +// ZU ERLEDIGEN: Verweisen Sie hier auf zus\xE4tzliche Header-Dateien, die Ihr Programm ben\xF6tigt + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ f\xFCgt zus\xE4tzliche Deklarationen unmittelbar vor der vorherigen Zeile ein. + +#endif // !defined(AFX_STDAFX_H__B4C4A995_C8B1_40C7_9A03_30372D9ACD0A__INCLUDED_) Added: trunk/Community/METK/Sources/common/StrList.h =================================================================== --- trunk/Community/METK/Sources/common/StrList.h (rev 0) +++ trunk/Community/METK/Sources/common/StrList.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,63 @@ +# ifndef __STRLIST_HEADER__ +# define __STRLIST_HEADER__ + + +#pragma warning(disable:4251) +#ifndef common_EXPORTS +#define __COMMON_IMPORTEXPORT __declspec(dllimport) +#else +#define __COMMON_IMPORTEXPORT __declspec(dllexport) +#endif + +# include <string> +# include <list> + +using namespace std; + +class __COMMON_IMPORTEXPORT StrList +{ + +public: + + StrList() + { + } + + + ~StrList() + { + } + + + + void add(string value) + { + stringList.push_back(value); + } + + void remove(string value) + { + list<string>::iterator iter; + for (iter = stringList.begin(); iter!=stringList.end(); iter++) + { + if ((string)(*iter) == value) + { + stringList.erase(iter); + return; + } + } + } + + int getSize() + { + return stringList.size(); + } + + +private: + list<string> stringList; + +}; + +#endif + Added: trunk/Community/METK/Sources/common/XMLParser.cpp =================================================================== --- trunk/Community/METK/Sources/common/XMLParser.cpp (rev 0) +++ trunk/Community/METK/Sources/common/XMLParser.cpp 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,264 @@ +#include "stdafx.h" +#include "XMLParser.h" + + +XMLParserErrorHandler::XMLParserErrorHandler() : fSawErrors(false) +{ +} + +XMLParserErrorHandler::~XMLParserErrorHandler() +{ +} + + +bool XMLParserErrorHandler::getSawErrors() const +{ + return fSawErrors; +} + + +bool XMLParserErrorHandler::handleError(const DOMError& domError) +{ + fSawErrors = true; + if (domError.getSeverity() == DOMError::DOM_SEVERITY_WARNING) + std::cerr << "\nWarning at file "; + else if (domError.getSeverity() == DOMError::DOM_SEVERITY_ERROR) + std::cerr << "\nError at file "; + else + std::cerr << "\nFatal Error at file "; + + std::cerr << domError.getLocation()->getURI() + << ", line " << domError.getLocation()->getLineNumber() + << ", char " << domError.getLocation()->getColumnNumber() + << "\n Message: " << domError.getMessage() << std::endl; + + return true; +} + + +void XMLParserErrorHandler::resetErrors() +{ + fSawErrors = false; +} + + +int XMLParser::parseXMLFile(const char* XMLFileName) +{ + bool errorOccurred = false; + + // Initialize the XML4C system + try + { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) + { + std::cerr << "Error during initialization! :\n" << toCatch.getMessage() << std::endl; + return 1; + } + + + // Instantiate the DOM parser. + static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; + + impl = DOMImplementationRegistry::getDOMImplementation(gLS); + parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0); + + + parser->setFeature(XMLUni::fgDOMNamespaces, false); + parser->setFeature(XMLUni::fgXercesSchema, false); + parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false); + + // enable datatype normalization - default is off + parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true); + + // And create our error handler and install it + XMLParserErrorHandler errorHandler; + parser->setErrorHandler(&errorHandler); + + + bool more = true; + std::ifstream file_input; + + file_input.open(XMLFileName); + + if (file_input.fail()) + { + std::cerr <<"Cannot open the file: " << XMLFileName << std::endl; + return 2; + } + + while (more) + { + char fURI[1000]; + //initialize the array to zeros + memset(fURI,0,sizeof(fURI)); + + more = false; + + //reset error count first + errorHandler.resetErrors(); + + try + { + // reset document pool + parser->resetDocumentPool(); + + + xml_doc = parser->parseURI(XMLFileName); + + } + catch (const XMLException& toCatch) + { + std::cerr << "\nError during parsing: '" << XMLFileName << "'\n" + << "Exception message is: \n" << toCatch.getMessage() << "\n" << std::endl; + errorOccurred = true; + continue; + } + catch (const DOMException& toCatch) + { + const unsigned int maxChars = 2047; + XMLCh errText[maxChars + 1]; + + std::cerr << "\nDOM Error during parsing: '" << XMLFileName << "'\n" + << "DOMException code is: " << toCatch.code << std::endl; + + if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars)) + std::cerr << "Message is: " << errText << std::endl; + + errorOccurred = true; + continue; + } + catch (...) + { + std::cerr << "\nUnexpected exception during parsing: '" << XMLFileName << "'\n"; + errorOccurred = true; + continue; + } + + + // Extract the DOM tree, get the list of all the elements and report the length as the count of elements. + if (errorHandler.getSawErrors()) + { + std::cerr << "\nErrors occurred, no output available\n" << std::endl; + errorOccurred = true; + } + else + { + //unsigned int elementCount = 0; + if (xml_doc) + { + rootNode =(DOMNode*)xml_doc->getDocumentElement(); + } + } + } + + file_input.close(); + + if (errorOccurred) return 4; + else return 0; +} + + + +int XMLParser::parseXMLString(const std::string* xmlString) +{ + bool errorOccurred = false; + + // Initialize the XML4C system + try + { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) + { + std::cerr << "Error during initialization! :\n" << toCatch.getMessage() << std::endl; + return 1; + } + + + // Instantiate the DOM parser. + static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; + + impl = DOMImplementationRegistry::getDOMImplementation(gLS); + //parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0); + +/* + MemBufInputSource *isource = new MemBufInputSource( (const XMLByte*)xmlString->c_str(), strlen(xmlString->c_str()), "XMLBuffer", false); + if (isource == NULL) return; + + XercesDOMParser* parser = new XercesDOMParser; + parser->parse(*isource); + DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Range")); + DOMDocument* doc = 0; + + try + { + doc = parser->getDocument(); + } + + */ + + MemBufInputSource *isource = new MemBufInputSource( (const XMLByte*)xmlString->c_str(), strlen(xmlString->c_str()), "XMLBuffer", false); + if (isource == NULL) return 5; + XercesDOMParser* parser2 = new XercesDOMParser; + + + //bool more = true; + + try + { + // reset document pool + parser2->resetDocumentPool(); + parser2->parse(*isource); + xml_doc = parser2->getDocument(); + + if (xml_doc==NULL) std::cout << "xml_doc==NULL!!!!" << std::endl; + DOMElement* root = 0; + root = xml_doc->getDocumentElement(); + } + catch (const XMLException& toCatch) + { + std::cerr << "\nError during parsing a xmlString\n" + << "Exception message is: \n" << toCatch.getMessage() << "\n" << std::endl; + errorOccurred = true; + } + catch (const DOMException& toCatch) + { + const unsigned int maxChars = 2047; + XMLCh errText[maxChars + 1]; + + std::cerr << "\nDOM Error during parsing a xmlString\n" + << "DOMException code is: " << toCatch.code << std::endl; + + if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars)) + std::cerr << "Message is: " << errText << std::endl; + + errorOccurred = true; + } + catch (...) + { + std::cerr << "\nUnexpected exception during parsing a xmlString\n"; + errorOccurred = true; + } + + // Extract the DOM tree, get the list of all the elements and report the length as the count of elements. + //unsigned int elementCount = 0; + if (xml_doc) + { + rootNode =(DOMNode*)xml_doc->getDocumentElement(); + } + + if (errorOccurred) return 4; + return 0; +} + + +XMLParser::~XMLParser() +{ + // Delete the parser itself. Must be done prior to calling Terminate, below. + parser->release(); + + // And call the termination method + XMLPlatformUtils::Terminate(); +} \ No newline at end of file Added: trunk/Community/METK/Sources/common/XMLParser.h =================================================================== --- trunk/Community/METK/Sources/common/XMLParser.h (rev 0) +++ trunk/Community/METK/Sources/common/XMLParser.h 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,79 @@ +//XMLParser.h + +#ifndef _XMLParser_ +#define _XMLParser_ + +#pragma warning(disable:4251) +#ifndef common_EXPORTS +#define __COMMON_IMPORTEXPORT __declspec(dllimport) +#else +#define __COMMON_IMPORTEXPORT __declspec(dllexport) +#endif + +#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/parsers/AbstractDOMParser.hpp> +#include <xercesc/dom/DOMImplementation.hpp> +#include <xercesc/dom/DOMImplementationLS.hpp> +#include <xercesc/dom/DOMImplementationRegistry.hpp> +#include <xercesc/dom/DOMBuilder.hpp> +#include <xercesc/dom/DOMException.hpp> +#include <xercesc/dom/DOMDocument.hpp> +#include <xercesc/dom/DOMNodeList.hpp> +#include <xercesc/dom/DOMError.hpp> +#include <xercesc/dom/DOMLocator.hpp> +#include <xercesc/dom/DOMNamedNodeMap.hpp> +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMErrorHandler.hpp> +#include <xercesc/util/XMLString.hpp> +#include <xercesc/framework/MemBufInputSource.hpp> +#include <xercesc/parsers/XercesDOMParser.hpp> + +#include <iostream> +#include <fstream> +#include <string> + +XERCES_CPP_NAMESPACE_USE + + +// Simple error handler deriviative to install on parser +class __COMMON_IMPORTEXPORT XMLParserErrorHandler : public DOMErrorHandler +{ +public: + XMLParserErrorHandler(); + ~XMLParserErrorHandler(); + + bool getSawErrors() const; + bool handleError(const DOMError& domError); + void resetErrors(); + +private : + XMLParserErrorHandler(const XMLParserErrorHandler&); + void operator=(const XMLParserErrorHandler&); + bool fSawErrors; //This is set if we get any errors +}; + + + +class __COMMON_IMPORTEXPORT XMLParser +{ +private: + DOMImplementation *impl; + DOMBuilder *parser; + XERCES_CPP_NAMESPACE::DOMDocument* xml_doc; + DOMNode* rootNode; + +public: + XMLParser() { } + ~XMLParser(); + + + DOMNode* getRootNode() { return rootNode; } + + int parseXMLFile(const char*); + int parseXMLString(const std::string* xmlString); + + int XMLParser::countChildElements(DOMNode *n); +}; + + +#endif // _XMLParser_ \ No newline at end of file Added: trunk/Community/METK/Sources/common/common.bat =================================================================== --- trunk/Community/METK/Sources/common/common.bat (rev 0) +++ trunk/Community/METK/Sources/common/common.bat 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,3 @@ +"%MLAB_ROOT%\MeVis\Foundation\BuildTools\Scripts\createProject.bat" common + + Added: trunk/Community/METK/Sources/common/common.pro =================================================================== --- trunk/Community/METK/Sources/common/common.pro (rev 0) +++ trunk/Community/METK/Sources/common/common.pro 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,49 @@ +# --------- common profile ------------------- +# +# Platform independent project and build file for +# project common. +# + +TEMPLATE = lib + +TARGET = common + +DESTDIR = ../../lib +DLLDESTDIR = ../../lib + +# add used packages here (see stdPackages.pro for packages): +CONFIG += dll inventor xerces ML MLObjMgr +MLAB_PACKAGES += MeVisLab_Standard + +# set high warn level (warn 4 on MSCV) +WARN = HIGH + +# DONT REMOVE THE FOLLOWING LINE: +include ($(MLAB_MeVis_Foundation)/Configuration/IncludePackages.pri) + + +DEFINES += common_EXPORTS + +HEADERS += \ + HashTable.h \ + kBasics.h \ + kCamera.h \ + #kObjMgrAttr.h \ + StdAfx.h \ + StrList.h \ + XMLParser.h \ + kSphere.h \ + kDebug.h \ + ObjMgrCommunicator.h \ + matrix.h \ + image_basic.h + +SOURCES += \ + kBasics.cpp \ + kCamera.cpp \ + StdAfx.cpp \ + XMLParser.cpp \ + kSphere.cpp \ + kDebug.cpp \ + ObjMgrCommunicator.cpp \ + image_basic.cpp \ No newline at end of file Added: trunk/Community/METK/Sources/common/image_basic.cpp =================================================================== --- trunk/Community/METK/Sources/common/image_basic.cpp (rev 0) +++ trunk/Community/METK/Sources/common/image_basic.cpp 2009-06-16 06:50:44 UTC (rev 65) @@ -0,0 +1,1782 @@ + +#include <cmath> +#include "image_basic.h" + +#define TIFF_LITTLE_ENDIAN 1 +#define TIFF_BIG_ENDIAN 0 + +#define TIFF_SHORT 3 +#define TIFF_LONG 4 +#define TIFF_RATIONAL 5 +using namespace std; + +image_basic::image_basic() +{ + color_mode = GRAY_8BPP; + width = 0; + height = 0; + // data.free(); +} +image_basic::image_basic(unsigned int size_x, unsigned int size_y, int set_color_mode) +{ + width = size_x; + height = size_y; + data.resize(width * height); + color_mode = set_color_mode; +} +image_basic::image_basic(const rect_range &range, int set_color_mode) +{ + width = abs(range.x2 - range.x1 + 1); + height = abs(range.y2 - range.y1 + 1); + data.resize(width * height); + color_mode = set_color_mode; +} +void image_basic::initialize(unsigned int size_x, unsigned int size_y, int set_color_mode) +{ + width = size_x; + height = size_y; + data.resize(width * height); + erase(); + if(set_color_mode != NULL) + color_mode = set_color_mode; +} +void image_basic::initialize(const rect_range &range, int set_color_mode) +{ + width = abs(range.x2 - range.x1 + 1); + height = abs(range.y2 - range.y1 + 1); + data.resize(width * height); + erase(); + if(set_color_mode != NULL) + color_mode = set_color_mode; +} +void image_basic::erase(void) +{ + data = 0; +} +int image_basic::empty(void) +{ + if(width == 0 || height == 0) + return 1; + else + return 0; +} +image_basic::~image_basic() +{ + //data.free(); +} +int image_basic::file_read(const std::string &filename) +{ + ifstream file; + unsigned char buffer[4]; + + file.open(filename.c_str() , ios_base::in | ios_base::binary); + if(file.fail()){ + cerr << "[image_basic::file_read] Error opening " << filename << endl; + return -1; + } + file.read((char*)buffer, 4); + if(file.fail()){ + cerr << "[image_basic::file_read] Error reading " << filename << endl; + return -1; + } + file.close(); + + if((buffer[0] == 0x49 && buffer[1] == 0x49) || (buffer[0] == 0x4d && buffer[1] == 0x4d)){ + if(file_read_tiff(filename)) + return -1; + } else if(buffer[0] == 'B' && buffer[1] == 'M'){ + if(file_read_bitmap(filename)) + return -1; + } else if(buffer[0] == 'P' && buffer[1] == '5'){ + if(file_read_pgm(filename)) + return -1; + } else { + cerr << "[image_basic::file_read] " << filename << " format is not supported" << endl; + return -1; + } + + return 0; +} +int image_basic::file_read_pgm(const std::string &filename) +{ + ifstream file; + unsigned char buffer[256]; + int flag, position_begin, position_end, value[3], x, y, offset_row; + std::string line; + + file.open(filename.c_str() , ios_base::in | ios_base::binary); + if(file.fail()){ + cerr << "[image_basic::file_read_pgm] Error opening " << filename << endl; + return -1; + } + file.getline((char *)buffer, 256); + if(file.fail()){ + cerr << "[image_basic::file_read_pgm] Error reading " << filename << endl; + return -1; + } + if(buffer[0] != 'P' || buffer[1] != '5'){ + cerr << "[image_basic::file_read_pgm] "<< filename << "is not a raw pgm file"<< endl; + return -1; + } + cout << "[image_basic::file_read_pgm] " << filename << "... "; + flag = 0; + position_begin = 2; + while(flag != 3){ + if(buffer[position_begin] == '\0' || buffer[0] == '#'){ + file.getline((char*)buffer, 256); + if(file.fail()){ + cerr << "[image_basic::file_read_pgm] Error reading " << filename << endl; + return -1; + } + position_begin = 0; + continue; + } + for( ; (isdigit(buffer[position_begin]) == 0) && position_begin < 256 ; position_begin++) + if(buffer[position_begin] == '\0') + continue; + for(position_end = position_begin; isdigit(buffer[position_end]) && position_end < 256; position_end++) + ; + value[flag] = atoi((const char*)&buffer[position_begin]); + flag++; + position_begin = position_end; + } + + width = value[0]; + height = value[1]; + if(value[2] < 0 || value[2] > 255){ + cerr << "[image_basic::file_read_pgm] Maximum value of " << filename << "should be 0-255" << endl; + return -1; + } + data.resize(width * height); + color_mode = GRAY_8BPP; + for(y = height - 1; y >= 0; y--){ + offset_row = y * width; + for(x = 0; (unsigned int)x < width; x++){ + file.read((char *)buffer, 1); + data[offset_row + x] = (int)buffer[0]; + } + } + if(file.fail()){ + cerr << "[image_basic::file_read_pgm] Error reading " << filename << endl; + return -1; + } + cout << width << "*" << height << " 8bpp" << endl; + + return 0; +} +inline unsigned short image_basic::byte_short(unsigned char *buffer, bool endian) +{ + if(endian) // == TIFF_LITTLE_ENDIAN + return ((short)buffer[1] << 8) | (short)buffer[0]; + else + return ((short)buffer[0] << 8) | (short)buffer[1]; +} +inline unsigned long image_basic::byte_long(unsigned char *buffer, bool endian) +{ + if(endian) // == TIFF_LITTLE_ENDIAN + return ((long)buffer[3] << 24) | ((long)buffer[2] << 16) | ((long)buffer[1] << 8) | (long)buffer[0]; + else + return ((long)buffer[0] << 24) | ((long)buffer[1] << 16) | ((long)buffer[2] << 8) | (long)buffer[3]; +} +int image_basic::file_read_tiff(const std::string &filename) +{ + ifstream file; + unsigned long ifd_offset, parameter_offset, height_strip = 0; + unsigned char buffer[12]; + unsigned short ifd_tag, ifd_count, strip_count = 0; + valarray<unsigned long> strip_offset; + int i, j, x, y, y_strip, offset_row; + bool endian; + + file.open(filename.c_str() , ios_base::in | ios_base::binary); + if(file.fail()){ + cerr << "[image_basic::file_read_tiff] Error opening " << filename << endl; + return -1; + } + + file.seekg(0, ios_base::beg); + file.read((char*)buffer, 4); + if(file.fail()){ + cerr << "[image_basic::file_read_tiff] Error reading " << filename << endl; + return -1; + } + + if(buffer[0] == 0x49 && buffer[1] == 0x49){ + endian = TIFF_LITTLE_ENDIAN; + cout << "[image_basic::file_read_tiff] " << filename << "(little endian)..." << endl; + } else if(buffer[0] == 0x4d && buffer[1] == 0x4d){ + endian = TIFF_BIG_ENDIAN; + cout << "[image_basic::file_read_tiff] " << filename << "(big endian)..." << endl; + } else { + cerr << "[image_basic::file_read_tiff] " << filename << " is not a TIFF file" << endl; + return -1; + } + if(byte_short(&buffer[2], endian) != 0x002a){ + cerr << "[image_basic::file_read_tiff] " << filename << " is not a TIFF file" << endl; + return -1; + } + file.read((char*)buffer, 4); + ifd_offset = byte_long(buffer, endian); + file.seekg(ifd_offset, ios_base::beg); + file.read((char*)buffer, 2); + ifd_count = byte_short(buffer, endian); + for(j = 0; j < ifd_count; j++){ + file.seekg(ifd_offset + 2 + j * 12, ios_base::beg); + file.read((char*)buffer, 12); + ifd_tag = byte_short(buffer, endian); + switch(ifd_tag){ + case 0x0100: // TIFF image width + if(byte_long(&buffer[4], endian) != 1){ + cerr << "[image_basic::file_read_tiff] Number of width paramerter should be 1" << endl; + return -1; + } + switch(byte_short(&buffer[2], endian)){ + case TIFF_SHORT: + width = byte_short(&buffer[8], endian); + break; + case TIFF_LONG: + width = byte_long(&buffer[8], endian); + break; + default: + cerr << "[image_basic::file_read_tiff] Width should be either long or short integer" << endl; + return -1; + } + // cout << "width " << width << endl; + break; + + case 0x0101: // TIFF image height + if(byte_long(&buffer[4], endian) != 1){ + cerr << "[image_basic::file_read_tiff] Number of height paramerter should be 1" << endl; + return -1; + } + switch(byte_short(&buffer[2], endian)){ + case TIFF_SHORT: + height = byte_short(&buffer[8], endian); + break; + case TIFF_LONG: + height = byte_long(&buffer[8], endian); + break; + default: + cerr << "[image_basic::file_read_tiff] Height should be either long or short integer" << endl; + return -1; + } + // cout << "height " << height << endl; + break; + case 0x0102: // TIFF image BPP + if(byte_short(&buffer[2], endian) != TIFF_SHORT){ + cerr << "[image_basic::file_read_tiff] BPP should be s... [truncated message content] |