N-gon grid matplot class added to the C++ data model. 23/2923/2
Manuel Juliachs [Fri, 14 Jan 2011 09:43:46 +0000 (10:43 +0100)]
Change-Id: I65a84079ca4e9fc2c73ac80bf59c6ca3b6cc636e

12 files changed:
scilab/modules/graphic_objects/Makefile.am
scilab/modules/graphic_objects/Makefile.in
scilab/modules/graphic_objects/includes/DataModel.hxx
scilab/modules/graphic_objects/includes/DataProperties.hxx
scilab/modules/graphic_objects/includes/NgonGridData.hxx
scilab/modules/graphic_objects/includes/NgonGridMatplotData.hxx [new file with mode: 0644]
scilab/modules/graphic_objects/includes/graphicObjectProperties.h
scilab/modules/graphic_objects/src/c/graphic_objects.vcproj
scilab/modules/graphic_objects/src/cpp/NgonGridMatplotData.cpp [new file with mode: 0644]
scilab/modules/graphic_objects/src/cpp/dataModel.cpp
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicObject/GraphicObjectProperties.java
scilab/modules/graphic_objects/src/scripts/propertiesMap.properties

index 422bad4..ba7fd87 100644 (file)
@@ -43,6 +43,7 @@ GRAPHIC_OBJECTS_CPP_SOURCES =         src/cpp/createGraphicObject.cpp \
                                                                src/cpp/NgonData.cpp \
                                                                src/cpp/NgonGeneralData.cpp \
                                                                src/cpp/NgonGridData.cpp \
+                                                               src/cpp/NgonGridMatplotData.cpp \
                                                                src/cpp/NgonPolylineData.cpp \
                                                                src/cpp/TriangleMeshData.cpp \
                                                                src/cpp/TriangleMeshFecData.cpp
index 813e107..dcff7f3 100644 (file)
@@ -146,6 +146,7 @@ am__objects_6 = libscigraphic_objects_la-createGraphicObject.lo \
        libscigraphic_objects_la-NgonData.lo \
        libscigraphic_objects_la-NgonGeneralData.lo \
        libscigraphic_objects_la-NgonGridData.lo \
+       libscigraphic_objects_la-NgonGridMatplotData.lo \
        libscigraphic_objects_la-NgonPolylineData.lo \
        libscigraphic_objects_la-TriangleMeshData.lo \
        libscigraphic_objects_la-TriangleMeshFecData.lo
@@ -531,6 +532,7 @@ GRAPHIC_OBJECTS_CPP_SOURCES = src/cpp/createGraphicObject.cpp \
                                                                src/cpp/NgonData.cpp \
                                                                src/cpp/NgonGeneralData.cpp \
                                                                src/cpp/NgonGridData.cpp \
+                                                               src/cpp/NgonGridMatplotData.cpp \
                                                                src/cpp/NgonPolylineData.cpp \
                                                                src/cpp/TriangleMeshData.cpp \
                                                                src/cpp/TriangleMeshFecData.cpp
@@ -667,6 +669,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-NgonData.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-NgonGeneralData.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-NgonGridData.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-NgonGridMatplotData.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-NgonPolylineData.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-TriangleMeshData.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscigraphic_objects_la-TriangleMeshFecData.Plo@am__quote@
@@ -825,6 +828,13 @@ libscigraphic_objects_la-NgonGridData.lo: src/cpp/NgonGridData.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigraphic_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscigraphic_objects_la-NgonGridData.lo `test -f 'src/cpp/NgonGridData.cpp' || echo '$(srcdir)/'`src/cpp/NgonGridData.cpp
 
