[opengtl-commits] [354] * add a wrapper structure for arrays, and common define for the future structure header

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


Revision: 354
Author:   cyrille
Date:     2008-09-03 09:29:51 +0200 (Wed, 03 Sep 2008)

Log Message:
-----------
* add a wrapper structure for arrays, and common define for the future structure header
* add generated/needed/changed function to the kernel

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Region.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h
    trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex
    trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva
    trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp

Added Paths:
-----------
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h
    trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Region.cpp	2008-09-03 07:29:51 UTC (rev 354)
@@ -58,6 +58,26 @@
   return m_height;
 }
 
+int Region::left() const
+{
+  return m_x;
+}
+
+int Region::right() const
+{
+  return m_y + m_width;
+}
+
+int Region::bottom() const
+{
+  return m_y + m_height;
+}
+
+int Region::top() const
+{
+  return m_y;
+}
+
 void Region::setHeight( int _height )
 {
   m_height = _height;

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Region.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Region.h	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Region.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -33,9 +33,13 @@
       ~Region();
       int x() const;
       int y() const;
+      int height() const;
       int width() const;
+      int left() const;
+      int right() const;
+      int bottom() const;
+      int top() const;
       void setWidth( int _width );
-      int height() const;
       void setHeight( int _height );
       bool operator!=( const Region& _region ) const;
     private:

Added: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/Allocate.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -0,0 +1,40 @@
+/*
+ *  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 _ALLOCATE_H_
+#define _ALLOCATE_H_
+
+#include <stdlib.h>
+
+template<class T>
+T* gtlAllocate()
+{
+  T* t = (T*)malloc( sizeof(T) );
+  // t.count = 1;
+  return t;
+}
+
+template<class T>
+void gtlFree( T* t)
+{
+  free(t);
+}
+
+
+#endif

Added: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/ArrayWrap.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -0,0 +1,31 @@
+/*
+ *  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 "GTLCore/wrappers/StructWrap.h"
+
+/**
+ * Internal mapping of a GTL array
+ * @ingroup GTLCore
+ * @internal
+ */
+struct ArrayWrap {
+  STRUCT_HEADER
+  int size;
+  void* data;
+};

Added: trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/wrappers/StructWrap.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -0,0 +1,29 @@
+/*
+ *  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 _STRUCT_WRAP_H_
+#define _STRUCT_WRAP_H_
+
+#define STRUCT_HEADER
+  // int count;
+
+#define STRUCT_FIRST_ELEMENT 0
+
+
+#endif

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-09-03 07:29:51 UTC (rev 354)
@@ -34,12 +34,14 @@
 #include "GTLCore/TypeManager.h"
 #include "GTLCore/Value.h"
 #include "GTLCore/VirtualMachine_p.h"
+#include "GTLCore/wrappers/Allocate.h"
 
 #include "Debug.h"
 #include "CodeGenerator_p.h"
 #include "Compiler_p.h"
 #include "Wrapper_p.h"
 #include "wrappers/ImageWrap_p.h"
+#include "wrappers/RegionWrap_p.h"
 
 using namespace OpenShiva;
 
@@ -189,7 +191,45 @@
   return d->moduleData->function( "MyKernel", "runTest");
 }
 
+GTLCore::Region Kernel::needed( GTLCore::Region output_region, int input_index, const std::list< GTLCore::Region>& input_DOD)
+{
+  return GTLCore::Region(0,0,0,0);
+}
 
+bool Kernel::hasNeededFunction() const
+{
+  return d->moduleData->function( "MyKernel", "needed");
+}
+
+GTLCore::Region Kernel::changed( GTLCore::Region changed_input_region, int input_index, const std::list< GTLCore::Region>& input_DOD)
+{
+  return GTLCore::Region(0,0,0,0);
+}
+
+bool Kernel::hasChangedFunction() const
+{
+  return d->moduleData->function( "MyKernel", "changed");
+}
+
+GTLCore::Region Kernel::generated()
+{
+ GTLCore::Function* f = d->moduleData->function( "MyKernel", "generated");
+ SHIVA_ASSERT( f );
+
+ RegionWrap* (*func)() = (RegionWrap* (*)())GTLCore::VirtualMachine::instance()->getPointerToFunction( f, 0 );
+ 
+ RegionWrap* rwrap = (*func)();
+ GTLCore::Region region = regionWrapToRegion( rwrap );
+ gtlFree( rwrap );
+ return region;
+}
+
+bool Kernel::hasGeneratedFunction() const
+{
+  return d->moduleData->function( "MyKernel", "generated");
+}
+
+
 GTLCore::String Kernel::compilationErrorsMessage() const
 {
   std::ostringstream os;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -86,6 +86,15 @@
        * @return true if the test function is available
        */
       bool hasTestFunction() const;
+      
+      GTLCore::Region needed( GTLCore::Region output_region, int input_index, const std::list< GTLCore::Region>& input_DOD);
+      bool hasNeededFunction() const;
+      GTLCore::Region changed( GTLCore::Region changed_input_region, int input_index, const std::list< GTLCore::Region>& input_DOD);
+      bool hasChangedFunction() const;
+      GTLCore::Region generated();
+      bool hasGeneratedFunction() const;
+      
+      
     private:
       struct Private;
       Private * const d;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -20,6 +20,8 @@
 #ifndef _IMAGE_WRAP_P_H_
 #define _IMAGE_WRAP_P_H_
 
+#include "GTLCore/wrappers/StructWrap.h"
+
 namespace GTLCore {
   class AbstractImage;
 }
@@ -30,13 +32,14 @@
 // Wrapper::createImageType !                          //
 //---------------------- WARNING ----------------------//
 struct ImageWrap {
+  STRUCT_HEADER
   GTLCore::AbstractImage* image;
   void* memToVec;
   void* vecToMem;
   enum ImageIndexes {
-    INDEX_IMAGE = 0,
-    INDEX_MEM_TO_VEC = 1,
-    INDEX_VEC_TO_MEM = 2
+    INDEX_IMAGE = STRUCT_FIRST_ELEMENT,
+    INDEX_MEM_TO_VEC = STRUCT_FIRST_ELEMENT + 1,
+    INDEX_VEC_TO_MEM = STRUCT_FIRST_ELEMENT + 2
   };
 };
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -20,17 +20,20 @@
 #ifndef _PIXEL_WRAP_P_H_
 #define _PIXEL_WRAP_P_H_
 
+#include "GTLCore/wrappers/StructWrap.h"
+
 //---------------------- WARNING ----------------------//
 // Whenever the following structure is edited,         //
 // it's llvm declaration must be changed too in        //
 // Wrapper::createPixelType !                          //
 //---------------------- WARNING ----------------------//
 struct PixelWrap {
+  STRUCT_HEADER
   void* data;
   void* coord;
   enum PixelIndexes {
-    INDEX_DATA = 0,
-    INDEX_COORD = 1
+    INDEX_DATA = STRUCT_FIRST_ELEMENT,
+    INDEX_COORD = STRUCT_FIRST_ELEMENT + 1
   };
 };
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/RegionWrap_p.h	2008-09-03 07:29:51 UTC (rev 354)
@@ -20,12 +20,19 @@
 #ifndef _REGION_WRAP_P_H_
 #define _REGION_WRAP_P_H_
 
+#include <list>
+
+#include "GTLCore/Region.h"
+#include "GTLCore/wrappers/Allocate.h"
+#include "GTLCore/wrappers/ArrayWrap.h"
+
 //---------------------- WARNING ----------------------//
 // Whenever the following structure is edited,         //
 // it's llvm declaration must be changed too in        //
 // Wrapper::createRegionType !                         //
 //---------------------- WARNING ----------------------//
 struct RegionWrap {
+  STRUCT_HEADER
   float x, y, width, height;
 };
 
@@ -42,4 +49,26 @@
   void region_wrap_inset( RegionWrap* self, float amount );
 }
 
