PeriDyno 1.0.0
Loading...
Searching...
No Matches
Curve.h
Go to the documentation of this file.
1#ifndef CURVE_H
2#define CURVE_H
3
4#pragma once
5#include <vector>
6#include <memory>
7#include <string>
8#include "Vector/Vector2D.h"
9#include "Vector/Vector3D.h"
10
11#include "Field.h"
12#include "Canvas.h"
13
14namespace dyno {
15
16 class Curve :public Canvas
17 {
18 public:
19
20 Curve();
22 {
23 curveClose = int(mode);
24 }
25 Curve(const Curve& curve);
26
27 ~Curve() { };
28
32 void updateResampleBezierCurve(std::vector<Coord2D>& myBezierPoint_H);
36 void UpdateFieldFinalCoord() override;
37
38 private:
39
40 };
41
42 template<>
43 inline std::string FVar<Curve>::serialize()
44 {
45
46 std::string finalText;
47 //serialize Array
48 this->getValue().convertCoordToStr("MyCoord", this->getValue().Curve::mCoord, finalText);
49 this->getValue().convertCoordToStr("myHandlePoint", this->getValue().Curve::myHandlePoint, finalText);
50
51 //serialize Var
52 this->getValue().convertVarToStr("useCurve", this->getValue().useBezierInterpolation, finalText);
53 this->getValue().convertVarToStr("resample", this->getValue().resample, finalText);
54 this->getValue().convertVarToStr("useSquard", this->getValue().useSquard, finalText);
55 this->getValue().convertVarToStr("Spacing", this->getValue().Spacing, finalText);
56
57 this->getValue().convertVarToStr("NminX", this->getValue().NminX, finalText);
58 this->getValue().convertVarToStr("NmaxX", this->getValue().NmaxX, finalText);
59 this->getValue().convertVarToStr("NminY", this->getValue().mNewMinY, finalText);
60 this->getValue().convertVarToStr("NmaxY", this->getValue().NmaxY, finalText);
61
62 this->getValue().convertVarToStr("curveClose", this->getValue().curveClose, finalText);
63 this->getValue().convertVarToStr("InterpMode", this->getValue().mInterpMode, finalText);
64 this->getValue().convertVarToStr("lockSize", this->getValue().lockSize, finalText);
65 this->getValue().convertVarToStr("useColseButton", this->getValue().useColseButton, finalText);
66 this->getValue().convertVarToStr("useSquardButton", this->getValue().useSquardButton, finalText);
67
68 {
69 finalText.append("remapRange");
70 finalText.append(" ");
71 for (int i = 0; i < 8; i++)
72 {
73 finalText.append(std::to_string(this->getValue().remapRange[i]));
74 if (i != 7) { finalText.append(" "); }
75 }
76 finalText.append(" ");
77 }
78
79 std::cout << std::endl << finalText;
80
81 std::stringstream ss;
82 ss << finalText;
83
84 return ss.str();
85 }
86
87
88 template<>
89 inline bool FVar<Curve>::deserialize(const std::string& str)
90 {
91 if (str.empty())
92 return false;
93
94
95 std::stringstream ss(str);
96 std::string substr;
97
98
99 auto ramp = std::make_shared<Curve>();
100
101 int countMyCoord = -1;
102 int countHandle = -1;
103 int countRange = -2;
104 double tempCoord = 0;
105 std::string currentVarName;
106
107 while (ss >> substr)
108 {
109 if (isalpha(substr[0]))
110 {
111 currentVarName = substr;
112 }
113
114 if (currentVarName == "MyCoord")
115 {
116 countMyCoord++;
117 if (countMyCoord > 0 && countMyCoord % 2 != 0)
118 {
119 tempCoord = std::stod(substr);
120 }
121 else if (countMyCoord > 0 && countMyCoord % 2 == 0)
122 {
123 ramp->mCoord.push_back(Curve::Coord2D(tempCoord, std::stod(substr)));
124 }
125 }
126 else if (currentVarName == "myHandlePoint")
127 {
128 countHandle++;
129 if (countHandle > 0 && countHandle % 2 != 0)
130 {
131 tempCoord = std::stod(substr);
132 }
133 else if (countHandle > 0 && countHandle % 2 == 0)
134 {
135 ramp->myHandlePoint.push_back(Curve::Coord2D(tempCoord, std::stod(substr)));
136 }
137 }
138 else if (currentVarName == "useCurve")
139 ramp->setVarByStr(substr, ramp->useBezierInterpolation);
140 else if (currentVarName == "resample")
141 ramp->setVarByStr(substr, ramp->resample);
142 else if (currentVarName == "useSquard")
143 ramp->setVarByStr(substr, ramp->useSquard);
144 else if (currentVarName == "Spacing")
145 ramp->setVarByStr(substr, ramp->Spacing);
146 else if (currentVarName == "NminX")
147 ramp->setVarByStr(substr, ramp->NminX);
148 else if (currentVarName == "NmaxX")
149 ramp->setVarByStr(substr, ramp->NmaxX);
150 else if (currentVarName == "NminY")
151 ramp->setVarByStr(substr, ramp->mNewMinY);
152 else if (currentVarName == "NmaxY")
153 ramp->setVarByStr(substr, ramp->NmaxY);
154 else if (currentVarName == "curveClose")
155 ramp->setVarByStr(substr, ramp->curveClose);
156 else if (currentVarName == "InterpMode")
157 ramp->setVarByStr(substr, ramp->mInterpMode);
158 else if (currentVarName == "lockSize")
159 ramp->setVarByStr(substr, ramp->lockSize);
160 else if (currentVarName == "useColseButton")
161 ramp->setVarByStr(substr, ramp->useColseButton);
162 else if (currentVarName == "useSquardButton")
163 ramp->setVarByStr(substr, ramp->useSquardButton);
164 else if (currentVarName == "useSquardButton")
165 ramp->setVarByStr(substr, ramp->useSquardButton);
166 else if (currentVarName == "useSquardButton")
167 ramp->setVarByStr(substr, ramp->useSquardButton);
168 else if (currentVarName == "remapRange")
169 {
170 countRange++;
171 if (countRange >= 0)
172 {
173 ramp->remapRange[countRange] = std::stof(substr);
174 }
175 }
176 }
177
178 ramp->updateBezierCurve();
179 ramp->UpdateFieldFinalCoord();
180
181 this->setValue(*ramp);
182
183 return true;
184 }
185
186 template class FVar<Curve>;
187}
188
189#endif
std::vector< Coord2D > mCoord
Definition Canvas.h:243
bool curveClose
Definition Canvas.h:263
std::vector< Coord2D > myHandlePoint
Definition Canvas.h:248
void updateResampleBezierCurve(std::vector< Coord2D > &myBezierPoint_H)
Resample Bezier curve.
Definition Curve.cpp:120
void UpdateFieldFinalCoord() override
Updating the data of a Field.
Definition Curve.cpp:57
Curve(CurveMode mode)
Definition Curve.h:21
std::string serialize() override
Definition Field.h:55
bool deserialize(const std::string &str) override
Definition Field.h:56
float getValue()
Definition Field.h:130
void setValue(float val)
Definition Field.h:111
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25