jan p. springer said the following on 11/02/06 12:52:
[ snip ]
> if someone could provide the minimal skeleton for an opensg 2.0 loader (or
> point me to it since i didn't look too hard) i would try to prototype a
> .trans and a .verify pseudo loader; if no-one objects that is.
[ snip ]

follow-up to myself; there are several problems to be solved:

- SceneFileHandler seems to be (a bit) too intelligent for this; it checks
  the existence of the file in the filesystem for a given file name before
  handing it over to the actual loader; how could this be changed (sanely)?

- i've fleshed out the .obj loader, get it compiled, linked, and registered
  as a .trans loader. however the call interface for read is an istream and
  a Char8*, the former does not help in the case of adding a node based on
  the file's name and the latter is called "fileNameOrExtension", so chances
  are it will not contain useful information.

- minor nitpick: why are all the string arguments passed as const Char8*?
  wouldn't const std::string& be the better choice?

for those interested i've attached a (na\"ive) implementation for .trans.

regards,

        j.

-- 
+------------------------------------+--------------------------------------+
| jan p. springer                    | [EMAIL PROTECTED]                       |
| computer science, buw.media.vrsys  | [EMAIL PROTECTED]    |
+------------------------------------+--------------------------------------+
/*---------------------------------------------------------------------------*\
 *                                OpenSG                                     *
 *                                                                           *
 *                                                                           *
 *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
 *                                                                           *
 *                            www.opensg.org                                 *
 *                                                                           *
 *   contact: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]          *
 *                                                                           *
 \*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
 *                                License                                    *
 *                                                                           *
 * This library is free software; you can redistribute it and/or modify it   *
 * under the terms of the GNU Library General Public License as published    *
 * by the Free Software Foundation, version 2.                               *
 *                                                                           *
 * This library is distributed in the hope that it will be useful, but       *
 * WITHOUT ANY WARRANTY; without even the implied warranty of                *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Library General Public License for more details.                          *
 *                                                                           *
 * You should have received a copy of the GNU Library General Public         *
 * License along with this library; if not, write to the Free Software       *
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
 *                                                                           *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
 *                                Changes                                    *
 *                                                                           *
\*---------------------------------------------------------------------------*/

#ifndef _OSGTRANSSCENEFILETYPE_H_
#define _OSGTRANSSCENEFILETYPE_H_
#ifdef  __sgi
#pragma  once
#endif

#include "OpenSG/OSGFileIODef.h"
#include "OpenSG/OSGBaseTypes.h"
#include "OpenSG/OSGSceneFileType.h"


OSG_BEGIN_NAMESPACE

/*! \brief OBJSceneFileType
*/

class OSG_FILEIO_DLLMAPPING TransSceneFileType : public SceneFileType
{
    /*==========================  PUBLIC  =================================*/
  public:

    /*---------------------------------------------------------------------*/
    /*! \name                   Class Get                                  */
    /*! \{                                                                 */

    static TransSceneFileType &the(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Destructors                                */
    /*! \{                                                                 */

    virtual ~TransSceneFileType(void);

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Get                                        */
    /*! \{                                                                 */

    virtual const Char8 *getName(void) const;

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Read                                       */
    /*! \{                                                                 */

    virtual NodePtr read(std::istream &is,
                         const Char8 *fileNameOrExtension) const;

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Write                                      */
    /*! \{                                                                 */

    virtual bool write(const NodePtr      &node, 
                             std::ostream &os,
                       const Char8        *fileNameOrExtension) const;

    /*! \}                                                                 */
    /*=========================  PROTECTED  ===============================*/
  protected:

    /*---------------------------------------------------------------------*/
    /*! \name                      Member                                  */
    /*! \{                                                                 */

    static const Char8              *_suffixA[];
    static       TransSceneFileType  _the;

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                   Constructors                               */
    /*! \{                                                                 */

    TransSceneFileType(const Char8  *suffixArray[],
                             UInt16  suffixByteCount,
                             bool    override,
                             UInt32  overridePriority,
                             UInt32  flags);

    TransSceneFileType(const TransSceneFileType &obj);

    /*! \}                                                                 */
    /*==========================  PRIVATE  ================================*/
  
  private:

    typedef SceneFileType Inherited;

    /* prohibit default function (move to 'public' if needed) */
    void operator =(const TransSceneFileType &source);
};

typedef TransSceneFileType* TransSceneFileTypeP;

OSG_END_NAMESPACE

#define OSGTRANSSCENEFILETYPE_HEADER_CVSID "@(#)$Id: OSGOBJSceneFileType.h 107 2006-09-14 03:21:56Z dirk $"

#endif // _OSGTRANSSCENEFILETYPE_H_

/*---------------------------------------------------------------------------*\
 *                                OpenSG                                     *
 *                                                                           *
 *                                                                           *
 *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
 *                                                                           *
 *                            www.opensg.org                                 *
 *                                                                           *
 *   contact: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]          *
 *                                                                           *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
 *                                License                                    *
 *                                                                           *
 * This library is free software; you can redistribute it and/or modify it   *
 * under the terms of the GNU Library General Public License as published    *
 * by the Free Software Foundation, version 2.                               *
 *                                                                           *
 * This library is distributed in the hope that it will be useful, but       *
 * WITHOUT ANY WARRANTY; without even the implied warranty of                *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Library General Public License for more details.                          *
 *                                                                           *
 * You should have received a copy of the GNU Library General Public         *
 * License along with this library; if not, write to the Free Software       *
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
 *                                                                           *
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
 *                                Changes                                    *
 *                                                                           *
\*---------------------------------------------------------------------------*/

//-------------------------------
//  Includes
//-------------------------------

#include "OpenSG/OSGConfig.h"

#include "OpenSG/OSGLog.h"
#include "OpenSG/OSGSceneFileHandler.h"
#include <OpenSG/OSGTransform.h>

#include "OSGTransSceneFileType.h"

OSG_USING_NAMESPACE


/*! \class OSG::TransSceneFileType
    \ingroup GrpSystemFileIO

 */

#if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
#pragma warning (disable : 383)
#endif

/*****************************
 *   Types
 *****************************/
// Static Class Varible implementations:
const Char8 *TransSceneFileType::_suffixA[] =  { "trans" };

TransSceneFileType  TransSceneFileType::_the(_suffixA,
                                             sizeof(_suffixA),
                                             false,
                                             10,
                                             SceneFileType::OSG_READ_SUPPORTED);

/*****************************
 *    Classvariables
 *****************************/


/********************************
 *    Class methodes
 *******************************/


/*******************************
*public
*******************************/

//----------------------------
// Function name: read
//----------------------------
//
//Parameters:
//p: Scene &image, const char *fileName
//GlobalVars:
//g:
//Returns:
//r:bool
// Caution
//c:
//Assumations:
//a:
//Describtions:
//d: read the image from the given file
//SeeAlso:
//s:
//
//------------------------------

namespace {

  // shamelessly borrowed from '/usr/share/Performer/src/lib/libpfdb/libpftran/pftrans.C'
  
  char*
  strrnchr(char *s, int n, int c)
  {
    char *p = 0;
    int i;
    
    for (i = 0; i < n && s[i] != '\0'; ++i)
      if (s[i] == c)
        p = s+i;
    
    return p;
  }

}

NodePtr TransSceneFileType::read(std::istream &, const Char8 *fileNameOrExtension) const
{
  SNOTICE << "TransSceneFileType::read: "
          << "reading " << fileNameOrExtension <<  "'"
          << std::endl;

  // scan: <filename>.<x>,<y>,<z>.trans; <x>, <y>, and <z> may have decimal points
  // shamelessly borrowed from '/usr/share/Performer/src/lib/libpfdb/libpftran/pftrans.C'
  
  float x(0.0), y(0.0), z(0.0);
  char *lastdot, *lastcomma, *firstcomma, *firstdot;
  char *fileName = const_cast<Char8*>(fileNameOrExtension);
  
  if ((lastdot = strrchr(fileName, '.')) == 0
      || (lastcomma = strrnchr(fileName, lastdot-fileName, ',')) == 0
      || (firstcomma = strrnchr(fileName, lastcomma-fileName, ',')) == 0
      || (firstdot = strrnchr(fileName, firstcomma-fileName, '.')) == 0
      || firstdot-fileName > 0 &&
      (firstdot[-1] == '.' || isdigit(firstdot[-1])) &&
      (firstdot = strrnchr(fileName, firstdot-fileName, '.')) == 0
      || sscanf(firstdot+1, "%f,%f,%f", &x, &y, &z) != 3) {
    SWARNING << "TransSceneFileType::read: "
             << "bad file name '" << fileName << "'"
             << std::endl;
    
    return NullFC;
  }

  std::string realName(fileName, firstdot-fileName);

  // no need for exception handling here
  NodePtr child(SceneFileHandler::the()->read(realName.c_str()));

  NodePtr node(NullFC);
  
  if (NullFC != child) {
    SINFO << "TransSceneFileType::read: "
          << "translating '" << realName << "' by [" << x << ", " << y << ", " << z << "]"
          << std::endl;
      
    Matrix m;

    m.setIdentity();
    m.setTranslate(x, y, z);

    TransformPtr xform(Transform::create());

    xform->setMatrix(m);
    
    node = Node::create();
    node->setCore(xform);
    node->addChild(child);
  }
  
  return node;
}

bool TransSceneFileType::write(const NodePtr &, std::ostream &,
                               const Char8 *fileNameOrExtension) const
{
  SNOTICE << "TransSceneFileType::write: '"
          << fileNameOrExtension <<  "'"
          << std::endl;
  
  return false;
}

/******************************
*protected
******************************/


/******************************
*private
******************************/


/***************************
*instance methodes
***************************/


/***************************
*public
***************************/


/**constructors & destructors**/


//----------------------------
// Function name: TransSceneFileType
//----------------------------
//
//Parameters:
//p: const char *suffixArray[], UInit16 suffixByteCount
//GlobalVars:
//g:
//Returns:
//r:
// Caution
//c:
//Assumations:
//a:
//Describtions:
//d: Default Constructor
//SeeAlso:
//s:
//
//------------------------------

TransSceneFileType::TransSceneFileType(const Char8  *suffixArray[],
                                             UInt16  suffixByteCount,
                                             bool    override,
                                             UInt32  overridePriority,
                                             UInt32  flags) :
    SceneFileType(suffixArray,
                  suffixByteCount,
                  override,
                  overridePriority,
                  flags)

{}

//----------------------------
// Function name: TransSceneFileType
//----------------------------
//
//Parameters:
//p: const TransSceneFileType &obj
//GlobalVars:
//g:
//Returns:
//r:
// Caution
//c:
//Assumations:
//a:
//Describtions:
//d: Copy Constructor
//SeeAlso:
//s:
//
//------------------------------

TransSceneFileType::TransSceneFileType(const TransSceneFileType &obj) :
    SceneFileType(obj)
{}

//----------------------------
// Function name: ~TransSceneFileType
//----------------------------
//
//Parameters:
//p: void
//GlobalVars:
//g:
//Returns:
//r:
// Caution
//c:
//Assumations:
//a:
//Describtions:
//d: Destructor
//SeeAlso:
//s:
//
//------------------------------

TransSceneFileType &TransSceneFileType::the(void)
{
    return _the;
}

TransSceneFileType::~TransSceneFileType(void)
{
    return;
}

const Char8 *TransSceneFileType::getName(void) const
{
    return "Translation Pseudo Loader";
}


/*------------access----------------*/

/*------------properies-------------*/

/*------------your Category---------*/

/*------------Operators-------------*/



/****************************
 *protected
 ****************************/


/****************************
 *private
 ****************************/


/*-------------------------------------------------------------------------*/
/*                              cvs id's                                   */

#ifdef __sgi
#pragma set woff 1174
#endif

#ifdef OSG_LINUX_ICC
#pragma warning( disable : 177 )
#endif

namespace
{
    static Char8 cvsid_cpp[] = "@(#)$Id: OSGTransSceneFileType.cpp 107 2006-09-14 03:21:56Z dirk $";
    static Char8 cvsid_hpp[] = OSGTRANSSCENEFILETYPE_HEADER_CVSID;
}

Attachment: signature.asc
Description: OpenPGP digital signature

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to