I have following graph
Vertex v1 = g.addVertex(null);
Vertex v2 = g.addVertex(null);
Vertex v3 = g.addVertex(null);
v1.addEdge("v1v2", v2);
v2.addEdge("v2v3", v3);
If I remove v2 vertex, v1v2 v2v3 edge is deleted but v1 v3 vertex remain in graph. Will I have to remove v1 and v3 manually?
If I add another vertex:
Vertex v4 = g.addVertex(null);
v3.addEdge("v3v4", v4);
Vertex v5 = g.addVertex(null);
v5.addEdge("v5v3", v3);
Now If I will delete v1 all vertices should be deleted. How to do that? Does titan provide something for this?
Titan doesn't provide anything that can detect orphaned vertices. You will have to write your own approach to doing so. I suppose you have at least two ways to deal with them.
If there's no harm in just leaving them there based on your
schema/application, then let them remain orphaned. Then batch
remove them with Faunus or some other script.
Make removal of a v2 in your first example, part of a transaction
that does some quick edge checks on v1 and v3. If neither of
those have edges then remove those vertices as well.
Related
I'm new to Graphx and doing some research, where I have to map the property graph model to hadoop. I have successfully created the graph by creating Vertex and edge RDD.Now I want to edit my graph by adding vertex at position X and the add a edge at position X-1 and X+1.
I have read multiple documents which says graphs are immutable, but there is an option of subgraph but according to me it is used only to eliminate certain vertex and edges.
Can some one guide me is there any way to edit the graphs ?
Given a mesh in Unity & C# (that itself was created in realtime by merging simpler base meshes), how could we during runtime* turn it into a smooth, almost like wrapped-in-cloth mesh version of itself? Not quite a fully convex version, but more rounded, softening sharp edges, bridging deep gaps and so on. The surface would also ideally look like when the "smoothing angle" normals setting is applied to imported objects. Thanks!
Before & after sketch
*The mesh setup is made by people and its specifics unknown beforehand. All its basic shape parts (before we merge them) are known though. The base parts may also remain unmerged if that helps a solution, and it would be extra terrific if there was a runtime solution that would fastly apply the wrapper mash even with base parts that change their transform over time, but a static one-time conversion would be great too.
(Some related keywords may be: marching cube algorithm & metaballs, skin above bones, meshfilter converting, smoothing shader, softening, vertices subdivision.)
There are many ways to get something similar so you can pick your preferred one:
Marching Cubes
This algorithm is easy to use but the result always inherits the blocky 'style' of it. If that's the look you want then use it. If you need something more smooth and/or pixel perfect then look for other ways.
Ray Marching and Signed Distance Functions
This is quite interesting technique that may give you a lot of control. You can represent your base parts with simple cube/cylinder/etc. equations and blend them together with simple math.
Here you can see some examples:
http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
The best thing here is that it's very simple to setup, you don't even need to merge your base parts, you just push your data to renderer. Worse, is that it may get computationaly hard on rendering part.
Old school mesh modifications
Here you have the most options but it's also most complicated. You start with your base parts which don't have much data by themselves so you should probably join them into one mesh using CSG Union operation.
Having this mesh you can compute neighbors data for your primitives:
for each vertex find triangles containing it.
for each vertex find edges containing it.
for each edge find triangles containing it.
etc.
With such data you may be able to do things like:
Find and cut some sharp vertex.
Find and cut some sharp edge.
Move the vertex to minimize angle between triangles/edges it creates.
and so on...
There are really a lot of details that may work for you or not, you just need to test some to see which one gives the preferred results
.
One simple thing I'd start with:
For each vertex find all vertices connected to it by any edge.
Compute average position of all those vertices.
Use some alpha parameter in [0,1] range to blend between initial vertex position and averaged one.
Implement multiple iterations of this algorithm and add parameter for it.
Experiment with alpha and number of iterations.
Using this way you also have two distinct phases: computation and rendering, so doing it with animation may become too slow, but just rendering the mesh will be faster than in Ray Marching approach.
Hope this helps.
EDIT:
Unfortunately I've never had such need so I don't have any sample code but here you have some pseudo-code that may help you:
You have your mesh:
Mesh mesh;
Array of vertex neighbors:
For any vertex index N, triNeighbors[N] will store indices of other vertices connected by edge
List<HashSet<int>> triNeighbors = new List<HashSet<int>>();
int[] meshTriangles = mesh.triangles;
// iterate vert indices per triangle and store neighbors
for( int i = 0; i < meshTriangles.Length; i += 3 ) {
// three indices making a triangle
int v0 = meshTriangles[i];
int v1 = meshTriangles[i+1];
int v2 = meshTriangles[i+2];
int maxV = Mathf.Max( Mathf.Max( v0, v1 ), v2 );
while( triNeighbors.Count <= maxV )
triNeighbors.Add( new HashSet<int>() );
triNeighbors[v0].Add( v1 );
triNeighbors[v0].Add( v2 );
triNeighbors[v1].Add( v0 );
triNeighbors[v1].Add( v2 );
triNeighbors[v2].Add( v0 );
triNeighbors[v2].Add( v1 );
}
Now, for any single vertex, with index N you can compute its new, averaged position like:
int counter = 0;
int N = 0;
Vector3 sum = Vector3.zero;
if( triNeighbors.Count > N && triNeighbors[N] != null )
{
foreach( int V in triNeighbors[N] ) {
sum += mesh.vertices[ V ];
counter++;
}
sum /= counter;
}
There may be some bugs in this code, I've just made it up but you should get the point.
I am a newbie in OrientDB. Currently I want to create the undirect Edge between 2 Vertexes, it looks like: Product A relates to Product B.
I am using Java API, blueprint.
Thank you.
aVertex.addEdge(endVertex, "label")
graph.addEdge(id, outVertex, inVertex, "label")
Either way, there are always an out and an in vertex
There is no way to create an undirected edges. In OrientDB, as in most graph databases in the market, edges always have a direction.
It is not a limitation, because you can traverse edges regardless their direction, using both() query operator or, in Java:
vertex.getEdges(Direction.BOTH, label)
Can I do one query to achieve vertex and all of his edges (including the other vertexes)?
now I'm doing multiple queries to achieve it:
For getting the vertex:
select from V where entity_name = 'SomeEntity'
Then going over each edge and select it:
select from #EDGE#rid // Multiple in the number of edges for this node
And at the end going over the edges and getting all other vertexes (except the original)
select from #VERTEX#rid // Multiple in the number of vertexes in the edges
SELECT *,in(),out() FROM V WHERE entity_name = 'SomeEntity'
I used the following to get all Vertexes and Edges in the required depth from my Vertex:
TRAVERSE inE(), outE(), inV(), outV()
FROM (select from V where entity_name = 'SomeEntity')
WHILE $depth <= 2
An observation; the answer by Dor Cohen works if the structure is a tree. However, if it is a cyclical graph, the last edge on the longest path is missed, due to the node visit strategy of not visiting the node which has been visited. The solution that worked for me is as below:
TRAVERSE out(), outE() FROM #22:1 WHILE $depth <= 4
The query traverses all the nodes with are deemed progressively out of the vertex and then the edges which are progressively out from all the vertices.
The output looks like:
The structure of the graph:
On the other hand if the above style of query is used (though I am not looking for in vertex or edge), the output is:
The edge from #22:4 to #23:1 is missed (as a record), as it falls on the longer path. The reference of the missed edge (#28:2) is available on both the above records though.
I'm using Tinkerpop 3.0.1 (Titan 1.0.0), and I try to list all edges for a vertex, sorted by degree of the node on the other end of the edge.
I tried:
g.V(1482896).bothE().order().by(otherV().bothE().count(), decr)
I get the following error from Titan:
The path history of the traverser does not contain a previous vertex: [e[1d2m8u-1d70ts-b2t-vs7k][82628848-DIRECTED->1482896]]
The strange thing is, there is a previous vertex in the path (namely vertex #1482896. I'm confused on how to solve this one.
Answering my own question, after playing around with this, I found a workaround:
g.V(123).bothE().as('edges')
.otherV().order().by(bothE().count(), decr)
.select('edges')
This will effectively sort edges adjacent to vertex #123 by highest degree of the node on the other end of the edge.