Hello Carsten,

thanks for the advice.
I've implemented my test class(e)s as you desribed below. But I've got
two problems / questions.
I honestly don't know what I have to do in part 3) (Isn't the code I
created in step 1 & 2 just used by the classes in 3. and I don't have to
manipulate the class of step 3?)

My classes for the  GeoPositionsMyPoint3i wouldn't link with VS 2005. He
couldn't find the function
osg::GeoProperty::getClassType(void)
Do I miss to use a special macro? When I implement this funtion in the
cpp (with dummy values), it compiles & links, but crashes on ::create()
(of course, he couldn't find the initMethod?!)

In my code in comment the following macros out (otherwise it wouldn't
compile):
// In the .h
#if !defined(OSG_COMPILEGEOPROPPOSITIONINST) && !defined(OSG_DO_DOC)
OSG_FC_DLLEXPORT_DECL(GeoProperty,
                     GeoPositionsMyPoint3iPropertyDesc,
                      OSG_SYSTEMLIB_DLLTMPLMAPPING )
#endif

// in the cpp
OSG_GEO_PROP_TYPE_TMPL_DEF(GeoProperty, GeoPropertyDesc, PtrType)
OSG_BEGIN_NAMESPACE
OSG_GEOPROP_DLLEXPORT_DEF (GeoProperty        ,
                          GeoPositionsMyPoint3iPropertyDesc,
                          OSG_SYSTEMLIB_DLLTMPLMAPPING);
OSG_END_NAMESPACE


I also can't direcly add my Class to the container:
template<>
inline
void GeoProperty::addValue(const MyPoint3i &val)
{
   _field.push_back(val);
}

The compiler just could find the function within the file
osggeopropertybase.h :
void osg::GeoProperty::addValue(const osg::PointInterface &)'
       with
       [
           GeoPropertyDesc=osg::GeoPositionsMyPoint3iPropertyDesc,
           ValueTypeT=osg::Real32,
           StorageInterfaceT=osg::VecStorage3


Could you give me a hint what I'm doing wrong?
Thanks

Rainer

Am Di 18.12.2007 00:58 schrieb Carsten Neumann :

>Hello Rainer,
>
>Rainer Schuetze wrote:
>>Because of the intensive memory cost of the high number of points, we
>>have look to for redundancy free methodic.
>>
>>We think of two ways to get this solved.
>>+ create a new “MyGeoPositions” container (which can be put in the
>>Geometry object) for our own point class. But we don’t know how. Are
>>there any examples or can you give us a hint. We had a look to the
>>example/NewTypes but we think this isn’t the way we have to use.
>>
>>+ put our point class in a OpenSG independent container. Now we need a
>>type of GeoPosition with hold the pointer to the elements of the
>>container. OpenSG must put the 3D values (by the pointer to the
>>Points)
>>to OpenGL when drawing. Does this make sense and how can this be done.
>
>while it is not completely impossible to implement one of these two
>approaches, it is definitely not an easy task. Unless you have a very
>compelling reason not to do so, I'd recommend to use the existing
>properties. What prevents you from using those ?
>
>Anyways, the general approach would look something like this:
>1. Define SField, MField - mainly requires a
>specialization of FieldTraits
>
>2. Define a GeoPositionsMyPointPropertyDesc (see

>>Source/System/NodeCores/Drawables/Geometry/OSGGeoPropPositions.{h,inl,cpp}).
>
>
>3. Use that as template argument for GeoProperty.
>
>The infrastructure for the GeoProperties is in the files
>OSGGeoPropertyBase.{h,inl,cpp} and OSGGeoPropertyInterface.{h,inl,cpp}.
>
>Your second approach would be even more difficult as you would have to
>create a specialization of GeoProperty that does not really store a
>field, but pretends to do so.
>
>Hope it helps,
>Carsten
>

>>-------------------------------------------------------------------------
>SF.Net email is sponsored by:
>Check out the new SourceForge.net Marketplace.
>It's the best place to buy or sell services
>for just about anything Open Source.

>>http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
>_______________________________________________
>Opensg-users mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/opensg-users




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

#pragma warning( disable :4996 )
//---------------------------------------------------------------------------
//  Includes
//---------------------------------------------------------------------------

#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGFieldType.h>
#include <opensg/OSGGeoPropertyBase.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGBase.h>
#include <OpenSG/OSGBaseTypes.h>
#include <OpenSG/OSGBaseFunctions.h>

#include <OpenSG/OSGSField.h>
#include <OpenSG/OSGMField.h>

OSG_BEGIN_NAMESPACE

// This files demonstrates how to create a new Field type, to support the
// integration of user-defined types into OpenSG FieldContainers.
//
// Classes/Types that are to be used in Field have to have some special
// capabilities, which not every class has be default.
//
// Field values need to be able to convert themselves into strings and
// to read themselves from strings. They also need to be able to transform
// themselevs into a binary stream and read themselves from a binary stream.

// Let's define a simple class that should be used in a Field

class MyPoint3i
{
    public:
    
		MyPoint3i(UInt32 i1 = 0, UInt32 i2 = 0, UInt32 i3 = 0, const std::string& name ="")
        {
            _values[0] = i1;
            _values[1] = i2;
            _values[2] = i3;    
			m_Name = name;
        }
        
        virtual ~MyPoint3i()
        {
        }
        
		UInt32& operator[](UInt16 ind)
		{
			if( ind > 3)
				_values[2];
			_values[ind]; 
		}
		const UInt32& operator[](UInt16 ind) const
		{
			if( ind > 3)
				_values[2];
			_values[ind]; 
		}
        UInt32 getValue(UInt16 ind) const
        {
            return _values[ind]; 
        }
         
        void setValue(UInt16 ind, UInt32 val)
        {
            _values[ind] = val;
        }
        void setValues(UInt32 val1 = 0,UInt32 val2 = 0, UInt32 val3 = 0)
        {
            _values[0] = val1;
			_values[1] = val2;
			_values[2] = val3;
        }
        bool operator ==(const MyPoint3i &rhs) const
        {
            return 
                _values[0] == rhs._values[0] &&
                _values[1] == rhs._values[1] &&
                _values[2] == rhs._values[2];
        }
	
		std::string getName() const { return m_Name; }
		void setName(const std::string& name) { m_Name = name;}

    private:
    
    	// This is not strictly necessary and just for illustration
    	// You could just as well do the internal access in this class and 
    	// supply methods to the FieldDataTraits<>
    	friend struct FieldDataTraits<MyPoint3i>;

		std::string m_Name;    	
        UInt32 _values[3]; 
};

// The FieldDataTraits class contains the methods needed to implement
// the features a Field data element needs to have

template <>
struct FieldDataTraits<MyPoint3i> : 
    public FieldTraitsRecurseBase<MyPoint3i>
{
    // Static DataType descriptor, see OSGNewFieldType.cpp for implementation
    static DataType       _type;

    // Define whether string conversions are available. It is strongly
    // recommended to implement both.
    enum                  { StringConvertable = ToStringConvertable | 
                                                FromStringConvertable    };

    // access method for the DataType
    static DataType       &getType      (void) { return _type;          }

    // Access to the names of the actual Fields
    static Char8          *getSName     (void) { return "SFMyPoint3i"; }
    static Char8          *getMName     (void) { return "MFMyPoint3i"; }

    // Create a default instance of the class, needed for Field creation
    static MyPoint3i       getDefault   (void) { return MyPoint3i();   }

    
    // This is where it gets interesting: the conversion functions

    // String conversion

    // Output inVal into outVal
    // the exact mapping doesn't matter, 
    // Our recommendation is to output as a string, 
    // i.e. start and stop with ", as this simplifies integration into the
    // OSG Loader.
    static void putToString(const MyPoint3i   &inVal,
                                  std::string &outVal)
    {
        // we can use the TypeTraits to do the conversion for the base types
        typedef TypeTraits<UInt32> tt;
        
        outVal.assign("\"");
        outVal.append(tt::putToString(inVal.getValue(0)));
        outVal.append(",");
        outVal.append(tt::putToString(inVal.getValue(1)));
        outVal.append(",");
        outVal.append(tt::putToString(inVal.getValue(2)));        
        outVal.append("\"");
    }
    
    // Setup outVal from the contents of inVal
    // For complicated classes it makes sense to implement this function
    // as a class method and just call that from here  
    static bool getFromString(      MyPoint3i  &outVal,
                              const Char8     *&inVal)
    {
        UInt32 i1 = 0, i2 = 0, i3 = 0;
        
        if(sscanf(inVal,"\"%d,%d,%d\"", &i1, &i2, &i3) != 3)
        	return false;
        
        outVal.setValue(0, i1);
        outVal.setValue(1, i2);
        outVal.setValue(2, i3);
        
        return true;
    }
    
    // Binary conversion
    
    // Return the size of the binary version in byte   
    // There are two versions of this function, one for a single object, 
    // one for an array of objects
    static UInt32 getBinSize(const MyPoint3i &)
    {
        return sizeof(UInt32) * 3;
    }

    static UInt32 getBinSize (const MyPoint3i *, UInt32 num)
    {
        return sizeof(UInt32)* 3 * num;
    }

    // Copy the object into the BinaryDataHandler
    // the BDH has a number of methods to add a simple type to the stream
    // just use those and use the same order to read them back in.
    // Again there are two versions, one for a single object, one for an 
    // array of objects
    static void copyToBin(      BinaryDataHandler &bdh, 
                          const MyPoint3i         &obj)
    {
    	// Put a single value at a time
        bdh.putValue(obj.getValue(0));
        bdh.putValue(obj.getValue(1));
        bdh.putValue(obj.getValue(2));
    }

    static void copyToBin(      BinaryDataHandler &bdh,
                          const MyPoint3i         *objs,
                                UInt32             num)
    {
    	// Put a set of values
    	for(UInt32 i = 0; i < num; ++i)
        	bdh.putValues(objs[i]._values, 3);
    }
    

    // Copy the object from the BinaryDataHandler
    // the BDH has a number of methods to get a simple type from the stream
    // just use those and use the same order you used to write them out.
    // Again there are two versions, one for a single object, one for an 
    // array of objects
    static void copyFromBin(BinaryDataHandler &bdh, 
                            MyPoint3i         &obj)
    {
        UInt32 i1,i2,i3;
        // Get a single value at a time
        bdh.getValue(i1);   
        obj.setValue(0, i1);
        bdh.getValue(i2);   
        obj.setValue(1, i2);
        bdh.getValue(i3);   
        obj.setValue(2, i3);
    }
    static void copyFromBin(BinaryDataHandler &bdh,
                            MyPoint3i         *objs,
                            UInt32             num)
    {
    	// Get a set of values
    	for(UInt32 i = 0; i < num; ++i)
        	bdh.getValues(objs[i]._values, 3);
    }
};

// Here the actual Field types are declared
// You don't always have to have both, either is fine

typedef SField<MyPoint3i> SFMyPoint3i;
typedef MField<MyPoint3i> MFMyPoint3i;


// Windows makes everything a lot more complicated than it needs to be,
// Thus you have to include the following Macro to make Windows happy.
// This is the variant for types which are directly used in an application,
// if the type should be included in a DLL, things need to be a little
// different.

// The define makes sure that the code is only included when the corresponding
// source is not compiled
#ifndef OSG_COMPILETRIPLEINTINST

// Declare the functions/classes/methods Windows needs
OSG_DLLEXPORT_DECL1(SField, MyPoint3i, )
OSG_DLLEXPORT_DECL1(MField, MyPoint3i, )

#endif
 

/** GeoPositionsMyPointPropertyDesc  

2. Define a GeoPositionsMyPointPropertyDesc 
(see Source/System/NodeCores/Drawables/Geometry/OSGGeoPropPositions.{h,inl,cpp}).
*/


/*! \brief The descriptor trait for osg::GeoPositions2f.
    \ingroup GrpSystemDrawablesGeometryProperties
    \hideinhierarchy
*/
struct GeoPositionsMyPoint3iPropertyDesc : public GeoPositionsPropertyDesc
{
    static FieldDescription *_desc[];

    /*---------------------------------------------------------------------*/
    /*! \name                          Get                                 */
    /*! \{                                                                 */
    
    static const Char8 *getTypeName (void) { return "GeoPositionsMyPoint3i";         }
    static const Char8 *getClassName(void) { return "GeoPositionsMyPoint3iProperty"; }
    static const Char8 *getFieldName(void) { return "positions";              }
    static const Char8 *getGroupName(void) { return "GeoPositions";           }

    static InitContainerF     getInitMethod(void) { return NULL;            }

    static UInt32             getFormat    (void) { return GL_INT;        }
    static UInt32             getFormatSize(void) { return sizeof(GLint); }
    static UInt32             getDimension (void) { return 3;               }
    static UInt32             getStride    (void) { return 0;               }

    static FieldDescription **getDesc      (void) { return _desc;           }

    /*! \}                                                                 */
    /*---------------------------------------------------------------------*/
    /*! \name                    Typedefs                                  */
    /*! \{                                                                 */
    
    typedef GeoPositions               Inherited;
    typedef GeoPositions::PtrType      InheritedPtr;

    typedef GeoPositionsPropertyDesc   InheritedDesc;
 
    typedef MFMyPoint3i                StoredFieldType;
    typedef InheritedDesc::GenericType GenericType;

#ifndef OSG_SUPPORT_NO_GEO_INTERFACE
    typedef GeoPropertyInterface<GeoPositionsPropertyDesc> Interface;
#endif

    /*! \}                                                                 */
};

 #if !defined(OSG_DO_DOC)   // created as a dummy class, remove to prevent doubles
typedef GeoProperty<GeoPositionsMyPoint3iPropertyDesc> GeoPositionsMyPoint3i;
#endif

 // DLL only ???? 
#if !defined(OSG_COMPILEGEOPROPPOSITIONINST) && !defined(OSG_DO_DOC)
OSG_FC_DLLEXPORT_DECL(GeoProperty,
                      GeoPositionsMyPoint3iPropertyDesc,
                       OSG_SYSTEMLIB_DLLTMPLMAPPING )
#endif

					  
typedef GeoPositionsMyPoint3i::PtrType  GeoPositionsMyPoint3iPtr;



//// Inine Functions

template<> inline 
Pnt3f GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::getValue(const UInt32 index)
{
    return Pnt3f(_field[index][0], _field[index][1], 0);
}

template<> inline 
Pnt3f GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::getValue( 
    const UInt32 index) const
{
    return Pnt3f(_field[index][0], _field[index][1], 0);
}

template<> inline 
void GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::getValue(
          Pnt3f   &res,
    const UInt32   index)
{
    res.setValues(_field[index][0], _field[index][1], 0);
}

template<> inline 
void GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::getValue(
          Pnt3f  &res,
    const UInt32  index) const
{
    res.setValues(_field[index][0], _field[index][1], 0);
}

template<> inline 
void GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::setValue(const Pnt3f  &val,
                                                       const UInt32  index)
{
    _field[index].setValues(val[0], val[1]);
}

template<>
inline
void GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::addValue(const Pnt3f &val)
{
	std::cout << "addValue(const Pnt3f &val) " << std::endl;
    _field.push_back(MyPoint3i( val[0], val[1]));
}

template<>
inline
void GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::addValue(const MyPoint3i &val)
{
    _field.push_back(val);
}


template <> inline
bool GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::insertValue(const Pnt3f &val,
                                                          const UInt32 index)
{
    if(_field.size() < index)
    {
        return false;
    }
    else if(_field.size() == index)
    {
        addValue(val);
        return true;
    }
    else
    {
        _field.insert(_field.begin() + index, MyPoint3i(val[0], val[1]));
        return true;
    }
}


/*** 
3. Use that as template argument for GeoProperty.
The infrastructure for the GeoProperties is in the files 
OSGGeoPropertyBase.{h,inl,cpp} and OSGGeoPropertyInterface.{h,inl,cpp}.
*/


OSG_END_NAMESPACE

#define OSGNEWFIELDTYPE_HEADER_CVSID "@(#)$Id: $"

#endif /* _OSGNEWFIELDTYPE_H_ */

 



// This define is only set in this source file. It switches the
// Windows-specific declarations in the header for compiling the Field, 
// not for using it.
#define OSG_COMPILETRIPLEINTINST

 


#include <stdlib.h>
#include <stdio.h>

#include <opensg/OSGConfig.h>

#include <opensg/OSGGeoPropPositions.h>

// You need this in every OpenSG file
#include <OpenSG/OSGConfig.h>

// Some basic system headers
#include <OpenSG/OSGBaseTypes.h>

#include "01MyPoint.h"

// Needed to instantiate some template functions on Windows
#include <OpenSG/OSGSFieldTypeDef.inl>
#include <OpenSG/OSGMFieldTypeDef.inl>


OSG_USING_NAMESPACE
 
OSG_BEGIN_NAMESPACE

// This is where the DataType for the new Fieldtype is defined.
// The parameters are the name of the type and the name of the parent type
DataType FieldDataTraits<MyPoint3i>::_type("MyPoint3i", "");

// These macros instantiate the necessary template methods for the fields
OSG_DLLEXPORT_SFIELD_DEF1(MyPoint3i, );
// !!! Doesn't work?!? 
OSG_DLLEXPORT_MFIELD_DEF1(MyPoint3i, );

OSG_END_NAMESPACE

/*
/// Wy is this necessary
FieldContainerType& osg::GeoProperty<osg::GeoPositionsMyPoint3iPropertyDesc>::getClassType(void)
{
	return FieldContainerType("GeoPositionsMyPoint3i",
    "GeoPositionsProperty");	 	 
}
*/

FieldDescription *GeoPositionsMyPoint3iPropertyDesc::_desc[] =
{
    new FieldDescription(
	StoredFieldType::getClassType(), 
        getFieldName(), 
        OSG_FC_FIELD_IDM_DESC(GeoProperty<
                                GeoPositionsMyPoint3iPropertyDesc>::GeoPropDataField),
        false,
#ifdef OSG_MICROSOFT_COMPILER_HACKS
        GeoProperty<GeoPositionsMyPoint3iPropertyDesc>::getFPtrAccessMethod())
#else
        (FieldAccessMethod) &GeoProperty<
                                GeoPositionsMyPoint3iPropertyDesc>::getFieldPtr)
#endif
};
 
/*
OSG_GEO_PROP_TYPE_TMPL_DEF(GeoProperty, GeoPropertyDesc, PtrType)

OSG_BEGIN_NAMESPACE
 

OSG_GEOPROP_DLLEXPORT_DEF (GeoProperty        , 
                           GeoPositionsMyPoint3iPropertyDesc, 
                           OSG_SYSTEMLIB_DLLTMPLMAPPING);

OSG_END_NAMESPACE

*/
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to