+libscigraphic_objects_la-NgonGridMatplotData.lo: src/cpp/NgonGridMatplotData.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigraphic_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscigraphic_objects_la-NgonGridMatplotData.lo -MD -MP -MF $(DEPDIR)/libscigraphic_objects_la-NgonGridMatplotData.Tpo -c -o libscigraphic_objects_la-NgonGridMatplotData.lo `test -f 'src/cpp/NgonGridMatplotData.cpp' || echo '$(srcdir)/'`src/cpp/NgonGridMatplotData.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscigraphic_objects_la-NgonGridMatplotData.Tpo $(DEPDIR)/libscigraphic_objects_la-NgonGridMatplotData.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/NgonGridMatplotData.cpp' object='libscigraphic_objects_la-NgonGridMatplotData.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigraphic_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscigraphic_objects_la-NgonGridMatplotData.lo `test -f 'src/cpp/NgonGridMatplotData.cpp' || echo '$(srcdir)/'`src/cpp/NgonGridMatplotData.cpp
+
 libscigraphic_objects_la-NgonPolylineData.lo: src/cpp/NgonPolylineData.cpp
 @am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscigraphic_objects_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscigraphic_objects_la-NgonPolylineData.lo -MD -MP -MF $(DEPDIR)/libscigraphic_objects_la-NgonPolylineData.Tpo -c -o libscigraphic_objects_la-NgonPolylineData.lo `test -f 'src/cpp/NgonPolylineData.cpp' || echo '$(srcdir)/'`src/cpp/NgonPolylineData.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscigraphic_objects_la-NgonPolylineData.Tpo $(DEPDIR)/libscigraphic_objects_la-NgonPolylineData.Plo
index 759c699..e7308fc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NgonGeneralData.hxx"
 #include "NgonGridData.hxx"
+#include "NgonGridMatplotData.hxx"
 #include "NgonPolylineData.hxx"
 #include "TriangleMeshData.hxx"
 #include "TriangleMeshFecData.hxx"
index ebad095..52f6353 100644 (file)
@@ -56,4 +56,6 @@
 #define COLORS                  27
 #define NUM_COLORS              28
 
+#define MATPLOT_BOUNDS          30
+
 #endif
