proportional ImagePlane

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
kisolre
Veteran
Posts: 4166
Joined: Wed Nov 21, 2018 1:13 pm

proportional ImagePlane

Post by kisolre »

Not sure if this is the correct place but here I go:

Some time ago I reported the following issue #3959. Since I have not done any coding soon I decided to leave it at that but today I found some drawings that I thought recreating and remembered about that problem. And decided to look into the code and find how it was done.
Creating ImagePlane is done in https://github.com/FreeCAD/FreeCAD/blob ... ommand.cpp and sizing is done in lines 141-149

Code: Select all

        std::string FeatName = getUniqueObjectName("ImagePlane");
        double xPixelsPerM = impQ.dotsPerMeterX();
        double width = impQ.width();
        width = width * 1000 / xPixelsPerM;
        int nWidth = static_cast<int>(width+0.5);
        double yPixelsPerM = impQ.dotsPerMeterY();
        double height = impQ.height();
        height = height * 1000 / yPixelsPerM;
        int nHeight = static_cast<int>(height+0.5);
This assumes that image will be a scan of a drawing with proper dpi settings and sets the ImagePlane size to realworld size. No problem here. But then with nWidth and nHeight it effectively rounds the size to whole mm and this breaks the original proportions of the image. It looks like it was implemented just to make the sizes prettier - 268 X 345 instead of 268,2345678 X 344,97543334567
For scans this could be neglected but I am pretty sure that 90% of the time images used as ImagePlane are either cropped photos or something downloaded from some site where only displaying on screen is important.
So my proposal is to change the last line to:

Code: Select all

        double nHeight = nWidth * height / width
This will still take into account image dpi, keep the xSize pretty but the imagePlane will be proportional to the image.
Post Reply