[opengtl-commits] [198] * make creating of external function available as static member of Function ::Private

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


Revision: 198
Author:   cyrille
Date:     2008-06-15 23:10:19 +0200 (Sun, 15 Jun 2008)

Log Message:
-----------
* make creating of external function available as static member of Function::Private
* move call of functions in CodeGenerator
* implement FunctionMemberAccessorExpression::generateValue
* add a CodeGenerator for OpenShiva, with a function to copy from memory to pixel
* StructFunctionMember embedd a Function
* add Region::left, right, top and bottomd
* add more test to structures/region.shiva

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
    trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Function.h
    trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Function_p.h
    trunk/OpenGTL/OpenGTL/GTLCore/Type.h
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h
    trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex
    trunk/OpenGTL/OpenShiva/doc/specification/region.pdf
    trunk/OpenGTL/OpenShiva/doc/specification/region.svg
    trunk/OpenGTL/OpenShiva/tests/structures/region.shiva

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -111,22 +111,15 @@
 void Compiler::createStdLibFunction(const GTLCore::String& _name, const GTLCore::String& _symbolName, const GTLCore::Type* retType, int count, ...)
 {
   std::vector<GTLCore::Parameter> arguments;
-  std::vector<const llvm::Type*> llvmArguments;
   va_list argp;
   va_start(argp, count);
   for(int i = 0; i < count; ++i)
   {
     const GTLCore::Type* type = va_arg(argp, const GTLCore::Type*);
     arguments.push_back(GTLCore::Parameter("", type, false, false, GTLCore::Value() ) );
-    llvmArguments.push_back(type->d->type());
   }
   va_end(argp);
-  std::vector<llvm::Function*> functions(arguments.size() + 1);
-  functions[arguments.size() ] = dynamic_cast<llvm::Function*>( d->module->getOrInsertFunction( _symbolName, llvm::FunctionType::get(retType->d->type(), llvmArguments, false ) ) );
-  GTLCore::Function::Data* data = new GTLCore::Function::Data(arguments, arguments.size() );
-  data->setFunctions( functions );
-  data->setModule( d->module );
-  GTLCore::Function* function = new GTLCore::Function( GTLCore::ScopedName("", _name), retType, data );
+  GTLCore::Function* function = GTLCore::Function::Private::createExternalFunction( d->module, _name, _symbolName, retType, arguments );
   OCTL_ASSERT( declareFunction(GTLCore::ScopedName("", _name), function) );
   d->functionsToDelete.push_back(function);
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -155,6 +155,7 @@
                                           const std::list<AST::Expression*>& _arguments )
   : m_parent( _parent ), m_member(_member), m_arguments(_arguments)
 {
+  m_arguments.push_front( _parent );
 }
 
 bool FunctionMemberAccessorExpression::isConstant() const
@@ -168,8 +169,7 @@
 }
 GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
 {
-  GTL_ASSERT( false ); // TODO implement
-  return GTLCore::ExpressionResult();
+  return GTLCore::ExpressionResult( _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments ) );
 }
 
 llvm::Value* FunctionMemberAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -87,7 +87,7 @@
       private:
         AccessorExpression* m_parent;
         const Type::StructFunctionMember* m_member;
-        const std::list<AST::Expression*> m_arguments;
+        std::list<AST::Expression*> m_arguments;
     };
   }
 }

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -91,56 +91,7 @@
 
 GTLCore::ExpressionResult FunctionCallExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
 {
-  // Function Type
-  GTL_ASSERT( m_function );
-  llvm::Function* llvmFunction = m_function->d->data->function( m_arguments.size() );
-    const llvm::FunctionType *FTy = llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>( llvmFunction->getType())->getElementType());
-    GTL_DEBUG( *FTy );
-  GTL_ASSERT( llvmFunction );
-  std::vector< Parameter >::const_iterator oparam_it = m_function->parameters().begin();
-  std::vector<llvm::Value*> convertedParams;
-  for( std::list< Expression* >::const_iterator it = m_arguments.begin();
-       it != m_arguments.end(); ++it, ++oparam_it)
-  {
-    if(oparam_it->output())
-    {
-#if USE_MEMBER_ARRAY
-      VariableExpression* varex = dynamic_cast<VariableExpression*>( *it);
-      GTL_ASSERT( varex );
-      GTL_ASSERT( varex->variable()->pointer()->getType() == llvm::PointerType::get( oparam_it->type()->d->type(), 0) );
-      convertedParams.push_back( varex->variable()->pointer() );
-      GTL_DEBUG(*varex->variable()->pointer()->getType() << " " << *oparam_it->type()->d->type() );
-#else
-      AccessorExpression* aexp = dynamic_cast<AccessorExpression*>( *it );
-      GTL_ASSERT( aexp );
-      llvm::Value* pointer = aexp->pointer( _gc, bb );
-      GTL_ASSERT( pointer->getType() == llvm::PointerType::get( oparam_it->type()->d->type(), 0) );
-      convertedParams.push_back( pointer );
-      GTL_DEBUG(*pointer->getType() << " " << *oparam_it->type()->d->type() );
-#endif
-    } else {
-      llvm::Value* value = 0;
-      if( (*it)->type()->dataType() == GTLCore::Type::ARRAY or (*it)->type()->dataType() == GTLCore::Type::STRUCTURE )
-      {
-        AccessorExpression* aexp = dynamic_cast<AccessorExpression*>( *it );
-        GTL_ASSERT( aexp );
-        value = aexp->pointer( _gc, bb );
-      } else {
-        value = (*it)->generateValue(_gc, bb).value();
-      }
-      GTL_ASSERT( value );
-      if( oparam_it->type()->d->type()->isFirstClassType() )
-      {
-        value = _gc.codeGenerator()-> convertValueTo( bb, value, (*it)->type(), oparam_it->type() );
-      }
-      convertedParams.push_back( value );
-    }
-    
-  }
-  llvm::CallInst *CallFunc = new llvm::CallInst(llvmFunction, convertedParams.begin(), convertedParams.end(), "", bb);
-  CallFunc->setTailCall();
-  return GTLCore::ExpressionResult( CallFunc );
-
+  return _gc.codeGenerator()->callFunction( _gc, bb, m_function, m_arguments );
 }
 
 // NumberExpression

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -27,13 +27,17 @@
 
 #include "Debug.h"
 #include "ExpressionResult_p.h"
