Scilab general title on subplot window - scilab

I want to put a title above the four subplots, how can I do that ?
I keep finding info on "suplabel" or "suptitle" for Matlab, but nothing for Scilab.
I tried "title" but i'm not sure of how to use it
Here is my code:
scf(1);
clf(1);
drawlater();
title('Spectre du signal non bruité');
subplot(2,2,1);
plot(f_n,zeros(1,N),'bk',f_n,real(X),'ro',[f_n;f_n],[zeros(1,N);real(X)],'b');
xtitle('Partie réelle','f','Re[X(f)]');
subplot(2,2,2);
plot(f_n,zeros(1,N),'bk',f_n,imag(X),'ro',[f_n;f_n],[zeros(1,N);imag(X)],'b');
xtitle('Partie imaginaire','f','Im[X(f)]');
subplot(2,2,3);
plot(f_n,zeros(1,N),'bk',f_n,abs(X),'ro',[f_n;f_n],[zeros(1,N);abs(X)],'b');
xtitle('Module','f','|X|');
subplot(2,2,4);
plot(f_n,zeros(1,N),'bk',f_n,atan(imag(X)./real(X)),'ro',[f_n;f_n],[zeros(1,N);atan(imag(X)./real(X))],'b');
xtitle('Argument','f','arg[X]');
drawnow();

You could also insert an UIlabel:
x=1:10;
y1=x**2;
y2=x**3;
y3=x**4;
y4=x**5;
f=scf(1);
clf(1);
drawlater();
f.figure_name='Spectre du signal non bruité';
as = f.axes_size;
disp(as)
uicontrol(f, "style", "text", ...
"string", "Spectre du signal non bruité", ...
"position",[as(1)/4 as(2)-17, as(1)/2 20],.. // => #top midle of figure
"fontsize",15);
subplot(2,2,1);
plot(x,y1);
xtitle('Partie réelle','f','Re[X(f)]');
subplot(2,2,2);
plot(x,y2);
xtitle('Partie imaginaire','f','Im[X(f)]');
subplot(2,2,3);
plot(x,y3);
xtitle('Module','f','|X|');
subplot(2,2,4);
plot(x,y4);
xtitle('Argument','f','arg[X]');
drawnow();

Related

How can I merge geometries in A-Frame without losing material information?

I have a large set of block objects using a custom geometry, that I am hoping to merge into a smaller number of larger geometries, as I believe this will reduce rendering costs.
I have been following guidance here: https://aframe.io/docs/1.2.0/introduction/best-practices.html#performance which has led me to the geometry-merger component here:
https://github.com/supermedium/superframe/tree/master/components/geometry-merger/
The A-Frame docs say:
"You can use geometry-merger and then make use a three.js material with vertex colors enabled. three.js geometries keep data such as color, uvs per vertex."
The geometry-merger component also says:
"Useful if using vertex or face coloring as individual geometries' colors can still be manipulated individually since this component keeps a faceIndex and vertexIndex."
However I have a couple of problems.
If I set vertexColors on my material (as suggested by the A-Frame docs), then this ruins the appearance of my blocks.
Whether or not I set vertexColors on my material, all material information seems to be lost when the geometries are merged, and everything just ends up white.
See this glitch for a demonstration of both problems.
https://tundra-mercurial-garden.glitch.me/
My suspicion is that the A-Frame geometry-merger component just won't do what I need here, and I need to implement something myself using the underlying three.js functions.
Is that right, or is there a way that I could make this work using geometry-merger?
For the vertexColors to work, you need to have your vertices coloured :)
More specifically - the BufferGeometry expects an array of rgb values for each vertex - which will be used as color for the material.
In this bit of code:
var geometry = new THREE.BoxGeometry();
var mat = new THREE.MeshStandardMaterial({color: 0xffffff, vertexColors: THREE.FaceColors});
var mesh = new THREE.Mesh(geometry, mat);
The mesh will be be black unless the geometry contains information about the vertex colors:
// create a color attribute in the geometry
geometry.setAttribute('color', new THREE.BufferAttribute(new Float32Array(vertices_count), 3));
// grab the array
const colors = this.geometry.attributes.color.array;
// fill the array with rgb values
const faceColor = new THREE.Color(color_hex);
for (var i = 0; i < vertices_count / 3; i += 3) {
colors[i + 0] = faceColor.r; // lol +0
colors[i + 1] = faceColor.g;
colors[i + 2] = faceColor.b;
}
// tell the geometry to update the color attribute
geometry.attributes.color.needsUpdate = true;
I can't make the buffer-geometry-merger component work for some reason, but It's core seems to be valid:
AFRAME.registerComponent("merger", {
init: function() {
// replace with an event where all child entities are ready
setTimeout(this.mergeChildren.bind(this), 500);
},
mergeChildren: function() {
const geometries = [];
// traverse the child and store all geometries.
this.el.object3D.traverse(node => {
if (node.type === "Mesh") {
const geometry = node.geometry.clone();
geometry.applyMatrix4(node.parent.matrix);
geometries.push(geometry)
// dispose the merged meshes
node.parent.remove(node);
node.geometry.dispose();
node.material.dispose();
}
});
// create a mesh from the "merged" geometry
const mergedGeo = THREE.BufferGeometryUtils.mergeBufferGeometries(geometries);
const mergedMaterial = new THREE.MeshStandardMaterial({color: 0xffffff, roughness: 0.3, vertexColors: THREE.FaceColors});
const mergedMesh = new THREE.Mesh(mergedGeo, mergedMaterial);
this.el.object3D.add(mergedMesh)
}
})
You can check it out in this glitch. There is also an example on using the vertex colors here (source).
I agree it sounds like you need to consider other solutions. Here are two different instances of instancing with A-Frame:
https://github.com/takahirox/aframe-instancing
https://github.com/EX3D/aframe-InstancedMesh
Neither are perfect or even fully finished, but can hopefully get you started as a guide.
Although my original question was about geometry merging, I now believe that Instanced Meshes were a better solution in this case.
Based on this suggestion I implemented this new A-Frame Component:
https://github.com/diarmidmackenzie/instanced-mesh
This glitch shows the scene from the original glitch being rendered with just 19 calls using this component. That compares pretty well with > 200 calls that would have been required if every object were rendered individually.
https://dull-stump-psychology.glitch.me/
A key limitation is that I was not able to use a single mesh for all the different block colors, but had to use one mesh per color (7 meshes total).
InstancedMesh can support different colored elements, but each element must have a single color, whereas the elements in this scene had 2 colors each (black frame + face color).

