Graph Layout Algorithms for JGraphT - jgrapht

I'm using JGraphT to create a graph and I want to be able to visualise and manipulate it. There are some examples that show how to visualise the graph, but it seems that it involves quite a lot of manual code to layout the vertices, etc.
I was wondering if there was any graph layout algorithm that could automate this process already in JGraph with a small example. Mostly the graphs I'm drawing are Directed Acyclic Graphs.
I have already drawn the graphs by exporting them to .dot format and display it using dot, but I need a little interaction now.

Since JGraph seems to now be mxGraph, but JGraphT embed JGraph 5.13, it's not that easy but I've found this doc
and the following piece of code is working:
// this a a JGraphT graph
ListenableDirectedGraph<TableColumn, DefaultEdge> dependencyGraph = getDependencyGraph();
JGraphModelAdapter adapter = new JGraphModelAdapter(dependencyGraph);
JGraph jgraph = new JGraph(adapter);
JGraphLayout layout = new JGraphHierarchicalLayout(); // or whatever layouting algorithm
JGraphFacade facade = new JGraphFacade(jgraph);
layout.run(facade);
Map nested = facade.createNestedMap(false, false);
jgraph.getGraphLayoutCache().edit(nested);
JScrollPane sp = new JScrollPane(jgraph);
this.add(sp);

Related

Get Array from Nifti File using PyVista

im new to programming and im working with a MRI dataset (.nii) in PyVista
Im trying read the Nifti File and extract an array so i can compare two MRIs based on the differences in the array and visualise it with PyVista.
PyVista is mostly based on the VTK library so maybe there is a function in VTK but im a bit helpless looking through the Docs.
I found a solution in nibabel to access an array:
img = nib.load(example_filename)
a = np.array(img.dataobj)
But with that i still can't access the PyVista Array to highlight the differences.
Thank you for your help in advance!
We need to perform two distinct operations:
retrieving the intensity values from your NIfTI dataset using, for instance, nibabel
plotting the 3D numpy array using, for instance, PyVista. Take a look at the PyVista documentation here and here for further details. You will have to add origin, spacing, etc. but for the sake of simplicity I am going to omit them.
Here is the code:
import nibabel as nb
example = nb.load("/nifti/path/example.nii.gz")
intensities = example.get_fdata()
grid = pv.UniformGrid()
grid.dimensions = np.array(values.shape) + 1
grid.cell_data["intensities"] = intensities.flatten(order="F")
grid.plot(volume=True, cmap="bone")

What is the purpose of `BRepLib::BuildCurves3d` calls in the OpenCASCADE tutorial?

As an OpenCASCADE newbie, I am reading the OpenCASCADE tutorial:
https://www.opencascade.com/doc/occt-7.4.0/overview/html/occt__tutorial.html
There are following two curious calls:
BRepLib::BuildCurves3d(threadingWire1);
BRepLib::BuildCurves3d(threadingWire2);
The tutorial explains the need for these two calls in this way:
Remember that these wires were built out of a surface and 2D curves. One important data item is missing as far as these wires are concerned: there is no information on the 3D curves. Fortunately, you do not need to compute this yourself, which can be a difficult task since the mathematics can be quite complex. When a shape contains all the necessary information except 3D curves, Open CASCADE Technology provides a tool to build them automatically. In the BRepLib tool package, you can use the BuildCurves3d method to compute 3D curves for all the edges of a shape.
which I did not find entirely clear.
Imagine that I have constructed some TopoDS_Shape object.
How can I, in general, figure out whether BRepLib::BuildCurves3d call is necessary or not?
With this code you can get the 3D curve of an edge (take from BRepExtrema_DistanceSS.cxx):
Standard_Real aFirst, aLast;
Handle(Geom_Curve) pCurv = BRep_Tool::Curve(E, aFirst, aLast);
If you have not created the 3D curves, pCurv will be a null handle. Using it will result in segmentation faults.
I have been excited about where the 3D curves are actually used. Therefore I have tried several algorithms. These are the algorithms I have tried where the 3D curves are not used:
Visualizing
Export to BREP
Export to STEP
Length Measurement
Checking Whether a Wire Is Closed or Ordered
The only algorithm I have found where the 3D curves are used are extrema/distance computations with BRepExtrema_DistShapeShape. You will not be able to use this class if you have not created the 3D curves.

