[opengtl-commits] [229] Kernel::evaluatePixeles take a Region as parameter

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


Revision: 229
Author:   cyrille
Date:     2008-06-24 21:37:12 +0200 (Tue, 24 Jun 2008)

Log Message:
-----------
Kernel::evaluatePixeles take a Region as parameter

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
    trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-24 19:36:28 UTC (rev 228)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-24 19:37:12 UTC (rev 229)
@@ -138,6 +138,24 @@
   return _currentBlock;
 }
 
+void CodeGenerator::setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _iVal, llvm::Value* _jVal )
+{
+  std::vector<llvm::Value*> indexes;
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
+  indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_X));
+  new llvm::StoreInst(
+        _gc.codeGenerator()->convertValueTo( _currentBlock, _iVal, GTLCore::Type::Integer32, GTLCore::Type::Float ),
+        new llvm::GetElementPtrInst( _pixel, indexes.begin(), indexes.end(), "", _currentBlock ),
+        "",
+        _currentBlock );
+  indexes[1] = _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_Y);
+  new llvm::StoreInst(
+        _gc.codeGenerator()->convertValueTo( _currentBlock, _jVal, GTLCore::Type::Integer32, GTLCore::Type::Float ),
+        new llvm::GetElementPtrInst( _pixel, indexes.begin(), indexes.end(), "", _currentBlock ),
+        "",
+        _currentBlock );
+}
+
 llvm::Function* CodeGenerator::generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription)
 {
   GTLCore::CodeGenerator codeGenerator( _moduleData );
@@ -147,13 +165,13 @@
   //  AbstractImage* are seen as a void*.
   //
   //  template< int nbSources >
-  //  void evaluatePixeles( int _width, int _height, AbstractImage** _sources, AbstractImage* _result)
+  //  void evaluatePixeles( int _x, int _y, int _width, int _height, AbstractImage** _sources, AbstractImage* _result)
   //  {
-  //    for( int i = 0; i < nbSource; ++i )
+  //    for( int i = _x; i < nbSource; ++i )
   //    {
   //      imageWrap[i] = wrap(sources[i]);
   //    }
-  //    for( int j = 0; j < height; ++j )
+  //    for( int j = _y; j < height; ++j )
   //    {
   //      for( int i = 0; i < width; ++i )
   //      {
@@ -170,6 +188,8 @@
   std::vector<const llvm::Type*> params;
   params.push_back( llvm::Type::Int32Ty );
   params.push_back( llvm::Type::Int32Ty );
+  params.push_back( llvm::Type::Int32Ty );
+  params.push_back( llvm::Type::Int32Ty );
   params.push_back( llvm::PointerType::get( llvm::PointerType::get( llvm::Type::Int8Ty, 0 ), 0 ) );
   params.push_back( llvm::PointerType::get( _moduleData->typeManager()->getStructure( "image" )->d->type(), 0 ) );
   llvm::FunctionType* definitionType = llvm::FunctionType::get( llvm::Type::VoidTy, params, false );
@@ -183,22 +203,31 @@
     func->getBasicBlockList().push_back( initialBlock );
   // Get the args.
     llvm::Function::arg_iterator arg_it = func->arg_begin();
-    //   int _width = first arg;
+    //   int _x = first arg;
+    llvm::Value* arg_x = arg_it;
+    //   int _y = second arg;
+    ++arg_it;
+    llvm::Value* arg_y = arg_it;
+    //   int _width = third arg;
+    ++arg_it;
     llvm::Value* arg_width = arg_it;
-    //   int _height = second arg;
+    //   int _height = fourth arg;
     ++arg_it;
     llvm::Value* arg_height = arg_it;
-    //   void** _sources = third arg;
+    //   void** _sources = fifth arg;
     ++arg_it;
 //     llvm::Value* arg_sources = arg_it;
-    //   void* _result = fourth arg;
+    //   void* _result = sixth arg;
     ++arg_it;
     llvm::Value* arg_result = arg_it;
+  // Create the pixel
+    GTLCore::VariableNG* resultVar = new GTLCore::VariableNG( _moduleData->typeManager()->getStructure( "pixel" ), false );
+  resultVar->initialise( generationContext, initialBlock, 0, 0, std::list<llvm::Value*>());
   // Construct the "conditions" of the first loop
     // int j = 0;
     GTLCore::VariableNG* incJ = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
     incJ->initialise( generationContext, initialBlock,
-                      GTLCore::CodeGenerator::integerToConstant(0),
+                      arg_x,
                       GTLCore::Type::Integer32, std::list<llvm::Value*>());
     // {
       llvm::BasicBlock* firstBlockJLoop = new llvm::BasicBlock;
@@ -206,14 +235,15 @@
       // int i = 0;
       GTLCore::VariableNG* incI = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
       incI->initialise( generationContext, firstBlockJLoop,
-                        GTLCore::CodeGenerator::integerToConstant(0),
+                        arg_y,
                         GTLCore::Type::Integer32, std::list<llvm::Value*>());
       // {
         llvm::BasicBlock* firstBlockILoop = new llvm::BasicBlock;
         func->getBasicBlockList().push_back( firstBlockILoop );
-        // Create the pixel
-        GTLCore::VariableNG* resultVar = new GTLCore::VariableNG( _moduleData->typeManager()->getStructure( "pixel" ), false );
-        resultVar->initialise( generationContext, firstBlockILoop, 0, 0, std::list<llvm::Value*>());
+        llvm::Value* jVal = incJ->get( generationContext, firstBlockILoop );
+        llvm::Value* iVal = incI->get( generationContext, firstBlockILoop );
+        // Set the coordinates of the pixel
+        setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(), iVal, jVal );
         // Call evaluatePixel
         GTLCore::Function* ePFunction = _moduleData->function( _kernel->name(), "evaluatePixel" );
         SHIVA_ASSERT( ePFunction );