Conversion from argument 1 of "QWidget *" to "QGroupBox *" not possible

this is my first question and I'm quite struggeling. I'm using Qt for creating a software for excentric viewing. A group of students did this project before, so I got pre-made code to work with.
My problem is the following one:
I am not coding the usual way, I use the QDesigner. I have a Scroll Area where I want to fit some QGroupBoxes inside. There is a general box named "Properties" which holds some other boxes with a vertical layout.
Now one of the boxes is called "symbolgen" and is using a custom class, called "SymbolGen". The class is defined as followed:
class SymbolGen : public QGroupBox
Now what I like to do is to extract alle boxes from the "Properties" box. That means: I want to replace the Group "Properties" by a label "Properties" and underneath with the smaller boxes. Now what Qt says to me is the following:
Fehler: C2664: "SymbolGen::SymbolGen(const SymbolGen &)" : Konvertierung von Argument 1 von "QWidget *" in "QGroupBox *" nicht m”glich
Yes, I am German, in English:
Error: C2664: "SymbolGen::SymbolGen(const SymbolGen &)" : Conversion from argument 1 of "QWidget *" to "QGroupBox *" not possible.
What I see here is, that this specific Group Box "symbolgen" (holds some important variables in the class) needs another group box around. So how can I get this box separated without error?
Thanks for your help!
edit://Line that causes this error:
symbolgen = new SymbolGen(scrollAreaWidgetContents_2);
This one is found at "ui_admin.h".
edit://Definition of "scrollAreaWidgetContents_2" from "ui_admin.h":
scrollAreaWidgetContents_2 = new QWidget();
scrollAreaWidgetContents_2->setObjectName(QStringLiteral("scrollAreaWidgetContents_2"));
scrollAreaWidgetContents_2->setGeometry(QRect(0, 0, 503, 851));
edit://SymbolGen::SymbolGen(const SymbolGen &):
SymbolGen::SymbolGen(QGroupBox *g) : QGroupBox(g)
{
srand (time(NULL));
//Wörterquelle lesen
std::ifstream f("source/ngerman.txt");
std::string l;
if(f.is_open())
{
while(f.good())
{
getline(f,l);
words.push_back(l);
//if( words.size() > 10000 ) break;
}
}
f.close();
//Satzquelle lesen
std::ifstream fs("source/sentences.txt");
//std::string l;
if(fs.is_open())
{
while(fs.good())
{
getline(fs,l);
phrase.push_back(l);
//if( words.size() > 10000 ) break;
}
}
fs.close();
}
It seems g is just the parent widget, that is just passed down to the constructor of QGroupBox, and which should be of type QWidget* instead of QGroupBox*.
You could change that in the declaration, as the QGroupBox constructor expects a QWidget* anyway. There may be a reason this was done this way, so the class may rely on the fact that the parent is a group box. Still, I would try to change it and see what happens.

