[opengtl-commits] [329] pixels are auto converted to vectors

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


Revision: 329
Author:   cyrille
Date:     2008-08-31 10:21:32 +0200 (Sun, 31 Aug 2008)

Log Message:
-----------
pixels are auto converted to vectors

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h
    trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva


Modified: trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ConvertCenter_p.cpp	2008-08-31 08:21:32 UTC (rev 329)
@@ -99,6 +99,8 @@
   // Auto conversion
   value1 = createConvertExpression( value1, autoConvertType( value1->type() ) );
   value2 = createConvertExpression( value2, autoConvertType( value2->type() ) );
+  GTL_ASSERT(value1);
+  GTL_ASSERT(value2);
   // If values are of the same type, there is no need to convert
   if( value1->type() == value2->type() )
   {

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-08-31 08:21:32 UTC (rev 329)
@@ -11,6 +11,7 @@
   Parser_p.cpp
   Wrapper_p.cpp
   PixelVisitor_p.cpp
+  PixelConvertExpressionFactory_p.cpp
 # Wrap
   wrappers/ImageWrap_p.cpp
   wrappers/PixelWrap_p.cpp

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-08-31 08:21:32 UTC (rev 329)
@@ -82,6 +82,7 @@
 
 llvm::Value* CodeGenerator::accessPixelDataPtr( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel)
 {
+  SHIVA_DEBUG( *_pixel );
   std::vector<llvm::Value*> indexes;
   indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
   indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_DATA));
@@ -106,7 +107,7 @@
 
 llvm::Value* CodeGenerator::callMemcpy( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _src, llvm::Value* _n )
 {
-  GTL_DEBUG( "memcpy( dst = " << *_dst << ", src = " << *_src << ", _n = " << *_n );
+  SHIVA_DEBUG( "memcpy( dst = " << *_dst << ", src = " << *_src << ", _n = " << *_n );
   // Initialise llvm_memcpy_i32
   llvm::Function* func_llvm_memcpy_i32 = createMemCpyFunction( _gc.llvmModule() );
   // Set parameters

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-08-31 08:21:32 UTC (rev 329)
@@ -42,6 +42,7 @@
   /**
    * @internal
    * Provide code generation function for specific features of OpenShiva
+   * @ingroup OpenShiva
    */
   class CodeGenerator {
     public:

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-08-31 08:21:32 UTC (rev 329)
@@ -124,8 +124,8 @@
   if(d->source.empty()) return;
   cleanup();
   d->moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
-  Wrapper::fillTypeManager( d->moduleData, d->moduleData->typeManager(), d->count_channels_generic );
   Compiler c;
+  Wrapper::fillTypeManager( d->moduleData, d->moduleData->typeManager(), c.convertCenter() , d->count_channels_generic );
   GTLCore::String nameSpace;
   bool result = c.compile( d->source, d->name, d->moduleData, nameSpace );
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-08-31 08:21:32 UTC (rev 329)
@@ -43,6 +43,7 @@
 #include "CodeGenerator_p.h"
 #include "Debug.h"
 #include "PixelVisitor_p.h"
+#include "PixelConvertExpressionFactory_p.h"
 
 #include "wrappers/ImageWrap_p.h"
 
@@ -98,35 +99,41 @@
   return owrap;
 }
 
-void Wrapper::fillTypeManager( GTLCore::ModuleData* _module, GTLCore::TypeManager* _typeManager, int _channels )
+void Wrapper::fillTypeManager( GTLCore::ModuleData* _module, GTLCore::TypeManager* _typeManager, GTLCore::ConvertCenter* _convertCenter, int _channels )
 {
   SHIVA_DEBUG("fillTypeManager");
+  _convertCenter->addConvertExpressionFactory(new PixelConvertExpressionFactory);
   for( int i = 1; i <= 5; ++i)
   {
     // Create Image type
-    const GTLCore::Type* pixelType = createPixelType( _module->llvmModule(), _typeManager, GTLCore::String::number( i ), i );
+    const GTLCore::Type* pixelType = createPixelType( _module->llvmModule(), _typeManager, _convertCenter, GTLCore::String::number( i ), i );
     createImageType( _module, _typeManager, GTLCore::String::number( i ), i, pixelType );
   }
-  const GTLCore::Type* pixelType = createPixelType( _module->llvmModule(), _typeManager, "", _channels );
+  const GTLCore::Type* pixelType = createPixelType( _module->llvmModule(), _typeManager, _convertCenter, "", _channels );
   createImageType( _module, _typeManager, "", _channels, pixelType );
   createRegionType( _module->llvmModule(), _typeManager );
 }
 
-const GTLCore::Type* Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels )
+const GTLCore::Type* Wrapper::createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, GTLCore::ConvertCenter* _convertCenter, const GTLCore::String& _suffix, int _channels )
 {
   //---------------------- WARNING ----------------------//
   // Whenever the following structure is edited,         //
   // it's llvm declaration must be changed too in        //
   // struct PixelWrap !                                  //
   //---------------------- WARNING ----------------------//
+  
+  const GTLCore::Type* vecType = vectorType( _typeManager, _channels );
   std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
-  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", vectorType( _typeManager, _channels ) ) );
+  pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", vecType ) );
   
   pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
   pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "y", GTLCore::Type::Float) );
   
   const GTLCore::Type* type = _typeManager->d->createStructure( "pixel" + _suffix, pixelDataMembers );
   type->d->setVisitor( PixelVisitor::instance() );