@@ -226,8 +256,8 @@
         // Call image_wrap_data on the result to get the pointer on destination data
         std::vector<llvm::Value*> image_wrap_data_params;
         image_wrap_data_params.push_back( arg_result );
-        image_wrap_data_params.push_back( incI->get( generationContext, firstBlockILoop ) );
-        image_wrap_data_params.push_back( incJ->get( generationContext, firstBlockILoop ) );
+        image_wrap_data_params.push_back( iVal );
+        image_wrap_data_params.push_back( jVal );
          llvm::Value* pointer =  new llvm::CallInst( Wrapper::image_wrap_dataFunction( _moduleData->llvmModule(), _moduleData->typeManager()->getStructure( "image" ) ), image_wrap_data_params.begin(), image_wrap_data_params.end(), "", firstBlockILoop );
         llvm::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(), pointer, _pixelDescription.bitsSize() / 8 );
       // }

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-24 19:36:28 UTC (rev 228)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-06-24 19:37:12 UTC (rev 229)
@@ -63,6 +63,7 @@
       static llvm::Function* createMemCpyFunction( llvm::Module* _module );
       static llvm::Value* accessPixelDataAsU8Ptr( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel);
       static llvm::Value* callMemcpy( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _src, llvm::Value* _n );
+      static void setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _iVal, llvm::Value* _jVal );
     private:
       static int s_evaluatePixelesId;
   };

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-24 19:36:28 UTC (rev 228)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-24 19:37:12 UTC (rev 229)
@@ -29,6 +29,7 @@
 #include "GTLCore/Function.h"
 #include "GTLCore/ModuleData_p.h"
 #include "GTLCore/PixelDescription.h"
+#include "GTLCore/Region.h"
 #include "GTLCore/Type.h"
 #include "GTLCore/TypeManager.h"
 #include "GTLCore/Value.h"
@@ -163,14 +164,14 @@
   
 }
 
-void Kernel::evaluatePixeles( const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const
+void Kernel::evaluatePixeles( const GTLCore::Region& _region, const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const
 {
   SHIVA_ASSERT( d->evaluatePixelesFunction );
-  void (*func)( int, int, void**, void*) = ( void(*)(int, int, void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
+  void (*func)( int, int, int, int, void**, void*) = ( void(*)(int, int, int, int, void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
   SHIVA_ASSERT(func);
   ImageWrap owrap;
   owrap.image = _outputImage;
-  (*func)( 200, 300, 0, (void*)&owrap); // TODO s/200/width s/300/height
+  (*func)( _region.x(), _region.y(), _region.width(), _region.height(), 0, (void*)&owrap); // TODO s/200/width s/300/height
 }
 
 int Kernel::runTest() const

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-06-24 19:36:28 UTC (rev 228)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-06-24 19:37:12 UTC (rev 229)
@@ -26,6 +26,7 @@
   class ErrorMessage;
   class Type;
   class PixelDescription;
+  class Region;
 }
 
 #include <GTLCore/String.h>
@@ -79,7 +80,7 @@
        */
       GTLCore::String asmSourceCode() const;
     public: // Function call
-      void evaluatePixeles( const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const;
+      void evaluatePixeles( const GTLCore::Region& _region, const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const;
       /**
        * Run the function called "int runTest()" in the Kernel.
        */

Modified: trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-06-24 19:36:28 UTC (rev 228)
+++ trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-06-24 19:37:12 UTC (rev 229)
@@ -25,6 +25,7 @@
 
 // GTLCore Headers
 #include <GTLCore/PixelDescription.h>
+#include <GTLCore/Region.h>
 #include <GTLCore/Type.h>
 
 // OpenShiva Headers
@@ -115,7 +116,7 @@
     }
     OpenShiva::Image image(200,300, pixel );
     memset( image.data(0, 0), 1, 200 * 300 );
-    p.evaluatePixeles( std::list<OpenShiva::AbstractImage*>(), &image );
+    p.evaluatePixeles( GTLCore::Region(0,0, 200, 300), std::list<OpenShiva::AbstractImage*>(), &image );
     std::cout << *((float*)image.data( 0, 0));
   }
   return EXIT_SUCCESS;


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