+#include "Function_p.h"
 #include "GenerationContext_p.h"
+#include "Parameter.h"
 #include "Type.h"
 #include "Type_p.h"
 #include "Value.h"
 #include "VariableNG_p.h"
 #include "ModuleData_p.h"
 
+#include "AST/AccessorExpression.h"
+
 #define UNIFORMIZE_TYPES( _v1_, _v2_) \
   GTL_ASSERT( _v1_.value() ); \
   GTL_ASSERT( _v2_.value() ); \
@@ -610,3 +614,48 @@
   llvm::Value* iptr_val = new llvm::LoadInst( iptr, "", _currentBlock);
   return new llvm::GetElementPtrInst( iptr_val, _index, "", _currentBlock);
 }
+
+GTLCore::ExpressionResult CodeGenerator::callFunction( GenerationContext& _gc, llvm::BasicBlock* bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& _arguments )
+{
+  // Function Type
+  GTL_ASSERT( _function );
+  llvm::Function* llvmFunction = _function->d->data->function( _arguments.size() );
+    const llvm::FunctionType *FTy = llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>( llvmFunction->getType())->getElementType());
+    GTL_DEBUG( *FTy );
+  GTL_ASSERT( llvmFunction );
+  std::vector< Parameter >::const_iterator oparam_it = _function->parameters().begin();
+  std::vector<llvm::Value*> convertedParams;
+  for( std::list< AST::Expression* >::const_iterator it = _arguments.begin();
+       it != _arguments.end(); ++it, ++oparam_it)
+  {
+    if(oparam_it->output())
+    {
+      AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it );
+      GTL_ASSERT( aexp );
+      llvm::Value* pointer = aexp->pointer( _gc, bb );
+      GTL_ASSERT( pointer->getType() == llvm::PointerType::get( oparam_it->type()->d->type(), 0) );
+      convertedParams.push_back( pointer );
+      GTL_DEBUG(*pointer->getType() << " " << *oparam_it->type()->d->type() );
+    } else {
+      llvm::Value* value = 0;
+      if( (*it)->type()->dataType() == GTLCore::Type::ARRAY or (*it)->type()->dataType() == GTLCore::Type::STRUCTURE )
+      {
+        AST::AccessorExpression* aexp = dynamic_cast<AST::AccessorExpression*>( *it );
+        GTL_ASSERT( aexp );
+        value = aexp->pointer( _gc, bb );
+      } else {
+        value = (*it)->generateValue(_gc, bb).value();
+      }
+      GTL_ASSERT( value );
+      if( oparam_it->type()->d->type()->isFirstClassType() )
+      {
+        value = _gc.codeGenerator()-> convertValueTo( bb, value, (*it)->type(), oparam_it->type() );
+      }
+      convertedParams.push_back( value );
+    }
+    
+  }
+  llvm::CallInst *CallFunc = new llvm::CallInst(llvmFunction, convertedParams.begin(), convertedParams.end(), "", bb);
+  CallFunc->setTailCall();
+  return GTLCore::ExpressionResult( CallFunc );
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -20,6 +20,8 @@
 #ifndef _GTLCORE_CODE_GENERATOR_H_
 #define _GTLCORE_CODE_GENERATOR_H_
 
+#include <list>
+
 #include <GTLCore/String.h>
 
 #include <GTLCore/Macros.h>
@@ -42,6 +44,11 @@
   class Type;
   class Value;
   class VariableNG;
+  class Function;
+  class GenerationContext;
+  namespace AST {
+    class Expression;
+  }
   /**
    * @internal
    * This class is private to OpenGTL and shouldn't be use outside.
@@ -60,19 +67,19 @@
       /**
        * @return an integer constant
        */
-      llvm::Constant* integerToConstant(int v);
+      static llvm::Constant* integerToConstant(int v);
       /**
        * @return a boolean constant
        */
-      llvm::Constant* boolToConstant(bool v);
+      static llvm::Constant* boolToConstant(bool v);
       /**
        * @return a float constant
        */