edge connections overlap and don't space out

I'm trying too see whether I can use the Dot programming language to apply it to an old project of mine.
The task is simple: create a high quality graph with ease.
Unfortunately, while it has been fairly easy to implement the details of my graph, I wound up having to take loads of time just for adjusting the layout.
Furthermore, it is quite unclear to me how the order of my instructions impact my graph, but it actually looks like putting the last instruction of my code at the beginning produces a completely different output!
Here is the code:
digraph {
TOP [shape=doublecircle]
TOP->TOP->{rank=same a->b->c->b->a}
a:s->c:s
a:nw->a:sw
c:ne->c:se
b:s->b:s
}
so. firstly, i finally mastered the 'get nodes to be on the same horizontal/vertical line' through ranking...
I also kinda fixed the problem of edges doing stupid interconnections (all free space below the graph for connections, and the edge winds up zig-zagging through the whole graph in an awkward way and overlapping everything?) using the direction indicators ":e" and the such (i believe they are called routes...), but it looks like graphviz isn't using them in a smart way, because the result looks funny to me.
Here is the output, how do I get it to avoid edge overlappings and make enough space for future (long) labels?
(made with dot -Tpng test.dot -o test.png)
(also, I would need to add a c->a edge at the bottom too, but adding one the "normal" way ruined everything)
You can use invisible nodes to "re-route" your edges as desired (edited as per comments below):
digraph
{
/* layout */
// node width to create space for longer labels
node [ width = 1.75 ];
{ rank=same; a; b; c }
/* nodes */
t [ label = "TOP", shape = doublecircle, width = 1];
a [ label = "short" ];
b [ label = "medium" ];
c [ label = "rather l o n g"]
// invisible nodes to 're-route' the edges
x [ style = invis, shape = point, width = 0 ];
y [ style = invis, shape = point, width = 0 ];
/* edges */
t -> t;
t -> { a b c }
t -> { a b c } [dir = back ]; // added for reverse arrows
a -> b -> c -> b -> a;
a:nw -> a:sw;
c:ne -> c:se;
b:s -> b:s;
// put the invisible nodes at the desired places with invisible edges
b -> x -> y [ style = invis ];
// edges to invisible nodes must not have heads
c:sw -> x [ arrowhead = "none" ];
x -> a:se;
a:s -> y [ arrowhead = "none" ];
y -> c:s;
}
yields

Show name of song on Qlabel

I am new to Qt and I'm trying is to create a media player with library phonon. I'm doing in here: http://doc.qt.io/qt-4.8/qt-phonon-qmusicplayer-example.html. I do not know how to present the songs on Qlabel name.
How to give name of song to on label.
In Function:
metaStateChanged(Phonon::State newState, Phonon::State /* oldState */)
Set the text of your label:
QString title = metaData.value("TITLE");
if (title == "")
title = metaInformationResolver->currentSource().fileName();
myLabel->setText(title);
And try reading the fantastic documentation that qt offers beside the examples: http://doc.qt.io/qt-4.8/index.html

How can I update the label of a Polygon Vector in OpenLayers after it has been drawn?

I am quite new to OpenLayers. Right now, I have a polygon vector with some styling applied and a label.
var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']);
style.pointRadius = 15;
style.label = "My Polygon";
style.fillColor = #f00;
style.strokeColor = #000;
var styleMap = new OpenLayers.StyleMap({"default" : style});
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer", {styleMap: styleMap});
At some point after doing some processing, I want to display the result as a label. How can I update the label? I figure it would be something like this, but this wasn't the way.
polygonLayer.options.styleMap.styles.label = "Updated label";
Thanks in advance.
You are on the right way. You can set new label for all features in a layer like that:
polygonLayer.styleMap.styles.default.defaultStyle.label = "new label";
polygonLayer.redraw();
As you see it's important to call redraw() method after you set new value.
That's how you change label for all features in a layer. Quite often though you'll need to set new labels per feature. To achieve that you should do following when you create pollygonLayer:
var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']);
style.label = "${feature_name}";
Each feature has a collection of attributes. In this case value of attribute feature_name will be displayed as a label. To change label value per feature you simply change value of the attribute on that feature and then of course call redraw() on layer.

Resources