问题起因:
在运行PointNet的可视化程序时,作者只提供了linux平台下的动态链接库程序源码,自己的windows平台下无法调用。发现是动态链接库的文件格式不对,遂学习如何将.so文件转换成.dll文件(PS:前提是你有文件的.cpp源码)
第一步新建C++动态链接库项目
将pch.h文件的内容改为如下:
#ifndef PCH_H
#define PCH_H
// 添加要在此处预编译的标头
#include "framework.h"
#endif //PCH_H
//定义宏
#ifdef IMPORT_DLL
#else
#define IMPORT_DLL extern "C" _declspec(dllimport) //指的是允许将其给外部调用
#endif
// 改为你所需要的链接库函数
IMPORT_DLL void render_ball(int h, int w, unsigned char* show, int n, int* xyzs, float* c0, float* c1, float* c2, int r);
第二步:重写dllmain.cpp文件
// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct PointInfo {
int x, y, z;
float r, g, b;
};
void render_ball(int h, int w, unsigned char* show, int n, int* xyzs, float* c0, float* c1, float* c2, int r) {
r = max(r, 1);
vector<int> depth(h * w, -2100000000);
vector<PointInfo> pattern;
for (int dx = -r; dx <= r; dx++)
for (int dy = -r; dy <= r; dy++)
if (dx * dx + dy * dy < r * r) {
double dz = sqrt(double(r * r - dx * dx - dy * dy));
PointInfo pinfo;
pinfo.x = dx;
pinfo.y = dy;
pinfo.z = dz;
pinfo.r = dz / r;
pinfo.g = dz / r;
pinfo.b = dz / r;
pattern.push_back(pinfo);
}
double zmin = 0, zmax = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
zmin = xyzs[i * 3 + 2] - r;
zmax = xyzs[i * 3 + 2] + r;
}
else {
zmin = min(zmin, double(xyzs[i * 3 + 2] - r));
zmax = max(zmax, double(xyzs[i * 3 + 2] + r));
}
}
for (int i = 0; i < n; i++) {
int x = xyzs[i * 3 + 0], y = xyzs[i * 3 + 1], z = xyzs[i * 3 + 2];
for (int j = 0; j<int(pattern.size()); j++) {
int x2 = x + pattern[j].x;
int y2 = y + pattern[j].y;
int z2 = z + pattern[j].z;
if (!(x2 < 0 || x2 >= h || y2 < 0 || y2 >= w) && depth[x2 * w + y2] < z2) {
depth[x2 * w + y2] = z2;
double intensity = min(1.0, (z2 - zmin) / (zmax - zmin) * 0.7 + 0.3);
show[(x2 * w + y2) * 3 + 0] = pattern[j].b * c2[i] * intensity;
show[(x2 * w + y2) * 3 + 1] = pattern[j].g * c0[i] * intensity;
show[(x2 * w + y2) * 3 + 2] = pattern[j].r * c1[i] * intensity;
}
}
}
}
// 具体内容改为你的文件内容