fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / PropertiesBase / OSGGeoVectorPropertyConversion.inl
blob91341f4a8eda98f517a1e2bd3e587f0b82a478ff
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *               Copyright (C) 2000-2006 by the OpenSG Forum                 *
6  *                                                                           *
7  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
8  *                                                                           *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11  *                                License                                    *
12  *                                                                           *
13  * This library is free software; you can redistribute it and/or modify it   *
14  * under the terms of the GNU Library General Public License as published    *
15  * by the Free Software Foundation, version 2.                               *
16  *                                                                           *
17  * This library is distributed in the hope that it will be useful, but       *
18  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
20  * Library General Public License for more details.                          *
21  *                                                                           *
22  * You should have received a copy of the GNU Library General Public         *
23  * License along with this library; if not, write to the Free Software       *
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
25  *                                                                           *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28  *                                Changes                                    *
29  *                                                                           *
30  *                                                                           *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35 \*---------------------------------------------------------------------------*/
37 //---------------------------------------------------------------------------
38 //  Includes
39 //---------------------------------------------------------------------------
41 OSG_BEGIN_NAMESPACE
44 // Normalize funcs
47 template <class ValueTypeT>
48 inline typename detail::NoNormalizationFunc<ValueTypeT>::ValueType
49 detail::NoNormalizationFunc<ValueTypeT>::apply(
50     const ValueType& src, const Real64, const Real64)
52     return src;
55 template <class ValueTypeT>
56 inline typename detail::InNormalizationFunc<ValueTypeT>::ValueType
57 detail::InNormalizationFunc<ValueTypeT>::apply(
58     const ValueType& src, const Real64 scale, const Real64 offset)
60     return static_cast<ValueType>((scale * src) + offset);
63 template <class ValueTypeT>
64 inline typename detail::OutNormalizationFunc<ValueTypeT>::ValueType
65 detail::OutNormalizationFunc<ValueTypeT>::apply(
66     const ValueType& src, const Real64 scale, const Real64 offset)
68     return static_cast<ValueType>((src - offset) / scale);
72 // Access funcs
75 template <class ValueTypeT>
76 inline typename detail::VectorElementAccessFunc<ValueTypeT>::ElementType
77 detail::VectorElementAccessFunc<ValueTypeT>::apply(
78     const ValueType& src, const UInt32 index)
80     return src[index];
83 template <class ValueTypeT>
84 inline typename detail::Fixed32VectorElementAccessFunc<ValueTypeT>::ElementType
85 detail::Fixed32VectorElementAccessFunc<ValueTypeT>::apply(
86     const ValueType& src, const UInt32 index)
88     return src[index].getValue();
92 // Convert funcs
95 template <class DestTypeT,
96           class SourceTypeT,
97           template <class> class NormalizeFuncT,
98           template <class> class ElementAccessFuncT>
99 inline void
100 detail::GeoConvertFunc<DestTypeT,
101                        SourceTypeT,
102                        NormalizeFuncT,
103                        ElementAccessFuncT>::convert(
104           DestType& dest,  const SourceType& src,
105     const Real64    scale, const Real64      offset)
107     if(SourceType::_uiSize >= DestType::_uiSize)
108     {
109         UInt32 i;
110         for(i = 0; i < DestType::_uiSize; ++i)
111         {
112             dest[i] = static_cast<DestElementType>(
113                 NormFunc::apply(AccessFunc::apply(src, i), scale, offset));
114         }
115     }
116     else
117     {
118         UInt32 i;
119         for(i = 0; i < SourceType::_uiSize; ++i)
120         {
121             dest[i] = static_cast<DestElementType>(
122                 NormFunc::apply(AccessFunc::apply(src, i), scale, offset));
123         }
125         for(; i < DestType::_uiSize; ++i)
126         {
127             dest[i] = static_cast<DestElementType>(
128                 NormFunc::apply(
129                     AccessFunc::apply(SourceType::Null, i), scale, offset));
130         }
131     }
134 template <class                  ValueTypeT,
135           template <class> class ElementAccessFuncT>
136 inline void
137 detail::GeoConvertFunc<ValueTypeT,
138                        ValueTypeT,
139                        detail::NoNormalizationFunc,
140                        ElementAccessFuncT          >::convert(
141           DestType& dest,  const SourceType& src,
142     const Real64    scale, const Real64      offset)
144     dest = src;
147 OSG_END_NAMESPACE