Skip to content

Commit

Permalink
Merge pull request #138 from godardma/master
Browse files Browse the repository at this point in the history
changed drawRaster signature from resolution to size
  • Loading branch information
SimonRohou authored Dec 11, 2024
2 parents 6a76524 + 60d6dac commit 72e1d69
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client-api/C++/examples/all_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int main()


vibes::newFigure("test Raster");
vibes::drawRaster(std::filesystem::current_path().string()+"/../VIBes.png", 10, 5, 0.1, 0.1);
vibes::drawRaster(std::filesystem::current_path().string()+"/../VIBes.png", 10, 5, 10.,5.);

std::cout << "end drawing" << std::endl;

Expand Down
7 changes: 4 additions & 3 deletions client-api/C++/src/vibes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// Vibes properties key,value system implementation
//


namespace vibes {
std::string Value::toJSONString() const {
std::ostringstream ss;
Expand Down Expand Up @@ -700,19 +701,19 @@ namespace vibes
fflush(channel.get());
}

void drawRaster(const std::string& rasterFilename, const double &xlb, const double &yub, const double &xres, const double &yres, Params params)
void drawRaster(const std::string& rasterFilename, const double &xlb, const double &yub, const double &width, const double &height, Params params)
{
beginDrawingIfNeeded();
Vec2d ul_corner = { xlb, yub };
Vec2d scale = { xres, yres };
Vec2d size = { width, height };

Params msg;
msg["action"] = "draw";
msg["figure"] = params.pop("figure",current_fig);
msg["shape"] = (params, "type", "raster",
"filename", rasterFilename,
"ul_corner", ul_corner,
"scale", scale
"size", size
);

fputs(Value(msg).toJSONString().append("\n\n").c_str(), channel.get());
Expand Down
6 changes: 3 additions & 3 deletions client-api/C++/src/vibes.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ namespace vibes {
const double &,r_min, const double &,r_max)

/// Draw a raster image with upper left corner at position <ulb, yub>
/// and with <xres, yres> pixel resolution.
/// and with <width, height> size.
/// The color used for transparency is throw the pen color
VIBES_FUNC_COLOR_PARAM_5(drawRaster, const std::string&, rasterFilename,
const double &,ulb, const double &, yub,
const double &,xres, const double &, yres);
const double &,width, const double &, height);

/// @}
/// @name Objects grouping and deletion
Expand Down Expand Up @@ -541,4 +541,4 @@ namespace vibes {
#define vibesDrawCircle(cx,cy,r,...) vibes::drawCircle(cx,cy,r,vibesParams(__VA_ARGS__))
#endif //#ifdef VIBES_GENERATE_vibesXXX_MACROS

#endif //#ifndef VIBES_CPP_API_H
#endif //#ifndef VIBES_CPP_API_H
1 change: 0 additions & 1 deletion client-api/python/vibes/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@
vibes.newFigure("raster")
vibes.drawArrow((0,0), (1,1), 0.1)


vibes.endDrawing()
4 changes: 2 additions & 2 deletions client-api/python/vibes/vibes.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def drawText(cls, cx, cy, text, scale, color='r', **kwargs):
cls._write(msg, **kwargs)

@classmethod
def drawRaster(cls, filename, xlb, yub, xres, yres, **kwargs):
def drawRaster(cls, filename, xlb, yub, width, height, **kwargs):
"""Draw raster from <filename> on the screen with upper left corner at <xlb, yub>
with pixels size of <xres, yres>.
Expand All @@ -553,7 +553,7 @@ def drawRaster(cls, filename, xlb, yub, xres, yres, **kwargs):
'shape': {'type': 'raster',
'filename' : filename,
'ul_corner': [xlb, yub],
'scale' : [xres, yres],
'size' : [width, height],
}
}
if "color" in kwargs:
Expand Down
12 changes: 7 additions & 5 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,10 +1869,10 @@ bool VibesGraphicsRaster::parseJsonGraphics(const QJsonObject& json)
QString type = json["type"].toString();

// VibesGraphicsPie has JSON type "arrow"
if (type == "raster" && json.contains("filename") && json.contains("ul_corner") && json.contains("scale"))
if (type == "raster" && json.contains("filename") && json.contains("ul_corner") && json.contains("size"))
{
if (json["ul_corner"].toArray().size() != 2) return false;
if (json["scale"].toArray().size() != 2) return false;
if (json["size"].toArray().size() != 2) return false;
// Compute dimension
this->_nbDim = 2; //center.size();
// Update successful
Expand All @@ -1899,14 +1899,16 @@ bool VibesGraphicsRaster::computeProjection(int dimX, int dimY)
{
QString filename = json["filename"].toString();
QJsonArray ul_corner = json["ul_corner"].toArray();
QJsonArray scale = json["scale"].toArray();
QJsonArray size = json["size"].toArray();
double xlb = ul_corner[0].toDouble();
double yub = ul_corner[1].toDouble();
double xres = scale[0].toDouble();
double yres = scale[1].toDouble();

QImage image(filename);
QPixmap pixmap = QPixmap::fromImage(image);

double xres = size[0].toDouble()/pixmap.width();
double yres = size[1].toDouble()/pixmap.height();

if (json.contains("EdgeColor")) {
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());
pixmap.setMask(pixmap.createMaskFromColor(pen.color().rgb()));
Expand Down

0 comments on commit 72e1d69

Please sign in to comment.