PeriDyno 1.2.1
Loading...
Searching...
No Matches
Ramp.inl
Go to the documentation of this file.
1#ifndef RAMP_SERIALIZATION
2#define RAMP_SERIALIZATION
3
4#include "Field.h"
5#include "Ramp.h"
6
7namespace dyno {
8
9 template<>
10 inline std::string FVar<Ramp>::serialize()
11 {
12
13 std::string finalText;
14 //serialize Array
15 this->getValue().convertCoordToStr("UserPoints", this->getValue().Ramp::getUserPoints(), finalText);
16 this->getValue().convertCoordToStr("UserHandles", this->getValue().Ramp::getUserHandles(), finalText);
17
18 //serialize Var
19 this->getValue().convertVarToStr("Resample", this->getValue().getResample(), finalText);
20 this->getValue().convertVarToStr("Spacing", this->getValue().getSpacing(), finalText);
21
22 this->getValue().convertVarToStr("Close", this->getValue().getClose(), finalText);
23 this->getValue().convertVarToStr("InterpMode", this->getValue().getInterpMode(), finalText);
24
25 std::stringstream ss;
26 ss << finalText;
27
28 return ss.str();
29 }
30
31
32 template<>
33 inline bool FVar<Ramp>::deserialize(const std::string& str)
34 {
35 if (str.empty())
36 return false;
37
38
39 std::stringstream ss(str);
40 std::string substr;
41
42
43 auto ramp = std::make_shared<Ramp>();
44
45 int countMyCoord = -1;
46 int countHandle = -1;
47 int countRange = -2;
48 double tempCoord = 0;
49 std::string currentVarName;
50
51 while (ss >> substr)
52 {
53 if (isalpha(substr[0]))
54 {
55 currentVarName = substr;
56 }
57
58 if (currentVarName == "UserPoints")
59 {
60 countMyCoord++;
61 if (countMyCoord > 0 && countMyCoord % 2 != 0)
62 {
63 tempCoord = std::stod(substr);
64 }
65 else if (countMyCoord > 0 && countMyCoord % 2 == 0)
66 {
67 ramp->getUserPoints().push_back(Ramp::Coord2D(tempCoord, std::stod(substr)));
68 }
69 }
70 else if (currentVarName == "UserHandles")
71 {
72 countHandle++;
73 if (countHandle > 0 && countHandle % 2 != 0)
74 {
75 tempCoord = std::stod(substr);
76 }
77 else if (countHandle > 0 && countHandle % 2 == 0)
78 {
79 ramp->getUserHandles().push_back(Ramp::Coord2D(tempCoord, std::stod(substr)));
80 }
81 }
82 else if (currentVarName == "Resample")
83 ramp->setVarByStr(substr, ramp->getResample());
84 else if (currentVarName == "Spacing")
85 ramp->setVarByStr(substr, ramp->getSpacing());
86 else if (currentVarName == "Close")
87 ramp->setVarByStr(substr, ramp->getClose());
88 else if (currentVarName == "InterpMode")
89 ramp->setVarByStr(substr, ramp->getInterpMode());
90 }
91
92 ramp->updateBezierCurve();
93 ramp->UpdateFieldFinalCoord();
94
95 this->setValue(*ramp);
96
97 return true;
98 }
99
100 template class FVar<Ramp>;
101}
102
103#endif // !CURVE_SERIALIZATION
std::vector< Coord2D > & getUserPoints()
Definition Canvas.h:203
std::vector< Coord2D > & getUserHandles()
Definition Canvas.h:204
std::string serialize() override
Definition Field.h:60
bool deserialize(const std::string &str) override
Definition Field.h:61
float getValue()
Definition Field.h:136
void setValue(float val, bool notify=true)
Definition Field.h:116
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25