-      llvm::Constant* floatToConstant(float v);
+      static llvm::Constant* floatToConstant(float v);
       /**
        * @return convert a \ref Value to a llvm constant
        */
-      llvm::Constant* valueToConstant( const GTLCore::Value& v);
+      static llvm::Constant* valueToConstant( const GTLCore::Value& v);
       /**
        * Create a function and add it to the module.
        * @param name name of the function
@@ -231,6 +238,8 @@
        * @return a pointer on the value of an array
        */
       llvm::Value* accessArrayValue( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _index );
+    public:
+      GTLCore::ExpressionResult callFunction( GenerationContext& _gc, llvm::BasicBlock* _bb, const GTLCore::Function* _function, const std::list<AST::Expression*>& m_arguments );
     private:
       llvm::Value* createComparisonExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);
       ExpressionResult createComparisonExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType, unsigned int integerPred, unsigned int floatPred);

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Function.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Function.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Function.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -28,6 +28,10 @@
   class Program;
 }
 
+namespace OpenShiva {
+  class Types;
+}
+
 namespace GTLCore {
   class Type;
   class Value;
@@ -48,6 +52,8 @@
       friend class ParserBase;
       friend class OpenCTL::Compiler;
       friend class OpenCTL::Program;
+      friend class OpenShiva::Types;
+      friend class CodeGenerator;
       class Data;
     public:
       /**

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Function_p.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -19,10 +19,17 @@
 
 #include "Function_p.h"
 
+#include <llvm/DerivedTypes.h>
+#include <llvm/Module.h>
+#include <llvm/Type.h>
+
 #include "Parameter.h"
 
 #include "Debug.h"
 #include "ScopedName.h"
+#include "Value.h"
+#include "Type.h"
+#include "Type_p.h"
 
 using namespace GTLCore;
 
@@ -66,3 +73,32 @@
 {
   return _functionName.nameSpace() + "_" + _functionName.name() + GTLCore::String::number( (int)_parameters.size() );
 }
+
+GTLCore::Function* Function::Private::createExternalFunction(llvm::Module* _module, const GTLCore::String& _name, const GTLCore::String& _symbolName, const GTLCore::Type* retType, int _count, ...)
+{
+  std::vector<GTLCore::Parameter> arguments;
+  va_list argp;
+  va_start(argp, _count);
+  for(int i = 0; i < _count; ++i)
+  {
+    const GTLCore::Type* type = va_arg(argp, const GTLCore::Type*);
+    arguments.push_back(GTLCore::Parameter("", type, false, false, GTLCore::Value() ) );
+  }
+  va_end(argp);
+  return createExternalFunction(_module, _name, _symbolName, retType, arguments );
+}
+
+GTLCore::Function* Function::Private::createExternalFunction(llvm::Module* _module, const GTLCore::String& _name, const GTLCore::String& _symbolName, const GTLCore::Type* retType, const std::vector<GTLCore::Parameter>& arguments)
+{
+  std::vector<const llvm::Type*> llvmArguments;
+  for(unsigned int i = 0; i < arguments.size(); ++i)
+  {
+    llvmArguments.push_back( arguments[i].type()->d->type());
+  }
+  std::vector<llvm::Function*> functions(arguments.size() + 1);
+  functions[arguments.size() ] = dynamic_cast<llvm::Function*>( _module->getOrInsertFunction( _symbolName, llvm::FunctionType::get(retType->d->type(), llvmArguments, false ) ) );
+  GTLCore::Function::Data* data = new GTLCore::Function::Data(arguments, arguments.size() );
+  data->setFunctions( functions );
+  data->setModule( _module );
+  return new GTLCore::Function( GTLCore::ScopedName("", _name), retType, data );
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Function_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Function_p.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Function_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -43,6 +43,8 @@
     const GTLCore::Type* returnType;
     Function::Data* data;
     std::vector<FunctionCaller*> functionsCaller;
+    static GTLCore::Function* createExternalFunction(llvm::Module* _module, const GTLCore::String& _name, const GTLCore::String& _symbolName, const GTLCore::Type* retType, const std::vector<GTLCore::Parameter>& arguments);
+    static GTLCore::Function* createExternalFunction(llvm::Module* _module, const GTLCore::String& _name, const GTLCore::String& _symbolName, const GTLCore::Type* retType, int _count, ...);
   };
   /**
    * @internal

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -56,6 +56,7 @@
     friend class VariableNG;
     friend class OpenShiva::Types;
     friend class ParserBase;
+    friend class Function;
     public:
       enum DataType {
         UNDEFINED,

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -20,7 +20,9 @@
 #include "Type_p.h"
 
 #include "Debug.h"
+#include "Function.h"
 #include "Parameter.h"
+#include "ScopedName.h"
 
 using namespace GTLCore;
 
@@ -29,18 +31,12 @@
 
 struct Type::StructFunctionMember::Private
 {
-  GTLCore::String name;
-  GTLCore::String symbolName;
-  const GTLCore::Type* returnType;
-  std::vector<Parameter> parameters;
+  GTLCore::Function* function; // TODO make it shareable, and free memory
 };
 
-Type::StructFunctionMember::StructFunctionMember(const GTLCore::String& _name, const GTLCore::String& _symbolName, const Type* _type, const std::vector<Parameter>& _parameters) : d(new Private)
+Type::StructFunctionMember::StructFunctionMember(Function* _function) : d(new Private)
 {
-  d->name = _name;
-  d->symbolName = _symbolName;
-  d->returnType = _type;
-  d->parameters = _parameters;
+  d->function = _function;
 }
 
 Type::StructFunctionMember::StructFunctionMember(const StructFunctionMember& _rhs) : d(new Private)
@@ -61,22 +57,22 @@
 
 const GTLCore::String& Type::StructFunctionMember::name() const
 {
-  return d->name;
+  return d->function->name().name();
 }
 
 const Type* Type::StructFunctionMember::returnType() const
 {
-  return d->returnType;
+  return d->function->returnType();
 }
 
-const GTLCore::String& Type::StructFunctionMember::symbolName() const
+const std::vector<Parameter>& Type::StructFunctionMember::parameters() const
 {
-  return d->symbolName;
+  return d->function->parameters();
 }
 
-const std::vector<Parameter>& Type::StructFunctionMember::parameters() const
+const Function* Type::StructFunctionMember::function() const
 {
-  return d->parameters;
+  return d->function;
 }
 
 Type::Private::Private( Type::DataType _dataType)

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -27,6 +27,7 @@
 }
 
 namespace GTLCore {
+  class Function;
   class Type::StructFunctionMember {
     public:
       /**
@@ -38,7 +39,7 @@
        * @param _type 
        * @param _parameters 
        */
-      StructFunctionMember(const GTLCore::String& _name, const GTLCore::String& _symbolName, const Type* _returnType, const std::vector<Parameter>& _parameters);
+      StructFunctionMember(Function* _function);
       StructFunctionMember(const StructFunctionMember& _rhs);
       StructFunctionMember& operator=(const StructFunctionMember& _rhs);
       ~StructFunctionMember();
@@ -51,13 +52,14 @@
         */
       const Type* returnType() const;
       /**
-        * @return the name of the function
-        */
-      const GTLCore::String& symbolName() const;
-      /**
         * @return the list of arguments
         */
       const std::vector<Parameter>& parameters() const;
+      
+      /**
+       * @return the function associated with this member
+       */
+      const Function* function() const;
     private:
       struct Private;
       Private* const d;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-15 21:10:19 UTC (rev 198)
@@ -8,6 +8,7 @@
   Kernel.cpp
 # Internal files
   Compiler_p.cpp
+  CodeGenerator_p.cpp
   Lexer_p.cpp
   Parser_p.cpp
   Types_p.cpp

Added: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -0,0 +1,90 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "CodeGenerator_p.h"
+
+#include <vector>
+
+#include <llvm/CallingConv.h>
+#include <llvm/Constant.h>
+#include <llvm/DerivedTypes.h>
+#include <llvm/Function.h>
+#include <llvm/Instructions.h>
+#include <llvm/Value.h>
+#include <llvm/ParameterAttributes.h>
+
+#include "GTLCore/GenerationContext_p.h"
+#include "GTLCore/CodeGenerator_p.h"
+
+#include "wrappers/PixelWrap_p.h"
+
+
+using namespace OpenShiva;
+
+llvm::BasicBlock* CodeGenerator::memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, int _size )
+{
+  // Initialise llvm_memcpy_i32
+  // TODO that stuff was copied from a llvmgcc output
+  std::vector<const llvm::Type*> memcpyTyArgs;
+  memcpyTyArgs.push_back(llvm::PointerType::get(llvm::IntegerType::get(8), 0));
+  memcpyTyArgs.push_back(llvm::PointerType::get(llvm::IntegerType::get(8), 0));
+  memcpyTyArgs.push_back(llvm::IntegerType::get(32));
+  memcpyTyArgs.push_back(llvm::IntegerType::get(32));
+  llvm::FunctionType* memcpyTy = llvm::FunctionType::get( llvm::Type::VoidTy, memcpyTyArgs, false);
+  
+  llvm::Function* func_llvm_memcpy_i32 = new llvm::Function(
+      memcpyTy, llvm::GlobalValue::ExternalLinkage, "llvm.memcpy.i32", _gc.llvmModule()); // (external, no body)
+  func_llvm_memcpy_i32->setCallingConv(llvm::CallingConv::C);
+  
+  const llvm::ParamAttrsList *func_llvm_memcpy_i32_PAL = 0;
+  {
+    llvm::ParamAttrsVector Attrs;
+    llvm::ParamAttrsWithIndex PAWI;
+    PAWI.index = 0; PAWI.attrs = 0  | llvm::ParamAttr::NoUnwind;
+    Attrs.push_back(PAWI);
+    func_llvm_memcpy_i32_PAL = llvm::ParamAttrsList::get(Attrs);
+  }
+  func_llvm_memcpy_i32->setParamAttrs(func_llvm_memcpy_i32_PAL);
+
+  // Access to the data pointer for the _pixel
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_DATA));
+  llvm::Value* _pointerToPixelVector =
+      new llvm::GetElementPtrInst( _pixel, indexes.begin(), indexes.end(), "", _currentBlock );
+  // Cast the vector to a "char*"
+  llvm::Value* _pointerToPixelVectorU8 = new llvm::BitCastInst(
+      _pointerToPixelVector, llvm::PointerType::get(llvm::IntegerType::get(8), 0), "", _currentBlock);
+  
+  
+  // Call llvm.memcpy.i32
+  std::vector<llvm::Value*> memcpy_params;
+  memcpy_params.push_back( _pointerToPixelVectorU8 );
+  memcpy_params.push_back( _dataPointer );
+  memcpy_params.push_back( GTLCore::CodeGenerator::integerToConstant( _size ) );
+  memcpy_params.push_back( GTLCore::CodeGenerator::integerToConstant( 1 ) );
+  llvm::CallInst* callMemCpy = new llvm::CallInst(
+                  func_llvm_memcpy_i32, memcpy_params.begin(), memcpy_params.end(), "", _currentBlock);
+  callMemCpy->setCallingConv(llvm::CallingConv::C);
+  callMemCpy->setTailCall( false );
+
+  
+  return _currentBlock;
+}
+


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPENSHIVA_CODE_GENERATOR_P_H_
+#define _OPENSHIVA_CODE_GENERATOR_P_H_
+
+namespace llvm {
+  class BasicBlock;
+  class Value;
+}
+
+namespace GTLCore {
+  class GenerationContext;
+}
+
+namespace OpenShiva {
+  class CodeGenerator {
+    public:
+      /**
+       * @internal
+       * Copy a pixel from memory to the vector.
+       */
+      static llvm::BasicBlock* memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, int _size );
+  };
+}
+
+#endif


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -124,7 +124,7 @@
   }
   delete d->moduleData;
   d->moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
