[opengtl-commits] [203] * Type::arrayType -> Type::embeddedType ( share the function between vector and array)

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 203
Author:   cyrille
Date:     2008-06-17 20:23:48 +0200 (Tue, 17 Jun 2008)

Log Message:
-----------
* Type::arrayType -> Type::embeddedType (share the function between vector and array)
* support for vector in GTLCore::Type
* add a 'data(x,y)' function to AbstractImage (and wrap it)
* add the 'data' field to Pixel for the simple case

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type.h
    trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h
    trunk/OpenGTL/OpenGTL/GTLCore/TypeManager_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h
    trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -123,7 +123,7 @@
 
 const GTLCore::Type* ArrayAccessorExpression::type() const
 {
-  return m_parent->type()->arrayType();
+  return m_parent->type()->embeddedType();
 }
 
 //------------------- VariableAccessorExpression -------------------//

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -60,7 +60,7 @@
   GTL_DEBUG( m_type->dataType() << " " << Type::ARRAY << " " << Type::STRUCTURE );
   if( m_type->dataType() == Type::ARRAY )
   {
-    const GTLCore::Type* arrayType = m_type->arrayType();
+    const GTLCore::Type* arrayType = m_type->embeddedType();
     std::vector< llvm::Constant* > members;
     for(  std::vector<Expression*>::const_iterator it = m_expressions.begin();
        it != m_expressions.end(); ++it)

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -62,9 +62,11 @@
       case Type::STRUCTURE:
         return ostr << "STRUCTURE";
       case Type::ARRAY:
-        return ostr << "ARRAY";
+        return ostr << "ARRAY[" << *type.embeddedType() << "]";
       case Type::POINTER:
         return ostr << "POINTER";
+      case Type::VECTOR:
+        return ostr << "VECTOR[" << type.vectorSize() << "," << *type.embeddedType() << "]";
     }
   return ostr;
   }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -226,7 +226,7 @@
       const GTLCore::Type* type = 0;
       if ( _type->dataType() == Type::ARRAY )
       {
-        type = _type->arrayType();
+        type = _type->embeddedType();
       } else if( _type->dataType() == Type::STRUCTURE )
       {
         type = (*_type->structDataMembers())[index].type();

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -102,24 +102,19 @@
 Type::Type(DataType _dataType) : d(new Private(_dataType))
 {
   GTL_DEBUG("Create type for " << _dataType);
-  assert(_dataType != STRUCTURE and _dataType != ARRAY);
+  GTL_ASSERT(_dataType != STRUCTURE and _dataType != ARRAY and _dataType != VECTOR );
   if(_dataType == STRUCTURE or _dataType == ARRAY)
   {
     d->dataType = UNDEFINED;
   }
-  d->dataType = _dataType;
-  d->arrayType = 0;
-  d->structDataMembers = 0;
-  d->structFunctionMembers = 0;
+  init(_dataType);
 }
 
 Type::Type(const GTLCore::String& _structName, const std::vector<StructDataMember>& _members) : d(new Private)
 {
-  d->dataType = STRUCTURE;
+  init(STRUCTURE);
   d->structName = _structName;
-  d->arrayType = 0;
   d->structDataMembers = new std::vector<StructDataMember>( _members );
-  d->structFunctionMembers = 0;
   std::vector< const llvm::Type * > types;
   for(std::vector<StructDataMember>::iterator it = d->structDataMembers->begin();
       it != d->structDataMembers->end(); ++it)
@@ -131,24 +126,39 @@
 
 Type::Type(const Type* _arrayType) : d(new Private)
 {
-  d->dataType = ARRAY;
+  init(ARRAY);
   d->arrayType = _arrayType;
-  d->structDataMembers = 0;
-  d->structFunctionMembers = 0;
+  
   std::vector< const llvm::Type * > types;
   types.push_back(llvm::Type::Int32Ty);
   types.push_back( llvm::PointerType::get( _arrayType->d->type(), 0));
   d->setType( llvm::StructType::get(types));
 }
 
+Type::Type(int _size, const Type* _vectorType) : d(new Private)
+{
+  init(VECTOR);
+  d->arrayType = _vectorType;
+  d->vectorSize = _size;
+  d->setType( llvm::VectorType::get( _vectorType->d->type(), d->vectorSize ) );
+}
+
+void Type::init(DataType _dataType)
+{
+  d->dataType = _dataType;
+  d->structDataMembers = 0;
+  d->structFunctionMembers = 0;
+  d->structPrivateFunctionMembers = 0;
+}
+
 Type::Type(const Type& _rhs) : d(new Private(*_rhs.d))
 {
+  GTL_ASSERT(false);
 }
 
 Type& Type::operator=(const Type& _rhs)
 {
-  *d = *_rhs.d;
-  return *this;
+  GTL_ASSERT(false);
 }
 
 Type::~Type()
@@ -161,6 +171,11 @@
   return d->dataType;
 }
 
+const Type* Type::embeddedType() const
+{
+  return d->arrayType;
+}
+
 const Type* Type::arrayType() const
 {
   return d->arrayType;
@@ -202,6 +217,8 @@
       return 32;
     case Type::VOID:
       return 0;
+    case Type::VECTOR:
+      return d->vectorSize * embeddedType()->bitsSize();
     default:
       return -1;
       break;
@@ -222,7 +239,15 @@
     case Type::UNSIGNED_INTEGER16:
     case Type::UNSIGNED_INTEGER32:
       return true;
+    case Type::VECTOR:
+      return embeddedType()->isUnsigned();
     default:
       return false;
   }
 }
