return false;\r
}\r
\r
-static std::map<int, std::vector<int> > myColorMap;\r
-\r
-void appendValues(std::vector<int>& theRGB, const int theRed, const int theGreen, const int theBlue)\r
-{\r
- theRGB.push_back(theRed);\r
- theRGB.push_back(theGreen);\r
- theRGB.push_back(theBlue);\r
-}\r
-\r
-bool containsValues(std::map<int, std::vector<int> >& theColorMap, std::vector<int>& theValues)\r
-{\r
- std::map<int, std::vector<int> >::const_iterator anIt = theColorMap.begin(), aLast = theColorMap.end();\r
- bool isFound = false;\r
- for (; anIt != aLast && !isFound; anIt++) {\r
- std::vector<int> aValues = anIt->second;\r
- isFound = aValues[0] == theValues[0] &&\r
- aValues[1] == theValues[1] &&\r
- aValues[2] == theValues[2];\r
- }\r
- return isFound;\r
-}\r
-\r
-std::vector<int> HSVtoRGB(int theH, int theS, int theV)\r
-{\r
- std::vector<int> aRGB;\r
- if (theH < 0 || theH > 360 ||\r
- theS < 0 || theS > 100 ||\r
- theV < 0 || theV > 100)\r
- return aRGB;\r
-\r
- int aHi = (int)theH/60;\r
-\r
- double aV = theV;\r
- double aVmin = (100 - theS)*theV/100;\r
-\r
- double anA = (theV - aVmin)* (theH % 60) / 60;\r
-\r
- double aVinc = aVmin + anA;\r
- double aVdec = theV - anA;\r
-\r
- double aPercentToValue = 255./100;\r
- int aV_int = (int)(aV*aPercentToValue);\r
- int aVinc_int = (int)(aVinc*aPercentToValue);\r
- int aVmin_int = (int)(aVmin*aPercentToValue);\r
- int aVdec_int = (int)(aVdec*aPercentToValue);\r
-\r
- switch(aHi) {\r
- case 0: appendValues(aRGB, aV_int, aVinc_int, aVmin_int); break;\r
- case 1: appendValues(aRGB, aVdec_int, aV_int, aVmin_int); break;\r
- case 2: appendValues(aRGB, aVmin_int, aV_int, aVinc_int); break;\r
- case 3: appendValues(aRGB, aVmin_int, aVdec_int, aV_int); break;\r
- case 4: appendValues(aRGB, aVinc_int, aVmin_int, aV_int); break;\r
- case 5: appendValues(aRGB, aV_int, aVmin_int, aVdec_int); break;\r
- default: break;\r
- }\r
- return aRGB;\r
-}\r
-\r
-\r
-void fillColorMap()\r
-{\r
- if (!myColorMap.empty())\r
- return;\r
-\r
- int i = 0;\r
- for (int s = 100; s > 0; s = s - 50)\r
- {\r
- for (int v = 100; v >= 40; v = v - 20)\r
- {\r
- for (int h = 0; h < 359 ; h = h + 60)\r
- {\r
- std::vector<int> aColor = HSVtoRGB(h, s, v);\r
- if (containsValues(myColorMap, aColor))\r
- continue;\r
- myColorMap[i] = aColor;\r
- i++;\r
- }\r
- }\r
- }\r
-}\r
-\r
-void findRandomColor(std::vector<int>& theValues)\r
-{\r
- theValues.clear();\r
- if (myColorMap.empty()) {\r
- fillColorMap();\r
- }\r
-\r
- size_t aSize = myColorMap.size();\r
- int anIndex = rand() % aSize;\r
- if (myColorMap.find(anIndex) != myColorMap.end()) {\r
- theValues = myColorMap.at(anIndex);\r
- }\r
-}\r
-\r
ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)\r
{\r
if (theMain != theSub) { // to optimize and avoid of crash on partset document close (don't touch the sub-document structure)\r
double& outValue, ResultParameterPtr& theParam,\r
const DocumentPtr& theDocument = DocumentPtr());\r
\r
-/*!\r
- * Returns the values of the next random color. The values are in range [0, 255]\r
- * \param theValues a container of component of RGB value: red, green, blue\r
- */\r
-MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);\r
-\r
/*!\r
* Searches for Part result that contains the reference to the given document.\r
* The result must be presented in the tree.\r
return aValues;
}
+// contains global cash for integer index of the color -> RGB of this color
+static std::map<int, std::vector<int> > myColorMap;
+
+void appendValues(std::vector<int>& theRGB, const int theRed, const int theGreen, const int theBlue)
+{
+ theRGB.push_back(theRed);
+ theRGB.push_back(theGreen);
+ theRGB.push_back(theBlue);
+}
+
+bool containsValues(std::map<int, std::vector<int> >& theColorMap, std::vector<int>& theValues)
+{
+ std::map<int, std::vector<int> >::const_iterator anIt = theColorMap.begin(), aLast = theColorMap.end();
+ bool isFound = false;
+ for (; anIt != aLast && !isFound; anIt++) {
+ std::vector<int> aValues = anIt->second;
+ isFound = aValues[0] == theValues[0] &&
+ aValues[1] == theValues[1] &&
+ aValues[2] == theValues[2];
+ }
+ return isFound;
+}
+
+std::vector<int> HSVtoRGB(int theH, int theS, int theV)
+{
+ std::vector<int> aRGB;
+ if (theH < 0 || theH > 360 ||
+ theS < 0 || theS > 100 ||
+ theV < 0 || theV > 100)
+ return aRGB;
+
+ int aHi = (int)theH/60;
+
+ double aV = theV;
+ double aVmin = (100 - theS)*theV/100;
+
+ double anA = (theV - aVmin)* (theH % 60) / 60;
+
+ double aVinc = aVmin + anA;
+ double aVdec = theV - anA;
+
+ double aPercentToValue = 255./100;
+ int aV_int = (int)(aV*aPercentToValue);
+ int aVinc_int = (int)(aVinc*aPercentToValue);
+ int aVmin_int = (int)(aVmin*aPercentToValue);
+ int aVdec_int = (int)(aVdec*aPercentToValue);
+
+ switch(aHi) {
+ case 0: appendValues(aRGB, aV_int, aVinc_int, aVmin_int); break;
+ case 1: appendValues(aRGB, aVdec_int, aV_int, aVmin_int); break;
+ case 2: appendValues(aRGB, aVmin_int, aV_int, aVinc_int); break;
+ case 3: appendValues(aRGB, aVmin_int, aVdec_int, aV_int); break;
+ case 4: appendValues(aRGB, aVinc_int, aVmin_int, aV_int); break;
+ case 5: appendValues(aRGB, aV_int, aVmin_int, aVdec_int); break;
+ default: break;
+ }
+ return aRGB;
+}
+
+
+void fillColorMap()
+{
+ if (!myColorMap.empty())
+ return;
+
+ int i = 0;
+ for (int s = 100; s > 0; s = s - 50)
+ {
+ for (int v = 100; v >= 40; v = v - 20)
+ {
+ for (int h = 0; h < 359 ; h = h + 60)
+ {
+ std::vector<int> aColor = HSVtoRGB(h, s, v);
+ if (containsValues(myColorMap, aColor))
+ continue;
+ myColorMap[i] = aColor;
+ i++;
+ }
+ }
+ }
+}
+
+void findRandomColor(std::vector<int>& theValues)
+{
+ theValues.clear();
+ if (myColorMap.empty()) {
+ fillColorMap();
+ }
+
+ size_t aSize = myColorMap.size();
+ int anIndex = rand() % aSize;
+ if (myColorMap.find(anIndex) != myColorMap.end()) {
+ theValues = myColorMap.at(anIndex);
+ }
+}
std::vector<int> XGUI_ColorDialog::getRandomColor() const
{
std::vector<int> aValues;
if (isRandomColor()) {
- ModelAPI_Tools::findRandomColor(aValues);
+ findRandomColor(aValues);
}
return aValues;
}