-  Types::fillTypeManager( d->moduleData->typeManager(), d->pixelDescription, d->referenceDepth );
+  Types::fillTypeManager( d->moduleData->llvmModule(), d->moduleData->typeManager(), d->pixelDescription, d->referenceDepth );
   Compiler c;
   bool result = c.compile( d->source, d->name, d->moduleData );
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -22,11 +22,12 @@
 #include <map>
 #include <vector>
 
+#include "GTLCore/Function_p.h"
+#include "GTLCore/Macros.h"
+#include "GTLCore/Parameter.h"
 #include "GTLCore/PixelDescription.h"
 #include "GTLCore/Type.h"
 #include "GTLCore/Type_p.h"
-#include "GTLCore/Macros.h"
-#include "GTLCore/Parameter.h"
 #include "GTLCore/TypeManager.h"
 #include "GTLCore/TypeManager_p.h"
 #include "GTLCore/Value.h"
@@ -49,7 +50,7 @@
 std::vector<GTLCore::Type::StructDataMember> Types::Private::s_imageDataMembers;
 std::vector<GTLCore::Type::StructDataMember> Types::Private::s_pixelDataMembers;
 
-void Types::fillTypeManager( GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  )
+void Types::fillTypeManager( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  )
 {
   SHIVA_DEBUG("fillTypeManager");
   for( int i = 1; i <= 5; ++i)
@@ -62,26 +63,11 @@
   }
   _typeManager->d->createStructure( "image", Private::s_imageDataMembers );
   _typeManager->d->createStructure( "pixel", Private::s_pixelDataMembers );
