Exemplo n.º 1
0
AssignedList * createTlistForTicks(void* _pvCtx)
{
    AssignedList* tlist = NULL;
    int nbRowLoc  = 0;
    int nbColLoc  = 0;
    int nbRowLab  = 0;
    int nbColLab  = 0;

    tlist = createAssignedList(_pvCtx, 3, 2);

    if (tlist == NULL)
    {
        Scierror(999, _("Tlist could not be created, check ticks location and label vectors.\n"));
        return NULL;
    }

    if (!isListCurrentElementDoubleMatrix(_pvCtx, tlist))
    {
        Scierror(999, _("%s should be a vector of double.\n"), "locations");
        return NULL;
    }

    getCurrentDoubleMatrixFromList(_pvCtx, tlist, &nbRowLoc, &nbColLoc);

    if (nbRowLoc * nbColLoc == 0)
    {
        /* labels should also be an empty matrix */
        if (!isListCurrentElementEmptyMatrix(_pvCtx, tlist))
        {
            Scierror(999, _("Ticks location and label vectors must have the same size.\n"));
            return NULL;
        }
    }
    else
    {
        if (!isListCurrentElementStringMatrix(_pvCtx, tlist))
        {
            Scierror(999, _("%s should be a string vector.\n"), "labels");
            return NULL;
        }

        getCurrentStringMatrixFromList(_pvCtx, tlist, &nbRowLab, &nbColLab);

        if (nbRowLoc != nbRowLab || nbColLoc != nbColLab)
        {
            Scierror(999, _("Ticks location and label vectors must have the same size.\n"));
            return NULL;
        }
    }

    rewindAssignedList(tlist);

    return tlist;

}
Exemplo n.º 2
0
/* set3ddata(pobj,cstk(l2), &l3, &numrow3, &numcol3) */
int set3ddata( char* pobjUID, AssignedList * tlist )
{
    char* type;

    int m1, n1, m2, n2, m3, n3;
    int m3n, n3n;
    int isFac3d;

    double * pvecx = NULL;
    double * pvecy = NULL;
    double * pvecz = NULL;
    int dimvectx = 0;
    int dimvecty = 0;

    double* inputColors;
    int nbInputColors;

    // number of specified colors
    int nc = 0;

    int izcol;

    /* no copy now we just perform tests on the matrices */
    pvecx = getCurrentDoubleMatrixFromList( tlist, &m1, &n1 );
    pvecy = getCurrentDoubleMatrixFromList( tlist, &m2, &n2 );
    pvecz = getCurrentDoubleMatrixFromList( tlist, &m3, &n3 );

    if ( m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1 )
    {
        if ( !(m1 == m2 && m2 == m3 && n1 == n2 && n2 == n3) )
        {
            Scierror(999, _("%s: Wrong size for arguments #%d, #%d and #%d: Incompatible length.\n"),"Tlist",1,2,3);
            return SET_PROPERTY_ERROR;
        }
    }
    else
    {
        if ( m2 * n2 != n3 )
        {
            Scierror(999, _("%s: Wrong size for arguments #%d and #%d: Incompatible length.\n"),"Tlist",2,3);
            return SET_PROPERTY_ERROR;
        }
        if ( m1 * n1 != m3 )
        {
            Scierror(999, _("%s: Wrong size for arguments #%d and #%d: Incompatible length.\n"),"Tlist",1,3);
            return SET_PROPERTY_ERROR;
        }
        if ( m1 * n1 <= 1 || m2 * n2 <= 1 )
        {
            Scierror(999, _("%s: Wrong size for arguments #%d and #%d: Should be >= %d.\n"),"Tlist",1,2,2);
            return SET_PROPERTY_ERROR;
        }
    }

    if ( m1 * n1 == 0 || m2 * n2 == 0 || m3 * n3 == 0 )
    {
        return sciReturnEmptyMatrix();
    }

    /* get color size if exists */
    if ( getAssignedListNbElement( tlist ) == 4 )
    {
        getCurrentDoubleMatrixFromList( tlist, &m3n, &n3n ) ;
        if ( m3n * n3n == m3 * n3 )
        {
            /* the color is a matrix, with same size as Z */
            izcol = 2;
        }
        else if (m3n * n3n == n3 && (m3n == 1 || n3n == 1))
        {
            /* a vector with as many colors as facets */
            izcol = 1;
        }
        else
        {
            Scierror(999, _("Wrong size for %s element: A %d-by-%d matrix or a vector of size %d expected.\n"), "color", m3, n3, n3);
            return SET_PROPERTY_ERROR;
        }
    }
    else
    {
        m3n = 0;
        n3n = 0;
        izcol = 0;
    }

    getGraphicObjectProperty(pobjUID, __GO_TYPE__, jni_string, &type);

    if (strcmp(type, __GO_FAC3D__) == 0)
    {
        isFac3d = 1;
    }
    else
    {
        isFac3d = 0;
    }

    if ( m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1 ) /* NG beg */
    {
        /* case isfac=1;*/
        if (isFac3d == 0)
        {
            Scierror(999, _("Can not change the %s of graphic object: its type is %s.\n"),"typeof3d","SCI_PLOT3D");
            return SET_PROPERTY_ERROR;
        }
    }
    else
    {
        /* case isfac=0;*/
        if (isFac3d == 1)
        {
            Scierror(999, _("Can not change the %s of graphic object: its type is %s.\n"),"typeof3d","SCI_FAC3D");
            return SET_PROPERTY_ERROR;
        }
    }

    /* check the monotony on x and y */

    if (isFac3d == 1)
    {
        /* x is considered as a matrix */
        dimvectx = -1;
    }
    else if ( m1 == 1 ) /* x is a row vector */
    {
        dimvectx = n1;
    }
    else if ( n1 == 1 ) /* x is a column vector */
    {
        dimvectx = m1;
    }
    else /* x is a matrix */
    {
        dimvectx = -1;
    }

    if ( dimvectx > 1 )
    {
        int monotony = checkMonotony( pvecx, dimvectx );
        if ( monotony == 0 )
        {
            Scierror(999, _("%s: Wrong value: Vector is not monotonous.\n"),"Objplot3d");
            return SET_PROPERTY_ERROR;
        }

        /* To be implemented within the MVC */
#if 0
        psurf->flag_x = monotony;
#endif
    }

    if (isFac3d == 1)
    {
        /* x is considered as a matrix */
        dimvecty = -1;
    }
    else if(m2 == 1) /* y is a row vector */
    {
        dimvecty = n2;
    }
    else if(n2 == 1) /* y is a column vector */
    {
        dimvecty = m2;
    }
    else /* y is a matrix */
    {
        dimvecty = -1;
    }

    if( dimvecty > 1 )
    {
        int monotony = checkMonotony( pvecy, dimvecty );
        if ( monotony == 0 )
        {
            Scierror(999, _("%s: Wrong value: Vector is not monotonous.\n"),"Objplot3d");
            return SET_PROPERTY_ERROR;
        }

        /* To be implemented within the MVC */
#if 0
        psurf->flag_y = monotony;
#endif
    }

    /* get the values now */
    rewindAssignedList( tlist );

    pvecx = getCurrentDoubleMatrixFromList( tlist, &m1, &n1 );
    pvecy = getCurrentDoubleMatrixFromList( tlist, &m2, &n2 );
    pvecz = getCurrentDoubleMatrixFromList( tlist, &m3, &n3 );

    if (isFac3d == 1)
    {
        int numElementsArray[3];
        int result;

        numElementsArray[0] = n1;
        numElementsArray[1] = m1;
        numElementsArray[2] = m3n * n3n;

        result = setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__, numElementsArray, jni_int_vector, 3);

        if (result == 0)
        {
            Scierror(999, _("%s: No more memory.\n"), "set3ddata");
            return SET_PROPERTY_ERROR;
        }
    }
    else if (isFac3d == 0)
    {
        int gridSize[4];
        int result;

        gridSize[0] = m1;
        gridSize[1] = n1;
        gridSize[2] = m2;
        gridSize[3] = n2;

        result = setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_GRID_SIZE__, gridSize, jni_int_vector, 4);

        if (result == 0)
        {
            Scierror(999, _("%s: No more memory.\n"), "set3ddata");
            return SET_PROPERTY_ERROR;
        }
    }

    setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, pvecx, jni_double_vector, m1*n1);
    setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, pvecy, jni_double_vector, m2*n2);
    setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, pvecz, jni_double_vector, m3*n3);

    if( getAssignedListNbElement( tlist ) == 4 ) /* F.Leray There is a color matrix */
    {
        inputColors = getCurrentDoubleMatrixFromList( tlist, &m3n, &n3n );
        nbInputColors = m3n * n3n;
    }
    else
    {
        inputColors = NULL;
        nbInputColors = 0;
    }

    /*
     * Plot 3d case not treated for now
     * To be implemented
     */
    if (isFac3d == 1)
    {
        setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_COLORS__, inputColors, jni_double_vector, nbInputColors);
    }

    /* Color vector/matrix dimensions: to be checked for MVC implementation */
#if 0
    psurf->m3n = m3n; /* If m3n and n3n are 0, then it means that no color matrix/vector was in input*/
    psurf->n3n = n3n;
#endif

    return SET_PROPERTY_SUCCEED;
}