Skip to content

通过坐标创建图 - CreateGraphFromCoordinates

函数简介

根据坐标点数据创建图,支持自动连接,可按最大距离阈值连接,并可选择使用欧几里得距离作为边权重。

接口名称

CreateGraphFromCoordinates

DLL调用

c
int64_t CreateGraphFromCoordinates(int64_t instance, char* json, bool connectAll, double maxDistance, bool useEuclideanDistance);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
json字符串坐标节点JSON数据,支持数组与对象两种格式。
connectAll整数型是否连接所有节点,默认 true。
maxDistance双精度浮点数最大连接距离阈值,默认无穷大(不限制)。
useEuclideanDistance整数型是否使用欧几里得距离作为边权重,默认 true。

支持的JSON格式:

json
// 数组格式
[{"name":"A","x":0,"y":0},{"name":"B","x":1,"y":1}]

// 对象格式
{"A":{"x":0,"y":0},"B":{"x":1,"y":1}}

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long graphPtr = ola.CreateGraphFromCoordinates(@"[{"name":"A","x":0,"y":0},{"name":"B","x":100,"y":0},{"name":"C","x":50,"y":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
graph_ptr = ola.CreateGraphFromCoordinates(r'[{"name":"A","x":0,"y":0},{"name":"B","x":100,"y":0},{"name":"C","x":50,"y":80}]', True, 200.0, True)
if graph_ptr != 0:
    # 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graph_ptr)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
cpp
var ola = com("OlaPlug.OlaSoft")
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
text
.局部变量 ola, OLAPlug
ola.创建 ()
long graphPtr = ola.CreateGraphFromCoordinates(“[{\“name\“:\“A\“,\“x\“:0,\“y\“:0},{\“name\“:\“B\“,\“x\“:100,\“y\“:0},{\“name\“:\“C\“,\“x\“:50,\“y\“:80}]“, true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long graphPtr = ola.CreateGraphFromCoordinates("[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", true, 200.0, true);
if (graphPtr != 0) {
    // 坐标图已创建,可继续 AddCoordinateNode 等操作
    ola.DeleteGraph(graphPtr);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long graphPtr = CreateGraphFromCoordinates(instance, "[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":100,\"y\":0},{\"name\":\"C\",\"x\":50,\"y\":80}]", 1, 200.0, 1);
if (graphPtr != 0) {
    DeleteGraph(instance, graphPtr);
}
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long graphPtr = CreateGraphFromCoordinates(instance, @"[{"name":"A","x":0,"y":0},{"name":"B","x":100,"y":0},{"name":"C","x":50,"y":80}]", 1, 200.0, 1);
if (graphPtr != 0) {
    DeleteGraph(instance, graphPtr);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
long graphPtr = CreateGraphFromCoordinates(instance, b'[{"name":"A","x":0,"y":0},{"name":"B","x":100,"y":0},{"name":"C","x":50,"y":80}]', 1, 200.0, 1);
if (graphPtr != 0) {
    DeleteGraph(instance, graphPtr);
}

返回值

返回值说明
(返回值)返回图的指针,失败返回0。

注意事项

项目说明
返回的图指针需要调用 DeleteGraph 释返回的图指针需要调用 DeleteGraph 释放内存。
connectAll 为 true 时connectAll 为 true 时,所有节点间距离小于 maxDistance 的会被连接。
useEuclideanDistance 为 tuseEuclideanDistance 为 true 时,边权重为节点间的欧几里得距离。
格式确保JSON格式正确,节点名需唯一。