-  createRegionType( _typeManager );
+  createRegionType( _module, _typeManager );
 }
 
-
-GTLCore::Type::StructFunctionMember createTypeMember(const GTLCore::String& _name, const GTLCore::String& _symbolName, const GTLCore::Type* retType, int count, ...)
+void Types::createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager )
 {
-  std::vector<GTLCore::Parameter> arguments;
-  va_list argp;
-  va_start(argp, count);
-  for(int i = 0; i < count; ++i)
-  {
-    const GTLCore::Type* type = va_arg(argp, const GTLCore::Type*);
-    arguments.push_back(GTLCore::Parameter("", type, false, false, GTLCore::Value() ) );
-  }
-  va_end(argp);
-  return GTLCore::Type::StructFunctionMember( _name, _symbolName, retType, arguments);
-}
-
-void Types::createRegionType( GTLCore::TypeManager* _typeManager )
-{
   static std::vector<GTLCore::Type::StructDataMember> regionDataMembers;
   static std::vector<GTLCore::Type::StructFunctionMember> regionFunctionMembers;
   regionDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
@@ -89,8 +75,38 @@
   regionDataMembers.push_back( GTLCore::Type::StructDataMember( "width", GTLCore::Type::Float ) );
   regionDataMembers.push_back( GTLCore::Type::StructDataMember( "height", GTLCore::Type::Float ) );
   const GTLCore::Type* type = _typeManager->d->createStructure( "region", regionDataMembers);
-  type->d->addFunctionMember( createTypeMember( "intersect", "_Z21region_wrap_intersectP10RegionWrapPKS_", GTLCore::Type::Void, 1, type ) );
-  type->d->addFunctionMember( createTypeMember( "union", "_Z17region_wrap_unionP10RegionWrapPKS_", GTLCore::Type::Void, 1, type ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "left", "region_wrap_left", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "right", "region_wrap_right", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "bottom", "region_wrap_bottom", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "top", "region_wrap_top", GTLCore::Type::Float, 1,
+                GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "intersect", "region_wrap_intersect", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "union", "region_wrap_union", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Pointer ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "outset", "region_wrap_outset", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Float ) ) );
+  type->d->addFunctionMember( GTLCore::Type::StructFunctionMember(
+          GTLCore::Function::Private::createExternalFunction(
+                _module, "inset", "region_wrap_inset", GTLCore::Type::Void, 2,
+                GTLCore::Type::Pointer, GTLCore::Type::Float ) ) );
 }
 
 