+  
+  _convertCenter->addAutoConversion( type, vecType );
+  
   return type;
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h	2008-08-31 08:21:32 UTC (rev 329)
@@ -35,6 +35,7 @@
   class PixelDescription;
   class TypeManager;
   class AbstractImage;
+  class ConvertCenter;
 }
 
 namespace OpenShiva {
@@ -54,7 +55,7 @@
       struct Private;
       Private* const d;
     public:
-      static void fillTypeManager( GTLCore::ModuleData* _module, GTLCore::TypeManager*, int _channels );
+      static void fillTypeManager( GTLCore::ModuleData* _module, GTLCore::TypeManager*, GTLCore::ConvertCenter*, int _channels );
       static llvm::Function* image_wrap_dataFunction( llvm::Module* _module, const GTLCore::Type* _imageType );
       static llvm::FunctionType* image_wrap_sample_nearest_type( GTLCore::TypeManager* _typeManager, const GTLCore::Type* _imageType, const GTLCore::Type* _pixelType );
       static llvm::FunctionType* image_wrap_mem_to_vec_float_type( GTLCore::TypeManager* _typeManager, int _channels );
@@ -65,7 +66,7 @@
       static const GTLCore::Type* vectorType( GTLCore::TypeManager* _typeManager, int _channels );
     private:
       static void createRegionType( llvm::Module* _module, GTLCore::TypeManager* _typeManager );
-      static const GTLCore::Type* createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels );
+      static const GTLCore::Type* createPixelType( llvm::Module* _module, GTLCore::TypeManager* _typeManager, GTLCore::ConvertCenter* _convertCenter, const GTLCore::String& _suffix, int _channels );
       static void createImageType( GTLCore::ModuleData* _moduleData, GTLCore::TypeManager* _typeManager, const GTLCore::String& _suffix, int _channels, const GTLCore::Type* _pixelType );
   };
 }

Modified: trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva	2008-08-31 08:02:30 UTC (rev 328)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva	2008-08-31 08:21:32 UTC (rev 329)
@@ -11,11 +11,8 @@
     float2 point3;
     point3[0] = result.x + 1;
     point3[1] = result.y + 1;
-//     pixel v1 = img.sampleNearest( point1 );
-//     pixel v2 = img.sampleNearest( point2 );
-//     pixel v3 = img.sampleNearest( point3 );
-//     pixel v4 = v1 + v2 + v3;
     pixel v4 = img.sampleNearest( point1 ) + img.sampleNearest( point2 ) + img.sampleNearest( point3 );
-    result = v4 / 3.0;
+    float4 vv4 = v4;
+    result = vv4 / 3.0;
   }
 }


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