RenderKit / embree

Embree ray tracing kernels repository.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple point query with curve example, RTCPointQueryFunction is never called

olihey opened this issue · comments

Hej, I am experimenting with finding the closest 2d line to a pixel and wanted to use embree 4 for that.
Therefore I create a small example but no matter what I do, my RTCPointQueryFunction is never called? Am I missing something?
The single flat linear line is going from (-10, -10) to (10, 10). A point query at (0, 0) with a radius of 2.0 should definitely find the curve and trigger the query function, but nothing happens. (all z are 0 because I only work in 2d)

#include <iostream>

#include <embree4/rtcore.h>

float vertices[] = {
	-10.0f, -10.0f, 0.0f,  // Start point
	 10.0f,  10.0f, 0.0f }; // End point
int indices[] = { 0, 1 }; // Single curve segment


bool query_function(struct RTCPointQueryFunctionArguments* args)
{
	std::cout << "Called" << std::endl << std::flush;
	return true;
}

int main(int argc, char *argv[])
{
	RTCDevice _rtc_device = rtcNewDevice(nullptr);
	RTCScene _edges_scene = rtcNewScene(_rtc_device);

    RTCGeometry rtc_line = rtcNewGeometry(_rtc_device, RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE);
	rtcSetSharedGeometryBuffer(rtc_line, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3, vertices, 0, 3 * sizeof(float), 2);
	rtcSetSharedGeometryBuffer(rtc_line, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT, indices, 0, 2 * sizeof(int), 1);

    rtcCommitGeometry(rtc_line);
    rtcAttachGeometry(_edges_scene, rtc_line);
    rtcReleaseGeometry(rtc_line);

	rtcCommitScene(_edges_scene);

	RTCPointQuery point_query;
	point_query.x = 0.0f;
	point_query.y = 0.0f;
	point_query.z = 0.0f;
	point_query.radius = 2.0f;
	point_query.time = 0.0f;

	RTCPointQueryContext context;
	rtcInitPointQueryContext(&context);

	rtcPointQuery(_edges_scene, &point_query, &context, query_function, nullptr);

	rtcReleaseScene(_edges_scene);
	rtcReleaseDevice(_rtc_device);

	std::cout << "DONE" << std::endl << std::flush;

    return EXIT_SUCCESS;
}