2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy
4 * desc : Strategy decomposing matplot objects
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14 #include "MatplotDecomposer.hxx"
18 #include "GetProperty.h"
23 /*---------------------------------------------------------------------------------*/
24 MatplotDecomposer::MatplotDecomposer(DrawableGrayplot * grayplot)
25 : GrayplotDecompositionStrategy(grayplot)
29 /*---------------------------------------------------------------------------------*/
30 MatplotDecomposer::~MatplotDecomposer(void)
34 /*---------------------------------------------------------------------------------*/
35 int MatplotDecomposer::getNbRow(void)
37 return pGRAYPLOT_FEATURE(m_pDrawed->getDrawedObject())->nx;
39 /*---------------------------------------------------------------------------------*/
40 int MatplotDecomposer::getNbCol(void)
42 return pGRAYPLOT_FEATURE(m_pDrawed->getDrawedObject())->ny;
44 /*---------------------------------------------------------------------------------*/
45 int MatplotDecomposer::getNbColors(void)
47 // we draw insie the grid
48 return (getNbRow() - 1) * (getNbCol() - 1);
50 /*---------------------------------------------------------------------------------*/
51 double MatplotDecomposer::getZCoordinate(void)
55 /*---------------------------------------------------------------------------------*/
56 void MatplotDecomposer::decomposeGrayplot(double xGrid[], double yGrid[], int colors[])
58 sciPointObj * pGray = m_pDrawed->getDrawedObject();
59 sciGrayplot * ppGray = pGRAYPLOT_FEATURE(pGray);
60 int nbRow = getNbRow();
61 int nbCol = getNbCol();
63 if (ppGray->type == 1)
65 decomposeMatplot(xGrid, yGrid);
69 decomposeMatplot1(xGrid, yGrid);
73 for (int i = 0; i < nbCol - 1; i++)
75 for (int j = 0; j < nbRow - 1; j++)
77 // scilab data are stored column wise
78 colors[j + (nbRow - 1) * i] = (int) ppGray->pvecz[j + (nbRow - 1) * i];
82 // apply log scale if needed
83 m_pDrawed->pointScale(xGrid, NULL, NULL, nbRow);
84 m_pDrawed->pointScale(NULL, yGrid, NULL, nbCol);
87 /*---------------------------------------------------------------------------------*/
88 void MatplotDecomposer::decomposeMatplot(double xGrid[], double yGrid[])
90 int nbRow = getNbRow();
91 int nbCol = getNbCol();
93 // the center of each facet is on (i,j) where i and j are integer
94 // so facet (i,j) vertices are (i-0.5,j-0.5), (i+0.5,j-0.5),
95 // (i+0.5,j+0.5), (i-0.5,j+0.5)
98 for (int i = 0; i < nbCol; i++)
100 // we start at i = 0, but matrix indices at 1
105 // top of the matrix starts on Y max
106 for (int j = 0; j < nbRow; j++)
108 // so the result is j - 0.5 + 1
109 yGrid[j] = nbRow - j - 0.5;
112 /*---------------------------------------------------------------------------------*/
113 void MatplotDecomposer::decomposeMatplot1(double xGrid[], double yGrid[])
115 int nbRow = getNbRow();
116 int nbCol = getNbCol();
118 sciPointObj * pGray = m_pDrawed->getDrawedObject();
119 sciGrayplot * ppGray = pGRAYPLOT_FEATURE(pGray);
122 double xMin = ppGray->pvecx[0];
123 double xMax = ppGray->pvecx[2];
124 double yMin = ppGray->pvecx[1];
125 double yMax = ppGray->pvecx[3];
127 // the matplot should fit in [xMin,xMax]x[yMin,yMax]
130 for (int i = 0; i < nbCol; i++)
132 xGrid[i] = xMin + i * (xMax - xMin) / (nbCol - 1);
135 // top of the matrix starts on Y max
136 for (int j = 0; j < nbRow; j++)
138 yGrid[j] = yMax - j * (yMax - yMin) / (nbRow - 1);
141 /*---------------------------------------------------------------------------------*/