How to use R-Tree of NetTopologySuite in GMap.NET to display abundant marker WPF

I am using GMap.NET to display a lot of Marker (about more than 10.000 markers). R-Tree is a solution to optimize render markers at area which window is showing.
STRtree in NetTopologySuite is a library to support R-tree. But I'm not sure it suitable for this problem.
My question is how to use R-Tree in NetTopologySuite to show markers. I don't know how to use library. (I'm new in WPF). How to catch event when GMap render marker to get marker from R-Tree and remove previous marker at same time?
Please give me some example about R-tree in NetTopologySuite.
I did it by my way. This is the way STRtree is decleared: STRtree<Coordinate> gpsSTRtree = new STRtree<Coordinate>(); You can change Coordinate data type by any other data type but STRtree need to Envelope to insert to tree.
For example: insert to STRtree:
Coordinate gps = new Coordinate(9.74233, 106.0213);
Envelope item = new Envelope(gps);
gpsSTRtree.Insert(item, gps);
Envelope is a node in STRtree to store the boundary of item.
STRtree query from two points. point1 and point2 are Coordinate
Envelope gpsQuery = new Envelope(p1, p2);
Coordinate gpsItems = gpsSTRtree.Query(gpsQuery);
Then you have a list of Coordinate
Good luck

GAS API implementation and usage

I'm trying to learn and use the GAS API to implement a Random Walk over my database, associating every visited vertex to the starting vertex.
I'm having some issues understanding how I can manage to do this; I've been reviewing the PATHS, BFS, PR, and other GAS classes as examples, but I'm not quite sure how to start.
I think my implementation should extend BaseGASProgram and implement the needed methods. Also, as iterative, the frontier contains all the vertexes of the current iteration. The concept of predecessor is also clear to me.
But I don't think that I understand very well the Gather, Apply, Scatter philosophy and how to distribute the Random Walk over these three concepts.
Also, once I implement my code, how do I call it? How do I even call the already implemented algorithms (PR, SSSP, BFS, etc.) inside my code? Should I instantiate an SSSP object and then what? Or GASContext? GASRunnerBase?
Take a look at the TestBFS class in the bigdata-gas package:
final IGASEngine gasEngine = getGraphFixture()
.newGASEngine(1/* nthreads */);
try {
final SailConnection cxn = getGraphFixture().getSail()
.getConnection();
try {
final IGraphAccessor graphAccessor = getGraphFixture()
.newGraphAccessor(cxn);
final IGASContext<BFS.VS, BFS.ES, Void> gasContext = gasEngine
.newGASContext(graphAccessor, new BFS());
final IGASState<BFS.VS, BFS.ES, Void> gasState = gasContext
.getGASState();
// Initialize the froniter.
gasState.setFrontier(gasContext, p.getMike());
// Converge.
gasContext.call();
[snip]
To use it outside of the test case context, you need to create a SailConnection of some sort. See the blazegraph-samples GitHub project for examples. Then you need to create a SAILGASEngine. This should get you started in terms of calling the GASEngine directly at the Java layer.

WPF Tree Diagram Library?

Is there any reliable and free WPF library to create simple tree diagrams dynamically? I mean, all I want is something that would allow me to do that kind of pseudo-code:
Item item1 = new Item("Level 1");
Item item11 = new Item("Level 1.1");
Item item12 = new Item("Level 1.2");
Item item111 = new Item("Level 1.1.1");
item11.AddChild(item111);
item1.AddChild(item11);
item1.AddChild(item12);
And then to generate automatically the correspoding diagram:
Thank you.
I found this diagram solution and tinkered a bit in order to adapt it to my needs.
I'm kinda surprised there's no library to do so. Still looking for it :)
I've found this one pretty easy to use:
https://www.codeproject.com/Articles/29518/A-Graph-Tree-Drawing-Control-for-WPF
You can find an example how to use it in the downloaded zip file here:
SilverTreeContainer.zip\TreeContainer\TreeContainerTest\winTreeContainerTest.xaml
Later, I also found this article interesting:
How to easily draw graphs in WPF?
This is for Graph drawing in general, not specialized for Trees; but I've found the above link here as well (top rated answer, option 6)

Resources