17 #ifndef JSONTRANSLATOR_H
18 #define JSONTRANSLATOR_H
23 #include "chain/ApiTypes.h"
24 #include "StatusUtils.h"
29 const double indeterminate = std::numeric_limits<double>::quiet_NaN();
34 const size_t FRONTAL_MARK_COUNT = 5;
35 const size_t NEAR_PD_MARK_COUNT = 3;
36 const size_t LATERAL_MARK_COUNT = 3;
37 const size_t EYE_COUNT = 2;
38 const size_t LENSBOX_CORNER_COUNT = 4;
39 const size_t WINDROSE_DIRECTION_COUNT = 4;
40 const size_t LATERALBOX_CORNER_COUNT = 3;
41 const size_t STRUT_LENSCONTOUR_INTERSECTION_COUNT = 4;
43 const json_string jsCameraAttitude =
"camera_attitude";
44 const json_string jsDetails =
"details";
46 const json_string jsExposureArrangement =
"exposure_arrangement";
48 const json_string jsImages =
"images";
49 const json_string jsFile =
"file";
50 const json_string jsImage =
"image";
51 const json_string jsOpticalAxis =
"optical_axis";
52 const json_string jsStatus =
"status";
53 const json_string jsResultImage =
"result_image";
54 const json_string jsSize =
"size";
55 const json_string jsFront =
"front";
56 const json_string jsNearFront =
"near_front";
57 const json_string jsRight =
"right";
58 const json_string jsLeft =
"left";
60 const json_string jsMethod =
"method";
62 const json_string jsNoMethod =
"";
63 const json_string jsFrontOnly =
"front";
64 const json_string jsRightSideFront =
"front+right";
65 const json_string jsFrontLeftSide =
"front+left";
66 const json_string jsRightSideFrontLeftSide =
"front+right+left";
68 const json_string jsRealizedSize =
"realised_size";
69 const json_string jsMinimumSize =
"minimum_size";
70 const json_string jsMaximumSize =
"maximum_size";
71 const json_string jsMinimumMarkMargin =
"minimum_mark_margin";
73 const json_string jsTransformation =
"transformation";
74 const json_string jsImageSize =
"image_size";
75 const json_string jsClippingOffset =
"clipping_offset";
76 const json_string jsPivot =
"pivot";
77 const json_string jsAngle =
"angle";
78 const json_string jsScaleFactor =
"scale_factor";
79 const json_string jsProgressiveCorridorLength =
"progressive_corridor_length";
80 const json_string jsComputationModel =
"computation_model";
82 const json_string jsMarks =
"marks";
83 const json_string jsIris =
"iris";
84 const json_string jsLens =
"lens";
85 const json_string jsLensL =
"lens_L";
86 const json_string jsLensR =
"lens_R";
87 const json_string jsLensMarginL =
"lens_margin_L";
88 const json_string jsLensMarginR =
"lens_margin_R";
89 const json_string jsCenter =
"center";
90 const json_string jsDiameter =
"diameter";
91 const json_string jsSpherical =
"spherical";
92 const json_string jsAspheric =
"aspheric";
93 const json_string jsProgressive =
"progressive";
94 const json_string jsMETS =
"hoya_mets";
95 const json_string jsBox =
"box";
96 const json_string jsPlanePixelsPerMm =
"plane_pixels_per_mm";
97 const json_string jsFaceFormAngleRef =
"face_form_angle_ref";
98 const json_string jsInfantGlassesConfig =
"infant_glasses_config";
99 const json_string jsMarkMarginInPercent =
"percentage_mark_margin";
100 const json_string jsProgressiveCorridorTop =
"progressive_corridor_top";
101 const json_string jsProgressiveCorridorBottom =
"progressive_corridor_bottom";
102 const json_string jsStrutLensContourIntersections =
"strut_lens_contour_intersections";
104 const json_string jsLensBevels =
"lens_bevels";
105 const json_string jsLensThickness =
"lens_thickness";
106 const json_string jsResults =
"results";
107 const json_string jsPreciseResults =
"precise_results";
109 const json_string jsGrooveDepth [GROOVE_DEPTH_CLASS] = {
111 "groove depth: 0.5 mm",
112 "groove depth: 0.7 mm"
115 const json_string jsHeadRotationCompensationOff =
"head rotation compensation: off";
116 const json_string jsHeadRotationCompensationOn =
"head rotation compensation: on";
117 const json_string jsReadingDistance =
"reading_distance";
118 const json_string jsVarioInsetTop =
"up";
119 const json_string jsVarioInsetMiddle =
"middle";
120 const json_string jsVarioInsetBottom =
"down";
122 JSONNode& getJsonNode(JSONNode& parent,
char nodeType,
const json_string& name,
bool clear =
false);
123 JSONNode& getEmptyJsonNode(JSONNode& parent,
const json_string& name);
124 JSONNode& getEmptyJsonArray(JSONNode& parent,
const json_string& name);
137 IntArray(
const json_string& key,
int initValue = 0)
139 for (
size_t i = 0; i < n; i++)
141 values[i] = initValue;
146 bool tryReadFromJson(
const JSONNode& node)
148 if (node.name() == key_) {
150 JSONNode::const_iterator i = node.begin();
152 for (
size_t j = 0; j < n; j++) {
153 if (i != node.end()) {
154 values[j] = i->as_int();
163 void writeToJson(JSONNode& parent)
165 JSONNode& node = getEmptyJsonArray(parent, key_);
166 JSONNode value(JSON_NUMBER);
168 for (
size_t j = 0; j < n; j++) {
170 node.push_back(value);
174 void writeToVrCore(
void (*setter)(
const int values[])) { setter(values); };
175 void writeToVrCore(
void (*setter)(
const int values[],
const LateralSide partialImage)) { setter(values, RIGHT); };
176 void readFromVrCore(
void (*getter)(
int values[])) { getter(values); };
195 for (
size_t i = 0; i < n; i++)
197 values[i] = initValue;
203 bool tryReadFromJson(
const JSONNode& node)
205 if (node.name() == key_) {
206 JSONNode::const_iterator k = node.begin();
207 readStatusFromJson(*k++, info_);
208 JSONNode::const_iterator i = (*k).begin();
209 for (
size_t j = 0; j < n; j++) {
210 if (i != (*k).end()) {
211 values[j] = i->as_int();
220 void writeArrayToJson(JSONNode& parent)
const
222 JSONNode node(JSON_ARRAY);
224 if (!(parent.name() == key_))
227 JSONNode value(JSON_NUMBER);
229 for (
size_t j = 0; j < n; j++) {
231 node.push_back(value);
234 parent.push_back(node);
237 void writeToJson(JSONNode& parent)
239 JSONNode& node = getEmptyJsonArray(parent, key_);
241 JSONNode s(JSON_STRING);
242 writeStatusToJson(s, info_);
245 writeArrayToJson(node);
257 void writeToVrCore(
void (*setter)(
const int values[],
const StatusInfo info_)) { setter(values, info_); };
258 void readFromVrCore(StatusInfo (*getter)(
int values[])) { info_ = getter(values); };
259 int& operator [](
size_t i) {
return values[i]; };
279 for (
size_t i = 0; i < n; i++)
281 values_[i] = indeterminate;
286 bool tryReadFromJson(
const JSONNode& node)
288 if (node.name() == key_) {
289 JSONNode::const_iterator i = node.begin();
290 for (
size_t j = 0; j < n; j++) {
291 if (i != node.end()) {
292 values_[j] = i->as_float();
301 void writeToJson(JSONNode& parent)
303 JSONNode& node = getEmptyJsonArray(parent, key_);
304 JSONNode value(JSON_NUMBER);
306 for (
size_t j = 0; j < n; j++) {
307 double x = values_[j];
308 if (!std::isfinite(x))
312 node.push_back(value);
316 void writeToVrCore(
void (*setter)(
const double values[]))
318 if (values_[0] == values_[0])
321 void readFromVrCore(
void (*getter)(
double values[])) { getter(values_); };
323 double& operator [](
size_t i) {
return values_[i]; };
342 for (
size_t i = 0; i < n; i++)
345 coordinates[i][0] = 0.0;
346 coordinates[i][1] = 0.0;
349 coordinates[i][0] = indeterminate;
350 coordinates[i][1] = indeterminate;
355 void readFromJson(
const JSONNode& node,
const char*
id[n])
357 for (
size_t i = 0; i < n; i++)
359 JSONNode j = node[
id[i]];
360 readStatusFromJson(j[0], info[i]);
361 coordinates[i][0] = (j[1][0].as_float());
362 coordinates[i][1] = (j[1][1].as_float());
366 void writeToJson(JSONNode& node,
const char*
id[n])
369 for (
size_t i = 0; i < n; i++)
371 JSONNode a(JSON_ARRAY);
374 JSONNode s(JSON_STRING);
375 writeStatusToJson(s, info[i]);
378 JSONNode a1(JSON_ARRAY);
379 JSONNode c(JSON_NUMBER);
380 double x = coordinates[i][0];
381 if (!std::isfinite(x))
386 x = coordinates[i][1];
387 if (!std::isfinite(x))
396 void writeToVrCore(
void (*setter)(
const double points[][2],
const StatusInfo info[]))
399 setter(coordinates, info);
401 void writeToVrCore(
void (*setter)(
const double points[][2],
const StatusInfo info[],
const LateralSide partialImage))
404 setter(coordinates, info, RIGHT);
406 void writeToVrCore(
void (*setter)(
const double points[][2],
const StatusInfo info[], VarioInsetPos,
size_t), VarioInsetPos p,
size_t i)
409 setter(coordinates, info, p, i);
411 void readFromVrCore(
void (*getter)(
double points[][2], StatusInfo info[])) { getter(coordinates, info); };
412 void readFromVrCore(
void (*getter)(
double points[][2], StatusInfo info[],
const LateralSide partialImage)) { getter(coordinates, info, RIGHT); };
413 void readFromVrCore(
void (*getter)(
double points[][2], StatusInfo info[], VarioInsetPos,
size_t), VarioInsetPos p,
size_t i)
414 { getter(coordinates, info, p, i); };
415 bool isValid() {
return info[0] != invalid; };
417 void getPoints(std::vector<cv::Point2d>& points)
const {
418 for (
size_t i = 0; i < n; i++) {
419 points.push_back(cv::Point2d(
425 void get(
double points[n][2], StatusInfo statusInfo[n]) {
426 for (
size_t i = 0; i < n; i++) {
427 points[i][0] = coordinates[i][0];
428 points[i][1] = coordinates[i][1];
429 statusInfo[i] = info[i];
432 void set(
double points[n][2], StatusInfo statusInfo[n]) {
433 for (
size_t i = 0; i < n; i++) {
434 coordinates[i][0] = points[i][0];
435 coordinates[i][1] = points[i][1];
436 info[i] = statusInfo[i];
440 double coordinates[n][2];
456 JsonPoint(
const json_string& key) : key_(key) {};
457 bool tryReadFromJson(
const JSONNode& node)
459 if (node.name() == key_) {
460 x = node[
"x"].as_float();
461 y = node[
"y"].as_float();
466 void writeToJson(JSONNode& parent)
468 JSONNode& node = getEmptyJsonNode(parent, key_);
470 JSONNode c(JSON_NUMBER);
495 JsonValue(json_string key, T value) : key_(key), value_(value) {};
496 bool tryReadFromJson(
const JSONNode& node)
498 if (node.name() == key_) {
504 void writeToVrCore(
void (*setter)(
const T value))
508 void readFromVrCore(T (*getter)()) { value_ = getter(); };
509 void writeToJson(JSONNode& parent)
511 JSONNode& value = getEmptyJsonNode(parent, key_);
514 inline void setValue(
const JSONNode& node);
515 void setValue(T value, StatusInfo status = guessed)
519 T getValue()
const {
return value_; };
537 ValueWithStatus(json_string key, T value) : key_(key), value_(value), status_(invalid) {};
538 bool tryReadFromJson(
const JSONNode& node)
540 if (node.name() == key_) {
541 readStatusFromJson(node[0], status_);
547 void writeToVrCore(
void (*setter)(
const T value,
const StatusInfo& statusInfo))
549 if (status_ != invalid)
550 setter(value_, status_);
552 void readFromVrCore(T (*getter)(StatusInfo& info)) { value_ = getter(status_); };
553 void writeToJson(JSONNode& parent)
555 if (status_ == invalid)
557 JSONNode& node = getEmptyJsonArray(parent, key_);
559 JSONNode s(JSON_STRING);
560 writeStatusToJson(s, status_);
563 JSONNode value(JSON_BOOL);
565 node.push_back(value);
567 inline void setValue(
const JSONNode& node);
568 void setValue(T value, StatusInfo status = guessed)
573 T getValue()
const {
return value_; };
599 bool readFromJson(JSONNode& rootNode);
600 void writeToJson(JSONNode& rootNode);
601 void writeToVrCore();
602 void readFromVrCore();
610 const std::string& getFileName()
const;
611 void setFileName(
const std::string& fileName);
612 StatusInfo getStatusInfo()
const;
613 void setStatusInfo(
const StatusInfo statusInfo);
615 virtual bool readFromJson(
const JSONNode& node);
616 virtual bool writeToJson(JSONNode& node);
617 virtual void writeToVrCore(
void (*setCameraAttitude)(
const double [3]),
618 void (*setOpticalAxis)(
const double [2]),
619 void (*setPercentageMarkMargins)(
const int [4]));
620 virtual void writeToVrCore(
void (*setCameraAttitude)(
const double [3]),
621 void (*setOpticalAxis)(
const double [2]),
622 void (*setPercentageMarkMargins)(
const int [4],
const LateralSide));
623 virtual void readFurther(
const JSONNode& node) = 0;
629 void readJson(
const JSONNode& node);
630 void writeJson(JSONNode& node);
631 void readFromVrCore(StatusInfo (*getStatusInfo)());
632 void writeToVrCore(
void (*setter) (
const char*,
const StatusInfo));
633 void writeToVrCore(
void (*setter) (
const char*,
const StatusInfo,
const LateralSide));
634 std::string fileName_;
635 StatusInfo statusInfo_;
641 void readJson(
const JSONNode& node);
642 void writeJson(JSONNode& node);
643 void readFromVrCore(
void (*getter)(
int [2],
int [2],
double [2],
double&));
644 void readFromVrCore(
void (*getter)(
int [2],
int [2],
double [2],
double&,
const LateralSide));
645 void writeToVrCore(
void (*setter)(
const int [2],
const int [2],
const double [2],
const double));
646 void writeToVrCore(
void (*setter)(
const int [2],
const int [2],
const double [2],
const double,
const LateralSide));
649 int clippingOffset_ [2];
652 bool isValid()
const;
657 std::string fileName_;
658 double opticalAxis_ [2];
659 double cameraUp_ [3];
661 StatusInfo statusInfo_;
662 SubStatus subStatus_;
663 bool readCameraAttitudeFromJson(
const JSONNode& node);
671 bool readFromJson(
const JSONNode& node);
672 void readFurther(
const JSONNode& node);
673 bool writeToJson(JSONNode& node);
674 void writeMetsArrayToJson(JSONNode& node)
const;
675 void writeToVrCore();
676 void readFromVrCore();
677 const IntValue& lensDiameter(LensType lensType, LateralSide side)
const {
return (side == _R) ? lensDiameter_[lensType][_R] : lensDiameter_[lensType][_L]; };
685 class ProgressiveCorridor {
694 LensBox lensBox_[LATERAL_SIDE];
700 ProgressiveCorridor progressiveCorridor_;
704 void readProgressiveCorridorBottoms(
const JSONNode& node);
705 void readLensData(
const JSONNode& node,
const LensType lensType);
706 void writeLensData(JSONNode& node,
const LensType lensType);
721 void readFurther(
const JSONNode& node);
722 bool writeToJson(JSONNode& node);
723 void writeToVrCore();
724 void readFromVrCore();
729 float readingDistance_;
730 VarioInsetPos varioInsetPos_;
735 std::vector<VarioInsetImageData> top_;
736 std::vector<VarioInsetImageData> middle_;
737 std::vector<VarioInsetImageData> bottom_;
740 void readImages(
const JSONNode& node, std::vector<VarioInsetImageData>& images, VarioInsetPos p);
741 void writeImages(JSONNode& node, std::vector<VarioInsetImageData>& images);
742 bool readFromJson(
const JSONNode& node);
743 void writeToJson(JSONNode& node);
744 void writeToVrCore();
745 void readFromVrCore();
757 void readFurther(
const JSONNode& node);
758 bool writeToJson(JSONNode& node);
760 void readFromVrCoreR();
761 void readFromVrCoreL();
762 void writeToVrCoreR();
763 void writeToVrCoreL();
770 MeasuringMethod method_;
771 ExposureArrangement exposureArrangement_;
778 double lensThickness_;
781 int computationModel_;
784 void readRightSideFromVrCore();
785 void readLeftSideFromVrCore();
786 void writeRightSideToVrCore();
787 void writeLeftSideToVrCore();
790 void createGrooveDepthBranch(JSONNode& parent, GrooveDepthClass grooveDepthClass,
const bool rounded);
791 void createGrooveDepthBranches(JSONNode& parent,
const bool rounded);
792 void createResultList(JSONNode& node,
const Results& results,
const bool rounded)
const;
796 #endif // JSONTRANSLATOR_H
Definition: JsonTranslator.h:534
Definition: JsonTranslator.h:453
Definition: JsonTranslator.h:492
Definition: JsonTranslator.h:734
Definition: JsonTranslator.h:190
Definition: JsonTranslator.h:625
vario Inset-Aufnahme
Definition: JsonTranslator.h:717
Definition: JsonTranslator.h:604
Definition: JsonTranslator.h:337
"Übersetzt" zwischen JSON und vrcore
Definition: JsonTranslator.h:593
Definition: core_viewer.h:13
Definition: JsonTranslator.h:274
Definition: JsonTranslator.h:134
Definition: JsonTranslator.h:666
Definition: JsonTranslator.h:748