OpenModelicaText getting commented when adding Bitmaps in Icon/Diagram View - openmodelica

I've noticed that the OM Script gets commented when I add a bitmap in either the Icon/Diagram View.
I'm using OpenModelica 1.9.1+dev (r18667) (RML version)
Code for reference
model Test
annotation(Diagram(coordinateSystem(extent = {{-100,-100},{100,100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2,2}), graphics = {Bitmap(origin = {0.12,-0.47}, extent = {{-99.77,99.65000000000001},{99.77,-99.65000000000001}}, fileName = "modelica://Test/C:/Users/MSK/Desktop/Capture.PNG")}));
end Test;
This may be a bug. Hence I've reported it

OpenModelica bug reports should be reported at: https://trac.openmodelica.org/OpenModelica/newticket
And yes, it is a bug so it does not really belong on stackoverflow.

Related

Manim / Cairo : color discrepancies

I have some discrepancies in terms of brightness, saturation and hue when using a jpg picture in Manim.
I have a picture which color profile/space is Adobe RGB. I create it, edit it and save it that way. All of my apps previewing the picture are more, or less consistent with the original (enough to be acceptable). Including a movie export test from After effects. Even the image previewer of VS Code shows the image correctly. But when I render it with Manim, it's no good. Way too bright, oversaturated with a slight shift in hue and as if it was downgraded in terms of quality (some subtle but weird color artifacts are showing). You can tell something is off.
Granted, the picture I try to use is an abstract background with subtle gradients of color and light but still. The overall difference and loss in quality are sufficiently there not to be acceptable.
I know that managing color spaces and profiles is a bit tricky and is an art in and on itself but the problem here is that the image is consistent everywhere so far but in Manim's rendered MP4 file.
The only thing I've seen in the doc related to color spaces is this parameter "image_mode". I tried to set it both to RGB and RGBA (only two options available) in the Manim script but it doesn't change anything.
I suspect it's a feature that is more related to the renderer (Cairo) or the MP4 export parameters than Manim itself or maybe it downgrades jpg to gif/png before it renders the picture in Mp4 ? I don't know and I don't know what to do with that anyway since I don't know how to parameter any of this within Manim itself. I can't see any parameters that allow to edit any of this in the doc.
Maybe a plugin could add some functionalities or something ?
Any help would be appreciated.
PS: the picture is 4k and I render it in 4k in Manim, so it should be a pixel to pixel match.
Here is my Manim script:
from manim import *
class Graph(Scene):
def construct(self):
bg = ImageMobject("media/background/13.jpg")
self.add(bg)
self.wait()
And here are the relevant parts of my manim.cfg
[CLI]
write_to_movie = True
format = mp4
save_last_frame = False
write_all = False
save_pngs = False
save_as_gif = False
preview = False
background_color = #212021
background_opacity = 1
renderer = cairo
use_webgl_renderer = False
webgl_renderer_path =
use_opengl_renderer = False
enable_gui = False
gui_location = 0,0
fullscreen = False
window_size = default
window_monitor = 0
force_window = False
use_projection_fill_shaders = False
use_projection_stroke_shaders = False
movie_file_extension = .mp4
frame_rate = 60
frame_size = 3664,1980
pixel_height = 1980
pixel_width = 3664
max_files_cached = 100
flush_cache = True
disable_caching = True
disable_caching_warning = False
enable_wireframe = False
dry_run = False
tex_template =
plugins =
TL;DR: Some random pointers, but no answer to the question.
I have no clue about manim, so I just went searching for "JPEG" in its source code. That brought me to https://github.com/3b1b/manim/blob/3c7a38660af41478e1561073a5319b23fb6b7787/docs/source/documentation/custom_config.rst#L59 which says
The directory for storing raster images to be used in the code (including .jpg, .jpeg, .png and .gif), which will be read by ImageMobject.
Okay, what's ImageMobject? Another search found the place where it loads images and apparently this just uses the Python library PIL to call PIL.Image.open: https://github.com/3b1b/manim/blob/669182944da040c227ccfd018250ee2bbc49649d/manimlib/mobject/types/image_mobject.py#L31
Okay, so does this support color profiles? I don't know. What does this question even mean? You are loading some color image that contains a color profile and it ends up being part of a movie... Should the movie now use that color profile?
Another random pointer that I found is PIL/Pillow decode icc profile information but that didn't really help. All I can say is: The manim code that I found doesn't do anything fancy with color profiles.

How do I carry over identical texture mapping when exporting to DAE?

I am able to open a 3DS file in MeshLab and when I export to Collada DAE format the textures are visible but they are not being projected onto the mesh in the same way as the preview in MeshLab. For example, the front/back faces of a cube would have the proper texture (suppose it's a polka dot) but the top and bottom have a striped look. How can I apply a single texture and have it appear as intended on all faces, like the imported model before I convert it?
This problem is a result of the end software being used to view the DAE file. It's not a problem with MeshLab.
For example, if loading the file into Away3D be sure to handle the texture materials using the TextureMaterial class instead of the simpler SinglePassMaterialBase such as what you might find in their example code. Here is what I use now, and it displays texture properly:
var material:TextureMaterial = cast(asset, TextureMaterial);
material.ambientColor = 0xffffff;
material.lightPicker = _lightPicker;
material.shadowMethod = new FilteredShadowMapMethod(_light);
material.lightPicker = _lightPicker;
material.gloss = 30;
material.specular = 1;
material.ambient = 1;
material.repeat = true;

Mapnik 2.2 disappearing markers (MarkerSymbolizer)

I'm using Mapnik v2.2.0 from Python 2.7 in an Ubuntu 16.04 environment. The application generates maps with a set of MarkerSymbolizers at various coordinates. In one map, when the MarkerSymbolizers are set to 25x25 pixels, one of the markers does not appear. If the marker size is set to 15x15, all of the markers appear.
The markers are loaded from a csv file:
layer = mapnik.Layer('GPS_tracking_points')
layer.datasource = mapnik.CSV(file=leak_file_name, layer_by_index=0)
The styling is below:
point_style = mapnik.Style()
point_rule = mapnik.Rule()
point_filter = mapnik.Filter ("[val] > 10")
point_rule.filter = point_filter
point_point_symbolizer = mapnik.MarkersSymbolizer()
point_point_symbolizer.width = mapnik.Expression ('25')
point_point_symbolizer.height = mapnik.Expression ('25')
point_point_symbolizer.fill = mapnik.Color ('#ff0000')
point_point_symbolizer.allow_overlap = True
point_point_symbolizer.opacity = 0.5 # semi-transparent
point_rule.symbols.append(point_point_symbolizer)
point_style.rules.append(point_rule)
map_canvas.append_style('high', point_style)
Screenshots are below.
Any help is appreciated.
Thanks.
The problem appears to be related to the way Mapnik 2.2 handles styling in code vs xml. I moved the styling specification to an xml file and everything works as expected.
The answer was found here: https://github.com/mapnik/python-mapnik/issues/117

F# Winforms Charting Asynchronous Updating

I'm trying to create a chart in winforms that databinds to a list in memory, and gets updated dynamically as the list changes. Here is my code:
open System
open System.Linq
open System.Collections
open System.Collections.Generic
open System.Drawing
open System.Windows.Forms
open System.Windows.Forms.DataVisualization
open System.Windows.Forms.DataVisualization.Charting
let link = new LinkedList<double>()
let rnd = new System.Random()
for i in 1 .. 10 do link.AddFirst(rnd.NextDouble()) |> ignore
let series = new Series()
let chart = new System.Windows.Forms.DataVisualization.Charting.Chart(Dock = DockStyle.Fill, Palette = ChartColorPalette.Pastel)
series.Points.DataBindY(link)
let form = new Form(Visible = true, Width = 700, Height = 500)
form.Controls.Add(chart)
let formloop = async {
while not chart.IsDisposed do
link.AddFirst((new System.Random()).NextDouble()) |> ignore
link.RemoveLast()
}
do
Async.StartImmediate(formloop)
Application.Run(form)
Console.WriteLine("Done")
Console.ReadLine() |> ignore
The async seems to work, but the chart never shows anything. It just shows a blank window. What am I doing wrong?
LinkedList<T> has no way to signal that it's been updated, so Chart has no way of knowing when to redraw itself.
In order for databinding to update the view, the source list must implement IBindingList and raise appropriate event when the contents change.
Separately, I must point out that it's dangerous to directly access UI properties/methods from non-UI threads (such as chart.IsDisposed in your code). In WinForms, this limitation is rarely actually enforced, so sometimes this might seem to work fine, only to crash later on a customer's machine with no way to attach a debugger.
You need to add the series to the SeriesCollection of the chart.
chart.Series.Add series
You need to construct a chart area and add it to the ChartAreaCollection of the chart.
let area = new ChartArea()
chart.ChartAreas.Add area
You need to make sure that the data binding method is called after the chart and form are set up.
...
form.Controls.Add chart
series.Points.DataBindY link
And now there's no way to communicate changes of your bound collection to the DataPointCollection of the series, as mentioned in Fyodor Soikin's answer. I'm not quite sure that IBindingList is an appropriate response;
while it's possible to hook into the ListChanged event, we could as well manipulate the series' DataPointCollection directly.
let formloop = async{
while not chart.IsDisposed do
series.Points.RemoveAt 0
series.Points.AddY(rnd.NextDouble()) |> ignore
do! Async.Sleep 100 }
Finally I'd like to point out this contribution by John Atwood which adresses both points raised by Fyodor; the data binding issue (by not using it) and the UI-thread safety issue.

o3d textures and transparency

I'm working at galery on o3d(plagin version) and I need make photos transparent. Photos are on hud. Here is some code:
g_canvasInfoPict = o3djs.canvas.create(g_pack, g_hudRoot, g_hudViewInfo);
alphaParam = g_canvasInfoPict.transparentState_.getStateParam("o3d.AlphaReference");
alphaParam.value = 0.5;
alphaParam = g_canvasInfoPict.transparentState_.getStateParam("o3d.BlendAlphaEquation");
alphaParam.value = g_o3d.State.BLEND_SUBTRACT;
alphaParam = g_canvasInfoPict.transparentState_.getStateParam("o3d.SourceBlendFunction");
alphaParam.value = g_o3d.State.BLENDFUNC_ONE;
paramOne = g_canvasInfoPict.transparentState_.getStateParam("o3d.DestinationBlendFunction");
paramOne.value = g_o3d.State.BLENDFUNC_DESTINATION_ALPHA;//or BLENDFUNC_SOURCE_ALPHA or BLENDFUNC_SOURCE_ALPHA_SATUTRATE or BLENDFUNC_ONE or BLENDFUNC_ZERO
g_fullPictCanvas = g_canvasInfoPict.createXYQuad(paddingX, paddingY, -14, g_fullPictTexture.width, g_fullPictTexture.height, true);
g_fullPictCanvas.canvas.drawBitmap(g_fullPictTexture, 0, g_fullPictTexture.height);
g_fullPictCanvas.updateTexture();
But it doesn't work. When setting paramOne.value = BLENDFUNC_ZERO photo displays (non-transparent)
paramOne.value = BLENDFUNC_ONE photo isn't displayed (full transparent)
So how to achive intermediate result?
Given that the O3D plug-in is deprecated in favor of the WebGL-based O3D, is it an option for you to migrate to the latter?
If so, you can inquire in the discussion group about the transparency issue (if it still exists under O3D-WebGL). The developers are very responsive.

Resources