index e02f4d3..431babe 100644 (file)
@@ -27,7 +27,7 @@ extern "C" {
 
 class NgonGridData : public NgonData
 {
-private :
+protected :
 
     /** The x coordinates array */
     double* xCoordinates;
diff --git a/scilab/modules/graphic_objects/includes/NgonGridMatplotData.hxx b/scilab/modules/graphic_objects/includes/NgonGridMatplotData.hxx
new file mode 100644 (file)
index 0000000..4e327db
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2011 - DIGITEO - Manuel Juliachs
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef NGON_GRID_MATPLOT_DATA_H
+#define NGON_GRID_MATPLOT_DATA_H
+
+#include <string>
+
+#include "NgonGridData.hxx"
+
+extern "C" {
+#include "BOOL.h"
+}
+
+/**
+ * N-gons grid Matplot data class
+ * The xDimensions and yDimensions properties inherited from NgonGridData have no
+ * useful purpose, as the x and y coordinates arrays are not currently visible to
+ * the user.
+ * To be done: refactoring
+ */
+
+class NgonGridMatplotData : public NgonGridData
+{
+private :
+
+    /** The 2D bounding rectangle {xmin, xmax, ymin, ymax} */
+    double boundingRectangle[4];
+
+    /**
+     * Matplot type
+     * Specifies whether x and y coordinates are computed directly from element indices (0)
+     * or computed using the 2D bounding rectangle (1)
+     */
+    int type;
+
+protected :
+
+    /**
+     * Computes the x and y coordinates depending on the type member
+     * If type is equal to 0, x and y coordinates are directly computed from matrix indices
+     * and the rectangle bounds are updated
+     * else, if equal to 1, the coordinates are computed by interpolating between the bounding
+     * rectangle's min and max vertices
+     */
+    void computeCoordinates(void);
+
+public :
+
+    /**
+     * Constructor
+     */
+    NgonGridMatplotData(void);
+
+    /**
+     * Destructor
+     */
+    ~NgonGridMatplotData(void);
+
+    /**
+     * Returns the value corresponding to a property name
+     * @param propertyName the property name
+     * @return the property value
+     */
+    int getPropertyFromName(char* propertyName);
+
+    /**
+     * Sets a data property
+     * @param property the property value
+     * @param value pointer to the property
+     * @param numElements the number of elements to set
+     * @return 1 if the property has been successfully set, 0 otherwise
+     */
+    int setDataProperty(int property, void* value, int numElements);
+
+    /**
+     * Returns a data property
+     * @param property the property value
+     * @return a pointer to the property
+     */
+    void* getDataProperty(int property);
+
+    /**
+     * Sets the grid'x and y vectors dimensions
+     * Resizes the x, y, and z data coordinates arrays if required
+     * and must therefore be called prior to any setData call
+     * Similar to NgonGridData's setGridSize method, the main difference being how the z data array's size
+     * is computed.
+     * To be done: refactoring
+     * @param gridSize 4-element array: x vector (nb rows, nb cols) and y vector (nb rows, nb cols) dimensions
+     * @return 1 if the property has been successfully set, 0 otherwise (failed allocation)
+     */
+    int setGridSize(int* gridSize);
+
+    /**
+     * Sets the 2D bounding rectangle's coordinates
+     * Also sets the internal property type according to the value of its argument
+     * To be done: use the same coordinate ordering as the internal array
+     * @param bounds 4-element array: {xmin, ymin, xmax, ymax}. If bounds is NULL, type is set to 0, else, it is set to 1
+     */
+    void setBounds(double* bounds);
+
+    /**
+     * Returns the 2D bounding rectangle's coordinates
+     * @return a pointer to the bounding rectangle coordinates array {xmin, xmax, ymin, ymax}
+     */
+    double* getBounds(void);
+
+
+    /**
+     * Sets the grid's z data
+     * This method is almost identical to NgonGridData's own setDataZ method
+     * the only difference being how the maximum number of elements is computed
+     * To be done: refactoring
+     * @param data the data (numElements values)
+     * @param numElements the number of elements to set
+     */
+    void setDataZ(double* data, int numElements);
+};
+
+#endif
index 9ca2df1..41a965e 100644 (file)
@@ -85,6 +85,8 @@
 #define __GO_DATA_MODEL_X_DIMENSIONS__                 "DataModelXDimensions"
 #define __GO_DATA_MODEL_Y_DIMENSIONS__                 "DataModelYDimensions"
 
+#define __GO_DATA_MODEL_MATPLOT_BOUNDS__               "DataModelMatplotBounds"
+
 #define __GO_REFERENCED__                  "Referenced"
 #define __GO_VALID__                       "Valid"
 
index 94d3932..7670d71 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath="..\cpp\NgonGridMatplotData.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\cpp\NgonPolylineData.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\..\includes\NgonGridMatplotData.hxx"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\includes\NgonPolylineData.hxx"
                                >
                        </File>
diff --git a/scilab/modules/graphic_objects/src/cpp/NgonGridMatplotData.cpp b/scilab/modules/graphic_objects/src/cpp/NgonGridMatplotData.cpp
new file mode 100644 (file)
index 0000000..eb57444
--- /dev/null
@@ -0,0 +1,355 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2011 - DIGITEO - Manuel Juliachs
+ *
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "NgonGridMatplotData.hxx"
+
+extern "C" {
+    #include <string.h>
+    #include <stdlib.h>
+
+    #include "graphicObjectProperties.h"
+}
+
+NgonGridMatplotData::NgonGridMatplotData(void)
+{
+
+}
+
+NgonGridMatplotData::~NgonGridMatplotData(void)
+{
+
+}
+
+int NgonGridMatplotData::getPropertyFromName(char* propertyName)
+{
+    if (strcmp(propertyName, __GO_DATA_MODEL_GRID_SIZE__) == 0)
+    {
+        return GRID_SIZE;
+    }
+    else if (strcmp(propertyName, __GO_DATA_MODEL_MATPLOT_BOUNDS__) == 0)
+    {
+        return MATPLOT_BOUNDS;
+    }
+    else if (strcmp(propertyName, __GO_DATA_MODEL_Z__) == 0)
+    {
+        return Z_COORDINATES;
+    }
+    else
+    {
+        return NgonGridData::getPropertyFromName(propertyName);
+    }
+
+}
+
+int NgonGridMatplotData::setDataProperty(int property, void* value, int numElements)
+{
+    if (property == GRID_SIZE)
+    {
+        return setGridSize((int*) value);
+    }
+    else if (property == MATPLOT_BOUNDS)
+    {
+        setBounds((double*) value);
+    }
+    else if (property == Z_COORDINATES)
+    {
+        setDataZ((double*) value, numElements);
+    }
+    else
+    {
+        return NgonGridData::setDataProperty(property, value, numElements);
+    }
+
+    return 1;
+}
+
+void* NgonGridMatplotData::getDataProperty(int property)
+{
+    /* Used for now to return the address of a single integer */
+    static int localIntResult;
+
+    if (property == MATPLOT_BOUNDS)
+    {
+        return getBounds();
+    }
+    else if (property == Z_COORDINATES)
+    {
+        return getDataZ();
+    }
+    else
+    {
+        return NgonGridData::getDataProperty(property);
+    }
+}
+
+/*
+ * To be done: refactoring with NgonGridData, as these two classes'
+ * setGridSize methods are almost identical.
+ */
+int NgonGridMatplotData::setGridSize(int* gridSize)
+{
+    int newXSize;
+    int newYSize;
+    int xModified;
+    int yModified;
+    int zModified;
+    int result;
+    int formerGridSize;
+
+    double* newXCoordinates = NULL;
+    double* newYCoordinates = NULL;
+    double* newZCoordinates = NULL;
+
+    result = 1;
+
+    xModified = 0;
+    yModified = 0;
+    zModified = 0;
+
+    if ((gridSize[0] != 1) && (gridSize[1] != 1))
+    {
+        return 0;
+    }
+
+    if ((gridSize[2] != 1) && (gridSize[3] != 1))
+    {
+        return 0;
+    }
+
+    newXSize = gridSize[0]*gridSize[1];
+    newYSize = gridSize[2]*gridSize[3];
+
+    if (newXSize != xSize)
+    {
+        xModified = 1;
+
+        try
+        {
+            newXCoordinates = new double[newXSize];
+        }
+        catch (const std::exception& e)
+        {
+            result = 0;
+        }
+    }
+
+    if (newYSize != ySize)
+    {
+        yModified = 1;
+
+        try
+        {
+            newYCoordinates = new double[newYSize];
+        }
+        catch (const std::exception& e)
+        {
+            result = 0;
+        }
+    }
+
+    if (xSize > 0 && ySize > 0)
+    {
+        formerGridSize = (xSize-1)*(ySize-1);
+    }
+    else
+    {
+        formerGridSize = 0;
+    }
+
+    if ((newXSize-1)*(newYSize-1) != formerGridSize)
+    {
+        zModified = 1;
+
+        try
+        {
+            newZCoordinates = new double[(newXSize-1)*(newYSize-1)];
+        }
+        catch (const std::exception& e)
+        {
+            result = 0;
+        }
+    }
+
+    if (result)
+    {
+        if (xModified)
+        {
+            if (xSize > 0)
+            {
+                delete [] xCoordinates;
+            }
+
+            xCoordinates = newXCoordinates;
+            xSize = newXSize;
+        }
+
+        xDimensions[0] = gridSize[0];
+        xDimensions[1] = gridSize[1];
+
+        if (yModified)
+        {
+            if (ySize > 0)
+            {
+                delete [] yCoordinates;
+            }
+
+            yCoordinates = newYCoordinates;
+            ySize = newYSize;
+        }
+
+        yDimensions[0] = gridSize[2];
+        yDimensions[1] = gridSize[3];
+
+        if (zModified)
+        {
+            if (formerGridSize > 0)
+            {
+                delete [] zCoordinates;
+            }
+
+            zCoordinates = newZCoordinates;
+
+            numGons = (xSize-1)*(ySize-1);
+
+        }
+
+        if (xModified || yModified)
+        {
+            computeCoordinates();
+        }
+
+    }
+    else
+    {
+        /* Failed allocation(s) */
+
+        if (xModified && (newXCoordinates != NULL))
+        {
+            delete [] newXCoordinates;
+        }
+
+        if (yModified && (newYCoordinates != NULL))
+        {
+            delete [] newYCoordinates;
+        }
+
+        if (zModified && (newZCoordinates != NULL))
+        {
+            delete [] newZCoordinates;
+        }
+
+    }
+
+    return result;
+}
+
+void NgonGridMatplotData::setBounds(double* bounds)
+{
+    if (bounds == NULL)
+    {
+        /* Type 0 object: bounds are computed from element indices by the setGridSize method */
+        type = 0;
+    }
+    else
+    {
+        /* To be done: test whether max > min */
+        boundingRectangle[0] = bounds[0];
+        boundingRectangle[1] = bounds[2];
+        boundingRectangle[2] = bounds[1];
+        boundingRectangle[3] = bounds[3];
+
+        type = 1;
+    }
+}
+
+double* NgonGridMatplotData::getBounds(void)
+{
+    return boundingRectangle;
+}
+
+void NgonGridMatplotData::computeCoordinates(void)
+{
+    int i;
+
+    if (type == 0)
+    {
+        for (i = 0; i < xSize; i++)
+        {
+            xCoordinates[i] = 0.5 + (double) i;
+        }
+
+        for (i = 0; i < ySize; i++)
+        {
+            yCoordinates[i] = 0.5 + (double) i;
+        }
+
+        boundingRectangle[0] = 0.5;
+        boundingRectangle[1] = 0.5 + (double) (xSize-1);
+        boundingRectangle[2] = 0.5;
+        boundingRectangle[3] = 0.5 + (double) (ySize-1);
+    }
+    else
+    {
+        double min;
+        double max;
+        int numElements;
+
+        min = boundingRectangle[0];
+        max = boundingRectangle[1];
+
+        if (xSize == 1)
+        {
+            numElements = 1;
+        }
+        else
+        {
+            numElements = xSize - 1;
+        }
+
+        for (i = 0; i < xSize; i++)
+        {
+            xCoordinates[i] = min + (double) i * (max - min) / (double) numElements;
+        }
+
+        min = boundingRectangle[2];
+        max = boundingRectangle[3];
+
+        if (ySize == 1)
+        {
+            numElements = 1;
+        }
+        else
+        {
+            numElements = ySize - 1;
+        }
+
+        for (i = 0; i < ySize; i++)
+        {
+            yCoordinates[i] = min + (double) i * (max - min) / (double) numElements;
+        }
+
+    }
+
+}
+
+void NgonGridMatplotData::setDataZ(double* data, int numElements)
+{
+    if (numElements > (xSize-1)*(ySize-1))
+    {
+        return;
+    }
+
+    for (int i = 0; i < numElements; i++)
+    {
+        zCoordinates[i] = data[i];
+    }
+}
index c09d111..8d80aa3 100644 (file)
@@ -75,7 +75,7 @@ char* DataModel::createDataObject(char* _pstID, char* _sType)
     }
     else if (strcmp(_sType, __GO_MATPLOT__) == 0)
     {
-       newObject = new NgonGridData();
+        newObject = new NgonGridMatplotData();
     }
     else if (strcmp(_sType, __GO_FAC3D__) == 0)
     {
index 8a2052e..751f001 100644 (file)
@@ -86,6 +86,8 @@ public static final String __GO_DATA_MODEL_GRID_SIZE__ =               "DataMode
 public static final String __GO_DATA_MODEL_X_DIMENSIONS__ =            "DataModelXDimensions";
 public static final String __GO_DATA_MODEL_Y_DIMENSIONS__ =            "DataModelYDimensions";
 
+public static final String __GO_DATA_MODEL_MATPLOT_BOUNDS__ =          "DataModelMatplotBounds";
+
 public static final String __GO_REFERENCED__ =             "Referenced";
 public static final String __GO_VALID__ =                  "Valid";
 
index 9963ad0..920e047 100644 (file)
@@ -64,6 +64,8 @@
 @DECLARE@ __GO_DATA_MODEL_X_DIMENSIONS__ @EQUAL@            "DataModelXDimensions" @END@
 @DECLARE@ __GO_DATA_MODEL_Y_DIMENSIONS__ @EQUAL@            "DataModelYDimensions" @END@
 
+@DECLARE@ __GO_DATA_MODEL_MATPLOT_BOUNDS__ @EQUAL@          "DataModelMatplotBounds" @END@
+
 @DECLARE@ __GO_REFERENCED__ @EQUAL@             "Referenced" @END@
 @DECLARE@ __GO_VALID__ @EQUAL@                  "Valid" @END@