+
+int Type::vectorSize() const
+{
+  GTL_ASSERT( dataType() == Type::VECTOR );
+  return d->vectorSize;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -20,6 +20,7 @@
 #ifndef _GTLCORE_TYPE_H_
 #define _GTLCORE_TYPE_H_
 
+#include <GTLCore/Macros.h>
 #include <GTLCore/String.h>
 #include <list>
 #include <vector>
@@ -57,6 +58,7 @@
     friend class OpenShiva::Types;
     friend class ParserBase;
     friend class Function;
+    friend class TypeManager;
     public:
       enum DataType {
         UNDEFINED,
@@ -73,7 +75,8 @@
         VOID,
         STRUCTURE,
         ARRAY,
-        POINTER
+        POINTER,
+        VECTOR
       };
       /**
        * This class defines a member of a structure.
@@ -129,25 +132,34 @@
        * This constructor construct a type of the given type.
        * But it shouldn't be used for arrays or structure.
        */
-      Type(DataType _dataType = UNDEFINED);
-      Type(const Type& rhs);
-      Type& operator=(const Type& rhs);
-    public:
+      Type( DataType _dataType = UNDEFINED );
+      Type( const Type& rhs );
+      Type& operator=( const Type& rhs );
       /**
        * Define a structure.
        */
-      Type(const GTLCore::String& _structName, const std::vector<Type::StructDataMember>& _members);
+      Type( const GTLCore::String& _structName, const std::vector<Type::StructDataMember>& _members );
       /**
        * Define an array.
        */
-      Type(const Type* _arrayType);
+      Type( const Type* _arrayType );
+      /**
+       * Define a vector
+       */
+      Type( int _size, const Type* _arrayType );
+      void init( DataType _dataType );
       ~Type();
     public:
       DataType dataType() const;
       /**
+       * The type of an array or a vector.
+       * @return embedded type
+       */
+      const Type* embeddedType() const;
+      /**
        * @return the type of the array, or 0 if not an array
        */
-      const Type* arrayType() const;
+      GTL_DEPRECATED const Type* arrayType() const;
       /**
        * @return the name of the structure
        */
@@ -170,6 +182,10 @@
        * @return true if the type is an unsigned integer
        */
       bool isUnsigned() const;
+      /**
+       * @return the size of a vector
+       */
+      int vectorSize() const;
     private:
       struct Private;
       Private* const d;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -24,6 +24,7 @@
 using namespace GTLCore;
 
 std::map< const GTLCore::Type*, const GTLCore::Type*> TypeManager::Private::knownArrays;
+std::map< const GTLCore::Type*, std::map< int, const GTLCore::Type* > > TypeManager::Private::knownVectors;
 
 TypeManager::TypeManager() : d(new Private)
 {
@@ -65,3 +66,15 @@
   }
   return type;
 }