@@ -106,6 +122,7 @@
 //     Types::Private::s_regionFunctionMembers.push_back( createTypeMember("intersect", "", 
   }
   { // Pixel
+    // struct { float x, float y, vecX data; }
 //     Types::Private::s_pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "pixel", GTLCore::Type::Pointer, -1) );
   }
 }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Types_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -20,6 +20,10 @@
 #ifndef _OPENSHIVA_TYPES_P_H_
 #define _OPENSHIVA_TYPES_P_H_
 
+namespace llvm {
+  class Module;
+}
+
 namespace GTLCore {
   class Type;
   class TypeManager;
@@ -42,11 +46,11 @@
   }
   class Types {
     public:
-      static void fillTypeManager( GTLCore::TypeManager*, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  );
+      static void fillTypeManager( llvm::Module* _module, GTLCore::TypeManager*, const GTLCore::PixelDescription& _pixelDescription, const GTLCore::Type* _referenceDepth  );
     public:
       struct Private;
     private:
-      static void createRegionType( GTLCore::TypeManager* _typeManager );
+      static void createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager );
   };
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -17,3 +17,23 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#ifndef _PIXEL_WRAP_P_H_
+#define _PIXEL_WRAP_P_H_
+
+//---------------------- WARNING ----------------------//
+// Whenever the following structure is edited,         //
+// it's llvm declaration must be changed too in        //
+// Types_p.cpp !                                       //
+//---------------------- WARNING ----------------------//
+struct PixelWrap {
+  float x;
+  float y;
+  void* data;
+  enum PixelIndexes {
+    INDEX_X = 0,
+    INDEX_Y = 1,
+    INDEX_DATA = 2
+  };
+};
+
+#endif

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.cpp	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.cpp	2008-06-15 21:10:19 UTC (rev 198)
@@ -19,6 +19,28 @@
 
 #include "RegionWrap_p.h"
 
+extern "C" {
+
+float region_wrap_left( RegionWrap* self )
+{
+  return self->x;
+}
+
+float region_wrap_top( RegionWrap* self )
+{
+  return self->y;
+}
+
+float region_wrap_right( RegionWrap* self )
+{
+  return self->x + self->width;
+}
+
+float region_wrap_bottom( RegionWrap* self )
+{
+  return self->y + self->height;
+}
+
 void region_wrap_intersect( RegionWrap* self, const RegionWrap* reg )
 {
   float s_x2 = self->x + self->width;
@@ -28,8 +50,8 @@
   
   if( self->x < reg->x) self->x = reg->x;
   if( self->y < reg->y) self->y = reg->y;
-  self->width = ( ( s_x2 > r_x2 ) ? r_x2 : s_x2 ) - reg->x;
-  self->height = ( ( s_y2 > r_y2 ) ? r_y2 : s_y2 ) - reg->y;
+  self->width = ( ( s_x2 > r_x2 ) ? r_x2 : s_x2 ) - self->x;
+  self->height = ( ( s_y2 > r_y2 ) ? r_y2 : s_y2 ) - self->y;
 }
 
 void region_wrap_union( RegionWrap* self, const RegionWrap* reg )
@@ -41,6 +63,24 @@
   
   if( self->x > reg->x) self->x = reg->x;
   if( self->y > reg->y) self->y = reg->y;
-  self->width = ( ( s_x2 > r_x2 ) ? s_x2 : r_x2 ) - reg->x;
-  self->height = ( ( s_y2 > r_y2 ) ? s_y2 : r_y2 ) - reg->y;
+  self->width = ( ( s_x2 > r_x2 ) ? s_x2 : r_x2 ) - self->x;
+  self->height = ( ( s_y2 > r_y2 ) ? s_y2 : r_y2 ) - self->y;
 }
+
+void region_wrap_outset( RegionWrap* self, float amount )
+{
+  self->x -= amount;
+  self->y -= amount;
+  self->width += 2 * amount;
+  self->height += 2 * amount;
+}
+
+void region_wrap_inset( RegionWrap* self, float amount )
+{
+  self->x += amount;
+  self->y += amount;
+  self->width -= 2 * amount;
+  self->height -= 2 * amount;
+}
+
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h	2008-06-15 21:10:19 UTC (rev 198)
@@ -30,7 +30,17 @@
   float x, y, width, height;
 };
 
