Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple point query with curve example, RTCPointQueryFunction is never called #480

Open
olihey opened this issue Mar 24, 2024 · 0 comments
Open

Comments

@olihey
Copy link

olihey commented Mar 24, 2024

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant