1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : Plot2d_NormalizeAlgorithm.cxx
24 #include "Plot2d_NormalizeAlgorithm.h"
27 #include "Plot2d_Object.h"
32 Plot2d_NormalizeAlgorithm::Plot2d_NormalizeAlgorithm(QObject *parent) :
33 Plot2d_Algorithm(parent),
34 myNormalizationMode(NormalizeNone)
41 Plot2d_NormalizeAlgorithm::~Plot2d_NormalizeAlgorithm()
46 Sets normalozation mode
48 void Plot2d_NormalizeAlgorithm::setNormalizationMode(NormalizationMode theMode) {
49 if(myNormalizationMode != theMode) {
50 myNormalizationMode = theMode;
56 Gets normalozation mode
58 Plot2d_NormalizeAlgorithm::NormalizationMode Plot2d_NormalizeAlgorithm::getNormalizationMode()const {
59 return myNormalizationMode;
63 Gets k normalization coefficient
65 double Plot2d_NormalizeAlgorithm::getKkoef(Plot2d_Object* theObj)
67 QMap<Plot2d_Object*,double>::iterator it = myKkoefs.find(theObj);
68 if(it != myKkoefs.end())
74 Gets b normalization coefficient
76 double Plot2d_NormalizeAlgorithm::getBkoef(Plot2d_Object* theObj)
78 QMap<Plot2d_Object*,double>::iterator it = myBkoefs.find(theObj);
79 if(it != myBkoefs.end())
85 void Plot2d_NormalizeAlgorithm::execute() {
86 if (!isDataChanged() || myInuptData.isEmpty())
89 if (myNormalizationMode != NormalizeNone) {
90 QList<double> yMinLst, yMaxLst;
91 QList<double> aKkoefs,aBkoefs;
93 for (int i = 0; i < myInuptData.size(); ++i) {
94 QList<double> aTmpItemValues;
95 Plot2d_Object* object = myInuptData.at(i);
97 long nb = object->getData( &x, &y );
98 for (int j = 0; j < nb; ++j) {
99 aTmpItemValues<<object->getPoint(j).y;
103 yMaxLst<<*(std::max_element(aTmpItemValues.begin(), aTmpItemValues.end()));
104 yMinLst<<*(std::min_element(aTmpItemValues.begin(), aTmpItemValues.end()));
106 _pMin = *(std::min_element(yMinLst.begin(), yMinLst.end()));
107 _pMax = *(std::max_element(yMaxLst.begin(), yMaxLst.end()));
109 double pMin, pMax, kKoef, bKoef, yMin, yMax;
110 switch( getNormalizationMode() ) {
113 for (int i = 0; i < yMaxLst.size(); ++i) {
114 yMin = yMinLst.at(i);
115 yMax = yMaxLst.at(i);
117 kKoef = (pMax - pMin)/(yMax - yMin);
118 bKoef = pMin - kKoef * yMin;
125 for (int i = 0; i < yMaxLst.size(); ++i) {
126 yMin = yMinLst.at(i);
127 yMax = yMaxLst.at(i);
129 kKoef = (pMax - pMin)/(yMax - yMin);
130 bKoef = pMin - kKoef * yMin;
135 case NormalizeToMinMax:
138 for (int i = 0; i < yMaxLst.size(); ++i) {
139 yMin = yMinLst.at(i);
140 yMax = yMaxLst.at(i);
141 kKoef = (pMax - pMin)/(yMax - yMin);
142 bKoef = pMin - kKoef * yMin;
149 for (int i = 0; i < myInuptData.size(); ++i) {
150 double yOld,xOld,yNew;
151 AlgoPlot2dItem tmpItem;
152 for (int j = 0; j < myInuptData.at(i)->nbPoints(); ++j) {
153 yOld = myInuptData.at(i)->getPoint(j).y;
154 xOld = myInuptData.at(i)->getPoint(j).x;
155 yNew = aKkoefs.at(i) * yOld + aBkoefs.at(i);
156 tmpItem.append( qMakePair(xOld, yNew) );
158 myResultData.insert(myInuptData.at(i),tmpItem);
159 myKkoefs.insert(myInuptData.at(i),aKkoefs.at(i));
160 myBkoefs.insert(myInuptData.at(i),aBkoefs.at(i));
163 for (int i = 0; i < myInuptData.size(); ++i) {
165 AlgoPlot2dItem tmpItem;
166 for (int j = 0; j < myInuptData.at(i)->nbPoints(); ++j) {
167 yOld = myInuptData.at(i)->getPoint(j).y;
168 xOld = myInuptData.at(i)->getPoint(j).x;
169 tmpItem.append( qMakePair(xOld, yOld) );
171 myResultData.insert(myInuptData.at(i),tmpItem);
174 myDataChanged = false;
178 void Plot2d_NormalizeAlgorithm::clear() {
179 Plot2d_Algorithm::clear();