-void region_wrap_intersect( const RegionWrap& self, const RegionWrap* reg );
-void region_wrap_union( const RegionWrap& self, const RegionWrap* reg );
+extern "C" {
+  float region_wrap_left( RegionWrap* self );
+  float region_wrap_top( RegionWrap* self );
+  float region_wrap_right( RegionWrap* self );
+  float region_wrap_bottom( RegionWrap* self );
+  
+  void region_wrap_intersect( RegionWrap* self, const RegionWrap* reg );
+  void region_wrap_union( RegionWrap* self, const RegionWrap* reg );
+  
+  void region_wrap_outset( RegionWrap* self, float amount );
+  void region_wrap_inset( RegionWrap* self, float amount );
+}
 
 #endif

Modified: trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex
===================================================================
--- trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex	2008-06-15 21:10:19 UTC (rev 198)
@@ -63,6 +63,17 @@
 
 \section{Functions}
 
+\subsection{evaluatePixel}
+
+\begin{verbatim}
+  void evaluatePixel(input image source1, input image source2, ..., output pixel
+result)
+  {
+    ...
+  }
+\end{verbatim}
+
+
 \subsection{needed}
 
 \begin{verbatim}
@@ -255,6 +266,9 @@
 
 And the generic pixel type \verb|pixel| whose number of channels is defined at compile type.
 
+\subsubsection{Members}
+\paragraph{}
+
 \subsection{Channel type for pixel and image}
 
 The channels type of generic \verb|pixel| and \verb|image| can either be an array of elements
@@ -286,7 +300,7 @@
 pixels, and the vertical coordinate of the top pixels and bottom pixels.
 
 \begin{verbatim}
-  Region reg = { 1, 2, 10, 20 };
+  region reg = { 1, 2, 10, 20 };
   reg.left() == 1;
   reg.left() == reg.x
   reg.top() == 2;
@@ -299,25 +313,45 @@
 
 
 \paragraph{Intersect}
-The intersect function will intersect the current region with an other region.
+The \verb|intersect| function will intersect the current region with an other
+region.
 
 \begin{verbatim}
-  Region reg1 = { 0, 0, 2, 2 };
-  Region reg2 = { 1, -1, 3, 2 };
+  region reg1 = { 0, 0, 2, 2 };
+  region reg2 = { 1, -1, 3, 2 };
   reg1.intersect( reg2 );
   // Now reg1 == { 1, 0, 1, 1 };
 \end{verbatim}
 
 \paragraph{Union}
-The union function will unify the current region with an other region.
+The \verb|union| function will unify the current region with an other region.
 
 \begin{verbatim}
-  Region reg1 = { 0, 0, 2, 2 };
-  Region reg2 = { 1, -1, 3, 2 };
+  region reg1 = { 0, 0, 2, 2 };
+  region reg2 = { 1, -1, 3, 2 };
   reg1.union( reg2 );
-  // Now reg1 == { 0, -1, 4, 2 };
+  // Now reg1 == { 0, -1, 4, 3 };
 \end{verbatim}
 
+\paragraph{Outset}
+The \verb|outset| function expand each edge of a given amount.
+
+\begin{verbatim}
+  region reg = { 0, 1, 2, 3 };
+  reg.outset(1);
+  // Now reg == { -1, 0, 4, 5 };
+\end{verbatim}
+
+\paragraph{Inset}
+The \verb|inset| function contract each edge of a given amount.
+
+\begin{verbatim}
+  region reg = { 0, 1, 2, 3 };
+  reg.inset(1);
+  // Now reg == { 1, 2, 0, 1 };
+\end{verbatim}
+
+
 \section{Special types}
 
 \subsection{Void}

Modified: trunk/OpenGTL/OpenShiva/doc/specification/region.pdf
===================================================================
(Binary files differ)

Modified: trunk/OpenGTL/OpenShiva/doc/specification/region.svg
===================================================================
--- trunk/OpenGTL/OpenShiva/doc/specification/region.svg	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/doc/specification/region.svg	2008-06-15 21:10:19 UTC (rev 198)
@@ -65,9 +65,9 @@
      objecttolerance="10"
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
-     inkscape:zoom="1.979899"
+     inkscape:zoom="1.4"
      inkscape:cx="278.02048"
-     inkscape:cy="596.04111"
+     inkscape:cy="547.7287"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="true"
@@ -215,43 +215,43 @@
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Sans"
-       x="110"
-       y="74.094482"
+       x="100"
+       y="64.094482"
        id="text5022"><tspan
          sodipodi:role="line"
          id="tspan5024"
-         x="110"
-         y="74.094482">(left, top)</tspan></text>
+         x="100"
+         y="64.094482">(left, top)</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Sans"
-       x="100"
+       x="90"
        y="294.09448"
        id="text5034"><tspan
          sodipodi:role="line"
          id="tspan5036"
-         x="100"
+         x="90"
          y="294.09448">(left, bottom)</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Sans"
-       x="260"
+       x="270"
        y="294.09448"
        id="text5038"><tspan
          sodipodi:role="line"
          id="tspan5040"
-         x="260"
+         x="270"
          y="294.09448">(bottom, top)</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Sans"
-       x="290"
-       y="74.094482"
+       x="300"
+       y="64.094482"
        id="text5042"><tspan
          sodipodi:role="line"
          id="tspan5044"
