How to remove edge between two vertices? - titan

I want to remove edge between two vertices, so my code in java tinkerpop3 as below
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
if(g.V(toV).inE(edgeLabel).bothV().hasId(fromV.id()).hasNext()){
List<Edge> edgeList = g.V(toV).inE(edgeLabel).toList();
for (Edge edge:edgeList){
if(edge.outVertex().id().equals(fromV.id())) {
TitanGraph().tx();
edge.remove();
TitanGraph().tx().commit();
return;//Remove edge ok, now return.
}
}
}
}
Is there a simpler way to remove edge between two vertices by a direct query to that edge and remove it? Thank for your help.

Here's an example of how to drop edges between two vertices (where you just have the ids of those vertices:
gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[7][1-knows->2]
==>e[8][1-knows->4]
For purpose of the example, let's say we want to drop edges between vertex 1 and vertex 2. We could find those with:
gremlin> g.V(1).bothE().where(otherV().hasId(2))
==>e[7][1-knows->2]
and then remove it with:
gremlin> g.V(1).bothE().where(otherV().hasId(2)).drop()
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[8][1-knows->4]
If you have the actual vertices, then you could just do:
gremlin> g.V(v1).bothE().where(otherV().is(v2)).drop()
gremlin> g.V(1).bothE()
==>e[9][1-created->3]
==>e[8][1-knows->4]
You could re-write your function as:
private void removeEdgeOfTwoVertices(Vertex fromV, Vertex toV,String edgeLabel,GraphTraversalSource g){
g.V(fromV).bothE().hasLabel(edgeLabel).where(__.otherV().is(toV)).drop().iterate();
g.tx().commit();
}

Related

Blurry Textures when calculating normals

I'm calculating the normals of a mesh that I've generated using the marching cubes algorithm but when I run it the object looks blurry like in the picture.
Variables:
CurrentTri is a Vector3int with the indexes of each vertex
CurrentNorm is a Vector3 with the current normal
Verts is a Vector3 array of the positions of the vertices
VertNorm is a Vector3 array of the normals of the vertices
The c# code where I calculate the normals:
// Repeated for each triangle
CurrentNorm = Vector3.Cross(Verts[CurrentTri.y] - Verts[CurrentTri.x], Verts[CurrentTri.z] - Verts[CurrentTri.x]);
VertNorm[CurrentTri.x] += CurrentNorm;
VertNorm[CurrentTri.y] += CurrentNorm;
VertNorm[CurrentTri.z] += CurrentNorm;
Normalising the normals:
for(int i = 0; i < VertNorm.Length; i++)
{
VertNorm[i] = VertNorm[i].normalized;
}
mesh.normals = VertNorm;
It's supposed to be like that (I think). I was a complete idiot.

Networkx visualization

I am new to netwrokx and I have a big network as follows that I need to just visualize its blue nodes:
Is there any way to see just blue nodes while the distance between them is same as the real graph's?
My desired output would be something like following one:
Result of using pos layout is as follows:
Joel helped med to find out the result and I share codes and outcome here for those who have the similar question:
Answer Codes:
pos = nx.spring_layout(G)
nx.draw_networkx(G, pos, nodelist = blue_nodes, node_color =
'blue',with_labels=False)
outcome:
Given a network G, with a list of "blue" nodes bluenodes, we can define a set of positions, and then draw just the blue nodes.
pos = nx.spring_layout(G) #there are other layouts that you might want to try.
nx.draw_networkx_nodes(G, pos, nodelist = bluenodes, node_color = 'blue', with_labels=False)

Is dropping an edge property expected to drop its edge?