+
+inline RegionWrap* regionToRegionWrap( const GTLCore::Region& region )
+{
+  RegionWrap* rw = gtlAllocate<RegionWrap>( );
+  rw->x = region.x();
+  rw->y = region.y();
+  rw->width = region.width();
+  rw->height = region.height();
+  return rw;
+}
+
+inline GTLCore::Region regionWrapToRegion( RegionWrap * rwrap)
+{
+ return GTLCore::Region( rwrap->x, rwrap->y, rwrap->width, rwrap->height );
+}
+
+inline ArrayWrap* regionListToArrayWrap( const std::list<GTLCore::Region> & regions)
+{
+  return 0;
+}
+
+
 #endif

Modified: trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex
===================================================================
--- trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex	2008-09-03 07:29:51 UTC (rev 354)
@@ -107,6 +107,37 @@
   }
 \end{verbatim}
 
+\subsection{changed}
+
+The \verb|changed| function indicates the Shiva interpreter which pixels in the
+output images need to be recomputed when a given region of the image has been
+changed. As a special note, the changed function is usually called at the first
+run to compute the region of the output image.
+
+\begin{verbatim}
+  region changed( region changed_input_region, int input_index, region
+input_DOD[])
+  {
+    ...
+  }
+\end{verbatim}
+
+\subsection{generated}
+
+The \verb|generated| function indicate the Shiva interpreter which pixels are
+changed when this generator is applied on the image. Even if images are
+expected to be of infinite size, some generators can have a more limited area
+of effect.
+
+\begin{verbatim}
+  region generated()
+  {
+    ...
+  }
+\end{verbatim}
+
+
+
 \subsection{runTest}
 This function is used for \verb|kernel| which are used for automatic testing of
 the language, and of the interpreter. It's a function that doesn't take any

Modified: trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva	2008-09-03 07:29:51 UTC (rev 354)
@@ -6,4 +6,9 @@
     result[1] = 0.0;
     result[2] = 0.0;
   }
+  region generated()
+  {
+    region reg1 = { 0, 0, 800, 600 };
+    return reg1;
+  }
 }

Modified: trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-09-02 19:48:45 UTC (rev 353)
+++ trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp	2008-09-03 07:29:51 UTC (rev 354)
@@ -150,7 +150,13 @@
       std::cerr << "Error: " << std::endl << p.compilationErrorsMessage() << std::endl;
       return EXIT_FAILURE;
     }
-    GTLCore::Image image(width, height, pixel );
+    
+    GTLCore::Region region(0,0,800,600);
+    if( p.hasGeneratedFunction() )
+    {
+      region = p.generated();
+    }
+    GTLCore::Image image( region.bottom() - 1, region.right() - 1, pixel );
     std::list<GTLCore::AbstractImage*> images;
     for( std::list< GTLCore::String >::iterator it = fileNames.begin();
          it != fileNames.end(); ++it )
@@ -168,7 +174,7 @@
       }
       images.push_back( image );
     }
-    p.evaluatePixeles( GTLCore::Region(0,0, width, height), images, &image );
+    p.evaluatePixeles( GTLCore::Region(region.x() , region.y(), region.width(), region.height()), images, &image );
     if( showAssembly )
     {
       std::cout << p.asmSourceCode();


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