-         x="290"
-         y="74.094482">(right, top)</tspan></text>
+         x="300"
+         y="64.094482">(right, top)</tspan></text>
     <path
        style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        d="M 360,264.27305 L 360,84.273058"
@@ -266,33 +266,33 @@
        id="path5050" />
     <path
        style="fill:none;fill-rule:evenodd;stroke:#808080;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
-       d="M 410,94.094482 L 410,64.936582 L 400,64.936582"
+       d="M 420,84.094482 L 420,65.036721 L 410,65.036721"
        id="path5054" />
     <path
        style="fill:none;fill-rule:evenodd;stroke:#808080;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
-       d="M 410,254.09448 L 410,283.25238 L 400,283.25238"
+       d="M 420,264.09448 L 420,283.15224 L 410,283.15224"
        id="path5056" />
     <path
        style="fill:none;fill-rule:evenodd;stroke:#808080;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
-       d="M 90,254.09448 L 90,283.25238 L 99.999996,283.25238"
+       d="M 80,264.09448 L 80,283.15224 L 89.999996,283.15224"
        id="path5058" />
     <path
        style="fill:none;fill-rule:evenodd;stroke:#808080;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
-       d="M 90,94.094482 L 90,64.936582 L 99.999996,64.936582"
+       d="M 80,84.936586 L 80,64.950081 L 89.999996,64.950081"
        id="path5060" />
     <text
        xml:space="preserve"
        style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Sans"
-       x="130"
-       y="49.094482"
+       x="100"
+       y="44.094482"
        id="text5102"><tspan
          sodipodi:role="line"
          id="tspan5104"
-         x="130"
-         y="49.094482">(x, y)</tspan></text>
+         x="100"
+         y="44.094482">(x, y)</tspan></text>
     <path
        style="fill:none;fill-rule:evenodd;stroke:#808080;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
-       d="M 90,73.252382 L 90,44.094482 L 99.999996,44.094482"
+       d="M 80,64.094482 L 80,45.036721 L 89.999996,45.036721"
        id="path5106" />
   </g>
 </svg>

Modified: trunk/OpenGTL/OpenShiva/tests/structures/region.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/structures/region.shiva	2008-06-14 13:29:57 UTC (rev 197)
+++ trunk/OpenGTL/OpenShiva/tests/structures/region.shiva	2008-06-15 21:10:19 UTC (rev 198)
@@ -3,15 +3,67 @@
   int runTest()
   {
     int count = 0;
-    region r;
-    r.x = 2;
-    r.y = 4;
-    r.width = 10;
-    r.height = 20;
-    if( r.x != 2 ) ++count;
-    if( r.y != 4 ) ++count;
-    if( r.width != 10 ) ++count;
-    if( r.height != 20 ) ++count;
+    {
+      region r;
+      r.x = 2;
+      r.y = 4;
+      r.width = 10;
+      r.height = 20;
+      if( r.left() != r.x ) ++count;
+      if( r.right() != 12 ) ++count;
+      if( r.top() != r.y ) ++count;
+      if( r.bottom() != 24 ) ++count;
+      if( r.x != 2 ) ++count;
+      if( r.y != 4 ) ++count;
+      if( r.width != 10 ) ++count;
+      if( r.height != 20 ) ++count;
+    }
+    {
+      region reg1 = { 0, 0, 2, 2 };
+      region reg2 = { 1, -1, 3, 2 };
+      if( reg1.x != 0 ) ++count;
+      if( reg1.y != 0 ) ++count;
+      if( reg1.width != 2 ) ++count;
+      if( reg1.height != 2 ) ++count;
+      if( reg2.x != 1 ) ++count;
+      if( reg2.y != -1 ) ++count;
+      if( reg2.width != 3 ) ++count;
+      if( reg2.height != 2 ) ++count;
+      
+      reg1.intersect( reg2 );
+      if( reg1.x != 1 ) ++count;
+      if( reg1.y != 0 ) ++count;
+      if( reg1.width != 1 ) ++count;
+      if( reg1.height != 1 ) ++count;
+    }
+    {
+      region reg1 = { 0, 0, 2, 2 };
+      region reg2 = { 1, -1, 3, 2 };
+      reg1.union(reg2);
+      if( reg1.x != 0 ) ++count;
+      if( reg1.y != -1 ) ++count;
+      if( reg1.width != 4 ) ++count;
+      if( reg1.height != 3 ) ++count;
+      
+    }
+    {
+      region reg1 = { 0, 1, 2, 3 };
+      reg1.outset(1);
+      if( reg1.x != -1 ) ++count;
+      if( reg1.y != 0 ) ++count;
+      if( reg1.width != 4 ) ++count;
+      if( reg1.height != 5 ) ++count;
+      reg1.inset(2);
+      if( reg1.x != 1 ) ++count;
+      if( reg1.y != 2 ) ++count;
+      if( reg1.width != 0 ) ++count;
+      if( reg1.height != 1 ) ++count;
+      reg1.outset(1);
+      if( reg1.x != 0 ) ++count;
+      if( reg1.y != 1 ) ++count;
+      if( reg1.width != 2 ) ++count;
+      if( reg1.height != 3 ) ++count;
+    }
     return count;
   }
 }


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