With DSE v5.0.3, I've encountered a situation where dropping an edge property drops its edge as well.
Both of the gremlin console examples use the following schema configuration:
gremlin> system.graph('example').create()
==>null
gremlin> :remote config alias g example.g
==>g=example.g
gremlin> schema.propertyKey('notes').Text().single().create()
==>null
gremlin> schema.vertexLabel('person').create()
==>null
gremlin> schema.edgeLabel('knows').properties('notes').create()
==>null
gremlin> schema.edgeLabel('knows').connection('person', 'person').add()
==>null
In the following example, dropping the edge property results in the edge itself being dropped:
gremlin> person1 = g.addV('person').next()
==>v[{~label=person, community_id=1566048896, member_id=0}]
gremlin> person2 = g.addV('person').next()
==>v[{~label=person, community_id=1062113536, member_id=0}]
gremlin> knows = g.V(person1).addE('knows').to(V(person2)).property('notes', 'online').next()
==>e[{~type=knows, out_vertex={~label=person, community_id=1566048896, member_id=0}, in_vertex={~label=person, community_id=1062113536, member_id=0}, local_id=4cd8f8e2-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1566048896, member_id=0}-knows->{~label=person, community_id=1062113536, member_id=0}]
gremlin> g.E(knows)
==>e[{~type=knows, out_vertex={~label=person, community_id=1566048896, member_id=0}, in_vertex={~label=person, community_id=1062113536, member_id=0}, local_id=4cd8f8e2-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1566048896, member_id=0}-knows->{~label=person, community_id=1062113536, member_id=0}]
gremlin> g.E(knows).properties('notes')
==>p[notes->online]
gremlin> g.E(knows).properties('notes').drop()
gremlin> g.E(knows)
gremlin>
This next example creates the same set of data, but instead of setting the 'notes' property in the same traversal as the addE step, it creates the property in a separate traversal. Unlike in the example above, dropping the 'notes' property drops the property while leaving the edge intact.
gremlin> person1 = g.addV('person').next()
==>v[{~label=person, community_id=1437137920, member_id=0}]
gremlin> person2 = g.addV('person').next()
==>v[{~label=person, community_id=1317720192, member_id=0}]
gremlin> knows = g.V(person1).addE('knows').to(V(person2)).next()
==>e[{~type=knows, out_vertex={~label=person, community_id=1437137920, member_id=0}, in_vertex={~label=person, community_id=1317720192, member_id=0}, local_id=847ebaf0-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1437137920, member_id=0}-knows->{~label=person, community_id=1317720192, member_id=0}]
gremlin> g.E(knows).property('notes', 'online')
==>e[{~type=knows, out_vertex={~label=person, community_id=1437137920, member_id=0}, in_vertex={~label=person, community_id=1317720192, member_id=0}, local_id=847ebaf0-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1437137920, member_id=0}-knows->{~label=person, community_id=1317720192, member_id=0}]
gremlin> g.E(knows).properties()
==>p[notes->online]
gremlin> g.E(knows).properties('notes').drop()
gremlin> g.E(knows)
==>e[{~type=knows, out_vertex={~label=person, community_id=1437137920, member_id=0}, in_vertex={~label=person, community_id=1317720192, member_id=0}, local_id=847ebaf0-a6b8-11e6-aa90-df2b21a156a2}][{~label=person, community_id=1437137920, member_id=0}-knows->{~label=person, community_id=1317720192, member_id=0}]
gremlin> g.E(knows).properties()
gremlin>
Thank you for the feedback Leifur. This appears to be a bug and we've filed an internal JIRA and the engineering team is investigating.

Drawing 3D polygon on unity 3d

I am trying out unity for a project that i am on.
I am attempting to draw 3D polygon from a set of coordinate that I have.
So what i am doing now is to build a row of cube btw the two points. I plan to build these points into either a solid shape or just "walls" to form a room.
However, it doesn't seem to work as expected. Please advise.
drawCube( Vector3(10,0,14),Vector3(70,0,14));
drawCube( Vector3(90,0,14),Vector3(60,87,45));
function drawCube(v1,v2) {
pA = v1;
pB = v2;
var plane : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
var between:Vector3 = pB - pA;
var distance:float = between.magnitude;
plane.transform.localScale.x = distance;
plane.transform.localScale.y=10;
plane.transform.position = pA + (between / 2.0);
plane.transform.LookAt(pB);
}
updated: I have also tried using a mesh but all i got was the below image. What am i doing wrong?
I am trying to achieve something like this
You could make primitives and manipulate them but that would limit you very much if you needed to scale or change your requirements in the future. I would recommend using a procedural mesh to create the geometry you need as you need it. The basics aren't too hard, it's just a matter of constructing the Mesh object from it's base components given some vertices. Here's an example of constructing a 3d quadrilateral:
using UnityEngine;
using System.Collections.Generic;
public class SquareMaker : MonoBehaviour {
public List<Vector3> points;
void Start()
{
GameObject threeDSquare = new GameObject("3DSquare");
threeDSquare.AddComponent<MeshRenderer>();
threeDSquare.AddComponent<MeshFilter>();
threeDSquare.GetComponent<MeshFilter>().mesh = CreateMesh(points);
}
private Mesh CreateMesh(List<Vector3> points)
{
List<int> tris = new List<int>(); // Every 3 ints represents a triangle
List<Vector2> uvs = new List<Vector2>(); // Vertex position in 0-1 UV space
/* 4 points in the list for the square made of two triangles:
0 *--* 1
| /|
|/ |
3 *--* 2
*/
tris.Add(1);
tris.Add(2);
tris.Add(3);
tris.Add(3);
tris.Add(0);
tris.Add(1);
// uvs determine vert (point) coordinates in uv space
uvs.Add(new Vector2(0f, 1f));
uvs.Add(new Vector2(1f, 1f));
uvs.Add(new Vector2(1f, 0f));
uvs.Add(new Vector2(0f, 0f));
Mesh mesh = new Mesh();
mesh.vertices = points.ToArray();
mesh.uv = uvs.ToArray();
mesh.triangles = tris.ToArray();
mesh.RecalculateNormals();
return mesh;
}
}

how to join vertices to form triangular mesh?

I have a set of triangulated mesh data. For every triangular face, I want to form a smaller similar triangle inside. I generated three new vertices for the new triangle in each original faces. How can I join all the three generated vertices in each faces using matlab?
Thanks for all help!
The vertices in your triangulated mesh data will be placed in a list.
v[0] = (x0,y0,z0)
v[1] = (x1,y1,z1)
.
.
v[n] = (xn,yn,zn)
Next to this list, there will be a list of triangle or polygon data.
triangle[0] = (0,1,2) // these are the indices of the vertex in the vertex list
triangle[1] = (1,2,3)
.
.
triangle[k] = ( , , )
If your new list of vertices has the same order as the original, you should be able to copy this list to a new mesh data object. If you now copy the same list of triangle or polygon data, your mesh should be created.