PeriDyno 1.0.0
Loading...
Searching...
No Matches
Ramp.h
Go to the documentation of this file.
1#ifndef RAMP_H
2#define RAMP_H
3
4#include <vector>
5#include <memory>
6#include <string>
7#include "Vector/Vector2D.h"
8#include "Vector/Vector3D.h"
9
10#include "Field.h"
11#include "Canvas.h"
12
13namespace dyno {
14
15
16 class Ramp : public Canvas
17 {
18 public:
19 Ramp();
20 Ramp(Direction dir);
21 Ramp(const Ramp& ramp);
22
23 ~Ramp() { ; };
24
28 float getCurveValueByX(float inputX);
32 void updateBezierCurve()override;
33
34 double calculateLengthForPointSet(std::vector<Coord2D> BezierPtSet);
42 void borderCloseResort();
46 void UpdateFieldFinalCoord() override;
47
48 public:
49 //ave
51
52 std::string DirectionStrings[int(Direction::count)] = { "x","y" };
53 std::vector<Coord2D> myBezierPoint_H;//
54
55 std::vector<Coord2D> FE_MyCoord;
56 std::vector<Coord2D> FE_HandleCoord;
57
58
59 private:
60 float xLess = 1;
61 float xGreater = 0;
62 float yLess = 1;
63 float yGreater = 0;
64
65
66 };
67
68 template<>
69 bool FVar<Ramp>::deserialize(const std::string& str)
70 {
71 if (str.empty())
72 return false;
73
74
75 std::stringstream ss(str);
76 std::string substr;
77
78
79 auto ramp = std::make_shared<Ramp>();
80
81 int countMyCoord = -1;
82 int countHandle = -1;
83 int countRange = -2;
84 double tempCoord = 0;
85 std::string currentVarName;
86
87 while (ss >> substr)
88 {
89 if (isalpha(substr[0]))
90 {
91 currentVarName = substr;
92 }
93
94 if (currentVarName == "MyCoord")
95 {
96 countMyCoord++;
97 if (countMyCoord > 0 && countMyCoord % 2 != 0)
98 {
99 tempCoord = std::stod(substr);
100 }
101 else if (countMyCoord > 0 && countMyCoord % 2 == 0)
102 {
103 ramp->mCoord.push_back(Ramp::Coord2D(tempCoord, std::stod(substr)));
104 }
105 }
106 else if (currentVarName == "myHandlePoint")
107 {
108 countHandle++;
109 if (countHandle > 0 && countHandle % 2 != 0)
110 {
111 tempCoord = std::stod(substr);
112 }
113 else if (countHandle > 0 && countHandle % 2 == 0)
114 {
115 ramp->myHandlePoint.push_back(Ramp::Coord2D(tempCoord, std::stod(substr)));
116 }
117 }
118 else if (currentVarName == "useCurve")
119 ramp->setVarByStr(substr, ramp->useBezierInterpolation);
120 else if (currentVarName == "resample")
121 ramp->setVarByStr(substr, ramp->resample);
122 else if (currentVarName == "useSquard")
123 ramp->setVarByStr(substr, ramp->useSquard);
124 else if (currentVarName == "Spacing")
125 ramp->setVarByStr(substr, ramp->Spacing);
126 else if (currentVarName == "NminX")
127 ramp->setVarByStr(substr, ramp->NminX);
128 else if (currentVarName == "NmaxX")
129 ramp->setVarByStr(substr, ramp->NmaxX);
130 else if (currentVarName == "NminY")
131 ramp->setVarByStr(substr, ramp->mNewMinY);
132 else if (currentVarName == "NmaxY")
133 ramp->setVarByStr(substr, ramp->NmaxY);
134 else if (currentVarName == "curveClose")
135 ramp->setVarByStr(substr, ramp->curveClose);
136 else if (currentVarName == "InterpMode")
137 ramp->setVarByStr(substr, ramp->mInterpMode);
138 else if (currentVarName == "Dirmode")
139 ramp->setVarByStr(substr, ramp->Dirmode);
140 else if (currentVarName == "lockSize")
141 ramp->setVarByStr(substr, ramp->lockSize);
142 else if (currentVarName == "useColseButton")
143 ramp->setVarByStr(substr, ramp->useColseButton);
144 else if (currentVarName == "useSquardButton")
145 ramp->setVarByStr(substr, ramp->useSquardButton);
146 else if (currentVarName == "segment")
147 ramp->setVarByStr(substr, ramp->segment);
148 else if (currentVarName == "resampleResolution")
149 ramp->setVarByStr(substr, ramp->resampleResolution);
150 else if (currentVarName == "useSquardButton")
151 ramp->setVarByStr(substr, ramp->useSquardButton);
152 else if (currentVarName == "useSquardButton")
153 ramp->setVarByStr(substr, ramp->useSquardButton);
154 else if (currentVarName == "remapRange")
155 {
156 countRange++;
157 if (countRange >= 0)
158 {
159 ramp->remapRange[countRange] = std::stof(substr);
160 }
161 }
162 }
163
164 ramp->updateBezierCurve();
165 ramp->UpdateFieldFinalCoord();
166
167 this->setValue(*ramp);
168
169 return true;
170 }
171
172 template class FVar<Ramp>;
173}
174
175#endif // !RAMP_H
bool deserialize(const std::string &str) override
Definition Field.h:56
void setValue(float val)
Definition Field.h:111
float xGreater
Definition Ramp.h:61
float getCurveValueByX(float inputX)
Get the value value"Y" of the curve by value"X" .
Definition Ramp.cpp:67
std::vector< Coord2D > FE_MyCoord
Definition Ramp.h:55
void updateBezierCurve() override
Update the data of the Bezier curve points.
Definition Ramp.cpp:101
void updateResampleBezierCurve()
Resample Bezier curve.
Definition Ramp.cpp:122
~Ramp()
Definition Ramp.h:23
float xLess
Definition Ramp.h:60
float yGreater
Definition Ramp.h:63
std::vector< Coord2D > FE_HandleCoord
Definition Ramp.h:56
double calculateLengthForPointSet(std::vector< Coord2D > BezierPtSet)
Definition Ramp.cpp:178
void borderCloseResort()
Reordering points on canvas boundaries.
Definition Ramp.cpp:201
std::string DirectionStrings[int(Direction::count)]
Definition Ramp.h:52
Direction Dirmode
Definition Ramp.h:50
float yLess
Definition Ramp.h:62
std::vector< Coord2D > myBezierPoint_H
Definition Ramp.h:53
void UpdateFieldFinalCoord() override
Updating the data of a Field.
Definition Ramp.cpp:269
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25