+
+const GTLCore::Type* TypeManager::getVector( const GTLCore::Type* _type, int _size ) const
+{
+  std::map< const GTLCore::Type*, std::map< int, const GTLCore::Type* > >::const_iterator it
+      = d->knownVectors.find( _type );
+  const GTLCore::Type*& type = d->knownVectors[ _type ][ _size ];
+  if( type == 0 )
+  {
+    type = new GTLCore::Type( _size, _type );
+  }
+  return type;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -52,6 +52,7 @@
        * @endcode
        */
       const GTLCore::Type* getArray( const GTLCore::Type* type, int _levelsCount) const;
+      const GTLCore::Type* getVector( const GTLCore::Type* _type, int _size ) const;
     private:
       struct Private;
       Private* const d;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager_p.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager_p.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -28,6 +28,7 @@
   struct TypeManager::Private {
     std::map< GTLCore::String, const GTLCore::Type*> knownTypes;
     static std::map< const GTLCore::Type*, const GTLCore::Type*> knownArrays;
+    static std::map< const GTLCore::Type*, std::map< int, const GTLCore::Type* > > knownVectors;
     /**
       * @param name the name of the type
       * @return true if the name given as argument is the name of a known type

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -132,6 +132,13 @@
   structFunctionMembers->push_back( sfm );
 }
 
+void Type::Private::addPrivateFunctionMember( const StructFunctionMember& sfm)
+{
+  GTL_ASSERT(  dataType == Type::STRUCTURE );
+  if( not structPrivateFunctionMembers ) structPrivateFunctionMembers = new std::vector<Type::StructFunctionMember>();
+  structPrivateFunctionMembers->push_back( sfm );
+}
+
 int Type::Private::memberToIndex(const GTLCore::String& name)
 {
   GTL_ASSERT(structDataMembers);
@@ -160,3 +167,18 @@
   }
   return 0;
 }
+
+const Type::StructFunctionMember* Type::Private::privateFunctionMember( const GTLCore::String& _name) const
+{
+  if(not structPrivateFunctionMembers) return 0;
+  for( std::vector<GTLCore::Type::StructFunctionMember>::const_iterator it = structPrivateFunctionMembers->begin();
+        it != structPrivateFunctionMembers->end(); ++it)
+  {
+    if( it->name() == _name)
+    {
+      return &*it;
+    }
+  }
+  return 0;
+}
+

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -77,20 +77,26 @@
       Private( const llvm::Type* _type ) : m_type(_type) {}
       const llvm::Type * type() const { return m_type; }
       void addFunctionMember( const StructFunctionMember& );
+      void addPrivateFunctionMember( const StructFunctionMember& );
       int memberToIndex(const GTLCore::String&);
       /**
        * @return the function member associated with that name, or null if none
        */
       const Type::StructFunctionMember* functionMember( const GTLCore::String&) const;
+      /**
+       * @return the private function member associated with that name, or null if none
+       */
+      const Type::StructFunctionMember* privateFunctionMember( const GTLCore::String&) const;
     private:
       void setType( const llvm::Type* _type);
       const llvm::Type* m_type;
       DataType dataType;
-      int size;
+      int vectorSize;
       const Type* arrayType;
       GTLCore::String structName;
       std::vector<StructDataMember>* structDataMembers;
       std::vector<Type::StructFunctionMember>* structFunctionMembers;
+      std::vector<Type::StructFunctionMember>* structPrivateFunctionMembers;
   };
   
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -170,17 +170,17 @@
     _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
 //     GTL_DEBUG( " value = " << *_pointer << " type = " << *_pointer->getType() );
 //     GTL_DEBUG( " value = " << *_value << " type = " << *_value->getType() );
-    const Visitor* visitor = Visitor::getVisitorFor( _pointerType->arrayType() );
+    const Visitor* visitor = Visitor::getVisitorFor( _pointerType->embeddedType() );
     llvm::BasicBlock* endBodyBlock = visitor->set( 
           _generationContext,
           bodyBlock, 
           _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock  ) ),
