Skip to content

Commit b9cc41c

Browse files
committed
[raster] added rot parameter for drawRaster()
1 parent fefcd61 commit b9cc41c

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

client-api/C++/src/vibes.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,17 +654,17 @@ namespace vibes
654654
}
655655

656656
void drawText(const double &top_left_x, const double &top_left_y, const string& text,
657-
const double &scale, Params params)
657+
const double &scale, Params params)
658658
{
659659
beginDrawingIfNeeded();
660660
Params msg;
661661
Vec2d top_left_xy = { top_left_x, top_left_y };
662662
msg["action"]="draw";
663663
msg["figure"]=params.pop("figure",current_fig);
664664
msg["shape"]=(params, "type","text",
665-
"text",text,
665+
"text",text,
666666
"position",top_left_xy,
667-
"scale", scale);
667+
"scale", scale);
668668
fputs(Value(msg).toJSONString().append("\n\n").c_str(), channel.get());
669669
fflush(channel.get());
670670
}
@@ -723,6 +723,11 @@ namespace vibes
723723
}
724724

725725
void drawRaster(const std::string& rasterFilename, const double &xlb, const double &yub, const double &width, const double &height, Params params)
726+
{
727+
drawRaster(rasterFilename, xlb, yub, width, height, 0., params);
728+
}
729+
730+
void drawRaster(const std::string& rasterFilename, const double &xlb, const double &yub, const double &width, const double &height, const double & rot, Params params)
726731
{
727732
beginDrawingIfNeeded();
728733
Vec2d ul_corner = { xlb, yub };
@@ -734,7 +739,8 @@ namespace vibes
734739
msg["shape"] = (params, "type", "raster",
735740
"filename", rasterFilename,
736741
"ul_corner", ul_corner,
737-
"size", size
742+
"size", size,
743+
"rot", rot
738744
);
739745

740746
fputs(Value(msg).toJSONString().append("\n\n").c_str(), channel.get());

client-api/C++/src/vibes.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,12 @@ namespace vibes {
343343
VIBES_FUNC_COLOR_PARAM_2(drawPolygon,const std::vector<double> &,x, const std::vector<double> &,y)
344344

345345
/// Draw a text <text> at position <cx, cy>
346-
VIBES_FUNC_COLOR_PARAM_3(drawText, const double&, top_left_x, const double&, top_left_y,
347-
const std::string&, text)
346+
VIBES_FUNC_COLOR_PARAM_3(drawText, const double&, top_left_x, const double&, top_left_y,
347+
const std::string&, text)
348348

349349
/// Draw a text <text> at position <cx, cy> and with scale <scale>
350-
VIBES_FUNC_COLOR_PARAM_4(drawText, const double&, top_left_x, const double&, top_left_y,
351-
const std::string&, text, const double&, scale)
350+
VIBES_FUNC_COLOR_PARAM_4(drawText, const double&, top_left_x, const double&, top_left_y,
351+
const std::string&, text, const double&, scale)
352352

353353
/// Draw a 2-D vehicle at position (cx,cy)
354354
VIBES_FUNC_COLOR_PARAM_4(drawVehicle,const double &,cx, const double &,cy, const double &,rot, const double &,length)
@@ -381,11 +381,14 @@ namespace vibes {
381381
const double &,r_min, const double &,r_max)
382382

383383
/// Draw a raster image with upper left corner at position <ulb, yub>
384-
/// and with <width, height> size.
384+
/// and with <width, height> size. Possibly with a rotation <rot> in degrees.
385385
/// The color used for transparency is throw the pen color
386386
VIBES_FUNC_COLOR_PARAM_5(drawRaster, const std::string&, rasterFilename,
387387
const double &,ulb, const double &, yub,
388388
const double &,width, const double &, height);
389+
VIBES_FUNC_COLOR_PARAM_6(drawRaster, const std::string&, rasterFilename,
390+
const double &,ulb, const double &, yub,
391+
const double &,width, const double &, height, const double &, rot);
389392

390393
/// @}
391394
/// @name Objects grouping and deletion
@@ -523,15 +526,15 @@ namespace vibes {
523526
inline void drawBoxes(const std::vector<ibex::IntervalVector> &boxes, Params params){
524527
std::vector<std::vector<double> > bounds;
525528
for(unsigned int i=0;i<boxes.size();i++)
526-
{
527-
std::vector<double> boundsI;
528-
boundsI.push_back(boxes[i][0].lb());
529-
boundsI.push_back(boxes[i][0].ub());
530-
boundsI.push_back(boxes[i][1].lb());
531-
boundsI.push_back(boxes[i][1].ub());
532-
bounds.push_back(boundsI);
533-
}
534-
vibes::drawBoxes(bounds, params);
529+
{
530+
std::vector<double> boundsI;
531+
boundsI.push_back(boxes[i][0].lb());
532+
boundsI.push_back(boxes[i][0].ub());
533+
boundsI.push_back(boxes[i][1].lb());
534+
boundsI.push_back(boxes[i][1].ub());
535+
bounds.push_back(boundsI);
536+
}
537+
vibes::drawBoxes(bounds, params);
535538
}
536539
#endif //#ifdef __IBEX_INTERVAL_VECTOR_H__
537540
}

client-api/python/vibes/vibes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,23 @@ def drawText(cls, cx, cy, text, scale, color='r', **kwargs):
539539
cls._write(msg, **kwargs)
540540

541541
@classmethod
542-
def drawRaster(cls, filename, xlb, yub, width, height, **kwargs):
542+
def drawRaster(cls, filename, xlb, yub, width, height, rot=0, **kwargs):
543543
"""Draw raster from <filename> on the screen with upper left corner at <xlb, yub>
544544
with pixels size of <xres, yres>.
545545
546546
Args:
547547
filename (string): image filename of the input data
548548
xlb, yub (double): coordinate of the upper left pixel
549-
xres, yres (double): x and y pixel resolution
549+
width, height (double): raster projected size
550+
rot (double): optional rotation of the raster in degrees
550551
color (optional, string): color to used for transparency
551552
"""
552553
msg = {'action': 'draw',
553554
'shape': {'type': 'raster',
554555
'filename' : filename,
555556
'ul_corner': [xlb, yub],
556557
'size' : [width, height],
558+
'rot' : rot
557559
}
558560
}
559561
if "color" in kwargs:

viewer/vibesgraphicsitem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,10 @@ bool VibesGraphicsRaster::computeProjection(int dimX, int dimY)
19801980
double xlb = ul_corner[0].toDouble();
19811981
double yub = ul_corner[1].toDouble();
19821982

1983+
double rot = 0.;
1984+
if (json.contains("rot"))
1985+
rot = json["rot"].toDouble();
1986+
19831987
QImage image(filename);
19841988
QPixmap pixmap = QPixmap::fromImage(image);
19851989

@@ -1997,6 +2001,8 @@ bool VibesGraphicsRaster::computeProjection(int dimX, int dimY)
19972001

19982002
pixmap_item->setShapeMode(QGraphicsPixmapItem::MaskShape);
19992003
pixmap_item->setTransform(transform);
2004+
pixmap_item->setTransformOriginPoint(0,0);
2005+
pixmap_item->setRotation(rot);
20002006

20012007
this->addToGroup(pixmap_item);
20022008
}

0 commit comments

Comments
 (0)