From ccb3a37d93957b8fda72125eea15c64ff45ea08c Mon Sep 17 00:00:00 2001 From: Jeremy Nicola Date: Fri, 9 Oct 2015 23:31:42 +0200 Subject: [PATCH 1/5] Missing cmath header --- viewer/vibesgraphicsitem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 0b58db9..6e3937a 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -14,6 +14,8 @@ #include #include +#include + // The only instance of VibesDefaults VibesDefaults VibesDefaults::_instance; From 66f692d704e0834f4c705dede7f9249496e38901 Mon Sep 17 00:00:00 2001 From: Jeremy Nicola Date: Sat, 10 Oct 2015 00:09:53 +0200 Subject: [PATCH 2/5] Canvas for ring drawing --- client-api/C++/examples/all_commands.cpp | 3 +++ client-api/C++/src/vibes.cpp | 12 ++++++++++++ client-api/C++/src/vibes.h | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/client-api/C++/examples/all_commands.cpp b/client-api/C++/examples/all_commands.cpp index 549afb1..27ccedd 100644 --- a/client-api/C++/examples/all_commands.cpp +++ b/client-api/C++/examples/all_commands.cpp @@ -216,6 +216,9 @@ int main() VIBES_TEST( vibes::drawPie(0,-20,3,1,-20, -220, "black[red]") ); VIBES_TEST( vibes::drawPie(10,-20,3,4,700, 800, "black[red]") ); VIBES_TEST( vibes::drawPie(5,-20,3,3,20, 120, "black[red]") ); + + cout << "drawRing"<< endl; + VIBES_TEST( vibes::drawRing(42,42,20,23,"black[red]")); cout << "drawBoxes with vector of vector of bounds" << std::endl; { diff --git a/client-api/C++/src/vibes.cpp b/client-api/C++/src/vibes.cpp index 426f017..b5ae137 100644 --- a/client-api/C++/src/vibes.cpp +++ b/client-api/C++/src/vibes.cpp @@ -297,6 +297,18 @@ namespace vibes fputs(Value(msg).toJSONString().append("\n\n").c_str(), channel); fflush(channel); } + + void drawRing(const double &cx, const double &cy, const double &r_min, const double &r_max, Params params) + { + Params msg; + msg["action"] = "draw"; + msg["figure"] = params.pop("figure",current_fig); + msg["shape"] = (params, "type", "ring", + "center", (Vec2d){cx,cy}, + "rho", (Vec2d){r_min,r_max}); + fputs(Value(msg).toJSONString().append("\n\n").c_str(), channel); + fflush(channel); + } void drawBoxes(const std::vector > &bounds, Params params) { diff --git a/client-api/C++/src/vibes.h b/client-api/C++/src/vibes.h index 1f02730..33dba7b 100644 --- a/client-api/C++/src/vibes.h +++ b/client-api/C++/src/vibes.h @@ -323,6 +323,11 @@ namespace vibes { VIBES_FUNC_COLOR_PARAM_6(drawPie, const double &,cx, const double &,cy, const double &,r_min, const double &,r_max, const double &,theta_min, const double &,theta_max) + + /// Draw a ring at position (cx, cy) with radius between (r_min, r_max) + VIBES_FUNC_COLOR_PARAM_4(drawRing, const double &,cx, const double &,cy, + const double &,r_min, const double &,r_max) + /// @} /// @name Objects grouping and deletion /// @{ From 544b0dbb24844968d1d1dd4f00a5c7c7f1c0c849 Mon Sep 17 00:00:00 2001 From: Jeremy Nicola Date: Sat, 10 Oct 2015 00:10:35 +0200 Subject: [PATCH 3/5] Fixing a missing return in Luc Jaulin's interval library --- client-api/C++/examples/interval/box.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client-api/C++/examples/interval/box.cpp b/client-api/C++/examples/interval/box.cpp index fb0d60a..af7e4b0 100644 --- a/client-api/C++/examples/interval/box.cpp +++ b/client-api/C++/examples/interval/box.cpp @@ -106,6 +106,7 @@ box& box::Intersect(const box& Y) { box X=*this; box Z=Inter(X,Y); *this=Z; + return *this; } @@ -208,7 +209,7 @@ box Sup(box X) } //---------------------------------------------------------------------- box Concat(const box& X, const box& Y) -/* Produit Cartesien ou Concat�nation de deuX pav�s X et y : +/* Produit Cartesien ou Concat�nation de deuX pav�s X et y : Ans=[X,Y] => Ans=Concat(X,Y); */ { double dim=X.Size()+Y.Size(); box Ans(dim); if ((!X.IsEmpty())&&(!Y.IsEmpty())) @@ -219,7 +220,7 @@ box Concat(const box& X, const box& Y) } //---------------------------------------------------------------------- box Proj(const box& X, int i, int j) -/* Projection du pav� X dans un espace de dimension dim=(j-i)+1; +/* Projection du pav� X dans un espace de dimension dim=(j-i)+1; X=[[X1],[X2],..,[Xi],..,[Xj],..[Xn]] => Proj(X,i,j)=[[Xi],..,[Xj]] et Proj(X,i,i)=[Xi] */ { int dim=abs(j-i)+1; box Ans(dim); From 687cbb4794f96de54d088d48c9f8726eea9b57ec Mon Sep 17 00:00:00 2001 From: Jeremy Nicola Date: Sat, 10 Oct 2015 00:56:28 +0200 Subject: [PATCH 4/5] Handling Ring drawings --- viewer/vibesgraphicsitem.cpp | 86 +++++++++++++++++++++++++++++++++++- viewer/vibesgraphicsitem.h | 14 +++++- 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 0b58db9..dcc5540 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -186,6 +186,9 @@ VibesGraphicsItem * VibesGraphicsItem::newWithType(const QString type) else if (type == "pie") { return new VibesGraphicsPie(); } + else if (type == "ring") { + return new VibesGraphicsRing(); + } else if (type == "point") { //! \todo Implement "point" type } @@ -1261,9 +1264,9 @@ bool VibesGraphicsPie::computeProjection(int dimX, int dimY) // Now process shape-specific properties // (we can only update properties of a shape, but mutation into another type is not supported) Q_ASSERT (json.contains("type")); - // VibesGraphicsPie has JSON type "arrow" + // VibesGraphicsPie has JSON type "pie" Q_ASSERT ( json["type"].toString() == "pie" ); - // "bounds" is a matrix + QJsonArray center = json["center"].toArray(); QJsonArray rho = json["rho"].toArray(); QJsonArray theta = json["theta"].toArray(); @@ -1307,3 +1310,82 @@ bool VibesGraphicsPie::computeProjection(int dimX, int dimY) // Update successful return true; } + +// +// VibesGraphicsRing +// +bool VibesGraphicsRing::parseJsonGraphics(const QJsonObject& json) +{ + // Now process shape-specific properties + // (we can only update properties of a shape, but mutation into another type is not supported) + if (json.contains("type")) + { + // Retrieve type + QString type = json["type"].toString(); + + // VibesGraphicsPie has JSON type "arrow" + if (type == "ring" && json.contains("center") && json.contains("rho")) + { + QJsonArray center = json["center"].toArray(); + if (center.size() != 2) return false; + if (json["rho"].toArray().size() != 2) return false; + // Compute dimension + this->_nbDim = center.size(); + + // Update successful + return true; + } + } + + // Unknown or empty JSON, update failed + return false; +} + +bool VibesGraphicsRing::computeProjection(int dimX, int dimY) +{ + const QJsonObject & json = this->_json; + + // Get ring color (or default if not specified) + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + + // Now process shape-specific properties + // (we can only update properties of a shape, but mutation into another type is not supported) + Q_ASSERT (json.contains("type")); + // VibesGraphicsRing has JSON type "ring" + Q_ASSERT ( json["type"].toString() == "ring" ); + + QJsonArray center = json["center"].toArray(); + QJsonArray rho = json["rho"].toArray(); + + Q_ASSERT ( rho[0].toDouble() >= 0); + Q_ASSERT ( rho[1].toDouble() >= rho[0].toDouble()); + + // Body + { + double cx = center[0].toDouble(); + double cy = center[1].toDouble(); + + double rho_m = rho[0].toDouble(); + double rho_p = rho[1].toDouble(); + + QRectF boundingBoxP(cx+rho_p,cy+rho_p,2*rho_p,2*rho_p); + + QPainterPath path; + path.addEllipse(boundingBoxP); + + QRectF boundingBoxM(cx+rho_m,cy+rho_m,2*rho_m,2*rho_m); + QPainterPath pathM; + pathM.addEllipse(boundingBoxM); + + path=path.subtracted(pathM); + + QGraphicsPathItem *graphics_path = new QGraphicsPathItem(path); + graphics_path->setPen(pen); + graphics_path->setBrush(brush); + this->addToGroup(graphics_path); + } + + // Update successful + return true; +} \ No newline at end of file diff --git a/viewer/vibesgraphicsitem.h b/viewer/vibesgraphicsitem.h index 6e31c78..fc4ce76 100644 --- a/viewer/vibesgraphicsitem.h +++ b/viewer/vibesgraphicsitem.h @@ -43,6 +43,8 @@ class VibesGraphicsItem VibesGraphicsEllipseType, VibesGraphicsPolygonType, VibesGraphicsArrowType, + VibesGraphicsPieType, + VibesGraphicsRingType, // Complex types based on primitive types VibesGraphicsVehicleType, VibesGraphicsVehicleAUVType, @@ -52,8 +54,7 @@ class VibesGraphicsItem VibesGraphicsBoxesType, VibesGraphicsBoxesUnionType, // Do not remove the following value! It signals the end of VibesGraphicsItem types - VibesGraphicsLastType, - VibesGraphicsPieType + VibesGraphicsLastType }; // Constructor VibesGraphicsItem(QGraphicsItem * qGraphicsItem); @@ -276,4 +277,13 @@ class VibesGraphicsPie : public QGraphicsItemGroup, public VibesGraphicsItem bool computeProjection(int dimX, int dimY); }; +class VibesGraphicsRing : public QGraphicsItemGroup, public VibesGraphicsItem +{ + VIBES_GRAPHICS_ITEM(VibesGraphicsRing, QGraphicsItemGroup) + VIBES_GEOMETRY_CHANGING_PROPERTIES("center","rho") +protected: + bool parseJsonGraphics(const QJsonObject &json); + bool computeProjection(int dimX, int dimY); +}; + #endif // VIBESGRAPHICSITEM_H From d09324d26ec524311259dd803612ad264e803e14 Mon Sep 17 00:00:00 2001 From: Jeremy Nicola Date: Sat, 10 Oct 2015 01:25:33 +0200 Subject: [PATCH 5/5] Rings are working --- viewer/vibesgraphicsitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 0ee7d67..ab0e720 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -1371,12 +1371,12 @@ bool VibesGraphicsRing::computeProjection(int dimX, int dimY) double rho_m = rho[0].toDouble(); double rho_p = rho[1].toDouble(); - QRectF boundingBoxP(cx+rho_p,cy+rho_p,2*rho_p,2*rho_p); + QRectF boundingBoxP(cx-rho_p,cy-rho_p,2*rho_p,2*rho_p); QPainterPath path; path.addEllipse(boundingBoxP); - QRectF boundingBoxM(cx+rho_m,cy+rho_m,2*rho_m,2*rho_m); + QRectF boundingBoxM(cx-rho_m,cy-rho_m,2*rho_m,2*rho_m); QPainterPath pathM; pathM.addEllipse(boundingBoxM);