-          _pointerType->arrayType(),
+          _pointerType->embeddedType(),
           new llvm::LoadInst(
                   _generationContext.codeGenerator()->accessArrayValue(
                                     bodyBlock, _value, index->get( _generationContext, bodyBlock  ) ),
                   "", bodyBlock ),
-          _valueType->arrayType() );
+          _valueType->embeddedType() );
     
     // Create the for statement
     return _generationContext.codeGenerator()->createIterationForStatement(
@@ -209,7 +209,7 @@
   {
     llvm::Value* ptr = new llvm::GetElementPtrInst( _pointer, indexes.begin(), indexes.end(), "", _currentBlock);
     llvm::Value* array = new llvm::AllocaInst::AllocaInst(
-                    _pointerType->arrayType()->d->type(), _size, "", _currentBlock);
+                    _pointerType->embeddedType()->d->type(), _size, "", _currentBlock);
     new llvm::StoreInst( array, ptr, "", _currentBlock);
   }
 }
@@ -240,13 +240,13 @@
     llvm::BasicBlock* bodyBlock = new llvm::BasicBlock("bodyBlock");
     _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
     
-    const Visitor* visitor = Visitor::getVisitorFor( _pointerType->arrayType() );
+    const Visitor* visitor = Visitor::getVisitorFor( _pointerType->embeddedType() );
     llvm::BasicBlock* endBodyBlock = visitor->initialise(
             _generationContext,
             bodyBlock,
             _generationContext.codeGenerator()->accessArrayValue(
                       bodyBlock, _pointer, index->get( _generationContext, bodyBlock ) ),
-            _pointerType->arrayType(),
+            _pointerType->embeddedType(),
             sizeAfter );
     
     // Create the for statement

Modified: trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenGTL/GTLCore/tests/TestType.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -26,7 +26,7 @@
     {
       GTLTEST_CHECK_EQUAL(Type::Float->dataType(), Type::FLOAT);
       GTLTEST_CHECK_EQUAL(Type::Float->bitsSize(), 32);
-      GTLTEST_CHECK_EQUAL(Type::Float->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Float->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Float->structDataMembers(), 0);
     }
 };
@@ -40,27 +40,27 @@
     {
       GTLTEST_CHECK_EQUAL(Type::Integer8->dataType(), Type::INTEGER8);
       GTLTEST_CHECK_EQUAL(Type::Integer8->bitsSize(), 8);
-      GTLTEST_CHECK_EQUAL(Type::Integer8->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Integer8->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer8->structDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->dataType(), Type::UNSIGNED_INTEGER8);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->bitsSize(), 8);
-      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger8->structDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer16->dataType(), Type::INTEGER16);
       GTLTEST_CHECK_EQUAL(Type::Integer16->bitsSize(), 16);
-      GTLTEST_CHECK_EQUAL(Type::Integer16->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Integer16->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer16->structDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->dataType(), Type::UNSIGNED_INTEGER16);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->bitsSize(), 16);
-      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger16->structDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer32->dataType(), Type::INTEGER32);
       GTLTEST_CHECK_EQUAL(Type::Integer32->bitsSize(), 32);
-      GTLTEST_CHECK_EQUAL(Type::Integer32->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::Integer32->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::Integer32->structDataMembers(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->dataType(), Type::UNSIGNED_INTEGER32);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->bitsSize(), 32);
-      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->arrayType(), 0);
+      GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->embeddedType(), 0);
       GTLTEST_CHECK_EQUAL(Type::UnsignedInteger32->structDataMembers(), 0);
     }
 };

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -17,3 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#include "AbstractImage.h"
+
+using namespace OpenShiva;
+

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -21,7 +21,23 @@
 #define _OPENSHIVA_ABSTRACT_IMAGE_H_
 
 namespace OpenShiva {
+  /**
+   * Base class of Images. Reimplement the virtual functions to give access to
+   * your internal image data.
+   */
   class AbstractImage {
+    public:
+      enum SamplingMode {
+        Nearest,
+        Linear
+      };
+    public:
+      /**
+       * @param _x
+       * @param _y
+       * @return a pointer to the pixel at coordinates (_x,_y)
+       */
+      virtual char* data( int _x, int _y ) = 0;
   };
 };
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -65,17 +65,35 @@
 
 void Types::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription)
 {
+  SHIVA_ASSERT(_pixelDescription.bitsSize() % 8 == 0);
   std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
-  _typeManager->d->createStructure( "pixel", pixelDataMembers );
+  createPixelType(_module, _typeManager, "", pixelDataMembers, _pixelDescription.bitsSize() / 8 );
 }
 
 void Types::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, int _channels, const GTLCore::Type* _referenceDepth )
 {
+  SHIVA_ASSERT(_referenceDepth->bitsSize() % 8 == 0);
   std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
-  _typeManager->d->createStructure(
-          "pixel" + GTLCore::String::number( _channels ), pixelDataMembers );
+  // Compute the size of the vector
+  int size_vector = 1;
+  while( size_vector < _channels )
+  {
+    size_vector *= 2;
+  }
+  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", _typeManager->getVector( _referenceDepth, _channels) ) );
+  // Create the generic part of the pixel type
+  createPixelType(_module, _typeManager, GTLCore::String::number( _channels ), pixelDataMembers, _channels * _referenceDepth->bitsSize() / 8 );
 }
 
+void Types::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, std::vector<GTLCore::Type::StructDataMember> _pixelDataMembers, int _pixelSize )
+{
+  SHIVA_DEBUG("createPixelType of size " << _pixelSize);
+  _pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
+  _pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "y", GTLCore::Type::Float) );
+  
+  _typeManager->d->createStructure( "pixel" + _suffix, _pixelDataMembers );
+}
+
 void Types::createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager )
 {
   std::vector<GTLCore::Type::StructDataMember> regionDataMembers;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -20,12 +20,13 @@
 #ifndef _OPENSHIVA_TYPES_P_H_
 #define _OPENSHIVA_TYPES_P_H_
 
+#include "GTLCore/Type_p.h"
+
 namespace llvm {
   class Module;
 }
 
 namespace GTLCore {
-  class Type;
   class TypeManager;
   class PixelDescription;
 }
@@ -53,6 +54,10 @@
       static void createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager );
       static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, int _channels, const GTLCore::Type* _referenceDepth );
       static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription);
+      /**
+       * @param _pixelSize size of one pixel in bytes
+       */
+      static void createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, std::vector<GTLCore::Type::StructDataMember> _pixelDataMembers, int _pixelSize );
   };
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp	2008-06-17 18:23:48 UTC (rev 203)
@@ -17,3 +17,15 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#include "ImageWrap_p.h"
+
+#include "AbstractImage.h"
+
+extern "C" {
+
+char* image_wrap_data( ImageWrap* _imageWrap, int _x, int _y )
+{
+  return _imageWrap->image->data(_x, _y);
+}
+
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -17,3 +17,25 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#ifndef _IMAGE_WRAP_P_H_
+#define _IMAGE_WRAP_P_H_
+
+namespace OpenShiva {
+  class AbstractImage;
+}
+
+//---------------------- WARNING ----------------------//
+// Whenever the following structure is edited,         //
+// it's llvm declaration must be changed too in        //
+// Types_p.cpp !                                       //
+//---------------------- WARNING ----------------------//
+struct ImageWrap {
+  OpenShiva::AbstractImage* image;
+};
+
+extern "C" {
+  char* image_wrap_data( ImageWrap* _imageWrap, int _x, int _y );
+
+}
+
+#endif

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-06-16 20:48:58 UTC (rev 202)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-06-17 18:23:48 UTC (rev 203)
@@ -26,13 +26,13 @@
 // Types_p.cpp !                                       //
 //---------------------- WARNING ----------------------//
 struct PixelWrap {
+  void* data;
   float x;
   float y;
-  void* data;
   enum PixelIndexes {
-    INDEX_X = 0,
-    INDEX_Y = 1,
-    INDEX_DATA = 2
+    INDEX_DATA = 0,
+    INDEX_X = 1,
+    INDEX_Y = 2
   };
 };
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/